Skip to content
This repository has been archived by the owner on Jan 9, 2025. It is now read-only.

Commit

Permalink
reduce chain id to u32::max - 1 at most (#1078)
Browse files Browse the repository at this point in the history
<!--- Please provide a general summary of your changes in the title
above -->

<!-- Give an estimate of the time you spent on this PR in terms of work
days.
Did you spend 0.5 days on this PR or rather 2 days?  -->

Time spent on this PR:

## Pull request type

<!-- Please try to limit your pull request to one type,
submit multiple pull requests if needed. -->

Please check the type of change your PR introduces:

- [x] Bugfix
- [ ] Feature
- [ ] Code style update (formatting, renaming)
- [ ] Refactoring (no functional changes, no api changes)
- [ ] Build related changes
- [ ] Documentation content changes
- [ ] Other (please describe):


## What is the new behavior?

<!-- Please describe the behavior or changes that are being added by
this PR. -->

- chain id will now be limited to 4 ascii characters
- we noticed bugs in metamask if chain_id > ~2**52, see
ethereum/EIPs#2294
- note this is not part of the evm spec

<!-- Reviewable:start -->
- - -
This change is [<img src="https://reviewable.io/review_button.svg"
height="34" align="absmiddle"
alt="Reviewable"/>](https://reviewable.io/reviews/kkrt-labs/kakarot/1078)
<!-- Reviewable:end -->
  • Loading branch information
Eikix authored Apr 6, 2024
1 parent 7b70620 commit b94b354
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 4 deletions.
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ build-sol:
forge build --names --force

install-katana:
cargo install --git https://github.com/dojoengine/dojo --locked --tag v0.6.0-alpha.2 katana
cargo install --git https://github.com/dojoengine/dojo --locked --tag v0.6.0-alpha.6 katana

run-katana:
katana --validate-max-steps 16777216 --invoke-max-steps 16777216 --eth-gas-price 0 --strk-gas-price 0 --disable-fee
katana --chain-id test --validate-max-steps 16777216 --invoke-max-steps 16777216 --eth-gas-price 0 --strk-gas-price 0 --disable-fee
2 changes: 1 addition & 1 deletion src/backend/starknet.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ namespace Starknet {

// No idea why this is required - but trying to pass prev_randao directly causes bugs.
let prev_randao = Uint256(low=prev_randao.low, high=prev_randao.high);
let (_, chain_id) = unsigned_div_rem(tx_info.chain_id, 2 ** 64);
let (_, chain_id) = unsigned_div_rem(tx_info.chain_id, 2 ** 32);

return new model.Environment(
origin=origin,
Expand Down
2 changes: 1 addition & 1 deletion tests/src/kakarot/instructions/test_block_information.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,4 +48,4 @@ def test__exec_block_information(self, cairo_run, opcode, expected_result):
)
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**64)
assert output == hex(BIG_CHAIN_ID % 2**32)

0 comments on commit b94b354

Please sign in to comment.