From e06ca9df393798421789c2508731d8d420f397ae Mon Sep 17 00:00:00 2001 From: Linda Guiga Date: Fri, 26 Jul 2024 13:08:50 +0100 Subject: [PATCH 01/12] Implement burn address for cdk-erigon --- evm_arithmetization/Cargo.toml | 1 + .../benches/fibonacci_25m_gas.rs | 2 + .../src/cpu/kernel/aggregator.rs | 10 +- .../src/cpu/kernel/asm/core/process_txn.asm | 93 +++++++++++--- .../cpu/kernel/constants/global_metadata.rs | 7 +- .../src/cpu/kernel/tests/add11.rs | 7 +- .../src/fixed_recursive_verifier.rs | 14 +++ evm_arithmetization/src/generation/mod.rs | 18 +++ evm_arithmetization/src/get_challenges.rs | 33 ++++- evm_arithmetization/src/proof.rs | 118 ++++++++++++++++-- evm_arithmetization/src/recursive_verifier.rs | 46 +++++++ evm_arithmetization/src/util.rs | 12 ++ evm_arithmetization/src/verifier.rs | 2 + evm_arithmetization/tests/add11_yml.rs | 9 ++ evm_arithmetization/tests/erc20.rs | 2 + evm_arithmetization/tests/erc721.rs | 2 + evm_arithmetization/tests/global_exit_root.rs | 2 + evm_arithmetization/tests/log_opcode.rs | 2 + evm_arithmetization/tests/selfdestruct.rs | 2 + evm_arithmetization/tests/simple_transfer.rs | 2 + evm_arithmetization/tests/two_to_one_block.rs | 4 +- evm_arithmetization/tests/withdrawals.rs | 2 + trace_decoder/Cargo.toml | 2 + trace_decoder/src/decoding.rs | 5 +- 24 files changed, 366 insertions(+), 31 deletions(-) diff --git a/evm_arithmetization/Cargo.toml b/evm_arithmetization/Cargo.toml index 7398aee08..be8309b5f 100644 --- a/evm_arithmetization/Cargo.toml +++ b/evm_arithmetization/Cargo.toml @@ -62,6 +62,7 @@ parallel = [ "starky/parallel", ] polygon_pos = [] +cdk_erigon = [] [[bin]] name = "assemble" diff --git a/evm_arithmetization/benches/fibonacci_25m_gas.rs b/evm_arithmetization/benches/fibonacci_25m_gas.rs index 9959acbc1..233712e82 100644 --- a/evm_arithmetization/benches/fibonacci_25m_gas.rs +++ b/evm_arithmetization/benches/fibonacci_25m_gas.rs @@ -178,6 +178,8 @@ fn prepare_setup() -> anyhow::Result { Ok(GenerationInputs { signed_txn: Some(txn.to_vec()), + #[cfg(feature = "cdk_erigon")] + burn_addr: None, withdrawals: vec![], tries: tries_before, trie_roots_after, diff --git a/evm_arithmetization/src/cpu/kernel/aggregator.rs b/evm_arithmetization/src/cpu/kernel/aggregator.rs index 211d1d69f..2838b120a 100644 --- a/evm_arithmetization/src/cpu/kernel/aggregator.rs +++ b/evm_arithmetization/src/cpu/kernel/aggregator.rs @@ -175,7 +175,15 @@ pub static KERNEL_FILES: [&str; NUMBER_KERNEL_FILES] = [ pub static KERNEL: Lazy = Lazy::new(combined_kernel); pub(crate) fn combined_kernel_from_files(files: [&str; N]) -> Kernel { - let parsed_files = files.iter().map(|f| parse(f, HashSet::new())).collect_vec(); + #[cfg(feature = "cdk_erigon")] + let active_features = HashSet::from(["cdk_erigon"]); + #[cfg(not(feature = "cdk_erigon"))] + let active_features = HashSet::new(); + + let parsed_files = files + .iter() + .map(|f| parse(f, active_features.clone())) + .collect_vec(); assemble(parsed_files, evm_constants(), true) } diff --git a/evm_arithmetization/src/cpu/kernel/asm/core/process_txn.asm b/evm_arithmetization/src/cpu/kernel/asm/core/process_txn.asm index c6d10eb40..3e7fb3d5a 100644 --- a/evm_arithmetization/src/cpu/kernel/asm/core/process_txn.asm +++ b/evm_arithmetization/src/cpu/kernel/asm/core/process_txn.asm @@ -75,6 +75,11 @@ global buy_gas: // stack: deduct_eth_status, retdest %jumpi(panic) // stack: retdest + #[cfg(feature = cdk_erigon)] + { + %add_max_burnt_eth + // stack: retdest + } global increment_sender_nonce: %mload_txn_field(@TXN_FIELD_ORIGIN) @@ -324,46 +329,83 @@ process_message_txn_fail: %transfer_eth %jumpi(panic) %jump(process_message_txn_after_call_contd) -%macro pay_coinbase_and_refund_sender - // stack: leftover_gas +global pay_coinbase_and_refund_sender: + // stack: leftover_gas, retdest DUP1 - // stack: leftover_gas, leftover_gas + // stack: leftover_gas, leftover_gas, retdest %mload_txn_field(@TXN_FIELD_GAS_LIMIT) SUB - // stack: used_gas, leftover_gas + // stack: used_gas, leftover_gas, retdest %mload_global_metadata(@GLOBAL_METADATA_REFUND_COUNTER) - // stack: refund, used_gas, leftover_gas + // stack: refund, used_gas, leftover_gas, retdest DUP2 %div_const(@MAX_REFUND_QUOTIENT) // max_refund = used_gas/5 - // stack: max_refund, refund, used_gas, leftover_gas + // stack: max_refund, refund, used_gas, leftover_gas, retdest %min %stack (refund, used_gas, leftover_gas) -> (leftover_gas, refund, refund, used_gas) ADD - // stack: leftover_gas', refund, used_gas + // stack: leftover_gas', refund, used_gas, retdest SWAP2 - // stack: used_gas, refund, leftover_gas' + // stack: used_gas, refund, leftover_gas', retdest SUB - // stack: used_gas', leftover_gas' + // stack: used_gas', leftover_gas', retdest // Pay the coinbase. %mload_txn_field(@TXN_FIELD_COMPUTED_PRIORITY_FEE_PER_GAS) MUL // stack: used_gas_tip, leftover_gas' %mload_global_metadata(@GLOBAL_METADATA_BLOCK_BENEFICIARY) - // stack: coinbase, used_gas_tip, leftover_gas' + // stack: coinbase, used_gas_tip, leftover_gas', retdest %add_eth - // stack: leftover_gas' + // stack: leftover_gas', retdest DUP1 // Refund gas to the origin. %mload_txn_field(@TXN_FIELD_COMPUTED_FEE_PER_GAS) MUL - // stack: leftover_gas_cost, leftover_gas' + // stack: leftover_gas_cost, leftover_gas', retdest %mload_txn_field(@TXN_FIELD_ORIGIN) - // stack: origin, leftover_gas_cost, leftover_gas' + // stack: origin, leftover_gas_cost, leftover_gas', retdest %add_eth - // stack: leftover_gas' + // stack: leftover_gas', retdest + + #[cfg(feature = cdk_erigon)] + { + %deduct_extra_burn_fees + } + SWAP1 JUMP + +%macro pay_coinbase_and_refund_sender + // stack: leftover_gas + %stack (leftover_gas) -> (leftover_gas, %%after) + %jump(pay_coinbase_and_refund_sender) +%%after: %endmacro +#[cfg(feature = cdk_erigon)] +{ + %macro deduct_extra_burn_fees + // stack: leftover_gas' + // Deduct the extra burn fees from the burn target. + %mload_global_metadata(@GLOBAL_METADATA_BURN_ADDR) DUP1 + %eq_const(@U256_MAX) %jumpi(%%deduct_extra_burn_fees_pop) + // stack: burn_target, leftover_gas' + DUP2 + %mload_global_metadata(@GLOBAL_METADATA_BLOCK_BASE_FEE) + MUL + // stack: refund_base_cost, burn_target, leftover_gas' + SWAP1 + %deduct_eth + // stack: deduct_status, leftover_gas' + %jumpi(panic) + %jump(%%deduct_extra_burn_fees_end) + %%deduct_extra_burn_fees_pop: + // stack: burn_target, leftover_gas' + POP + %%deduct_extra_burn_fees_end: + // stack: leftover_gas' + %endmacro +} + // Sets @TXN_FIELD_MAX_FEE_PER_GAS and @TXN_FIELD_MAX_PRIORITY_FEE_PER_GAS. %macro compute_fees // stack: (empty) @@ -395,6 +437,29 @@ process_message_txn_fail: // stack: gas_limit - intrinsic_gas %endmacro +#[cfg(feature = cdk_erigon)] +{ + %macro add_max_burnt_eth + // stack: (empty) + %mload_global_metadata(@GLOBAL_METADATA_BURN_ADDR) + // If there is no burn target, we skip the transfer. + DUP1 %eq_const(@U256_MAX) %jumpi(%%add_max_burnt_eth_pop) + // stack: burn_target + %mload_global_metadata(@GLOBAL_METADATA_BLOCK_BASE_FEE) + %mload_txn_field(@TXN_FIELD_GAS_LIMIT) + MUL + // stack: max_burnt_cost, burn_target + SWAP1 + %add_eth + %jump(%%add_max_burnt_eth_end) + %%add_max_burnt_eth_pop: + // stack: burn_target + POP + %%add_max_burnt_eth_end: + // stack: (empty) + %endmacro +} + create_contract_account_fault: %revert_checkpoint // stack: address, retdest diff --git a/evm_arithmetization/src/cpu/kernel/constants/global_metadata.rs b/evm_arithmetization/src/cpu/kernel/constants/global_metadata.rs index 8f18ec60a..84e2a2c88 100644 --- a/evm_arithmetization/src/cpu/kernel/constants/global_metadata.rs +++ b/evm_arithmetization/src/cpu/kernel/constants/global_metadata.rs @@ -111,10 +111,13 @@ pub(crate) enum GlobalMetadata { BlobVersionedHashesRlpLen, // Number of blob versioned hashes contained in the current type-3 transaction. BlobVersionedHashesLen, + + /// Address where the base fee to be burnt is sent. + BurnAddr, } impl GlobalMetadata { - pub(crate) const COUNT: usize = 55; + pub(crate) const COUNT: usize = 56; /// Unscales this virtual offset by their respective `Segment` value. pub(crate) const fn unscale(&self) -> usize { @@ -178,6 +181,7 @@ impl GlobalMetadata { Self::BlobVersionedHashesRlpStart, Self::BlobVersionedHashesRlpLen, Self::BlobVersionedHashesLen, + Self::BurnAddr, ] } @@ -239,6 +243,7 @@ impl GlobalMetadata { Self::BlobVersionedHashesRlpStart => "GLOBAL_METADATA_BLOB_VERSIONED_HASHES_RLP_START", Self::BlobVersionedHashesRlpLen => "GLOBAL_METADATA_BLOB_VERSIONED_HASHES_RLP_LEN", Self::BlobVersionedHashesLen => "GLOBAL_METADATA_BLOB_VERSIONED_HASHES_LEN", + Self::BurnAddr => "GLOBAL_METADATA_BURN_ADDR", } } } diff --git a/evm_arithmetization/src/cpu/kernel/tests/add11.rs b/evm_arithmetization/src/cpu/kernel/tests/add11.rs index ae5ac3871..a5d870bca 100644 --- a/evm_arithmetization/src/cpu/kernel/tests/add11.rs +++ b/evm_arithmetization/src/cpu/kernel/tests/add11.rs @@ -15,7 +15,7 @@ use crate::generation::TrieInputs; use crate::proof::{BlockHashes, BlockMetadata, TrieRoots}; use crate::testing_utils::{ beacon_roots_account_nibbles, beacon_roots_contract_from_storage, ger_account_nibbles, - preinitialized_state_and_storage_tries, update_beacon_roots_account_storage, + init_logger, preinitialized_state_and_storage_tries, update_beacon_roots_account_storage, GLOBAL_EXIT_ROOT_ACCOUNT, }; use crate::GenerationInputs; @@ -181,6 +181,8 @@ fn test_add11_yml() { let inputs = GenerationInputs { signed_txn: Some(txn.to_vec()), + #[cfg(feature = "cdk_erigon")] + burn_addr: None, withdrawals: vec![], global_exit_roots: vec![], tries: tries_before, @@ -208,6 +210,7 @@ fn test_add11_yml() { #[test] fn test_add11_yml_with_exception() { + init_logger(); // In this test, we make sure that the user code throws a stack underflow // exception. let beneficiary = hex!("2adc25665018aa1fe0e6bc666dac8fc2697ff9ba"); @@ -362,6 +365,8 @@ fn test_add11_yml_with_exception() { let inputs = GenerationInputs { signed_txn: Some(txn.to_vec()), + #[cfg(feature = "cdk_erigon")] + burn_addr: None, withdrawals: vec![], global_exit_roots: vec![], tries: tries_before, diff --git a/evm_arithmetization/src/fixed_recursive_verifier.rs b/evm_arithmetization/src/fixed_recursive_verifier.rs index 3fa6e208f..7a9cdb3b6 100644 --- a/evm_arithmetization/src/fixed_recursive_verifier.rs +++ b/evm_arithmetization/src/fixed_recursive_verifier.rs @@ -38,6 +38,8 @@ use starky::stark::Stark; use crate::all_stark::{all_cross_table_lookups, AllStark, Table, NUM_TABLES}; use crate::generation::GenerationInputs; use crate::get_challenges::observe_public_values_target; +#[cfg(feature = "cdk_erigon")] +use crate::proof::BurnAddrTarget; use crate::proof::{ AllProof, BlockHashesTarget, BlockMetadataTarget, ExtraBlockData, ExtraBlockDataTarget, PublicValues, PublicValuesTarget, TrieRoots, TrieRootsTarget, @@ -784,6 +786,13 @@ where lhs_public_values.trie_roots_after, rhs_public_values.trie_roots_before, ); + #[cfg(feature = "cdk_erigon")] + // Connect the burn targets. + BurnAddrTarget::connect( + &mut builder, + lhs_public_values.burn_addr, + rhs_public_values.burn_addr, + ); Self::connect_extra_public_values( &mut builder, @@ -931,6 +940,9 @@ where public_values.extra_block_data, agg_pv.extra_block_data, ); + #[cfg(feature = "cdk_erigon")] + // Connect the burn targets. + BurnAddrTarget::connect(&mut builder, parent_pv.burn_addr, parent_pv.burn_addr); // Make connections between block proofs, and check initial and final block // values. @@ -1405,6 +1417,8 @@ where let agg_public_values = PublicValues { trie_roots_before: lhs_public_values.trie_roots_before, trie_roots_after: rhs_public_values.trie_roots_after, + #[cfg(feature = "cdk_erigon")] + burn_addr: lhs_public_values.burn_addr, extra_block_data: ExtraBlockData { checkpoint_state_trie_root: lhs_public_values .extra_block_data diff --git a/evm_arithmetization/src/generation/mod.rs b/evm_arithmetization/src/generation/mod.rs index 5940e8be3..5250b56c4 100644 --- a/evm_arithmetization/src/generation/mod.rs +++ b/evm_arithmetization/src/generation/mod.rs @@ -1,6 +1,8 @@ use std::collections::HashMap; use anyhow::anyhow; +#[cfg(feature = "cdk_erigon")] +use ethereum_types::H160; use ethereum_types::{Address, BigEndianHash, H256, U256}; use log::log_enabled; use mpt_trie::partial_trie::{HashedPartialTrie, PartialTrie}; @@ -53,6 +55,10 @@ pub struct GenerationInputs { /// A None would yield an empty proof, otherwise this contains the encoding /// of a transaction. pub signed_txn: Option>, + #[cfg(feature = "cdk_erigon")] + /// Target address for the base fee to be 'burnt', if there is one. If + /// `None`, then the base fee is directly burnt. + pub burn_addr: Option, /// 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)>, @@ -110,6 +116,10 @@ fn apply_metadata_and_tries_memops, const D: usize> let metadata = &inputs.block_metadata; let tries = &inputs.tries; let trie_roots_after = &inputs.trie_roots_after; + #[cfg(feature = "cdk_erigon")] + let burn_addr = inputs + .burn_addr + .map_or_else(U256::max_value, |addr| U256::from_big_endian(&addr.0)); let fields = [ ( GlobalMetadata::BlockBeneficiary, @@ -175,6 +185,8 @@ fn apply_metadata_and_tries_memops, const D: usize> ), (GlobalMetadata::KernelHash, h2u(KERNEL.code_hash)), (GlobalMetadata::KernelLen, KERNEL.code.len().into()), + #[cfg(feature = "cdk_erigon")] + (GlobalMetadata::BurnAddr, burn_addr), ]; let channel = MemoryChannel::GeneralPurpose(0); @@ -280,6 +292,12 @@ pub fn generate_traces, const D: usize>( let public_values = PublicValues { trie_roots_before, trie_roots_after, + #[cfg(feature = "cdk_erigon")] + burn_addr: if let Some(burn_addr) = inputs.burn_addr { + U256::from_big_endian(&burn_addr.0) + } else { + U256::MAX + }, block_metadata: inputs.block_metadata, block_hashes: inputs.block_hashes, extra_block_data, diff --git a/evm_arithmetization/src/get_challenges.rs b/evm_arithmetization/src/get_challenges.rs index 1fb80af6d..3dd338350 100644 --- a/evm_arithmetization/src/get_challenges.rs +++ b/evm_arithmetization/src/get_challenges.rs @@ -138,6 +138,29 @@ fn observe_extra_block_data_target< challenger.observe_element(extra_data.gas_used_after); } +#[cfg(feature = "cdk_erigon")] +fn observe_burn_addr, C: GenericConfig, const D: usize>( + challenger: &mut Challenger, + burn_addr: U256, +) -> Result<(), ProgramError> { + challenger.observe_elements(&u256_limbs(burn_addr)); + Ok(()) +} + +#[cfg(feature = "cdk_erigon")] +fn observe_burn_addr_target< + F: RichField + Extendable, + C: GenericConfig, + const D: usize, +>( + challenger: &mut RecursiveChallenger, + burn_addr: BurnAddrTarget, +) where + C::Hasher: AlgebraicHasher, +{ + challenger.observe_elements(&burn_addr.burn_addr); +} + fn observe_block_hashes< F: RichField + Extendable, C: GenericConfig, @@ -178,7 +201,13 @@ pub(crate) fn observe_public_values< observe_trie_roots::(challenger, &public_values.trie_roots_after); observe_block_metadata::(challenger, &public_values.block_metadata)?; observe_block_hashes::(challenger, &public_values.block_hashes); - observe_extra_block_data::(challenger, &public_values.extra_block_data) + #[cfg(not(feature = "cdk_erigon"))] + return observe_extra_block_data::(challenger, &public_values.extra_block_data); + #[cfg(feature = "cdk_erigon")] + { + observe_extra_block_data::(challenger, &public_values.extra_block_data)?; + observe_burn_addr::(challenger, public_values.burn_addr) + } } pub(crate) fn observe_public_values_target< @@ -196,6 +225,8 @@ pub(crate) fn observe_public_values_target< observe_block_metadata_target::(challenger, &public_values.block_metadata); observe_block_hashes_target::(challenger, &public_values.block_hashes); observe_extra_block_data_target::(challenger, &public_values.extra_block_data); + #[cfg(feature = "cdk_erigon")] + observe_burn_addr_target::(challenger, public_values.burn_addr); } impl, C: GenericConfig, const D: usize> AllProof { diff --git a/evm_arithmetization/src/proof.rs b/evm_arithmetization/src/proof.rs index 442e1a455..0b1a2ecad 100644 --- a/evm_arithmetization/src/proof.rs +++ b/evm_arithmetization/src/proof.rs @@ -11,6 +11,8 @@ use starky::lookup::GrandProductChallengeSet; use starky::proof::{MultiProof, StarkProofChallenges}; use crate::all_stark::NUM_TABLES; +#[cfg(feature = "cdk_erigon")] +use crate::util::get_u256; use crate::util::{get_h160, get_h256, h2u}; /// A STARK proof for each table, plus some metadata used to create recursive @@ -46,6 +48,9 @@ pub struct PublicValues { pub trie_roots_before: TrieRoots, /// Trie hashes after the execution of the local state transition. pub trie_roots_after: TrieRoots, + #[cfg(feature = "cdk_erigon")] + /// Address to store the base fee to be burnt. + pub burn_addr: U256, /// Block metadata: it remains unchanged within a block. pub block_metadata: BlockMetadata, /// 256 previous block hashes and current block's hash. @@ -61,19 +66,35 @@ impl PublicValues { pub fn from_public_inputs(pis: &[F]) -> Self { assert!(PublicValuesTarget::SIZE <= pis.len()); + #[cfg(not(feature = "cdk_erigon"))] + let burn_addr_offset = 0; + #[cfg(feature = "cdk_erigon")] + let burn_addr_offset = BurnAddrTarget::SIZE; let trie_roots_before = TrieRoots::from_public_inputs(&pis[0..TrieRootsTarget::SIZE]); let trie_roots_after = TrieRoots::from_public_inputs(&pis[TrieRootsTarget::SIZE..TrieRootsTarget::SIZE * 2]); + #[cfg(feature = "cdk_erigon")] + let burn_addr = get_u256( + &pis[TrieRootsTarget::SIZE * 2..TrieRootsTarget::SIZE * 2 + BurnAddrTarget::SIZE], + ); let block_metadata = BlockMetadata::from_public_inputs( - &pis[TrieRootsTarget::SIZE * 2..TrieRootsTarget::SIZE * 2 + BlockMetadataTarget::SIZE], + &pis[burn_addr_offset + TrieRootsTarget::SIZE * 2 + ..burn_addr_offset + TrieRootsTarget::SIZE * 2 + BlockMetadataTarget::SIZE], ); let block_hashes = BlockHashes::from_public_inputs( - &pis[TrieRootsTarget::SIZE * 2 + BlockMetadataTarget::SIZE - ..TrieRootsTarget::SIZE * 2 + BlockMetadataTarget::SIZE + BlockHashesTarget::SIZE], + &pis[burn_addr_offset + TrieRootsTarget::SIZE * 2 + BlockMetadataTarget::SIZE + ..burn_addr_offset + + TrieRootsTarget::SIZE * 2 + + BlockMetadataTarget::SIZE + + BlockHashesTarget::SIZE], ); let extra_block_data = ExtraBlockData::from_public_inputs( - &pis[TrieRootsTarget::SIZE * 2 + BlockMetadataTarget::SIZE + BlockHashesTarget::SIZE - ..TrieRootsTarget::SIZE * 2 + &pis[burn_addr_offset + + TrieRootsTarget::SIZE * 2 + + BlockMetadataTarget::SIZE + + BlockHashesTarget::SIZE + ..burn_addr_offset + + TrieRootsTarget::SIZE * 2 + BlockMetadataTarget::SIZE + BlockHashesTarget::SIZE + ExtraBlockDataTarget::SIZE], @@ -82,6 +103,8 @@ impl PublicValues { Self { trie_roots_before, trie_roots_after, + #[cfg(feature = "cdk_erigon")] + burn_addr, block_metadata, block_hashes, extra_block_data, @@ -278,6 +301,9 @@ pub struct PublicValuesTarget { pub trie_roots_before: TrieRootsTarget, /// Trie hashes after the execution of the local state transition. pub trie_roots_after: TrieRootsTarget, + #[cfg(feature = "cdk_erigon")] + /// Address to store the base fee to be burnt. + pub burn_addr: BurnAddrTarget, /// Block metadata: it remains unchanged within a block. pub block_metadata: BlockMetadataTarget, /// 256 previous block hashes and current block's hash. @@ -380,6 +406,11 @@ impl PublicValuesTarget { receipts_root: buffer.read_target_array()?, }; + #[cfg(feature = "cdk_erigon")] + let burn_addr = BurnAddrTarget { + burn_addr: buffer.read_target_array()?, + }; + let block_metadata = BlockMetadataTarget { block_beneficiary: buffer.read_target_array()?, block_timestamp: buffer.read_target()?, @@ -412,6 +443,8 @@ impl PublicValuesTarget { Ok(Self { trie_roots_before, trie_roots_after, + #[cfg(feature = "cdk_erigon")] + burn_addr, block_metadata, block_hashes, extra_block_data, @@ -431,24 +464,37 @@ impl PublicValuesTarget { - 1 ); + #[cfg(not(feature = "cdk_erigon"))] + let burn_addr_offset = 0; + #[cfg(feature = "cdk_erigon")] + let burn_addr_offset = BurnAddrTarget::SIZE; Self { trie_roots_before: TrieRootsTarget::from_public_inputs(&pis[0..TrieRootsTarget::SIZE]), trie_roots_after: TrieRootsTarget::from_public_inputs( &pis[TrieRootsTarget::SIZE..TrieRootsTarget::SIZE * 2], ), + #[cfg(feature = "cdk_erigon")] + burn_addr: BurnAddrTarget::from_public_inputs( + &pis[TrieRootsTarget::SIZE * 2..TrieRootsTarget::SIZE * 2 + BurnAddrTarget::SIZE], + ), block_metadata: BlockMetadataTarget::from_public_inputs( - &pis[TrieRootsTarget::SIZE * 2 - ..TrieRootsTarget::SIZE * 2 + BlockMetadataTarget::SIZE], + &pis[burn_addr_offset + TrieRootsTarget::SIZE * 2 + ..burn_addr_offset + TrieRootsTarget::SIZE * 2 + BlockMetadataTarget::SIZE], ), block_hashes: BlockHashesTarget::from_public_inputs( - &pis[TrieRootsTarget::SIZE * 2 + BlockMetadataTarget::SIZE - ..TrieRootsTarget::SIZE * 2 + &pis[burn_addr_offset + TrieRootsTarget::SIZE * 2 + BlockMetadataTarget::SIZE + ..burn_addr_offset + + TrieRootsTarget::SIZE * 2 + BlockMetadataTarget::SIZE + BlockHashesTarget::SIZE], ), extra_block_data: ExtraBlockDataTarget::from_public_inputs( - &pis[TrieRootsTarget::SIZE * 2 + BlockMetadataTarget::SIZE + BlockHashesTarget::SIZE - ..TrieRootsTarget::SIZE * 2 + &pis[burn_addr_offset + + TrieRootsTarget::SIZE * 2 + + BlockMetadataTarget::SIZE + + BlockHashesTarget::SIZE + ..burn_addr_offset + + TrieRootsTarget::SIZE * 2 + BlockMetadataTarget::SIZE + BlockHashesTarget::SIZE + ExtraBlockDataTarget::SIZE], @@ -476,6 +522,8 @@ impl PublicValuesTarget { pv0.trie_roots_after, pv1.trie_roots_after, ), + #[cfg(feature = "cdk_erigon")] + burn_addr: BurnAddrTarget::select(builder, condition, pv0.burn_addr, pv1.burn_addr), block_metadata: BlockMetadataTarget::select( builder, condition, @@ -570,6 +618,54 @@ impl TrieRootsTarget { } } +/// Circuit version of `BurnAddr`. +/// Address used to store the base fee to be burnt. +#[derive(Eq, PartialEq, Debug, Copy, Clone)] +#[cfg(feature = "cdk_erigon")] +pub struct BurnAddrTarget { + pub(crate) burn_addr: [Target; 8], +} + +#[cfg(feature = "cdk_erigon")] +impl BurnAddrTarget { + /// Number of `Target`s required for the block metadata. + pub(crate) const SIZE: usize = 8; + + /// Extracts block metadata `Target`s from the provided public input + /// `Target`s. The provided `pis` should start with the block metadata. + pub(crate) fn from_public_inputs(pis: &[Target]) -> Self { + let burn_addr = pis[0..8].try_into().unwrap(); + + Self { burn_addr } + } + + /// If `condition`, returns the block metadata in `bm0`, + /// otherwise returns the block metadata in `bm1`. + pub(crate) fn select, const D: usize>( + builder: &mut CircuitBuilder, + condition: BoolTarget, + ba0: Self, + ba1: Self, + ) -> Self { + Self { + burn_addr: core::array::from_fn(|i| { + builder.select(condition, ba0.burn_addr[i], ba1.burn_addr[i]) + }), + } + } + + /// Connects the block metadata in `bm0` to the block metadata in `bm1`. + pub(crate) fn connect, const D: usize>( + builder: &mut CircuitBuilder, + ba0: Self, + ba1: Self, + ) { + for i in 0..5 { + builder.connect(ba0.burn_addr[i], ba1.burn_addr[i]); + } + } +} + /// Circuit version of `BlockMetadata`. /// Metadata contained in a block header. Those are identical between /// all state transition proofs within the same block. diff --git a/evm_arithmetization/src/recursive_verifier.rs b/evm_arithmetization/src/recursive_verifier.rs index 26ee4c116..37e2921c9 100644 --- a/evm_arithmetization/src/recursive_verifier.rs +++ b/evm_arithmetization/src/recursive_verifier.rs @@ -34,6 +34,8 @@ use crate::cpu::kernel::aggregator::KERNEL; use crate::cpu::kernel::constants::global_metadata::GlobalMetadata; use crate::memory::segments::Segment; use crate::memory::VALUE_LIMBS; +#[cfg(feature = "cdk_erigon")] +use crate::proof::BurnAddrTarget; use crate::proof::{ BlockHashes, BlockHashesTarget, BlockMetadata, BlockMetadataTarget, ExtraBlockData, ExtraBlockDataTarget, PublicValues, PublicValuesTarget, TrieRoots, TrieRootsTarget, @@ -424,6 +426,16 @@ pub(crate) fn get_memory_extra_looking_sum_circuit, ); }); + #[cfg(feature = "cdk_erigon")] + let mut sum = add_data_write( + builder, + challenge, + sum, + metadata_segment, + GlobalMetadata::BurnAddr.unscale(), + &public_values.burn_addr.burn_addr, + ); + block_fields_arrays.map(|(field, targets)| { sum = add_data_write( builder, @@ -571,18 +583,30 @@ pub(crate) fn add_virtual_public_values, const D: u ) -> PublicValuesTarget { let trie_roots_before = add_virtual_trie_roots(builder); let trie_roots_after = add_virtual_trie_roots(builder); + #[cfg(feature = "cdk_erigon")] + let burn_addr = add_virtual_burn_addr(builder); let block_metadata = add_virtual_block_metadata(builder); let block_hashes = add_virtual_block_hashes(builder); let extra_block_data = add_virtual_extra_block_data(builder); PublicValuesTarget { trie_roots_before, trie_roots_after, + #[cfg(feature = "cdk_erigon")] + burn_addr, block_metadata, block_hashes, extra_block_data, } } +#[cfg(feature = "cdk_erigon")] +pub(crate) fn add_virtual_burn_addr, const D: usize>( + builder: &mut CircuitBuilder, +) -> BurnAddrTarget { + let burn_addr = builder.add_virtual_public_input_arr(); + BurnAddrTarget { burn_addr } +} + pub(crate) fn add_virtual_trie_roots, const D: usize>( builder: &mut CircuitBuilder, ) -> TrieRootsTarget { @@ -704,6 +728,12 @@ where &public_values_target.extra_block_data, &public_values.extra_block_data, )?; + #[cfg(feature = "cdk_erigon")] + set_burn_addr_target( + witness, + &public_values_target.burn_addr, + public_values.burn_addr, + )?; Ok(()) } @@ -762,6 +792,22 @@ pub(crate) fn set_trie_roots_target( } } +#[cfg(feature = "cdk_erigon")] +pub(crate) fn set_burn_addr_target( + witness: &mut W, + burn_addr_target: &BurnAddrTarget, + burn_addr: U256, +) -> Result<(), ProgramError> +where + F: RichField + Extendable, + W: Witness, +{ + let burn_addr_limbs: [F; 8] = u256_limbs::(burn_addr); + witness.set_target_arr(&burn_addr_target.burn_addr, &burn_addr_limbs); + + Ok(()) +} + pub(crate) fn set_block_metadata_target( witness: &mut W, block_metadata_target: &BlockMetadataTarget, diff --git a/evm_arithmetization/src/util.rs b/evm_arithmetization/src/util.rs index f8463258b..14fd6e3f6 100644 --- a/evm_arithmetization/src/util.rs +++ b/evm_arithmetization/src/util.rs @@ -112,6 +112,18 @@ pub(crate) fn u256_limbs(u256: U256) -> [F; 8] { .unwrap() } +#[allow(unused)] +pub(crate) fn get_u256(u256_limbs: &[F]) -> U256 { + U256( + u256_limbs + .chunks(2) + .map(|c| c[0].to_canonical_u64() + ((c[1].to_canonical_u64()) << 32)) + .collect::>() + .try_into() + .unwrap(), + ) +} + /// Returns the 32-bit little-endian limbs of a `H256`. pub(crate) fn h256_limbs(h256: H256) -> [F; 8] { let mut temp_h256 = h256.0; diff --git a/evm_arithmetization/src/verifier.rs b/evm_arithmetization/src/verifier.rs index 90a287f1e..efce24b81 100644 --- a/evm_arithmetization/src/verifier.rs +++ b/evm_arithmetization/src/verifier.rs @@ -154,6 +154,8 @@ where GlobalMetadata::BlockBeneficiary, U256::from_big_endian(&public_values.block_metadata.block_beneficiary.0), ), + #[cfg(feature = "cdk_erigon")] + (GlobalMetadata::BurnAddr, public_values.burn_addr), ( GlobalMetadata::BlockTimestamp, public_values.block_metadata.block_timestamp, diff --git a/evm_arithmetization/tests/add11_yml.rs b/evm_arithmetization/tests/add11_yml.rs index dca625d36..10b74a88c 100644 --- a/evm_arithmetization/tests/add11_yml.rs +++ b/evm_arithmetization/tests/add11_yml.rs @@ -109,6 +109,13 @@ fn add11_yml() -> anyhow::Result<()> { let beacon_roots_account = beacon_roots_contract_from_storage(&beacon_roots_account_storage); + #[cfg(feature = "cdk_erigon")] + let beneficiary_account_after = AccountRlp { + nonce: 1.into(), + balance: block_metadata.block_base_fee * block_metadata.block_gas_used, + ..AccountRlp::default() + }; + #[cfg(not(feature = "cdk_erigon"))] let beneficiary_account_after = AccountRlp { nonce: 1.into(), ..AccountRlp::default() @@ -174,6 +181,8 @@ fn add11_yml() -> anyhow::Result<()> { }; let inputs = GenerationInputs { signed_txn: Some(txn.to_vec()), + #[cfg(feature = "cdk_erigon")] + burn_addr: Some(Address::from(beneficiary)), withdrawals: vec![], global_exit_roots: vec![], tries: tries_before, diff --git a/evm_arithmetization/tests/erc20.rs b/evm_arithmetization/tests/erc20.rs index 1c829efc1..0a89fa114 100644 --- a/evm_arithmetization/tests/erc20.rs +++ b/evm_arithmetization/tests/erc20.rs @@ -180,6 +180,8 @@ fn test_erc20() -> anyhow::Result<()> { }; let inputs = GenerationInputs { signed_txn: Some(txn.to_vec()), + #[cfg(feature = "cdk_erigon")] + burn_addr: None, withdrawals: vec![], global_exit_roots: vec![], tries: tries_before, diff --git a/evm_arithmetization/tests/erc721.rs b/evm_arithmetization/tests/erc721.rs index 3a02d8968..f2dd0ffdc 100644 --- a/evm_arithmetization/tests/erc721.rs +++ b/evm_arithmetization/tests/erc721.rs @@ -184,6 +184,8 @@ fn test_erc721() -> anyhow::Result<()> { let inputs = GenerationInputs { signed_txn: Some(txn.to_vec()), + #[cfg(feature = "cdk_erigon")] + burn_addr: None, withdrawals: vec![], global_exit_roots: vec![], tries: tries_before, diff --git a/evm_arithmetization/tests/global_exit_root.rs b/evm_arithmetization/tests/global_exit_root.rs index 507ffe0f7..1d3f5997a 100644 --- a/evm_arithmetization/tests/global_exit_root.rs +++ b/evm_arithmetization/tests/global_exit_root.rs @@ -78,6 +78,8 @@ fn test_global_exit_root() -> anyhow::Result<()> { let inputs = GenerationInputs { signed_txn: None, + #[cfg(feature = "cdk_erigon")] + burn_addr: None, withdrawals: vec![], global_exit_roots, tries: TrieInputs { diff --git a/evm_arithmetization/tests/log_opcode.rs b/evm_arithmetization/tests/log_opcode.rs index 8cd5c57c0..58cf62943 100644 --- a/evm_arithmetization/tests/log_opcode.rs +++ b/evm_arithmetization/tests/log_opcode.rs @@ -239,6 +239,8 @@ fn test_log_opcodes() -> anyhow::Result<()> { let inputs = GenerationInputs { signed_txn: Some(txn.to_vec()), + #[cfg(feature = "cdk_erigon")] + burn_addr: None, withdrawals: vec![], global_exit_roots: vec![], tries: tries_before, diff --git a/evm_arithmetization/tests/selfdestruct.rs b/evm_arithmetization/tests/selfdestruct.rs index 708646e16..a5d30d220 100644 --- a/evm_arithmetization/tests/selfdestruct.rs +++ b/evm_arithmetization/tests/selfdestruct.rs @@ -154,6 +154,8 @@ fn test_selfdestruct() -> anyhow::Result<()> { }; let inputs = GenerationInputs { signed_txn: Some(txn.to_vec()), + #[cfg(feature = "cdk_erigon")] + burn_addr: None, withdrawals: vec![], global_exit_roots: vec![], tries: tries_before, diff --git a/evm_arithmetization/tests/simple_transfer.rs b/evm_arithmetization/tests/simple_transfer.rs index 030b2c3e1..699da5060 100644 --- a/evm_arithmetization/tests/simple_transfer.rs +++ b/evm_arithmetization/tests/simple_transfer.rs @@ -146,6 +146,8 @@ fn test_simple_transfer() -> anyhow::Result<()> { }; let inputs = GenerationInputs { signed_txn: Some(txn.to_vec()), + #[cfg(feature = "cdk_erigon")] + burn_addr: None, withdrawals: vec![], global_exit_roots: vec![], tries: tries_before, diff --git a/evm_arithmetization/tests/two_to_one_block.rs b/evm_arithmetization/tests/two_to_one_block.rs index fe479bf65..b795573ed 100644 --- a/evm_arithmetization/tests/two_to_one_block.rs +++ b/evm_arithmetization/tests/two_to_one_block.rs @@ -2,7 +2,7 @@ use std::collections::HashMap; use std::str::FromStr; use env_logger::{try_init_from_env, Env, DEFAULT_FILTER_ENV}; -use ethereum_types::{Address, BigEndianHash, H256, U256}; +use ethereum_types::{Address, BigEndianHash, H160, H256, U256}; use evm_arithmetization::fixed_recursive_verifier::{ extract_block_public_values, extract_two_to_one_block_hash, }; @@ -174,6 +174,8 @@ fn get_test_block_proof( let inputs = inputs0.clone(); let dummy0 = GenerationInputs { txn_number_before: inputs.txn_number_before, + #[cfg(feature = "cdk_erigon")] + burn_addr: Some(Address::from(H160::random())), gas_used_before: inputs.gas_used_after, gas_used_after: inputs.gas_used_after, signed_txn: None, diff --git a/evm_arithmetization/tests/withdrawals.rs b/evm_arithmetization/tests/withdrawals.rs index e17b775b1..a5b19f93c 100644 --- a/evm_arithmetization/tests/withdrawals.rs +++ b/evm_arithmetization/tests/withdrawals.rs @@ -86,6 +86,8 @@ fn test_withdrawals() -> anyhow::Result<()> { let inputs = GenerationInputs { signed_txn: None, + #[cfg(feature = "cdk_erigon")] + burn_addr: None, withdrawals, global_exit_roots: vec![], tries: TrieInputs { diff --git a/trace_decoder/Cargo.toml b/trace_decoder/Cargo.toml index ed086283c..2918b38a1 100644 --- a/trace_decoder/Cargo.toml +++ b/trace_decoder/Cargo.toml @@ -47,6 +47,8 @@ plonky2_maybe_rayon = { workspace = true } alloy = { workspace = true } rstest = "0.21.0" +[features] +cdk_erigon = [] [[bench]] name = "block_processing" diff --git a/trace_decoder/src/decoding.rs b/trace_decoder/src/decoding.rs index 64e0a1fbd..60f0db80e 100644 --- a/trace_decoder/src/decoding.rs +++ b/trace_decoder/src/decoding.rs @@ -4,7 +4,7 @@ use std::{ iter::once, }; -use ethereum_types::{Address, BigEndianHash, H256, U256, U512}; +use ethereum_types::{Address, BigEndianHash, H160, H256, U256, U512}; use evm_arithmetization::{ generation::{mpt::AccountRlp, GenerationInputs, TrieInputs}, proof::{BlockMetadata, ExtraBlockData, TrieRoots}, @@ -761,6 +761,9 @@ impl ProcessedBlockTrace { let trie_roots_after = calculate_trie_input_hashes(curr_block_tries); let gen_inputs = GenerationInputs { txn_number_before: extra_data.txn_number_before, + // TODO: retrieve the actual burn address from cdk-erigon. + #[cfg(feature = "cdk_erigon")] + burn_addr: Some(H160::zero()), gas_used_before: extra_data.gas_used_before, gas_used_after: extra_data.gas_used_after, signed_txn: txn_info.meta.txn_bytes, From b12951ae1c168d3f4030c966feda7feffd0e523f Mon Sep 17 00:00:00 2001 From: Linda Guiga Date: Mon, 5 Aug 2024 18:38:53 +0100 Subject: [PATCH 02/12] Fix block connections and comments --- .../src/fixed_recursive_verifier.rs | 76 +++++++++++++------ evm_arithmetization/src/proof.rs | 12 +-- 2 files changed, 60 insertions(+), 28 deletions(-) diff --git a/evm_arithmetization/src/fixed_recursive_verifier.rs b/evm_arithmetization/src/fixed_recursive_verifier.rs index 7a9cdb3b6..701ed1e9a 100644 --- a/evm_arithmetization/src/fixed_recursive_verifier.rs +++ b/evm_arithmetization/src/fixed_recursive_verifier.rs @@ -50,7 +50,7 @@ use crate::recursive_verifier::{ recursive_stark_circuit, set_public_value_targets, PlonkWrapperCircuit, PublicInputs, StarkWrapperCircuit, }; -use crate::util::h256_limbs; +use crate::util::{h256_limbs, u256_limbs}; /// The recursion threshold. We end a chain of recursive proofs once we reach /// this size. @@ -787,13 +787,19 @@ where rhs_public_values.trie_roots_before, ); #[cfg(feature = "cdk_erigon")] - // Connect the burn targets. - BurnAddrTarget::connect( - &mut builder, - lhs_public_values.burn_addr, - rhs_public_values.burn_addr, - ); - + { + // Connect the burn address targets. + BurnAddrTarget::connect( + &mut builder, + lhs_public_values.burn_addr, + rhs_public_values.burn_addr, + ); + BurnAddrTarget::connect( + &mut builder, + public_values.burn_addr, + rhs_public_values.burn_addr, + ); + } Self::connect_extra_public_values( &mut builder, &public_values.extra_block_data, @@ -941,8 +947,11 @@ where agg_pv.extra_block_data, ); #[cfg(feature = "cdk_erigon")] - // Connect the burn targets. - BurnAddrTarget::connect(&mut builder, parent_pv.burn_addr, parent_pv.burn_addr); + // Connect the burn address targets. + { + BurnAddrTarget::connect(&mut builder, parent_pv.burn_addr, agg_pv.burn_addr); + BurnAddrTarget::connect(&mut builder, public_values.burn_addr, agg_pv.burn_addr); + } // Make connections between block proofs, and check initial and final block // values. @@ -1540,13 +1549,29 @@ where nonzero_pis.insert(key, value); } + #[cfg(not(feature = "cdk_erigon"))] + let burn_addr_offset = 0; + #[cfg(feature = "cdk_erigon")] + let burn_addr_offset = BurnAddrTarget::SIZE; + + #[cfg(feature = "cdk_erigon")] + { + let burn_addr_keys = + TrieRootsTarget::SIZE * 2..TrieRootsTarget::SIZE * 2 + BurnAddrTarget::SIZE; + for (key, &value) in burn_addr_keys.zip_eq(&u256_limbs(public_values.burn_addr)) { + nonzero_pis.insert(key, value); + } + } // Initialize the checkpoint state root extra data. - let checkpoint_state_trie_keys = - TrieRootsTarget::SIZE * 2 + BlockMetadataTarget::SIZE + BlockHashesTarget::SIZE - ..TrieRootsTarget::SIZE * 2 - + BlockMetadataTarget::SIZE - + BlockHashesTarget::SIZE - + 8; + let checkpoint_state_trie_keys = burn_addr_offset + + TrieRootsTarget::SIZE * 2 + + BlockMetadataTarget::SIZE + + BlockHashesTarget::SIZE + ..burn_addr_offset + + TrieRootsTarget::SIZE * 2 + + BlockMetadataTarget::SIZE + + BlockHashesTarget::SIZE + + 8; for (key, &value) in checkpoint_state_trie_keys.zip_eq(&h256_limbs::( public_values.extra_block_data.checkpoint_state_trie_root, )) { @@ -1555,9 +1580,13 @@ where // Initialize checkpoint block hashes. // These will be all zeros the initial genesis checkpoint. - let block_hashes_keys = TrieRootsTarget::SIZE * 2 + BlockMetadataTarget::SIZE - ..TrieRootsTarget::SIZE * 2 + BlockMetadataTarget::SIZE + BlockHashesTarget::SIZE - - 8; + let block_hashes_keys = + burn_addr_offset + TrieRootsTarget::SIZE * 2 + BlockMetadataTarget::SIZE + ..burn_addr_offset + + TrieRootsTarget::SIZE * 2 + + BlockMetadataTarget::SIZE + + BlockHashesTarget::SIZE + - 8; for i in 0..public_values.block_hashes.prev_hashes.len() - 1 { let targets = h256_limbs::(public_values.block_hashes.prev_hashes[i]); @@ -1565,8 +1594,11 @@ where nonzero_pis.insert(block_hashes_keys.start + 8 * (i + 1) + j, targets[j]); } } - let block_hashes_current_start = - TrieRootsTarget::SIZE * 2 + BlockMetadataTarget::SIZE + BlockHashesTarget::SIZE - 8; + let block_hashes_current_start = burn_addr_offset + + TrieRootsTarget::SIZE * 2 + + BlockMetadataTarget::SIZE + + BlockHashesTarget::SIZE + - 8; let cur_targets = h256_limbs::(public_values.block_hashes.prev_hashes[255]); for i in 0..8 { nonzero_pis.insert(block_hashes_current_start + i, cur_targets[i]); @@ -1575,7 +1607,7 @@ where // Initialize the checkpoint block number. // Subtraction would result in an invalid proof for genesis, but we shouldn't // try proving this block anyway. - let block_number_key = TrieRootsTarget::SIZE * 2 + 6; + let block_number_key = burn_addr_offset + TrieRootsTarget::SIZE * 2 + 6; nonzero_pis.insert( block_number_key, F::from_canonical_u64(public_values.block_metadata.block_number.low_u64() - 1), diff --git a/evm_arithmetization/src/proof.rs b/evm_arithmetization/src/proof.rs index 0b1a2ecad..6b37cb2a7 100644 --- a/evm_arithmetization/src/proof.rs +++ b/evm_arithmetization/src/proof.rs @@ -628,19 +628,19 @@ pub struct BurnAddrTarget { #[cfg(feature = "cdk_erigon")] impl BurnAddrTarget { - /// Number of `Target`s required for the block metadata. + /// Number of `Target`s required for the burn address. pub(crate) const SIZE: usize = 8; - /// Extracts block metadata `Target`s from the provided public input - /// `Target`s. The provided `pis` should start with the block metadata. + /// Extracts the burn address from the provided public input + /// `Target`s. The provided `pis` should start with the burn address. pub(crate) fn from_public_inputs(pis: &[Target]) -> Self { let burn_addr = pis[0..8].try_into().unwrap(); Self { burn_addr } } - /// If `condition`, returns the block metadata in `bm0`, - /// otherwise returns the block metadata in `bm1`. + /// If `condition`, returns the burn address in `ba0`, + /// otherwise returns the burn address in `ba1`. pub(crate) fn select, const D: usize>( builder: &mut CircuitBuilder, condition: BoolTarget, @@ -654,7 +654,7 @@ impl BurnAddrTarget { } } - /// Connects the block metadata in `bm0` to the block metadata in `bm1`. + /// Connects the burn address in `ba0` to the burn address in `ba1`. pub(crate) fn connect, const D: usize>( builder: &mut CircuitBuilder, ba0: Self, From bfd36c4e35e2a1d795e0814e91b1d0cb01793972 Mon Sep 17 00:00:00 2001 From: Linda Guiga Date: Mon, 12 Aug 2024 10:43:04 +0100 Subject: [PATCH 03/12] Apply some comments --- .../src/cpu/kernel/aggregator.rs | 2 +- .../src/cpu/kernel/assembler.rs | 5 ++++- evm_arithmetization/src/cpu/kernel/mod.rs | 2 +- evm_arithmetization/src/cpu/kernel/parser.rs | 20 +++++++++---------- .../src/cpu/kernel/tests/add11.rs | 3 +-- .../src/fixed_recursive_verifier.rs | 4 +++- 6 files changed, 20 insertions(+), 16 deletions(-) diff --git a/evm_arithmetization/src/cpu/kernel/aggregator.rs b/evm_arithmetization/src/cpu/kernel/aggregator.rs index 2838b120a..068ffa3a9 100644 --- a/evm_arithmetization/src/cpu/kernel/aggregator.rs +++ b/evm_arithmetization/src/cpu/kernel/aggregator.rs @@ -182,7 +182,7 @@ pub(crate) fn combined_kernel_from_files(files: [&str; N]) -> Ke let parsed_files = files .iter() - .map(|f| parse(f, active_features.clone())) + .map(|f| parse(f, &active_features)) .collect_vec(); assemble(parsed_files, evm_constants(), true) } diff --git a/evm_arithmetization/src/cpu/kernel/assembler.rs b/evm_arithmetization/src/cpu/kernel/assembler.rs index c055e7a84..992491f8d 100644 --- a/evm_arithmetization/src/cpu/kernel/assembler.rs +++ b/evm_arithmetization/src/cpu/kernel/assembler.rs @@ -761,7 +761,10 @@ mod tests { constants: HashMap, optimize: bool, ) -> Kernel { - let parsed_files = files.iter().map(|f| parse(f, HashSet::new())).collect_vec(); + let parsed_files = files + .iter() + .map(|f| parse(f, &HashSet::new())) + .collect_vec(); assemble(parsed_files, constants, optimize) } } diff --git a/evm_arithmetization/src/cpu/kernel/mod.rs b/evm_arithmetization/src/cpu/kernel/mod.rs index 7b8a58566..ac8147488 100644 --- a/evm_arithmetization/src/cpu/kernel/mod.rs +++ b/evm_arithmetization/src/cpu/kernel/mod.rs @@ -28,7 +28,7 @@ use crate::cpu::kernel::constants::evm_constants; /// Assemble files, outputting bytes. /// This is for debugging the kernel only. pub fn assemble_to_bytes(files: &[String]) -> Vec { - let parsed_files: Vec<_> = files.iter().map(|f| parse(f, HashSet::new())).collect(); + let parsed_files: Vec<_> = files.iter().map(|f| parse(f, &HashSet::new())).collect(); let kernel = assemble(parsed_files, evm_constants(), true); kernel.code } diff --git a/evm_arithmetization/src/cpu/kernel/parser.rs b/evm_arithmetization/src/cpu/kernel/parser.rs index 5e880964e..222d51ce4 100644 --- a/evm_arithmetization/src/cpu/kernel/parser.rs +++ b/evm_arithmetization/src/cpu/kernel/parser.rs @@ -12,14 +12,14 @@ use crate::cpu::kernel::ast::{File, Item, PushTarget, StackReplacement}; #[grammar = "cpu/kernel/evm_asm.pest"] struct AsmParser; -pub(crate) fn parse(s: &str, active_features: HashSet<&str>) -> File { +pub(crate) fn parse(s: &str, active_features: &HashSet<&str>) -> File { let file = AsmParser::parse(Rule::file, s) .expect("Parsing failed") .next() .unwrap(); let body = file .into_inner() - .map(|i| parse_item(i, &active_features)) + .map(|i| parse_item(i, active_features)) .collect(); File { body } } @@ -284,7 +284,7 @@ mod tests { // Test `feature_1`. let active_features = HashSet::from(["feature_1"]); - let parsed_code = parse(code, active_features); + let parsed_code = parse(code, &active_features); let final_code = assemble(vec![parsed_code], HashMap::new(), false); let expected_code = r#" @@ -308,7 +308,7 @@ mod tests { DIV "#; - let parsed_expected = parse(expected_code, HashSet::new()); + let parsed_expected = parse(expected_code, &HashSet::new()); let final_expected = assemble(vec![parsed_expected], HashMap::new(), false); assert_eq!(final_code.code, final_expected.code); @@ -316,7 +316,7 @@ mod tests { // Test `feature_2`. let active_features = HashSet::from(["feature_2"]); - let parsed_code = parse(code, active_features); + let parsed_code = parse(code, &active_features); let final_code = assemble(vec![parsed_code], HashMap::new(), false); let expected_code = r#" @@ -338,7 +338,7 @@ mod tests { MOD "#; - let parsed_expected = parse(expected_code, HashSet::new()); + let parsed_expected = parse(expected_code, &HashSet::new()); let final_expected = assemble(vec![parsed_expected], HashMap::new(), false); assert_eq!(final_code.code, final_expected.code); @@ -346,7 +346,7 @@ mod tests { // Test with both features enabled. let active_features = HashSet::from(["feature_1", "feature_2"]); - let parsed_code = parse(code, active_features); + let parsed_code = parse(code, &active_features); let final_code = assemble(vec![parsed_code], HashMap::new(), false); let expected_code = r#" @@ -375,7 +375,7 @@ mod tests { MOD "#; - let parsed_expected = parse(expected_code, HashSet::new()); + let parsed_expected = parse(expected_code, &HashSet::new()); let final_expected = assemble(vec![parsed_expected], HashMap::new(), false); assert_eq!(final_code.code, final_expected.code); @@ -383,7 +383,7 @@ mod tests { // Test with all features disabled. let active_features = HashSet::new(); - let parsed_code = parse(code, active_features); + let parsed_code = parse(code, &active_features); let final_code = assemble(vec![parsed_code], HashMap::new(), false); let expected_code = r#" @@ -400,7 +400,7 @@ mod tests { DIV "#; - let parsed_expected = parse(expected_code, HashSet::new()); + let parsed_expected = parse(expected_code, &HashSet::new()); let final_expected = assemble(vec![parsed_expected], HashMap::new(), false); assert_eq!(final_code.code, final_expected.code); diff --git a/evm_arithmetization/src/cpu/kernel/tests/add11.rs b/evm_arithmetization/src/cpu/kernel/tests/add11.rs index a5d870bca..058fe48d8 100644 --- a/evm_arithmetization/src/cpu/kernel/tests/add11.rs +++ b/evm_arithmetization/src/cpu/kernel/tests/add11.rs @@ -15,7 +15,7 @@ use crate::generation::TrieInputs; use crate::proof::{BlockHashes, BlockMetadata, TrieRoots}; use crate::testing_utils::{ beacon_roots_account_nibbles, beacon_roots_contract_from_storage, ger_account_nibbles, - init_logger, preinitialized_state_and_storage_tries, update_beacon_roots_account_storage, + preinitialized_state_and_storage_tries, update_beacon_roots_account_storage, GLOBAL_EXIT_ROOT_ACCOUNT, }; use crate::GenerationInputs; @@ -210,7 +210,6 @@ fn test_add11_yml() { #[test] fn test_add11_yml_with_exception() { - init_logger(); // In this test, we make sure that the user code throws a stack underflow // exception. let beneficiary = hex!("2adc25665018aa1fe0e6bc666dac8fc2697ff9ba"); diff --git a/evm_arithmetization/src/fixed_recursive_verifier.rs b/evm_arithmetization/src/fixed_recursive_verifier.rs index 701ed1e9a..14e490ce2 100644 --- a/evm_arithmetization/src/fixed_recursive_verifier.rs +++ b/evm_arithmetization/src/fixed_recursive_verifier.rs @@ -50,7 +50,9 @@ use crate::recursive_verifier::{ recursive_stark_circuit, set_public_value_targets, PlonkWrapperCircuit, PublicInputs, StarkWrapperCircuit, }; -use crate::util::{h256_limbs, u256_limbs}; +use crate::util::h256_limbs; +#[cfg(feature = "cdk_erigon")] +use crate::util::u256_limbs; /// The recursion threshold. We end a chain of recursive proofs once we reach /// this size. From a1a919eb3df554bbf3b04ef6d6f1a4ef2d2749cb Mon Sep 17 00:00:00 2001 From: Linda Guiga Date: Thu, 15 Aug 2024 19:14:54 +0100 Subject: [PATCH 04/12] Revert macro to global change for pay_coinbase_and_refund_sender --- .../src/cpu/kernel/asm/core/process_txn.asm | 35 ++++++++----------- 1 file changed, 14 insertions(+), 21 deletions(-) diff --git a/evm_arithmetization/src/cpu/kernel/asm/core/process_txn.asm b/evm_arithmetization/src/cpu/kernel/asm/core/process_txn.asm index 3e7fb3d5a..a87e057f5 100644 --- a/evm_arithmetization/src/cpu/kernel/asm/core/process_txn.asm +++ b/evm_arithmetization/src/cpu/kernel/asm/core/process_txn.asm @@ -329,56 +329,49 @@ process_message_txn_fail: %transfer_eth %jumpi(panic) %jump(process_message_txn_after_call_contd) -global pay_coinbase_and_refund_sender: - // stack: leftover_gas, retdest +%macro pay_coinbase_and_refund_sender + // stack: leftover_gas DUP1 - // stack: leftover_gas, leftover_gas, retdest + // stack: leftover_gas, leftover_gas %mload_txn_field(@TXN_FIELD_GAS_LIMIT) SUB - // stack: used_gas, leftover_gas, retdest + // stack: used_gas, leftover_gas %mload_global_metadata(@GLOBAL_METADATA_REFUND_COUNTER) - // stack: refund, used_gas, leftover_gas, retdest + // stack: refund, used_gas, leftover_gas DUP2 %div_const(@MAX_REFUND_QUOTIENT) // max_refund = used_gas/5 - // stack: max_refund, refund, used_gas, leftover_gas, retdest + // stack: max_refund, refund, used_gas, leftover_gas %min %stack (refund, used_gas, leftover_gas) -> (leftover_gas, refund, refund, used_gas) ADD - // stack: leftover_gas', refund, used_gas, retdest + // stack: leftover_gas', refund, used_gas SWAP2 - // stack: used_gas, refund, leftover_gas', retdest + // stack: used_gas, refund, leftover_gas' SUB - // stack: used_gas', leftover_gas', retdest + // stack: used_gas', leftover_gas' // Pay the coinbase. %mload_txn_field(@TXN_FIELD_COMPUTED_PRIORITY_FEE_PER_GAS) MUL // stack: used_gas_tip, leftover_gas' %mload_global_metadata(@GLOBAL_METADATA_BLOCK_BENEFICIARY) - // stack: coinbase, used_gas_tip, leftover_gas', retdest + // stack: coinbase, used_gas_tip, leftover_gas' %add_eth - // stack: leftover_gas', retdest + // stack: leftover_gas' DUP1 // Refund gas to the origin. %mload_txn_field(@TXN_FIELD_COMPUTED_FEE_PER_GAS) MUL - // stack: leftover_gas_cost, leftover_gas', retdest + // stack: leftover_gas_cost, leftover_gas' %mload_txn_field(@TXN_FIELD_ORIGIN) - // stack: origin, leftover_gas_cost, leftover_gas', retdest + // stack: origin, leftover_gas_cost, leftover_gas' %add_eth - // stack: leftover_gas', retdest + // stack: leftover_gas' #[cfg(feature = cdk_erigon)] { %deduct_extra_burn_fees } - SWAP1 JUMP - -%macro pay_coinbase_and_refund_sender - // stack: leftover_gas - %stack (leftover_gas) -> (leftover_gas, %%after) - %jump(pay_coinbase_and_refund_sender) -%%after: %endmacro #[cfg(feature = cdk_erigon)] From 9adc580fa91255d7800d23ee1c5154af84cba822 Mon Sep 17 00:00:00 2001 From: Linda Guiga Date: Mon, 19 Aug 2024 18:56:53 +0200 Subject: [PATCH 05/12] Apply comments --- .../benches/fibonacci_25m_gas.rs | 1 - .../src/cpu/kernel/tests/add11.rs | 2 - .../src/fixed_recursive_verifier.rs | 41 ++++-- evm_arithmetization/src/generation/mod.rs | 22 +-- evm_arithmetization/src/get_challenges.rs | 15 +- evm_arithmetization/src/proof.rs | 138 ++++++++++++------ evm_arithmetization/src/recursive_verifier.rs | 36 +++-- evm_arithmetization/src/verifier.rs | 7 +- evm_arithmetization/tests/add11_yml.rs | 8 +- evm_arithmetization/tests/erc20.rs | 1 - evm_arithmetization/tests/erc721.rs | 1 - evm_arithmetization/tests/global_exit_root.rs | 1 - evm_arithmetization/tests/log_opcode.rs | 1 - evm_arithmetization/tests/selfdestruct.rs | 1 - evm_arithmetization/tests/simple_transfer.rs | 1 - evm_arithmetization/tests/withdrawals.rs | 1 - trace_decoder/src/decoding.rs | 10 +- 17 files changed, 188 insertions(+), 99 deletions(-) diff --git a/evm_arithmetization/benches/fibonacci_25m_gas.rs b/evm_arithmetization/benches/fibonacci_25m_gas.rs index 233712e82..5fa528037 100644 --- a/evm_arithmetization/benches/fibonacci_25m_gas.rs +++ b/evm_arithmetization/benches/fibonacci_25m_gas.rs @@ -178,7 +178,6 @@ fn prepare_setup() -> anyhow::Result { Ok(GenerationInputs { signed_txn: Some(txn.to_vec()), - #[cfg(feature = "cdk_erigon")] burn_addr: None, withdrawals: vec![], tries: tries_before, diff --git a/evm_arithmetization/src/cpu/kernel/tests/add11.rs b/evm_arithmetization/src/cpu/kernel/tests/add11.rs index 058fe48d8..b7e9771b7 100644 --- a/evm_arithmetization/src/cpu/kernel/tests/add11.rs +++ b/evm_arithmetization/src/cpu/kernel/tests/add11.rs @@ -181,7 +181,6 @@ fn test_add11_yml() { let inputs = GenerationInputs { signed_txn: Some(txn.to_vec()), - #[cfg(feature = "cdk_erigon")] burn_addr: None, withdrawals: vec![], global_exit_roots: vec![], @@ -364,7 +363,6 @@ fn test_add11_yml_with_exception() { let inputs = GenerationInputs { signed_txn: Some(txn.to_vec()), - #[cfg(feature = "cdk_erigon")] burn_addr: None, withdrawals: vec![], global_exit_roots: vec![], diff --git a/evm_arithmetization/src/fixed_recursive_verifier.rs b/evm_arithmetization/src/fixed_recursive_verifier.rs index 14e490ce2..bf8518fc4 100644 --- a/evm_arithmetization/src/fixed_recursive_verifier.rs +++ b/evm_arithmetization/src/fixed_recursive_verifier.rs @@ -38,11 +38,9 @@ use starky::stark::Stark; use crate::all_stark::{all_cross_table_lookups, AllStark, Table, NUM_TABLES}; use crate::generation::GenerationInputs; use crate::get_challenges::observe_public_values_target; -#[cfg(feature = "cdk_erigon")] -use crate::proof::BurnAddrTarget; use crate::proof::{ - AllProof, BlockHashesTarget, BlockMetadataTarget, ExtraBlockData, ExtraBlockDataTarget, - PublicValues, PublicValuesTarget, TrieRoots, TrieRootsTarget, + AllProof, BlockHashesTarget, BlockMetadataTarget, BurnAddrTarget, ExtraBlockData, + ExtraBlockDataTarget, PublicValues, PublicValuesTarget, TrieRoots, TrieRootsTarget, }; use crate::prover::{check_abort_signal, prove}; use crate::recursive_verifier::{ @@ -794,11 +792,11 @@ where BurnAddrTarget::connect( &mut builder, lhs_public_values.burn_addr, - rhs_public_values.burn_addr, + rhs_public_values.burn_addr.clone(), ); BurnAddrTarget::connect( &mut builder, - public_values.burn_addr, + public_values.burn_addr.clone(), rhs_public_values.burn_addr, ); } @@ -951,8 +949,16 @@ where #[cfg(feature = "cdk_erigon")] // Connect the burn address targets. { - BurnAddrTarget::connect(&mut builder, parent_pv.burn_addr, agg_pv.burn_addr); - BurnAddrTarget::connect(&mut builder, public_values.burn_addr, agg_pv.burn_addr); + BurnAddrTarget::connect( + &mut builder, + parent_pv.burn_addr.clone(), + agg_pv.burn_addr.clone(), + ); + BurnAddrTarget::connect( + &mut builder, + public_values.burn_addr.clone(), + agg_pv.burn_addr.clone(), + ); } // Make connections between block proofs, and check initial and final block @@ -1428,7 +1434,6 @@ where let agg_public_values = PublicValues { trie_roots_before: lhs_public_values.trie_roots_before, trie_roots_after: rhs_public_values.trie_roots_after, - #[cfg(feature = "cdk_erigon")] burn_addr: lhs_public_values.burn_addr, extra_block_data: ExtraBlockData { checkpoint_state_trie_root: lhs_public_values @@ -1551,16 +1556,20 @@ where nonzero_pis.insert(key, value); } - #[cfg(not(feature = "cdk_erigon"))] - let burn_addr_offset = 0; - #[cfg(feature = "cdk_erigon")] - let burn_addr_offset = BurnAddrTarget::SIZE; + let burn_addr_offset = match cfg!(feature = "cdk_erigon") { + true => BurnAddrTarget::get_size(), + false => 0, + }; #[cfg(feature = "cdk_erigon")] { - let burn_addr_keys = - TrieRootsTarget::SIZE * 2..TrieRootsTarget::SIZE * 2 + BurnAddrTarget::SIZE; - for (key, &value) in burn_addr_keys.zip_eq(&u256_limbs(public_values.burn_addr)) { + let burn_addr_keys = TrieRootsTarget::SIZE * 2 + ..TrieRootsTarget::SIZE * 2 + BurnAddrTarget::get_size(); + for (key, &value) in burn_addr_keys.zip_eq(&u256_limbs( + public_values + .burn_addr + .expect("We should have a burn addr when cdk_erigon is activated"), + )) { nonzero_pis.insert(key, value); } } diff --git a/evm_arithmetization/src/generation/mod.rs b/evm_arithmetization/src/generation/mod.rs index 5250b56c4..0ec9f85ae 100644 --- a/evm_arithmetization/src/generation/mod.rs +++ b/evm_arithmetization/src/generation/mod.rs @@ -1,7 +1,6 @@ use std::collections::HashMap; use anyhow::anyhow; -#[cfg(feature = "cdk_erigon")] use ethereum_types::H160; use ethereum_types::{Address, BigEndianHash, H256, U256}; use log::log_enabled; @@ -55,9 +54,9 @@ pub struct GenerationInputs { /// A None would yield an empty proof, otherwise this contains the encoding /// of a transaction. pub signed_txn: Option>, - #[cfg(feature = "cdk_erigon")] /// Target address for the base fee to be 'burnt', if there is one. If - /// `None`, then the base fee is directly burnt. + /// `None`, then the base fee is directly burnt. Note: this is only used + /// when feature `cdk_erigon` is activated. pub burn_addr: Option, /// Withdrawal pairs `(addr, amount)`. At the end of the txs, `amount` is /// added to `addr`'s balance. See EIP-4895. @@ -289,15 +288,20 @@ pub fn generate_traces, const D: usize>( gas_used_after, }; + let burn_addr = match cfg!(feature = "cdk_erigon") { + true => { + if let Some(burn_addr) = inputs.burn_addr { + Some(U256::from_big_endian(&burn_addr.0)) + } else { + Some(U256::MAX) + } + } + false => None, + }; let public_values = PublicValues { trie_roots_before, trie_roots_after, - #[cfg(feature = "cdk_erigon")] - burn_addr: if let Some(burn_addr) = inputs.burn_addr { - U256::from_big_endian(&burn_addr.0) - } else { - U256::MAX - }, + burn_addr, block_metadata: inputs.block_metadata, block_hashes: inputs.block_hashes, extra_block_data, diff --git a/evm_arithmetization/src/get_challenges.rs b/evm_arithmetization/src/get_challenges.rs index 3dd338350..8e0d34428 100644 --- a/evm_arithmetization/src/get_challenges.rs +++ b/evm_arithmetization/src/get_challenges.rs @@ -158,7 +158,10 @@ fn observe_burn_addr_target< ) where C::Hasher: AlgebraicHasher, { - challenger.observe_elements(&burn_addr.burn_addr); + match burn_addr { + BurnAddrTarget::BurnAddr(addr) => challenger.observe_elements(&addr), + BurnAddrTarget::Burnt() => panic!("There should be an address set in cdk_erigon."), + } } fn observe_block_hashes< @@ -206,7 +209,13 @@ pub(crate) fn observe_public_values< #[cfg(feature = "cdk_erigon")] { observe_extra_block_data::(challenger, &public_values.extra_block_data)?; - observe_burn_addr::(challenger, public_values.burn_addr) + + observe_burn_addr::( + challenger, + public_values + .burn_addr + .expect("There should be an address set in cdk_erigon."), + ) } } @@ -226,7 +235,7 @@ pub(crate) fn observe_public_values_target< observe_block_hashes_target::(challenger, &public_values.block_hashes); observe_extra_block_data_target::(challenger, &public_values.extra_block_data); #[cfg(feature = "cdk_erigon")] - observe_burn_addr_target::(challenger, public_values.burn_addr); + observe_burn_addr_target::(challenger, public_values.burn_addr.clone()); } impl, C: GenericConfig, const D: usize> AllProof { diff --git a/evm_arithmetization/src/proof.rs b/evm_arithmetization/src/proof.rs index 6b37cb2a7..1a301cbb9 100644 --- a/evm_arithmetization/src/proof.rs +++ b/evm_arithmetization/src/proof.rs @@ -11,7 +11,6 @@ use starky::lookup::GrandProductChallengeSet; use starky::proof::{MultiProof, StarkProofChallenges}; use crate::all_stark::NUM_TABLES; -#[cfg(feature = "cdk_erigon")] use crate::util::get_u256; use crate::util::{get_h160, get_h256, h2u}; @@ -48,9 +47,9 @@ pub struct PublicValues { pub trie_roots_before: TrieRoots, /// Trie hashes after the execution of the local state transition. pub trie_roots_after: TrieRoots, - #[cfg(feature = "cdk_erigon")] - /// Address to store the base fee to be burnt. - pub burn_addr: U256, + /// Address to store the base fee to be burnt: only used when feature + /// `cdk_erigon` is active. + pub burn_addr: Option, /// Block metadata: it remains unchanged within a block. pub block_metadata: BlockMetadata, /// 256 previous block hashes and current block's hash. @@ -66,17 +65,20 @@ impl PublicValues { pub fn from_public_inputs(pis: &[F]) -> Self { assert!(PublicValuesTarget::SIZE <= pis.len()); - #[cfg(not(feature = "cdk_erigon"))] - let burn_addr_offset = 0; - #[cfg(feature = "cdk_erigon")] - let burn_addr_offset = BurnAddrTarget::SIZE; + let burn_addr_offset = match cfg!(feature = "cdk_erigon") { + true => BurnAddrTarget::get_size(), + false => 0, + }; let trie_roots_before = TrieRoots::from_public_inputs(&pis[0..TrieRootsTarget::SIZE]); let trie_roots_after = TrieRoots::from_public_inputs(&pis[TrieRootsTarget::SIZE..TrieRootsTarget::SIZE * 2]); - #[cfg(feature = "cdk_erigon")] - let burn_addr = get_u256( - &pis[TrieRootsTarget::SIZE * 2..TrieRootsTarget::SIZE * 2 + BurnAddrTarget::SIZE], - ); + let burn_addr = match cfg!(feature = "cdk_erigon") { + true => Some(get_u256( + &pis[TrieRootsTarget::SIZE * 2 + ..TrieRootsTarget::SIZE * 2 + BurnAddrTarget::get_size()], + )), + false => None, + }; let block_metadata = BlockMetadata::from_public_inputs( &pis[burn_addr_offset + TrieRootsTarget::SIZE * 2 ..burn_addr_offset + TrieRootsTarget::SIZE * 2 + BlockMetadataTarget::SIZE], @@ -103,7 +105,6 @@ impl PublicValues { Self { trie_roots_before, trie_roots_after, - #[cfg(feature = "cdk_erigon")] burn_addr, block_metadata, block_hashes, @@ -301,7 +302,6 @@ pub struct PublicValuesTarget { pub trie_roots_before: TrieRootsTarget, /// Trie hashes after the execution of the local state transition. pub trie_roots_after: TrieRootsTarget, - #[cfg(feature = "cdk_erigon")] /// Address to store the base fee to be burnt. pub burn_addr: BurnAddrTarget, /// Block metadata: it remains unchanged within a block. @@ -406,9 +406,9 @@ impl PublicValuesTarget { receipts_root: buffer.read_target_array()?, }; - #[cfg(feature = "cdk_erigon")] - let burn_addr = BurnAddrTarget { - burn_addr: buffer.read_target_array()?, + let burn_addr = match cfg!(feature = "cdk_erigon") { + true => BurnAddrTarget::BurnAddr(buffer.read_target_array()?), + false => BurnAddrTarget::Burnt(), }; let block_metadata = BlockMetadataTarget { @@ -443,7 +443,6 @@ impl PublicValuesTarget { Ok(Self { trie_roots_before, trie_roots_after, - #[cfg(feature = "cdk_erigon")] burn_addr, block_metadata, block_hashes, @@ -464,18 +463,18 @@ impl PublicValuesTarget { - 1 ); - #[cfg(not(feature = "cdk_erigon"))] - let burn_addr_offset = 0; - #[cfg(feature = "cdk_erigon")] - let burn_addr_offset = BurnAddrTarget::SIZE; + let burn_addr_offset = match cfg!(feature = "cdk_erigon") { + true => BurnAddrTarget::get_size(), + false => 0, + }; Self { trie_roots_before: TrieRootsTarget::from_public_inputs(&pis[0..TrieRootsTarget::SIZE]), trie_roots_after: TrieRootsTarget::from_public_inputs( &pis[TrieRootsTarget::SIZE..TrieRootsTarget::SIZE * 2], ), - #[cfg(feature = "cdk_erigon")] burn_addr: BurnAddrTarget::from_public_inputs( - &pis[TrieRootsTarget::SIZE * 2..TrieRootsTarget::SIZE * 2 + BurnAddrTarget::SIZE], + &pis[TrieRootsTarget::SIZE * 2 + ..TrieRootsTarget::SIZE * 2 + BurnAddrTarget::get_size()], ), block_metadata: BlockMetadataTarget::from_public_inputs( &pis[burn_addr_offset + TrieRootsTarget::SIZE * 2 @@ -522,7 +521,6 @@ impl PublicValuesTarget { pv0.trie_roots_after, pv1.trie_roots_after, ), - #[cfg(feature = "cdk_erigon")] burn_addr: BurnAddrTarget::select(builder, condition, pv0.burn_addr, pv1.burn_addr), block_metadata: BlockMetadataTarget::select( builder, @@ -620,23 +618,27 @@ impl TrieRootsTarget { /// Circuit version of `BurnAddr`. /// Address used to store the base fee to be burnt. -#[derive(Eq, PartialEq, Debug, Copy, Clone)] -#[cfg(feature = "cdk_erigon")] -pub struct BurnAddrTarget { - pub(crate) burn_addr: [Target; 8], +#[derive(Eq, PartialEq, Debug, Clone)] +pub enum BurnAddrTarget { + BurnAddr([Target; 8]), + Burnt(), } -#[cfg(feature = "cdk_erigon")] impl BurnAddrTarget { - /// Number of `Target`s required for the burn address. - pub(crate) const SIZE: usize = 8; + pub fn get_size() -> usize { + match cfg!(feature = "cdk_erigon") { + true => 8, + false => 0, + } + } /// Extracts the burn address from the provided public input /// `Target`s. The provided `pis` should start with the burn address. pub(crate) fn from_public_inputs(pis: &[Target]) -> Self { - let burn_addr = pis[0..8].try_into().unwrap(); - - Self { burn_addr } + match cfg!(feature = "cdk_erigon") { + true => BurnAddrTarget::BurnAddr(pis[0..8].try_into().unwrap()), + false => BurnAddrTarget::Burnt(), + } } /// If `condition`, returns the burn address in `ba0`, @@ -647,10 +649,16 @@ impl BurnAddrTarget { ba0: Self, ba1: Self, ) -> Self { - Self { - burn_addr: core::array::from_fn(|i| { - builder.select(condition, ba0.burn_addr[i], ba1.burn_addr[i]) - }), + match cfg!(feature = "cdk_erigon") { + true => match (ba0, ba1) { + (BurnAddrTarget::BurnAddr(a0), BurnAddrTarget::BurnAddr(a1)) => { + BurnAddrTarget::BurnAddr(core::array::from_fn(|i| { + builder.select(condition, a0[i], a1[i]) + })) + } + _ => panic!("We should have set an address before already"), + }, + false => BurnAddrTarget::Burnt(), } } @@ -660,12 +668,60 @@ impl BurnAddrTarget { ba0: Self, ba1: Self, ) { - for i in 0..5 { - builder.connect(ba0.burn_addr[i], ba1.burn_addr[i]); + match cfg!(feature = "cdk_erigon") { + true => match (ba0, ba1) { + (BurnAddrTarget::BurnAddr(a0), BurnAddrTarget::BurnAddr(a1)) => { + for i in 0..5 { + builder.connect(a0[i], a1[i]); + } + } + _ => panic!("We should have set an address before already"), + }, + false => (), } } } +// #[cfg(feature = "cdk_erigon")] +// impl BurnAddrTarget { +// /// Number of `Target`s required for the burn address. +// pub(crate) const SIZE: usize = 8; + +// /// Extracts the burn address from the provided public input +// /// `Target`s. The provided `pis` should start with the burn address. +// pub(crate) fn from_public_inputs(pis: &[Target]) -> Self { +// let burn_addr = pis[0..8].try_into().unwrap(); + +// Self { burn_addr } +// } + +// /// If `condition`, returns the burn address in `ba0`, +// /// otherwise returns the burn address in `ba1`. +// pub(crate) fn select, const D: usize>( +// builder: &mut CircuitBuilder, +// condition: BoolTarget, +// ba0: Self, +// ba1: Self, +// ) -> Self { +// Self { +// burn_addr: core::array::from_fn(|i| { +// builder.select(condition, ba0.burn_addr[i], ba1.burn_addr[i]) +// }), +// } +// } + +// /// Connects the burn address in `ba0` to the burn address in `ba1`. +// pub(crate) fn connect, const D: usize>( +// builder: &mut CircuitBuilder, +// ba0: Self, +// ba1: Self, +// ) { +// for i in 0..5 { +// builder.connect(ba0.burn_addr[i], ba1.burn_addr[i]); +// } +// } +// } + /// Circuit version of `BlockMetadata`. /// Metadata contained in a block header. Those are identical between /// all state transition proofs within the same block. diff --git a/evm_arithmetization/src/recursive_verifier.rs b/evm_arithmetization/src/recursive_verifier.rs index 37e2921c9..d9934265d 100644 --- a/evm_arithmetization/src/recursive_verifier.rs +++ b/evm_arithmetization/src/recursive_verifier.rs @@ -34,11 +34,10 @@ use crate::cpu::kernel::aggregator::KERNEL; use crate::cpu::kernel::constants::global_metadata::GlobalMetadata; use crate::memory::segments::Segment; use crate::memory::VALUE_LIMBS; -#[cfg(feature = "cdk_erigon")] -use crate::proof::BurnAddrTarget; use crate::proof::{ - BlockHashes, BlockHashesTarget, BlockMetadata, BlockMetadataTarget, ExtraBlockData, - ExtraBlockDataTarget, PublicValues, PublicValuesTarget, TrieRoots, TrieRootsTarget, + BlockHashes, BlockHashesTarget, BlockMetadata, BlockMetadataTarget, BurnAddrTarget, + ExtraBlockData, ExtraBlockDataTarget, PublicValues, PublicValuesTarget, TrieRoots, + TrieRootsTarget, }; use crate::util::{h256_limbs, u256_limbs, u256_to_u32, u256_to_u64}; use crate::witness::errors::ProgramError; @@ -426,6 +425,11 @@ pub(crate) fn get_memory_extra_looking_sum_circuit, ); }); + #[cfg(feature = "cdk_erigon")] + let burn_addr = match public_values.burn_addr { + BurnAddrTarget::BurnAddr(addr) => addr, + BurnAddrTarget::Burnt() => panic!("There should be an address set in cdk_erigon."), + }; #[cfg(feature = "cdk_erigon")] let mut sum = add_data_write( builder, @@ -433,7 +437,7 @@ pub(crate) fn get_memory_extra_looking_sum_circuit, sum, metadata_segment, GlobalMetadata::BurnAddr.unscale(), - &public_values.burn_addr.burn_addr, + &burn_addr, ); block_fields_arrays.map(|(field, targets)| { @@ -583,7 +587,6 @@ pub(crate) fn add_virtual_public_values, const D: u ) -> PublicValuesTarget { let trie_roots_before = add_virtual_trie_roots(builder); let trie_roots_after = add_virtual_trie_roots(builder); - #[cfg(feature = "cdk_erigon")] let burn_addr = add_virtual_burn_addr(builder); let block_metadata = add_virtual_block_metadata(builder); let block_hashes = add_virtual_block_hashes(builder); @@ -591,7 +594,6 @@ pub(crate) fn add_virtual_public_values, const D: u PublicValuesTarget { trie_roots_before, trie_roots_after, - #[cfg(feature = "cdk_erigon")] burn_addr, block_metadata, block_hashes, @@ -599,12 +601,13 @@ pub(crate) fn add_virtual_public_values, const D: u } } -#[cfg(feature = "cdk_erigon")] pub(crate) fn add_virtual_burn_addr, const D: usize>( builder: &mut CircuitBuilder, ) -> BurnAddrTarget { - let burn_addr = builder.add_virtual_public_input_arr(); - BurnAddrTarget { burn_addr } + match cfg!(feature = "cdk_erigon") { + true => BurnAddrTarget::BurnAddr(builder.add_virtual_public_input_arr()), + false => BurnAddrTarget::Burnt(), + } } pub(crate) fn add_virtual_trie_roots, const D: usize>( @@ -732,7 +735,9 @@ where set_burn_addr_target( witness, &public_values_target.burn_addr, - public_values.burn_addr, + public_values + .burn_addr + .expect("There should be an address set in cdk_erigon."), )?; Ok(()) @@ -802,8 +807,13 @@ where F: RichField + Extendable, W: Witness, { - let burn_addr_limbs: [F; 8] = u256_limbs::(burn_addr); - witness.set_target_arr(&burn_addr_target.burn_addr, &burn_addr_limbs); + match burn_addr_target { + BurnAddrTarget::BurnAddr(addr_target) => { + let burn_addr_limbs: [F; 8] = u256_limbs::(burn_addr); + witness.set_target_arr(addr_target, &burn_addr_limbs); + } + BurnAddrTarget::Burnt() => panic!("There should be an address set in cdk_erigon."), + } Ok(()) } diff --git a/evm_arithmetization/src/verifier.rs b/evm_arithmetization/src/verifier.rs index efce24b81..74cb8ce68 100644 --- a/evm_arithmetization/src/verifier.rs +++ b/evm_arithmetization/src/verifier.rs @@ -155,7 +155,12 @@ where U256::from_big_endian(&public_values.block_metadata.block_beneficiary.0), ), #[cfg(feature = "cdk_erigon")] - (GlobalMetadata::BurnAddr, public_values.burn_addr), + ( + GlobalMetadata::BurnAddr, + public_values + .burn_addr + .expect("There should be an address set in cdk_erigon."), + ), ( GlobalMetadata::BlockTimestamp, public_values.block_metadata.block_timestamp, diff --git a/evm_arithmetization/tests/add11_yml.rs b/evm_arithmetization/tests/add11_yml.rs index 10b74a88c..de9078b28 100644 --- a/evm_arithmetization/tests/add11_yml.rs +++ b/evm_arithmetization/tests/add11_yml.rs @@ -179,10 +179,14 @@ fn add11_yml() -> anyhow::Result<()> { transactions_root: transactions_trie.hash(), receipts_root: receipts_trie.hash(), }; + + let burn_addr = match cfg!(feature = "cdk_erigon") { + true => Some(Address::from(beneficiary)), + false => None, + }; let inputs = GenerationInputs { signed_txn: Some(txn.to_vec()), - #[cfg(feature = "cdk_erigon")] - burn_addr: Some(Address::from(beneficiary)), + burn_addr, withdrawals: vec![], global_exit_roots: vec![], tries: tries_before, diff --git a/evm_arithmetization/tests/erc20.rs b/evm_arithmetization/tests/erc20.rs index 0a89fa114..25896bacf 100644 --- a/evm_arithmetization/tests/erc20.rs +++ b/evm_arithmetization/tests/erc20.rs @@ -180,7 +180,6 @@ fn test_erc20() -> anyhow::Result<()> { }; let inputs = GenerationInputs { signed_txn: Some(txn.to_vec()), - #[cfg(feature = "cdk_erigon")] burn_addr: None, withdrawals: vec![], global_exit_roots: vec![], diff --git a/evm_arithmetization/tests/erc721.rs b/evm_arithmetization/tests/erc721.rs index f2dd0ffdc..c16a212e3 100644 --- a/evm_arithmetization/tests/erc721.rs +++ b/evm_arithmetization/tests/erc721.rs @@ -184,7 +184,6 @@ fn test_erc721() -> anyhow::Result<()> { let inputs = GenerationInputs { signed_txn: Some(txn.to_vec()), - #[cfg(feature = "cdk_erigon")] burn_addr: None, withdrawals: vec![], global_exit_roots: vec![], diff --git a/evm_arithmetization/tests/global_exit_root.rs b/evm_arithmetization/tests/global_exit_root.rs index 1d3f5997a..f670a1a3b 100644 --- a/evm_arithmetization/tests/global_exit_root.rs +++ b/evm_arithmetization/tests/global_exit_root.rs @@ -78,7 +78,6 @@ fn test_global_exit_root() -> anyhow::Result<()> { let inputs = GenerationInputs { signed_txn: None, - #[cfg(feature = "cdk_erigon")] burn_addr: None, withdrawals: vec![], global_exit_roots, diff --git a/evm_arithmetization/tests/log_opcode.rs b/evm_arithmetization/tests/log_opcode.rs index 58cf62943..28f10e636 100644 --- a/evm_arithmetization/tests/log_opcode.rs +++ b/evm_arithmetization/tests/log_opcode.rs @@ -239,7 +239,6 @@ fn test_log_opcodes() -> anyhow::Result<()> { let inputs = GenerationInputs { signed_txn: Some(txn.to_vec()), - #[cfg(feature = "cdk_erigon")] burn_addr: None, withdrawals: vec![], global_exit_roots: vec![], diff --git a/evm_arithmetization/tests/selfdestruct.rs b/evm_arithmetization/tests/selfdestruct.rs index a5d30d220..1f7c4195f 100644 --- a/evm_arithmetization/tests/selfdestruct.rs +++ b/evm_arithmetization/tests/selfdestruct.rs @@ -154,7 +154,6 @@ fn test_selfdestruct() -> anyhow::Result<()> { }; let inputs = GenerationInputs { signed_txn: Some(txn.to_vec()), - #[cfg(feature = "cdk_erigon")] burn_addr: None, withdrawals: vec![], global_exit_roots: vec![], diff --git a/evm_arithmetization/tests/simple_transfer.rs b/evm_arithmetization/tests/simple_transfer.rs index 699da5060..21419afed 100644 --- a/evm_arithmetization/tests/simple_transfer.rs +++ b/evm_arithmetization/tests/simple_transfer.rs @@ -146,7 +146,6 @@ fn test_simple_transfer() -> anyhow::Result<()> { }; let inputs = GenerationInputs { signed_txn: Some(txn.to_vec()), - #[cfg(feature = "cdk_erigon")] burn_addr: None, withdrawals: vec![], global_exit_roots: vec![], diff --git a/evm_arithmetization/tests/withdrawals.rs b/evm_arithmetization/tests/withdrawals.rs index a5b19f93c..25d48b8a6 100644 --- a/evm_arithmetization/tests/withdrawals.rs +++ b/evm_arithmetization/tests/withdrawals.rs @@ -86,7 +86,6 @@ fn test_withdrawals() -> anyhow::Result<()> { let inputs = GenerationInputs { signed_txn: None, - #[cfg(feature = "cdk_erigon")] burn_addr: None, withdrawals, global_exit_roots: vec![], diff --git a/trace_decoder/src/decoding.rs b/trace_decoder/src/decoding.rs index 0ca068d97..5d21f7b36 100644 --- a/trace_decoder/src/decoding.rs +++ b/trace_decoder/src/decoding.rs @@ -1,7 +1,6 @@ use std::collections::HashMap; use anyhow::{anyhow, Context as _}; -#[cfg(feature = "cdk_erigon")] use ethereum_types::H160; use ethereum_types::{Address, BigEndianHash, H256, U256, U512}; use evm_arithmetization::{ @@ -547,11 +546,14 @@ fn process_txn_info( delta_out, )?; + let burn_addr = match cfg!(feature = "cdk_erigon") { + // TODO: retrieve the actual burn address from cdk-erigon. + true => Some(H160::zero()), + false => None, + }; let gen_inputs = GenerationInputs { txn_number_before: extra_data.txn_number_before, - // TODO: retrieve the actual burn address from cdk-erigon. - #[cfg(feature = "cdk_erigon")] - burn_addr: Some(H160::zero()), + burn_addr, gas_used_before: extra_data.gas_used_before, gas_used_after: extra_data.gas_used_after, signed_txn: txn_info.meta.txn_bytes, From e9fc82e2c6ea04f80c14dff6280f46376156a02a Mon Sep 17 00:00:00 2001 From: Linda Guiga Date: Wed, 21 Aug 2024 16:49:19 +0200 Subject: [PATCH 06/12] Cleanup --- evm_arithmetization/src/proof.rs | 48 +++---------------- evm_arithmetization/src/recursive_verifier.rs | 2 +- 2 files changed, 7 insertions(+), 43 deletions(-) diff --git a/evm_arithmetization/src/proof.rs b/evm_arithmetization/src/proof.rs index 1a301cbb9..907410874 100644 --- a/evm_arithmetization/src/proof.rs +++ b/evm_arithmetization/src/proof.rs @@ -650,13 +650,15 @@ impl BurnAddrTarget { ba1: Self, ) -> Self { match cfg!(feature = "cdk_erigon") { + // If the `cdk_erigon` feature is activated, both `ba0` and `ba1` should be of type + // `BurnAddr`. true => match (ba0, ba1) { (BurnAddrTarget::BurnAddr(a0), BurnAddrTarget::BurnAddr(a1)) => { BurnAddrTarget::BurnAddr(core::array::from_fn(|i| { builder.select(condition, a0[i], a1[i]) })) } - _ => panic!("We should have set an address before already"), + _ => panic!("We should have already set an address (or U256::MAX) before."), }, false => BurnAddrTarget::Burnt(), } @@ -669,59 +671,21 @@ impl BurnAddrTarget { ba1: Self, ) { match cfg!(feature = "cdk_erigon") { + // If the `cdk_erigon` feature is activated, both `ba0` and `ba1` should be of type + // `BurnAddr`. true => match (ba0, ba1) { (BurnAddrTarget::BurnAddr(a0), BurnAddrTarget::BurnAddr(a1)) => { for i in 0..5 { builder.connect(a0[i], a1[i]); } } - _ => panic!("We should have set an address before already"), + _ => panic!("We should have already set an address (or U256::MAX) before."), }, false => (), } } } -// #[cfg(feature = "cdk_erigon")] -// impl BurnAddrTarget { -// /// Number of `Target`s required for the burn address. -// pub(crate) const SIZE: usize = 8; - -// /// Extracts the burn address from the provided public input -// /// `Target`s. The provided `pis` should start with the burn address. -// pub(crate) fn from_public_inputs(pis: &[Target]) -> Self { -// let burn_addr = pis[0..8].try_into().unwrap(); - -// Self { burn_addr } -// } - -// /// If `condition`, returns the burn address in `ba0`, -// /// otherwise returns the burn address in `ba1`. -// pub(crate) fn select, const D: usize>( -// builder: &mut CircuitBuilder, -// condition: BoolTarget, -// ba0: Self, -// ba1: Self, -// ) -> Self { -// Self { -// burn_addr: core::array::from_fn(|i| { -// builder.select(condition, ba0.burn_addr[i], ba1.burn_addr[i]) -// }), -// } -// } - -// /// Connects the burn address in `ba0` to the burn address in `ba1`. -// pub(crate) fn connect, const D: usize>( -// builder: &mut CircuitBuilder, -// ba0: Self, -// ba1: Self, -// ) { -// for i in 0..5 { -// builder.connect(ba0.burn_addr[i], ba1.burn_addr[i]); -// } -// } -// } - /// Circuit version of `BlockMetadata`. /// Metadata contained in a block header. Those are identical between /// all state transition proofs within the same block. diff --git a/evm_arithmetization/src/recursive_verifier.rs b/evm_arithmetization/src/recursive_verifier.rs index d9934265d..acb620700 100644 --- a/evm_arithmetization/src/recursive_verifier.rs +++ b/evm_arithmetization/src/recursive_verifier.rs @@ -812,7 +812,7 @@ where let burn_addr_limbs: [F; 8] = u256_limbs::(burn_addr); witness.set_target_arr(addr_target, &burn_addr_limbs); } - BurnAddrTarget::Burnt() => panic!("There should be an address set in cdk_erigon."), + BurnAddrTarget::Burnt() => panic!("There should be an address target set in cdk_erigon."), } Ok(()) From 0c3b00c6f4973fd55d978980a2ce3f00e9cd3b95 Mon Sep 17 00:00:00 2001 From: Linda Guiga Date: Wed, 21 Aug 2024 17:11:39 +0200 Subject: [PATCH 07/12] Fix Clippy --- evm_arithmetization/src/proof.rs | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/evm_arithmetization/src/proof.rs b/evm_arithmetization/src/proof.rs index 907410874..33eda11c1 100644 --- a/evm_arithmetization/src/proof.rs +++ b/evm_arithmetization/src/proof.rs @@ -670,18 +670,17 @@ impl BurnAddrTarget { ba0: Self, ba1: Self, ) { - match cfg!(feature = "cdk_erigon") { - // If the `cdk_erigon` feature is activated, both `ba0` and `ba1` should be of type - // `BurnAddr`. - true => match (ba0, ba1) { + if cfg!(feature = "cdk_erigon") == true { + // If the `cdk_erigon` feature is activated, both `ba0` and `ba1` should be of + // type `BurnAddr`. + match (ba0, ba1) { (BurnAddrTarget::BurnAddr(a0), BurnAddrTarget::BurnAddr(a1)) => { for i in 0..5 { builder.connect(a0[i], a1[i]); } } _ => panic!("We should have already set an address (or U256::MAX) before."), - }, - false => (), + } } } } From 8c7cd8c8b19b538aac3331b77d502f3f256de9d6 Mon Sep 17 00:00:00 2001 From: Linda Guiga Date: Thu, 22 Aug 2024 17:46:02 +0200 Subject: [PATCH 08/12] Remove feature in trace_decoder, and add it to zero_bin --- Cargo.lock | 1 + .../src/fixed_recursive_verifier.rs | 54 +++++++++---------- evm_arithmetization/src/proof.rs | 4 +- evm_arithmetization/src/prover.rs | 6 +++ trace_decoder/Cargo.toml | 3 -- trace_decoder/benches/block_processing.rs | 3 +- trace_decoder/src/decoding.rs | 5 +- trace_decoder/src/lib.rs | 2 + trace_decoder/tests/trace_decoder_tests.rs | 14 ++++- zero_bin/leader/Cargo.toml | 2 + zero_bin/prover/Cargo.toml | 1 + zero_bin/prover/src/lib.rs | 18 +++++-- 12 files changed, 74 insertions(+), 39 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 33b8be650..d0aec0fdc 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2859,6 +2859,7 @@ dependencies = [ "cargo_metadata", "clap", "dotenvy", + "evm_arithmetization", "futures", "ops", "paladin-core", diff --git a/evm_arithmetization/src/fixed_recursive_verifier.rs b/evm_arithmetization/src/fixed_recursive_verifier.rs index bf8518fc4..9cc50c0aa 100644 --- a/evm_arithmetization/src/fixed_recursive_verifier.rs +++ b/evm_arithmetization/src/fixed_recursive_verifier.rs @@ -786,20 +786,19 @@ where lhs_public_values.trie_roots_after, rhs_public_values.trie_roots_before, ); - #[cfg(feature = "cdk_erigon")] - { - // Connect the burn address targets. - BurnAddrTarget::connect( - &mut builder, - lhs_public_values.burn_addr, - rhs_public_values.burn_addr.clone(), - ); - BurnAddrTarget::connect( - &mut builder, - public_values.burn_addr.clone(), - rhs_public_values.burn_addr, - ); - } + + // Connect the burn address targets. + BurnAddrTarget::connect( + &mut builder, + lhs_public_values.burn_addr, + rhs_public_values.burn_addr.clone(), + ); + BurnAddrTarget::connect( + &mut builder, + public_values.burn_addr.clone(), + rhs_public_values.burn_addr, + ); + Self::connect_extra_public_values( &mut builder, &public_values.extra_block_data, @@ -946,20 +945,18 @@ where public_values.extra_block_data, agg_pv.extra_block_data, ); - #[cfg(feature = "cdk_erigon")] + // Connect the burn address targets. - { - BurnAddrTarget::connect( - &mut builder, - parent_pv.burn_addr.clone(), - agg_pv.burn_addr.clone(), - ); - BurnAddrTarget::connect( - &mut builder, - public_values.burn_addr.clone(), - agg_pv.burn_addr.clone(), - ); - } + BurnAddrTarget::connect( + &mut builder, + parent_pv.burn_addr.clone(), + agg_pv.burn_addr.clone(), + ); + BurnAddrTarget::connect( + &mut builder, + public_values.burn_addr.clone(), + agg_pv.burn_addr.clone(), + ); // Make connections between block proofs, and check initial and final block // values. @@ -1222,6 +1219,9 @@ where timing: &mut TimingTree, abort_signal: Option>, ) -> anyhow::Result<(ProofWithPublicInputs, PublicValues)> { + if generation_inputs.burn_addr.is_some() && !cfg!(feature = "cdk_erigon") { + log::warn!("The burn address in the GenerationInputs will be ignored, as the `cdk_erigon` feature is not activated.") + } let all_proof = prove::( all_stark, config, diff --git a/evm_arithmetization/src/proof.rs b/evm_arithmetization/src/proof.rs index 33eda11c1..ac0a2506d 100644 --- a/evm_arithmetization/src/proof.rs +++ b/evm_arithmetization/src/proof.rs @@ -670,12 +670,14 @@ impl BurnAddrTarget { ba0: Self, ba1: Self, ) { + // There only are targets to connect if there is a burn address, i.e. when the + // `cdk_erigon` feature is active. if cfg!(feature = "cdk_erigon") == true { // If the `cdk_erigon` feature is activated, both `ba0` and `ba1` should be of // type `BurnAddr`. match (ba0, ba1) { (BurnAddrTarget::BurnAddr(a0), BurnAddrTarget::BurnAddr(a1)) => { - for i in 0..5 { + for i in 0..BurnAddrTarget::get_size() { builder.connect(a0[i], a1[i]); } } diff --git a/evm_arithmetization/src/prover.rs b/evm_arithmetization/src/prover.rs index f6c40cf89..88a674a0b 100644 --- a/evm_arithmetization/src/prover.rs +++ b/evm_arithmetization/src/prover.rs @@ -37,6 +37,9 @@ where F: RichField + Extendable, C: GenericConfig, { + if inputs.burn_addr.is_some() && !cfg!(feature = "cdk_erigon") { + log::warn!("The burn address in the GenerationInputs will be ignored, as the `cdk_erigon` feature is not activated.") + } timed!(timing, "build kernel", Lazy::force(&KERNEL)); let (traces, public_values) = timed!( timing, @@ -377,6 +380,9 @@ pub mod testing { /// Simulates the zkEVM CPU execution. /// It does not generate any trace or proof of correct state transition. pub fn simulate_execution(inputs: GenerationInputs) -> Result<()> { + if inputs.burn_addr.is_some() && !cfg!(feature = "cdk_erigon") { + log::warn!("The burn address in the GenerationInputs will be ignored, as the `cdk_erigon` feature is not activated.") + } let initial_stack = vec![]; let initial_offset = KERNEL.global_labels["main"]; let mut interpreter: Interpreter = diff --git a/trace_decoder/Cargo.toml b/trace_decoder/Cargo.toml index 9bb6a1666..45aa8bc9a 100644 --- a/trace_decoder/Cargo.toml +++ b/trace_decoder/Cargo.toml @@ -49,9 +49,6 @@ plonky2_maybe_rayon = { workspace = true } alloy = { workspace = true } rstest = "0.21.0" -[features] -cdk_erigon = [] - [[bench]] name = "block_processing" harness = false diff --git a/trace_decoder/benches/block_processing.rs b/trace_decoder/benches/block_processing.rs index 784b487db..5d142bb1d 100644 --- a/trace_decoder/benches/block_processing.rs +++ b/trace_decoder/benches/block_processing.rs @@ -26,7 +26,8 @@ fn criterion_benchmark(c: &mut Criterion) { block_trace, other_data, }| { - trace_decoder::entrypoint(block_trace, other_data, |_| unimplemented!()).unwrap() + trace_decoder::entrypoint(block_trace, other_data, |_| unimplemented!(), false) + .unwrap() }, BatchSize::LargeInput, ) diff --git a/trace_decoder/src/decoding.rs b/trace_decoder/src/decoding.rs index 5d21f7b36..99ea01461 100644 --- a/trace_decoder/src/decoding.rs +++ b/trace_decoder/src/decoding.rs @@ -53,6 +53,7 @@ pub fn into_txn_proof_gen_ir( withdrawals, }: ProcessedBlockTrace, other_data: OtherBlockData, + use_burn_addr: bool, ) -> anyhow::Result> { let mut curr_block_tries = PartialTrieState { state: state.clone(), @@ -89,6 +90,7 @@ pub fn into_txn_proof_gen_ir( &mut curr_block_tries, &mut extra_data, &other_data, + use_burn_addr, ) .context(format!("at transaction index {}", current_idx)) }) @@ -493,6 +495,7 @@ fn process_txn_info( curr_block_tries: &mut PartialTrieState, extra_data: &mut ExtraBlockData, other_data: &OtherBlockData, + use_burn_target: bool, ) -> anyhow::Result { log::trace!("Generating proof IR for txn {}...", txn_idx); @@ -546,7 +549,7 @@ fn process_txn_info( delta_out, )?; - let burn_addr = match cfg!(feature = "cdk_erigon") { + let burn_addr = match use_burn_target { // TODO: retrieve the actual burn address from cdk-erigon. true => Some(H160::zero()), false => None, diff --git a/trace_decoder/src/lib.rs b/trace_decoder/src/lib.rs index a095e850a..5b6fd0de0 100644 --- a/trace_decoder/src/lib.rs +++ b/trace_decoder/src/lib.rs @@ -290,6 +290,7 @@ pub fn entrypoint( trace: BlockTrace, other: OtherBlockData, resolve: impl Fn(H256) -> Vec, + use_burn_addr: bool, ) -> anyhow::Result> { use anyhow::Context as _; use mpt_trie::partial_trie::PartialTrie as _; @@ -443,6 +444,7 @@ pub fn entrypoint( withdrawals: other.b_data.withdrawals.clone(), }, other, + use_burn_addr, ) } diff --git a/trace_decoder/tests/trace_decoder_tests.rs b/trace_decoder/tests/trace_decoder_tests.rs index e4938b8f3..9d4e2ad77 100644 --- a/trace_decoder/tests/trace_decoder_tests.rs +++ b/trace_decoder/tests/trace_decoder_tests.rs @@ -77,12 +77,14 @@ fn derive_header_file_path(witness_file_path: &Path) -> Result anyhow::Result> { let block_num = block_prover_input.other_data.b_data.b_meta.block_number; let trace_decoder_output = trace_decoder::entrypoint( block_prover_input.block_trace, block_prover_input.other_data.clone(), |_| unimplemented!(), + use_burn_addr, ) .context(format!( "Failed to execute trace decoder on block {}", @@ -168,6 +170,9 @@ fn verify_generation_inputs( fn test_parsing_decoding_proving(#[case] test_witness_directory: &str) { init_logger(); + // TODO: Once CDK_ERIGON_WITNESS_DIR is available, change this so + // `use_burn_addr` is only true in that case. + let use_burn_addr = test_witness_directory != JERIGON_WITNESS_DIR; let results = find_witness_data_files(test_witness_directory) .expect("valid json data files found") .into_iter() @@ -180,7 +185,8 @@ fn test_parsing_decoding_proving(#[case] test_witness_directory: &str) { .map_ok(|block_prover_inputs| { block_prover_inputs.into_iter().map(|block_prover_input| { // Run trace decoder, create list of generation inputs - let block_generation_inputs = decode_generation_inputs(block_prover_input)?; + let block_generation_inputs = + decode_generation_inputs(block_prover_input, use_burn_addr)?; block_generation_inputs .into_par_iter() .map(|generation_inputs| { @@ -223,6 +229,9 @@ fn test_parsing_decoding_proving(#[case] test_witness_directory: &str) { fn test_generation_inputs_consistency(#[case] test_witness_directory: &str) { init_logger(); + // TODO: Once CDK_ERIGON_WITNESS_DIR is available, change this so + // `use_burn_addr` is only true in that case. + let use_burn_addr = test_witness_directory != JERIGON_WITNESS_DIR; let result: Vec> = find_witness_data_files(test_witness_directory) .expect("valid json data files found") .into_iter() @@ -252,7 +261,8 @@ fn test_generation_inputs_consistency(#[case] test_witness_directory: &str) { .map_ok(|(block_header, block_prover_input)| { let other_block_data = block_prover_input.other_data.clone(); // Run trace decoder, create generation inputs for this block - let block_generation_inputs = decode_generation_inputs(block_prover_input)?; + let block_generation_inputs = + decode_generation_inputs(block_prover_input, use_burn_addr)?; // Verify generation inputs for this block verify_generation_inputs(&block_header, &other_block_data, block_generation_inputs) }) diff --git a/zero_bin/leader/Cargo.toml b/zero_bin/leader/Cargo.toml index 5d0881da1..054f19032 100644 --- a/zero_bin/leader/Cargo.toml +++ b/zero_bin/leader/Cargo.toml @@ -30,11 +30,13 @@ toml = { workspace = true } ops = { workspace = true } prover = { workspace = true } rpc = { workspace = true } +evm_arithmetization = { workspace = true } zero_bin_common = { workspace = true } [features] default = [] test_only = ["ops/test_only", "prover/test_only"] +cdk_erigon = ["prover/cdk_erigon", "evm_arithmetization/cdk_erigon"] [build-dependencies] cargo_metadata = { workspace = true } diff --git a/zero_bin/prover/Cargo.toml b/zero_bin/prover/Cargo.toml index d1eaab7b3..8c059ccfd 100644 --- a/zero_bin/prover/Cargo.toml +++ b/zero_bin/prover/Cargo.toml @@ -27,3 +27,4 @@ num-traits = { workspace = true } [features] default = [] test_only = ["ops/test_only"] +cdk_erigon = [] diff --git a/zero_bin/prover/src/lib.rs b/zero_bin/prover/src/lib.rs index 78005f99e..177366814 100644 --- a/zero_bin/prover/src/lib.rs +++ b/zero_bin/prover/src/lib.rs @@ -40,8 +40,13 @@ impl BlockProverInput { let block_number = self.get_block_number(); - let txs = - trace_decoder::entrypoint(self.block_trace, self.other_data, |_| unimplemented!())?; + let use_burn_addr = cfg!(feature = "cdk_erigon"); + let txs = trace_decoder::entrypoint( + self.block_trace, + self.other_data, + |_| unimplemented!(), + use_burn_addr, + )?; let agg_proof = IndexedStream::from(txs) .map(&TxProof { @@ -87,8 +92,13 @@ impl BlockProverInput { let block_number = self.get_block_number(); info!("Testing witness generation for block {block_number}."); - let txs = - trace_decoder::entrypoint(self.block_trace, self.other_data, |_| unimplemented!())?; + let use_burn_addr = cfg!(feature = "cdk_erigon"); + let txs = trace_decoder::entrypoint( + self.block_trace, + self.other_data, + |_| unimplemented!(), + use_burn_addr, + )?; IndexedStream::from(txs) .map(&TxProof { From 0cfdb39442396464652d6d2030f61661f8b9b4ef Mon Sep 17 00:00:00 2001 From: Linda Guiga Date: Wed, 28 Aug 2024 10:33:57 +0100 Subject: [PATCH 09/12] Fix RPC entrypoint --- zero_bin/leader/Cargo.toml | 2 +- zero_bin/rpc/Cargo.toml | 3 +++ zero_bin/rpc/src/main.rs | 2 ++ 3 files changed, 6 insertions(+), 1 deletion(-) diff --git a/zero_bin/leader/Cargo.toml b/zero_bin/leader/Cargo.toml index 7059650fa..1f70f96a2 100644 --- a/zero_bin/leader/Cargo.toml +++ b/zero_bin/leader/Cargo.toml @@ -35,7 +35,7 @@ zero_bin_common = { workspace = true } [features] default = [] -cdk_erigon = ["prover/cdk_erigon", "evm_arithmetization/cdk_erigon"] +cdk_erigon = ["prover/cdk_erigon", "evm_arithmetization/cdk_erigon", "rpc/cdk_erigon"] [build-dependencies] cargo_metadata = { workspace = true } diff --git a/zero_bin/rpc/Cargo.toml b/zero_bin/rpc/Cargo.toml index 1273cd590..d5eea0bfd 100644 --- a/zero_bin/rpc/Cargo.toml +++ b/zero_bin/rpc/Cargo.toml @@ -38,3 +38,6 @@ prover = { workspace = true } cargo_metadata = { workspace = true } vergen = { workspace = true } anyhow = { workspace = true } + +[features] +cdk_erigon = [] \ No newline at end of file diff --git a/zero_bin/rpc/src/main.rs b/zero_bin/rpc/src/main.rs index b878b8cf1..160a5898f 100644 --- a/zero_bin/rpc/src/main.rs +++ b/zero_bin/rpc/src/main.rs @@ -167,10 +167,12 @@ impl Cli { block_number ))?; + let use_burn_addr = cfg!(feature = "cdk_erigon"); let generation_inputs = trace_decoder::entrypoint( block_prover_input.block_trace, block_prover_input.other_data, batch_size, + use_burn_addr, )?; if let Some(index) = tx_info.transaction_index { From 125187626820d6ebbe86e7903c4afe4657909930 Mon Sep 17 00:00:00 2001 From: Linda Guiga Date: Wed, 28 Aug 2024 11:51:49 +0100 Subject: [PATCH 10/12] Apply comments --- evm_arithmetization/src/cpu/kernel/aggregator.rs | 8 ++++---- .../src/cpu/kernel/asm/core/process_txn.asm | 3 ++- .../src/fixed_recursive_verifier.rs | 4 ++-- evm_arithmetization/src/generation/mod.rs | 5 +++-- evm_arithmetization/src/get_challenges.rs | 11 ++++++----- evm_arithmetization/src/proof.rs | 15 +++++++++++++-- evm_arithmetization/tests/add11_yml.rs | 14 +------------- evm_arithmetization/tests/log_opcode.rs | 14 +++++++++++++- evm_arithmetization/tests/two_to_one_block.rs | 5 ++--- 9 files changed, 46 insertions(+), 33 deletions(-) diff --git a/evm_arithmetization/src/cpu/kernel/aggregator.rs b/evm_arithmetization/src/cpu/kernel/aggregator.rs index f1582e9db..16e3a3450 100644 --- a/evm_arithmetization/src/cpu/kernel/aggregator.rs +++ b/evm_arithmetization/src/cpu/kernel/aggregator.rs @@ -178,10 +178,10 @@ pub static KERNEL_FILES: [&str; NUMBER_KERNEL_FILES] = [ pub static KERNEL: Lazy = Lazy::new(combined_kernel); pub(crate) fn combined_kernel_from_files(files: [&str; N]) -> Kernel { - #[cfg(feature = "cdk_erigon")] - let active_features = HashSet::from(["cdk_erigon"]); - #[cfg(not(feature = "cdk_erigon"))] - let active_features = HashSet::new(); + let mut active_features = HashSet::new(); + if cfg!(feature = "cdk_erigon") { + active_features.insert("cdk_erigon"); + } let parsed_files = files .iter() diff --git a/evm_arithmetization/src/cpu/kernel/asm/core/process_txn.asm b/evm_arithmetization/src/cpu/kernel/asm/core/process_txn.asm index 33a4150c0..6a006ef71 100644 --- a/evm_arithmetization/src/cpu/kernel/asm/core/process_txn.asm +++ b/evm_arithmetization/src/cpu/kernel/asm/core/process_txn.asm @@ -376,9 +376,9 @@ process_message_txn_fail: #[cfg(feature = cdk_erigon)] { + // Deduct the extra burn fees from the burn target. %macro deduct_extra_burn_fees // stack: leftover_gas' - // Deduct the extra burn fees from the burn target. %mload_global_metadata(@GLOBAL_METADATA_BURN_ADDR) DUP1 %eq_const(@U256_MAX) %jumpi(%%deduct_extra_burn_fees_pop) // stack: burn_target, leftover_gas' @@ -432,6 +432,7 @@ process_message_txn_fail: #[cfg(feature = cdk_erigon)] { + // Refund extra burn fees to the burn target. %macro add_max_burnt_eth // stack: (empty) %mload_global_metadata(@GLOBAL_METADATA_BURN_ADDR) diff --git a/evm_arithmetization/src/fixed_recursive_verifier.rs b/evm_arithmetization/src/fixed_recursive_verifier.rs index 353939122..762477c0e 100644 --- a/evm_arithmetization/src/fixed_recursive_verifier.rs +++ b/evm_arithmetization/src/fixed_recursive_verifier.rs @@ -2224,8 +2224,8 @@ where #[cfg(feature = "cdk_erigon")] { - let burn_addr_keys = TrieRootsTarget::SIZE * 2 - ..TrieRootsTarget::SIZE * 2 + BurnAddrTarget::get_size(); + let burn_addr_keys = + TrieRootsTarget::SIZE * 2..TrieRootsTarget::SIZE * 2 + burn_addr_offset; for (key, &value) in burn_addr_keys.zip_eq(&u256_limbs( public_values .burn_addr diff --git a/evm_arithmetization/src/generation/mod.rs b/evm_arithmetization/src/generation/mod.rs index ae738c9aa..16d078d89 100644 --- a/evm_arithmetization/src/generation/mod.rs +++ b/evm_arithmetization/src/generation/mod.rs @@ -70,8 +70,9 @@ pub struct GenerationInputs { /// of a transaction. pub signed_txns: Vec>, /// Target address for the base fee to be 'burnt', if there is one. If - /// `None`, then the base fee is directly burnt. Note: this is only used - /// when feature `cdk_erigon` is activated. + /// `None`, then the base fee is directly burnt. + /// + /// Note: this is only used when feature `cdk_erigon` is activated. pub burn_addr: Option, /// Withdrawal pairs `(addr, amount)`. At the end of the txs, `amount` is /// added to `addr`'s balance. See EIP-4895. diff --git a/evm_arithmetization/src/get_challenges.rs b/evm_arithmetization/src/get_challenges.rs index 8e0d34428..bb37e01f0 100644 --- a/evm_arithmetization/src/get_challenges.rs +++ b/evm_arithmetization/src/get_challenges.rs @@ -148,6 +148,7 @@ fn observe_burn_addr, C: GenericConfig, c } #[cfg(feature = "cdk_erigon")] +/// This will panic if no burn address was specified. fn observe_burn_addr_target< F: RichField + Extendable, C: GenericConfig, @@ -204,19 +205,19 @@ pub(crate) fn observe_public_values< observe_trie_roots::(challenger, &public_values.trie_roots_after); observe_block_metadata::(challenger, &public_values.block_metadata)?; observe_block_hashes::(challenger, &public_values.block_hashes); - #[cfg(not(feature = "cdk_erigon"))] - return observe_extra_block_data::(challenger, &public_values.extra_block_data); + observe_extra_block_data::(challenger, &public_values.extra_block_data)?; + #[cfg(feature = "cdk_erigon")] { - observe_extra_block_data::(challenger, &public_values.extra_block_data)?; - observe_burn_addr::( challenger, public_values .burn_addr .expect("There should be an address set in cdk_erigon."), - ) + )?; } + + Ok(()) } pub(crate) fn observe_public_values_target< diff --git a/evm_arithmetization/src/proof.rs b/evm_arithmetization/src/proof.rs index cf1e9ae5b..e7e4bae00 100644 --- a/evm_arithmetization/src/proof.rs +++ b/evm_arithmetization/src/proof.rs @@ -138,8 +138,7 @@ pub struct FinalPublicValues { /// Address to store the base fee to be burnt: only used when feature /// `cdk_erigon` is active. pub burn_addr: Option, - /// Block metadata: it remains unchanged within a - /// block. + /// Block metadata: it remains unchanged within a block. pub block_metadata: BlockMetadata, /// 256 previous block hashes and current block's hash. pub block_hashes: BlockHashes, @@ -924,6 +923,10 @@ impl BurnAddrTarget { /// If `condition`, returns the burn address in `ba0`, /// otherwise returns the burn address in `ba1`. + /// This is a no-op if `cdk_erigon` feature is not activated. + /// + /// This will panic if the `cdk_erigon` is activated and not both + /// `BurnAddrTarget`s are `BurnAddr` variants. pub(crate) fn select, const D: usize>( builder: &mut CircuitBuilder, condition: BoolTarget, @@ -946,6 +949,10 @@ impl BurnAddrTarget { } /// Connects the burn address in `ba0` to the burn address in `ba1`. + /// This is a no-op if `cdk_erigon` feature is not activated. + /// + /// This will panic if the `cdk_erigon` is activated and not both + /// `BurnAddrTarget`s are `BurnAddr` variants. pub(crate) fn connect, const D: usize>( builder: &mut CircuitBuilder, ba0: Self, @@ -968,6 +975,10 @@ impl BurnAddrTarget { } /// If `condition`, asserts that `ba0 == ba1`. + /// This is a no-op if `cdk_erigon` feature is not activated. + /// + /// This will panic if the `cdk_erigon` is activated and not both + /// `BurnAddrTarget` are `BurnAddr` variants. pub(crate) fn conditional_assert_eq, const D: usize>( builder: &mut CircuitBuilder, condition: BoolTarget, diff --git a/evm_arithmetization/tests/add11_yml.rs b/evm_arithmetization/tests/add11_yml.rs index 5ffe6261a..ed5eaaa94 100644 --- a/evm_arithmetization/tests/add11_yml.rs +++ b/evm_arithmetization/tests/add11_yml.rs @@ -111,13 +111,6 @@ fn get_generation_inputs() -> GenerationInputs { let beacon_roots_account = beacon_roots_contract_from_storage(&beacon_roots_account_storage); - #[cfg(feature = "cdk_erigon")] - let beneficiary_account_after = AccountRlp { - nonce: 1.into(), - balance: block_metadata.block_base_fee * block_metadata.block_gas_used, - ..AccountRlp::default() - }; - #[cfg(not(feature = "cdk_erigon"))] let beneficiary_account_after = AccountRlp { nonce: 1.into(), ..AccountRlp::default() @@ -192,14 +185,9 @@ fn get_generation_inputs() -> GenerationInputs { receipts_root: receipts_trie.hash(), }; - let burn_addr = match cfg!(feature = "cdk_erigon") { - true => Some(Address::from(beneficiary)), - false => None, - }; - GenerationInputs { signed_txns: vec![txn.to_vec()], - burn_addr, + burn_addr: None, withdrawals: vec![], global_exit_roots: vec![], tries: tries_before, diff --git a/evm_arithmetization/tests/log_opcode.rs b/evm_arithmetization/tests/log_opcode.rs index 0918f8942..8d71e0a19 100644 --- a/evm_arithmetization/tests/log_opcode.rs +++ b/evm_arithmetization/tests/log_opcode.rs @@ -156,6 +156,13 @@ fn test_log_opcodes() -> anyhow::Result<()> { // Update the state and receipt tries after the transaction, so that we have the // correct expected tries: Update accounts + #[cfg(feature = "cdk_erigon")] + let beneficiary_account_after = AccountRlp { + nonce: 1.into(), + balance: block_metadata.block_base_fee * gas_used, + ..AccountRlp::default() + }; + #[cfg(not(feature = "cdk_erigon"))] let beneficiary_account_after = AccountRlp { nonce: 1.into(), ..AccountRlp::default() @@ -237,9 +244,14 @@ fn test_log_opcodes() -> anyhow::Result<()> { receipts_root: receipts_trie.hash(), }; + let burn_addr = match cfg!(feature = "cdk_erigon") { + true => Some(Address::from(beneficiary)), + false => None, + }; + let inputs = GenerationInputs { signed_txns: vec![txn.to_vec()], - burn_addr: None, + burn_addr, withdrawals: vec![], global_exit_roots: vec![], tries: tries_before, diff --git a/evm_arithmetization/tests/two_to_one_block.rs b/evm_arithmetization/tests/two_to_one_block.rs index ab9e72d50..c5a0a1b58 100644 --- a/evm_arithmetization/tests/two_to_one_block.rs +++ b/evm_arithmetization/tests/two_to_one_block.rs @@ -1,5 +1,5 @@ use env_logger::{try_init_from_env, Env, DEFAULT_FILTER_ENV}; -use ethereum_types::{Address, BigEndianHash, H160, H256}; +use ethereum_types::{Address, BigEndianHash, H256}; use evm_arithmetization::fixed_recursive_verifier::{ extract_block_public_values, extract_two_to_one_block_hash, }; @@ -94,8 +94,7 @@ fn dummy_payload(timestamp: u64, is_first_payload: bool) -> anyhow::Result Date: Thu, 29 Aug 2024 10:24:48 +0100 Subject: [PATCH 11/12] Link issue to the TODOs --- trace_decoder/src/decoding.rs | 3 ++- trace_decoder/tests/trace_decoder_tests.rs | 10 ++++++---- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/trace_decoder/src/decoding.rs b/trace_decoder/src/decoding.rs index 69a15e7e8..c51639dc3 100644 --- a/trace_decoder/src/decoding.rs +++ b/trace_decoder/src/decoding.rs @@ -586,7 +586,8 @@ fn process_txn_info( )?; let burn_addr = match use_burn_target { - // TODO: retrieve the actual burn address from cdk-erigon. + // TODO: https://github.com/0xPolygonZero/zk_evm/issues/565 + // Retrieve the actual burn address from `cdk-erigon`. true => Some(H160::zero()), false => None, }; diff --git a/trace_decoder/tests/trace_decoder_tests.rs b/trace_decoder/tests/trace_decoder_tests.rs index 36fbe1836..63cd4dd37 100644 --- a/trace_decoder/tests/trace_decoder_tests.rs +++ b/trace_decoder/tests/trace_decoder_tests.rs @@ -170,8 +170,9 @@ fn verify_generation_inputs( fn test_parsing_decoding_proving(#[case] test_witness_directory: &str) { init_logger(); - // TODO: Once CDK_ERIGON_WITNESS_DIR is available, change this so - // `use_burn_addr` is only true in that case. + // TODO: https://github.com/0xPolygonZero/zk_evm/issues/565 + // Once CDK_ERIGON_WITNESS_DIR is available, change this so + // `use_burn_addr` is only true in that case. let use_burn_addr = test_witness_directory != JERIGON_WITNESS_DIR; let results = find_witness_data_files(test_witness_directory) .expect("valid json data files found") @@ -231,8 +232,9 @@ fn test_parsing_decoding_proving(#[case] test_witness_directory: &str) { fn test_generation_inputs_consistency(#[case] test_witness_directory: &str) { init_logger(); - // TODO: Once CDK_ERIGON_WITNESS_DIR is available, change this so - // `use_burn_addr` is only true in that case. + // TODO: https://github.com/0xPolygonZero/zk_evm/issues/565 + // Once CDK_ERIGON_WITNESS_DIR is available, change this so + // `use_burn_addr` is only true in that case. let use_burn_addr = test_witness_directory != JERIGON_WITNESS_DIR; let result: Vec> = find_witness_data_files(test_witness_directory) .expect("valid json data files found") From 6e9c7336c16dc268c4399d423c9389ae076e0982 Mon Sep 17 00:00:00 2001 From: Linda Guiga Date: Fri, 30 Aug 2024 13:57:26 +0100 Subject: [PATCH 12/12] Apply comment --- evm_arithmetization/src/recursive_verifier.rs | 27 ++++++++++--------- 1 file changed, 14 insertions(+), 13 deletions(-) diff --git a/evm_arithmetization/src/recursive_verifier.rs b/evm_arithmetization/src/recursive_verifier.rs index 928a749d4..a15c86b2d 100644 --- a/evm_arithmetization/src/recursive_verifier.rs +++ b/evm_arithmetization/src/recursive_verifier.rs @@ -429,19 +429,20 @@ pub(crate) fn get_memory_extra_looking_sum_circuit, }); #[cfg(feature = "cdk_erigon")] - let burn_addr = match public_values.burn_addr { - BurnAddrTarget::BurnAddr(addr) => addr, - BurnAddrTarget::Burnt() => panic!("There should be an address set in cdk_erigon."), - }; - #[cfg(feature = "cdk_erigon")] - let mut sum = add_data_write( - builder, - challenge, - sum, - metadata_segment, - GlobalMetadata::BurnAddr.unscale(), - &burn_addr, - ); + { + let burn_addr = match public_values.burn_addr { + BurnAddrTarget::BurnAddr(addr) => addr, + BurnAddrTarget::Burnt() => panic!("There should be an address set in cdk_erigon."), + }; + sum = add_data_write( + builder, + challenge, + sum, + metadata_segment, + GlobalMetadata::BurnAddr.unscale(), + &burn_addr, + ); + } block_fields_arrays.map(|(field, targets)| { sum = add_data_write(