Skip to content

STR-1308: EVM state diff(snapshot) prototype #800

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 21 commits into from
May 21, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
7e10bf7
Implement a prototype of EE batch state diff.
evgenyzdanovich Apr 30, 2025
8901eab
Implement exex for EE state diff generation.
evgenyzdanovich Apr 30, 2025
20b236b
Implement an RPC to fetch block state diff.
evgenyzdanovich Apr 30, 2025
8285495
Implement StateDiff traits for DB.
evgenyzdanovich Apr 30, 2025
cd50dba
Use state diff as an exex in alpen-reth, guarded by the config flag.
evgenyzdanovich Apr 30, 2025
c53f4c1
Implement unit tests for state diff DB table.
evgenyzdanovich May 1, 2025
d58a305
Add basic fntest for state diff.
evgenyzdanovich May 5, 2025
1d706c7
Fmt and other small fixes.
evgenyzdanovich May 5, 2025
809f448
Add unit tests for state diff.
evgenyzdanovich May 6, 2025
5ded8f6
Introduce a separate BatchStateDiff builder for a cleaner interface.
evgenyzdanovich May 13, 2025
7b1b4aa
Factor our mpt into its own separate crate.
evgenyzdanovich May 14, 2025
d748d63
Use strata-mpt in the evm-ee-stf.
evgenyzdanovich May 14, 2025
c223321
Basic interative state reconstruction from batch state diffs.
evgenyzdanovich May 14, 2025
9bd8563
Extend exex DB with number to hash mapping to facilitate easier testing.
evgenyzdanovich May 14, 2025
222dbc9
Expose an additional RPC that reconstructs and returns the block stat…
evgenyzdanovich May 14, 2025
5496eeb
Minor fixes
evgenyzdanovich May 14, 2025
c9025a7
Prettify structure, factor out pieces.
evgenyzdanovich May 16, 2025
06c74f7
Split out chainspec into a separate microcrate and use it in statedif…
evgenyzdanovich May 18, 2025
3f45638
Add fntests for state reconstructure from state diffs using load gen …
evgenyzdanovich May 18, 2025
2f573bf
Minor review fixes.
evgenyzdanovich May 18, 2025
1edbb1d
Fix chain configs path in the fntests.
evgenyzdanovich May 18, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 50 additions & 8 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,14 @@ members = [
"crates/evmexec",
"crates/key-derivation",
"crates/l1tx",
"crates/mpt",
"crates/primitives",
"crates/proof-impl/btc-blockspace",
"crates/proof-impl/checkpoint",
"crates/proof-impl/cl-stf",
"crates/proof-impl/evm-ee-stf",
"crates/zkvm/hosts",
"crates/reth/chainspec",
"crates/reth/db",
"crates/reth/evm",
"crates/reth/exex",
Expand Down Expand Up @@ -65,12 +67,14 @@ default-members = [
resolver = "2"

[workspace.dependencies]
alpen-chainspec = { path = "crates/reth/chainspec" }
alpen-reth-db = { path = "crates/reth/db" }
alpen-reth-evm = { path = "crates/reth/evm" }
alpen-reth-exex = { path = "crates/reth/exex" }
alpen-reth-node = { path = "crates/reth/node" }
alpen-reth-primitives = { path = "crates/reth/primitives" }
alpen-reth-rpc = { path = "crates/reth/rpc" }
alpen-reth-statediff = { path = "crates/reth/statediff" }
strata-btcio = { path = "crates/btcio" }
strata-chaintsn = { path = "crates/chaintsn" }
strata-common = { path = "crates/common" }
Expand All @@ -83,6 +87,7 @@ strata-evmexec = { path = "crates/evmexec" }
strata-key-derivation = { path = "crates/key-derivation" }
strata-l1tx = { path = "crates/l1tx" }
strata-mmr = { path = "crates/util/mmr" }
strata-mpt = { path = "crates/mpt" }
strata-primitives = { path = "crates/primitives" }
strata-proofimpl-btc-blockspace = { path = "crates/proof-impl/btc-blockspace" }
strata-proofimpl-checkpoint = { path = "crates/proof-impl/checkpoint" }
Expand Down
9 changes: 1 addition & 8 deletions bin/alpen-reth/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,31 +8,24 @@ name = "alpen-reth"
path = "src/main.rs"

[dependencies]
alpen-chainspec.workspace = true
alpen-reth-db.workspace = true
alpen-reth-exex.workspace = true
alpen-reth-node.workspace = true
alpen-reth-rpc.workspace = true

alloy-genesis.workspace = true
alloy-rpc-types.workspace = true
async-trait.workspace = true
clap.workspace = true
eyre.workspace = true
hex.workspace = true
jsonrpsee-types.workspace = true
reqwest.workspace = true
reth.workspace = true
reth-chainspec.workspace = true
reth-cli.workspace = true
reth-cli-commands.workspace = true
reth-cli-util.workspace = true
reth-db.workspace = true
reth-primitives.workspace = true
reth-provider.workspace = true
reth-rpc-eth-api.workspace = true
reth-rpc-eth-types.workspace = true
rockbound.workspace = true
serde_json.workspace = true
shellexpand = "3.0.0"
thiserror.workspace = true
tracing.workspace = true
88 changes: 24 additions & 64 deletions bin/alpen-reth/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
mod db;

use std::{fs, future::Future, path::PathBuf, sync::Arc};
use std::{future::Future, sync::Arc};

use alloy_genesis::Genesis;
use alpen_chainspec::{chain_value_parser, StrataChainSpecParser};
use alpen_reth_db::rocksdb::WitnessDB;
use alpen_reth_exex::ProverWitnessGenerator;
use alpen_reth_exex::{ProverWitnessGenerator, StateDiffGenerator};
use alpen_reth_node::{args::StrataNodeArgs, StrataEthereumNode};
use alpen_reth_rpc::{StrataRPC, StrataRpcApiServer};
use clap::Parser;
Expand All @@ -14,14 +14,9 @@
CliRunner,
};
use reth_chainspec::ChainSpec;
use reth_cli::chainspec::ChainSpecParser;
use reth_cli_commands::node::NodeCommand;
use tracing::info;

const DEFAULT_CHAIN_SPEC: &str = include_str!("../res/testnet-chain.json");
const DEVNET_CHAIN_SPEC: &str = include_str!("../res/devnet-chain.json");
const DEV_CHAIN_SPEC: &str = include_str!("../res/alpen-dev-chain.json");

fn main() {
reth_cli_util::sigsegv_handler::install();

Expand All @@ -48,17 +43,27 @@

let mut extend_rpc = None;

// Install Prover Input ExEx, persist to DB, and add RPC for querying block witness.
if ext.enable_witness_gen {
if ext.enable_witness_gen || ext.enable_state_diff_gen {

Check warning on line 46 in bin/alpen-reth/src/main.rs

View check run for this annotation

Codecov / codecov/patch

bin/alpen-reth/src/main.rs#L46

Added line #L46 was not covered by tests
let rbdb = db::open_rocksdb_database(datadir.clone()).expect("open rocksdb");
let db = Arc::new(WitnessDB::new(rbdb));
let rpc_db = db.clone();

extend_rpc.replace(StrataRPC::new(rpc_db));
// Add RPC for querying block witness and state diffs.
extend_rpc.replace(StrataRPC::new(db.clone()));

// Install Prover Input ExEx and persist to DB
if ext.enable_witness_gen {
let witness_db = db.clone();
node_builder = node_builder.install_exex("prover_input", |ctx| async {
Ok(ProverWitnessGenerator::new(ctx, witness_db).start())
});
}

Check warning on line 58 in bin/alpen-reth/src/main.rs

View check run for this annotation

Codecov / codecov/patch

bin/alpen-reth/src/main.rs#L49-L58

Added lines #L49 - L58 were not covered by tests

node_builder = node_builder.install_exex("prover_input", |ctx| async {
Ok(ProverWitnessGenerator::new(ctx, db).start())
});
// Install State Diff ExEx and persist to DB
if ext.enable_state_diff_gen {
let state_diff_db = db.clone();
node_builder = node_builder.install_exex("state_diffs", |ctx| async {
Ok(StateDiffGenerator::new(ctx, state_diff_db).start())
});
}

Check warning on line 66 in bin/alpen-reth/src/main.rs

View check run for this annotation

Codecov / codecov/patch

bin/alpen-reth/src/main.rs#L61-L66

Added lines #L61 - L66 were not covered by tests
}

// Note: can only add single hook
Expand Down Expand Up @@ -100,59 +105,14 @@
#[arg(long, default_value_t = false)]
pub enable_witness_gen: bool,

#[arg(long, default_value_t = false)]
pub enable_state_diff_gen: bool,

Check warning on line 109 in bin/alpen-reth/src/main.rs

View check run for this annotation

Codecov / codecov/patch

bin/alpen-reth/src/main.rs#L108-L109

Added lines #L108 - L109 were not covered by tests

/// Rpc of sequener's reth node to forward transactions to.
#[arg(long, required = false)]
pub sequencer_http: Option<String>,
}

#[derive(Debug, Clone, Default)]
#[non_exhaustive]
pub struct StrataChainSpecParser;

impl ChainSpecParser for StrataChainSpecParser {
type ChainSpec = ChainSpec;

const SUPPORTED_CHAINS: &'static [&'static str] = &["dev", "devnet", "testnet"];

fn parse(s: &str) -> eyre::Result<Arc<Self::ChainSpec>> {
chain_value_parser(s)
}
}

pub fn chain_value_parser(s: &str) -> eyre::Result<Arc<ChainSpec>, eyre::Error> {
Ok(match s {
"testnet" => parse_chain_spec(DEFAULT_CHAIN_SPEC)?,
"devnet" => parse_chain_spec(DEVNET_CHAIN_SPEC)?,
"dev" => parse_chain_spec(DEV_CHAIN_SPEC)?,
_ => {
// try to read json from path first
let raw = match fs::read_to_string(PathBuf::from(shellexpand::full(s)?.into_owned())) {
Ok(raw) => raw,
Err(io_err) => {
// valid json may start with "\n", but must contain "{"
if s.contains('{') {
s.to_string()
} else {
return Err(io_err.into()); // assume invalid path
}
}
};

// both serialized Genesis and ChainSpec structs supported
let genesis: Genesis = serde_json::from_str(&raw)?;

Arc::new(genesis.into())
}
})
}

fn parse_chain_spec(chain_json: &str) -> eyre::Result<Arc<ChainSpec>> {
// both serialized Genesis and ChainSpec structs supported
let genesis: Genesis = serde_json::from_str(chain_json)?;

Ok(Arc::new(genesis.into()))
}

/// Run node with logging
/// based on reth::cli::Cli::run
fn run<L, Fut>(
Expand Down
1 change: 1 addition & 0 deletions bin/datatool/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ name = "strata-datatool"
path = "src/main.rs"

[dependencies]
alpen-chainspec.workspace = true
strata-key-derivation.workspace = true
strata-primitives.workspace = true
strata-risc0-guest-builder = { path = "../../provers/risc0", optional = true }
Expand Down
2 changes: 1 addition & 1 deletion bin/datatool/src/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ const OPKEY_ENVVAR: &str = "STRATA_OP_KEY";
const DEFAULT_NETWORK: Network = Network::Signet;

/// The default evm chainspec to use in params.
const DEFAULT_CHAIN_SPEC: &str = include_str!("../../alpen-reth/res/alpen-dev-chain.json");
const DEFAULT_CHAIN_SPEC: &str = alpen_chainspec::DEV_CHAIN_SPEC;

/// Resolves a [`Network`] from a string.
pub(super) fn resolve_network(arg: Option<&str>) -> anyhow::Result<Network> {
Expand Down
19 changes: 19 additions & 0 deletions crates/mpt/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
[package]
description = "Implementation of the Merkle-Patricia Trie"
edition = "2021"
name = "strata-mpt"
version = "0.1.0"

[dependencies]
alloy-rlp.workspace = true
alloy-rlp-derive.workspace = true
alloy-rpc-types-eth.workspace = true

anyhow.workspace = true
revm-primitives.workspace = true
rlp = "0.5.2"
serde.workspace = true
thiserror.workspace = true

[dev-dependencies]
hex-literal = "0.4"
File renamed without changes.
1 change: 1 addition & 0 deletions crates/proof-impl/evm-ee-stf/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ version = "0.3.0-alpha.1"
[dependencies]
alpen-reth-evm.workspace = true
alpen-reth-primitives.workspace = true
strata-mpt.workspace = true
strata-primitives.workspace = true
strata-state.workspace = true
zkaleido.workspace = true
Expand Down
Loading
Loading