Skip to content
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

feat: add EIP-7702 tx support #85

Merged
merged 12 commits into from
Feb 18, 2025
Merged
Show file tree
Hide file tree
Changes from 9 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
1,955 changes: 717 additions & 1,238 deletions Cargo.lock

Large diffs are not rendered by default.

61 changes: 33 additions & 28 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ members = [
"crates/sbv",
"crates/trie",
"crates/utils",
"crates/utils-cli",
]
resolver = "2"

Expand All @@ -22,33 +23,39 @@ repository = "https://github.com/scroll-tech/stateless-block-verifier"

[workspace.dependencies]
# https://github.com/alloy-rs/alloy
alloy = { version = "0.8", default-features = false }
alloy-consensus = { version = "0.8", default-features = false }
alloy-eips = { version = "0.8", default-features = false }
alloy-provider = { version = "0.8", default-features = false }
alloy-rpc-types-eth = { version = "0.8", default-features = false }
alloy-serde = { version = "0.8", default-features = false }
alloy-transport = { version = "0.8", default-features = false }
alloy = { version = "0.11", default-features = false }
alloy-consensus = { version = "0.11", default-features = false }
alloy-eips = { version = "0.11", default-features = false }
alloy-network = { version = "0.11", default-features = false }
alloy-provider = { version = "0.11", default-features = false }
alloy-rpc-types-eth = { version = "0.11", default-features = false }
alloy-serde = { version = "0.11", default-features = false }
alloy-transport = { version = "0.11", default-features = false }
# https://github.com/alloy-rs/rlp
alloy-rlp = { version = "0.3", default-features = false }
# https://github.com/alloy-rs/trie
alloy-trie = { version = "0.7", default-features = false }
# https://github.com/alloy-rs/core
alloy-primitives = { version = "0.8", default-features = false, features = ["map-hashbrown", "map-fxhash", "rkyv"] }

reth-chainspec = { git = "https://github.com/scroll-tech/reth", branch = "fix/scroll", default-features = false }
reth-evm = { git = "https://github.com/scroll-tech/reth", branch = "fix/scroll", default-features = false }
reth-evm-ethereum = { git = "https://github.com/scroll-tech/reth", branch = "fix/scroll", default-features = false }
reth-execution-types = { git = "https://github.com/scroll-tech/reth", branch = "fix/scroll", default-features = false }
reth-primitives = { git = "https://github.com/scroll-tech/reth", branch = "fix/scroll", default-features = false }
reth-scroll-chainspec = { git = "https://github.com/scroll-tech/reth", branch = "fix/scroll", default-features = false }
reth-scroll-evm = { git = "https://github.com/scroll-tech/reth", branch = "fix/scroll", default-features = false }
reth-scroll-primitives = { git = "https://github.com/scroll-tech/reth", branch = "fix/scroll", default-features = false }
reth-scroll-revm = { git = "https://github.com/scroll-tech/reth", branch = "fix/scroll", default-features = false }
reth-scroll-storage = { git = "https://github.com/scroll-tech/reth", branch = "fix/scroll", default-features = false }
reth-storage-errors = { git = "https://github.com/scroll-tech/reth", branch = "fix/scroll", default-features = false }
reth-trie = { git = "https://github.com/scroll-tech/reth", branch = "fix/scroll", default-features = false }
reth-trie-sparse = { git = "https://github.com/scroll-tech/reth", branch = "fix/scroll", default-features = false }
reth-chainspec = { git = "https://github.com/scroll-tech/reth", branch = "scroll", default-features = false }
reth-evm = { git = "https://github.com/scroll-tech/reth", branch = "scroll", default-features = false }
reth-evm-ethereum = { git = "https://github.com/scroll-tech/reth", branch = "scroll", default-features = false }
reth-execution-types = { git = "https://github.com/scroll-tech/reth", branch = "scroll", default-features = false }
reth-primitives = { git = "https://github.com/scroll-tech/reth", branch = "scroll", default-features = false }
reth-primitives-traits = { git = "https://github.com/scroll-tech/reth", branch = "scroll", default-features = false }
reth-storage-errors = { git = "https://github.com/scroll-tech/reth", branch = "scroll", default-features = false }
reth-trie = { git = "https://github.com/scroll-tech/reth", branch = "scroll", default-features = false }
reth-trie-sparse = { git = "https://github.com/scroll-tech/reth", branch = "scroll", default-features = false }

reth-scroll-chainspec = { git = "https://github.com/scroll-tech/reth", branch = "scroll", default-features = false }
reth-scroll-evm = { git = "https://github.com/scroll-tech/reth", branch = "scroll", default-features = false }
reth-scroll-primitives = { git = "https://github.com/scroll-tech/reth", branch = "scroll", default-features = false }

scroll-alloy-consensus = { git = "https://github.com/scroll-tech/reth", branch = "scroll", default-features = false }
scroll-alloy-primitives = { git = "https://github.com/scroll-tech/reth", branch = "scroll", default-features = false }
scroll-alloy-rpc-types = { git = "https://github.com/scroll-tech/reth", branch = "scroll", default-features = false }
scroll-alloy-network = { git = "https://github.com/scroll-tech/reth", branch = "scroll", default-features = false }

#reth-chainspec = { path = "../reth/crates/chainspec", default-features = false }
#reth-evm = { path = "../reth/crates/evm/", default-features = false }
Expand All @@ -58,15 +65,14 @@ reth-trie-sparse = { git = "https://github.com/scroll-tech/reth", branch = "fix/
#reth-scroll-chainspec = { path = "../reth/crates/scroll/chainspec", default-features = false }
#reth-scroll-evm = { path = "../reth/crates/scroll/evm", default-features = false }
#reth-scroll-primitives = { path = "../reth/crates/scroll/primitives", default-features = false }
#reth-scroll-revm = { path = "../reth/crates/scroll/revm", default-features = false }
#reth-scroll-storage = { path = "../reth/crates/scroll/storage", default-features = false }
#reth-storage-errors = { path = "../reth/crates/storage/errors", default-features = false }
#reth-trie = { path = "../reth/crates/trie/trie", default-features = false }
#reth-trie-sparse = { path = "../reth/crates/trie/sparse", default-features = false }

async-trait = "0.1"
auto_impl = "1.2"
console = "0.15"
futures = "0.3"
hashbrown = { version = "0.15", default-features = false }
indicatif = "0.17"
itertools = "0.14"
Expand All @@ -81,7 +87,6 @@ url = ">=2.5.3"
# binary dependencies
anyhow = "1.0"
clap = "4"
futures = "0.3"
serde = "1.0"
serde_json = "1.0"
serde_path_to_error = "0.1"
Expand Down Expand Up @@ -113,7 +118,7 @@ sbv-utils = { path = "crates/utils" }

[workspace.dependencies.revm]
git = "https://github.com/scroll-tech/revm"
branch = "scroll-evm-executor/v50"
branch = "scroll-evm-executor/v55"
default-features = false
features = ["std"]

Expand All @@ -127,10 +132,10 @@ ruint = { git = "https://github.com/scroll-tech/uint.git", branch = "v1.12.3" }

alloy-primitives = { git = "https://github.com/scroll-tech/alloy-core", branch = "v0.8.18" }

revm = { git = "https://github.com/scroll-tech/revm", branch = "scroll-evm-executor/v50" }
revm-interpreter = { git = "https://github.com/scroll-tech/revm", branch = "scroll-evm-executor/v50" }
revm-precompile = { git = "https://github.com/scroll-tech/revm", branch = "scroll-evm-executor/v50" }
revm-primitives = { git = "https://github.com/scroll-tech/revm", branch = "scroll-evm-executor/v50" }
revm = { git = "https://github.com/scroll-tech/revm", branch = "scroll-evm-executor/v55" }
revm-interpreter = { git = "https://github.com/scroll-tech/revm", branch = "scroll-evm-executor/v55" }
revm-precompile = { git = "https://github.com/scroll-tech/revm", branch = "scroll-evm-executor/v55" }
revm-primitives = { git = "https://github.com/scroll-tech/revm", branch = "scroll-evm-executor/v55" }

# for local development
# [patch."https://github.com/scroll-tech/revm"]
Expand Down
2 changes: 1 addition & 1 deletion crates/bin/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,4 @@ debug-account = ["sbv/debug-account"]
debug-storage = ["sbv/debug-storage"]
profiling = ["dep:pprof"]
scroll = ["sbv/scroll"]
metrics = ["sbv/metrics"]
metrics = ["sbv/metrics"]
9 changes: 3 additions & 6 deletions crates/bin/src/commands/run_file.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,11 +71,8 @@ impl RunFileCommand {
.iter()
.map(|w| w.build_reth_block())
.collect::<Result<Vec<_>, _>>()?;
let chunk_info = ChunkInfo::from_blocks_iter(
witnesses[0].chain_id,
witnesses[0].pre_state_root,
blocks.iter().map(|b| &b.block),
);
let chunk_info =
ChunkInfo::from_blocks(witnesses[0].chain_id, witnesses[0].pre_state_root, &blocks);

let chain_spec = get_chain_spec(Chain::from_id(chunk_info.chain_id())).unwrap();
let mut code_db = NoHashMap::default();
Expand All @@ -101,7 +98,7 @@ impl RunFileCommand {
let withdraw_root = db.withdraw_root()?;
let tx_bytes_hash = blocks
.iter()
.flat_map(|b| b.block.body.transactions.iter())
.flat_map(|b| b.body().transactions.iter())
.tx_bytes_hash();
let _public_input_hash = chunk_info.public_input_hash(&withdraw_root, &tx_bytes_hash);
dev_info!("[chunk mode] public input hash: {_public_input_hash:?}");
Expand Down
8 changes: 1 addition & 7 deletions crates/core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,11 @@ repository.workspace = true
workspace = true

[dependencies]
revm.workspace = true
reth-evm.workspace = true
reth-evm-ethereum.workspace = true
reth-execution-types.workspace = true
reth-scroll-evm = { workspace = true, optional = true }
reth-storage-errors.workspace = true
reth-scroll-storage = { workspace = true, optional = true }
serde.workspace = true
serde_json.workspace = true
thiserror.workspace = true
Expand All @@ -40,14 +38,10 @@ tracing-subscriber.workspace = true
[features]
scroll = [
"dep:reth-scroll-evm",
"dep:reth-scroll-storage",
"reth-evm/scroll",
"reth-evm-ethereum/scroll",
"reth-execution-types/scroll",
"reth-scroll-evm/scroll",
"reth-scroll-storage/scroll",
"revm/scroll-default-handler",
"revm/optional_no_base_fee",
"sbv-primitives/scroll",
]
debug-account = ["sbv-helpers/debug-account"]
Expand All @@ -59,4 +53,4 @@ metrics = ["sbv-helpers/metrics"]
sp1 = ["sbv-trie/sp1"]
cycle-tracker = ["sbv-trie/cycle-tracker"]

openvm = ["revm/openvm"]
openvm = ["sbv-primitives/openvm"]
23 changes: 9 additions & 14 deletions crates/core/src/chunk.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
use revm::primitives::B256;
use sbv_primitives::{Block, BlockChunkExt};
use sbv_primitives::{B256, BlockChunkExt, RecoveredBlock, types::reth::Block};
use tiny_keccak::{Hasher, Keccak};

/// A chunk is a set of continuous blocks.
Expand All @@ -21,20 +20,20 @@ pub struct ChunkInfo {
impl ChunkInfo {
/// Construct by block traces
#[must_use]
pub fn from_blocks_iter<'a, I: IntoIterator<Item = &'a Block> + Clone>(
pub fn from_blocks(
chain_id: u64,
prev_state_root: B256,
iter: I,
blocks: &[RecoveredBlock<Block>],
) -> Self {
let last_block = iter.clone().into_iter().last().expect("at least one block");
let last_block = blocks.last().expect("at least one block");

let data_hash = cycle_track!(
{
let mut data_hasher = Keccak::v256();
for block in iter.clone().into_iter() {
for block in blocks.iter() {
block.hash_da_header(&mut data_hasher);
}
for block in iter.into_iter() {
for block in blocks.iter() {
block.hash_l1_msg(&mut data_hasher);
}
let mut data_hash = B256::ZERO;
Expand Down Expand Up @@ -100,7 +99,7 @@ impl ChunkInfo {
#[cfg(test)]
mod tests {
use super::*;
use sbv_primitives::{BlockWithSenders, BlockWitness as _, types::BlockWitness};
use sbv_primitives::{BlockWitness as _, RecoveredBlock, types::BlockWitness};

const TRACES_STR: [&str; 4] = [
include_str!("../../../testdata/holesky_witness/2971844.json"),
Expand All @@ -112,13 +111,9 @@ mod tests {
#[test]
fn test_public_input_hash() {
let witnesses: [BlockWitness; 4] = TRACES_STR.map(|s| serde_json::from_str(s).unwrap());
let blocks: [BlockWithSenders; 4] =
let blocks: [RecoveredBlock<Block>; 4] =
witnesses.clone().map(|s| s.build_reth_block().unwrap());

let _ = ChunkInfo::from_blocks_iter(
1,
witnesses[0].pre_state_root,
blocks.iter().map(|b| &b.block),
);
let _ = ChunkInfo::from_blocks(1, witnesses[0].pre_state_root, &blocks);
}
}
13 changes: 5 additions & 8 deletions crates/core/src/database.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
use revm::{
interpreter::analysis::to_analysed,
primitives::{AccountInfo, Address, Bytecode},
};
use sbv_kv::{HashMap, KeyValueStoreGet};
use sbv_primitives::{B256, Bytes, U256, states::BundleAccount};
use sbv_primitives::{
AccountInfo, Address, B256, Bytecode, Bytes, U256,
revm::{db::BundleAccount, interpreter::analysis::to_analysed},
};
use sbv_trie::{PartialStateTrie, TrieNode};
use std::{cell::RefCell, fmt};

pub use revm::db::DatabaseRef;
pub use sbv_primitives::revm::db::DatabaseRef;

/// A database that consists of account and storage information.
pub struct EvmDatabase<CodeDb, NodesProvider, BlockHashProvider> {
Expand Down Expand Up @@ -140,8 +139,6 @@ impl<
#[cfg(feature = "scroll")]
code_size: code.as_ref().map(|c| c.len()).unwrap_or(0), // FIXME: this should be remove
code_hash: account.code_hash,
#[cfg(feature = "scroll")]
poseidon_code_hash: Default::default(), // FIXME: this should be remove
code,
};

Expand Down
21 changes: 10 additions & 11 deletions crates/core/src/executor.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
use crate::{database::EvmDatabase, error::VerificationError};
use reth_evm::execute::{BlockExecutorProvider, Executor};
use reth_execution_types::{BlockExecutionInput, BlockExecutionOutput};
use revm::db::CacheDB;
use reth_execution_types::BlockExecutionOutput;
use sbv_kv::KeyValueStoreGet;
use sbv_primitives::{B256, BlockWithSenders, Bytes, Receipt, chainspec::ChainSpec};
use sbv_primitives::{
B256, Bytes, RecoveredBlock,
chainspec::ChainSpec,
revm::db::CacheDB,
types::reth::{Block, Receipt},
};
use sbv_trie::TrieNode;
use std::{fmt::Debug, sync::Arc};

Expand All @@ -17,7 +21,7 @@ use reth_scroll_evm::ScrollExecutorProvider as ExecutorProvider;
pub struct EvmExecutor<'a, CodeDb, NodesProvider, BlockHashProvider> {
chain_spec: Arc<ChainSpec>,
db: &'a EvmDatabase<CodeDb, NodesProvider, BlockHashProvider>,
block: &'a BlockWithSenders,
block: &'a RecoveredBlock<Block>,
}

impl<'a, CodeDb, NodesProvider, BlockHashProvider>
Expand All @@ -27,7 +31,7 @@ impl<'a, CodeDb, NodesProvider, BlockHashProvider>
pub fn new(
chain_spec: Arc<ChainSpec>,
db: &'a EvmDatabase<CodeDb, NodesProvider, BlockHashProvider>,
block: &'a BlockWithSenders,
block: &'a RecoveredBlock<Block>,
) -> Self {
Self {
chain_spec,
Expand All @@ -54,12 +58,7 @@ impl<
let output = measure_duration_millis!(
handle_block_duration_milliseconds,
cycle_track!(
provider
.executor(CacheDB::new(self.db))
.execute(BlockExecutionInput::new(
self.block,
self.block.header.difficulty,
)),
provider.executor(CacheDB::new(self.db)).execute(self.block),
"handle_block"
)
)?;
Expand Down
2 changes: 1 addition & 1 deletion crates/helpers/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,4 @@ debug-storage = ["dep:csv", "dep:serde", "revm/serde"]
dev = ["dep:tracing"]
metrics = ["dep:hyper", "dep:hyper-util", "dep:http-body-util", "dep:once_cell", "dep:prometheus-client", "dep:tokio", "tokio/macros", "tokio/signal"]

openvm = ["revm/openvm"]
openvm = ["revm/openvm"]
2 changes: 0 additions & 2 deletions crates/helpers/src/utils/debug.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ struct AccountData {
nonce: u64,
balance: U256,
code_hash: B256,
poseidon_code_hash: B256,
code_size: u64,
storage_root: B256,
}
Expand Down Expand Up @@ -55,7 +54,6 @@ impl DebugRecorder {
nonce: info.nonce,
balance: info.balance,
code_hash: info.code_hash,
poseidon_code_hash: info.poseidon_code_hash,
code_size: info.code_size as u64,
storage_root,
});
Expand Down
22 changes: 13 additions & 9 deletions crates/primitives/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ repository.workspace = true
workspace = true

[dependencies]
async-trait.workspace = true
auto_impl.workspace = true
itertools.workspace = true
rkyv.workspace = true
Expand All @@ -22,37 +21,42 @@ tiny-keccak.workspace = true

alloy-consensus.workspace = true
alloy-eips.workspace = true
alloy-provider.workspace = true
alloy-network.workspace = true
alloy-rpc-types-eth.workspace = true
alloy-serde.workspace = true
alloy-transport.workspace = true

alloy-primitives.workspace = true

revm.workspace = true
reth-chainspec.workspace = true
reth-primitives.workspace = true
reth-primitives-traits.workspace = true
reth-scroll-chainspec = { workspace = true, optional = true }
reth-scroll-primitives = { workspace = true, optional = true }
reth-scroll-revm = { workspace = true, optional = true }

scroll-alloy-consensus = { workspace = true, optional = true }
scroll-alloy-rpc-types = { workspace = true, optional = true }
scroll-alloy-network = { workspace = true, optional = true }

sbv-helpers.workspace = true
sbv-kv.workspace = true

[dev-dependencies]
serde_json.workspace = true

[features]
scroll = [
"dep:reth-scroll-chainspec",
"dep:reth-scroll-primitives",
"dep:reth-scroll-revm",
"reth-chainspec/scroll",
"reth-primitives/scroll",
"dep:scroll-alloy-consensus",
"dep:scroll-alloy-rpc-types",
"dep:scroll-alloy-network",
"reth-scroll-primitives/serde",
"revm/scroll-default-handler",
"revm/optional_no_base_fee",
]
dev = ["sbv-helpers/dev"]

sp1 = []
cycle-tracker = []

openvm = ["revm/openvm"]
openvm = ["revm/openvm"]
Loading
Loading