state: Validate transaction chain id against the chain - #1610
Conversation
Codecov Report❌ Patch coverage is 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
Flags with carried forward coverage won't be shown. Click here to find out more.
🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
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_idand propagate it fromconfig.chainidin state/blockchain fixture loaders and from--state.chainid/T8NArgs::chain_idint8n. - Use
BlockInfo::chain_idinHost::get_tx_context()for the CHAINID opcode. - Add
INVALID_CHAIN_IDerror 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.
2bd2066 to
a6932af
Compare
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.
a6932af to
c35457a
Compare
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.