Skip to content

Commit

Permalink
Skip missing Cancun bits for non Eth mainnet chains (#605)
Browse files Browse the repository at this point in the history
  • Loading branch information
Nashtare authored Sep 12, 2024
1 parent 4ef831b commit fec2365
Show file tree
Hide file tree
Showing 33 changed files with 198 additions and 777 deletions.
7 changes: 7 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

19 changes: 19 additions & 0 deletions common/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,25 @@ pub const EMPTY_TRIE_HASH: H256 = H256([
108, 173, 192, 1, 98, 47, 181, 227, 99, 180, 33,
]);

#[macro_export]
/// A convenience macro to check the feature flags activating chain specific
/// behaviors. Only one of these flags may be activated at a time.
macro_rules! check_chain_features {
() => {
#[cfg(any(
all(feature = "cdk_erigon", feature = "polygon_pos"),
all(feature = "cdk_erigon", feature = "eth_mainnet"),
all(feature = "polygon_pos", feature = "eth_mainnet"),
not(any(
feature = "cdk_erigon",
feature = "eth_mainnet",
feature = "polygon_pos"
))
))]
compile_error!("One and only one of the feature chains `cdk_erigon`, `polygon_pos` or `eth_mainnet` must be selected");
};
}

/// Converts an amount in `ETH` to `wei` units.
pub fn eth_to_wei(eth: U256) -> U256 {
// 1 ether = 10^18 wei.
Expand Down
2 changes: 1 addition & 1 deletion evm_arithmetization/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@ serde-big-array = { workspace = true }
# Local dependencies
mpt_trie = { workspace = true }
smt_trie = { workspace = true, optional = true }
zk_evm_proc_macro = { workspace = true }
zk_evm_common = { workspace = true }
zk_evm_proc_macro = { workspace = true }

[dev-dependencies]
criterion = { workspace = true }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ global handle_precompiles:
{
%eq_const(@BLAKE2_F) %jumpi(precompile_blake2_f)
}
// TODO: Add support of EIP-7712 for Polygon Pos, https://github.com/0xPolygonZero/zk_evm/issues/265
// stack: retdest
JUMP

Expand Down
16 changes: 14 additions & 2 deletions evm_arithmetization/src/cpu/kernel/asm/core/util.asm
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,20 @@

%macro is_precompile
// stack: addr
DUP1 %ge_const(@ECREC) SWAP1 %le_const(@KZG_PEVAL)
// stack: addr>=1, addr<=10
DUP1 %ge_const(@ECREC)
SWAP1
// stack: addr, addr>=1
#[cfg(feature = eth_mainnet)]
{
%le_const(@KZG_PEVAL)
// stack: addr>=1, addr<=10
}
// TODO: Update after support of EIP-7712 for Polygon Pos, https://github.com/0xPolygonZero/zk_evm/issues/265
#[cfg(not(feature = eth_mainnet))]
{
%le_const(@BLAKE2_F)
// stack: addr>=1, addr<=9
}
MUL // Cheaper than AND
%endmacro

Expand Down
5 changes: 2 additions & 3 deletions evm_arithmetization/src/generation/mod.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
use std::collections::HashMap;

use anyhow::anyhow;
use ethereum_types::H160;
use ethereum_types::{Address, BigEndianHash, H256, U256};
use keccak_hash::keccak;
use log::log_enabled;
Expand Down Expand Up @@ -73,7 +72,7 @@ pub struct GenerationInputs<F: RichField> {
/// `None`, then the base fee is directly burnt.
///
/// Note: this is only used when feature `cdk_erigon` is activated.
pub burn_addr: Option<H160>,
pub burn_addr: Option<Address>,
/// Withdrawal pairs `(addr, amount)`. At the end of the txs, `amount` is
/// added to `addr`'s balance. See EIP-4895.
pub withdrawals: Vec<(Address, U256)>,
Expand Down Expand Up @@ -152,7 +151,7 @@ pub struct TrimmedGenerationInputs<F: RichField> {

/// Address where the burnt fees are stored. Only used if the `cfg_erigon`
/// feature is activated.
pub burn_addr: Option<H160>,
pub burn_addr: Option<Address>,

/// The hash of the current block, and a list of the 256 previous block
/// hashes.
Expand Down
11 changes: 1 addition & 10 deletions evm_arithmetization/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -183,16 +183,7 @@
#![allow(clippy::field_reassign_with_default)]
#![feature(let_chains)]

#[cfg_attr(
not(any(feature = "polygon_pos", feature = "cdk_erigon")),
cfg(feature = "eth_mainnet")
)]
#[cfg(any(
all(feature = "cdk_erigon", feature = "polygon_pos"),
all(feature = "cdk_erigon", feature = "eth_mainnet"),
all(feature = "polygon_pos", feature = "eth_mainnet"),
))]
compile_error!("Only a single network feature should be enabled at a time!");
zk_evm_common::check_chain_features!();

// Individual STARK processing units
pub mod arithmetic;
Expand Down
2 changes: 1 addition & 1 deletion evm_arithmetization/src/prover.rs
Original file line number Diff line number Diff line change
Expand Up @@ -475,7 +475,7 @@ pub fn check_abort_signal(abort_signal: Option<Arc<AtomicBool>>) -> Result<()> {
/// Sanity checks on the consistency between this proof payload and the feature
/// flags being used.
pub(crate) fn features_check<F: RichField>(inputs: &TrimmedGenerationInputs<F>) {
if cfg!(feature = "polygon_pos") || cfg!(feature = "cdk_erigon") {
if !cfg!(feature = "eth_mainnet") {
assert!(inputs.block_metadata.parent_beacon_block_root.is_zero());
assert!(inputs.block_metadata.block_blob_gas_used.is_zero());
assert!(inputs.block_metadata.block_excess_blob_gas.is_zero());
Expand Down
4 changes: 4 additions & 0 deletions proof_gen/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ hashbrown = { workspace = true }

# Local dependencies
evm_arithmetization = { workspace = true }
zk_evm_common = { workspace = true }

[features]
default = ["eth_mainnet"]
Expand All @@ -27,6 +28,9 @@ eth_mainnet = [
cdk_erigon = [
"evm_arithmetization/cdk_erigon"
]
polygon_pos = [
"evm_arithmetization/polygon_pos"
]

[lints]
workspace = true
2 changes: 2 additions & 0 deletions proof_gen/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,8 @@
//! assert!(verifier_state.verify(block_proof.intern).is_ok());
//! ```
zk_evm_common::check_chain_features!();

pub(crate) mod constants;
pub mod proof_gen;
pub mod proof_types;
Expand Down
17 changes: 15 additions & 2 deletions trace_decoder/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -62,17 +62,30 @@ serde_path_to_error = { workspace = true }

[features]
default = ["eth_mainnet"]
eth_mainnet = ["evm_arithmetization/eth_mainnet", "prover/eth_mainnet"]
cdk_erigon = ["evm_arithmetization/cdk_erigon", "prover/cdk_erigon"]
eth_mainnet = [
"evm_arithmetization/eth_mainnet",
"prover/eth_mainnet",
]
cdk_erigon = [
"evm_arithmetization/cdk_erigon",
"prover/cdk_erigon",
]
polygon_pos = [
"evm_arithmetization/polygon_pos",
"prover/polygon_pos",
]

[[bench]]
name = "block_processing"
harness = false
required-features = ["eth_mainnet"]

[[test]]
name = "consistent-with-header"
harness = false
required-features = ["eth_mainnet"]

[[test]]
name = "simulate-execution"
harness = false
required-features = ["eth_mainnet"]
2 changes: 1 addition & 1 deletion trace_decoder/benches/block_processing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ fn criterion_benchmark(c: &mut Criterion) {
block_trace,
other_data,
}| {
trace_decoder::entrypoint(block_trace, other_data, batch_size, false).unwrap()
trace_decoder::entrypoint(block_trace, other_data, batch_size).unwrap()
},
BatchSize::LargeInput,
)
Expand Down
4 changes: 2 additions & 2 deletions trace_decoder/src/core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ pub fn entrypoint(
trace: BlockTrace,
other: OtherBlockData,
batch_size_hint: usize,
use_burn_addr: bool,
) -> anyhow::Result<Vec<GenerationInputs<Field>>> {
ensure!(batch_size_hint != 0);

Expand All @@ -53,6 +52,7 @@ pub fn entrypoint(
},
checkpoint_state_trie_root,
checkpoint_consolidated_hash,
burn_addr,
} = other;

for (_, amt) in &mut withdrawals {
Expand Down Expand Up @@ -112,7 +112,7 @@ pub fn entrypoint(
.collect(),
block_metadata: b_meta.clone(),
block_hashes: b_hashes.clone(),
burn_addr: use_burn_addr.then_some(Address::zero()),
burn_addr,
},
)
.collect())
Expand Down
Loading

0 comments on commit fec2365

Please sign in to comment.