← Back to Pull requests

test: Recover the blockchain test transaction senders #1634

Open
chfast opened this pull request with 55 lines diff across 4 files
View on GitHub
chfast chfast commented on Aug 10, 2026 19:08 UTC
Author

The runner trusted the sender the fixture supplies, so a transaction whose signature the test broke executed as that sender and the block was rejected by whatever rule it happened to break. Recover from the transaction's own encoding instead, and reject it when the signature does not recover. This removes the exemption added in #1632 and the TODO from #1623; the two fixtures added there now exercise the recovery.

recover_sender() also had to reject a v outside its domain, a rule only decode_transaction() enforced and the JSON path never runs. Without it the v=34 cases of frontier/validation/bad_v_r_s recover a stranger's address and fail on its empty balance instead of on the signature — 13 blockchain fixtures.

Recovery is opt-in via BlockTransitionOptions, so t8n keeps using the sender it is given.

Diff: 55 lines (+33 / -22) across 4 files Reviewer: chfast Review duration: 121518m
All Vouch review confidence checks passed
Residual risk 0.10 = Change Risk (0.52) × (1 − Review Confidence (0.82)). Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.52 · 55 lines diff across 4 files
0.52
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.91 · 5 substantive comment(s)
0.91
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 50%
81%
Bedrock Claude 3 · Risk Narration
(disconnected)
Groq
Groq Risk Narration
AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
Model 1 · Change Risk Attribution
SHAP Weights
Diff Size diff_size
0.241
Self Review self_review
0.140
Real PR Conversation Timeline
8 items
chfast chfast commented on code on Aug 10, 2026 19:10 UTC
Code Review
test/state/transaction.cpp:1
@@ -164,6 +164,8 @@ std::optional<address> recover_sender(const Transaction& tx, bytes_view txbytes)
 
     // A typed v is {0, 1}. A legacy v is 27 + y_parity, or 35 + 2 * chain_id + y_parity (EIP-155):
     // both bases are odd, so an even v means y_parity 1.
+    if (typed ? tx.v > 1 : (tx.v < 27 || (tx.v > 28 && tx.v < 35)))

Why this is here now?

Copilot Copilot commented on code on Aug 10, 2026 19:14 UTC
Code Review
test/blockchaintest/blockchaintest_runner.cpp:1
@@ -346,22 +346,15 @@ void run_blockchain_tests(std::span<const BlockchainTest> tests, evmc::VM& vm)
                 const auto names_spec_exception =
                     test_block.expected_exception.find("Exception.") != std::string::npos;
 
-                // TODO: The transaction senders come from the fixture instead of being recovered
-                //   from the signatures, so evmone never sees the signature the test broke. Such a
-                //   transaction executes as the sender the fixture names and the block is rejected
-                //   by whatever rule that sender happens to break, or by its state root alone.
-                const auto sender_not_recovered = contains_any(
-                    test_block.expected_exception, "TransactionException.INVALID_SIGNATURE_VRS");
-
-                const auto res =
-                    apply_block(pre_state, vm, bi, block_hashes, test_block.transactions, rev,
-                        blob_gas_limit, {.block_reward = mining_reward(rev)});
+                const auto res = apply_block(pre_state, vm, bi, block_hashes,
+                    test_block.transactions, rev, blob_gas_limit,
+                    {.block_reward = mining_reward(rev), .recover_senders = true});

Recovery is enabled only in the expected-invalid branch. The expected-valid path at lines 274-275 still calls apply_block() with the default recover_senders = false, so it continues trusting the JSON sender and can accept a purportedly valid block whose transaction signature does not recover. Opt the valid blockchain path into recovery as well (while leaving the t8n call explicitly opted out).

Copilot Copilot commented on code on Aug 10, 2026 19:14 UTC
Code Review
test/utils/block_transition.cpp:1
@@ -55,8 +55,24 @@ TransitionResult apply_block(const TestState& state, evmc::VM& vm, const state::
 
     for (size_t i = 0; i < txs.size(); ++i)
     {
-        const auto& tx = txs[i];
-        const auto computed_tx_hash = keccak256(rlp::encode(tx));
+        const auto& input_tx = txs[i];
+        const auto tx_bytes = rlp::encode(input_tx);
+        const auto computed_tx_hash = keccak256(tx_bytes);
+
+        std::optional<state::Transaction> recovered_tx;
+        if (opts.recover_senders)
+        {
+            const auto sender = state::recover_sender(input_tx, tx_bytes);

recover_sender() always uses RecoveryMode::strict, which rejects high-s signatures, but EIP-2 introduced that restriction only at Homestead. Enabling this path for every blockchain revision means an otherwise valid Frontier high-s transaction in an invalid block is now rejected as INVALID_SIGNATURE before the runner can check the block's intended invalidity. Make recovery/validation revision-aware: allow the malleable s range before EVMC_HOMESTEAD and enforce low-s from Homestead onward.

Copilot Copilot commented on code on Aug 10, 2026 19:14 UTC
Code Review
test/utils/block_transition.cpp:1
@@ -55,8 +55,24 @@ TransitionResult apply_block(const TestState& state, evmc::VM& vm, const state::
 
     for (size_t i = 0; i < txs.size(); ++i)
     {
-        const auto& tx = txs[i];
-        const auto computed_tx_hash = keccak256(rlp::encode(tx));
+        const auto& input_tx = txs[i];
+        const auto tx_bytes = rlp::encode(input_tx);
+        const auto computed_tx_hash = keccak256(tx_bytes);
+
+        std::optional<state::Transaction> recovered_tx;
+        if (opts.recover_senders)
+        {
+            const auto sender = state::recover_sender(input_tx, tx_bytes);
+            if (!sender.has_value())
+            {
+                rejected_txs.push_back(
+                    {computed_tx_hash, i, make_error_code(state::INVALID_SIGNATURE)});
+                continue;
+            }
+            recovered_tx = input_tx;
+            recovered_tx->sender = *sender;
+        }

This passes a JSON-loaded transaction to an API whose documented precondition is that the transaction was decoded from tx_bytes. For protected legacy transactions, chain_id is not encoded independently—decoding derives it from v—so a JSON chainId inconsistent with v makes recovery hash the wrong preimage and later validates a chain ID that is not on the wire. Normalize the legacy chain ID from v before both recovery and execution.

copilot-pull-request-reviewer[bot] copilot-pull-request-reviewer[bot] commented on Aug 10, 2026 19:14 UTC
Reviewer

Pull request overview

Adds transaction sender recovery to blockchain-test execution so invalid signatures are rejected directly.

Changes:

  • Adds opt-in sender recovery to block transitions.

  • Enables recovery for expected-invalid blockchain fixtures.

  • Rejects out-of-domain signature v values.
  • Reviewed changes

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

    | File | Description |
    | ---- | ----------- |
    | test/utils/block_transition.hpp | Adds sender-recovery option. |
    | test/utils/block_transition.cpp | Recovers senders before execution. |
    | test/state/transaction.cpp | Validates signature v. |
    | test/blockchaintest/blockchaintest_runner.cpp | Enables recovery for invalid blocks. |

    ---

    💡 <a href="/ipsilon/evmone/new/master?filename=.github/skills/code-review/SKILL.md" class="Link--inTextBlock" target="_blank" rel="noopener noreferrer">Add a code-review agent skill</a> or configure MCP servers for context-aware, tailored reviews. <a href="https://docs.github.com/en/copilot/how-tos/use-copilot-agents/request-a-code-review/use-code-review#mcp-servers-and-agent-skills" class="Link--inTextBlock" target="_blank" rel="noopener noreferrer">Learn more in the docs.</a>

    chfast chfast commented on code on Aug 10, 2026 19:14 UTC
    Code Review
    test/state/transaction.cpp:1
    @@ -164,6 +164,8 @@ std::optional<address> recover_sender(const Transaction& tx, bytes_view txbytes)
     
         // A typed v is {0, 1}. A legacy v is 27 + y_parity, or 35 + 2 * chain_id + y_parity (EIP-155):
         // both bases are odd, so an even v means y_parity 1.
    +    if (typed ? tx.v > 1 : (tx.v < 27 || (tx.v > 28 && tx.v < 35)))

    Because the JSON path never decodes, and this is the only function that interprets v.

    decode_transaction() bounds v while parsing (transaction.cpp:109-112 for legacy, :128 for typed), so a transaction that came from RLP can never reach here out of domain. A blockchain-test transaction is built field by field from rlp_decoded JSON, which applies no such bound, and this PR is the first caller to recover a sender from one. Without the check the v=34 cases of frontier/validation/bad_v_r_s derive y_parity = 1 from an even v, recover a stranger's address, and get rejected for its empty balance — got INSUFFICIENT_ACCOUNT_FUNDS, expected INVALID_SIGNATURE_VRS, 13 fixtures.

    It sits immediately above the y_parity derivation because that is what it guards: the line below assumes v is one of the forms the comment describes.

    It does duplicate the decoder's bound for now. The intended end state is the reverse — drop it from decode_transaction() so an out-of-range v is reported as INVALID_SIGNATURE rather than INVALID_ENCODING, which is what would let the over-broad {INVALID_ENCODING, "TransactionException.INVALID_SIGNATURE_VRS"} alternative come out of error_matching.cpp. That changes state-test behaviour, so I kept it out of this PR. Happy to fold it in if you would rather have it in one go.

    codecov[bot] codecov[bot] commented on Aug 10, 2026 19:30 UTC
    Bot

    Codecov Report


    :x: Patch coverage is 91.66667% with 2 lines in your changes missing coverage. Please review.
    :white_check_mark: Project coverage is 97.70%. Comparing base (56808b6) to head (1f4978b).
    :warning: Report is 2 commits behind head on master.

    | Files with missing lines | Patch % | Lines |
    |---|---|---|
    | test/blockchaintest/blockchaintest\_runner.cpp | 88.88% | 0 Missing and 1 partial :warning: |
    | test/state/transaction.cpp | 50.00% | 0 Missing and 1 partial :warning: |

    <details><summary>Additional details and impacted files</summary>

    @@            Coverage Diff             @@
    ##           master    #1634      +/-   ##
    ==========================================
    - Coverage   97.71%   97.70%   -0.01%     
    ==========================================
      Files         171      171              
      Lines       15593    15602       +9     
      Branches     3607     3610       +3     
    ==========================================
    + Hits        15236    15244       +8     
      Misses        269      269              
    - Partials       88       89       +1     
    

    | Flag | Coverage Δ | |
    |---|---|---|
    | eest-develop | 88.56% <87.50%> (-0.06%) | :arrow_down: |
    | eest-develop-gmp | 26.65% <0.00%> (-0.02%) | :arrow_down: |
    | eest-legacy | 18.83% <54.16%> (+1.66%) | :arrow_up: |
    | eest-libsecp256k1 | 28.84% <0.00%> (-0.02%) | :arrow_down: |
    | eest-stable | 88.56% <87.50%> (-0.06%) | :arrow_down: |
    | evmone-unittests | 93.37% <50.00%> (-0.05%) | :arrow_down: |

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

    | Components | Coverage Δ | |
    |---|---|---|
    | core | 96.06% <50.00%> (-0.02%) | :arrow_down: |
    | tooling | 91.95% <95.45%> (+0.03%) | :arrow_up: |
    | tests | 99.80% <ø> (ø) | |

    | Files with missing lines | Coverage Δ | |
    |---|---|---|
    | test/utils/block\_transition.cpp | 100.00% <100.00%> (ø) | |
    | test/blockchaintest/blockchaintest\_runner.cpp | 83.27% <88.88%> (-0.25%) | :arrow_down: |
    | test/state/transaction.cpp | 98.87% <50.00%> (-1.13%) | :arrow_down: |
    </details>
    <details><summary> :rocket: New features to boost your workflow: </summary>

  • :snowflake: Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

  • </details>

    Reviewers
    Assignees
    chfast chfast
    Labels
    risk: low confidence: 81.8% reviewed
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 52.5% (MEDIUM) · Higher = larger blast radius
    52.5%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 81.8% · Lower = rushed or shallow review
    81.8%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 9.5% · Safe to merge
    9.5%
    Repository