Skip to content

state: Validate transaction chain id against the chain - #1610

Merged
chfast merged 1 commit into
masterfrom
state/chainid-from-json
Jul 24, 2026
Merged

state: Validate transaction chain id against the chain#1610
chfast merged 1 commit into
masterfrom
state/chainid-from-json

Conversation

@chfast

@chfast chfast commented Jul 23, 2026

Copy link
Copy Markdown
Member

Load config.chainid into BlockInfo in the state and blockchain loaders, use it for the CHAINID opcode (was hardcoded 1), and reject mismatched tx chain ids (0 = unspecified). Fixes the EEST invalid_chain_id cases.

@codecov

codecov Bot commented Jul 23, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 89.47368% with 4 lines in your changes missing coverage. Please review.
✅ Project coverage is 97.39%. Comparing base (26ddc83) to head (c35457a).

Files with missing lines Patch % Lines
test/state/errors.hpp 0.00% 1 Missing and 1 partial ⚠️
test/utils/blockchaintest_loader.cpp 80.00% 0 Missing and 1 partial ⚠️
test/utils/statetest_loader.cpp 88.88% 0 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #1610      +/-   ##
==========================================
- Coverage   97.41%   97.39%   -0.03%     
==========================================
  Files         164      164              
  Lines       14730    14764      +34     
  Branches     3394     3400       +6     
==========================================
+ Hits        14349    14379      +30     
- Misses        280      281       +1     
- Partials      101      104       +3     
Flag Coverage Δ
eest-develop 89.41% <68.42%> (-0.08%) ⬇️
eest-develop-gmp 26.00% <23.68%> (-0.03%) ⬇️
eest-legacy 17.45% <13.15%> (-0.02%) ⬇️
eest-libsecp256k1 27.62% <23.68%> (-0.03%) ⬇️
eest-stable 89.38% <68.42%> (-0.08%) ⬇️
evmone-unittests 92.67% <86.84%> (-0.02%) ⬇️

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

Components Coverage Δ
core 95.91% <60.00%> (-0.04%) ⬇️
tooling 90.32% <88.88%> (-0.04%) ⬇️
tests 99.80% <100.00%> (+<0.01%) ⬆️
Files with missing lines Coverage Δ
test/state/block.hpp 100.00% <ø> (ø)
test/state/host.cpp 99.54% <100.00%> (ø)
test/state/state.cpp 99.69% <100.00%> (+<0.01%) ⬆️
test/unittests/state_transition_tx_test.cpp 100.00% <100.00%> (ø)
test/unittests/state_tx_test.cpp 98.84% <100.00%> (+0.01%) ⬆️
test/utils/rlp_encode.cpp 100.00% <ø> (ø)
test/utils/statetest_export.cpp 72.44% <100.00%> (+0.66%) ⬆️
test/utils/t8n.cpp 94.53% <100.00%> (+0.04%) ⬆️
tools/evmone/main.cpp 96.32% <ø> (ø)
test/utils/blockchaintest_loader.cpp 95.41% <80.00%> (-0.62%) ⬇️
... and 2 more
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

This PR wires a configurable chain ID through the state/blockchain test loaders and the t8n tool so that BlockInfo carries the configured chain ID, the CHAINID opcode reflects it (instead of being effectively fixed to 1), and transactions with an explicit mismatching chain ID are rejected (supporting EEST invalid_chain_id cases).

Changes:

  • Add BlockInfo::chain_id and propagate it from config.chainid in state/blockchain fixture loaders and from --state.chainid / T8NArgs::chain_id in t8n.
  • Use BlockInfo::chain_id in Host::get_tx_context() for the CHAINID opcode.
  • Add INVALID_CHAIN_ID error and a unit test covering a mismatching transaction chain id.

Reviewed changes

Copilot reviewed 10 out of 10 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
tools/evmone/main.cpp Changes t8n CLI default chain id and passes it into T8NArgs.
test/utils/t8n.hpp Updates T8NArgs default chain id.
test/utils/t8n.cpp Copies T8NArgs::chain_id into BlockInfo::chain_id.
test/utils/statetest_loader.cpp Loads config.chainid and applies it to the per-case BlockInfo.
test/utils/blockchaintest_loader.cpp Loads config.chainid and applies it to all TestBlock::block_info.
test/unittests/state_transition_tx_test.cpp Adds a unit test for mismatching transaction chain id.
test/state/state.cpp Adds transaction chain-id validation against the block’s chain id.
test/state/host.cpp Returns CHAINID from m_block.chain_id in the tx context.
test/state/errors.hpp Introduces INVALID_CHAIN_ID error code and message.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread test/state/state.cpp Outdated
@chfast
chfast force-pushed the state/chainid-from-json branch 3 times, most recently from 2bd2066 to a6932af Compare July 23, 2026 21:10
Load config.chainid into BlockInfo (state and blockchain loaders), use
it for the CHAINID opcode (was hardcoded 1), and reject a mismatching tx
chain id; only a legacy tx may use 0 (unspecified, EIP-155). Fixes the
EEST invalid_chain_id cases.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 14 out of 14 changed files in this pull request and generated no new comments.

@chfast
chfast merged commit 83d2c6f into master Jul 24, 2026
22 of 24 checks passed
@chfast
chfast deleted the state/chainid-from-json branch July 24, 2026 17:29
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.

2 participants