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

Perf: nondet sigs + genesis serde #124

Merged
merged 17 commits into from
Dec 12, 2024
Merged
Show file tree
Hide file tree
Changes from 12 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
352 changes: 205 additions & 147 deletions Cargo.lock

Large diffs are not rendered by default.

17 changes: 9 additions & 8 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,15 @@ opt-level = 3

# RISC Zero
[workspace.dependencies.bonsai-sdk]
version = "1.1.3"
version = "1.2.1-rc.0"
features = ["non_blocking"]

[workspace.dependencies.risc0-build]
version = "1.1.3"
version = "1.2.1-rc.0"
features = ["unstable"]

[workspace.dependencies.risc0-zkvm]
version = "1.1.3"
version = "1.2.1-rc.0"
default-features = false

# External
Expand All @@ -38,12 +39,11 @@ default-features = false
alloy = { version = "0.4.2", features = ["full"] }
alloy-chains = "0.1.38"
alloy-consensus = "0.4.2"
alloy-primitives = { version = "0.8.8", default-features = false }
alloy-genesis = "0.4.2"
alloy-primitives = { version = "0.8.8", default-features = false, features = ["k256"] }
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
Expand Down Expand Up @@ -77,13 +77,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"] }
thiserror = "1.0.64"
tiny-keccak = "2.0.2"
tokio = { version = "1.40.0", features = ["full"] }
tokio = { version = "1.41.0", features = ["full"] }
tracing = { version = "0.1.40", features = ["log"] }
5 changes: 3 additions & 2 deletions bin/benchmark/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ 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"]
16 changes: 4 additions & 12 deletions bin/ethereum/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
cuda = ["zeth/cuda"]
metal = ["zeth/metal"]
prove = ["zeth/prove"]
Binary file added bin/ethereum/data/ethereum/1-21231350.json.gz
Binary file not shown.
17 changes: 7 additions & 10 deletions bin/ethereum/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::<RethBlockBuilder, _, _, _, _>(
ZETH_GUESTS_RETH_ETHEREUM_ELF,
ZETH_GUESTS_RETH_ETHEREUM_ID,
NamedChain::Mainnet,
"ethereum",
)
})
.await?
zeth::run::<RethBlockBuilder, _, _, _, _>(
ZETH_GUESTS_RETH_ETHEREUM_ELF,
ZETH_GUESTS_RETH_ETHEREUM_ID,
NamedChain::Mainnet,
"ethereum",
)
.await
}
16 changes: 4 additions & 12 deletions bin/optimism/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
cuda = ["zeth/cuda"]
metal = ["zeth/metal"]
prove = ["zeth/prove"]
Binary file not shown.
17 changes: 7 additions & 10 deletions bin/optimism/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::<OpRethBlockBuilder, _, _, _, _>(
ZETH_GUESTS_RETH_OPTIMISM_ELF,
ZETH_GUESTS_RETH_OPTIMISM_ID,
NamedChain::Optimism,
"optimism",
)
})
.await?
zeth::run::<OpRethBlockBuilder, _, _, _, _>(
ZETH_GUESTS_RETH_OPTIMISM_ELF,
ZETH_GUESTS_RETH_OPTIMISM_ID,
NamedChain::Optimism,
"optimism",
)
.await
}
3 changes: 3 additions & 0 deletions crates/core-ethereum/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
143 changes: 143 additions & 0 deletions crates/core-ethereum/src/chain_spec.rs
Original file line number Diff line number Diff line change
@@ -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<Arc<ChainSpec>> = 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(),
// <https://etherscan.io/block/15537394>
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<Arc<ChainSpec>> = 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(),
// <https://sepolia.etherscan.io/block/1450409>
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<Arc<ChainSpec>> = 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<Arc<ChainSpec>> = 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()
});
20 changes: 15 additions & 5 deletions crates/core-ethereum/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,12 @@
// 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::VerifyingKey;
use reth_chainspec::{ChainSpec, NamedChain};
use reth_consensus::Consensus;
use reth_ethereum_consensus::EthBeaconConsensus;
use reth_evm::execute::{
Expand All @@ -30,6 +34,7 @@ use std::mem::take;
use std::sync::Arc;
use zeth_core::db::MemoryDB;
use zeth_core::driver::CoreDriver;
use zeth_core::recover_sender;
use zeth_core::stateless::client::StatelessClient;
use zeth_core::stateless::execute::ExecutionStrategy;
use zeth_core::stateless::finalize::RethFinalizationStrategy;
Expand Down Expand Up @@ -98,17 +103,22 @@ where
fn execute_transactions(
chain_spec: Arc<ChainSpec>,
block: &mut Block,
signers: &[VerifyingKey],
total_difficulty: &mut U256,
db: &mut Option<Database>,
) -> anyhow::Result<BundleState> {
// Instantiate execution engine using database
let mut executor = EthExecutorProvider::ethereum(chain_spec.clone())
.batch_executor(db.take().expect("Missing database."));
// Recover transaction signer addresses with non-det vk hints
let senders = core::iter::zip(signers, block.body.transactions())
.map(|(vk, tx)| {
recover_sender(vk, *tx.signature(), tx.signature_hash())
.expect("Sender recovery failed")
})
.collect::<Vec<_>>();
// 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,
Expand Down
3 changes: 3 additions & 0 deletions crates/core-optimism/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading
Loading