Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

ethrex-replay

A tool for executing and proving Ethereum blocks, transactions, and L2 batches — inspired by starknet-replay. Currently ethrex replay only works against ethrex nodes with the debug_executionWitness RPC endpoint.

Features

L1

FeatureDescription
ethrex-replay blockReplay a single block.
ethrex-replay blocksReplay a list of specific block numbers, a range of blocks, or from a specific block to the latest (see ethrex-replay blocks --help)
ethrex-replay block-composition
ethrex-replay customBuild your block before to replay it.
ethrex-replay transactionReplay a single transaction of a block.
ethrex-replay cacheGenerate witness data prior to block replay (see ethrex-replay cache --help)

L2

FeatureDescription
ethrex-replay l2 batch
ethrex-replay l2 block
ethrex-replay l2 custom
ethrex-replay l2 transaction

Supported Clients

✅: supported. ⚠️: supported, but flaky. 🔜: to be supported.

ClientHoodiSepoliaMainnetPublic ethrex L2s
ethrex
reth-
geth-
Nethermind⚠️⚠️⚠️-
erigon🔜🔜🔜-

Supported zkVM Replays (execution & proving)

✅: supported. ⚠️: supported, but flaky. 🔜: to be supported.

zkVMHoodiSepoliaMainnetPublic ethrex L2s
RISC0🔜
SP1🔜
OpenVM⚠️🔜🔜🔜
ZisK🔜🔜⚠️🔜
Jolt🔜🔜🔜🔜
Nexus🔜🔜🔜🔜
Pico🔜🔜🔜🔜
Ziren🔜🔜🔜🔜

Getting Started

Dependencies

RISC0

curl -L https://risczero.com/install | bash
rzup install cargo-risczero 3.0.3
rzup install risc0-groth16
rzup install rust

SP1

curl -L https://sp1up.succinct.xyz | bash
sp1up --version 5.0.8

Installation

From Cargo

# L1 Replay

## Install without features for vanilla execution (no prover backend)
cargo install --locked --git https://github.com/lambdaclass/ethrex.git ethrex-replay

## Install for CPU execution/proving with SP1
cargo install --locked --git https://github.com/lambdaclass/ethrex.git ethrex-replay --features sp1

## Install for CPU execution/proving with RISC0
cargo install --locked --git https://github.com/lambdaclass/ethrex.git ethrex-replay --features risc0

## Install for GPU execution/proving with SP1
cargo install --locked --git https://github.com/lambdaclass/ethrex.git ethrex-replay --features sp1,gpu

## Install for GPU execution/proving with RISC0
cargo install --locked --git https://github.com/lambdaclass/ethrex.git ethrex-replay --features risc0,gpu

# L2 Replay

## Install without features for vanilla execution (no prover backend)
cargo install --locked --git https://github.com/lambdaclass/ethrex.git ethrex-replay --features l2

## Install for CPU execution/proving with SP1
cargo install --locked --git https://github.com/lambdaclass/ethrex.git ethrex-replay --features l2,sp1

## Install for CPU execution/proving with RISC0
cargo install --locked --git https://github.com/lambdaclass/ethrex.git ethrex-replay --features l2,risc0

## Install for GPU execution/proving with SP1
cargo install --locked --git https://github.com/lambdaclass/ethrex.git ethrex-replay --features l2,sp1,gpu

## Install for GPU execution/proving with RISC0
cargo install --locked --git https://github.com/lambdaclass/ethrex.git ethrex-replay --features l2,risc0,gpu

Run from Source

git clone git@github.com:lambdaclass/ethrex.git

cd ethrex

# L1 replay

## Vanilla execution (no prover backend)
cargo r -r -p ethrex-replay -- <COMMAND> [ARGS]

## SP1 backend
cargo r -r -p ethrex-replay --features sp1 -- <COMMAND> [ARGS]

## SP1 backend + GPU
cargo r -r -p ethrex-replay --features sp1,gpu -- <COMMAND> [ARGS]

## RISC0 backend
cargo r -r -p ethrex-replay --features risc0 -- <COMMAND> [ARGS]

## RISC0 backend + GPU
cargo r -r -p ethrex-replay --features risc0,gpu -- <COMMAND> [ARGS]

# L2 replay

## Vanilla execution (no prover backend)
cargo r -r -p ethrex-replay --features l2 -- <COMMAND> [ARGS]

## SP1 backend
cargo r -r -p ethrex-replay --features l2,sp1 -- <COMMAND> [ARGS]

## SP1 backend + GPU
SP1_PROVER=cuda cargo r -r -p ethrex-replay --features l2,sp1,gpu -- <COMMAND> [ARGS]

## RISC0 backend
cargo r -r -p ethrex-replay --features l2,risc0 -- <COMMAND> [ARGS]

## RISC0 backend + GPU
cargo r -r -p ethrex-replay --features l2,risc0,gpu -- <COMMAND> [ARGS]

Features

The following table lists the available features for ethrex-replay. To enable a feature, use the --features flag with cargo install, specifying a comma-separated list of features.

FeatureDescription
gpuEnables GPU support with SP1 or RISC0 backends (must be combined with one of each features, e.g. sp1,gpu or risc0,gpu)
risc0Execution and proving is done with RISC0 backend
sp1Execution and proving is done with SP1 backend
l2Enables L2 batch execution and proving (can be combined with SP1 or RISC0 and GPU features, e.g. sp1,l2,gpu, risc0,l2,gpu, sp1,l2, risc0,l2)
jemallocUse jemalloc as the global allocator. This is useful to combine with tools like Bytehound and Heaptrack for memory profiling
profilingUseful to run with tools like Samply.

Running Examples

Examples ToC

important

The following instructions assume that you've installed ethrex-replay as described in the Getting Started section.

Execute a single block from a public network

note

  1. If BLOCK_NUMBER is not provided, the latest block will be executed.
  2. If ZKVM is not provided, no zkVM will be used for execution.
  3. If RESOURCE is not provided, CPU will be used for execution.
  4. If ACTION is not provided, only execution will be performed.
ethrex-replay block <BLOCK_NUMBER> --zkvm <ZKVM> --resource <RESOURCE> --action <ACTION> --rpc-url <RPC_URL>

Prove a single block

note

  1. If BLOCK_NUMBER is not provided, the latest block will be executed and proved.
  2. Proving requires a prover backend to be enabled during installation (e.g., sp1 or risc0).
  3. Proving with GPU requires the gpu feature to be enabled during installation.
  4. If proving with SP1, add SP1_PROVER=cuda to the command to enable GPU support.
ethrex-replay block <BLOCK_NUMBER> --zkvm <ZKVM> --resource gpu --action prove --rpc-url <RPC_URL>

Execute an L2 batch

ethrex-replay l2 batch --batch <BATCH_NUMBER> --execute --rpc-url <RPC_URL>

Prove an L2 batch

note

  1. Proving requires a prover backend to be enabled during installation (e.g., sp1 or risc0). Proving with GPU requires the gpu feature to be enabled during installation.
  2. If proving with SP1, add SP1_PROVER=cuda to the command to enable GPU support.
  3. Batch replay requires the binary to be run/compiled with the l2 feature.
ethrex-replay l2 batch --batch <BATCH_NUMBER> --prove --rpc-url <RPC_URL>

Execute a transaction

note

L2 transaction replay requires the binary to be run/compiled with the l2 feature.

ethrex-replay transaction <TX_HASH> --execute --rpc-url <RPC_URL>

ethrex-replay l2 transaction <TX_HASH> --execute --rpc-url <RPC_URL>

Plot block composition

ethrex-replay block-composition --start-block <START_BLOCK> --end-block <END_BLOCK> --rpc-url <RPC_URL> --network <NETWORK>

Benchmarking & Profiling

Run Samply

On zkVMs

important

  1. For profiling zkVMs like SP1 the ethrex-replay binary must be built with the profiling feature enabled.
  2. The TRACE_SAMPLE_RATE environment variable controls the sampling rate (in milliseconds). Adjust it according to your needs.
TRACE_FILE=output.json TRACE_SAMPLE_RATE=1000 ethrex-replay <COMMAND> [ARGS]

Execution without zkVMs

We recommend building in release-with-debug mode so that the flamegraph is the most accurate.

cargo build -p ethrex-replay --profile release-with-debug
samply record target/release-with-debug/ethrex-replay <COMMAND> [ARGS]

Run Bytehound

important

  1. The following requires Jemalloc and Bytehound to be installed.
  2. The ethrex-replay binary must be built with the jemalloc feature enabled.
export MEMORY_PROFILER_LOG=warn
LD_PRELOAD=/path/to/bytehound/preload/target/release/libbytehound.so:/path/to/libjemalloc.so  ethrex-replay <COMMAND> [ARGS]

Run Heaptrack

important

  1. The following requires Jemalloc and Heaptrack to be installed.
  2. The ethrex-replay binary must be built with the jemalloc feature enabled.
LD_PRELOAD=/path/to/libjemalloc.so heaptrack ethrex-replay <COMMAND> [ARGS]
heaptrack_print heaptrack.<program>.<pid>.gz > heaptrack.stacks

Check All Available Commands

Run:

cargo r -r -p ethrex-replay -- --help