Skip to content

Commit

Permalink
Merge pull request risc0#44 from taikoxyz/multi-guests-input-4844
Browse files Browse the repository at this point in the history
Multi guests input 4844
  • Loading branch information
Brechtpd authored Mar 5, 2024
2 parents aaacc7b + ee1d37c commit 7facea3
Show file tree
Hide file tree
Showing 43 changed files with 3,367 additions and 733 deletions.
1,089 changes: 791 additions & 298 deletions Cargo.lock

Large diffs are not rendered by default.

12 changes: 10 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,13 @@ lto = true
[profile.release.build-override]
opt-level = 3

[patch.crates-io]
# use optimized risc0 circuit
revm = { git = "https://github.com/johntaiko/revm", branch = "feat/taiko" }
revm-primitives = { git = "https://github.com/johntaiko/revm", branch = "feat/taiko" }
ethers-core = { git = "https://github.com/smtmfft/ethers-rs", branch = "ethers-core-2.0.10" }
ethers-providers = { git = "https://github.com/smtmfft/ethers-rs", branch = "ethers-core-2.0.10" }
ethers-contract = { git = "https://github.com/smtmfft/ethers-rs", branch = "ethers-core-2.0.10" }


[workspace.dependencies]
Expand All @@ -35,5 +42,6 @@ hashbrown = { version = "0.14", features = ["inline-more"] }
risc0-build = "0.19"
risc0-zkvm = { version = "0.19", default-features = false }
revm-primitives = { git = "https://github.com/ceciliaz030/revm.git", branch = "sync-taiko-v3.5", default_features = false }
revm = { git = "https://github.com/ceciliaz030/revm.git", branch = "sync-taiko-v3.5", default-features = false, features = ["serde"] }

revm = { git = "https://github.com/ceciliaz030/revm.git", branch = "sync-taiko-v3.5", default-features = false, features = [
"serde",
] }
39 changes: 22 additions & 17 deletions lib/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,28 +18,37 @@ alloy-primitives = { version = "0.6", default-features = false, features = [
alloy-rpc-types = { git = "https://github.com/alloy-rs/alloy", version = "0.1.0" }
alloy-providers = { git = "https://github.com/alloy-rs/alloy", version = "0.1.0" }
alloy-transport-http = { git = "https://github.com/alloy-rs/alloy", version = "0.1.0" }
bytes = {version = "1.5", default-features = false}
bytes = { version = "1.5", default-features = false }
hashbrown = { workspace = true }
libflate = {version = "2.0.0", optional = true}
libflate = { version = "2.0.0", optional = true }
once_cell = { version = "1.18", default-features = false }
revm = { workspace = true, default-features = false }
ruint = { version = "1.10", default-features = false }
serde = { version = "1.0", default-features = false, features = ["alloc"] }
thiserror-no-std = "2.0.2"
zeth-primitives = { path = "../primitives", features = ["revm"] }
hex = { version = "0.4.3", default-features = false, optional = true}
reth-primitives = { git = "https://github.com/paradigmxyz/reth.git", branch = "main", features = [
"c-kzg",
] }
hex = { version = "0.4.3", default-features = false, optional = true }
url = "2.5.0"
reqwest = "0.11.22"
sha2 = "0.10.8"
proptest = "1.4.0"
c-kzg = "0.4.0"

# [target.'cfg(feature = "std")'.dependencies]
ethers-core = { version = "2.0", optional = true }
thiserror = {version = "1.0", optional = true}
chrono = { version = "0.4", default-features = false , optional = true}
flate2 = {version = "1.0.26", optional = true}
log = {version = "0.4", optional = true}
serde_json = { version = "1.0", default-features = false, features = ["alloc"] , optional = true}
serde_with = {version = "3.0", optional = true}
tokio = { version = "1.23", features = ["full"], optional = true}
ethers-providers = { version = "2.0", default-features = false, optional = true }
thiserror = { version = "1.0", optional = true }
chrono = { version = "0.4", default-features = false, optional = true }
flate2 = { version = "1.0.26", optional = true }
log = { version = "0.4", optional = true }
serde_json = { version = "1.0", default-features = false, features = [
"alloc",
], optional = true }
serde_with = { version = "3.0", optional = true }
tokio = { version = "1.23", features = ["full"], optional = true }

[dev-dependencies]
bincode = "1.3"
Expand All @@ -60,13 +69,9 @@ std = [
"dep:serde_with",
# "dep:tokio",
"zeth-primitives/ethers",
]
]
rpc = ["dep:ethers-providers", "dep:tokio"]
taiko = [
"zeth-primitives/taiko",
"revm/taiko",
"dep:hex",
]
taiko = ["zeth-primitives/taiko", "revm/taiko", "dep:hex"]
optimism = [
"std",
"dep:ethers-core",
Expand All @@ -75,4 +80,4 @@ optimism = [
"ethers-providers/optimism",
"zeth-primitives/optimism",
"revm/optimism",
]
]
19 changes: 16 additions & 3 deletions lib/src/builder/execute/taiko.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,21 @@ use revm::{
};
use ruint::aliases::U256;
use zeth_primitives::{
mpt::MptNode, receipt::Receipt, transactions::{ethereum::{EthereumTxEssence, TransactionKind}, TxEssence}, Bloom, RlpBytes
mpt::MptNode,
receipt::Receipt,
transactions::{
ethereum::{EthereumTxEssence, TransactionKind},
TxEssence,
},
Bloom, RlpBytes,
};

use super::TxExecStrategy;
use crate::{
builder::BlockBuilder,
consts::{self, ChainSpec, GWEI_TO_WEI},
guest_mem_forget, taiko_utils::check_anchor_tx,
guest_mem_forget,
taiko_utils::check_anchor_tx,
};

/// Minimum supported protocol version: Bedrock (Block no. 105235063).
Expand Down Expand Up @@ -128,7 +135,13 @@ impl TxExecStrategy<EthereumTxEssence> for TkoTxExecStrategy {
.with_context(|| anyhow!("Error recovering address for transaction {tx_no}"))?;

if is_anchor {
check_anchor_tx(&block_builder.input, &tx, &tx_from,&block_builder.input.taiko.chain_spec_name).expect("invalid anchor tx");
check_anchor_tx(
&block_builder.input,
&tx,
&tx_from,
&block_builder.input.taiko.chain_spec_name,
)
.expect("invalid anchor tx");
}

#[cfg(feature = "std")]
Expand Down
5 changes: 4 additions & 1 deletion lib/src/builder/finalize.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,10 @@ use core::mem;
use anyhow::Result;
use revm::{Database, DatabaseCommit};
use zeth_primitives::{
block::Header, keccak::keccak, mpt::{MptNode, StateAccount}, transactions::TxEssence
block::Header,
keccak::keccak,
mpt::{MptNode, StateAccount},
transactions::TxEssence,
};

use crate::{
Expand Down
5 changes: 4 additions & 1 deletion lib/src/builder/initialize.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,10 @@ use revm::{
Database, DatabaseCommit,
};
use zeth_primitives::{
keccak::{keccak, KECCAK_EMPTY}, mpt::StateAccount, transactions::TxEssence, Bytes
keccak::{keccak, KECCAK_EMPTY},
mpt::StateAccount,
transactions::TxEssence,
Bytes,
};

use crate::{
Expand Down
13 changes: 8 additions & 5 deletions lib/src/builder/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@
use anyhow::Result;
use revm::{Database, DatabaseCommit};
use zeth_primitives::{
block::Header, mpt::MptNode, transactions::{ethereum::EthereumTxEssence, TxEssence}
block::Header,
mpt::MptNode,
transactions::{ethereum::EthereumTxEssence, TxEssence},
};

#[cfg(feature = "taiko")]
Expand All @@ -26,7 +28,10 @@ use crate::{
finalize::{BlockFinalizeStrategy, MemDbBlockFinalizeStrategy},
initialize::{DbInitStrategy, MemDbInitStrategy},
prepare::{EthHeaderPrepStrategy, HeaderPrepStrategy},
}, consts::{get_chain_spec, ChainSpec}, input::GuestInput, mem_db::MemDb
},
consts::{get_chain_spec, ChainSpec},
input::GuestInput,
mem_db::MemDb,
};

mod execute;
Expand Down Expand Up @@ -106,9 +111,7 @@ pub trait BlockBuilderStrategy {
type BlockFinalizeStrategy: BlockFinalizeStrategy<MemDb>;

/// Builds a block from the given input.
fn build_from(
input: GuestInput<Self::TxEssence>,
) -> Result<(Header, MptNode)> {
fn build_from(input: GuestInput<Self::TxEssence>) -> Result<(Header, MptNode)> {
BlockBuilder::<MemDb, Self::TxEssence>::new(input)
.initialize_database::<Self::DbInitStrategy>()?
.prepare_header::<Self::HeaderPrepStrategy>()?
Expand Down
57 changes: 25 additions & 32 deletions lib/src/consts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,7 @@
//! Constants for the Ethereum protocol.
extern crate alloc;

use alloc::{
collections::BTreeMap,
str::FromStr,
};
use alloc::{collections::BTreeMap, str::FromStr};

use anyhow::bail;
use once_cell::unsync::Lazy;
Expand Down Expand Up @@ -66,37 +63,33 @@ pub const ETH_MAINNET_CHAIN_SPEC: Lazy<ChainSpec> = Lazy::new(|| {
});

/// The Taiko testnet specification.
const TKO_TESTNET_CHAIN_SPEC: Lazy<ChainSpec> = Lazy::new(|| {
ChainSpec {
chain_id: 167008,
hard_forks: BTreeMap::from([
(SpecId::SHANGHAI, ForkCondition::Block(0)),
(SpecId::CANCUN, ForkCondition::TBD),
]),
eip_1559_constants: Eip1559Constants {
base_fee_change_denominator: uint!(8_U256),
base_fee_max_increase_denominator: uint!(8_U256),
base_fee_max_decrease_denominator: uint!(8_U256),
elasticity_multiplier: uint!(2_U256),
},
}
pub const TKO_TESTNET_CHAIN_SPEC: Lazy<ChainSpec> = Lazy::new(|| ChainSpec {
chain_id: 167008,
hard_forks: BTreeMap::from([
(SpecId::SHANGHAI, ForkCondition::Block(0)),
(SpecId::CANCUN, ForkCondition::TBD),
]),
eip_1559_constants: Eip1559Constants {
base_fee_change_denominator: uint!(8_U256),
base_fee_max_increase_denominator: uint!(8_U256),
base_fee_max_decrease_denominator: uint!(8_U256),
elasticity_multiplier: uint!(2_U256),
},
});

/// The Taiko testnet specification.
const TKO_DEVNETA_CHAIN_SPEC: Lazy<ChainSpec> = Lazy::new(|| {
ChainSpec {
chain_id: 167001,
hard_forks: BTreeMap::from([
(SpecId::SHANGHAI, ForkCondition::Block(0)),
(SpecId::CANCUN, ForkCondition::TBD),
]),
eip_1559_constants: Eip1559Constants {
base_fee_change_denominator: uint!(8_U256),
base_fee_max_increase_denominator: uint!(8_U256),
base_fee_max_decrease_denominator: uint!(8_U256),
elasticity_multiplier: uint!(2_U256),
},
}
pub const TKO_DEVNETA_CHAIN_SPEC: Lazy<ChainSpec> = Lazy::new(|| ChainSpec {
chain_id: 167001,
hard_forks: BTreeMap::from([
(SpecId::SHANGHAI, ForkCondition::Block(0)),
(SpecId::CANCUN, ForkCondition::TBD),
]),
eip_1559_constants: Eip1559Constants {
base_fee_change_denominator: uint!(8_U256),
base_fee_max_increase_denominator: uint!(8_U256),
base_fee_max_decrease_denominator: uint!(8_U256),
elasticity_multiplier: uint!(2_U256),
},
});

pub fn get_chain_spec(name: &str) -> ChainSpec {
Expand Down
Loading

0 comments on commit 7facea3

Please sign in to comment.