NEWTON
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
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
Cairo: How to reassign Uint256 in a conditional
How do you optimize gas in Cairo with Uint256/felt?
Cairo Error: 'range_check_ptr' cannot be used as an implicit return value. Consider using a 'with' statement.
Fixed Point pow operation error
How to import uint256 in Cairo?
How can I send a Uint256 amount of ERC20 tokens from L1 to starknet? And how should I build my payload for "sendMessageToL2" to match the Uint256 format of Cairo?
Is uint256 math operators like uint256_le safe? Why do I need to use uint256_check?