Skip to content

Commit

Permalink
use SW DEFAULT_PRIME
Browse files Browse the repository at this point in the history
  • Loading branch information
enitrat committed Nov 12, 2024
1 parent e703c48 commit 21410e6
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 13 deletions.
10 changes: 5 additions & 5 deletions cairo_zero/tests/src/kakarot/test_gas.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
)
from hypothesis import given
from hypothesis.strategies import integers
from starkware.cairo.lang.cairo_constants import DEFAULT_PRIME

from kakarot_scripts.utils.uint256 import int_to_uint256
from tests.utils.constants import FELT_252_PRIME


class TestGas:
Expand Down Expand Up @@ -36,10 +36,10 @@ def test_should_return_correct_expansion_cost(
assert diff == output

@given(
offset_1=integers(min_value=0, max_value=FELT_252_PRIME - 1),
size_1=integers(min_value=0, max_value=FELT_252_PRIME - 1),
offset_2=integers(min_value=0, max_value=FELT_252_PRIME - 1),
size_2=integers(min_value=0, max_value=FELT_252_PRIME - 1),
offset_1=integers(min_value=0, max_value=DEFAULT_PRIME - 1),
size_1=integers(min_value=0, max_value=DEFAULT_PRIME - 1),
offset_2=integers(min_value=0, max_value=DEFAULT_PRIME - 1),
size_2=integers(min_value=0, max_value=DEFAULT_PRIME - 1),
)
def test_should_return_max_expansion_cost(
self, cairo_run, offset_1, size_1, offset_2, size_2
Expand Down
12 changes: 6 additions & 6 deletions cairo_zero/tests/src/utils/test_bytes.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
import pytest
from hypothesis import given
from hypothesis.strategies import integers
from starkware.cairo.lang.cairo_constants import DEFAULT_PRIME

from kakarot_scripts.utils.uint256 import int_to_uint256
from tests.utils.constants import FELT_252_PRIME
from tests.utils.errors import cairo_error
from tests.utils.hints import patch_hint

Expand All @@ -28,7 +28,7 @@ def test_should_return_bytes(self, cairo_run, n):
)
assert expected == bytes(output)

@given(n=integers(min_value=2**248, max_value=FELT_252_PRIME - 1))
@given(n=integers(min_value=2**248, max_value=DEFAULT_PRIME - 1))
def test_should_raise_when_value_sup_31_bytes(self, cairo_run, n):
with cairo_error(message="felt_to_bytes_little: value >= 2**248"):
cairo_run("test__felt_to_bytes_little", n=n)
Expand Down Expand Up @@ -100,15 +100,15 @@ def test_should_return_bytes(self, cairo_run, n):

class TestFeltToBytes20:
@pytest.mark.parametrize(
"n", [0, 10, 1234, 0xFFFFFF, 2**128, FELT_252_PRIME - 1]
"n", [0, 10, 1234, 0xFFFFFF, 2**128, DEFAULT_PRIME - 1]
)
def test_should_return_bytes20(self, cairo_run, n):
output = cairo_run("test__felt_to_bytes20", n=n)
assert f"{n:064x}"[-40:] == bytes(output).hex()

class TestUint256ToBytesLittle:
@pytest.mark.parametrize(
"n", [0, 10, 1234, 0xFFFFFF, 2**128, FELT_252_PRIME - 1, 2**256 - 1]
"n", [0, 10, 1234, 0xFFFFFF, 2**128, DEFAULT_PRIME - 1, 2**256 - 1]
)
def test_should_return_bytes(self, cairo_run, n):
output = cairo_run("test__uint256_to_bytes_little", n=int_to_uint256(n))
Expand All @@ -117,7 +117,7 @@ def test_should_return_bytes(self, cairo_run, n):

class TestUint256ToBytes:
@pytest.mark.parametrize(
"n", [0, 10, 1234, 0xFFFFFF, 2**128, FELT_252_PRIME - 1, 2**256 - 1]
"n", [0, 10, 1234, 0xFFFFFF, 2**128, DEFAULT_PRIME - 1, 2**256 - 1]
)
def test_should_return_bytes(self, cairo_run, n):
output = cairo_run("test__uint256_to_bytes", n=int_to_uint256(n))
Expand All @@ -126,7 +126,7 @@ def test_should_return_bytes(self, cairo_run, n):

class TestUint256ToBytes32:
@pytest.mark.parametrize(
"n", [0, 10, 1234, 0xFFFFFF, 2**128, FELT_252_PRIME - 1, 2**256 - 1]
"n", [0, 10, 1234, 0xFFFFFF, 2**128, DEFAULT_PRIME - 1, 2**256 - 1]
)
def test_should_return_bytes(self, cairo_run, n):
output = cairo_run("test__uint256_to_bytes32", n=int_to_uint256(n))
Expand Down
2 changes: 0 additions & 2 deletions tests/utils/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,6 @@
BLOCK_NUMBER = 0x42
BLOCK_TIMESTAMP = int(time())

FELT_252_PRIME = 0x800000000000011000000000000000000000000000000000000000000000001

# Taken from eth_account.account.Account.sign_transaction docstring
# https://eth-account.readthedocs.io/en/stable/eth_account.html?highlight=sign_transaction#eth_account.account.Account.sign_transaction
TRANSACTIONS = [
Expand Down

0 comments on commit 21410e6

Please sign in to comment.