Skip to content

Commit

Permalink
Skip missing Cancun bits for non Eth mainnet chains
Browse files Browse the repository at this point in the history
  • Loading branch information
Nashtare committed Sep 6, 2024
1 parent 223a0d9 commit f03db41
Show file tree
Hide file tree
Showing 20 changed files with 220 additions and 36 deletions.
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 @@ -72,7 +71,7 @@ pub struct GenerationInputs {
/// `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 @@ -144,7 +143,7 @@ pub struct TrimmedGenerationInputs {

/// 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
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(inputs: &TrimmedGenerationInputs) {
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
3 changes: 3 additions & 0 deletions proof_gen/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ eth_mainnet = [
cdk_erigon = [
"evm_arithmetization/cdk_erigon"
]
polygon_pos = [
"evm_arithmetization/polygon_pos"
]

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

#[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!");

pub(crate) mod constants;
pub mod proof_gen;
pub mod proof_types;
Expand Down
4 changes: 4 additions & 0 deletions trace_decoder/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,10 @@ cdk_erigon = [
"evm_arithmetization/cdk_erigon",
"prover/cdk_erigon",
]
polygon_pos = [
"evm_arithmetization/polygon_pos",
"prover/polygon_pos",
]

[[bench]]
name = "block_processing"
Expand Down
52 changes: 39 additions & 13 deletions trace_decoder/src/decoding.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,17 @@ use std::{cmp::min, collections::HashMap, ops::Range};

use anyhow::{anyhow, Context as _};
use ethereum_types::H160;
use ethereum_types::{Address, BigEndianHash, H256, U256, U512};
use ethereum_types::{Address, H256, U256, U512};
#[cfg(feature = "eth_mainnet")]
use evm_arithmetization::testing_utils::{
BEACON_ROOTS_CONTRACT_ADDRESS, BEACON_ROOTS_CONTRACT_ADDRESS_HASHED, HISTORY_BUFFER_LENGTH,
};
use evm_arithmetization::{
generation::{
mpt::{decode_receipt, AccountRlp},
GenerationInputs, TrieInputs,
},
proof::{BlockMetadata, ExtraBlockData, TrieRoots},
testing_utils::{
BEACON_ROOTS_CONTRACT_ADDRESS, BEACON_ROOTS_CONTRACT_ADDRESS_HASHED, HISTORY_BUFFER_LENGTH,
},
proof::{ExtraBlockData, TrieRoots},
};
use mpt_trie::{
nibbles::Nibbles,
Expand Down Expand Up @@ -113,15 +114,35 @@ pub fn into_txn_proof_gen_ir(
Ok(txn_gen_inputs)
}

/// Includes additional state and storage updates for pre-block execution.
#[allow(unused)]
fn pre_block_execution(
trie_state: &mut PartialTrieState<impl StateTrie>,
delta_out: &mut TrieDeltaApplicationOutput,
nodes_used: &mut NodesUsedByTxnBatch,
block_data: &evm_arithmetization::proof::BlockMetadata,
) -> anyhow::Result<()> {
#[cfg(feature = "eth_mainnet")]
return update_beacon_block_root_contract_storage(
trie_state, delta_out, nodes_used, block_data,
);

#[cfg(not(feature = "eth_mainnet"))]
Ok(())
}

#[cfg(feature = "eth_mainnet")]
/// Cancun HF specific: At the start of a block, prior txn execution, we
/// need to update the storage of the beacon block root contract.
// See <https://eips.ethereum.org/EIPS/eip-4788>.
fn update_beacon_block_root_contract_storage(
trie_state: &mut PartialTrieState<impl StateTrie>,
delta_out: &mut TrieDeltaApplicationOutput,
nodes_used: &mut NodesUsedByTxnBatch,
block_data: &BlockMetadata,
block_data: &evm_arithmetization::proof::BlockMetadata,
) -> anyhow::Result<()> {
use ethereum_types::BigEndianHash;

const HISTORY_BUFFER_LENGTH_MOD: U256 = U256([HISTORY_BUFFER_LENGTH.1, 0, 0, 0]);

let timestamp_idx = block_data.block_timestamp % HISTORY_BUFFER_LENGTH_MOD;
Expand Down Expand Up @@ -457,18 +478,23 @@ fn add_withdrawals_to_txns(

if last_inputs.signed_txns.is_empty() {
let mut state_trie = final_trie_state.state.clone();
let is_eth_mainnet = cfg!(feature = "eth_mainnet");
state_trie.trim_to(
// This is a dummy payload, hence it does not contain yet
// state accesses to the withdrawal addresses.
withdrawals
.iter()
.map(|(addr, _)| *addr)
.chain(match last_inputs.txn_number_before == 0.into() {
// We need to include the beacon roots contract as this payload is at the
// start of the block execution.
true => Some(BEACON_ROOTS_CONTRACT_ADDRESS),
false => None,
})
.chain(
match is_eth_mainnet && last_inputs.txn_number_before == 0.into() {
// We need to include the beacon roots contract as this payload is at the
// start of the block execution.
true => {
Some(evm_arithmetization::testing_utils::BEACON_ROOTS_CONTRACT_ADDRESS)
}
false => None,
},
)
.map(TrieKey::from_address),
)?;
last_inputs.tries.state_trie = state_trie.try_into()?;
Expand Down Expand Up @@ -558,7 +584,7 @@ fn process_txn_info(

let nodes_used_by_txn = if is_initial_payload {
let mut nodes_used = txn_info.nodes_used_by_txn;
update_beacon_block_root_contract_storage(
pre_block_execution(
curr_block_tries,
&mut delta_out,
&mut nodes_used,
Expand Down
14 changes: 14 additions & 0 deletions trace_decoder/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,17 @@
#![warn(missing_debug_implementations)]
#![warn(missing_docs)]

#[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!");

/// The broad overview is as follows:
///
/// 1. Ethereum nodes emit a bunch of binary [`wire::Instruction`]s, which are
Expand Down Expand Up @@ -268,6 +279,9 @@ pub struct OtherBlockData {
pub b_data: BlockLevelData,
/// State trie root hash at the checkpoint.
pub checkpoint_state_trie_root: H256,
/// Address to store the base fee to be burnt.
/// Will be `None` when `cdk_erigon` feature flag is off.
pub burn_addr: Option<Address>,
}

/// Data that is specific to a block and is constant for all txns in a given
Expand Down
5 changes: 5 additions & 0 deletions zero_bin/common/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,11 @@ cdk_erigon = [
"proof_gen/cdk_erigon",
"trace_decoder/cdk_erigon",
]
polygon_pos = [
"evm_arithmetization/polygon_pos",
"proof_gen/polygon_pos",
"trace_decoder/polygon_pos",
]

[lints]
workspace = true
11 changes: 11 additions & 0 deletions zero_bin/common/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,15 @@
#[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!");
pub mod block_interval;

pub mod debug_utils;
pub mod fs;
pub mod parsing;
Expand Down
8 changes: 8 additions & 0 deletions zero_bin/leader/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,14 @@ cdk_erigon = [
"rpc/cdk_erigon",
"zero_bin_common/cdk_erigon"
]
polygon_pos = [
"evm_arithmetization/polygon_pos",
"ops/polygon_pos",
"proof_gen/polygon_pos",
"prover/polygon_pos",
"rpc/polygon_pos",
"zero_bin_common/polygon_pos",
]

[build-dependencies]
cargo_metadata = { workspace = true }
Expand Down
11 changes: 11 additions & 0 deletions zero_bin/leader/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,14 @@
#[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!");

use std::sync::Arc;
use std::{env, io};
use std::{fs::File, path::PathBuf};
Expand Down
6 changes: 6 additions & 0 deletions zero_bin/ops/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,9 @@ cdk_erigon = [
"trace_decoder/cdk_erigon",
"zero_bin_common/cdk_erigon",
]
polygon_pos = [
"evm_arithmetization/polygon_pos",
"proof_gen/polygon_pos",
"trace_decoder/polygon_pos",
"zero_bin_common/polygon_pos",
]
11 changes: 11 additions & 0 deletions zero_bin/ops/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,14 @@
#[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!");

use std::time::Instant;

use evm_arithmetization::generation::TrimmedGenerationInputs;
Expand Down
6 changes: 6 additions & 0 deletions zero_bin/prover/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,12 @@ cdk_erigon = [
"trace_decoder/cdk_erigon",
"zero_bin_common/cdk_erigon",
]
polygon_pos = [
"evm_arithmetization/polygon_pos",
"proof_gen/polygon_pos",
"trace_decoder/polygon_pos",
"zero_bin_common/polygon_pos",
]

[lints]
workspace = true
11 changes: 11 additions & 0 deletions zero_bin/prover/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,14 @@
#[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!");

pub mod cli;

use std::future::Future;
Expand Down
8 changes: 7 additions & 1 deletion zero_bin/rpc/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -51,4 +51,10 @@ cdk_erigon = [
"prover/cdk_erigon",
"trace_decoder/cdk_erigon",
"zero_bin_common/cdk_erigon",
]
]
polygon_pos = [
"evm_arithmetization/polygon_pos",
"prover/polygon_pos",
"trace_decoder/polygon_pos",
"zero_bin_common/polygon_pos",
]
Loading

0 comments on commit f03db41

Please sign in to comment.