Skip to content

test: Take the state test transaction from its encoding - #1614

Merged
chfast merged 1 commit into
masterfrom
state/tx-decode-wiring
Jul 27, 2026
Merged

test: Take the state test transaction from its encoding#1614
chfast merged 1 commit into
masterfrom
state/tx-decode-wiring

Conversation

@chfast

@chfast chfast commented Jul 27, 2026

Copy link
Copy Markdown
Member

Load test transaction from its encoding in "txbytes" instead of trusting the decomposed JSON variant.
This detected some additional expect decoding failures in tests.
We still lack sender address recovery from signatures, so take it as previously from JSON "sender".

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 improves state test execution fidelity by preferring the canonical transaction serialization (txbytes) when available, instead of trusting the decomposed JSON transaction template, enabling detection of additional decoding/encoding failures in state tests.

Changes:

  • Added txbytes storage to per-case expectations and loaded it from JSON when present.
  • Updated the state test runner to decode transactions from txbytes (falling back to the template transaction when not provided) and to report INVALID_ENCODING on decode failure.
  • Introduced INVALID_ENCODING as a new transaction error code and added export mapping for it.

Reviewed changes

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

Show a summary per file
File Description
test/utils/statetest.hpp Adds txbytes to per-case expectations to carry the canonical serialized transaction bytes.
test/utils/statetest_loader.cpp Loads optional txbytes from JSON into expectations.
test/utils/statetest_export.cpp Maps the new INVALID_ENCODING error to the standardized exported error string.
test/statetest/statetest_runner.cpp Decodes transaction from txbytes when provided; returns INVALID_ENCODING if decoding fails.
test/state/errors.hpp Adds INVALID_ENCODING to the error enum and category messages.

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

Comment thread test/statetest/statetest_runner.cpp
@codecov

codecov Bot commented Jul 27, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 73.33333% with 4 lines in your changes missing coverage. Please review.
✅ Project coverage is 97.46%. Comparing base (7686df8) to head (57e3d53).
⚠️ Report is 1 commits behind head on master.

Files with missing lines Patch % Lines
test/state/errors.hpp 0.00% 1 Missing and 1 partial ⚠️
test/statetest/statetest_runner.cpp 81.81% 0 Missing and 2 partials ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #1614      +/-   ##
==========================================
- Coverage   97.48%   97.46%   -0.03%     
==========================================
  Files         170      170              
  Lines       15376    15388      +12     
  Branches     3591     3596       +5     
==========================================
+ Hits        14990    14998       +8     
- Misses        281      282       +1     
- Partials      105      108       +3     
Flag Coverage Δ
eest-develop 88.26% <60.00%> (-1.16%) ⬇️
eest-develop-gmp 25.60% <60.00%> (+0.58%) ⬆️
eest-legacy 16.74% <0.00%> (-0.02%) ⬇️
eest-libsecp256k1 27.74% <60.00%> (+0.58%) ⬆️
eest-stable 88.22% <60.00%> (-1.16%) ⬇️
evmone-unittests 93.01% <40.00%> (-0.06%) ⬇️

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

Components Coverage Δ
core 95.99% <0.00%> (-0.04%) ⬇️
tooling 90.30% <84.61%> (-0.06%) ⬇️
tests 99.80% <ø> (ø)
Files with missing lines Coverage Δ
test/utils/statetest.hpp 90.90% <ø> (ø)
test/utils/statetest_loader.cpp 92.92% <100.00%> (+0.04%) ⬆️
test/state/errors.hpp 81.01% <0.00%> (-2.11%) ⬇️
test/statetest/statetest_runner.cpp 85.36% <81.81%> (-2.52%) ⬇️
🚀 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

Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.

Comment on lines +35 to +37
tx = state::decode_transaction(*expected.txbytes);
if (tx.has_value())
tx->sender = template_tx.sender; // No recovery yet, take sender from JSON.
Comment on lines +40 to +44
const auto res =
tx.has_value() ?
transition(state, block, test.block_hashes, *tx, rev, vm, block.gas_limit,
static_cast<int64_t>(state::max_blob_gas_per_block(blob_params))) :
make_error_code(state::INVALID_ENCODING);
@chfast
chfast force-pushed the state/tx-decode-wiring branch from 1c514a6 to 7f72262 Compare July 27, 2026 07:39
@chfast chfast changed the title test: Take the state test transaction from its serialization test: Take the state test transaction from its encoding Jul 27, 2026
A state test's transaction is built from a shared multi-transaction
template, which describes the transaction rather than being it: the
template cannot express a malformed encoding, so a case whose defect lives
in the bytes was executed as if it were well formed. In execution-specs
tests@v20.0.1 that is the whole frontier/validation/bad_v_r_s family, 116
cases the runner reported as "unexpected valid transaction".

Each post entry carries the serialization it was built from as "txbytes".
Decode it and run that transaction instead; input that does not decode
makes the transaction invalid (INVALID_ENCODING). The sender still comes
from the template, so nothing about the signature is verified yet.
@chfast
chfast force-pushed the state/tx-decode-wiring branch from 7f72262 to 57e3d53 Compare July 27, 2026 07:53
@chfast
chfast merged commit fd14fd8 into master Jul 27, 2026
21 of 23 checks passed
@chfast
chfast deleted the state/tx-decode-wiring branch July 27, 2026 08:18
chfast added a commit that referenced this pull request Aug 9, 2026
The state test runner still took the sender from the fixture's template,
so a signature was only ever checked for shape. The remaining
frontier/validation/bad_v_r_s cases are legacy transactions that decode
cleanly and carry an out-of-range r or s; nothing rejected them.

Add state::recover_sender() and use it, as a node does; a signature that
does not recover makes the transaction invalid (INVALID_SIGNATURE).
Recovery is strict, so EIP-2 low-s and r, s in [1, secp256k1n) come from
ecrecover itself.

The signing preimage is a slice of the serialization -- the payload
without the trailing (v, r, s), and for a protected legacy transaction
(chain_id, 0, 0) in their place -- so recover_sender() takes the decoded
transaction together with the bytes it came from, and finds the end of
the signed prefix by subtracting the sizes of the canonically encoded
signature fields. Reusing the slice avoids restating every transaction
type's field order next to rlp_encode(), which already states it.

The exported "expectException" name is added for the new code as well;
EEST names encoding failures one by one, so INVALID_ENCODING, minted by
the same runner path since #1614, gets its plain message instead.
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