NEWTON

NEWTON


Popular tags

    Cairo error "Expected expression of type 'starkware.cairo.common.uint256.Uint256' to have an address."

    Asked

    4 months ago

    4

    views


    0

    I’m having a problem where I’m trying to use a Uint256 in a hint, but I keep getting this error

    Here is my code:

    %builtins output range_check

    

    from starkware.cairo.common.uint256 import (uint256_add, Uint256,

    uint256_mul)

    from starkware.cairo.common.serialize import serialize_word

    

    func main{output_ptr : felt*, range_check_ptr}():

    alloc_locals

    let num1 = Uint256(20000, 0)

    %{print(ids.num1)%}

    let num2 = Uint256(low=0,high=7)

    let (local mul_low : Uint256, local mul_high : Uint256) = uint256_mul(num1, num2)

    serialize_word(mul_high.low)

    

    return ()

    end

    This question was originally posted on Triality

      cairocairo-lang

    1 answers

    0

    To use a variable in a hint in Dairo it has to be a local variable. This is because when it does the hint execution it need the variable to be based on the function pointer instead of the allocation pointer, and only the local variable is based on the allocation pointer.

    Just replace let num1 = Uint256(20000, 0), with local num1 : Uint256 = Uint256(20000, 0).

    You also need to add alloc_locals to the beginning of your function.

    This answer was originally posted on Triality

    answered

    4 months ago

    Your answer

    NEWTON

    NEWTON