Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
998 changes: 447 additions & 551 deletions Cargo.lock

Large diffs are not rendered by default.

31 changes: 14 additions & 17 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,24 +23,24 @@ repository = "https://github.com/scroll-tech/stateless-block-verifier"

[workspace.dependencies]
# https://github.com/alloy-rs/alloy
alloy = { version = "1.0", default-features = false }
alloy-consensus = { version = "1.0", default-features = false }
alloy-eips = { version = "1.0", default-features = false }
alloy-network = { version = "1.0", default-features = false }
alloy-provider = { version = "1.0", default-features = false }
alloy-rpc-client = { version = "1.0", default-features = false }
alloy-rpc-types-eth = { version = "1.0", default-features = false }
alloy-rpc-types-debug = { version = "1.0", default-features = false }
alloy-serde = { version = "1.0", default-features = false }
alloy-transport = { version = "1.0", default-features = false }
alloy = { version = "1.0.30", default-features = false }
alloy-consensus = { version = "1.0.30", default-features = false }
alloy-eips = { version = "1.0.30", default-features = false }
alloy-network = { version = "1.0.30", default-features = false }
alloy-provider = { version = "1.0.30", default-features = false }
alloy-rpc-client = { version = "1.0.30", default-features = false }
alloy-rpc-types-eth = { version = "1.0.30", default-features = false }
alloy-rpc-types-debug = { version = "1.0.30", default-features = false }
alloy-serde = { version = "1.0.30", default-features = false }
alloy-transport = { version = "1.0.30", default-features = false }
# https://github.com/alloy-rs/rlp
alloy-rlp = { version = "0.3", default-features = false }
alloy-rlp = { version = "0.3.10", default-features = false }
# https://github.com/alloy-rs/trie
alloy-trie = { version = "0.9", default-features = false }
alloy-trie = { version = "0.9.1", default-features = false }
# https://github.com/alloy-rs/core
alloy-primitives = { version = "1.3", default-features = false, features = ["map-hashbrown", "map-fxhash"] }
alloy-primitives = { version = "1.3.1", default-features = false, features = ["map-hashbrown", "map-fxhash"] }
# https://github.com/alloy-rs/evm
alloy-evm = { version = "0.17", default-features = false }
alloy-evm = { version = "0.20.1", default-features = false }

revm-scroll = { git = "https://github.com/scroll-tech/scroll-revm", default-features = false }

Expand Down Expand Up @@ -83,7 +83,6 @@ scroll-alloy-network = { git = "https://github.com/scroll-tech/reth", branch = "
#scroll-alloy-network = { path = "../reth/crates/scroll/alloy/network", default-features = false }

openvm-ecc-guest = { git = "https://github.com/openvm-org/openvm.git", tag = "v1.4.0" }
openvm-keccak256 = { git = "https://github.com/openvm-org/openvm.git", tag = "v1.4.0" }
openvm-sha2 = { git = "https://github.com/openvm-org/openvm.git", tag = "v1.4.0" }
openvm-pairing = { git = "https://github.com/openvm-org/openvm.git", tag = "v1.4.0" }
openvm-k256 = { package = "k256", git = "https://github.com/openvm-org/openvm.git", tag = "v1.4.0" }
Expand All @@ -94,13 +93,11 @@ async-trait = "0.1"
auto_impl = "1.2"
console = "0.16"
futures = "0.3"
hashbrown = { version = "0.15", default-features = false }
indicatif = "0.18"
itertools = "0.14"
rkyv = "0.8"
rustc-hash = "2.1"
thiserror = "2.0"
tiny-keccak = "2.0"
url = ">=2.5.3"
rstest = "0.26"
cfg-if = "1.0"
Expand Down
73 changes: 3 additions & 70 deletions crates/core/src/executor/ethereum.rs
Original file line number Diff line number Diff line change
@@ -1,36 +1,19 @@
use crate::{EvmDatabase, VerificationError};
use sbv_kv::KeyValueStoreGet;
use sbv_precompile::PrecompileProvider;
use sbv_primitives::{
B256, Bytes,
chainspec::ChainSpec,
types::{
evm::precompiles::PrecompilesMap,
reth::{
evm::{
ConfigureEvm, Database, EthEvm, EthEvmConfig, EvmEnv, EvmFactory,
eth::EthEvmContext,
execute::Executor,
revm::{
Context, Inspector, MainBuilder, MainContext,
context::{
BlockEnv, CfgEnv, TxEnv,
result::{EVMError, HaltReason},
},
inspector::NoOpInspector,
},
},
evm::{ConfigureEvm, EthEvmConfig, execute::Executor},
execution_types::BlockExecutionOutput,
primitives::{Block, Receipt, RecoveredBlock},
},
revm::{SpecId, database::CacheDB, precompile::PrecompileSpecId},
revm::database::CacheDB,
},
};
use std::sync::Arc;

/// Ethereum-related EVM configuration with [`SbvEthEvmFactory`] as the factory.
pub type EvmConfig = EthEvmConfig<ChainSpec, SbvEthEvmFactory>;

/// EVM executor that handles the block.
#[derive(Debug)]
pub struct EvmExecutor<'a, CodeDb, BlockHashProvider> {
Expand Down Expand Up @@ -59,7 +42,7 @@ impl<CodeDb: KeyValueStoreGet<B256, Bytes>, BlockHashProvider: KeyValueStoreGet<
{
/// Handle the block with the given witness
pub fn execute(self) -> Result<BlockExecutionOutput<Receipt>, VerificationError> {
let provider = EvmConfig::new_with_evm_factory(self.chain_spec.clone(), SbvEthEvmFactory);
let provider = EthEvmConfig::new(self.chain_spec.clone());

let output = cycle_track!(
provider.executor(CacheDB::new(self.db)).execute(self.block),
Expand All @@ -69,53 +52,3 @@ impl<CodeDb: KeyValueStoreGet<B256, Bytes>, BlockHashProvider: KeyValueStoreGet<
Ok(output)
}
}

/// Factory producing [`EthEvm`].
#[derive(Debug, Default, Clone, Copy)]
#[non_exhaustive]
pub struct SbvEthEvmFactory;

impl EvmFactory for SbvEthEvmFactory {
type Evm<DB: Database, I: Inspector<EthEvmContext<DB>>> = EthEvm<DB, I, Self::Precompiles>;
type Context<DB: Database> = Context<BlockEnv, TxEnv, CfgEnv, DB>;
type Tx = TxEnv;
type Error<DBError: core::error::Error + Send + Sync + 'static> = EVMError<DBError>;
type HaltReason = HaltReason;
type Spec = SpecId;
type Precompiles = PrecompilesMap;

fn create_evm<DB: Database>(&self, db: DB, input: EvmEnv) -> Self::Evm<DB, NoOpInspector> {
let spec_id = input.cfg_env.spec;
EthEvm::new(
Context::mainnet()
.with_block(input.block_env)
.with_cfg(input.cfg_env)
.with_db(db)
.build_mainnet_with_inspector(NoOpInspector {})
.with_precompiles(PrecompileProvider::with_spec(
PrecompileSpecId::from_spec_id(spec_id),
)),
false,
)
}

fn create_evm_with_inspector<DB: Database, I: Inspector<Self::Context<DB>>>(
&self,
db: DB,
input: EvmEnv,
inspector: I,
) -> Self::Evm<DB, I> {
let spec_id = input.cfg_env.spec;
EthEvm::new(
Context::mainnet()
.with_block(input.block_env)
.with_cfg(input.cfg_env)
.with_db(db)
.build_mainnet_with_inspector(inspector)
.with_precompiles(PrecompileProvider::with_spec(
PrecompileSpecId::from_spec_id(spec_id),
)),
true,
)
}
}
4 changes: 2 additions & 2 deletions crates/core/src/executor/mod.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
#[cfg(not(feature = "scroll"))]
mod ethereum;
#[cfg(not(feature = "scroll"))]
pub use ethereum::{EvmConfig, EvmExecutor, SbvEthEvmFactory};
pub use ethereum::EvmExecutor;

#[cfg(feature = "scroll")]
mod scroll;
#[cfg(feature = "scroll")]
pub use scroll::{EvmConfig, EvmExecutor};
pub use scroll::EvmExecutor;
10 changes: 3 additions & 7 deletions crates/core/src/executor/scroll.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,15 @@ use sbv_primitives::{
chainspec::ChainSpec,
types::{
reth::{
evm::{ConfigureEvm, EthEvmConfig, RethReceiptBuilder},
evm::{ConfigureEvm, EthEvmConfig},
execution_types::BlockExecutionOutput,
primitives::{Block, EthPrimitives, Receipt, RecoveredBlock},
primitives::{Block, Receipt, RecoveredBlock},
},
revm::database::CacheDB,
},
};
use std::sync::Arc;

/// Ethereum-related EVM configuration.
pub type EvmConfig =
EthEvmConfig<ChainSpec, EthPrimitives, RethReceiptBuilder, sbv_precompile::PrecompileProvider>;

/// EVM executor that handles the block.
#[derive(Debug)]
pub struct EvmExecutor<'a, CodeDb, BlockHashProvider, CompressionRatios> {
Expand Down Expand Up @@ -60,7 +56,7 @@ impl<
revm::database::{State, states::bundle_state::BundleRetention},
};

let provider = EvmConfig::new(self.chain_spec.clone(), Default::default());
let provider = EthEvmConfig::scroll(self.chain_spec.clone());
let factory = provider.block_executor_factory();

let mut db = State::builder()
Expand Down
4 changes: 1 addition & 3 deletions crates/core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,7 @@ mod error;
pub use error::VerificationError;

mod executor;
#[cfg(not(feature = "scroll"))]
pub use executor::SbvEthEvmFactory;
pub use executor::{EvmConfig, EvmExecutor};
pub use executor::EvmExecutor;

pub mod verifier;

Expand Down
52 changes: 0 additions & 52 deletions crates/core/src/witness.rs
Original file line number Diff line number Diff line change
Expand Up @@ -237,55 +237,3 @@ impl BlockWitnessChunkExt for [BlockWitness] {
.all(|(a, b)| a.header.state_root == b.prev_state_root)
}
}

#[cfg(test)]
#[cfg(feature = "scroll")]
mod tests {
use super::*;
use std::{collections::BTreeSet, ffi::OsStr, path::PathBuf};

#[rstest::rstest]
fn serde_scroll_blocks_roundtrip(
#[files("../../testdata/scroll_witness/**/*.json")]
#[mode = path]
path: PathBuf,
) {
let file_content = std::fs::read_to_string(path).unwrap();
let witness: BlockWitness = serde_json::from_str(&file_content).unwrap();
let serialized = serde_json::to_string(&witness).unwrap();
let deserialized: BlockWitness = serde_json::from_str(&serialized).unwrap();
assert_eq!(witness, deserialized);
}

#[rstest::rstest]
fn serde_scroll_blocks_legacy_compatibility(
#[files("../../testdata/scroll_witness/**/*.json")]
#[mode = path]
path: PathBuf,
) {
let file_content = std::fs::read_to_string(&path).unwrap();
let witness: BlockWitness = serde_json::from_str(&file_content).unwrap();

let base_dir = path
.ancestors()
.find(|p| p.file_name().unwrap() == OsStr::new("testdata"))
.unwrap();
let filename = path.file_name().unwrap();
let harfork = path.parent().unwrap().file_name().unwrap();
let legacy_path = base_dir
.join("legacy")
.join("scroll_witness")
.join(harfork)
.join(filename);
let legacy_content = std::fs::read_to_string(legacy_path).unwrap();
let mut legacy_witness: sbv_primitives::legacy_types::BlockWitness =
serde_json::from_str(&legacy_content).unwrap();
legacy_witness.states = Vec::from_iter(BTreeSet::from_iter(legacy_witness.states));
legacy_witness.codes = Vec::from_iter(BTreeSet::from_iter(legacy_witness.codes));

let mut legacy_converted = witness.into_legacy();
legacy_converted.states = Vec::from_iter(BTreeSet::from_iter(legacy_converted.states));
legacy_converted.codes = Vec::from_iter(BTreeSet::from_iter(legacy_converted.codes));
assert_eq!(legacy_converted, legacy_witness);
}
}
4 changes: 1 addition & 3 deletions crates/kv/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,5 @@ workspace = true

[dependencies]
auto_impl.workspace = true
hashbrown = { workspace = true, features = [
"rayon",
] } # reth use rayon::IntoParallelIterator
alloy-primitives.workspace = true
rustc-hash.workspace = true
5 changes: 2 additions & 3 deletions crates/kv/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,12 @@ use auto_impl::auto_impl;
use std::{borrow::Borrow, hash::Hash};

mod imps;
pub use hashbrown;
pub use imps::{nohash, null};

/// HashMap
pub type HashMap<K, V, S = rustc_hash::FxBuildHasher> = hashbrown::HashMap<K, V, S>;
pub type HashMap<K, V, S = rustc_hash::FxBuildHasher> = alloy_primitives::map::HashMap<K, V, S>;
/// HashSet
pub type HashSet<V, S = rustc_hash::FxBuildHasher> = hashbrown::HashSet<V, S>;
pub type HashSet<V, S = rustc_hash::FxBuildHasher> = alloy_primitives::map::HashSet<V, S>;

/// Key-Value store insert trait
#[auto_impl(&mut, Box)]
Expand Down
16 changes: 3 additions & 13 deletions crates/precompile/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ repository.workspace = true
sbv-primitives = { workspace = true, features = ["evm-types", "revm-types"] }

openvm-ecc-guest = { workspace = true, optional = true }
openvm-keccak256 = { workspace = true, optional = true }
openvm-k256 = { workspace = true, optional = true }
openvm-sha2 = { workspace = true, optional = true }
openvm-pairing = { workspace = true, optional = true }
Expand All @@ -31,41 +30,32 @@ scroll = [
]
scroll-openvm = [
"scroll",
"openvm-bn128",
"openvm-bn254",
"openvm-sha256"
]
ethereum-openvm = [
"openvm-bn128",
"openvm-bn254",
"openvm-kzg",
"openvm-secp256k1",
"openvm-sha256",
]

bn128 = [] # marker, won't be used in dependencies
openvm-bn128 = [
"bn128",
openvm-bn254 = [
"dep:openvm-ecc-guest",
"dep:openvm-pairing",
"openvm-pairing/bn254",
]

kzg = [] # marker, won't be used in dependencies
openvm-kzg = [
"kzg",
"dep:openvm-kzg",
]

secp256k1 = [] # marker, won't be used in dependencies
openvm-secp256k1 = [
"secp256k1",
"dep:openvm-ecc-guest",
"dep:openvm-keccak256",
"dep:openvm-k256",
]

sha256 = []
openvm-sha256 = [
"sha256",
"dep:openvm-sha2"
]

Loading
Loading