Skip to content

fix: align L2 header fields between assemble and import paths#58

Merged
panos-xyz merged 2 commits intomainfrom
fix/l2-header-hash-alignment
Mar 26, 2026
Merged

fix: align L2 header fields between assemble and import paths#58
panos-xyz merged 2 commits intomainfrom
fix/l2-header-hash-alignment

Conversation

@panos-xyz
Copy link
Copy Markdown
Contributor

@panos-xyz panos-xyz commented Mar 25, 2026

Summary

Fixes a block hash mismatch between the assembleL2Block (assemble path) and newL2Block (import path) by ensuring both sides construct identical headers.

Root Causes

  1. mix_hash: MorphBlockAssembler used prevrandao() which can be non-zero, while the import side used B256::ZERO. Morph L2 always keeps mix_hash = 0 (confirmed from geth source).

  2. withdrawals_root / blob_gas_used / excess_blob_gas: Import side conditionally set these based on Shanghai/Cancun hardfork activation, but MorphBlockAssembler always emits None for all three (Morph L2 has no withdrawals or blob transactions). This caused a hash divergence on any network where Shanghai/Cancun is active.

Changes

  • crates/evm/src/assemble.rs: mix_hash: Default::default() (was prevrandao())
  • crates/engine-api/src/builder.rs:
    • withdrawals_root, blob_gas_used, excess_blob_gas → always None
    • Extract header_and_body_from_executable_data() helper
    • Remove unused EMPTY_WITHDRAWALS and EthereumHardforks imports

Test plan

  • cargo check -p morph-engine-api -p morph-evm passes
  • Existing unit tests pass
  • New block import via newL2Block no longer returns hash mismatch errors

Summary by CodeRabbit

  • Chores
    • Removed hardfork dependency and related code to streamline dependencies
    • Refactored block header and body assembly logic
    • Updated header field handling for consistent L2 block structure

- mix_hash fixed to zero in MorphBlockAssembler (matches geth L2 behavior)
- withdrawals_root/blob_gas_used/excess_blob_gas always None on import side
- extract header_and_body_from_executable_data() helper for clarity
- remove unused EMPTY_WITHDRAWALS and EthereumHardforks imports
@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Mar 25, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 74709ff2-e6c8-4951-94b5-46924ebb7a05

📥 Commits

Reviewing files that changed from the base of the PR and between b2275d4 and 8a7278c.

⛔ Files ignored due to path filters (1)
  • Cargo.lock is excluded by !**/*.lock
📒 Files selected for processing (3)
  • crates/engine-api/Cargo.toml
  • crates/engine-api/src/builder.rs
  • crates/evm/src/assemble.rs
💤 Files with no reviewable changes (1)
  • crates/engine-api/Cargo.toml

📝 Walkthrough

Walkthrough

The PR removes the alloy-hardforks dependency and refactors header/body construction in the engine-api builder to eliminate conditional logic based on hardfork timestamps. It also simplifies EVM block assembly by setting mix_hash to a constant zero value instead of deriving it from prevrandao.

Changes

Cohort / File(s) Summary
Dependency Cleanup
crates/engine-api/Cargo.toml
Removed the unused alloy-hardforks workspace dependency from the engine-api crate.
Builder Refactoring
crates/engine-api/src/builder.rs
Extracted header and body construction into a new helper function header_and_body_from_executable_data(); removed hardfork timestamp-based conditionals (shanghai_active, cancun_active); made withdrawals_root, blob_gas_used, and excess_blob_gas unconditional fields; added PartialEq derive to InMemoryHead.
EVM Assembly
crates/evm/src/assemble.rs
Changed mix_hash to always default to zero instead of deriving from evm_env.block_env.prevrandao().

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Possibly related PRs

Suggested reviewers

  • anylots
  • chengwenxi

Poem

🐰 A rabbit hops through Morph's code with glee,
Hardforks untangled, L2-only and free!
No Shanghai, no Cancun conditions to weigh—
Just clean, simple logic to brighten the day!

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely summarizes the main change: aligning L2 header fields between the assemble and import code paths to resolve block hash mismatches.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/l2-header-hash-alignment

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@panos-xyz panos-xyz requested review from anylots and chengwenxi March 25, 2026 11:06
Copy link
Copy Markdown
Contributor

@anylots anylots left a comment

Choose a reason for hiding this comment

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

It is recommended to add test coverage: ensure that corresponding unit tests and integration tests are included.

@panos-xyz
Copy link
Copy Markdown
Contributor Author

It is recommended to add test coverage: ensure that corresponding unit tests and integration tests are included.

Yeah, these issues were caught by the e2e tests in the subsequent PR, and there will be corresponding tests to cover them.

@panos-xyz panos-xyz merged commit 539cc25 into main Mar 26, 2026
9 checks passed
@panos-xyz panos-xyz deleted the fix/l2-header-hash-alignment branch March 26, 2026 06:45
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