Skip to content

vm: Fix BlockBuilder bug#4277

Draft
ScottyPoi wants to merge 8 commits into
masterfrom
builder-fix
Draft

vm: Fix BlockBuilder bug#4277
ScottyPoi wants to merge 8 commits into
masterfrom
builder-fix

Conversation

@ScottyPoi
Copy link
Copy Markdown
Contributor

@ScottyPoi ScottyPoi commented Apr 22, 2026

Implemented the fix for #4271.

I was able to reproduce the user's sceanario and confirm that the issue is valid.

The current BlockBuilder flow does runTx(...), then mutates builder accounting, then reconstructs the minimal blob tx.

That means a throw from minimal tx reconstruction can happen after execution has already committed into the builder journal and after blobGasUsed has been mutated, but before the tx/result arrays and gasUsed are updated.

The decode path in 4844/constructors.ts also constructs the tx first and only later assigns decodedTx.networkWrapperVersion = networkWrapperVersionInt, so the constructor checks in tx.ts do not run against the wire wrapper version during initial decode.

Fix:

In packages/tx/src/4844/tx.ts and packages/tx/src/4844/constructors.ts, I factored the fork-sensitive blob checks into a shared validator and now run that validation during network-wrapper deserialization before mutating the decoded tx. That closes the split-validation gap where a wrapper_version = 1 payload could be decoded under a pre-7594 Common and only fail later.

In packages/vm/src/buildBlock.ts, BlockBuilder.addTransaction() is now atomic at the builder level. It creates a nested checkpoint per transaction attempt, precomputes the minimal blob tx before execution, and restores builder counters/arrays on any error. That prevents partial state, blobGasUsed, and tx bookkeeping from diverging if something throws mid-flow.

Copilot AI review requested due to automatic review settings April 22, 2026 23:41
@codecov
Copy link
Copy Markdown

codecov Bot commented Apr 22, 2026

Codecov Report

❌ Patch coverage is 81.92771% with 15 lines in your changes missing coverage. Please review.
✅ Project coverage is 73.26%. Comparing base (b3ea7a4) to head (b2815c9).

Additional details and impacted files

Impacted file tree graph

Flag Coverage Δ
block 87.33% <ø> (ø)
blockchain 88.82% <ø> (ø)
common 93.44% <ø> (ø)
evm 61.22% <ø> (ø)
mpt 89.73% <ø> (+0.08%) ⬆️
statemanager 78.04% <ø> (ø)
static 91.35% <ø> (ø)
tx 88.06% <86.66%> (+0.04%) ⬆️
util 80.83% <ø> (ø)
vm 55.92% <79.24%> (+0.47%) ⬆️

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

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@github-actions
Copy link
Copy Markdown

github-actions Bot commented Apr 22, 2026

📦 Bundle Size Analysis

Package Size (min+gzip) Δ
binarytree 17.5 KB ⚪ ±0%
block 43.7 KB 🔴 +0.1 KB (+0.16%)
blockchain 69.8 KB 🔴 +0.1 KB (+0.12%)
common 25.4 KB ⚪ ±0%
devp2p 17.7 KB ⚪ ±0%
e2store 87.3 KB 🔴 +0.1 KB (+0.08%)
ethash 61.8 KB 🔴 +0.1 KB (+0.16%)
evm 62.5 KB ⚪ ±0%
genesis 272.2 KB ⚪ ±0%
mpt 21.9 KB ⚪ ±0%
rlp 1.7 KB ⚪ ±0%
statemanager 41.2 KB ⚪ ±0%
testdata 43.8 KB ⚪ ±0%
tx 20.8 KB 🔴 +0.1 KB (+0.46%)
util 13.2 KB ⚪ ±0%
vm 154.8 KB 🔴 +0.2 KB (+0.11%)
wallet 15.0 KB ⚪ ±0%

Values are minified+gzipped bundles of each package entry. Workspace deps are bundled; external deps are excluded.

Generated by bundle-size workflow

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Fixes a BlockBuilder atomicity bug and closes a fork-validation gap for EIP-4844/EIP-7594 blob transactions by validating fork-sensitive constraints earlier during network-wrapper deserialization and by making BlockBuilder.addTransaction() roll back cleanly on errors.

Changes:

  • Add fork-sensitive blob/network-wrapper validation during network-wrapper deserialization and reuse it in Blob4844Tx validation.
  • Refactor BlockBuilder.addTransaction() to be builder-atomic via per-transaction rollback + precomputing minimal blob tx.
  • Add regression tests for builder rollback behavior and pre-7594 deserialization rejection.

Reviewed changes

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

Show a summary per file
File Description
packages/vm/src/buildBlock.ts Makes addTransaction() atomic by checkpointing and rolling back builder accounting/state on failures.
packages/vm/test/api/buildBlock.spec.ts Adds regression test ensuring builder state is reverted when bookkeeping throws.
packages/tx/src/4844/tx.ts Factors fork/network-wrapper checks into a shared validator and reuses it in constructor/validation paths.
packages/tx/src/4844/constructors.ts Runs fork/network-wrapper validation during network-wrapper deserialization before mutating the decoded tx.
packages/tx/test/eip7594.spec.ts Adds regression coverage for rejecting EIP-7594 wrappers under pre-7594 Common and adjusts timeouts.

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

Comment thread packages/vm/test/api/buildBlock.spec.ts Outdated
Comment thread packages/vm/src/buildBlock.ts Outdated
ScottyPoi and others added 3 commits April 22, 2026 18:03
@ScottyPoi ScottyPoi marked this pull request as draft April 23, 2026 16:46
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