Skip to content

fix(specs): check chain id - #3000

Merged
SamWilsn merged 2 commits into
ethereum:forks/amsterdamfrom
SamWilsn:check-chain-id
Jun 24, 2026
Merged

SamWilsn merged 2 commits into
ethereum:forks/amsterdamfrom
SamWilsn:check-chain-id

Conversation

@SamWilsn

Copy link
Copy Markdown
Contributor

🗒️ Description

EELS didn't check incoming transaction's chain id

Cute Animal Picture

Put a link to a cute animal picture inside the parenthesis-->

@codecov

codecov Bot commented Jun 17, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 93.19%. Comparing base (d844821) to head (fa9fde7).
⚠️ Report is 1 commits behind head on forks/amsterdam.

Additional details and impacted files
@@                 Coverage Diff                 @@
##           forks/amsterdam    #3000      +/-   ##
===================================================
+ Coverage            92.80%   93.19%   +0.38%     
===================================================
  Files                  620      624       +4     
  Lines                36728    36926     +198     
  Branches              3345     3377      +32     
===================================================
+ Hits                 34087    34413     +326     
+ Misses                1780     1716      -64     
+ Partials               861      797      -64     
Flag Coverage Δ
unittests 93.19% <100.00%> (+0.38%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@SamWilsn SamWilsn changed the title Check chain id fix(specs): check chain id Jun 17, 2026

@LouisTsai-Csie LouisTsai-Csie left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Leave one question, thank you

Comment on lines +385 to +390
if isinstance(tx, LegacyTransaction):
if tx.v == 27 or tx.v == 28:
return None
return U64((tx.v - U256(35)) >> U256(1))
else:
return tx.chain_id

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if isinstance(tx, LegacyTransaction):
if tx.v == 27 or tx.v == 28:
return None
return U64((tx.v - U256(35)) >> U256(1))
else:
return tx.chain_id
if isinstance(tx, LegacyTransaction):
if tx.v == 27 or tx.v == 28:
return None
return U64((tx.v - U256(35)) >> U256(1))
return tx.chain_id

Not very important suggestion.

Comment on lines +336 to +338
tx_chain_id = U64((v - U256(35)) >> U256(1))
v = (v - U256(35)) & U256(1)
if v != 0 and v != 1:

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will this always be false? since v masks with U256(1), so it would always be either 0 or 1.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good catch!

@marioevz marioevz left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just one comment I think needs addressing. Thanks!

if isinstance(tx, LegacyTransaction):
if tx.v == 27 or tx.v == 28:
return None
return U64((tx.v - U256(35)) >> U256(1))

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test generates an overflow error in this line:

@pytest.mark.valid_from("Istanbul")
@pytest.mark.exception_test
def test_chainid_invalid_v(
    state_test: StateTestFiller,
    pre: Alloc,
    chain_config: ChainConfig,
) -> None:
    """Test CHAINID opcode."""
    chain_id = chain_config.chain_id
    contract_address = pre.deploy_contract(Op.SSTORE(1, Op.CHAINID) + Op.STOP)

    tx = Transaction(
        ty=0,
        chain_id=chain_id,
        to=contract_address,
        v=34,
        r=1,
        s=1,
        sender=Address(0x0),
        error=TransactionException.INVALID_SIGNATURE_VRS,
    )

    post = {
        contract_address: Account(storage={1: chain_id}),
    }

    state_test(pre=pre, post=post, tx=tx)

We still need to check that the v value is equal to 35 or greater. Same for the rest of the forks I believe.

@SamWilsn
SamWilsn force-pushed the check-chain-id branch 3 times, most recently from e0a625f to 9d2a0b8 Compare June 23, 2026 01:27
SamWilsn and others added 2 commits June 22, 2026 22:22
Co-authored-by: Mario Vega Zavala <mario.vegazavala@ethereum.org>

@marioevz marioevz left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks!

@marioevz
marioevz dismissed LouisTsai-Csie’s stale review June 24, 2026 20:11

Comment no longer applies.

@SamWilsn
SamWilsn merged commit fd6e6b8 into ethereum:forks/amsterdam Jun 24, 2026
26 checks passed
@SamWilsn
SamWilsn deleted the check-chain-id branch June 24, 2026 20:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants