Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: chain_id mod 53 #1359

Merged
merged 4 commits into from
Aug 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/kakarot/library.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ namespace Kakarot {
chain_id: felt
) {
let (tx_info) = get_tx_info();
let (_, chain_id) = unsigned_div_rem(tx_info.chain_id, 2 ** 32);
let (_, chain_id) = unsigned_div_rem(tx_info.chain_id, 2 ** 53);
return (chain_id=chain_id);
}

Expand Down
23 changes: 1 addition & 22 deletions tests/src/kakarot/instructions/test_block_information.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
from collections import OrderedDict
from unittest.mock import patch

import pytest

from kakarot_scripts.constants import COINBASE
from tests.utils.constants import BIG_CHAIN_ID, BLOCK_GAS_LIMIT, CHAIN_ID, Opcodes
from tests.utils.constants import BLOCK_GAS_LIMIT, CHAIN_ID, Opcodes
from tests.utils.syscall_handler import SyscallHandler


Expand All @@ -29,23 +28,3 @@ class TestBlockInformation:
def test__exec_block_information(self, cairo_run, opcode, expected_result):
output = cairo_run("test__exec_block_information", opcode=opcode)
assert output == hex(expected_result)

@patch.object(
SyscallHandler,
"tx_info",
OrderedDict(
{
"version": 1,
"account_contract_address": 0xABDE1,
"max_fee": int(1e17),
"signature_len": None,
"signature": [],
"transaction_hash": 0xABDE1,
"chain_id": BIG_CHAIN_ID,
"nonce": 1,
}
),
)
def test__exec_chain_id__should_return_mod_64(self, cairo_run):
output = cairo_run("test__exec_block_information", opcode=Opcodes.CHAINID)
assert output == hex(BIG_CHAIN_ID % 2**32)
5 changes: 5 additions & 0 deletions tests/src/kakarot/test_kakarot.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -194,3 +194,8 @@ func test__set_cairo1_helpers_class_hash{
set_cairo1_helpers_class_hash(value);
return ();
}

func test__eth_chain_id{syscall_ptr: felt*, pedersen_ptr: HashBuiltin*, range_check_ptr}() -> felt {
let (chain_id) = Kakarot.eth_chain_id();
return chain_id;
}
9 changes: 9 additions & 0 deletions tests/src/kakarot/test_kakarot.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
from eth_abi import decode, encode
from eth_utils import keccak
from eth_utils.address import to_checksum_address
from hypothesis import given
from hypothesis.strategies import integers
from starkware.starknet.public.abi import get_storage_var_address
from web3._utils.abi import map_abi_data
from web3._utils.normalizers import BASE_RETURN_NORMALIZERS
Expand Down Expand Up @@ -405,6 +407,13 @@ def test_failing_contract(self, cairo_run):
)
assert not evm["reverted"]

class TestEthChainIdEntrypoint:
@given(chain_id=integers(min_value=0, max_value=2**64 - 1))
def test_should_return_chain_id_modulo_53(self, cairo_run, chain_id):
with patch.dict(SyscallHandler.tx_info, {"chain_id": chain_id}):
res = cairo_run("test__eth_chain_id")
assert res == chain_id % 2**53

class TestLoopProfiling:
@pytest.mark.slow
@pytest.mark.NoCI
Expand Down
Loading