diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 43c0c1254..6f9d24ee7 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -237,10 +237,10 @@ jobs: run: cargo fmt --all --check - name: Run cargo clippy - run: cargo clippy --all-features --all-targets -- -D warnings -A incomplete-features + run: cargo clippy --all-targets -- -D warnings -A incomplete-features - name: Run cargo clippy (with `cdk_erigon` flag) - run: cargo clippy --all-features --all-targets --features cdk_erigon -- -D warnings -A incomplete-features + run: cargo clippy --all-targets --no-default-features --features cdk_erigon -- -D warnings -A incomplete-features - name: Rustdoc run: cargo doc --all diff --git a/Cargo.toml b/Cargo.toml index 008257556..9628a345c 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -111,19 +111,19 @@ vergen = { version = "9.0.0", features = ["build", "rustc"] } winnow = "0.6.13" # local dependencies -evm_arithmetization = { path = "evm_arithmetization", version = "0.4.0" } +evm_arithmetization = { path = "evm_arithmetization", version = "0.4.0", default-features = false } mpt_trie = { path = "mpt_trie", version = "0.4.1" } -proof_gen = { path = "proof_gen", version = "0.4.0" } +proof_gen = { path = "proof_gen", version = "0.4.0", default-features = false } smt_trie = { path = "smt_trie", version = "0.1.1" } -trace_decoder = { path = "trace_decoder", version = "0.6.0" } +trace_decoder = { path = "trace_decoder", version = "0.6.0", default-features = false } zk_evm_common = { path = "common", version = "0.1.0" } zk_evm_proc_macro = { path = "proc_macro", version = "0.1.0" } # zero-bin related dependencies -ops = { path = "zero_bin/ops" } -prover = { path = "zero_bin/prover" } -rpc = { path = "zero_bin/rpc" } -zero_bin_common = { path = "zero_bin/common" } +ops = { path = "zero_bin/ops", default-features = false } +prover = { path = "zero_bin/prover", default-features = false } +rpc = { path = "zero_bin/rpc", default-features = false } +zero_bin_common = { path = "zero_bin/common", default-features = false } # plonky2-related dependencies plonky2 = { git = "https://github.com/0xPolygonZero/plonky2.git", rev = "dc77c77f2b06500e16ad4d7f1c2b057903602eed" } diff --git a/evm_arithmetization/Cargo.toml b/evm_arithmetization/Cargo.toml index 96d435bc8..a2b38cc7e 100644 --- a/evm_arithmetization/Cargo.toml +++ b/evm_arithmetization/Cargo.toml @@ -24,15 +24,15 @@ hex-literal = { workspace = true } itertools = { workspace = true } keccak-hash = { workspace = true } log = { workspace = true } -plonky2_maybe_rayon = { workspace = true } +plonky2_maybe_rayon = { workspace = true, features = ["parallel"] } num = { workspace = true } num-bigint = { workspace = true } once_cell = { workspace = true } pest = { workspace = true } pest_derive = { workspace = true } -plonky2 = { workspace = true } +plonky2 = { workspace = true, features = ["parallel"] } plonky2_util = { workspace = true } -starky = { workspace = true } +starky = { workspace = true, features = ["parallel"] } rand = { workspace = true } rand_chacha = { workspace = true } rlp = { workspace = true } @@ -57,15 +57,11 @@ hex = { workspace = true } ripemd = { workspace = true } [features] -default = ["parallel"] +default = ["eth_mainnet"] asmtools = ["hex"] -parallel = [ - "plonky2/parallel", - "plonky2_maybe_rayon/parallel", - "starky/parallel", -] polygon_pos = [] cdk_erigon = ["smt_trie"] +eth_mainnet = [] [[bin]] name = "assemble" diff --git a/evm_arithmetization/src/cpu/kernel/aggregator.rs b/evm_arithmetization/src/cpu/kernel/aggregator.rs index 27054ac37..4ac839659 100644 --- a/evm_arithmetization/src/cpu/kernel/aggregator.rs +++ b/evm_arithmetization/src/cpu/kernel/aggregator.rs @@ -9,10 +9,15 @@ use super::assembler::{assemble, Kernel}; use crate::cpu::kernel::constants::evm_constants; use crate::cpu::kernel::parser::parse; -pub const NUMBER_KERNEL_FILES: usize = if cfg!(feature = "cdk_erigon") { - 159 +pub const NUMBER_KERNEL_FILES: usize = if cfg!(feature = "eth_mainnet") { + 157 +} else if cfg!(feature = "cdk_erigon") { + 156 +} else if cfg!(feature = "polygon_pos") { + 155 } else { - 158 + // unreachable + 0 }; pub static KERNEL_FILES: [&str; NUMBER_KERNEL_FILES] = [ @@ -60,8 +65,9 @@ pub static KERNEL_FILES: [&str; NUMBER_KERNEL_FILES] = [ include_str!("asm/core/precompiles/bn_mul.asm"), include_str!("asm/core/precompiles/snarkv.asm"), include_str!("asm/core/precompiles/blake2_f.asm"), + #[cfg(feature = "eth_mainnet")] include_str!("asm/core/precompiles/kzg_peval.asm"), - include_str!("asm/curve/bls381/util.asm"), + // include_str!("asm/curve/bls381/util.asm"), include_str!("asm/curve/bn254/curve_arithmetic/constants.asm"), include_str!("asm/curve/bn254/curve_arithmetic/curve_add.asm"), include_str!("asm/curve/bn254/curve_arithmetic/curve_mul.asm"), @@ -168,6 +174,7 @@ pub static KERNEL_FILES: [&str; NUMBER_KERNEL_FILES] = [ include_str!("asm/transactions/type_0.asm"), include_str!("asm/transactions/type_1.asm"), include_str!("asm/transactions/type_2.asm"), + #[cfg(feature = "eth_mainnet")] include_str!("asm/transactions/type_3.asm"), include_str!("asm/util/assertions.asm"), include_str!("asm/util/basic_macros.asm"), @@ -186,6 +193,10 @@ pub(crate) fn combined_kernel_from_files(files: [&str; N]) -> Ke let mut active_features = HashSet::new(); if cfg!(feature = "cdk_erigon") { active_features.insert("cdk_erigon"); + } else if cfg!(feature = "polygon_pos") { + active_features.insert("polygon_pos"); + } else { + active_features.insert("eth_mainnet"); } let parsed_files = files diff --git a/evm_arithmetization/src/cpu/kernel/asm/beacon_roots.asm b/evm_arithmetization/src/cpu/kernel/asm/beacon_roots.asm index 36f491fb5..17ade9e86 100644 --- a/evm_arithmetization/src/cpu/kernel/asm/beacon_roots.asm +++ b/evm_arithmetization/src/cpu/kernel/asm/beacon_roots.asm @@ -3,16 +3,11 @@ /// /// *NOTE*: This will panic if one of the provided timestamps is zero. +/// Pre-stack: (empty) +/// Post-stack: (empty) global set_beacon_root: - #[cfg(feature = cdk_erigon)] - { - PUSH pre_block_execution - } - #[cfg(not(feature = cdk_erigon))] - { - PUSH txn_loop - } - + // stack: (empty) + PUSH txn_loop %timestamp // stack: timestamp, retdest PUSH @HISTORY_BUFFER_LENGTH diff --git a/evm_arithmetization/src/cpu/kernel/asm/core/exception.asm b/evm_arithmetization/src/cpu/kernel/asm/core/exception.asm index a2a2742ec..925921097 100644 --- a/evm_arithmetization/src/cpu/kernel/asm/core/exception.asm +++ b/evm_arithmetization/src/cpu/kernel/asm/core/exception.asm @@ -327,8 +327,16 @@ min_stack_len_for_opcode: BYTES 0 // 0x46, CHAINID BYTES 0 // 0x47, SELFBALANCE BYTES 0 // 0x48, BASEFEE - BYTES 1 // 0x49, BLOBHASH - BYTES 0 // 0x4a, BLOBBASEFEE + #[cfg(feature = eth_mainnet)] + { + BYTES 1 // 0x49, BLOBHASH + BYTES 0 // 0x4a, BLOBBASEFEE + } + #[cfg(not(feature = eth_mainnet))] + { + BYTES 0 // 0x49, BLOBHASH is only active on Ethereum mainnet + BYTES 0 // 0x4a, BLOBBASEFEE is only active on Ethereum mainnet + } %rep 5 // 0x4b-0x4f, invalid BYTES 0 %endrep diff --git a/evm_arithmetization/src/cpu/kernel/asm/core/precompiles/main.asm b/evm_arithmetization/src/cpu/kernel/asm/core/precompiles/main.asm index 0a1883491..4bb924f87 100644 --- a/evm_arithmetization/src/cpu/kernel/asm/core/precompiles/main.asm +++ b/evm_arithmetization/src/cpu/kernel/asm/core/precompiles/main.asm @@ -18,8 +18,15 @@ global handle_precompiles: DUP1 %eq_const(@BN_ADD) %jumpi(precompile_bn_add) DUP1 %eq_const(@BN_MUL) %jumpi(precompile_bn_mul) DUP1 %eq_const(@SNARKV) %jumpi(precompile_snarkv) - DUP1 %eq_const(@BLAKE2_F) %jumpi(precompile_blake2_f) - %eq_const(@KZG_PEVAL) %jumpi(precompile_kzg_peval) + #[cfg(feature = eth_mainnet)] + { + DUP1 %eq_const(@BLAKE2_F) %jumpi(precompile_blake2_f) + %eq_const(@KZG_PEVAL) %jumpi(precompile_kzg_peval) + } + #[cfg(not(feature = eth_mainnet))] + { + %eq_const(@BLAKE2_F) %jumpi(precompile_blake2_f) + } // stack: retdest JUMP diff --git a/evm_arithmetization/src/cpu/kernel/asm/core/syscall.asm b/evm_arithmetization/src/cpu/kernel/asm/core/syscall.asm index 87c01dc7f..7677654e2 100644 --- a/evm_arithmetization/src/cpu/kernel/asm/core/syscall.asm +++ b/evm_arithmetization/src/cpu/kernel/asm/core/syscall.asm @@ -69,8 +69,16 @@ global syscall_jumptable: JUMPTABLE sys_chainid JUMPTABLE sys_selfbalance JUMPTABLE sys_basefee - JUMPTABLE sys_blobhash - JUMPTABLE sys_blobbasefee + #[cfg(feature = eth_mainnet)] + { + JUMPTABLE sys_blobhash + JUMPTABLE sys_blobbasefee + } + #[cfg(not(feature = eth_mainnet))] + { + JUMPTABLE panic // BLOBHASH is only active on Ethereum mainnet + JUMPTABLE panic // BLOBBASEFEE is only active on Ethereum mainnet + } %rep 5 JUMPTABLE panic // 0x4b-0x4f are invalid opcodes %endrep diff --git a/evm_arithmetization/src/cpu/kernel/asm/main.asm b/evm_arithmetization/src/cpu/kernel/asm/main.asm index 58e969ee2..8d2b09c66 100644 --- a/evm_arithmetization/src/cpu/kernel/asm/main.asm +++ b/evm_arithmetization/src/cpu/kernel/asm/main.asm @@ -127,10 +127,20 @@ global start_txns: %mload_global_metadata(@GLOBAL_METADATA_BLOCK_GAS_USED_BEFORE) // stack: init_gas_used, txn_counter, num_nibbles, txn_nb - // If txn_idx == 0, update the beacon_root and exit roots. - %mload_global_metadata(@GLOBAL_METADATA_TXN_NUMBER_BEFORE) - ISZERO - %jumpi(set_beacon_root) + #[cfg(feature = eth_mainnet)] + { + // If txn_idx == 0, update the beacon_root for Ethereum mainnet. + %mload_global_metadata(@GLOBAL_METADATA_TXN_NUMBER_BEFORE) + ISZERO + %jumpi(set_beacon_root) + } + #[cfg(feature = cdk_erigon)] + { + // If txn_idx == 0, perform pre-state execution for CDK erigon. + %mload_global_metadata(@GLOBAL_METADATA_TXN_NUMBER_BEFORE) + ISZERO + %jumpi(pre_block_execution) + } // stack: init_gas_used, txn_counter, num_nibbles, txn_nb global txn_loop: @@ -255,5 +265,8 @@ global check_final_state_trie: PUSH 0 %mstore_txn_field(@TXN_FIELD_CHAIN_ID_PRESENT) PUSH 0 %mstore_txn_field(@TXN_FIELD_TO) - %reset_blob_versioned_hashes + #[cfg(feature = eth_mainnet)] + { + %reset_blob_versioned_hashes + } %endmacro diff --git a/evm_arithmetization/src/cpu/kernel/asm/memory/metadata.asm b/evm_arithmetization/src/cpu/kernel/asm/memory/metadata.asm index 1747d6692..5e94794f6 100644 --- a/evm_arithmetization/src/cpu/kernel/asm/memory/metadata.asm +++ b/evm_arithmetization/src/cpu/kernel/asm/memory/metadata.asm @@ -277,47 +277,51 @@ global sys_basefee: SWAP1 EXIT_KERNEL -global sys_blobhash: - // stack: kexit_info, index - %charge_gas_const(@GAS_HASH_OPCODE) - // stack: kexit_info, index - %blobhash - // stack: blobhash, kexit_info - SWAP1 - EXIT_KERNEL - -%macro blobhash - // stack: kexit_info, index - SWAP1 - // stack: index, kexit_info - %mload_global_metadata(@GLOBAL_METADATA_BLOB_VERSIONED_HASHES_LEN) - DUP2 - LT ISZERO // == GE - // stack: index >= len, index, kexit_info - %jumpi(%%index_too_big) - PUSH @SEGMENT_TXN_BLOB_VERSIONED_HASHES - %build_kernel_address - // stack: read_addr, kexit_info - MLOAD_GENERAL - %jump(%%end) -%%index_too_big: - // The index is larger than the list, just push 0. - // stack: index, kexit_info - POP - PUSH 0 - // stack: 0, kexit_info -%%end: - // stack: blobhash, kexit_info -%endmacro - -global sys_blobbasefee: - // stack: kexit_info - %charge_gas_const(@GAS_BASE) - // stack: kexit_info - PROVER_INPUT(blobbasefee) - // stack: blobbasefee, kexit_info - SWAP1 - EXIT_KERNEL +/// Blob-related macros are only available for Ethereum mainnet. +#[cfg(feature = eth_mainnet)] +{ + global sys_blobhash: + // stack: kexit_info, index + %charge_gas_const(@GAS_HASH_OPCODE) + // stack: kexit_info, index + %blobhash + // stack: blobhash, kexit_info + SWAP1 + EXIT_KERNEL + + %macro blobhash + // stack: kexit_info, index + SWAP1 + // stack: index, kexit_info + %mload_global_metadata(@GLOBAL_METADATA_BLOB_VERSIONED_HASHES_LEN) + DUP2 + LT ISZERO // == GE + // stack: index >= len, index, kexit_info + %jumpi(%%index_too_big) + PUSH @SEGMENT_TXN_BLOB_VERSIONED_HASHES + %build_kernel_address + // stack: read_addr, kexit_info + MLOAD_GENERAL + %jump(%%end) + %%index_too_big: + // The index is larger than the list, just push 0. + // stack: index, kexit_info + POP + PUSH 0 + // stack: 0, kexit_info + %%end: + // stack: blobhash, kexit_info + %endmacro + + global sys_blobbasefee: + // stack: kexit_info + %charge_gas_const(@GAS_BASE) + // stack: kexit_info + PROVER_INPUT(blobbasefee) + // stack: blobbasefee, kexit_info + SWAP1 + EXIT_KERNEL +} global sys_blockhash: // stack: kexit_info, block_number diff --git a/evm_arithmetization/src/cpu/kernel/asm/transactions/common_decoding.asm b/evm_arithmetization/src/cpu/kernel/asm/transactions/common_decoding.asm index 0621db533..6ee92ca2b 100644 --- a/evm_arithmetization/src/cpu/kernel/asm/transactions/common_decoding.asm +++ b/evm_arithmetization/src/cpu/kernel/asm/transactions/common_decoding.asm @@ -127,66 +127,6 @@ %%after: %endmacro -%macro decode_and_store_max_fee_per_blob_gas - // stack: rlp_addr - %decode_rlp_scalar - %stack (rlp_addr, max_fee_per_blob_gas) -> (max_fee_per_blob_gas, rlp_addr) - %mstore_txn_field(@TXN_FIELD_MAX_FEE_PER_BLOB_GAS) - // stack: rlp_addr -%endmacro - -%macro decode_and_store_blob_versioned_hashes - // stack: rlp_addr - %decode_rlp_list_len - %stack (rlp_addr, len) -> (len, len, rlp_addr, %%after) - - // EIP-4844: Blob transactions should have at least 1 versioned hash - %assert_nonzero(invalid_txn_2) - - // stack: len, rlp_addr, %%after - %jump(decode_and_store_blob_versioned_hashes) -%%after: -%endmacro - -// The blob versioned hashes are just a list of hashes. -global decode_and_store_blob_versioned_hashes: - // stack: len, rlp_addr - // Store the list length - DUP1 %mstore_global_metadata(@GLOBAL_METADATA_BLOB_VERSIONED_HASHES_LEN) - - // stack: len, rlp_addr - DUP2 ADD - // stack: end_rlp_addr, rlp_addr - // stack: end_rlp_addr, rlp_addr - PUSH @SEGMENT_TXN_BLOB_VERSIONED_HASHES // initial address to write to - SWAP2 -decode_and_store_blob_versioned_hashes_loop: - // stack: rlp_addr, end_rlp_addr, store_addr - DUP2 DUP2 EQ %jumpi(decode_and_store_blob_versioned_hashes_finish) - // stack: rlp_addr, end_rlp_addr, store_addr - %decode_rlp_scalar // blob_versioned_hashes[i] - // stack: rlp_addr, hash, end_rlp_addr, store_addr - - // EIP-4844: Versioned hashes should have `VERSIONED_HASH_VERSION_KZG` as MSB - DUP2 - %shr_const(248) - // stack: MSB, hash, end_rlp_addr, store_addr - %eq_const(1) - // stack: hash_is_valid?, rlp_addr, hash, end_rlp_addr, store_addr - %assert_nonzero(invalid_txn_3) - - // stack: rlp_addr, hash, end_rlp_addr, store_addr - SWAP3 DUP1 SWAP2 - // stack: hash, store_addr, store_addr, end_rlp_addr, rlp_addr - MSTORE_GENERAL - // stack: store_addr, end_rlp_addr, rlp_addr - %increment SWAP2 - // stack: rlp_addr, end_rlp_addr, store_addr' - %jump(decode_and_store_blob_versioned_hashes_loop) -decode_and_store_blob_versioned_hashes_finish: - %stack (rlp_addr, end_rlp_addr, store_addr, retdest) -> (retdest, rlp_addr) - JUMP - %macro decode_and_store_y_parity // stack: rlp_addr %decode_rlp_scalar @@ -303,3 +243,67 @@ sload_with_addr: // stack: value, retdest SWAP1 JUMP + +/// Type-3 transactions specific decoding helper macros. +#[cfg(feature = eth_mainnet)] +{ + %macro decode_and_store_max_fee_per_blob_gas + // stack: rlp_addr + %decode_rlp_scalar + %stack (rlp_addr, max_fee_per_blob_gas) -> (max_fee_per_blob_gas, rlp_addr) + %mstore_txn_field(@TXN_FIELD_MAX_FEE_PER_BLOB_GAS) + // stack: rlp_addr + %endmacro + + %macro decode_and_store_blob_versioned_hashes + // stack: rlp_addr + %decode_rlp_list_len + %stack (rlp_addr, len) -> (len, len, rlp_addr, %%after) + + // EIP-4844: Blob transactions should have at least 1 versioned hash + %assert_nonzero(invalid_txn_2) + + // stack: len, rlp_addr, %%after + %jump(decode_and_store_blob_versioned_hashes) + %%after: + %endmacro + + // The blob versioned hashes are just a list of hashes. + global decode_and_store_blob_versioned_hashes: + // stack: len, rlp_addr + // Store the list length + DUP1 %mstore_global_metadata(@GLOBAL_METADATA_BLOB_VERSIONED_HASHES_LEN) + + // stack: len, rlp_addr + DUP2 ADD + // stack: end_rlp_addr, rlp_addr + // stack: end_rlp_addr, rlp_addr + PUSH @SEGMENT_TXN_BLOB_VERSIONED_HASHES // initial address to write to + SWAP2 + decode_and_store_blob_versioned_hashes_loop: + // stack: rlp_addr, end_rlp_addr, store_addr + DUP2 DUP2 EQ %jumpi(decode_and_store_blob_versioned_hashes_finish) + // stack: rlp_addr, end_rlp_addr, store_addr + %decode_rlp_scalar // blob_versioned_hashes[i] + // stack: rlp_addr, hash, end_rlp_addr, store_addr + + // EIP-4844: Versioned hashes should have `VERSIONED_HASH_VERSION_KZG` as MSB + DUP2 + %shr_const(248) + // stack: MSB, hash, end_rlp_addr, store_addr + %eq_const(1) + // stack: hash_is_valid?, rlp_addr, hash, end_rlp_addr, store_addr + %assert_nonzero(invalid_txn_3) + + // stack: rlp_addr, hash, end_rlp_addr, store_addr + SWAP3 DUP1 SWAP2 + // stack: hash, store_addr, store_addr, end_rlp_addr, rlp_addr + MSTORE_GENERAL + // stack: store_addr, end_rlp_addr, rlp_addr + %increment SWAP2 + // stack: rlp_addr, end_rlp_addr, store_addr' + %jump(decode_and_store_blob_versioned_hashes_loop) + decode_and_store_blob_versioned_hashes_finish: + %stack (rlp_addr, end_rlp_addr, store_addr, retdest) -> (retdest, rlp_addr) + JUMP +} \ No newline at end of file diff --git a/evm_arithmetization/src/cpu/kernel/asm/transactions/router.asm b/evm_arithmetization/src/cpu/kernel/asm/transactions/router.asm index e7c7f88ee..eaef7efd7 100644 --- a/evm_arithmetization/src/cpu/kernel/asm/transactions/router.asm +++ b/evm_arithmetization/src/cpu/kernel/asm/transactions/router.asm @@ -33,14 +33,18 @@ read_txn_from_memory: %jumpi(process_type_2_txn) // stack: rlp_start_addr, retdest - DUP1 - MLOAD_GENERAL - %eq_const(3) - // stack: first_byte == 3, rlp_start_addr, retdest - %jumpi(process_type_3_txn) - // stack: rlp_start_addr, retdest + // Only Ethereum mainnet supports Blob-transactions. + #[cfg(feature = eth_mainnet)] + { + DUP1 + MLOAD_GENERAL + %eq_const(3) + // stack: first_byte == 3, rlp_start_addr, retdest + %jumpi(process_type_3_txn) + // stack: rlp_start_addr, retdest + } - // At this point, since it's not a type 1, 2 or 3 transaction, + // At this point, since it's not a typed transaction, // it must be a legacy (aka type 0) transaction. %jump(process_type_0_txn) diff --git a/evm_arithmetization/src/cpu/kernel/constants/exc_bitfields.rs b/evm_arithmetization/src/cpu/kernel/constants/exc_bitfields.rs index 0abc84e70..5ed5972c1 100644 --- a/evm_arithmetization/src/cpu/kernel/constants/exc_bitfields.rs +++ b/evm_arithmetization/src/cpu/kernel/constants/exc_bitfields.rs @@ -28,6 +28,7 @@ const fn u256_from_set_index_ranges(ranges: &[RangeInclusive U256(res_limbs) } +#[cfg(feature = "eth_mainnet")] pub(crate) const STACK_LENGTH_INCREASING_OPCODES_USER: U256 = u256_from_set_index_ranges(&[ 0x30..=0x30, // ADDRESS 0x32..=0x34, // ORIGIN, CALLER, CALLVALUE @@ -42,6 +43,20 @@ pub(crate) const STACK_LENGTH_INCREASING_OPCODES_USER: U256 = u256_from_set_inde 0x5f..=0x8f, // PUSH*, DUP* ]); +#[cfg(not(feature = "eth_mainnet"))] +pub(crate) const STACK_LENGTH_INCREASING_OPCODES_USER: U256 = u256_from_set_index_ranges(&[ + 0x30..=0x30, // ADDRESS + 0x32..=0x34, // ORIGIN, CALLER, CALLVALUE + 0x36..=0x36, // CALLDATASIZE + 0x38..=0x38, // CODESIZE + 0x3a..=0x3a, // GASPRICE + 0x3d..=0x3d, // RETURNDATASIZE + 0x41..=0x48, /* COINBASE, TIMESTAMP, NUMBER, DIFFICULTY, GASLIMIT, CHAINID, SELFBALANCE, + * BASEFEE */ + 0x58..=0x5a, // PC, MSIZE, GAS + 0x5f..=0x8f, // PUSH*, DUP* +]); + pub(crate) const INVALID_OPCODES_USER: U256 = u256_from_set_index_ranges(&[ 0x0c..=0x0f, 0x1e..=0x1f, diff --git a/evm_arithmetization/src/cpu/kernel/interpreter.rs b/evm_arithmetization/src/cpu/kernel/interpreter.rs index 3d44d8040..ec54b308d 100644 --- a/evm_arithmetization/src/cpu/kernel/interpreter.rs +++ b/evm_arithmetization/src/cpu/kernel/interpreter.rs @@ -263,10 +263,6 @@ impl Interpreter { // Set `GlobalMetadata` values. let metadata = &inputs.block_metadata; - #[cfg(feature = "cdk_erigon")] - let burn_addr = inputs - .burn_addr - .map_or_else(U256::max_value, |addr| U256::from_big_endian(&addr.0)); let global_metadata_to_set = [ ( GlobalMetadata::BlockBeneficiary, @@ -287,14 +283,17 @@ impl Interpreter { h2u(inputs.block_hashes.cur_hash), ), (GlobalMetadata::BlockGasUsed, metadata.block_gas_used), + #[cfg(feature = "eth_mainnet")] ( GlobalMetadata::BlockBlobGasUsed, metadata.block_blob_gas_used, ), + #[cfg(feature = "eth_mainnet")] ( GlobalMetadata::BlockExcessBlobGas, metadata.block_excess_blob_gas, ), + #[cfg(feature = "eth_mainnet")] ( GlobalMetadata::ParentBeaconBlockRoot, h2u(metadata.parent_beacon_block_root), @@ -333,7 +332,12 @@ impl Interpreter { (GlobalMetadata::KernelHash, h2u(KERNEL.code_hash)), (GlobalMetadata::KernelLen, KERNEL.code.len().into()), #[cfg(feature = "cdk_erigon")] - (GlobalMetadata::BurnAddr, burn_addr), + ( + GlobalMetadata::BurnAddr, + inputs + .burn_addr + .map_or_else(U256::max_value, |addr| U256::from_big_endian(&addr.0)), + ), ]; self.set_global_metadata_multi_fields(&global_metadata_to_set); diff --git a/evm_arithmetization/src/cpu/kernel/parser.rs b/evm_arithmetization/src/cpu/kernel/parser.rs index 4cbef3c81..be80ae5d4 100644 --- a/evm_arithmetization/src/cpu/kernel/parser.rs +++ b/evm_arithmetization/src/cpu/kernel/parser.rs @@ -91,7 +91,9 @@ fn parse_conditional_block(item: Pair, active_features: &HashSet<&str>) -> features_string: &str, group_rule: FeatureGroupRule, ) -> bool { - let features = features_string.split(","); + let features = features_string + .split(&[',', ' ']) // allows for both `foo,bar` and `foo, bar` in ASM + .filter(|s| !s.is_empty()); match group_rule { FeatureGroupRule::Not => { diff --git a/evm_arithmetization/src/cpu/kernel/tests/bls381.rs b/evm_arithmetization/src/cpu/kernel/tests/bls381.rs index 40a28ac5b..f61229796 100644 --- a/evm_arithmetization/src/cpu/kernel/tests/bls381.rs +++ b/evm_arithmetization/src/cpu/kernel/tests/bls381.rs @@ -2,40 +2,13 @@ use anyhow::Result; use ethereum_types::U256; use hex_literal::hex; use plonky2::field::goldilocks_field::GoldilocksField as F; -use rand::Rng; -use super::{run_interpreter_with_memory, InterpreterMemoryInitialization}; use crate::cpu::kernel::aggregator::KERNEL; use crate::cpu::kernel::cancun_constants::POINT_EVALUATION_PRECOMPILE_RETURN_VALUE; use crate::cpu::kernel::constants::cancun_constants::KZG_VERSIONED_HASH; use crate::cpu::kernel::interpreter::Interpreter; -use crate::extension_tower::{Fp2, Stack, BLS381}; -use crate::memory::segments::Segment::KernelGeneral; use crate::util::sha2; -#[test] -fn test_bls_fp2_mul() -> Result<()> { - let mut rng = rand::thread_rng(); - let x: Fp2 = rng.gen::>(); - let y: Fp2 = rng.gen::>(); - - let mut stack = x.to_stack().to_vec(); - stack.extend(y.to_stack().to_vec()); - stack.push(U256::from(0xdeadbeefu32)); - let setup = InterpreterMemoryInitialization { - label: "mul_fp381_2".to_string(), - stack, - segment: KernelGeneral, - memory: vec![], - }; - let interpreter = run_interpreter_with_memory::(setup).unwrap(); - let stack: Vec = interpreter.stack().iter().rev().cloned().collect(); - let output = Fp2::::from_stack(&stack); - - assert_eq!(output, x * y); - Ok(()) -} - /// A KZG point evaluation precompile payload consists in: /// - a G1 compressed point commitment (48 bytes) /// - a Scalar element z (32 bytes) diff --git a/evm_arithmetization/src/cpu/kernel/tests/mod.rs b/evm_arithmetization/src/cpu/kernel/tests/mod.rs index 53f65e9f8..39810148b 100644 --- a/evm_arithmetization/src/cpu/kernel/tests/mod.rs +++ b/evm_arithmetization/src/cpu/kernel/tests/mod.rs @@ -1,10 +1,13 @@ mod account_code; +#[cfg(feature = "eth_mainnet")] mod add11; mod balance; mod bignum; mod blake2_f; +#[cfg(feature = "eth_mainnet")] mod blobhash; mod block_hash; +#[cfg(feature = "eth_mainnet")] mod bls381; mod bn254; mod core; diff --git a/evm_arithmetization/src/cpu/kernel/tests/transaction_parsing/mod.rs b/evm_arithmetization/src/cpu/kernel/tests/transaction_parsing/mod.rs index c2ee22f4f..1f70a3a1e 100644 --- a/evm_arithmetization/src/cpu/kernel/tests/transaction_parsing/mod.rs +++ b/evm_arithmetization/src/cpu/kernel/tests/transaction_parsing/mod.rs @@ -9,6 +9,7 @@ use crate::{ mod parse_type_0_txn; mod parse_type_1_txn; mod parse_type_2_txn; +#[cfg(feature = "eth_mainnet")] mod parse_type_3_txn; pub(crate) fn prepare_interpreter_for_txn_parsing( diff --git a/evm_arithmetization/src/fixed_recursive_verifier.rs b/evm_arithmetization/src/fixed_recursive_verifier.rs index 8746d705a..be9a3daeb 100644 --- a/evm_arithmetization/src/fixed_recursive_verifier.rs +++ b/evm_arithmetization/src/fixed_recursive_verifier.rs @@ -46,7 +46,7 @@ use crate::proof::{ PublicValuesTarget, RegistersDataTarget, TrieRoots, TrieRootsTarget, DEFAULT_CAP_LEN, TARGET_HASH_SIZE, }; -use crate::prover::{check_abort_signal, prove}; +use crate::prover::{check_abort_signal, features_check, prove}; use crate::recursive_verifier::{ add_common_recursion_gates, add_virtual_final_public_values_public_input, add_virtual_public_values_public_input, get_memory_extra_looking_sum_circuit, @@ -54,8 +54,6 @@ use crate::recursive_verifier::{ PlonkWrapperCircuit, PublicInputs, StarkWrapperCircuit, }; use crate::util::h256_limbs; -#[cfg(feature = "cdk_erigon")] -use crate::util::u256_limbs; use crate::verifier::initial_memory_merkle_cap; /// The recursion threshold. We end a chain of recursive proofs once we reach @@ -1044,18 +1042,21 @@ where ); // Connect the burn address targets. - BurnAddrTarget::conditional_assert_eq( - &mut builder, - is_not_dummy, - lhs_pv.burn_addr, - rhs_pv.burn_addr.clone(), - ); - BurnAddrTarget::conditional_assert_eq( - &mut builder, - is_not_dummy, - public_values.burn_addr.clone(), - rhs_pv.burn_addr, - ); + #[cfg(feature = "cdk_erigon")] + { + BurnAddrTarget::conditional_assert_eq( + &mut builder, + is_not_dummy, + lhs_pv.burn_addr, + rhs_pv.burn_addr.clone(), + ); + BurnAddrTarget::conditional_assert_eq( + &mut builder, + is_not_dummy, + public_values.burn_addr.clone(), + rhs_pv.burn_addr, + ); + } BlockMetadataTarget::conditional_assert_eq( &mut builder, @@ -1194,16 +1195,19 @@ where ); // Connect the burn address targets. - BurnAddrTarget::connect( - &mut builder, - lhs_pv.burn_addr.clone(), - rhs_pv.burn_addr.clone(), - ); - BurnAddrTarget::connect( - &mut builder, - public_values.burn_addr.clone(), - rhs_pv.burn_addr.clone(), - ); + #[cfg(feature = "cdk_erigon")] + { + BurnAddrTarget::connect( + &mut builder, + lhs_pv.burn_addr.clone(), + rhs_pv.burn_addr.clone(), + ); + BurnAddrTarget::connect( + &mut builder, + public_values.burn_addr.clone(), + rhs_pv.burn_addr.clone(), + ); + } Self::connect_extra_public_values( &mut builder, @@ -1378,16 +1382,19 @@ where ); // 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(), - ); + #[cfg(feature = "cdk_erigon")] + { + 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. @@ -1816,9 +1823,8 @@ where timing: &mut TimingTree, abort_signal: Option>, ) -> anyhow::Result> { - 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.") - } + features_check(&generation_inputs); + let all_proof = prove::( all_stark, config, @@ -1892,6 +1898,8 @@ where timing: &mut TimingTree, abort_signal: Option>, ) -> anyhow::Result>> { + features_check(&generation_inputs.clone().trim()); + let segment_iterator = SegmentDataIterator::::new(&generation_inputs, Some(max_cpu_len_log)); @@ -2347,7 +2355,7 @@ where { let burn_addr_keys = TrieRootsTarget::SIZE * 2..TrieRootsTarget::SIZE * 2 + burn_addr_offset; - for (key, &value) in burn_addr_keys.zip_eq(&u256_limbs( + for (key, &value) in burn_addr_keys.zip_eq(&crate::util::u256_limbs( public_values .burn_addr .expect("We should have a burn addr when cdk_erigon is activated"), diff --git a/evm_arithmetization/src/generation/mod.rs b/evm_arithmetization/src/generation/mod.rs index 315f85265..f30e1e5de 100644 --- a/evm_arithmetization/src/generation/mod.rs +++ b/evm_arithmetization/src/generation/mod.rs @@ -234,10 +234,6 @@ fn apply_metadata_and_tries_memops, const D: usize> ) { let metadata = &inputs.block_metadata; 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, @@ -258,14 +254,17 @@ fn apply_metadata_and_tries_memops, const D: usize> h2u(inputs.block_hashes.cur_hash), ), (GlobalMetadata::BlockGasUsed, metadata.block_gas_used), + #[cfg(feature = "eth_mainnet")] ( GlobalMetadata::BlockBlobGasUsed, metadata.block_blob_gas_used, ), + #[cfg(feature = "eth_mainnet")] ( GlobalMetadata::BlockExcessBlobGas, metadata.block_excess_blob_gas, ), + #[cfg(feature = "eth_mainnet")] ( GlobalMetadata::ParentBeaconBlockRoot, h2u(metadata.parent_beacon_block_root), @@ -304,7 +303,12 @@ 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), + ( + GlobalMetadata::BurnAddr, + inputs + .burn_addr + .map_or_else(U256::max_value, |addr| U256::from_big_endian(&addr.0)), + ), ]; let channel = MemoryChannel::GeneralPurpose(0); diff --git a/evm_arithmetization/src/get_challenges.rs b/evm_arithmetization/src/get_challenges.rs index bb37e01f0..7a8e25f58 100644 --- a/evm_arithmetization/src/get_challenges.rs +++ b/evm_arithmetization/src/get_challenges.rs @@ -65,13 +65,16 @@ fn observe_block_metadata< challenger.observe_element(basefee.0); challenger.observe_element(basefee.1); challenger.observe_element(u256_to_u32(block_metadata.block_gas_used)?); - let blob_gas_used = u256_to_u64(block_metadata.block_blob_gas_used)?; - challenger.observe_element(blob_gas_used.0); - challenger.observe_element(blob_gas_used.1); - let excess_blob_gas = u256_to_u64(block_metadata.block_excess_blob_gas)?; - challenger.observe_element(excess_blob_gas.0); - challenger.observe_element(excess_blob_gas.1); - challenger.observe_elements(&h256_limbs::(block_metadata.parent_beacon_block_root)); + #[cfg(feature = "eth_mainnet")] + { + let blob_gas_used = u256_to_u64(block_metadata.block_blob_gas_used)?; + challenger.observe_element(blob_gas_used.0); + challenger.observe_element(blob_gas_used.1); + let excess_blob_gas = u256_to_u64(block_metadata.block_excess_blob_gas)?; + challenger.observe_element(excess_blob_gas.0); + challenger.observe_element(excess_blob_gas.1); + challenger.observe_elements(&h256_limbs::(block_metadata.parent_beacon_block_root)); + } for i in 0..8 { challenger.observe_elements(&u256_limbs(block_metadata.block_bloom[i])); } @@ -98,9 +101,12 @@ fn observe_block_metadata_target< challenger.observe_element(block_metadata.block_chain_id); challenger.observe_elements(&block_metadata.block_base_fee); challenger.observe_element(block_metadata.block_gas_used); - challenger.observe_elements(&block_metadata.block_blob_gas_used); - challenger.observe_elements(&block_metadata.block_excess_blob_gas); - challenger.observe_elements(&block_metadata.parent_beacon_block_root); + #[cfg(feature = "eth_mainnet")] + { + challenger.observe_elements(&block_metadata.block_blob_gas_used); + challenger.observe_elements(&block_metadata.block_excess_blob_gas); + challenger.observe_elements(&block_metadata.parent_beacon_block_root); + } challenger.observe_elements(&block_metadata.block_bloom); } diff --git a/evm_arithmetization/src/lib.rs b/evm_arithmetization/src/lib.rs index 7e456bc63..bdabc1c79 100644 --- a/evm_arithmetization/src/lib.rs +++ b/evm_arithmetization/src/lib.rs @@ -183,6 +183,17 @@ #![allow(clippy::field_reassign_with_default)] #![feature(let_chains)] +#[cfg_attr( + not(any(feature = "polygon_pos", feature = "cdk_erigon")), + cfg(feature = "eth_mainnet") +)] +#[cfg(any( + all(feature = "cdk_erigon", feature = "polygon_pos"), + all(feature = "cdk_erigon", feature = "eth_mainnet"), + all(feature = "polygon_pos", feature = "eth_mainnet"), +))] +compile_error!("Only a single network feature should be enabled at a time!"); + // Individual STARK processing units pub mod arithmetic; pub mod byte_packing; diff --git a/evm_arithmetization/src/proof.rs b/evm_arithmetization/src/proof.rs index 27f71f8c1..8c4742a07 100644 --- a/evm_arithmetization/src/proof.rs +++ b/evm_arithmetization/src/proof.rs @@ -968,59 +968,45 @@ impl BurnAddrTarget { } } + #[cfg(feature = "cdk_erigon")] /// 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, 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..BurnAddrTarget::get_size() { - builder.connect(a0[i], a1[i]); - } + match (ba0, ba1) { + (BurnAddrTarget::BurnAddr(a0), BurnAddrTarget::BurnAddr(a1)) => { + for i in 0..BurnAddrTarget::get_size() { + builder.connect(a0[i], a1[i]); } - _ => panic!("We should have already set an address (or U256::MAX) before."), } + _ => panic!("We should have already set an address (or U256::MAX) before."), } } + #[cfg(feature = "cdk_erigon")] /// 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, ba0: Self, ba1: Self, ) { - if cfg!(feature = "cdk_erigon") { - match (ba0, ba1) { - ( - BurnAddrTarget::BurnAddr(addr_targets_0), - BurnAddrTarget::BurnAddr(addr_targets_1), - ) => { - for i in 0..BurnAddrTarget::get_size() { - builder.conditional_assert_eq( - condition.target, - addr_targets_0[i], - addr_targets_1[i], - ) - } + match (ba0, ba1) { + ( + BurnAddrTarget::BurnAddr(addr_targets_0), + BurnAddrTarget::BurnAddr(addr_targets_1), + ) => { + for i in 0..BurnAddrTarget::get_size() { + builder.conditional_assert_eq( + condition.target, + addr_targets_0[i], + addr_targets_1[i], + ) } - _ => panic!("There should be an address set in cdk_erigon."), } + _ => panic!("There should be an address set in cdk_erigon."), } } } diff --git a/evm_arithmetization/src/prover.rs b/evm_arithmetization/src/prover.rs index bd6769607..736c900ef 100644 --- a/evm_arithmetization/src/prover.rs +++ b/evm_arithmetization/src/prover.rs @@ -40,9 +40,8 @@ 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.") - } + features_check(&inputs); + // Sanity check on the provided config assert_eq!(DEFAULT_CAP_LEN, 1 << config.fri_config.cap_height); @@ -473,6 +472,20 @@ pub fn check_abort_signal(abort_signal: Option>) -> Result<()> { Ok(()) } +/// Sanity checks on the consistency between this proof payload and the feature +/// flags being used. +pub(crate) fn features_check(inputs: &TrimmedGenerationInputs) { + if cfg!(feature = "polygon_pos") || cfg!(feature = "cdk_erigon") { + assert!(inputs.block_metadata.parent_beacon_block_root.is_zero()); + assert!(inputs.block_metadata.block_blob_gas_used.is_zero()); + assert!(inputs.block_metadata.block_excess_blob_gas.is_zero()); + } + + if !cfg!(feature = "cdk_erigon") { + assert!(inputs.burn_addr.is_none()); + } +} + /// A utility module designed to test witness generation externally. pub mod testing { use super::*; @@ -488,9 +501,8 @@ 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.") - } + features_check(&inputs.clone().trim()); + let initial_stack = vec![]; let initial_offset = KERNEL.global_labels["init"]; let mut interpreter: Interpreter = @@ -545,6 +557,8 @@ pub mod testing { where F: RichField, { + features_check(&inputs.clone().trim()); + for segment in SegmentDataIterator::::new(&inputs, Some(max_cpu_len_log)) { if let Err(e) = segment { return Err(anyhow::format_err!(e)); diff --git a/evm_arithmetization/src/recursive_verifier.rs b/evm_arithmetization/src/recursive_verifier.rs index a15c86b2d..29344ff11 100644 --- a/evm_arithmetization/src/recursive_verifier.rs +++ b/evm_arithmetization/src/recursive_verifier.rs @@ -380,10 +380,12 @@ pub(crate) fn get_memory_extra_looking_sum_circuit, ), ]; - // This contains the `block_beneficiary`, `block_random`, `block_base_fee`, - // `block_blob_gas_used`, `block_excess_blob_gas`, `parent_beacon_block_root` - // as well as `cur_hash`. - let block_fields_arrays: [(GlobalMetadata, &[Target]); 7] = [ + // This contains the `block_beneficiary`, `block_random`, `block_base_fee`, and + // `cur_hash`, as well as the additional `block_blob_gas_used`, + // `block_excess_blob_gas`, `parent_beacon_block_root` when compiling with + // `eth_mainnet` feature flag. + const LENGTH: usize = if cfg!(feature = "eth_mainnet") { 7 } else { 4 }; + let block_fields_arrays: [(GlobalMetadata, &[Target]); LENGTH] = [ ( GlobalMetadata::BlockBeneficiary, &public_values.block_metadata.block_beneficiary, @@ -396,14 +398,17 @@ pub(crate) fn get_memory_extra_looking_sum_circuit, GlobalMetadata::BlockBaseFee, &public_values.block_metadata.block_base_fee, ), + #[cfg(feature = "eth_mainnet")] ( GlobalMetadata::BlockBlobGasUsed, &public_values.block_metadata.block_blob_gas_used, ), + #[cfg(feature = "eth_mainnet")] ( GlobalMetadata::BlockExcessBlobGas, &public_values.block_metadata.block_excess_blob_gas, ), + #[cfg(feature = "eth_mainnet")] ( GlobalMetadata::ParentBeaconBlockRoot, &public_values.block_metadata.parent_beacon_block_root, @@ -1046,31 +1051,34 @@ where block_metadata_target.block_gas_used, u256_to_u32(block_metadata.block_gas_used)?, ); - // BlobGasUsed fits in 2 limbs - let blob_gas_used = u256_to_u64(block_metadata.block_blob_gas_used)?; - witness.set_target( - block_metadata_target.block_blob_gas_used[0], - blob_gas_used.0, - ); - witness.set_target( - block_metadata_target.block_blob_gas_used[1], - blob_gas_used.1, - ); - // ExcessBlobGas fits in 2 limbs - let excess_blob_gas = u256_to_u64(block_metadata.block_excess_blob_gas)?; - witness.set_target( - block_metadata_target.block_excess_blob_gas[0], - excess_blob_gas.0, - ); - witness.set_target( - block_metadata_target.block_excess_blob_gas[1], - excess_blob_gas.1, - ); + #[cfg(feature = "eth_mainnet")] + { + // BlobGasUsed fits in 2 limbs + let blob_gas_used = u256_to_u64(block_metadata.block_blob_gas_used)?; + witness.set_target( + block_metadata_target.block_blob_gas_used[0], + blob_gas_used.0, + ); + witness.set_target( + block_metadata_target.block_blob_gas_used[1], + blob_gas_used.1, + ); + // ExcessBlobGas fits in 2 limbs + let excess_blob_gas = u256_to_u64(block_metadata.block_excess_blob_gas)?; + witness.set_target( + block_metadata_target.block_excess_blob_gas[0], + excess_blob_gas.0, + ); + witness.set_target( + block_metadata_target.block_excess_blob_gas[1], + excess_blob_gas.1, + ); - witness.set_target_arr( - &block_metadata_target.parent_beacon_block_root, - &h256_limbs(block_metadata.parent_beacon_block_root), - ); + witness.set_target_arr( + &block_metadata_target.parent_beacon_block_root, + &h256_limbs(block_metadata.parent_beacon_block_root), + ); + } let mut block_bloom_limbs = [F::ZERO; 64]; for (i, limbs) in block_bloom_limbs.chunks_exact_mut(8).enumerate() { diff --git a/evm_arithmetization/src/verifier.rs b/evm_arithmetization/src/verifier.rs index 52c2c21eb..89220b607 100644 --- a/evm_arithmetization/src/verifier.rs +++ b/evm_arithmetization/src/verifier.rs @@ -320,6 +320,7 @@ where GlobalMetadata::BlockBaseFee, public_values.block_metadata.block_base_fee, ), + #[cfg(feature = "eth_mainnet")] ( GlobalMetadata::ParentBeaconBlockRoot, h2u(public_values.block_metadata.parent_beacon_block_root), @@ -332,10 +333,12 @@ where GlobalMetadata::BlockGasUsed, public_values.block_metadata.block_gas_used, ), + #[cfg(feature = "eth_mainnet")] ( GlobalMetadata::BlockBlobGasUsed, public_values.block_metadata.block_blob_gas_used, ), + #[cfg(feature = "eth_mainnet")] ( GlobalMetadata::BlockExcessBlobGas, public_values.block_metadata.block_excess_blob_gas, @@ -505,6 +508,13 @@ pub(crate) mod debug_utils { GlobalMetadata::BlockBeneficiary, U256::from_big_endian(&public_values.block_metadata.block_beneficiary.0), ), + #[cfg(feature = "cdk_erigon")] + ( + GlobalMetadata::BurnAddr, + public_values + .burn_addr + .expect("There should be an address set in cdk_erigon."), + ), ( GlobalMetadata::BlockTimestamp, public_values.block_metadata.block_timestamp, @@ -541,14 +551,17 @@ pub(crate) mod debug_utils { GlobalMetadata::BlockGasUsed, public_values.block_metadata.block_gas_used, ), + #[cfg(feature = "eth_mainnet")] ( GlobalMetadata::BlockBlobGasUsed, public_values.block_metadata.block_blob_gas_used, ), + #[cfg(feature = "eth_mainnet")] ( GlobalMetadata::BlockExcessBlobGas, public_values.block_metadata.block_excess_blob_gas, ), + #[cfg(feature = "eth_mainnet")] ( GlobalMetadata::ParentBeaconBlockRoot, h2u(public_values.block_metadata.parent_beacon_block_root), diff --git a/evm_arithmetization/src/witness/transition.rs b/evm_arithmetization/src/witness/transition.rs index 1bcbeb567..6263977f4 100644 --- a/evm_arithmetization/src/witness/transition.rs +++ b/evm_arithmetization/src/witness/transition.rs @@ -120,7 +120,9 @@ pub(crate) fn decode(registers: RegistersState, opcode: u8) -> Result Ok(Operation::Syscall(opcode, 0, true)), // CHAINID (0x47, _) => Ok(Operation::Syscall(opcode, 0, true)), // SELFBALANCE (0x48, _) => Ok(Operation::Syscall(opcode, 0, true)), // BASEFEE + #[cfg(feature = "eth_mainnet")] (0x49, _) => Ok(Operation::Syscall(opcode, 1, false)), // BLOBHASH + #[cfg(feature = "eth_mainnet")] (0x4a, _) => Ok(Operation::Syscall(opcode, 0, true)), // BLOBBASEFEE (0x50, _) => Ok(Operation::Pop), (0x51, _) => Ok(Operation::Syscall(opcode, 1, false)), // MLOAD diff --git a/evm_arithmetization/tests/add11_yml.rs b/evm_arithmetization/tests/add11_yml.rs index e892d2772..a7624a6df 100644 --- a/evm_arithmetization/tests/add11_yml.rs +++ b/evm_arithmetization/tests/add11_yml.rs @@ -1,4 +1,4 @@ -#![cfg(not(feature = "cdk_erigon"))] +#![cfg(feature = "eth_mainnet")] use std::collections::HashMap; use std::str::FromStr; diff --git a/evm_arithmetization/tests/erc20.rs b/evm_arithmetization/tests/erc20.rs index cd16de80f..61bb3f2ef 100644 --- a/evm_arithmetization/tests/erc20.rs +++ b/evm_arithmetization/tests/erc20.rs @@ -1,4 +1,4 @@ -#![cfg(not(feature = "cdk_erigon"))] +#![cfg(feature = "eth_mainnet")] use std::str::FromStr; use std::time::Duration; diff --git a/evm_arithmetization/tests/erc721.rs b/evm_arithmetization/tests/erc721.rs index 851560430..47d214f9e 100644 --- a/evm_arithmetization/tests/erc721.rs +++ b/evm_arithmetization/tests/erc721.rs @@ -1,4 +1,4 @@ -#![cfg(not(feature = "cdk_erigon"))] +#![cfg(feature = "eth_mainnet")] use std::str::FromStr; use std::time::Duration; diff --git a/evm_arithmetization/tests/global_exit_root.rs b/evm_arithmetization/tests/global_exit_root.rs index ba9ac1c02..0bc41eaf8 100644 --- a/evm_arithmetization/tests/global_exit_root.rs +++ b/evm_arithmetization/tests/global_exit_root.rs @@ -8,10 +8,8 @@ use evm_arithmetization::generation::{GenerationInputs, TrieInputs}; use evm_arithmetization::proof::{BlockHashes, BlockMetadata, TrieRoots}; use evm_arithmetization::prover::testing::prove_all_segments; use evm_arithmetization::testing_utils::{ - beacon_roots_account_nibbles, beacon_roots_contract_from_storage, ger_account_nibbles, - ger_contract_from_storage, init_logger, preinitialized_state_and_storage_tries, - scalable_account_nibbles, scalable_contract_from_storage, update_beacon_roots_account_storage, - update_ger_account_storage, update_scalable_account_storage, + ger_account_nibbles, ger_contract_from_storage, init_logger, scalable_account_nibbles, + scalable_contract_from_storage, update_ger_account_storage, update_scalable_account_storage, ADDRESS_SCALABLE_L2_ADDRESS_HASHED, GLOBAL_EXIT_ROOT_ACCOUNT, GLOBAL_EXIT_ROOT_ADDRESS_HASHED, }; use evm_arithmetization::verifier::testing::verify_all_proofs; @@ -40,13 +38,13 @@ fn test_global_exit_root() -> anyhow::Result<()> { ..BlockMetadata::default() }; - let (mut state_trie_before, mut storage_tries) = preinitialized_state_and_storage_tries()?; + let mut state_trie_before = HashedPartialTrie::from(Node::Empty); + let mut storage_tries = vec![]; state_trie_before.insert( ger_account_nibbles(), rlp::encode(&GLOBAL_EXIT_ROOT_ACCOUNT).to_vec(), )?; - let mut beacon_roots_account_storage = storage_tries[0].1.clone(); let mut ger_account_storage = HashedPartialTrie::from(Node::Empty); let mut scalable_account_storage = HashedPartialTrie::from(Node::Empty); @@ -66,11 +64,6 @@ fn test_global_exit_root() -> anyhow::Result<()> { let state_trie_after = { let mut trie = HashedPartialTrie::from(Node::Empty); - update_beacon_roots_account_storage( - &mut beacon_roots_account_storage, - block_metadata.block_timestamp, - block_metadata.parent_beacon_block_root, - )?; update_ger_account_storage(&mut ger_account_storage, ger_data)?; update_scalable_account_storage( &mut scalable_account_storage, @@ -78,15 +71,9 @@ fn test_global_exit_root() -> anyhow::Result<()> { state_trie_before.hash(), )?; - let beacon_roots_account = - beacon_roots_contract_from_storage(&beacon_roots_account_storage); let ger_account = ger_contract_from_storage(&ger_account_storage); let scalable_account = scalable_contract_from_storage(&scalable_account_storage); - trie.insert( - beacon_roots_account_nibbles(), - rlp::encode(&beacon_roots_account).to_vec(), - )?; trie.insert(ger_account_nibbles(), rlp::encode(&ger_account).to_vec())?; trie.insert( scalable_account_nibbles(), diff --git a/evm_arithmetization/tests/log_opcode.rs b/evm_arithmetization/tests/log_opcode.rs index b08ace71c..0b925ceae 100644 --- a/evm_arithmetization/tests/log_opcode.rs +++ b/evm_arithmetization/tests/log_opcode.rs @@ -1,4 +1,4 @@ -#![cfg(not(feature = "cdk_erigon"))] +#![cfg(feature = "eth_mainnet")] use std::collections::HashMap; use std::str::FromStr; diff --git a/evm_arithmetization/tests/selfdestruct.rs b/evm_arithmetization/tests/selfdestruct.rs index 0669486bc..271630512 100644 --- a/evm_arithmetization/tests/selfdestruct.rs +++ b/evm_arithmetization/tests/selfdestruct.rs @@ -1,4 +1,4 @@ -#![cfg(not(feature = "cdk_erigon"))] +#![cfg(feature = "eth_mainnet")] use std::str::FromStr; use std::time::Duration; diff --git a/evm_arithmetization/tests/simple_transfer.rs b/evm_arithmetization/tests/simple_transfer.rs index 37d14bf05..81454fb0e 100644 --- a/evm_arithmetization/tests/simple_transfer.rs +++ b/evm_arithmetization/tests/simple_transfer.rs @@ -1,4 +1,4 @@ -#![cfg(not(feature = "cdk_erigon"))] +#![cfg(feature = "eth_mainnet")] use std::collections::HashMap; use std::str::FromStr; diff --git a/evm_arithmetization/tests/two_to_one_block.rs b/evm_arithmetization/tests/two_to_one_block.rs index 6c107c54d..2474bb82b 100644 --- a/evm_arithmetization/tests/two_to_one_block.rs +++ b/evm_arithmetization/tests/two_to_one_block.rs @@ -1,4 +1,4 @@ -#![cfg(not(feature = "cdk_erigon"))] +#![cfg(feature = "eth_mainnet")] use ethereum_types::{Address, BigEndianHash, H256}; use evm_arithmetization::fixed_recursive_verifier::{ @@ -173,36 +173,19 @@ fn test_two_to_one_block_aggregation() -> anyhow::Result<()> { let all_stark = AllStark::::default(); let config = StarkConfig::standard_fast_config(); - let circuit_ranges = if cfg!(feature = "cdk_erigon") { - vec![ - 16..17_usize, - 8..9, - 14..15, - 9..10, - 8..9, - 7..8, - 17..18, - 17..18, - 7..8, - 4..5, - ] - } else { - vec![ - 16..17_usize, + let all_circuits = AllRecursiveCircuits::::new( + &all_stark, + &[ + 16..17, 8..9, - 14..15, + 12..13, 9..10, 8..9, - 7..8, + 6..7, 17..18, 17..18, 7..8, - ] - }; - - let all_circuits = AllRecursiveCircuits::::new( - &all_stark, - &circuit_ranges.try_into().unwrap(), + ], &config, ); diff --git a/evm_arithmetization/tests/withdrawals.rs b/evm_arithmetization/tests/withdrawals.rs index 9839c6646..4868a2fd4 100644 --- a/evm_arithmetization/tests/withdrawals.rs +++ b/evm_arithmetization/tests/withdrawals.rs @@ -1,4 +1,4 @@ -#![cfg(not(feature = "cdk_erigon"))] +#![cfg(feature = "eth_mainnet")] use std::collections::HashMap; use std::time::Duration; diff --git a/proof_gen/Cargo.toml b/proof_gen/Cargo.toml index 304862ece..9c72b0362 100644 --- a/proof_gen/Cargo.toml +++ b/proof_gen/Cargo.toml @@ -20,8 +20,13 @@ hashbrown = { workspace = true } evm_arithmetization = { workspace = true } [features] -default = [] -cdk_erigon = ["evm_arithmetization/cdk_erigon"] +default = ["eth_mainnet"] +eth_mainnet = [ + "evm_arithmetization/eth_mainnet" +] +cdk_erigon = [ + "evm_arithmetization/cdk_erigon" +] [lints] workspace = true diff --git a/trace_decoder/Cargo.toml b/trace_decoder/Cargo.toml index 78e0aa3ef..4febd85f2 100644 --- a/trace_decoder/Cargo.toml +++ b/trace_decoder/Cargo.toml @@ -20,23 +20,25 @@ copyvec = "0.2.0" either = { workspace = true } enum-as-inner = { workspace = true } ethereum-types = { workspace = true } -evm_arithmetization = { workspace = true } hex = { workspace = true } hex-literal = { workspace = true } itertools.workspace = true keccak-hash = { workspace = true } log = { workspace = true } -mpt_trie = { workspace = true } nunny = { workspace = true, features = ["serde"] } plonky2 = { workspace = true } rlp = { workspace = true } serde = { workspace = true } -smt_trie = { workspace = true } stackstack = "0.3.0" strum = { version = "0.26.3", features = ["derive"] } thiserror = { workspace = true } u4 = { workspace = true } winnow = { workspace = true } + +# Local dependencies +evm_arithmetization = { workspace = true } +mpt_trie = { workspace = true } +smt_trie = { workspace = true } zk_evm_common = { workspace = true } [dev-dependencies] @@ -53,6 +55,18 @@ prover = { workspace = true } serde_json = { workspace = true } serde_path_to_error = { workspace = true } + +[features] +default = ["eth_mainnet"] +eth_mainnet = [ + "evm_arithmetization/eth_mainnet", + "prover/eth_mainnet", +] +cdk_erigon = [ + "evm_arithmetization/cdk_erigon", + "prover/cdk_erigon", +] + [[bench]] name = "block_processing" harness = false diff --git a/zero_bin/common/Cargo.toml b/zero_bin/common/Cargo.toml index 7171fa2a8..0b389cf9f 100644 --- a/zero_bin/common/Cargo.toml +++ b/zero_bin/common/Cargo.toml @@ -14,32 +14,40 @@ anyhow = { workspace = true } async-stream = { workspace = true } cargo_metadata = { workspace = true } clap = { workspace = true } -evm_arithmetization = { workspace = true } futures = { workspace = true } lru = { workspace = true } once_cell = { workspace = true } plonky2 = { workspace = true } -proof_gen = { workspace = true } serde = { workspace = true } serde_json = { workspace = true } thiserror = { workspace = true } tokio = { workspace = true } -trace_decoder = { workspace = true } tracing = { workspace = true } vergen = { workspace = true } directories = "5.0.1" +# Local dependencies +evm_arithmetization = { workspace = true } +proof_gen = { workspace = true } +trace_decoder = { workspace = true } + [build-dependencies] cargo_metadata = { workspace = true } vergen = { workspace = true } anyhow = { workspace = true } [features] -default = [] +default = ["eth_mainnet"] +eth_mainnet = [ + "evm_arithmetization/eth_mainnet", + "proof_gen/eth_mainnet", + "trace_decoder/eth_mainnet", +] cdk_erigon = [ "evm_arithmetization/cdk_erigon", - "proof_gen/cdk_erigon" + "proof_gen/cdk_erigon", + "trace_decoder/cdk_erigon", ] [lints] diff --git a/zero_bin/leader/Cargo.toml b/zero_bin/leader/Cargo.toml index cad05cd22..5b9a67f34 100644 --- a/zero_bin/leader/Cargo.toml +++ b/zero_bin/leader/Cargo.toml @@ -18,7 +18,6 @@ anyhow = { workspace = true } serde = { workspace = true } dotenvy = { workspace = true } tokio = { workspace = true } -proof_gen = { workspace = true } serde_json = { workspace = true } serde_path_to_error = { workspace = true } futures = { workspace = true } @@ -27,16 +26,26 @@ axum = { workspace = true } toml = { workspace = true } # Local dependencies +evm_arithmetization = { workspace = true } ops = { workspace = true } +proof_gen = { workspace = true } prover = { workspace = true } rpc = { workspace = true } -evm_arithmetization = { workspace = true } zero_bin_common = { workspace = true } [features] -default = [] +default = ["eth_mainnet"] +eth_mainnet = [ + "evm_arithmetization/eth_mainnet", + "ops/eth_mainnet", + "proof_gen/eth_mainnet", + "prover/eth_mainnet", + "rpc/eth_mainnet", + "zero_bin_common/eth_mainnet" +] cdk_erigon = [ "evm_arithmetization/cdk_erigon", + "ops/cdk_erigon", "proof_gen/cdk_erigon", "prover/cdk_erigon", "rpc/cdk_erigon", diff --git a/zero_bin/ops/Cargo.toml b/zero_bin/ops/Cargo.toml index 8975cc8d5..4e7bef01a 100644 --- a/zero_bin/ops/Cargo.toml +++ b/zero_bin/ops/Cargo.toml @@ -11,13 +11,26 @@ categories.workspace = true [dependencies] paladin-core = { workspace = true } serde = { workspace = true } -evm_arithmetization = { workspace = true } -proof_gen = { workspace = true } tracing = { workspace = true } -trace_decoder = { workspace = true } keccak-hash = { workspace = true } -zero_bin_common = { path = "../common" } +# Local dependencies +evm_arithmetization = { workspace = true } +proof_gen = { workspace = true } +trace_decoder = { workspace = true } +zero_bin_common = { workspace = true } [features] -default = [] +default = ["eth_mainnet"] +eth_mainnet = [ + "evm_arithmetization/eth_mainnet", + "proof_gen/eth_mainnet", + "trace_decoder/eth_mainnet", + "zero_bin_common/eth_mainnet", +] +cdk_erigon = [ + "evm_arithmetization/cdk_erigon", + "proof_gen/cdk_erigon", + "trace_decoder/cdk_erigon", + "zero_bin_common/cdk_erigon", +] diff --git a/zero_bin/prover/Cargo.toml b/zero_bin/prover/Cargo.toml index 6295f65b4..b4e54b19a 100644 --- a/zero_bin/prover/Cargo.toml +++ b/zero_bin/prover/Cargo.toml @@ -12,25 +12,39 @@ categories.workspace = true alloy.workspace = true anyhow = { workspace = true } clap = {workspace = true, features = ["derive", "string"] } -evm_arithmetization = { workspace = true } futures = { workspace = true } num-traits = { workspace = true } ops = { workspace = true } paladin-core = { workspace = true } plonky2 = { workspace = true } plonky2_maybe_rayon = { workspace = true } -proof_gen = { workspace = true } ruint = { workspace = true, features = ["num-traits", "primitive-types"] } serde = { workspace = true } serde_json = { workspace = true } tokio = { workspace = true } -trace_decoder = { workspace = true } tracing = { workspace = true } + +# Local dependencies +evm_arithmetization = { workspace = true } +proof_gen = { workspace = true } +trace_decoder = { workspace = true } zero_bin_common = { workspace = true } + [features] -default = [] -cdk_erigon = [] +default = ["eth_mainnet"] +eth_mainnet = [ + "evm_arithmetization/eth_mainnet", + "proof_gen/eth_mainnet", + "trace_decoder/eth_mainnet", + "zero_bin_common/eth_mainnet", +] +cdk_erigon = [ + "evm_arithmetization/cdk_erigon", + "proof_gen/cdk_erigon", + "trace_decoder/cdk_erigon", + "zero_bin_common/cdk_erigon", +] [lints] workspace = true diff --git a/zero_bin/rpc/Cargo.toml b/zero_bin/rpc/Cargo.toml index 046461569..8d4444bb6 100644 --- a/zero_bin/rpc/Cargo.toml +++ b/zero_bin/rpc/Cargo.toml @@ -14,15 +14,12 @@ __compat_primitive_types = { workspace = true } alloy.workspace = true anyhow = { workspace = true } clap = { workspace = true } -evm_arithmetization = { workspace = true } futures = { workspace = true } hex = { workspace = true } -mpt_trie = { workspace = true } serde = { workspace = true } serde_json = { workspace = true } tokio = { workspace = true } tower = { workspace = true, features = ["retry"] } -trace_decoder = { workspace = true } tracing = { workspace = true } tracing-subscriber = { workspace = true } url = { workspace = true } @@ -30,8 +27,11 @@ itertools = { workspace = true } # Local dependencies compat = { workspace = true } -zero_bin_common = { workspace = true } +evm_arithmetization = { workspace = true } +mpt_trie = { workspace = true } prover = { workspace = true } +trace_decoder = { workspace = true } +zero_bin_common = { workspace = true } [build-dependencies] cargo_metadata = { workspace = true } @@ -39,4 +39,16 @@ vergen = { workspace = true } anyhow = { workspace = true } [features] -cdk_erigon = [] \ No newline at end of file +default = ["eth_mainnet"] +eth_mainnet = [ + "evm_arithmetization/eth_mainnet", + "prover/eth_mainnet", + "trace_decoder/eth_mainnet", + "zero_bin_common/eth_mainnet", +] +cdk_erigon = [ + "evm_arithmetization/cdk_erigon", + "prover/cdk_erigon", + "trace_decoder/cdk_erigon", + "zero_bin_common/cdk_erigon", +] \ No newline at end of file diff --git a/zero_bin/verifier/Cargo.toml b/zero_bin/verifier/Cargo.toml index ab9e5068f..80d64df1f 100644 --- a/zero_bin/verifier/Cargo.toml +++ b/zero_bin/verifier/Cargo.toml @@ -13,12 +13,24 @@ dotenvy = { workspace = true } anyhow = { workspace = true } serde_json = { workspace = true } serde_path_to_error = { workspace = true } -proof_gen = { workspace = true } # Local dependencies -zero_bin_common = { path = "../common" } +proof_gen = { workspace = true } +zero_bin_common = { workspace = true } [build-dependencies] cargo_metadata = { workspace = true } vergen = { workspace = true } anyhow = { workspace = true } + + +[features] +default = ["eth_mainnet"] +eth_mainnet = [ + "proof_gen/eth_mainnet", + "zero_bin_common/eth_mainnet", +] +cdk_erigon = [ + "proof_gen/cdk_erigon", + "zero_bin_common/cdk_erigon", +] diff --git a/zero_bin/worker/Cargo.toml b/zero_bin/worker/Cargo.toml index 3a146c90e..0e7d80d0b 100644 --- a/zero_bin/worker/Cargo.toml +++ b/zero_bin/worker/Cargo.toml @@ -28,3 +28,14 @@ jemallocator = "0.5.4" cargo_metadata = { workspace = true } vergen = { workspace = true } anyhow = { workspace = true } + +[features] +default = ["eth_mainnet"] +eth_mainnet = [ + "ops/eth_mainnet", + "zero_bin_common/eth_mainnet", +] +cdk_erigon = [ + "ops/cdk_erigon", + "zero_bin_common/cdk_erigon", +] \ No newline at end of file