Skip to content

Conversation

rauljordan
Copy link
Contributor

@rauljordan rauljordan commented Jul 7, 2025

This PR creates a functional replay binary for MEL (the message extraction layer) of Arbitrum nodes. Here's how it works:

  1. Start with an initial MEL state and an ending parent chain block hash (this is agreed upon by parties in a dispute)
  2. Fetch all block hashes from startMelState.BlockHash to EndParentChainBlockHash by walking backwards over block header parent linkages
  3. For each block header, run the ExtractMessages function which will produce a new MEL state
  4. Set the MELStateRoot in wavmio of the machine executing the MEL replay binary at the end

Other changes

  • Arbitrator machine has been changed to add a new field MELStateRoot to its global state. We do not modify the hash() or serialize() methods in order to not break existing code. This will require an arbos upgrade once we touch those two methods
  • We add a new WAVM opcode called GetEndParentChainBlockHash which gets us the ending block hash of a MEL machine execution
  • New flags are added to replay binary machine generation: --until-hostio-bin-filename="mel-until-host-io-state.bin" --brotli-wavm-machine-filename="mel_machine.wavm.br" --module-root-filename="mel_module_root.txt" which have defaults for the existing replay binary but can be changed when generating a MEL replay binary

Testing

In a following PR, we will introduce a testing utility that can run this MEL replay binary for verification and include automated tests. Adding that to this PR would increase the code diff significantly and also requires more changes from #3174 before it works perfectly

Submodule Updates

This PR also updates to Bold's main branch, which includes a change to a global state struct within it to include the MELRoot

Resolves NIT-3320

@rauljordan rauljordan marked this pull request as ready for review July 7, 2025 20:15
Copy link
Contributor

@Copilot 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

This PR adds a fully functional MEL replay binary, integrating new WAVM I/O bindings, a specialized CLI, and corresponding prover support to track and replay MEL state across a range of blocks.

  • Introduces stub (non-WASM) and WASM import bindings for MEL I/O, including a new GetEndParentChainBlockHash opcode
  • Implements cmd/mel-replay to walk backward through blocks and extract messages into a final MEL state
  • Extends the arbitrator prover with a third global-state slot for MEL state root, host I/O support, and updated binary-generation targets

Reviewed Changes

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

Show a summary per file
File Description
wavmio/mel/stub.go Added non-WASM stub I/O (flags, preimage map)
wavmio/mel/raw.go Added WASM imports for MEL stub functions
wavmio/mel/higher.go Implemented higher-level wrappers for WASM MEL I/O
cmd/mel-replay/main.go New MEL replay CLI and message-extraction loop
arbitrator/wasm-libraries/host-io/src/lib.rs Added wavmio__getEndParentChainBlockHash host function
arbitrator/prover/src/wavm.rs Introduced GetEndParentChainBlockHash opcode
arbitrator/prover/src/prepare.rs Extended global-state byte array length from 2 to 3
arbitrator/prover/src/parse_input.rs Added mel_root and end_parent_chain_block_hash to JSON parsing
arbitrator/prover/src/main.rs Added --mel-state-root flag and binary-generation filename flags
arbitrator/prover/src/machine.rs Expanded GLOBAL_STATE_BYTES32_NUM to 3; added opcode handler and field
arbitrator/prover/src/host.rs Mapped new opcode in the prover host I/O enum
Makefile Added targets and variables for MEL replay WASM and machine artifacts
Comments suppressed due to low confidence (5)

arbitrator/prover/src/parse_input.rs:80

  • [nitpick] The JSON field mel_root does not match the CLI flag name mel_state_root. Consider renaming for consistency or documenting the difference clearly.
    pub mel_root: Vec<u8>,

cmd/mel-replay/main.go:60

  • [nitpick] The error message lacks context about which hash failed. Consider including the startMelRoot or the hash value in the formatted error to aid debugging.
		panic(fmt.Errorf("error resolving preimage: %w", err))

wavmio/mel/stub.go:64

  • [nitpick] The error does not include the missing hash, which makes troubleshooting harder. You could wrap the hash in the error, e.g., fmt.Errorf("preimage not found for %s", hash.Hex()).
		return []byte{}, errors.New("preimage not found")

wavmio/mel/higher.go:22

  • The readBuffer helper contains nontrivial logic for dynamically resizing and reading chunks; consider adding unit tests to validate its behavior across boundary conditions.
func readBuffer(f func(uint32, unsafe.Pointer) uint32) []byte {

arbitrator/prover/src/main.rs:72

  • [nitpick] The new CLI flag --mel-state-root lacks a help description. Add a doc comment (e.g., /// Hex-encoded initial MEL state root) to clarify its purpose.
    #[structopt(long)]

@rauljordan rauljordan assigned rauljordan and unassigned eljobe Jul 7, 2025
@rauljordan
Copy link
Contributor Author

Investigating why CI fails

@rauljordan rauljordan assigned eljobe and unassigned rauljordan Jul 8, 2025
@rauljordan rauljordan assigned rauljordan and unassigned eljobe Jul 8, 2025
Copy link
Contributor

@tsahee tsahee left a comment

Choose a reason for hiding this comment

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

initial

setGlobalStateBytes32(IDX_MEL_ROOT, hashUnsafe)
}

func ResolveTypedPreimage(ty arbutil.PreimageType, hash common.Hash) ([]byte, error) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Why do you not use the existing wavmio functions for that?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Mostly because of the stub functions, which will read some flags and load into an in-memory map when run natively

@tsahee tsahee assigned rauljordan and unassigned tsahee Jul 18, 2025
Copy link

codecov bot commented Jul 31, 2025

Codecov Report

❌ Patch coverage is 0% with 10 lines in your changes missing coverage. Please review.
✅ Project coverage is 22.71%. Comparing base (16c01f8) to head (9477576).

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #3382      +/-   ##
==========================================
+ Coverage   22.67%   22.71%   +0.03%     
==========================================
  Files         383      383              
  Lines       58109    58111       +2     
==========================================
+ Hits        13177    13198      +21     
+ Misses      42903    42885      -18     
+ Partials     2029     2028       -1     
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@rauljordan rauljordan assigned tsahee and unassigned rauljordan Jul 31, 2025
@tsahee tsahee assigned rauljordan and unassigned tsahee Sep 16, 2025
@rauljordan rauljordan assigned tsahee and unassigned rauljordan Sep 23, 2025
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.

3 participants