diff --git a/Cargo.lock b/Cargo.lock index 307725a8..c6fa8c99 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1692,6 +1692,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "fffa369a668c8af7dbf8b5e56c9f744fbd399949ed171606040001947de40b1c" dependencies = [ "const-oid", + "pem-rfc7468", "zeroize", ] @@ -1876,6 +1877,7 @@ dependencies = [ "digest 0.10.7", "elliptic-curve", "rfc6979", + "serdect", "signature", "spki", ] @@ -1904,9 +1906,11 @@ dependencies = [ "ff", "generic-array", "group", + "pem-rfc7468", "pkcs8", "rand_core", "sec1", + "serdect", "subtle", "zeroize", ] @@ -2703,7 +2707,9 @@ dependencies = [ "ecdsa", "elliptic-curve", "once_cell", + "serdect", "sha2", + "signature", ] [[package]] @@ -3340,6 +3346,15 @@ version = "1.0.14" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "de3145af08024dea9fa9914f381a17b8fc6034dfb00f3a84013f7ff43f29ed4c" +[[package]] +name = "pem-rfc7468" +version = "0.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "88b39c9bfcfc231068454382784bb460aae594343fb030d46e9f50a645418412" +dependencies = [ + "base64ct", +] + [[package]] name = "percent-encoding" version = "2.3.1" @@ -4961,6 +4976,7 @@ dependencies = [ "der", "generic-array", "pkcs8", + "serdect", "subtle", "zeroize", ] @@ -5087,11 +5103,11 @@ dependencies = [ [[package]] name = "serde_with" -version = "3.7.0" +version = "3.11.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ee80b0e361bbf88fd2f6e242ccd19cfda072cb0faa6ae694ecee08199938569a" +checksum = "8e28bdad6db2b8340e449f7108f020b3b092e8583a9e3fb82713e1d4e71fe817" dependencies = [ - "base64 0.21.7", + "base64 0.22.1", "chrono", "hex", "indexmap 1.9.3", @@ -5105,9 +5121,9 @@ dependencies = [ [[package]] name = "serde_with_macros" -version = "3.7.0" +version = "3.11.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6561dc161a9224638a31d876ccdfefbc1df91d3f3a8342eddb35f055d48c7655" +checksum = "9d846214a9854ef724f3da161b426242d8de7c1fc7de2f89bb1efcb154dca79d" dependencies = [ "darling", "proc-macro2", @@ -5115,6 +5131,16 @@ dependencies = [ "syn 2.0.87", ] +[[package]] +name = "serdect" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a84f14a19e9a014bb9f4512488d9829a68e04ecabffb0f9904cd1ace94598177" +dependencies = [ + "base16ct", + "serde", +] + [[package]] name = "sha1" version = "0.10.6" @@ -6320,12 +6346,8 @@ dependencies = [ "clap", "env_logger", "log", - "pot", "reth-chainspec", "risc0-zkvm", - "serde", - "tokio", - "tracing", "zeth-core", "zeth-guests", "zeth-preflight", @@ -6337,10 +6359,8 @@ version = "0.1.0" dependencies = [ "alloy", "alloy-chains", - "anyhow", "clap", "env_logger", - "log", "tracing", "zeth", "zeth-core", @@ -6354,13 +6374,9 @@ dependencies = [ "alloy-primitives", "alloy-rlp", "anyhow", - "hashbrown 0.15.0", + "k256", "pot", "reth-chainspec", - "reth-consensus", - "reth-ethereum-consensus", - "reth-evm", - "reth-evm-ethereum", "reth-primitives", "reth-revm", "reth-storage-errors", @@ -6373,7 +6389,10 @@ dependencies = [ name = "zeth-core-ethereum" version = "0.1.0" dependencies = [ + "alloy-genesis", "anyhow", + "k256", + "once_cell", "reth-chainspec", "reth-consensus", "reth-ethereum-consensus", @@ -6389,7 +6408,11 @@ dependencies = [ name = "zeth-core-optimism" version = "0.1.0" dependencies = [ + "alloy-genesis", "anyhow", + "k256", + "once_cell", + "op-alloy-consensus", "reth-chainspec", "reth-consensus", "reth-evm", @@ -6407,18 +6430,9 @@ dependencies = [ name = "zeth-ethereum" version = "0.1.0" dependencies = [ - "alloy", "anyhow", - "bincode", - "bytemuck", - "clap", - "env_logger", - "log", - "pot", "reth-chainspec", - "serde", "tokio", - "tracing", "zeth", "zeth-guests", "zeth-preflight-ethereum", @@ -6435,18 +6449,9 @@ dependencies = [ name = "zeth-optimism" version = "0.1.0" dependencies = [ - "alloy", "anyhow", - "bincode", - "bytemuck", - "clap", - "env_logger", - "log", - "pot", "reth-chainspec", - "serde", "tokio", - "tracing", "zeth", "zeth-guests", "zeth-preflight-optimism", @@ -6459,20 +6464,17 @@ dependencies = [ "alloy", "anyhow", "async-trait", - "env_logger", "flate2", - "hashbrown 0.15.0", + "k256", "log", "pot", "reth-chainspec", - "reth-evm-ethereum", "reth-primitives", "reth-revm", "reth-storage-errors", "serde", "serde_json", "tokio", - "tracing", "zeth-core", ] @@ -6483,7 +6485,6 @@ dependencies = [ "alloy", "reth-chainspec", "reth-primitives", - "reth-revm", "zeth-core", "zeth-core-ethereum", "zeth-preflight", diff --git a/Cargo.toml b/Cargo.toml index 1ad5ca98..e440e9d6 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -38,12 +38,11 @@ default-features = false alloy = { version = "0.4.2", features = ["full"] } alloy-chains = "0.1.38" alloy-consensus = "0.4.2" +alloy-genesis = "0.4.2" alloy-primitives = { version = "0.8.8", default-features = false } alloy-rlp = "0.3.8" op-alloy-consensus = "0.4.0" op-alloy-network = "0.4.0" -op-alloy-protocol = "0.4.0" -op-alloy-provider = "0.4.0" op-alloy-rpc-types = "0.4.0" # Reth @@ -92,13 +91,14 @@ bincode = "1.3.3" bytemuck = "1.19.0" clap = { version = "4.0", features = ["derive"] } env_logger = "0.11.5" -hashbrown = { version = "0.15.0", features = ["inline-more"] } +k256 = { version = "0.13.3", features = ["serde", "pem"] } log = "0.4.22" flate2 = "1.0.34" +once_cell = "1.20.2" pot = "3.0.1" serde = { version = "1.0.210", features = ["derive"] } serde_json = { version = "1.0.128", features = ["alloc"] } -serde_with = "3.7.0" +serde_with = "3.11.0" thiserror = "1.0.64" tiny-keccak = "2.0.2" tokio = { version = "1.41.0", features = ["full"] } diff --git a/bin/benchmark/Cargo.toml b/bin/benchmark/Cargo.toml index 93693188..0ffda1f8 100644 --- a/bin/benchmark/Cargo.toml +++ b/bin/benchmark/Cargo.toml @@ -12,13 +12,12 @@ workspace = true [dependencies] alloy.workspace = true alloy-chains.workspace = true -anyhow.workspace = true clap.workspace = true env_logger.workspace = true tracing.workspace = true -log = "0.4.22" [features] -metal = ["zeth/metal"] -cuda = ["zeth/cuda"] disable-dev-mode = ["zeth/disable-dev-mode"] +cuda = ["zeth/cuda"] +metal = ["zeth/metal"] +prove = ["zeth/prove"] diff --git a/bin/ethereum/Cargo.toml b/bin/ethereum/Cargo.toml index b6cd68a7..1ac4dd99 100644 --- a/bin/ethereum/Cargo.toml +++ b/bin/ethereum/Cargo.toml @@ -14,21 +14,13 @@ workspace = true [dependencies] -alloy.workspace = true anyhow.workspace = true -bincode.workspace = true -bytemuck.workspace = true -clap.workspace = true -env_logger.workspace = true -log.workspace = true -pot.workspace = true reth-chainspec.workspace = true -serde.workspace = true tokio.workspace = true -tracing.workspace = true [features] -metal = ["zeth/metal"] -cuda = ["zeth/cuda"] +debug-guest-build = ["zeth-guests/debug-guest-build"] disable-dev-mode = ["zeth/disable-dev-mode"] -debug-guest-build = ["zeth-guests/debug-guest-build"] \ No newline at end of file +cuda = ["zeth/cuda"] +metal = ["zeth/metal"] +prove = ["zeth/prove"] diff --git a/bin/ethereum/src/main.rs b/bin/ethereum/src/main.rs index ef678e69..e200a88e 100644 --- a/bin/ethereum/src/main.rs +++ b/bin/ethereum/src/main.rs @@ -13,19 +13,16 @@ // limitations under the License. use reth_chainspec::NamedChain; -use tokio::task::spawn_blocking; use zeth_guests::{ZETH_GUESTS_RETH_ETHEREUM_ELF, ZETH_GUESTS_RETH_ETHEREUM_ID}; use zeth_preflight_ethereum::RethBlockBuilder; #[tokio::main] async fn main() -> anyhow::Result<()> { - spawn_blocking(move || { - zeth::run::( - ZETH_GUESTS_RETH_ETHEREUM_ELF, - ZETH_GUESTS_RETH_ETHEREUM_ID, - NamedChain::Mainnet, - "ethereum", - ) - }) - .await? + zeth::run::( + ZETH_GUESTS_RETH_ETHEREUM_ELF, + ZETH_GUESTS_RETH_ETHEREUM_ID, + NamedChain::Mainnet, + "ethereum", + ) + .await } diff --git a/bin/optimism/Cargo.toml b/bin/optimism/Cargo.toml index 821099dc..73f95caa 100644 --- a/bin/optimism/Cargo.toml +++ b/bin/optimism/Cargo.toml @@ -14,21 +14,13 @@ workspace = true [dependencies] -alloy.workspace = true anyhow.workspace = true -bincode.workspace = true -bytemuck.workspace = true -clap.workspace = true -env_logger.workspace = true -log.workspace = true -pot.workspace = true reth-chainspec.workspace = true -serde.workspace = true tokio.workspace = true -tracing.workspace = true [features] -metal = ["zeth/metal"] -cuda = ["zeth/cuda"] +debug-guest-build = ["zeth-guests/debug-guest-build"] disable-dev-mode = ["zeth/disable-dev-mode"] -debug-guest-build = ["zeth-guests/debug-guest-build"] \ No newline at end of file +cuda = ["zeth/cuda"] +metal = ["zeth/metal"] +prove = ["zeth/prove"] diff --git a/bin/optimism/data/optimism/11155420-17664000.json.gz b/bin/optimism/data/optimism/11155420-17664000.json.gz new file mode 100644 index 00000000..24af1f60 Binary files /dev/null and b/bin/optimism/data/optimism/11155420-17664000.json.gz differ diff --git a/bin/optimism/src/main.rs b/bin/optimism/src/main.rs index fe0beb61..ecda4ddf 100644 --- a/bin/optimism/src/main.rs +++ b/bin/optimism/src/main.rs @@ -13,19 +13,16 @@ // limitations under the License. use reth_chainspec::NamedChain; -use tokio::task::spawn_blocking; use zeth_guests::{ZETH_GUESTS_RETH_OPTIMISM_ELF, ZETH_GUESTS_RETH_OPTIMISM_ID}; use zeth_preflight_optimism::OpRethBlockBuilder; #[tokio::main] async fn main() -> anyhow::Result<()> { - spawn_blocking(move || { - zeth::run::( - ZETH_GUESTS_RETH_OPTIMISM_ELF, - ZETH_GUESTS_RETH_OPTIMISM_ID, - NamedChain::Optimism, - "optimism", - ) - }) - .await? + zeth::run::( + ZETH_GUESTS_RETH_OPTIMISM_ELF, + ZETH_GUESTS_RETH_OPTIMISM_ID, + NamedChain::Optimism, + "optimism", + ) + .await } diff --git a/crates/core-ethereum/Cargo.toml b/crates/core-ethereum/Cargo.toml index 92509ebc..79d5c397 100644 --- a/crates/core-ethereum/Cargo.toml +++ b/crates/core-ethereum/Cargo.toml @@ -7,7 +7,10 @@ edition = "2021" workspace = true [dependencies] +alloy-genesis.workspace = true anyhow.workspace = true +k256.workspace = true +once_cell.workspace = true reth-chainspec.workspace = true reth-consensus.workspace = true diff --git a/crates/core-ethereum/src/chain_spec.rs b/crates/core-ethereum/src/chain_spec.rs new file mode 100644 index 00000000..09273fac --- /dev/null +++ b/crates/core-ethereum/src/chain_spec.rs @@ -0,0 +1,143 @@ +// Copyright 2024 RISC Zero, Inc. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +use alloy_genesis::Genesis; +use once_cell::sync::Lazy; +use reth_chainspec::{ + once_cell_set, BaseFeeParams, BaseFeeParamsKind, Chain, ChainSpec, DepositContract, + EthereumHardfork, DEV_HARDFORKS, +}; +use reth_primitives::constants::ETHEREUM_BLOCK_GAS_LIMIT; +use reth_primitives::revm_primitives::{address, b256, U256}; +use reth_primitives::{ + DEV_GENESIS_HASH, HOLESKY_GENESIS_HASH, MAINNET_GENESIS_HASH, SEPOLIA_GENESIS_HASH, +}; +use reth_revm::primitives::bytes; +use std::sync::Arc; + +/// The Ethereum mainnet spec +pub static MAINNET: Lazy> = Lazy::new(|| { + ChainSpec { + chain: Chain::mainnet(), + genesis: { + let mut genesis = Genesis::default() + .with_nonce(0x42) + .with_extra_data(bytes!( + "11bbe8db4e347b4e8c937c1c8370e4b5ed33adb3db69cbdb7a38e1e50b1b82fa" + )) + .with_gas_limit(0x1388) + .with_difficulty(U256::from(0x400000000u128)); + genesis.config.dao_fork_support = true; + genesis + }, + genesis_hash: once_cell_set(MAINNET_GENESIS_HASH), + genesis_header: Default::default(), + // + paris_block_and_final_difficulty: Some(( + 15537394, + U256::from(58_750_003_716_598_352_816_469u128), + )), + hardforks: EthereumHardfork::mainnet().into(), + // https://etherscan.io/tx/0xe75fb554e433e03763a1560646ee22dcb74e5274b34c5ad644e7c0f619a7e1d0 + deposit_contract: Some(DepositContract::new( + address!("00000000219ab540356cbb839cbe05303d7705fa"), + 11052984, + b256!("649bbc62d0e31342afea4e5cd82d4049e7e1ee912fc0889aa790803be39038c5"), + )), + base_fee_params: BaseFeeParamsKind::Constant(BaseFeeParams::ethereum()), + max_gas_limit: ETHEREUM_BLOCK_GAS_LIMIT, + prune_delete_limit: 20000, + } + .into() +}); + +/// The Sepolia spec +pub static SEPOLIA: Lazy> = Lazy::new(|| { + ChainSpec { + chain: Chain::sepolia(), + genesis: { + let mut genesis = Genesis::default() + .with_timestamp(0x6159af19) + .with_extra_data(bytes!( + "5365706f6c69612c20417468656e732c204174746963612c2047726565636521" + )) + .with_gas_limit(0x1c9c380) + .with_difficulty(U256::from(0x20000u128)); + genesis.config.dao_fork_support = true; + genesis + }, + genesis_hash: once_cell_set(SEPOLIA_GENESIS_HASH), + genesis_header: Default::default(), + // + paris_block_and_final_difficulty: Some((1450409, U256::from(17_000_018_015_853_232u128))), + hardforks: EthereumHardfork::sepolia().into(), + // https://sepolia.etherscan.io/tx/0x025ecbf81a2f1220da6285d1701dc89fb5a956b62562ee922e1a9efd73eb4b14 + deposit_contract: Some(DepositContract::new( + address!("7f02c3e3c98b133055b8b348b2ac625669ed295d"), + 1273020, + b256!("649bbc62d0e31342afea4e5cd82d4049e7e1ee912fc0889aa790803be39038c5"), + )), + base_fee_params: BaseFeeParamsKind::Constant(BaseFeeParams::ethereum()), + max_gas_limit: ETHEREUM_BLOCK_GAS_LIMIT, + prune_delete_limit: 10000, + } + .into() +}); + +/// The Holesky spec +pub static HOLESKY: Lazy> = Lazy::new(|| { + ChainSpec { + chain: Chain::holesky(), + genesis: { + let mut genesis = Genesis::default() + .with_nonce(0x1234) + .with_timestamp(1695902100) + .with_extra_data(bytes!("017D7840")) + .with_difficulty(U256::from(0x01u128)); + genesis.config.dao_fork_support = true; + genesis + }, + genesis_hash: once_cell_set(HOLESKY_GENESIS_HASH), + genesis_header: Default::default(), + paris_block_and_final_difficulty: Some((0, U256::from(1))), + hardforks: EthereumHardfork::holesky().into(), + deposit_contract: Some(DepositContract::new( + address!("4242424242424242424242424242424242424242"), + 0, + b256!("649bbc62d0e31342afea4e5cd82d4049e7e1ee912fc0889aa790803be39038c5"), + )), + base_fee_params: BaseFeeParamsKind::Constant(BaseFeeParams::ethereum()), + max_gas_limit: ETHEREUM_BLOCK_GAS_LIMIT, + prune_delete_limit: 10000, + } + .into() +}); + +/// Dev testnet specification +/// +/// Includes 20 prefunded accounts with `10_000` ETH each derived from mnemonic "test test test test +/// test test test test test test test junk". +pub static DEV: Lazy> = Lazy::new(|| { + ChainSpec { + chain: Chain::dev(), + genesis: Genesis::default(), + genesis_hash: once_cell_set(DEV_GENESIS_HASH), + paris_block_and_final_difficulty: Some((0, U256::from(0))), + hardforks: DEV_HARDFORKS.clone(), + base_fee_params: BaseFeeParamsKind::Constant(BaseFeeParams::ethereum()), + deposit_contract: None, // TODO: do we even have? + ..Default::default() + } + .into() +}); diff --git a/crates/core-ethereum/src/lib.rs b/crates/core-ethereum/src/lib.rs index e2055b9b..687cc417 100644 --- a/crates/core-ethereum/src/lib.rs +++ b/crates/core-ethereum/src/lib.rs @@ -12,8 +12,13 @@ // See the License for the specific language governing permissions and // limitations under the License. +mod chain_spec; + +use crate::chain_spec::{DEV, HOLESKY, MAINNET, SEPOLIA}; use anyhow::Context; -use reth_chainspec::{ChainSpec, NamedChain, DEV, HOLESKY, MAINNET, SEPOLIA}; +use k256::ecdsa::signature::hazmat::PrehashVerifier; +use k256::ecdsa::VerifyingKey; +use reth_chainspec::{ChainSpec, NamedChain}; use reth_consensus::Consensus; use reth_ethereum_consensus::EthBeaconConsensus; use reth_evm::execute::{ @@ -21,7 +26,7 @@ use reth_evm::execute::{ }; use reth_evm_ethereum::execute::EthExecutorProvider; use reth_primitives::revm_primitives::alloy_primitives::{BlockNumber, Sealable}; -use reth_primitives::revm_primitives::{B256, U256}; +use reth_primitives::revm_primitives::{Address, B256, U256}; use reth_primitives::{Block, Header, Receipt, SealedHeader, TransactionSigned}; use reth_revm::db::BundleState; use reth_storage_errors::provider::ProviderError; @@ -98,23 +103,36 @@ where fn execute_transactions( chain_spec: Arc, block: &mut Block, + signers: &[VerifyingKey], total_difficulty: &mut U256, db: &mut Option, ) -> anyhow::Result { // Instantiate execution engine using database let mut executor = EthExecutorProvider::ethereum(chain_spec.clone()) .batch_executor(db.take().expect("Missing database.")); + + // Verify the transaction signatures and compute senders + let mut senders = Vec::with_capacity(block.body.transactions.len()); + for (i, tx) in block.body.transactions().enumerate() { + let vk = &signers[i]; + let sig = tx.signature(); + + sig.to_k256() + .and_then(|sig| vk.verify_prehash(tx.signature_hash().as_slice(), &sig)) + .with_context(|| format!("invalid signature for tx {i}"))?; + + senders.push(Address::from_public_key(vk)) + } + // Execute transactions - // todo: recover signers with non-det hints - let block_with_senders = take(block) - .with_recovered_senders() - .expect("Senders recovery failed"); + let block_with_senders = take(block).with_senders_unchecked(senders); executor .execute_and_verify_one(BlockExecutionInput { block: &block_with_senders, total_difficulty: *total_difficulty, }) - .expect("Execution failed"); + .context("execution failed")?; + // Return block *block = block_with_senders.block; // Return bundle state diff --git a/crates/core-optimism/Cargo.toml b/crates/core-optimism/Cargo.toml index 2fe66563..a47df300 100644 --- a/crates/core-optimism/Cargo.toml +++ b/crates/core-optimism/Cargo.toml @@ -7,7 +7,11 @@ edition = "2021" workspace = true [dependencies] +alloy-genesis.workspace = true anyhow.workspace = true +k256.workspace = true +once_cell.workspace = true +op-alloy-consensus.workspace = true reth-chainspec.workspace = true reth-consensus.workspace = true diff --git a/crates/core-optimism/src/lib.rs b/crates/core-optimism/src/lib.rs index f3dee3ea..4be49e63 100644 --- a/crates/core-optimism/src/lib.rs +++ b/crates/core-optimism/src/lib.rs @@ -13,6 +13,9 @@ // limitations under the License. use anyhow::Context; +use k256::ecdsa::signature::hazmat::PrehashVerifier; +use k256::ecdsa::VerifyingKey; +use op_alloy_consensus::TxDeposit; use reth_chainspec::NamedChain; use reth_consensus::Consensus; use reth_evm::execute::{ @@ -24,8 +27,8 @@ use reth_optimism_chainspec::{ use reth_optimism_consensus::OptimismBeaconConsensus; use reth_optimism_evm::OpExecutorProvider; use reth_primitives::revm_primitives::alloy_primitives::{BlockNumber, Sealable}; -use reth_primitives::revm_primitives::{B256, U256}; -use reth_primitives::{Block, Header, Receipt, SealedHeader, TransactionSigned}; +use reth_primitives::revm_primitives::{Address, B256, U256}; +use reth_primitives::{Block, Header, Receipt, SealedHeader, Transaction, TransactionSigned}; use reth_revm::db::BundleState; use reth_storage_errors::provider::ProviderError; use std::fmt::Display; @@ -100,23 +103,43 @@ where fn execute_transactions( chain_spec: Arc, block: &mut Block, + signers: &[VerifyingKey], total_difficulty: &mut U256, db: &mut Option, ) -> anyhow::Result { // Instantiate execution engine using database let mut executor = OpExecutorProvider::optimism(chain_spec.clone()) .batch_executor(db.take().expect("Missing database")); + + // Verify the transaction signatures and compute senders + let mut vk_it = signers.iter(); + let mut senders = Vec::with_capacity(block.body.transactions.len()); + for (i, tx) in block.body.transactions().enumerate() { + let sender = if let Transaction::Deposit(TxDeposit { from, .. }) = tx.transaction { + // Deposit transactions are unsigned and contain the sender + from + } else { + let vk = vk_it.next().unwrap(); + let sig = tx.signature(); + + sig.to_k256() + .and_then(|sig| vk.verify_prehash(tx.signature_hash().as_slice(), &sig)) + .with_context(|| format!("invalid signature for tx {i}"))?; + + Address::from_public_key(vk) + }; + senders.push(sender); + } + // Execute transactions - // todo: recover signers with non-det hints - let block_with_senders = take(block) - .with_recovered_senders() - .expect("Senders recovery failed"); + let block_with_senders = take(block).with_senders_unchecked(senders); executor .execute_and_verify_one(BlockExecutionInput { block: &block_with_senders, total_difficulty: *total_difficulty, }) - .expect("Execution failed"); + .context("execution failed")?; + // Return block *block = block_with_senders.block; // Return bundle state diff --git a/crates/core/Cargo.toml b/crates/core/Cargo.toml index f36c4537..ae1eb7cc 100644 --- a/crates/core/Cargo.toml +++ b/crates/core/Cargo.toml @@ -8,19 +8,14 @@ anyhow.workspace = true alloy-consensus.workspace = true alloy-primitives.workspace = true alloy-rlp.workspace = true - -hashbrown.workspace = true +k256.workspace = true +pot.workspace = true +serde.workspace = true +thiserror.workspace = true +tiny-keccak.workspace = true reth-chainspec.workspace = true -reth-consensus.workspace = true -reth-ethereum-consensus.workspace = true -reth-evm.workspace = true -reth-evm-ethereum.workspace = true reth-primitives.workspace = true reth-revm.workspace = true reth-storage-errors.workspace = true -pot.workspace = true -serde.workspace = true -thiserror.workspace = true -tiny-keccak.workspace = true diff --git a/crates/core/src/mpt.rs b/crates/core/src/mpt.rs index c6972ce1..98e95e8e 100644 --- a/crates/core/src/mpt.rs +++ b/crates/core/src/mpt.rs @@ -1,4 +1,4 @@ -// Copyright 2024, 2024 RISC Zero, Inc. +// Copyright 2023, 2024 RISC Zero, Inc. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. diff --git a/crates/core/src/stateless/client.rs b/crates/core/src/stateless/client.rs index 6ade97a9..5aab6dbd 100644 --- a/crates/core/src/stateless/client.rs +++ b/crates/core/src/stateless/client.rs @@ -32,12 +32,18 @@ where type Execution: ExecutionStrategy>; type Finalization: FinalizationStrategy; - fn deserialize_data( + fn data_from_reader( reader: I, ) -> anyhow::Result> { Ok(pot::from_reader(reader)?) } + fn data_from_slice( + slice: &[u8], + ) -> anyhow::Result> { + Ok(pot::from_slice(slice)?) + } + fn validate( data: StatelessClientData, ) -> anyhow::Result> { diff --git a/crates/core/src/stateless/data.rs b/crates/core/src/stateless/data.rs index 415084a3..0664bf53 100644 --- a/crates/core/src/stateless/data.rs +++ b/crates/core/src/stateless/data.rs @@ -15,6 +15,7 @@ use crate::mpt::MptNode; use alloy_primitives::map::HashMap; use alloy_primitives::{Address, Bytes, U256}; +use k256::ecdsa::VerifyingKey; use reth_chainspec::NamedChain; use serde::{Deserialize, Serialize}; @@ -30,6 +31,8 @@ pub struct StatelessClientData { pub chain: NamedChain, /// Block and transaction data to execute pub blocks: Vec, + /// List of public keys for transaction signatures + pub signers: Vec>, /// State trie of the parent block. pub state_trie: MptNode, /// Maps each address with its storage trie and the used storage slots. diff --git a/crates/core/src/stateless/engine.rs b/crates/core/src/stateless/engine.rs index 136175b0..88268e70 100644 --- a/crates/core/src/stateless/engine.rs +++ b/crates/core/src/stateless/engine.rs @@ -112,6 +112,7 @@ impl StatelessClientEngine StatelessClientEngine { fn execute_transactions( chain_spec: Arc, block: &mut Driver::Block, + signers: &[VerifyingKey], total_difficulty: &mut U256, db: &mut Option, ) -> anyhow::Result; diff --git a/crates/preflight-ethereum/Cargo.toml b/crates/preflight-ethereum/Cargo.toml index 291c435c..599a67dc 100644 --- a/crates/preflight-ethereum/Cargo.toml +++ b/crates/preflight-ethereum/Cargo.toml @@ -16,4 +16,3 @@ workspace = true alloy.workspace = true reth-chainspec.workspace = true reth-primitives.workspace = true -reth-revm.workspace = true \ No newline at end of file diff --git a/crates/preflight-ethereum/src/lib.rs b/crates/preflight-ethereum/src/lib.rs index 01a7ecf1..c82a3f52 100644 --- a/crates/preflight-ethereum/src/lib.rs +++ b/crates/preflight-ethereum/src/lib.rs @@ -16,6 +16,7 @@ use alloy::network::ReceiptResponse; use alloy::network::{Ethereum, Network}; use alloy::primitives::{B256, U256}; use alloy::rpc::types::serde_helpers::WithOtherFields; +use alloy::signers::k256::ecdsa::VerifyingKey; use reth_chainspec::ChainSpec; use reth_primitives::{Block, BlockBody, Header, Log, Receipt, TransactionSigned, Withdrawals}; use std::iter::zip; @@ -132,11 +133,14 @@ impl PreflightDriver for RethPreflightDriver { >, ommers: Vec::HeaderResponse>>, ) -> StatelessClientData { + let blocks: Vec<_> = zip(data.blocks, ommers) + .map(|(block, ommers)| Self::derive_block(block, ommers)) + .collect(); + let signers = blocks.iter().map(Self::recover_signers).collect(); StatelessClientData { chain: data.chain, - blocks: zip(data.blocks, ommers) - .map(|(block, ommers)| Self::derive_block(block, ommers)) - .collect(), + blocks, + signers, state_trie: data.state_trie, storage_tries: data.storage_tries, contracts: data.contracts, @@ -149,4 +153,16 @@ impl PreflightDriver for RethPreflightDriver { total_difficulty: data.total_difficulty, } } + + fn recover_signers(block: &Block) -> Vec { + block + .body + .transactions() + .map(|tx| { + tx.signature() + .recover_from_prehash(&tx.signature_hash()) + .unwrap() + }) + .collect() + } } diff --git a/crates/preflight-optimism/src/lib.rs b/crates/preflight-optimism/src/lib.rs index fc364c0e..9fe59962 100644 --- a/crates/preflight-optimism/src/lib.rs +++ b/crates/preflight-optimism/src/lib.rs @@ -15,6 +15,7 @@ use alloy::network::{Network, ReceiptResponse}; use alloy::primitives::{Log, B256, U256}; use alloy::rpc::types::serde_helpers::WithOtherFields; +use alloy::signers::k256::ecdsa::VerifyingKey; use op_alloy_consensus::OpTxType; use op_alloy_network::Optimism; use reth_optimism_chainspec::OpChainSpec; @@ -151,11 +152,14 @@ impl PreflightDriver for OpRethPreflightDriver { ::Block, ::Header, > { + let blocks: Vec<_> = zip(data.blocks, ommers) + .map(|(block, ommers)| Self::derive_block(block, ommers)) + .collect(); + let signers = blocks.iter().map(Self::recover_signers).collect(); StatelessClientData { chain: data.chain, - blocks: zip(data.blocks, ommers) - .map(|(block, ommers)| Self::derive_block(block, ommers)) - .collect(), + blocks, + signers, state_trie: data.state_trie, storage_tries: data.storage_tries, contracts: data.contracts, @@ -168,4 +172,17 @@ impl PreflightDriver for OpRethPreflightDriver { total_difficulty: data.total_difficulty, } } + + fn recover_signers(block: &Block) -> Vec { + block + .body + .transactions() + .filter(|tx| !matches!(tx.tx_type(), TxType::Deposit)) + .map(|tx| { + tx.signature() + .recover_from_prehash(&tx.signature_hash()) + .unwrap() + }) + .collect() + } } diff --git a/crates/preflight/Cargo.toml b/crates/preflight/Cargo.toml index 4122d7fc..35140605 100644 --- a/crates/preflight/Cargo.toml +++ b/crates/preflight/Cargo.toml @@ -10,14 +10,12 @@ workspace = true alloy.workspace = true anyhow.workspace = true async-trait.workspace = true -env_logger.workspace = true -hashbrown.workspace = true +k256.workspace = true log.workspace = true serde.workspace = true flate2.workspace = true reth-chainspec.workspace = true -reth-evm-ethereum.workspace = true reth-revm.workspace = true reth-primitives.workspace = true reth-storage-errors.workspace = true @@ -25,4 +23,3 @@ reth-storage-errors.workspace = true pot.workspace = true serde_json.workspace = true tokio.workspace = true -tracing.workspace = true diff --git a/crates/preflight/src/client.rs b/crates/preflight/src/client.rs index 56d300b2..21679ee0 100644 --- a/crates/preflight/src/client.rs +++ b/crates/preflight/src/client.rs @@ -139,6 +139,7 @@ where let data = StatelessClientData { chain, blocks: blocks.into_iter().rev().collect(), + signers: Default::default(), state_trie: Default::default(), storage_tries: Default::default(), contracts: Default::default(), @@ -324,11 +325,14 @@ where .sum(); info!("{transactions} total transactions."); - Ok(StatelessClientData:: { + let blocks: Vec<_> = zip(data.blocks, ommers) + .map(|(block, ommers)| P::derive_block(block, ommers)) + .collect(); + let signers = blocks.iter().map(P::recover_signers).collect(); + Ok(StatelessClientData { chain: data.chain, - blocks: zip(data.blocks, ommers) - .map(|(block, ommers)| P::derive_block(block, ommers)) - .collect(), + blocks, + signers, state_trie, storage_tries, contracts, diff --git a/crates/preflight/src/driver.rs b/crates/preflight/src/driver.rs index e6a32629..c2c66782 100644 --- a/crates/preflight/src/driver.rs +++ b/crates/preflight/src/driver.rs @@ -14,6 +14,7 @@ use alloy::network::Network; use alloy::primitives::{B256, U256}; +use k256::ecdsa::VerifyingKey; use zeth_core::driver::CoreDriver; use zeth_core::stateless::data::StatelessClientData; @@ -31,4 +32,5 @@ pub trait PreflightDriver { data: StatelessClientData, ommers: Vec>, ) -> StatelessClientData; + fn recover_signers(block: &Core::Block) -> Vec; } diff --git a/crates/preflight/src/lib.rs b/crates/preflight/src/lib.rs index cb0cd615..5e4d5a3e 100644 --- a/crates/preflight/src/lib.rs +++ b/crates/preflight/src/lib.rs @@ -99,7 +99,7 @@ where build_result.encoded_input.len() ); let deserialized_preflight_data: StatelessClientData = - Self::StatelessClient::deserialize_data(build_result.encoded_input.as_slice()) + Self::StatelessClient::data_from_reader(build_result.encoded_input.as_slice()) .context("input deserialization failed")?; ::validate(deserialized_preflight_data) .expect("Block validation failed"); diff --git a/crates/zeth/Cargo.toml b/crates/zeth/Cargo.toml index 3744261e..e017ca16 100644 --- a/crates/zeth/Cargo.toml +++ b/crates/zeth/Cargo.toml @@ -5,7 +5,7 @@ edition = "2021" [dependencies.risc0-zkvm] workspace = true -features = ["std", "client"] +features = ["std", "client", "unstable"] [dependencies.zeth-guests] workspace = true @@ -24,14 +24,11 @@ bytemuck.workspace = true clap.workspace = true env_logger.workspace = true log.workspace = true -pot.workspace = true reth-chainspec.workspace = true -serde.workspace = true -tokio.workspace = true -tracing.workspace = true [features] -metal = ["risc0-zkvm/metal"] -cuda = ["risc0-zkvm/cuda"] +debug-guest-build = ["zeth-guests/debug-guest-build"] disable-dev-mode = ["risc0-zkvm/disable-dev-mode"] -debug-guest-build = ["zeth-guests/debug-guest-build"] \ No newline at end of file +cuda = ["risc0-zkvm/cuda"] +metal = ["risc0-zkvm/metal"] +prove = ["risc0-zkvm/prove"] diff --git a/crates/zeth/src/executor.rs b/crates/zeth/src/executor.rs index 40d048a9..80d75005 100644 --- a/crates/zeth/src/executor.rs +++ b/crates/zeth/src/executor.rs @@ -25,7 +25,7 @@ pub fn build_executor_env<'b>( ) -> anyhow::Result> { let run_args = cli.run_args(); let mut builder = ExecutorEnv::builder(); - builder.write_slice(&witness.encoded_input); + builder.write_frame(&witness.encoded_input); builder.segment_limit_po2(run_args.execution_po2); if run_args.profile { if std::env::var("RISC0_PPROF_OUT").is_ok() { diff --git a/crates/zeth/src/lib.rs b/crates/zeth/src/lib.rs index b3da7b1a..4200acbf 100644 --- a/crates/zeth/src/lib.rs +++ b/crates/zeth/src/lib.rs @@ -23,7 +23,6 @@ use risc0_zkvm::{default_executor, default_prover, is_dev_mode, ProverOpts, Rece use std::fs::File; use std::io::{Read, Write}; use std::path::{Path, PathBuf}; -use tokio::runtime::Handle; use zeth_core::driver::CoreDriver; use zeth_core::keccak::keccak; use zeth_core::rescue::Recoverable; @@ -33,7 +32,7 @@ use zeth_preflight::BlockBuilder; pub mod cli; pub mod executor; -pub fn run< +pub async fn run< B: BlockBuilder + Send + Sync + 'static, N: Network, D: Recoverable + 'static, @@ -63,14 +62,16 @@ where .cache .as_ref() .map(|dir| cache_dir_path(dir, network_name)); + // select a guest program - let expected_journal = Handle::current().block_on(B::build_journal( + let expected_journal = B::build_journal( chain_id, cache_dir.clone(), build_args.rpc.clone(), build_args.block_number, build_args.block_count, - ))?; + ) + .await?; info!("Journal prepared."); if !cli.should_build() { @@ -113,13 +114,14 @@ where } // preflight the block building process - let build_result = Handle::current().block_on(B::build_blocks( + let build_result = B::build_blocks( chain_id, cache_dir.clone(), build_args.rpc.clone(), build_args.block_number, build_args.block_count, - ))?; + ) + .await?; if !cli.should_execute() { return Ok(()); diff --git a/guests/reth-ethereum/Cargo.lock b/guests/reth-ethereum/Cargo.lock index 892aa8a2..abc1a075 100644 --- a/guests/reth-ethereum/Cargo.lock +++ b/guests/reth-ethereum/Cargo.lock @@ -23,12 +23,6 @@ dependencies = [ "memchr", ] -[[package]] -name = "allocator-api2" -version = "0.2.18" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5c6cb57a04249c6480766f7f7cef5467412af1490f8d1e243141daddada3264f" - [[package]] name = "alloy-chains" version = "0.1.43" @@ -999,6 +993,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f55bf8e7b65898637379c1b74eb1551107c8294ed26d855ceb9fd1a09cfc9bc0" dependencies = [ "const-oid", + "pem-rfc7468", "zeroize", ] @@ -1094,6 +1089,7 @@ dependencies = [ "digest 0.10.7", "elliptic-curve", "rfc6979", + "serdect", "signature", "spki", ] @@ -1122,9 +1118,11 @@ dependencies = [ "ff", "generic-array", "group", + "pem-rfc7468", "pkcs8", "rand_core", "sec1", + "serdect", "subtle", "zeroize", ] @@ -1372,8 +1370,6 @@ version = "0.15.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1e087f84d4f86bf4b218b927129862374b72199ae7d8657835f1e89000eea4fb" dependencies = [ - "allocator-api2", - "equivalent", "foldhash", "serde", ] @@ -1554,7 +1550,9 @@ dependencies = [ "elliptic-curve", "once_cell", "risc0-bigint2", + "serdect", "sha2", + "signature", ] [[package]] @@ -1896,6 +1894,15 @@ version = "1.0.15" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "57c0d7b74b563b49d38dae00a0c37d4d6de9b432382b2892f0574ddcae73fd0a" +[[package]] +name = "pem-rfc7468" +version = "0.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "88b39c9bfcfc231068454382784bb460aae594343fb030d46e9f50a645418412" +dependencies = [ + "base64ct", +] + [[package]] name = "percent-encoding" version = "2.3.1" @@ -2974,6 +2981,7 @@ dependencies = [ "der", "generic-array", "pkcs8", + "serdect", "subtle", "zeroize", ] @@ -3084,6 +3092,16 @@ dependencies = [ "syn 2.0.85", ] +[[package]] +name = "serdect" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a84f14a19e9a014bb9f4512488d9829a68e04ecabffb0f9904cd1ace94598177" +dependencies = [ + "base16ct", + "serde", +] + [[package]] name = "sha2" version = "0.10.6" @@ -3772,13 +3790,9 @@ dependencies = [ "alloy-primitives", "alloy-rlp", "anyhow", - "hashbrown 0.15.0", + "k256", "pot", "reth-chainspec", - "reth-consensus", - "reth-ethereum-consensus", - "reth-evm", - "reth-evm-ethereum", "reth-primitives", "reth-revm", "reth-storage-errors", @@ -3791,7 +3805,10 @@ dependencies = [ name = "zeth-core-ethereum" version = "0.1.0" dependencies = [ + "alloy-genesis", "anyhow", + "k256", + "once_cell", "reth-chainspec", "reth-consensus", "reth-ethereum-consensus", diff --git a/guests/reth-ethereum/src/main.rs b/guests/reth-ethereum/src/main.rs index 7a275973..9958808f 100644 --- a/guests/reth-ethereum/src/main.rs +++ b/guests/reth-ethereum/src/main.rs @@ -14,7 +14,6 @@ // use c_kzg::KzgSettings; use risc0_zkvm::guest::env; -use risc0_zkvm::guest::env::stdin; use zeth_core::stateless::client::StatelessClient; use zeth_core_ethereum::RethStatelessClient; // todo: use this instead of the alloy KzgEnv to save cycles @@ -34,7 +33,9 @@ pub extern "C" fn __ctzsi2(x: u32) -> usize { fn main() { // todo: load up revm with hashbrown feat - let stateless_client_data = RethStatelessClient::deserialize_data(stdin()) + let stateless_client_data_pot = env::read_frame(); + env::log("Deserializing input data"); + let stateless_client_data = RethStatelessClient::data_from_slice(&stateless_client_data_pot) .expect("Failed to load client data from stdin"); let validation_depth = stateless_client_data.blocks.len() as u64; assert!(stateless_client_data.chain.is_ethereum(), "This program only supports Ethereum chains"); diff --git a/guests/reth-optimism/Cargo.lock b/guests/reth-optimism/Cargo.lock index 416722f3..c4cba3ac 100644 --- a/guests/reth-optimism/Cargo.lock +++ b/guests/reth-optimism/Cargo.lock @@ -23,12 +23,6 @@ dependencies = [ "memchr", ] -[[package]] -name = "allocator-api2" -version = "0.2.18" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5c6cb57a04249c6480766f7f7cef5467412af1490f8d1e243141daddada3264f" - [[package]] name = "alloy-chains" version = "0.1.43" @@ -110,18 +104,6 @@ dependencies = [ "serde", ] -[[package]] -name = "alloy-json-abi" -version = "0.8.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d46eb5871592c216d39192499c95a99f7175cb94104f88c307e6dc960676d9f1" -dependencies = [ - "alloy-primitives", - "alloy-sol-type-parser", - "serde", - "serde_json", -] - [[package]] name = "alloy-network-primitives" version = "0.4.2" @@ -275,27 +257,15 @@ dependencies = [ "syn-solidity", ] -[[package]] -name = "alloy-sol-type-parser" -version = "0.8.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f631f0bd9a9d79619b27c91b6b1ab2c4ef4e606a65192369a1ee05d40dcf81cc" -dependencies = [ - "serde", - "winnow", -] - [[package]] name = "alloy-sol-types" version = "0.8.8" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c2841af22d99e2c0f82a78fe107b6481be3dd20b89bfb067290092794734343a" dependencies = [ - "alloy-json-abi", "alloy-primitives", "alloy-sol-macro", "const-hex", - "serde", ] [[package]] @@ -999,6 +969,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f55bf8e7b65898637379c1b74eb1551107c8294ed26d855ceb9fd1a09cfc9bc0" dependencies = [ "const-oid", + "pem-rfc7468", "zeroize", ] @@ -1094,6 +1065,7 @@ dependencies = [ "digest 0.10.7", "elliptic-curve", "rfc6979", + "serdect", "signature", "spki", ] @@ -1122,9 +1094,11 @@ dependencies = [ "ff", "generic-array", "group", + "pem-rfc7468", "pkcs8", "rand_core", "sec1", + "serdect", "subtle", "zeroize", ] @@ -1372,8 +1346,6 @@ version = "0.15.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1e087f84d4f86bf4b218b927129862374b72199ae7d8657835f1e89000eea4fb" dependencies = [ - "allocator-api2", - "equivalent", "foldhash", "serde", ] @@ -1554,7 +1526,9 @@ dependencies = [ "elliptic-curve", "once_cell", "risc0-bigint2", + "serdect", "sha2", + "signature", ] [[package]] @@ -1908,6 +1882,15 @@ version = "1.0.15" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "57c0d7b74b563b49d38dae00a0c37d4d6de9b432382b2892f0574ddcae73fd0a" +[[package]] +name = "pem-rfc7468" +version = "0.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "88b39c9bfcfc231068454382784bb460aae594343fb030d46e9f50a645418412" +dependencies = [ + "base64ct", +] + [[package]] name = "percent-encoding" version = "2.3.1" @@ -2305,19 +2288,6 @@ dependencies = [ "serde", ] -[[package]] -name = "reth-ethereum-consensus" -version = "1.1.0" -source = "git+https://github.com/risc0/reth?branch=p1.1.0_zstd#49b1950fa8e368537b23f5f580637aa6f712e60c" -dependencies = [ - "alloy-primitives", - "reth-chainspec", - "reth-consensus", - "reth-consensus-common", - "reth-primitives", - "tracing", -] - [[package]] name = "reth-ethereum-forks" version = "1.1.0" @@ -2357,25 +2327,6 @@ dependencies = [ "revm-primitives", ] -[[package]] -name = "reth-evm-ethereum" -version = "1.1.0" -source = "git+https://github.com/risc0/reth?branch=p1.1.0_zstd#49b1950fa8e368537b23f5f580637aa6f712e60c" -dependencies = [ - "alloy-eips", - "alloy-primitives", - "alloy-sol-types", - "reth-chainspec", - "reth-ethereum-consensus", - "reth-ethereum-forks", - "reth-evm", - "reth-execution-types", - "reth-primitives", - "reth-prune-types", - "reth-revm", - "revm-primitives", -] - [[package]] name = "reth-execution-errors" version = "1.1.0" @@ -3070,6 +3021,7 @@ dependencies = [ "der", "generic-array", "pkcs8", + "serdect", "subtle", "zeroize", ] @@ -3180,6 +3132,16 @@ dependencies = [ "syn 2.0.85", ] +[[package]] +name = "serdect" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a84f14a19e9a014bb9f4512488d9829a68e04ecabffb0f9904cd1ace94598177" +dependencies = [ + "base16ct", + "serde", +] + [[package]] name = "sha2" version = "0.10.6" @@ -3868,13 +3830,9 @@ dependencies = [ "alloy-primitives", "alloy-rlp", "anyhow", - "hashbrown 0.15.0", + "k256", "pot", "reth-chainspec", - "reth-consensus", - "reth-ethereum-consensus", - "reth-evm", - "reth-evm-ethereum", "reth-primitives", "reth-revm", "reth-storage-errors", @@ -3887,7 +3845,11 @@ dependencies = [ name = "zeth-core-optimism" version = "0.1.0" dependencies = [ + "alloy-genesis", "anyhow", + "k256", + "once_cell", + "op-alloy-consensus", "reth-chainspec", "reth-consensus", "reth-evm", diff --git a/guests/reth-optimism/src/main.rs b/guests/reth-optimism/src/main.rs index 1eabd0dd..9a5f85cd 100644 --- a/guests/reth-optimism/src/main.rs +++ b/guests/reth-optimism/src/main.rs @@ -14,7 +14,6 @@ // use c_kzg::KzgSettings; use risc0_zkvm::guest::env; -use risc0_zkvm::guest::env::stdin; use zeth_core::stateless::client::StatelessClient; use zeth_core_optimism::OpRethStatelessClient; // todo: use this instead of the alloy KzgEnv to save cycles @@ -34,7 +33,9 @@ pub extern "C" fn __ctzsi2(x: u32) -> usize { fn main() { // todo: load up revm with hashbrown feat - let stateless_client_data = OpRethStatelessClient::deserialize_data(stdin()) + let stateless_client_data_pot = env::read_frame(); + env::log("Deserializing input data"); + let stateless_client_data = OpRethStatelessClient::data_from_slice(&stateless_client_data_pot) .expect("Failed to load client data from stdin"); let validation_depth = stateless_client_data.blocks.len() as u64; assert!(stateless_client_data.chain.is_optimism(), "This program only supports Optimism chains"); diff --git a/justfile b/justfile index cd0b53f6..eaebbf54 100644 --- a/justfile +++ b/justfile @@ -40,6 +40,7 @@ test: cargo test --all-targets -p zeth-testeth -F ef-tests just test-cache-eth + just test-cache-op test-cache-eth: (build "") RUST_LOG=info RISC0_DEV_MODE=1 ./target/debug/zeth-ethereum build --cache=bin/ethereum/data -b=1 @@ -58,3 +59,6 @@ test-cache-eth: (build "") RUST_LOG=info RISC0_DEV_MODE=1 ./target/debug/zeth-ethereum build --cache=bin/ethereum/data -b=15537394 RUST_LOG=info RISC0_DEV_MODE=1 ./target/debug/zeth-ethereum build --cache=bin/ethereum/data -b=17034870 RUST_LOG=info RISC0_DEV_MODE=1 ./target/debug/zeth-ethereum build --cache=bin/ethereum/data -b=19426587 + +test-cache-op: (build "") + RUST_LOG=info ./target/debug/zeth-optimism build --cache=bin/optimism/data -c=optimism-sepolia -b=17664000 \ No newline at end of file diff --git a/testing/ef-tests/Cargo.toml b/testing/ef-tests/Cargo.toml index 34a33d2c..4794d3d6 100644 --- a/testing/ef-tests/Cargo.toml +++ b/testing/ef-tests/Cargo.toml @@ -4,8 +4,8 @@ version = "0.1.0" edition = "2021" [features] -ef-tests = [] cuda = [] +ef-tests = [] metal = [] [dependencies] diff --git a/testing/ef-tests/src/driver.rs b/testing/ef-tests/src/driver.rs index 0c56417a..7c451887 100644 --- a/testing/ef-tests/src/driver.rs +++ b/testing/ef-tests/src/driver.rs @@ -1,3 +1,4 @@ +use alloy::signers::k256::ecdsa::VerifyingKey; use alloy::{ eips::eip1559::BaseFeeParams, network::{Ethereum, Network}, @@ -164,12 +165,14 @@ where fn execute_transactions( chain_spec: Arc, block: &mut reth_primitives::Block, + signers: &[VerifyingKey], total_difficulty: &mut U256, db: &mut Option, ) -> anyhow::Result { >::execute_transactions( chain_spec, block, + signers, total_difficulty, db, ) @@ -243,4 +246,8 @@ impl PreflightDriver for RethPreflightDriver { data, ommers, ) } + + fn recover_signers(block: &::Block) -> Vec { + >::recover_signers(block) + } } diff --git a/testing/ef-tests/tests/evm.rs b/testing/ef-tests/tests/evm.rs index 532f142e..daf9a662 100644 --- a/testing/ef-tests/tests/evm.rs +++ b/testing/ef-tests/tests/evm.rs @@ -74,7 +74,7 @@ where assert_eq!(build_result.validated_tip_hash, expected_hash); let deserialized_preflight_data = - R::StatelessClient::deserialize_data(build_result.encoded_input.as_slice()) + R::StatelessClient::data_from_reader(build_result.encoded_input.as_slice()) .expect("Input deserialization failed"); R::StatelessClient::validate(deserialized_preflight_data).expect("Block validation failed");