NEWTON
Asked
6 months ago
9
views
0
According to the doc a felt is a field element, ie any integer between in the range [0, P) with P = 2^251 + 17 * 2^192 + 1.
On the other hand, the range_check_ptr checks that a felt is within [0, 2^128).
I don't understand this limitation : why not [0, 2^250) such that a felt is somehow a int250?
MWE:
%lang starknet
from starkware.cairo.common.math import assert_nn
@view
func foo{range_check_ptr}() -> ():
alloc_locals
local x
%{ ids.x = PRIME - 10 %}
assert_nn(a=x)
return ()
end
this fails because of how the assert_nn
and range_check_ptr
are defined but I can't understand why it's design so:
Error at pc=0:0:
Got an exception while executing a hint.
%{
^^
Cairo traceback (most recent call last):
contracts/main.cairo:6:6: (pc=0:13)
func foo{range_check_ptr}() -> ():
^**^
contracts/tmp.cairo:10:5: (pc=0:8)
assert_nn(a=x)
^************^
Traceback (most recent call last):
File "/Users/clementwalter/.pyenv/versions/3.9.13/envs/starksheet/lib/python3.9/site-packages/starkware/cairo/common/math.cairo", line 43, in <module>
assert 0 <= ids.a % PRIME < range_check_builtin.bound, f\'a = {ids.a} is out of range.\'
AssertionError: a = 3618502788666131213697322783095070105623107215331596699973092056135872020471 is out of range.'})
ㅤ This question was originally posted on Stack Overflow
0
Both are valid options. You can use 2 250-range checks to simulate a 128-range check, or 3-128 range checks to simulate a 250-range check. It boils down to performance (less is better) and what is a more common use.
ㅤ This answer was originally posted on Stack Overflow
answered
6 months ago
How to make math operation with Field Elements (felts) in Cairo lang?
What is the inefficiency in this cairo code using alloc_locals
Cairo Lang / StarkNet: What are Revoked references? What is alloc_locals?
How to use get_fp_and_pc in Cairo Lang?
Declaring a StarkNet contract on DevNet with Account() but I get GatewayError in StarkNetJS
StarknetPy Error in get_balance_sync (StarknetErrorCode.ENTRY_POINT_NOT_FOUND_IN_CONTRACT)
Cairo: Getting the zero address
signing a message using account.signMessage(data) | starknet.js
How can i learn Cairo with Python base?
What are the projects on starknet that plan to do the domain .stark?
Do you know a function that converts an array of felts (numbers) to a single string in JS? [Cairo Lang]
Can you explain about cancellation (L1 -> L2) in StarkNet (sequencer)?
ApeWorX: Why am I getting an "account __execute__" error message?
Is it possible to transpile contracts that use openzeppelin libraries?