From 79f0c204f5ed3b2297e212943d89dc8ff3e9428c Mon Sep 17 00:00:00 2001 From: Robin Salen Date: Sat, 31 Aug 2024 10:01:10 -0400 Subject: [PATCH 01/17] WIP --- .../src/cpu/kernel/asm/beacon_roots.asm | 11 +- .../src/cpu/kernel/asm/cdk_pre_execution.asm | 112 ++++++++++++++++++ .../src/cpu/kernel/asm/global_exit_root.asm | 48 -------- .../asm/mpt/linked_list/linked_list.asm | 10 ++ .../src/cpu/kernel/constants/mod.rs | 35 ++++++ 5 files changed, 167 insertions(+), 49 deletions(-) create mode 100644 evm_arithmetization/src/cpu/kernel/asm/cdk_pre_execution.asm delete mode 100644 evm_arithmetization/src/cpu/kernel/asm/global_exit_root.asm diff --git a/evm_arithmetization/src/cpu/kernel/asm/beacon_roots.asm b/evm_arithmetization/src/cpu/kernel/asm/beacon_roots.asm index 6fba36fec..e3607af8b 100644 --- a/evm_arithmetization/src/cpu/kernel/asm/beacon_roots.asm +++ b/evm_arithmetization/src/cpu/kernel/asm/beacon_roots.asm @@ -4,7 +4,16 @@ /// *NOTE*: This will panic if one of the provided timestamps is zero. global set_beacon_root: - PUSH set_global_exit_roots + // TODO(Robin): Add conditional neg feature + #[cfg(feature = cdk_erigon)] + { + PUSH pre_block_execution + } + #[cfg(feature = not_cdk_erigon)] + { + PUSH start_txn + } + %timestamp // stack: timestamp, retdest PUSH @HISTORY_BUFFER_LENGTH diff --git a/evm_arithmetization/src/cpu/kernel/asm/cdk_pre_execution.asm b/evm_arithmetization/src/cpu/kernel/asm/cdk_pre_execution.asm new file mode 100644 index 000000000..6221b72db --- /dev/null +++ b/evm_arithmetization/src/cpu/kernel/asm/cdk_pre_execution.asm @@ -0,0 +1,112 @@ +/// CDK-Erigon pre-block execution logic. +/// Reference implementation: `cdk-erigon/core/state/intra_block_state_zkevm.go`. +/// This currently supports the Etrog upgrade. + +// TODO(Robin): Remove code template +// func (sdb *IntraBlockState) SyncerPreExecuteStateSet( +// chainConfig *chain.Config, +// blockNumber uint64, +// blockTimestamp uint64, +// prevBlockHash, blockGer, l1BlockHash *libcommon.Hash, +// gerUpdates *[]dstypes.GerUpdate, +// reUsedL1InfoTreeIndex bool, +// ) { +// if !sdb.Exist(ADDRESS_SCALABLE_L2) { +// // create account if not exists +// sdb.CreateAccount(ADDRESS_SCALABLE_L2, true) +// } + +// //save block number +// sdb.scalableSetBlockNum(blockNumber) +// emptyHash := libcommon.Hash{} + +// //ETROG +// if chainConfig.IsForkID7Etrog(blockNumber) { +// currentTimestamp := sdb.ScalableGetTimestamp() +// if blockTimestamp > currentTimestamp { +// sdb.ScalableSetTimestamp(blockTimestamp) +// } + +// //save prev block hash +// sdb.scalableSetBlockHash(blockNumber-1, prevBlockHash) + +// //save ger with l1blockhash - but only in the case that the l1 info tree index hasn't been +// // re-used. If it has been re-used we never write this to the contract storage +// if !reUsedL1InfoTreeIndex && blockGer != nil && *blockGer != emptyHash { +// sdb.WriteGerManagerL1BlockHash(*blockGer, *l1BlockHash) +// } +// } +// } + + +/// Pre-stack: (empty) +/// Post-stack: (empty) +global pre_block_execution: + // stack: (empty) + PUSH start_txn + // stack: retdest + PUSH @ADDRESS_SCALABLE_L2_STATE_KEY + %is_non_existent + %jumpi(create_scalable_l2_account) + +global update_scalable_block_number: + // stack: retdest + %blocknumber + PUSH @LAST_BLOCK_STORAGE_POS + // stack: last_block_slot, block_number, retdest + %write_scalable_storage + // stack: retdest + + // Check timestamp + PUSH @ADDRESS_SCALABLE_L2_STATE_KEY + PUSH @TIMESTAMP_STORAGE_POS + %read_storage_linked_list_w_state_key + // stack: old_timestamp, retdest + %timestamp + GT %jumpi(update_scalable_timestamp) + +global update_scalable_prev_block_root_hash: + // stack: retdest + %mload_global_metadata(@GLOBAL_METADATA_STATE_TRIE_DIGEST_BEFORE) + // stack: prev_block_root, retdest + PUSH 1 %block_number SUB + // stack: block_number - 1, prev_block_root, retdest + %write_scalable_storage + // stack: retdest + +global update_scalable_l1_blockhash: + // stack: retdest + // TODO(RObin): FINISH + JUMP + +global update_scalable_timestamp: + %timestamp + PUSH @TIMESTAMP_STORAGE_POS + // stack: timestamp_slot, timestamp, retdest + %write_scalable_storage + %jump(update_scalable_prev_block_root_hash) + +global create_scalable_l2_account: + // stack: (empty) + PUSH update_scalable_block_number + // stack: retdest + %get_trie_data_size // pointer to new account we're about to create + // stack: new_account_ptr, retdest + PUSH 0 %append_to_trie_data // nonce + PUSH 0 %append_to_trie_data // balance + PUSH 0 %append_to_trie_data // storage root pointer + PUSH @EMPTY_STRING_HASH %append_to_trie_data // code hash + // stack: new_account_ptr, retdest + PUSH @L2ADDRESS_SCALABLE_L2_STATE_KEY + // stack: key, new_account_ptr, retdest + %jump(mpt_insert_state_trie) + +%macro write_scalable_storage + // stack: slot, value + %slot_to_storage_key + // stack: storage_key, value + PUSH @ADDRESS_SCALABLE_L2_STATE_KEY + // stack: state_key, storage_key, value + %insert_slot_with_value_from_keys + // stack: (empty) +%endmacro diff --git a/evm_arithmetization/src/cpu/kernel/asm/global_exit_root.asm b/evm_arithmetization/src/cpu/kernel/asm/global_exit_root.asm deleted file mode 100644 index 94c81fdf4..000000000 --- a/evm_arithmetization/src/cpu/kernel/asm/global_exit_root.asm +++ /dev/null @@ -1,48 +0,0 @@ -/// At the top of the block, the global exit roots (if any) are written to storage. -/// Global exit roots (GER) are of the form `(timestamp, root)` and are loaded from prover inputs. -/// The timestamp is written to the storage of address `GLOBAL_EXIT_ROOT_MANAGER_L2_STATE_KEY` in the slot `keccak256(abi.encodePacked(root, GLOBAL_EXIT_ROOT_STORAGE_POS))`. -/// See https://github.com/0xPolygonHermez/cdk-erigon/blob/zkevm/zk/utils/global_exit_root.go for reference. -/// -/// *NOTE*: This will panic if one of the provided timestamps is zero. - -global set_global_exit_roots: - // stack: (empty) - PUSH txn_loop - // stack: retdest - PUSH @GLOBAL_EXIT_ROOT_MANAGER_L2_STATE_KEY - %addr_to_state_key - PROVER_INPUT(ger) - // stack: num_ger, state_key, retdest - PUSH 0 -ger_loop: - // stack: i, num_ger, state_key, retdest - DUP2 DUP2 EQ %jumpi(ger_loop_end) - PROVER_INPUT(ger) - // stack: timestamp, i, num_ger, state_key, retdest - PUSH @GLOBAL_EXIT_ROOT_STORAGE_POS - PROVER_INPUT(ger) - // stack: root, GLOBAL_EXIT_ROOT_STORAGE_POS, timestamp, i, num_ger, state_key, retdest - PUSH @SEGMENT_KERNEL_GENERAL - // stack: addr, root, GLOBAL_EXIT_ROOT_STORAGE_POS, timestamp, i, num_ger, state_key, retdest - MSTORE_32BYTES_32 - // stack: addr, GLOBAL_EXIT_ROOT_STORAGE_POS, timestamp, i, num_ger, state_key, retdest - MSTORE_32BYTES_32 - // stack: addr, timestamp, i, num_ger, state_key, retdest - POP - // stack: timestamp, i, num_ger, state_key, retdest - PUSH 64 PUSH @SEGMENT_KERNEL_GENERAL - // stack: addr, len, timestamp, i, num_ger, state_key, retdest - KECCAK_GENERAL - // stack: slot, timestamp, i, num_ger, state_key, retdest - %slot_to_storage_key - // stack: slot_key, timestamp, i, num_ger, state_key, retdest - DUP5 - // stack: state_key, slot_key, timestamp, i, num_ger, state_key, retdest - %insert_slot_with_value_from_keys - // stack: i, num_ger, state_key, retdest - %increment - %jump(ger_loop) - -ger_loop_end: - // stack: i, num_ger, state_key, retdest - %pop3 JUMP diff --git a/evm_arithmetization/src/cpu/kernel/asm/mpt/linked_list/linked_list.asm b/evm_arithmetization/src/cpu/kernel/asm/mpt/linked_list/linked_list.asm index a28d83779..e4bff5b12 100644 --- a/evm_arithmetization/src/cpu/kernel/asm/mpt/linked_list/linked_list.asm +++ b/evm_arithmetization/src/cpu/kernel/asm/mpt/linked_list/linked_list.asm @@ -878,6 +878,16 @@ remove_all_slots_end: // stack: slot_value %endmacro +%macro read_storage_linked_list_w_state_key + // stack: slot, state_key + %slot_to_storage_key + SWAP1 + %stack (state_key, key) -> (state_key, key, 0, %%after) + %jump(search_slot) +%%after: + // stack: slot_ptr +%endmacro + %macro first_account // stack: empty PUSH @SEGMENT_ACCOUNTS_LINKED_LIST diff --git a/evm_arithmetization/src/cpu/kernel/constants/mod.rs b/evm_arithmetization/src/cpu/kernel/constants/mod.rs index 577bfb875..9d7c40219 100644 --- a/evm_arithmetization/src/cpu/kernel/constants/mod.rs +++ b/evm_arithmetization/src/cpu/kernel/constants/mod.rs @@ -85,6 +85,26 @@ pub(crate) fn evm_constants() -> HashMap { global_exit_root::GLOBAL_EXIT_ROOT_STORAGE_POS.0.into(), U256::from(global_exit_root::GLOBAL_EXIT_ROOT_STORAGE_POS.1), ); + c.insert( + global_exit_root::ADDRESS_SCALABLE_L2_STATE_KEY.0.into(), + U256::from_big_endian(&global_exit_root::ADDRESS_SCALABLE_L2_STATE_KEY.1), + ); + c.insert( + global_exit_root::LAST_BLOCK_STORAGE_POS.0.into(), + U256::from(global_exit_root::LAST_BLOCK_STORAGE_POS.1), + ); + c.insert( + global_exit_root::STATE_ROOT_STORAGE_POS.0.into(), + U256::from(global_exit_root::STATE_ROOT_STORAGE_POS.1), + ); + c.insert( + global_exit_root::TIMESTAMP_STORAGE_POS.0.into(), + U256::from(global_exit_root::TIMESTAMP_STORAGE_POS.1), + ); + c.insert( + global_exit_root::BLOCK_INFO_ROOT_STORAGE_POS.0.into(), + U256::from(global_exit_root::BLOCK_INFO_ROOT_STORAGE_POS.1), + ); for segment in Segment::all() { c.insert(segment.var_name().into(), (segment as usize).into()); @@ -444,9 +464,24 @@ pub mod global_exit_root { "GLOBAL_EXIT_ROOT_MANAGER_L2_STATE_KEY", hex!("a40D5f56745a118D0906a34E69aeC8C0Db1cB8fA"), ); + /// Taken from https://github.com/0xPolygonHermez/cdk-erigon/blob/dc3cbcc59a95769626056c7bc70aade501e7741d/core/state/intra_block_state_zkevm.go#L20. + pub const ADDRESS_SCALABLE_L2: (&str, [u8; 20]) = ( + "ADDRESS_SCALABLE_L2", + hex!("000000000000000000000000000000005ca1ab1e"), + ); + pub const ADDRESS_SCALABLE_L2_STATE_KEY: (&str, [u8; 32]) = ( + "ADDRESS_SCALABLE_L2_STATE_KEY", + hex!("4bff39c4f33dafcd90c45c9a0a1f2e72949b200788587b306eda5dd84aa87577"), + ); /// Taken from https://github.com/0xPolygonHermez/cdk-erigon/blob/61f0b6912055c73f6879ea7e9b5bac22ea5fc85c/zk/utils/global_exit_root.go#L17. pub const GLOBAL_EXIT_ROOT_STORAGE_POS: (&str, u64) = ("GLOBAL_EXIT_ROOT_STORAGE_POS", 0); + /// Taken from https://github.com/0xPolygonHermez/cdk-erigon/blob/dc3cbcc59a95769626056c7bc70aade501e7741d/core/state/intra_block_state_zkevm.go#L16. + pub const LAST_BLOCK_STORAGE_POS: (&str, u64) = ("LAST_BLOCK_STORAGE_POS", 0); + pub const STATE_ROOT_STORAGE_POS: (&str, u64) = ("STATE_ROOT_STORAGE_POS", 1); + pub const TIMESTAMP_STORAGE_POS: (&str, u64) = ("TIMESTAMP_STORAGE_POS", 2); + pub const BLOCK_INFO_ROOT_STORAGE_POS: (&str, u64) = ("BLOCK_INFO_ROOT_STORAGE_POS", 3); + /// Taken from https://zkevm.polygonscan.com/address/0xa40D5f56745a118D0906a34E69aeC8C0Db1cB8fA#code. pub const GLOBAL_EXIT_ROOT_CONTRACT_CODE: [u8; 2112] = hex!("60806040526004361061004e5760003560e01c80633659cfe6146100655780634f1ef286146100855780635c60da1b146100985780638f283970146100c9578063f851a440146100e95761005d565b3661005d5761005b6100fe565b005b61005b6100fe565b34801561007157600080fd5b5061005b6100803660046106ca565b610118565b61005b6100933660046106e5565b61015f565b3480156100a457600080fd5b506100ad6101d0565b6040516001600160a01b03909116815260200160405180910390f35b3480156100d557600080fd5b5061005b6100e43660046106ca565b61020b565b3480156100f557600080fd5b506100ad610235565b610106610292565b610116610111610331565b61033b565b565b61012061035f565b6001600160a01b0316336001600160a01b031614156101575761015481604051806020016040528060008152506000610392565b50565b6101546100fe565b61016761035f565b6001600160a01b0316336001600160a01b031614156101c8576101c38383838080601f01602080910402602001604051908101604052809392919081815260200183838082843760009201919091525060019250610392915050565b505050565b6101c36100fe565b60006101da61035f565b6001600160a01b0316336001600160a01b03161415610200576101fb610331565b905090565b6102086100fe565b90565b61021361035f565b6001600160a01b0316336001600160a01b0316141561015757610154816103f1565b600061023f61035f565b6001600160a01b0316336001600160a01b03161415610200576101fb61035f565b606061028583836040518060600160405280602781526020016107e460279139610445565b9392505050565b3b151590565b61029a61035f565b6001600160a01b0316336001600160a01b031614156101165760405162461bcd60e51b815260206004820152604260248201527f5472616e73706172656e745570677261646561626c6550726f78793a2061646d60448201527f696e2063616e6e6f742066616c6c6261636b20746f2070726f78792074617267606482015261195d60f21b608482015260a4015b60405180910390fd5b60006101fb610519565b3660008037600080366000845af43d6000803e80801561035a573d6000f35b3d6000fd5b60007fb53127684a568b3173ae13b9f8a6016e243e63b6e8ee1178d6a717850b5d61035b546001600160a01b0316919050565b61039b83610541565b6040516001600160a01b038416907fbc7cd75a20ee27fd9adebab32041f755214dbc6bffa90cc0225b39da2e5c2d3b90600090a26000825111806103dc5750805b156101c3576103eb8383610260565b50505050565b7f7e644d79422f17c01e4894b5f4f588d331ebfa28653d42ae832dc59e38c9798f61041a61035f565b604080516001600160a01b03928316815291841660208301520160405180910390a1610154816105e9565b6060833b6104a45760405162461bcd60e51b815260206004820152602660248201527f416464726573733a2064656c65676174652063616c6c20746f206e6f6e2d636f6044820152651b9d1c9858dd60d21b6064820152608401610328565b600080856001600160a01b0316856040516104bf9190610794565b600060405180830381855af49150503d80600081146104fa576040519150601f19603f3d011682016040523d82523d6000602084013e6104ff565b606091505b509150915061050f828286610675565b9695505050505050565b60007f360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc610383565b803b6105a55760405162461bcd60e51b815260206004820152602d60248201527f455243313936373a206e657720696d706c656d656e746174696f6e206973206e60448201526c1bdd08184818dbdb9d1c9858dd609a1b6064820152608401610328565b807f360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc5b80546001600160a01b0319166001600160a01b039290921691909117905550565b6001600160a01b03811661064e5760405162461bcd60e51b815260206004820152602660248201527f455243313936373a206e65772061646d696e20697320746865207a65726f206160448201526564647265737360d01b6064820152608401610328565b807fb53127684a568b3173ae13b9f8a6016e243e63b6e8ee1178d6a717850b5d61036105c8565b60608315610684575081610285565b8251156106945782518084602001fd5b8160405162461bcd60e51b815260040161032891906107b0565b80356001600160a01b03811681146106c557600080fd5b919050565b6000602082840312156106dc57600080fd5b610285826106ae565b6000806000604084860312156106fa57600080fd5b610703846106ae565b9250602084013567ffffffffffffffff8082111561072057600080fd5b818601915086601f83011261073457600080fd5b81358181111561074357600080fd5b87602082850101111561075557600080fd5b6020830194508093505050509250925092565b60005b8381101561078357818101518382015260200161076b565b838111156103eb5750506000910152565b600082516107a6818460208701610768565b9190910192915050565b60208152600082518060208401526107cf816040850160208701610768565b601f01601f1916919091016040019291505056fe416464726573733a206c6f772d6c6576656c2064656c65676174652063616c6c206661696c6564a26469706673582212204675187caf3a43285d9a2c1844a981e977bd52a85ff073e7fc649f73847d70a464736f6c63430008090033"); pub const GLOBAL_EXIT_ROOT_CONTRACT_CODE_HASH: [u8; 32] = From 0e3419b120264274df94144cf3a7e4da4f9395f8 Mon Sep 17 00:00:00 2001 From: Robin Salen Date: Wed, 4 Sep 2024 13:58:30 -0400 Subject: [PATCH 02/17] Tweak --- evm_arithmetization/src/cpu/kernel/aggregator.rs | 9 +++++++-- evm_arithmetization/src/cpu/kernel/asm/beacon_roots.asm | 3 +-- .../src/cpu/kernel/asm/cdk_pre_execution.asm | 9 +-------- 3 files changed, 9 insertions(+), 12 deletions(-) diff --git a/evm_arithmetization/src/cpu/kernel/aggregator.rs b/evm_arithmetization/src/cpu/kernel/aggregator.rs index 16e3a3450..27054ac37 100644 --- a/evm_arithmetization/src/cpu/kernel/aggregator.rs +++ b/evm_arithmetization/src/cpu/kernel/aggregator.rs @@ -9,7 +9,11 @@ use super::assembler::{assemble, Kernel}; use crate::cpu::kernel::constants::evm_constants; use crate::cpu::kernel::parser::parse; -pub const NUMBER_KERNEL_FILES: usize = 159; +pub const NUMBER_KERNEL_FILES: usize = if cfg!(feature = "cdk_erigon") { + 159 +} else { + 158 +}; pub static KERNEL_FILES: [&str; NUMBER_KERNEL_FILES] = [ "global jumped_to_0: PANIC", @@ -172,7 +176,8 @@ pub static KERNEL_FILES: [&str; NUMBER_KERNEL_FILES] = [ include_str!("asm/account_code.asm"), include_str!("asm/balance.asm"), include_str!("asm/bloom_filter.asm"), - include_str!("asm/global_exit_root.asm"), + #[cfg(feature = "cdk_erigon")] + include_str!("asm/cdk_pre_execution.asm"), ]; pub static KERNEL: Lazy = Lazy::new(combined_kernel); diff --git a/evm_arithmetization/src/cpu/kernel/asm/beacon_roots.asm b/evm_arithmetization/src/cpu/kernel/asm/beacon_roots.asm index e3607af8b..5b6b09278 100644 --- a/evm_arithmetization/src/cpu/kernel/asm/beacon_roots.asm +++ b/evm_arithmetization/src/cpu/kernel/asm/beacon_roots.asm @@ -4,12 +4,11 @@ /// *NOTE*: This will panic if one of the provided timestamps is zero. global set_beacon_root: - // TODO(Robin): Add conditional neg feature #[cfg(feature = cdk_erigon)] { PUSH pre_block_execution } - #[cfg(feature = not_cdk_erigon)] + #[cfg(not(feature = cdk_erigon))] { PUSH start_txn } diff --git a/evm_arithmetization/src/cpu/kernel/asm/cdk_pre_execution.asm b/evm_arithmetization/src/cpu/kernel/asm/cdk_pre_execution.asm index 6221b72db..bb1207788 100644 --- a/evm_arithmetization/src/cpu/kernel/asm/cdk_pre_execution.asm +++ b/evm_arithmetization/src/cpu/kernel/asm/cdk_pre_execution.asm @@ -11,14 +11,6 @@ // gerUpdates *[]dstypes.GerUpdate, // reUsedL1InfoTreeIndex bool, // ) { -// if !sdb.Exist(ADDRESS_SCALABLE_L2) { -// // create account if not exists -// sdb.CreateAccount(ADDRESS_SCALABLE_L2, true) -// } - -// //save block number -// sdb.scalableSetBlockNum(blockNumber) -// emptyHash := libcommon.Hash{} // //ETROG // if chainConfig.IsForkID7Etrog(blockNumber) { @@ -80,6 +72,7 @@ global update_scalable_l1_blockhash: JUMP global update_scalable_timestamp: + // stack: retdest %timestamp PUSH @TIMESTAMP_STORAGE_POS // stack: timestamp_slot, timestamp, retdest From 416130d561cfe2c7f3ce27ae5b4051f0d0e936e4 Mon Sep 17 00:00:00 2001 From: Robin Salen Date: Wed, 4 Sep 2024 18:33:05 -0400 Subject: [PATCH 03/17] Final tweaks and test --- .../benches/fibonacci_25m_gas.rs | 9 +-- .../src/cpu/kernel/asm/beacon_roots.asm | 2 +- .../src/cpu/kernel/asm/cdk_pre_execution.asm | 69 ++++++++++--------- .../src/cpu/kernel/constants/mod.rs | 34 +++++++-- .../src/cpu/kernel/interpreter.rs | 4 +- .../src/cpu/kernel/tests/add11.rs | 19 +---- .../src/cpu/kernel/tests/init_exc_stop.rs | 45 +++++------- evm_arithmetization/src/generation/mod.rs | 9 ++- .../src/generation/prover_input.rs | 4 +- evm_arithmetization/src/generation/state.rs | 23 +++---- evm_arithmetization/src/testing_utils.rs | 68 +++++++++++++----- evm_arithmetization/tests/add11_yml.rs | 13 +--- evm_arithmetization/tests/erc20.rs | 9 +-- evm_arithmetization/tests/erc721.rs | 10 +-- evm_arithmetization/tests/global_exit_root.rs | 42 ++++++++--- evm_arithmetization/tests/log_opcode.rs | 11 +-- evm_arithmetization/tests/selfdestruct.rs | 11 +-- evm_arithmetization/tests/simple_transfer.rs | 11 +-- evm_arithmetization/tests/two_to_one_block.rs | 12 +--- evm_arithmetization/tests/withdrawals.rs | 11 +-- trace_decoder/src/decoding.rs | 2 +- 21 files changed, 207 insertions(+), 211 deletions(-) diff --git a/evm_arithmetization/benches/fibonacci_25m_gas.rs b/evm_arithmetization/benches/fibonacci_25m_gas.rs index 21702d2d1..28c9a2333 100644 --- a/evm_arithmetization/benches/fibonacci_25m_gas.rs +++ b/evm_arithmetization/benches/fibonacci_25m_gas.rs @@ -17,9 +17,8 @@ use evm_arithmetization::generation::{GenerationInputs, TrieInputs}; use evm_arithmetization::proof::{BlockHashes, BlockMetadata, TrieRoots}; use evm_arithmetization::prover::testing::simulate_execution; use evm_arithmetization::testing_utils::{ - beacon_roots_account_nibbles, beacon_roots_contract_from_storage, ger_account_nibbles, + beacon_roots_account_nibbles, beacon_roots_contract_from_storage, preinitialized_state_and_storage_tries, update_beacon_roots_account_storage, - GLOBAL_EXIT_ROOT_ACCOUNT, }; use evm_arithmetization::Node; use hex_literal::hex; @@ -148,10 +147,6 @@ fn prepare_setup() -> anyhow::Result { beacon_roots_account_nibbles(), rlp::encode(&beacon_roots_account).to_vec(), )?; - expected_state_trie_after.insert( - ger_account_nibbles(), - rlp::encode(&GLOBAL_EXIT_ROOT_ACCOUNT).to_vec(), - )?; let receipt_0 = LegacyReceiptRlp { status: false, @@ -186,7 +181,7 @@ fn prepare_setup() -> anyhow::Result { checkpoint_state_trie_root: H256(hex!( "fe07ff6d1ab215df17884b89112ccf2373597285a56c5902150313ad1a53ee57" )), - global_exit_roots: vec![], + ger_data: None, block_metadata, txn_number_before: 0.into(), gas_used_before: 0.into(), diff --git a/evm_arithmetization/src/cpu/kernel/asm/beacon_roots.asm b/evm_arithmetization/src/cpu/kernel/asm/beacon_roots.asm index 5b6b09278..36f491fb5 100644 --- a/evm_arithmetization/src/cpu/kernel/asm/beacon_roots.asm +++ b/evm_arithmetization/src/cpu/kernel/asm/beacon_roots.asm @@ -10,7 +10,7 @@ global set_beacon_root: } #[cfg(not(feature = cdk_erigon))] { - PUSH start_txn + PUSH txn_loop } %timestamp diff --git a/evm_arithmetization/src/cpu/kernel/asm/cdk_pre_execution.asm b/evm_arithmetization/src/cpu/kernel/asm/cdk_pre_execution.asm index bb1207788..37034c1df 100644 --- a/evm_arithmetization/src/cpu/kernel/asm/cdk_pre_execution.asm +++ b/evm_arithmetization/src/cpu/kernel/asm/cdk_pre_execution.asm @@ -2,40 +2,11 @@ /// Reference implementation: `cdk-erigon/core/state/intra_block_state_zkevm.go`. /// This currently supports the Etrog upgrade. -// TODO(Robin): Remove code template -// func (sdb *IntraBlockState) SyncerPreExecuteStateSet( -// chainConfig *chain.Config, -// blockNumber uint64, -// blockTimestamp uint64, -// prevBlockHash, blockGer, l1BlockHash *libcommon.Hash, -// gerUpdates *[]dstypes.GerUpdate, -// reUsedL1InfoTreeIndex bool, -// ) { - -// //ETROG -// if chainConfig.IsForkID7Etrog(blockNumber) { -// currentTimestamp := sdb.ScalableGetTimestamp() -// if blockTimestamp > currentTimestamp { -// sdb.ScalableSetTimestamp(blockTimestamp) -// } - -// //save prev block hash -// sdb.scalableSetBlockHash(blockNumber-1, prevBlockHash) - -// //save ger with l1blockhash - but only in the case that the l1 info tree index hasn't been -// // re-used. If it has been re-used we never write this to the contract storage -// if !reUsedL1InfoTreeIndex && blockGer != nil && *blockGer != emptyHash { -// sdb.WriteGerManagerL1BlockHash(*blockGer, *l1BlockHash) -// } -// } -// } - - /// Pre-stack: (empty) /// Post-stack: (empty) global pre_block_execution: // stack: (empty) - PUSH start_txn + PUSH txn_loop // stack: retdest PUSH @ADDRESS_SCALABLE_L2_STATE_KEY %is_non_existent @@ -61,14 +32,44 @@ global update_scalable_prev_block_root_hash: // stack: retdest %mload_global_metadata(@GLOBAL_METADATA_STATE_TRIE_DIGEST_BEFORE) // stack: prev_block_root, retdest - PUSH 1 %block_number SUB + PUSH 1 %blocknumber SUB // stack: block_number - 1, prev_block_root, retdest %write_scalable_storage // stack: retdest -global update_scalable_l1_blockhash: +global update_scalable_l1blockhash: + // stack: retdest + PROVER_INPUT(ger) + // stack: l1blockhash?, retdest + DUP1 %eq_const(@U256_MAX) %jumpi(skip_and_exit) + // stack: l1blockhash, retdest + PUSH @GLOBAL_EXIT_ROOT_STORAGE_POS + PROVER_INPUT(ger) + // stack: root, GLOBAL_EXIT_ROOT_STORAGE_POS, l1blockhash, retdest + PUSH @SEGMENT_KERNEL_GENERAL + // stack: addr, root, GLOBAL_EXIT_ROOT_STORAGE_POS, l1blockhash, retdest + MSTORE_32BYTES_32 + // stack: addr, GLOBAL_EXIT_ROOT_STORAGE_POS, l1blockhash, retdest + MSTORE_32BYTES_32 + // stack: addr, l1blockhash, retdest + POP + // stack: l1blockhash, retdest + PUSH 64 PUSH @SEGMENT_KERNEL_GENERAL + // stack: addr, len, l1blockhash, retdest + KECCAK_GENERAL + // stack: slot, l1blockhash, retdest + %slot_to_storage_key + // stack: slot, 1blockhash, retdest + // stack: storage_key, 1blockhash, retdest + PUSH @GLOBAL_EXIT_ROOT_MANAGER_L2_STATE_KEY + // stack: state_key, storage_key, 1blockhash, retdest + %insert_slot_with_value_from_keys // stack: retdest - // TODO(RObin): FINISH + JUMP + +skip_and_exit: + // stack: null, retdest + POP JUMP global update_scalable_timestamp: @@ -90,7 +91,7 @@ global create_scalable_l2_account: PUSH 0 %append_to_trie_data // storage root pointer PUSH @EMPTY_STRING_HASH %append_to_trie_data // code hash // stack: new_account_ptr, retdest - PUSH @L2ADDRESS_SCALABLE_L2_STATE_KEY + PUSH @ADDRESS_SCALABLE_L2_STATE_KEY // stack: key, new_account_ptr, retdest %jump(mpt_insert_state_trie) diff --git a/evm_arithmetization/src/cpu/kernel/constants/mod.rs b/evm_arithmetization/src/cpu/kernel/constants/mod.rs index 9d7c40219..1c076040a 100644 --- a/evm_arithmetization/src/cpu/kernel/constants/mod.rs +++ b/evm_arithmetization/src/cpu/kernel/constants/mod.rs @@ -417,11 +417,11 @@ pub mod cancun_constants { hex!("000000000000000000000000000000001666c54b0a32529503432fcae0181b4bef79de09fc63671fda5ed1ba9bfa07899495346f3d7ac9cd23048ef30d0a154f"), // y_im ]; - pub const HISTORY_BUFFER_LENGTH: (&str, u64) = ("HISTORY_BUFFER_LENGTH", 8191); - // Beacon constants /////////////////// + pub const HISTORY_BUFFER_LENGTH: (&str, u64) = ("HISTORY_BUFFER_LENGTH", 8191); + pub const BEACON_ROOTS_CONTRACT_ADDRESS: Address = H160(hex!("000F3df6D732807Ef1319fB7B8bB8522d0Beac02")); @@ -460,18 +460,28 @@ pub mod global_exit_root { use super::*; /// Taken from https://github.com/0xPolygonHermez/cdk-erigon/blob/61f0b6912055c73f6879ea7e9b5bac22ea5fc85c/zk/utils/global_exit_root.go#L16. - pub const GLOBAL_EXIT_ROOT_MANAGER_L2_STATE_KEY: (&str, [u8; 20]) = ( - "GLOBAL_EXIT_ROOT_MANAGER_L2_STATE_KEY", + pub const GLOBAL_EXIT_ROOT_MANAGER_L2: (&str, [u8; 20]) = ( + "GLOBAL_EXIT_ROOT_MANAGER_L2", hex!("a40D5f56745a118D0906a34E69aeC8C0Db1cB8fA"), ); + pub const GLOBAL_EXIT_ROOT_ADDRESS_HASHED: H256 = H256(hex!( + "1d5e9c22b4b1a781d0ef63e9c1293c2a45fee966809019aa9804b5e7148b0ca9" + )); + pub const GLOBAL_EXIT_ROOT_MANAGER_L2_STATE_KEY: (&str, [u8; 32]) = ( + "GLOBAL_EXIT_ROOT_MANAGER_L2_STATE_KEY", + GLOBAL_EXIT_ROOT_ADDRESS_HASHED.to_fixed_bytes(), + ); /// Taken from https://github.com/0xPolygonHermez/cdk-erigon/blob/dc3cbcc59a95769626056c7bc70aade501e7741d/core/state/intra_block_state_zkevm.go#L20. pub const ADDRESS_SCALABLE_L2: (&str, [u8; 20]) = ( "ADDRESS_SCALABLE_L2", hex!("000000000000000000000000000000005ca1ab1e"), ); + pub const ADDRESS_SCALABLE_L2_ADDRESS_HASHED: H256 = H256(hex!( + "4bff39c4f33dafcd90c45c9a0a1f2e72949b200788587b306eda5dd84aa87577" + )); pub const ADDRESS_SCALABLE_L2_STATE_KEY: (&str, [u8; 32]) = ( "ADDRESS_SCALABLE_L2_STATE_KEY", - hex!("4bff39c4f33dafcd90c45c9a0a1f2e72949b200788587b306eda5dd84aa87577"), + ADDRESS_SCALABLE_L2_ADDRESS_HASHED.to_fixed_bytes(), ); /// Taken from https://github.com/0xPolygonHermez/cdk-erigon/blob/61f0b6912055c73f6879ea7e9b5bac22ea5fc85c/zk/utils/global_exit_root.go#L17. pub const GLOBAL_EXIT_ROOT_STORAGE_POS: (&str, u64) = ("GLOBAL_EXIT_ROOT_STORAGE_POS", 0); @@ -486,8 +496,6 @@ pub mod global_exit_root { pub const GLOBAL_EXIT_ROOT_CONTRACT_CODE: [u8; 2112] = hex!("60806040526004361061004e5760003560e01c80633659cfe6146100655780634f1ef286146100855780635c60da1b146100985780638f283970146100c9578063f851a440146100e95761005d565b3661005d5761005b6100fe565b005b61005b6100fe565b34801561007157600080fd5b5061005b6100803660046106ca565b610118565b61005b6100933660046106e5565b61015f565b3480156100a457600080fd5b506100ad6101d0565b6040516001600160a01b03909116815260200160405180910390f35b3480156100d557600080fd5b5061005b6100e43660046106ca565b61020b565b3480156100f557600080fd5b506100ad610235565b610106610292565b610116610111610331565b61033b565b565b61012061035f565b6001600160a01b0316336001600160a01b031614156101575761015481604051806020016040528060008152506000610392565b50565b6101546100fe565b61016761035f565b6001600160a01b0316336001600160a01b031614156101c8576101c38383838080601f01602080910402602001604051908101604052809392919081815260200183838082843760009201919091525060019250610392915050565b505050565b6101c36100fe565b60006101da61035f565b6001600160a01b0316336001600160a01b03161415610200576101fb610331565b905090565b6102086100fe565b90565b61021361035f565b6001600160a01b0316336001600160a01b0316141561015757610154816103f1565b600061023f61035f565b6001600160a01b0316336001600160a01b03161415610200576101fb61035f565b606061028583836040518060600160405280602781526020016107e460279139610445565b9392505050565b3b151590565b61029a61035f565b6001600160a01b0316336001600160a01b031614156101165760405162461bcd60e51b815260206004820152604260248201527f5472616e73706172656e745570677261646561626c6550726f78793a2061646d60448201527f696e2063616e6e6f742066616c6c6261636b20746f2070726f78792074617267606482015261195d60f21b608482015260a4015b60405180910390fd5b60006101fb610519565b3660008037600080366000845af43d6000803e80801561035a573d6000f35b3d6000fd5b60007fb53127684a568b3173ae13b9f8a6016e243e63b6e8ee1178d6a717850b5d61035b546001600160a01b0316919050565b61039b83610541565b6040516001600160a01b038416907fbc7cd75a20ee27fd9adebab32041f755214dbc6bffa90cc0225b39da2e5c2d3b90600090a26000825111806103dc5750805b156101c3576103eb8383610260565b50505050565b7f7e644d79422f17c01e4894b5f4f588d331ebfa28653d42ae832dc59e38c9798f61041a61035f565b604080516001600160a01b03928316815291841660208301520160405180910390a1610154816105e9565b6060833b6104a45760405162461bcd60e51b815260206004820152602660248201527f416464726573733a2064656c65676174652063616c6c20746f206e6f6e2d636f6044820152651b9d1c9858dd60d21b6064820152608401610328565b600080856001600160a01b0316856040516104bf9190610794565b600060405180830381855af49150503d80600081146104fa576040519150601f19603f3d011682016040523d82523d6000602084013e6104ff565b606091505b509150915061050f828286610675565b9695505050505050565b60007f360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc610383565b803b6105a55760405162461bcd60e51b815260206004820152602d60248201527f455243313936373a206e657720696d706c656d656e746174696f6e206973206e60448201526c1bdd08184818dbdb9d1c9858dd609a1b6064820152608401610328565b807f360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc5b80546001600160a01b0319166001600160a01b039290921691909117905550565b6001600160a01b03811661064e5760405162461bcd60e51b815260206004820152602660248201527f455243313936373a206e65772061646d696e20697320746865207a65726f206160448201526564647265737360d01b6064820152608401610328565b807fb53127684a568b3173ae13b9f8a6016e243e63b6e8ee1178d6a717850b5d61036105c8565b60608315610684575081610285565b8251156106945782518084602001fd5b8160405162461bcd60e51b815260040161032891906107b0565b80356001600160a01b03811681146106c557600080fd5b919050565b6000602082840312156106dc57600080fd5b610285826106ae565b6000806000604084860312156106fa57600080fd5b610703846106ae565b9250602084013567ffffffffffffffff8082111561072057600080fd5b818601915086601f83011261073457600080fd5b81358181111561074357600080fd5b87602082850101111561075557600080fd5b6020830194508093505050509250925092565b60005b8381101561078357818101518382015260200161076b565b838111156103eb5750506000910152565b600082516107a6818460208701610768565b9190910192915050565b60208152600082518060208401526107cf816040850160208701610768565b601f01601f1916919091016040019291505056fe416464726573733a206c6f772d6c6576656c2064656c65676174652063616c6c206661696c6564a26469706673582212204675187caf3a43285d9a2c1844a981e977bd52a85ff073e7fc649f73847d70a464736f6c63430008090033"); pub const GLOBAL_EXIT_ROOT_CONTRACT_CODE_HASH: [u8; 32] = hex!("6bec2bf64f7e824109f6ed55f77dd7665801d6195e461666ad6a5342a9f6daf5"); - pub const GLOBAL_EXIT_ROOT_ADDRESS_HASHED: [u8; 32] = - hex!("1d5e9c22b4b1a781d0ef63e9c1293c2a45fee966809019aa9804b5e7148b0ca9"); pub const GLOBAL_EXIT_ROOT_ACCOUNT: AccountRlp = AccountRlp { nonce: U256::zero(), @@ -498,4 +506,16 @@ pub mod global_exit_root { )), code_hash: H256(GLOBAL_EXIT_ROOT_CONTRACT_CODE_HASH), }; + + #[test] + fn hashed() { + assert_eq!( + keccak_hash::keccak(GLOBAL_EXIT_ROOT_MANAGER_L2.1), + GLOBAL_EXIT_ROOT_ADDRESS_HASHED + ); + assert_eq!( + keccak_hash::keccak(ADDRESS_SCALABLE_L2.1), + ADDRESS_SCALABLE_L2_ADDRESS_HASHED + ); + } } diff --git a/evm_arithmetization/src/cpu/kernel/interpreter.rs b/evm_arithmetization/src/cpu/kernel/interpreter.rs index f6e9b67ed..23b4507f0 100644 --- a/evm_arithmetization/src/cpu/kernel/interpreter.rs +++ b/evm_arithmetization/src/cpu/kernel/interpreter.rs @@ -22,7 +22,7 @@ use crate::generation::debug_inputs; use crate::generation::mpt::{load_linked_lists_and_txn_and_receipt_mpts, TrieRootPtrs}; use crate::generation::rlp::all_rlp_prover_inputs_reversed; use crate::generation::state::{ - all_ger_prover_inputs_reversed, all_withdrawals_prover_inputs_reversed, GenerationState, + all_ger_prover_inputs, all_withdrawals_prover_inputs_reversed, GenerationState, GenerationStateCheckpoint, }; use crate::generation::{state::State, GenerationInputs}; @@ -256,7 +256,7 @@ impl Interpreter { // Update the RLP and withdrawal prover inputs. let rlp_prover_inputs = all_rlp_prover_inputs_reversed(&inputs.signed_txns); let withdrawal_prover_inputs = all_withdrawals_prover_inputs_reversed(&inputs.withdrawals); - let ger_prover_inputs = all_ger_prover_inputs_reversed(&inputs.global_exit_roots); + let ger_prover_inputs = all_ger_prover_inputs(inputs.ger_data); self.generation_state.rlp_prover_inputs = rlp_prover_inputs; self.generation_state.withdrawal_prover_inputs = withdrawal_prover_inputs; self.generation_state.ger_prover_inputs = ger_prover_inputs; diff --git a/evm_arithmetization/src/cpu/kernel/tests/add11.rs b/evm_arithmetization/src/cpu/kernel/tests/add11.rs index 1840bbc07..6f4ec1ec9 100644 --- a/evm_arithmetization/src/cpu/kernel/tests/add11.rs +++ b/evm_arithmetization/src/cpu/kernel/tests/add11.rs @@ -14,9 +14,8 @@ use crate::generation::mpt::{AccountRlp, LegacyReceiptRlp}; 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, + beacon_roots_account_nibbles, beacon_roots_contract_from_storage, preinitialized_state_and_storage_tries, update_beacon_roots_account_storage, - GLOBAL_EXIT_ROOT_ACCOUNT, }; use crate::GenerationInputs; @@ -147,12 +146,6 @@ fn test_add11_yml() { ) .unwrap(); expected_state_trie_after - .insert( - ger_account_nibbles(), - rlp::encode(&GLOBAL_EXIT_ROOT_ACCOUNT).to_vec(), - ) - .unwrap(); - expected_state_trie_after }; let receipt_0 = LegacyReceiptRlp { status: true, @@ -183,7 +176,7 @@ fn test_add11_yml() { signed_txns: vec![txn.to_vec()], burn_addr: None, withdrawals: vec![], - global_exit_roots: vec![], + ger_data: None, tries: tries_before, trie_roots_after, contract_code: contract_code.clone(), @@ -328,12 +321,6 @@ fn test_add11_yml_with_exception() { ) .unwrap(); expected_state_trie_after - .insert( - ger_account_nibbles(), - rlp::encode(&GLOBAL_EXIT_ROOT_ACCOUNT).to_vec(), - ) - .unwrap(); - expected_state_trie_after }; let receipt_0 = LegacyReceiptRlp { @@ -365,7 +352,7 @@ fn test_add11_yml_with_exception() { signed_txns: vec![txn.to_vec()], burn_addr: None, withdrawals: vec![], - global_exit_roots: vec![], + ger_data: None, tries: tries_before, trie_roots_after, contract_code: contract_code.clone(), diff --git a/evm_arithmetization/src/cpu/kernel/tests/init_exc_stop.rs b/evm_arithmetization/src/cpu/kernel/tests/init_exc_stop.rs index 7e7e6851d..57ad232cb 100644 --- a/evm_arithmetization/src/cpu/kernel/tests/init_exc_stop.rs +++ b/evm_arithmetization/src/cpu/kernel/tests/init_exc_stop.rs @@ -1,31 +1,24 @@ use std::collections::HashMap; use ethereum_types::U256; -use keccak_hash::keccak; -use keccak_hash::H256; -use mpt_trie::partial_trie::HashedPartialTrie; -use mpt_trie::partial_trie::PartialTrie; +use keccak_hash::{keccak, H256}; +use mpt_trie::partial_trie::{HashedPartialTrie, PartialTrie}; use plonky2::field::goldilocks_field::GoldilocksField as F; -use crate::cpu::kernel::aggregator::KERNEL; -use crate::cpu::kernel::interpreter::Interpreter; -use crate::generation::state::State; -use crate::generation::TrieInputs; -use crate::generation::NUM_EXTRA_CYCLES_AFTER; -use crate::generation::NUM_EXTRA_CYCLES_BEFORE; +use crate::cpu::kernel::{aggregator::KERNEL, interpreter::Interpreter}; +use crate::generation::{ + state::State, TrieInputs, NUM_EXTRA_CYCLES_AFTER, NUM_EXTRA_CYCLES_BEFORE, +}; use crate::memory::segments::Segment; -use crate::proof::BlockMetadata; -use crate::proof::TrieRoots; -use crate::testing_utils::beacon_roots_account_nibbles; -use crate::testing_utils::beacon_roots_contract_from_storage; -use crate::testing_utils::ger_account_nibbles; -use crate::testing_utils::init_logger; -use crate::testing_utils::preinitialized_state_and_storage_tries; -use crate::testing_utils::update_beacon_roots_account_storage; -use crate::testing_utils::GLOBAL_EXIT_ROOT_ACCOUNT; -use crate::witness::memory::MemoryAddress; -use crate::witness::state::RegistersState; -use crate::{proof::BlockHashes, GenerationInputs, Node}; +use crate::testing_utils::{ + beacon_roots_account_nibbles, beacon_roots_contract_from_storage, init_logger, + preinitialized_state_and_storage_tries, update_beacon_roots_account_storage, +}; +use crate::witness::{memory::MemoryAddress, state::RegistersState}; +use crate::{ + proof::{BlockHashes, BlockMetadata, TrieRoots}, + GenerationInputs, Node, +}; enum RegistersIdx { ProgramCounter = 0, @@ -72,12 +65,6 @@ fn test_init_exc_stop() { ) .unwrap(); expected_state_trie_after - .insert( - ger_account_nibbles(), - rlp::encode(&GLOBAL_EXIT_ROOT_ACCOUNT).to_vec(), - ) - .unwrap(); - expected_state_trie_after }; let mut contract_code = HashMap::new(); @@ -110,7 +97,7 @@ fn test_init_exc_stop() { prev_hashes: vec![H256::default(); 256], cur_hash: H256::default(), }, - global_exit_roots: vec![], + ger_data: None, }; let initial_stack = vec![]; let initial_offset = KERNEL.global_labels["init"]; diff --git a/evm_arithmetization/src/generation/mod.rs b/evm_arithmetization/src/generation/mod.rs index d1bbfbad5..f9b3bb39a 100644 --- a/evm_arithmetization/src/generation/mod.rs +++ b/evm_arithmetization/src/generation/mod.rs @@ -77,8 +77,7 @@ pub struct GenerationInputs { /// 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)>, - /// Global exit roots pairs `(timestamp, root)`. - pub global_exit_roots: Vec<(U256, H256)>, + pub tries: TrieInputs, /// Expected trie roots after the transactions are executed. pub trie_roots_after: TrieRoots, @@ -99,6 +98,12 @@ pub struct GenerationInputs { /// The hash of the current block, and a list of the 256 previous block /// hashes. pub block_hashes: BlockHashes, + + /// The the global exit root along with the l1blockhash to write to the GER + /// manager. + /// + /// This is specific to `cdk-erigon`. + pub ger_data: Option<(H256, H256)>, } /// A lighter version of [`GenerationInputs`], which have been trimmed diff --git a/evm_arithmetization/src/generation/prover_input.rs b/evm_arithmetization/src/generation/prover_input.rs index 601e1c525..1b22f2026 100644 --- a/evm_arithmetization/src/generation/prover_input.rs +++ b/evm_arithmetization/src/generation/prover_input.rs @@ -70,7 +70,7 @@ impl GenerationState { "jumpdest_table" => self.run_jumpdest_table(input_fn), "access_lists" => self.run_access_lists(input_fn), "linked_list" => self.run_linked_list(input_fn), - "ger" => self.run_global_exit_roots(), + "ger" => self.run_global_exit_root(), "kzg_point_eval" => self.run_kzg_point_eval(), "kzg_point_eval_2" => self.run_kzg_point_eval_2(), _ => Err(ProgramError::ProverInputError(InvalidFunction)), @@ -372,7 +372,7 @@ impl GenerationState { } } - fn run_global_exit_roots(&mut self) -> Result { + fn run_global_exit_root(&mut self) -> Result { self.ger_prover_inputs .pop() .ok_or(ProgramError::ProverInputError(OutOfGerData)) diff --git a/evm_arithmetization/src/generation/state.rs b/evm_arithmetization/src/generation/state.rs index 96865806a..de0031366 100644 --- a/evm_arithmetization/src/generation/state.rs +++ b/evm_arithmetization/src/generation/state.rs @@ -400,7 +400,7 @@ impl GenerationState { pub(crate) fn new(inputs: &GenerationInputs, kernel_code: &[u8]) -> Result { let rlp_prover_inputs = all_rlp_prover_inputs_reversed(&inputs.signed_txns); let withdrawal_prover_inputs = all_withdrawals_prover_inputs_reversed(&inputs.withdrawals); - let ger_prover_inputs = all_ger_prover_inputs_reversed(&inputs.global_exit_roots); + let ger_prover_inputs = all_ger_prover_inputs(inputs.ger_data); let bignum_modmul_result_limbs = Vec::new(); let mut state = Self { @@ -412,7 +412,6 @@ impl GenerationState { stale_contexts: Vec::new(), rlp_prover_inputs, withdrawal_prover_inputs, - ger_prover_inputs, state_key_to_address: HashMap::new(), bignum_modmul_result_limbs, trie_root_ptrs: TrieRootPtrs { @@ -421,6 +420,7 @@ impl GenerationState { receipt_root_ptr: 0, }, jumpdest_table: None, + ger_prover_inputs, }; let trie_root_ptrs = state.preinitialize_linked_lists_and_txn_and_receipt_mpts(&inputs.tries); @@ -738,15 +738,12 @@ pub(crate) fn all_withdrawals_prover_inputs_reversed(withdrawals: &[(Address, U2 withdrawal_prover_inputs } -/// Global exit roots prover input array is of the form `[N, timestamp1, -/// root1,..., timestampN, rootN]`. Returns the reversed array. -pub(crate) fn all_ger_prover_inputs_reversed(global_exit_roots: &[(U256, H256)]) -> Vec { - let mut ger_prover_inputs = vec![global_exit_roots.len().into()]; - ger_prover_inputs.extend( - global_exit_roots - .iter() - .flat_map(|ger| [ger.0, ger.1.into_uint()]), - ); - ger_prover_inputs.reverse(); - ger_prover_inputs +/// Global exit root prover input tuple containing the global exit root and its +/// associated l1blockhash. +pub(crate) fn all_ger_prover_inputs(ger_data: Option<(H256, H256)>) -> Vec { + if ger_data.is_none() { + return vec![U256::MAX]; + } + let (root, l1blockhash) = ger_data.unwrap(); + vec![root.into_uint(), l1blockhash.into_uint()] } diff --git a/evm_arithmetization/src/testing_utils.rs b/evm_arithmetization/src/testing_utils.rs index 4ad47b65f..4152da5b6 100644 --- a/evm_arithmetization/src/testing_utils.rs +++ b/evm_arithmetization/src/testing_utils.rs @@ -11,10 +11,8 @@ use mpt_trie::{ }; pub use crate::cpu::kernel::cancun_constants::*; -pub use crate::cpu::kernel::constants::global_exit_root::{ - GLOBAL_EXIT_ROOT_ACCOUNT, GLOBAL_EXIT_ROOT_ADDRESS_HASHED, GLOBAL_EXIT_ROOT_STORAGE_POS, -}; -use crate::{generation::mpt::AccountRlp, util::h2u}; +pub use crate::cpu::kernel::constants::global_exit_root::*; +use crate::{generation::mpt::AccountRlp, proof::BlockMetadata, util::h2u}; pub const EMPTY_NODE_HASH: H256 = H256(hex!( "56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421" @@ -90,15 +88,8 @@ pub fn preinitialized_state_and_storage_tries( beacon_roots_account_nibbles(), rlp::encode(&BEACON_ROOTS_ACCOUNT).to_vec(), )?; - state_trie.insert( - ger_account_nibbles(), - rlp::encode(&GLOBAL_EXIT_ROOT_ACCOUNT).to_vec(), - )?; - let storage_tries = vec![ - (BEACON_ROOTS_CONTRACT_ADDRESS_HASHED, Node::Empty.into()), - (H256(GLOBAL_EXIT_ROOT_ADDRESS_HASHED), Node::Empty.into()), - ]; + let storage_tries = vec![(BEACON_ROOTS_CONTRACT_ADDRESS_HASHED, Node::Empty.into())]; Ok((state_trie, storage_tries)) } @@ -108,21 +99,53 @@ pub fn beacon_roots_account_nibbles() -> Nibbles { Nibbles::from_bytes_be(BEACON_ROOTS_CONTRACT_ADDRESS_HASHED.as_bytes()).unwrap() } -/// Returns the `Nibbles` corresponding to the beacon roots contract account. +/// Returns the `Nibbles` corresponding to the GER manager account. pub fn ger_account_nibbles() -> Nibbles { - Nibbles::from_bytes_be(&GLOBAL_EXIT_ROOT_ADDRESS_HASHED).unwrap() + Nibbles::from_bytes_be(GLOBAL_EXIT_ROOT_ADDRESS_HASHED.as_bytes()).unwrap() } pub fn update_ger_account_storage( storage_trie: &mut HashedPartialTrie, - root: H256, - timestamp: U256, + ger_data: Option<(H256, H256)>, +) -> anyhow::Result<()> { + if let Some((root, l1blockhash)) = ger_data { + let mut arr = [0; 64]; + arr[0..32].copy_from_slice(&root.0); + U256::from(GLOBAL_EXIT_ROOT_STORAGE_POS.1).to_big_endian(&mut arr[32..64]); + let slot = keccak(arr); + insert_storage(storage_trie, slot.into_uint(), h2u(l1blockhash))? + } + + Ok(()) +} + +/// Returns the `Nibbles` corresponding to the 5ca1ab1e contract account. +pub fn scalable_account_nibbles() -> Nibbles { + Nibbles::from_bytes_be(ADDRESS_SCALABLE_L2_ADDRESS_HASHED.as_bytes()).unwrap() +} + +/// Note: This *will* overwrite the timestamp stored at the contract address. +pub fn update_scalable_account_storage( + storage_trie: &mut HashedPartialTrie, + block: &BlockMetadata, + initial_trie_hash: H256, ) -> anyhow::Result<()> { + insert_storage( + storage_trie, + U256::from(LAST_BLOCK_STORAGE_POS.1), + block.block_number, + )?; + insert_storage( + storage_trie, + U256::from(TIMESTAMP_STORAGE_POS.1), + block.block_timestamp, + )?; + let mut arr = [0; 64]; - arr[0..32].copy_from_slice(&root.0); - U256::from(GLOBAL_EXIT_ROOT_STORAGE_POS.1).to_big_endian(&mut arr[32..64]); + (block.block_number - U256::one()).to_big_endian(&mut arr[0..32]); + U256::from(STATE_ROOT_STORAGE_POS.1).to_big_endian(&mut arr[32..64]); let slot = keccak(arr); - insert_storage(storage_trie, slot.into_uint(), timestamp) + insert_storage(storage_trie, slot.into_uint(), h2u(initial_trie_hash)) } pub fn ger_contract_from_storage(storage_trie: &HashedPartialTrie) -> AccountRlp { @@ -132,6 +155,13 @@ pub fn ger_contract_from_storage(storage_trie: &HashedPartialTrie) -> AccountRlp } } +pub fn scalable_contract_from_storage(storage_trie: &HashedPartialTrie) -> AccountRlp { + AccountRlp { + storage_root: storage_trie.hash(), + ..Default::default() + } +} + /// Converts an amount in `ETH` to `wei` units. pub fn eth_to_wei(eth: U256) -> U256 { // 1 ether = 10^18 wei. diff --git a/evm_arithmetization/tests/add11_yml.rs b/evm_arithmetization/tests/add11_yml.rs index ed5eaaa94..1a70d6873 100644 --- a/evm_arithmetization/tests/add11_yml.rs +++ b/evm_arithmetization/tests/add11_yml.rs @@ -8,9 +8,8 @@ use evm_arithmetization::generation::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, - init_logger, preinitialized_state_and_storage_tries, update_beacon_roots_account_storage, - GLOBAL_EXIT_ROOT_ACCOUNT, + beacon_roots_account_nibbles, beacon_roots_contract_from_storage, init_logger, + preinitialized_state_and_storage_tries, update_beacon_roots_account_storage, }; use evm_arithmetization::verifier::testing::verify_all_proofs; use evm_arithmetization::StarkConfig; @@ -152,12 +151,6 @@ fn get_generation_inputs() -> GenerationInputs { ) .unwrap(); expected_state_trie_after - .insert( - ger_account_nibbles(), - rlp::encode(&GLOBAL_EXIT_ROOT_ACCOUNT).to_vec(), - ) - .unwrap(); - expected_state_trie_after }; let receipt_0 = LegacyReceiptRlp { @@ -189,7 +182,7 @@ fn get_generation_inputs() -> GenerationInputs { signed_txns: vec![txn.to_vec()], burn_addr: None, withdrawals: vec![], - global_exit_roots: vec![], + ger_data: None, tries: tries_before, trie_roots_after, contract_code, diff --git a/evm_arithmetization/tests/erc20.rs b/evm_arithmetization/tests/erc20.rs index b9f3d6cf0..acfd6aacc 100644 --- a/evm_arithmetization/tests/erc20.rs +++ b/evm_arithmetization/tests/erc20.rs @@ -8,8 +8,7 @@ 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, create_account_storage, - ger_account_nibbles, init_logger, preinitialized_state_and_storage_tries, sd2u, - update_beacon_roots_account_storage, GLOBAL_EXIT_ROOT_ACCOUNT, + init_logger, preinitialized_state_and_storage_tries, sd2u, update_beacon_roots_account_storage, }; use evm_arithmetization::verifier::testing::verify_all_proofs; use evm_arithmetization::{AllStark, Node, StarkConfig}; @@ -132,10 +131,6 @@ fn test_erc20() -> anyhow::Result<()> { beacon_roots_account_nibbles(), rlp::encode(&beacon_roots_account).to_vec(), )?; - state_trie_after.insert( - ger_account_nibbles(), - rlp::encode(&GLOBAL_EXIT_ROOT_ACCOUNT).to_vec(), - )?; state_trie_after }; @@ -183,7 +178,7 @@ fn test_erc20() -> anyhow::Result<()> { signed_txns: vec![txn.to_vec()], burn_addr: None, withdrawals: vec![], - global_exit_roots: vec![], + ger_data: None, tries: tries_before, trie_roots_after, contract_code, diff --git a/evm_arithmetization/tests/erc721.rs b/evm_arithmetization/tests/erc721.rs index df3099e1f..b7f2a6de6 100644 --- a/evm_arithmetization/tests/erc721.rs +++ b/evm_arithmetization/tests/erc721.rs @@ -8,8 +8,8 @@ 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, create_account_storage, - ger_account_nibbles, init_logger, preinitialized_state_and_storage_tries, sd2u, sh2u, - update_beacon_roots_account_storage, GLOBAL_EXIT_ROOT_ACCOUNT, + init_logger, preinitialized_state_and_storage_tries, sd2u, sh2u, + update_beacon_roots_account_storage, }; use evm_arithmetization::verifier::testing::verify_all_proofs; use evm_arithmetization::{AllStark, Node, StarkConfig}; @@ -154,10 +154,6 @@ fn test_erc721() -> anyhow::Result<()> { beacon_roots_account_nibbles(), rlp::encode(&beacon_roots_account).to_vec(), )?; - state_trie_after.insert( - ger_account_nibbles(), - rlp::encode(&GLOBAL_EXIT_ROOT_ACCOUNT).to_vec(), - )?; state_trie_after }; @@ -186,7 +182,7 @@ fn test_erc721() -> anyhow::Result<()> { signed_txns: vec![txn.to_vec()], burn_addr: None, withdrawals: vec![], - global_exit_roots: vec![], + ger_data: None, tries: tries_before, trie_roots_after, contract_code, diff --git a/evm_arithmetization/tests/global_exit_root.rs b/evm_arithmetization/tests/global_exit_root.rs index 69e45bef4..b108ac1ee 100644 --- a/evm_arithmetization/tests/global_exit_root.rs +++ b/evm_arithmetization/tests/global_exit_root.rs @@ -1,14 +1,18 @@ +#![cfg(feature = "cdk_erigon")] + use std::collections::HashMap; use std::time::Duration; -use ethereum_types::{H256, U256}; +use ethereum_types::H256; 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, - update_beacon_roots_account_storage, update_ger_account_storage, + scalable_account_nibbles, scalable_contract_from_storage, update_beacon_roots_account_storage, + update_ger_account_storage, update_scalable_account_storage, + ADDRESS_SCALABLE_L2_ADDRESS_HASHED, GLOBAL_EXIT_ROOT_ADDRESS_HASHED, }; use evm_arithmetization::verifier::testing::verify_all_proofs; use evm_arithmetization::{AllStark, Node, StarkConfig}; @@ -17,13 +21,12 @@ use mpt_trie::partial_trie::{HashedPartialTrie, PartialTrie}; use plonky2::field::goldilocks_field::GoldilocksField; use plonky2::plonk::config::PoseidonGoldilocksConfig; use plonky2::util::timing::TimingTree; -use rand::random; type F = GoldilocksField; const D: usize = 2; type C = PoseidonGoldilocksConfig; -/// Add a new Global Exit Root to the state trie. +/// Test pre-state execution as performed by cdk-erigon. #[test] fn test_global_exit_root() -> anyhow::Result<()> { init_logger(); @@ -33,19 +36,27 @@ fn test_global_exit_root() -> anyhow::Result<()> { let block_metadata = BlockMetadata { block_timestamp: 1.into(), + block_number: 42.into(), ..BlockMetadata::default() }; - let (state_trie_before, storage_tries) = preinitialized_state_and_storage_tries()?; + let (state_trie_before, mut storage_tries) = preinitialized_state_and_storage_tries()?; let mut beacon_roots_account_storage = storage_tries[0].1.clone(); - let mut ger_account_storage = storage_tries[1].1.clone(); + let mut ger_account_storage = HashedPartialTrie::from(Node::Empty); + let mut scalable_account_storage = HashedPartialTrie::from(Node::Empty); + storage_tries.push((GLOBAL_EXIT_ROOT_ADDRESS_HASHED, ger_account_storage.clone())); + storage_tries.push(( + ADDRESS_SCALABLE_L2_ADDRESS_HASHED, + scalable_account_storage.clone(), + )); + let transactions_trie = HashedPartialTrie::from(Node::Empty); let receipts_trie = HashedPartialTrie::from(Node::Empty); let mut contract_code = HashMap::new(); contract_code.insert(keccak(vec![]), vec![]); - let global_exit_roots = vec![(U256(random()), H256(random()))]; + let ger_data = Some((H256::random(), H256::random())); let state_trie_after = { let mut trie = HashedPartialTrie::from(Node::Empty); @@ -54,18 +65,27 @@ fn test_global_exit_root() -> anyhow::Result<()> { 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, + &block_metadata, + state_trie_before.hash(), + )?; + let beacon_roots_account = beacon_roots_contract_from_storage(&beacon_roots_account_storage); - for &(timestamp, root) in &global_exit_roots { - update_ger_account_storage(&mut ger_account_storage, root, timestamp)?; - } 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(), + rlp::encode(&scalable_account).to_vec(), + )?; trie }; @@ -80,7 +100,7 @@ fn test_global_exit_root() -> anyhow::Result<()> { signed_txns: vec![], burn_addr: None, withdrawals: vec![], - global_exit_roots, + ger_data, tries: TrieInputs { state_trie: state_trie_before, transactions_trie, diff --git a/evm_arithmetization/tests/log_opcode.rs b/evm_arithmetization/tests/log_opcode.rs index 8d71e0a19..f02737cff 100644 --- a/evm_arithmetization/tests/log_opcode.rs +++ b/evm_arithmetization/tests/log_opcode.rs @@ -12,9 +12,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, - init_logger, preinitialized_state_and_storage_tries, update_beacon_roots_account_storage, - GLOBAL_EXIT_ROOT_ACCOUNT, + beacon_roots_account_nibbles, beacon_roots_contract_from_storage, init_logger, + preinitialized_state_and_storage_tries, update_beacon_roots_account_storage, }; use evm_arithmetization::verifier::testing::verify_all_proofs; use evm_arithmetization::{AllStark, Node, StarkConfig}; @@ -227,10 +226,6 @@ fn test_log_opcodes() -> anyhow::Result<()> { beacon_roots_account_nibbles(), rlp::encode(&beacon_roots_account).to_vec(), )?; - expected_state_trie_after.insert( - ger_account_nibbles(), - rlp::encode(&GLOBAL_EXIT_ROOT_ACCOUNT).to_vec(), - )?; let transactions_trie: HashedPartialTrie = Node::Leaf { nibbles: Nibbles::from_str("0x80").unwrap(), @@ -253,7 +248,7 @@ fn test_log_opcodes() -> anyhow::Result<()> { signed_txns: vec![txn.to_vec()], burn_addr, withdrawals: vec![], - global_exit_roots: vec![], + ger_data: None, tries: tries_before, trie_roots_after, contract_code, diff --git a/evm_arithmetization/tests/selfdestruct.rs b/evm_arithmetization/tests/selfdestruct.rs index a4b6aa4f9..56f8f5929 100644 --- a/evm_arithmetization/tests/selfdestruct.rs +++ b/evm_arithmetization/tests/selfdestruct.rs @@ -7,9 +7,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, eth_to_wei, - ger_account_nibbles, init_logger, preinitialized_state_and_storage_tries, - update_beacon_roots_account_storage, GLOBAL_EXIT_ROOT_ACCOUNT, + beacon_roots_account_nibbles, beacon_roots_contract_from_storage, eth_to_wei, init_logger, + preinitialized_state_and_storage_tries, update_beacon_roots_account_storage, }; use evm_arithmetization::verifier::testing::verify_all_proofs; use evm_arithmetization::{AllStark, Node, StarkConfig}; @@ -122,10 +121,6 @@ fn test_selfdestruct() -> anyhow::Result<()> { beacon_roots_account_nibbles(), rlp::encode(&beacon_roots_account).to_vec(), )?; - state_trie_after.insert( - ger_account_nibbles(), - rlp::encode(&GLOBAL_EXIT_ROOT_ACCOUNT).to_vec(), - )?; state_trie_after }; @@ -157,7 +152,7 @@ fn test_selfdestruct() -> anyhow::Result<()> { signed_txns: vec![txn.to_vec()], burn_addr: None, withdrawals: vec![], - global_exit_roots: vec![], + ger_data: None, tries: tries_before, trie_roots_after, contract_code, diff --git a/evm_arithmetization/tests/simple_transfer.rs b/evm_arithmetization/tests/simple_transfer.rs index d497142a4..a6496deca 100644 --- a/evm_arithmetization/tests/simple_transfer.rs +++ b/evm_arithmetization/tests/simple_transfer.rs @@ -8,9 +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, eth_to_wei, - ger_account_nibbles, init_logger, preinitialized_state_and_storage_tries, - update_beacon_roots_account_storage, GLOBAL_EXIT_ROOT_ACCOUNT, + beacon_roots_account_nibbles, beacon_roots_contract_from_storage, eth_to_wei, init_logger, + preinitialized_state_and_storage_tries, update_beacon_roots_account_storage, }; use evm_arithmetization::verifier::testing::verify_all_proofs; use evm_arithmetization::{AllStark, Node, StarkConfig}; @@ -114,10 +113,6 @@ fn test_simple_transfer() -> anyhow::Result<()> { beacon_roots_account_nibbles(), rlp::encode(&beacon_roots_account).to_vec(), )?; - state_trie_after.insert( - ger_account_nibbles(), - rlp::encode(&GLOBAL_EXIT_ROOT_ACCOUNT).to_vec(), - )?; state_trie_after }; @@ -149,7 +144,7 @@ fn test_simple_transfer() -> anyhow::Result<()> { signed_txns: vec![txn.to_vec()], burn_addr: None, withdrawals: vec![], - global_exit_roots: vec![], + ger_data: None, tries: tries_before, trie_roots_after, contract_code, diff --git a/evm_arithmetization/tests/two_to_one_block.rs b/evm_arithmetization/tests/two_to_one_block.rs index ba0396693..679f9ddbf 100644 --- a/evm_arithmetization/tests/two_to_one_block.rs +++ b/evm_arithmetization/tests/two_to_one_block.rs @@ -1,4 +1,3 @@ -use env_logger::{try_init_from_env, Env, DEFAULT_FILTER_ENV}; use ethereum_types::{Address, BigEndianHash, H256}; use evm_arithmetization::fixed_recursive_verifier::{ extract_block_final_public_values, extract_two_to_one_block_hash, @@ -6,9 +5,8 @@ use evm_arithmetization::fixed_recursive_verifier::{ use evm_arithmetization::generation::{GenerationInputs, TrieInputs}; use evm_arithmetization::proof::{BlockMetadata, FinalPublicValues, PublicValues, TrieRoots}; use evm_arithmetization::testing_utils::{ - beacon_roots_account_nibbles, beacon_roots_contract_from_storage, ger_account_nibbles, + beacon_roots_account_nibbles, beacon_roots_contract_from_storage, init_logger, preinitialized_state_and_storage_tries, update_beacon_roots_account_storage, - GLOBAL_EXIT_ROOT_ACCOUNT, }; use evm_arithmetization::{AllRecursiveCircuits, AllStark, Node, StarkConfig}; use hex_literal::hex; @@ -23,10 +21,6 @@ type F = GoldilocksField; const D: usize = 2; type C = PoseidonGoldilocksConfig; -fn init_logger() { - let _ = try_init_from_env(Env::default().filter_or(DEFAULT_FILTER_ENV, "info")); -} - /// Get `GenerationInputs` for a dummy payload, where the block has the given /// timestamp. fn dummy_payload(timestamp: u64, is_first_payload: bool) -> anyhow::Result { @@ -78,10 +72,6 @@ fn dummy_payload(timestamp: u64, is_first_payload: bool) -> anyhow::Result anyhow::Result<()> { beacon_roots_account_nibbles(), rlp::encode(&beacon_roots_account).to_vec(), )?; - trie.insert( - ger_account_nibbles(), - rlp::encode(&GLOBAL_EXIT_ROOT_ACCOUNT).to_vec(), - )?; trie }; @@ -88,7 +83,7 @@ fn test_withdrawals() -> anyhow::Result<()> { signed_txns: vec![], burn_addr: None, withdrawals, - global_exit_roots: vec![], + ger_data: None, tries: TrieInputs { state_trie: state_trie_before, transactions_trie, diff --git a/trace_decoder/src/decoding.rs b/trace_decoder/src/decoding.rs index 758951b45..b0f909374 100644 --- a/trace_decoder/src/decoding.rs +++ b/trace_decoder/src/decoding.rs @@ -610,7 +610,7 @@ fn process_txn_info( .collect(), block_metadata: other_data.b_data.b_meta.clone(), block_hashes: other_data.b_data.b_hashes.clone(), - global_exit_roots: vec![], + ger_data: None, }; // After processing a transaction, we update the remaining accumulators From 533b95377f441b67c26c11235711f73933b8ee6d Mon Sep 17 00:00:00 2001 From: Robin Salen Date: Wed, 4 Sep 2024 18:59:35 -0400 Subject: [PATCH 04/17] Fix --- .../src/cpu/kernel/asm/cdk_pre_execution.asm | 15 ++++++++++++++- evm_arithmetization/tests/global_exit_root.rs | 11 +++++++++-- 2 files changed, 23 insertions(+), 3 deletions(-) diff --git a/evm_arithmetization/src/cpu/kernel/asm/cdk_pre_execution.asm b/evm_arithmetization/src/cpu/kernel/asm/cdk_pre_execution.asm index 37034c1df..27993d178 100644 --- a/evm_arithmetization/src/cpu/kernel/asm/cdk_pre_execution.asm +++ b/evm_arithmetization/src/cpu/kernel/asm/cdk_pre_execution.asm @@ -32,8 +32,21 @@ global update_scalable_prev_block_root_hash: // stack: retdest %mload_global_metadata(@GLOBAL_METADATA_STATE_TRIE_DIGEST_BEFORE) // stack: prev_block_root, retdest + PUSH @STATE_ROOT_STORAGE_POS PUSH 1 %blocknumber SUB - // stack: block_number - 1, prev_block_root, retdest + // stack: block_number - 1, STATE_ROOT_STORAGE_POS, prev_block_root, retdest + PUSH @SEGMENT_KERNEL_GENERAL + // stack: addr, block_number - 1, STATE_ROOT_STORAGE_POS, prev_block_root, retdest + MSTORE_32BYTES_32 + // stack: addr, STATE_ROOT_STORAGE_POS, prev_block_root, retdest + MSTORE_32BYTES_32 + // stack: addr, prev_block_root, retdest + POP + // stack: prev_block_root, retdest + PUSH 64 PUSH @SEGMENT_KERNEL_GENERAL + // stack: addr, len, prev_block_root, retdest + KECCAK_GENERAL + // stack: slot, prev_block_root, retdest %write_scalable_storage // stack: retdest diff --git a/evm_arithmetization/tests/global_exit_root.rs b/evm_arithmetization/tests/global_exit_root.rs index b108ac1ee..aa88529af 100644 --- a/evm_arithmetization/tests/global_exit_root.rs +++ b/evm_arithmetization/tests/global_exit_root.rs @@ -12,7 +12,8 @@ use evm_arithmetization::testing_utils::{ 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, - ADDRESS_SCALABLE_L2_ADDRESS_HASHED, GLOBAL_EXIT_ROOT_ADDRESS_HASHED, + ADDRESS_SCALABLE_L2_ADDRESS_HASHED, BEACON_ROOTS_ACCOUNT, GLOBAL_EXIT_ROOT_ACCOUNT, + GLOBAL_EXIT_ROOT_ADDRESS_HASHED, }; use evm_arithmetization::verifier::testing::verify_all_proofs; use evm_arithmetization::{AllStark, Node, StarkConfig}; @@ -40,10 +41,16 @@ fn test_global_exit_root() -> anyhow::Result<()> { ..BlockMetadata::default() }; - let (state_trie_before, mut storage_tries) = preinitialized_state_and_storage_tries()?; + let (mut state_trie_before, mut storage_tries) = preinitialized_state_and_storage_tries()?; + 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); + storage_tries.push((GLOBAL_EXIT_ROOT_ADDRESS_HASHED, ger_account_storage.clone())); storage_tries.push(( ADDRESS_SCALABLE_L2_ADDRESS_HASHED, From 4e3c73d7595d12dddc28c784187cdfd8f9b70e25 Mon Sep 17 00:00:00 2001 From: Robin Salen Date: Wed, 4 Sep 2024 19:03:51 -0400 Subject: [PATCH 05/17] Clippy --- evm_arithmetization/tests/global_exit_root.rs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/evm_arithmetization/tests/global_exit_root.rs b/evm_arithmetization/tests/global_exit_root.rs index aa88529af..ba9ac1c02 100644 --- a/evm_arithmetization/tests/global_exit_root.rs +++ b/evm_arithmetization/tests/global_exit_root.rs @@ -12,8 +12,7 @@ use evm_arithmetization::testing_utils::{ 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, - ADDRESS_SCALABLE_L2_ADDRESS_HASHED, BEACON_ROOTS_ACCOUNT, GLOBAL_EXIT_ROOT_ACCOUNT, - GLOBAL_EXIT_ROOT_ADDRESS_HASHED, + ADDRESS_SCALABLE_L2_ADDRESS_HASHED, GLOBAL_EXIT_ROOT_ACCOUNT, GLOBAL_EXIT_ROOT_ADDRESS_HASHED, }; use evm_arithmetization::verifier::testing::verify_all_proofs; use evm_arithmetization::{AllStark, Node, StarkConfig}; From ac7ca50d286c9f67d36a318567eba0b0e9740ed9 Mon Sep 17 00:00:00 2001 From: Robin Salen Date: Wed, 4 Sep 2024 19:09:52 -0400 Subject: [PATCH 06/17] Add feature-gating --- evm_arithmetization/src/cpu/kernel/tests/add11.rs | 2 ++ evm_arithmetization/tests/add11_yml.rs | 2 ++ evm_arithmetization/tests/erc20.rs | 2 ++ evm_arithmetization/tests/erc721.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 | 2 ++ evm_arithmetization/tests/withdrawals.rs | 2 ++ 9 files changed, 18 insertions(+) diff --git a/evm_arithmetization/src/cpu/kernel/tests/add11.rs b/evm_arithmetization/src/cpu/kernel/tests/add11.rs index 6f4ec1ec9..9e44c8bfa 100644 --- a/evm_arithmetization/src/cpu/kernel/tests/add11.rs +++ b/evm_arithmetization/src/cpu/kernel/tests/add11.rs @@ -1,3 +1,5 @@ +#![cfg(not(feature = "cdk_erigon"))] + use std::collections::HashMap; use std::str::FromStr; diff --git a/evm_arithmetization/tests/add11_yml.rs b/evm_arithmetization/tests/add11_yml.rs index 1a70d6873..e892d2772 100644 --- a/evm_arithmetization/tests/add11_yml.rs +++ b/evm_arithmetization/tests/add11_yml.rs @@ -1,3 +1,5 @@ +#![cfg(not(feature = "cdk_erigon"))] + use std::collections::HashMap; use std::str::FromStr; use std::time::Duration; diff --git a/evm_arithmetization/tests/erc20.rs b/evm_arithmetization/tests/erc20.rs index acfd6aacc..cd16de80f 100644 --- a/evm_arithmetization/tests/erc20.rs +++ b/evm_arithmetization/tests/erc20.rs @@ -1,3 +1,5 @@ +#![cfg(not(feature = "cdk_erigon"))] + use std::str::FromStr; use std::time::Duration; diff --git a/evm_arithmetization/tests/erc721.rs b/evm_arithmetization/tests/erc721.rs index b7f2a6de6..851560430 100644 --- a/evm_arithmetization/tests/erc721.rs +++ b/evm_arithmetization/tests/erc721.rs @@ -1,3 +1,5 @@ +#![cfg(not(feature = "cdk_erigon"))] + use std::str::FromStr; use std::time::Duration; diff --git a/evm_arithmetization/tests/log_opcode.rs b/evm_arithmetization/tests/log_opcode.rs index f02737cff..b08ace71c 100644 --- a/evm_arithmetization/tests/log_opcode.rs +++ b/evm_arithmetization/tests/log_opcode.rs @@ -1,3 +1,5 @@ +#![cfg(not(feature = "cdk_erigon"))] + use std::collections::HashMap; use std::str::FromStr; use std::time::Duration; diff --git a/evm_arithmetization/tests/selfdestruct.rs b/evm_arithmetization/tests/selfdestruct.rs index 56f8f5929..0669486bc 100644 --- a/evm_arithmetization/tests/selfdestruct.rs +++ b/evm_arithmetization/tests/selfdestruct.rs @@ -1,3 +1,5 @@ +#![cfg(not(feature = "cdk_erigon"))] + 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 a6496deca..37d14bf05 100644 --- a/evm_arithmetization/tests/simple_transfer.rs +++ b/evm_arithmetization/tests/simple_transfer.rs @@ -1,3 +1,5 @@ +#![cfg(not(feature = "cdk_erigon"))] + use std::collections::HashMap; use std::str::FromStr; use std::time::Duration; diff --git a/evm_arithmetization/tests/two_to_one_block.rs b/evm_arithmetization/tests/two_to_one_block.rs index 679f9ddbf..875009d67 100644 --- a/evm_arithmetization/tests/two_to_one_block.rs +++ b/evm_arithmetization/tests/two_to_one_block.rs @@ -1,3 +1,5 @@ +#![cfg(not(feature = "cdk_erigon"))] + use ethereum_types::{Address, BigEndianHash, H256}; use evm_arithmetization::fixed_recursive_verifier::{ extract_block_final_public_values, extract_two_to_one_block_hash, diff --git a/evm_arithmetization/tests/withdrawals.rs b/evm_arithmetization/tests/withdrawals.rs index 788385bae..9839c6646 100644 --- a/evm_arithmetization/tests/withdrawals.rs +++ b/evm_arithmetization/tests/withdrawals.rs @@ -1,3 +1,5 @@ +#![cfg(not(feature = "cdk_erigon"))] + use std::collections::HashMap; use std::time::Duration; From 45a5fb4439e19eaa0285661d19cd6831362ad2dd Mon Sep 17 00:00:00 2001 From: Robin Salen Date: Thu, 5 Sep 2024 15:49:03 -0400 Subject: [PATCH 07/17] feat: Feature-gate specific bits of the prover for pos and cdk --- .../src/cpu/kernel/aggregator.rs | 15 ++- .../src/cpu/kernel/asm/beacon_roots.asm | 13 +- .../src/cpu/kernel/asm/cdk_pre_execution.asm | 2 +- .../src/cpu/kernel/asm/core/exception.asm | 12 +- .../cpu/kernel/asm/core/precompiles/main.asm | 11 +- .../src/cpu/kernel/asm/core/syscall.asm | 12 +- .../src/cpu/kernel/asm/main.asm | 23 +++- .../src/cpu/kernel/asm/memory/metadata.asm | 86 ++++++------ .../asm/transactions/common_decoding.asm | 124 +++++++++--------- .../cpu/kernel/asm/transactions/router.asm | 16 ++- .../src/cpu/kernel/constants/exc_bitfields.rs | 15 +++ .../src/cpu/kernel/constants/mod.rs | 4 + .../src/cpu/kernel/interpreter.rs | 14 +- evm_arithmetization/src/cpu/kernel/parser.rs | 5 +- .../src/cpu/kernel/tests/add11.rs | 2 - .../src/cpu/kernel/tests/bls381.rs | 27 ---- .../src/cpu/kernel/tests/mod.rs | 3 + .../kernel/tests/transaction_parsing/mod.rs | 1 + .../src/fixed_recursive_verifier.rs | 86 ++++++------ evm_arithmetization/src/generation/mod.rs | 14 +- evm_arithmetization/src/get_challenges.rs | 26 ++-- evm_arithmetization/src/proof.rs | 52 +++----- evm_arithmetization/src/prover.rs | 26 +++- evm_arithmetization/src/recursive_verifier.rs | 61 +++++---- evm_arithmetization/src/verifier.rs | 13 ++ evm_arithmetization/src/witness/transition.rs | 2 + evm_arithmetization/tests/add11_yml.rs | 2 +- evm_arithmetization/tests/erc20.rs | 2 +- evm_arithmetization/tests/erc721.rs | 2 +- evm_arithmetization/tests/global_exit_root.rs | 21 +-- 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 | 2 +- evm_arithmetization/tests/withdrawals.rs | 2 +- 35 files changed, 392 insertions(+), 310 deletions(-) diff --git a/evm_arithmetization/src/cpu/kernel/aggregator.rs b/evm_arithmetization/src/cpu/kernel/aggregator.rs index 27054ac37..b360bfc2a 100644 --- a/evm_arithmetization/src/cpu/kernel/aggregator.rs +++ b/evm_arithmetization/src/cpu/kernel/aggregator.rs @@ -9,10 +9,12 @@ 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 = "polygon_pos") { + 155 +} else if cfg!(feature = "cdk_erigon") { + 156 } else { - 158 + 157 }; pub static KERNEL_FILES: [&str; NUMBER_KERNEL_FILES] = [ @@ -60,8 +62,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(not(any(feature = "polygon_pos", feature = "cdk_erigon")))] 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 +171,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(not(any(feature = "polygon_pos", feature = "cdk_erigon")))] include_str!("asm/transactions/type_3.asm"), include_str!("asm/util/assertions.asm"), include_str!("asm/util/basic_macros.asm"), @@ -187,6 +191,9 @@ pub(crate) fn combined_kernel_from_files(files: [&str; N]) -> Ke if cfg!(feature = "cdk_erigon") { active_features.insert("cdk_erigon"); } + if cfg!(feature = "polygon_pos") { + active_features.insert("polygon_pos"); + } let parsed_files = files .iter() 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/cdk_pre_execution.asm b/evm_arithmetization/src/cpu/kernel/asm/cdk_pre_execution.asm index 27993d178..c73c5ccd7 100644 --- a/evm_arithmetization/src/cpu/kernel/asm/cdk_pre_execution.asm +++ b/evm_arithmetization/src/cpu/kernel/asm/cdk_pre_execution.asm @@ -8,7 +8,7 @@ global pre_block_execution: // stack: (empty) PUSH txn_loop // stack: retdest - PUSH @ADDRESS_SCALABLE_L2_STATE_KEY + PUSH @ADDRESS_SCALABLE_L2 %is_non_existent %jumpi(create_scalable_l2_account) diff --git a/evm_arithmetization/src/cpu/kernel/asm/core/exception.asm b/evm_arithmetization/src/cpu/kernel/asm/core/exception.asm index a2a2742ec..ab9f2b54f 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(not(feature = polygon_pos, cdk_erigon))] + { + BYTES 1 // 0x49, BLOBHASH + BYTES 0 // 0x4a, BLOBBASEFEE + } + #[cfg(any(feature = polygon_pos, cdk_erigon))] + { + 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..56e0e365c 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(not(feature = polygon_pos, cdk_erigon))] + { + DUP1 %eq_const(@BLAKE2_F) %jumpi(precompile_blake2_f) + %eq_const(@KZG_PEVAL) %jumpi(precompile_kzg_peval) + } + #[cfg(any(feature = polygon_pos, cdk_erigon))] + { + %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..ab48dfa33 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(not(feature = polygon_pos, cdk_erigon))] + { + JUMPTABLE sys_blobhash + JUMPTABLE sys_blobbasefee + } + #[cfg(any(feature = polygon_pos, cdk_erigon))] + { + 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..d5befe5cd 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(not(feature = polygon_pos, cdk_erigon))] + { + // 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(not(feature = polygon_pos, cdk_erigon))] + { + %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..1d0ee2f8d 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(not(feature = polygon_pos, cdk_erigon))] +{ + 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..a5aee8b08 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(not(feature = polygon_pos, cdk_erigon))] +{ + %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..47eb30d19 100644 --- a/evm_arithmetization/src/cpu/kernel/asm/transactions/router.asm +++ b/evm_arithmetization/src/cpu/kernel/asm/transactions/router.asm @@ -33,12 +33,16 @@ 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(not(feature = polygon_pos,cdk_erigon))] + { + 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, // it must be a legacy (aka type 0) transaction. diff --git a/evm_arithmetization/src/cpu/kernel/constants/exc_bitfields.rs b/evm_arithmetization/src/cpu/kernel/constants/exc_bitfields.rs index 0abc84e70..c255ff583 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(not(any(feature = "polygon_pos", feature = "cdk_erigon")))] 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(any(feature = "polygon_pos", feature = "cdk_erigon"))] +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/constants/mod.rs b/evm_arithmetization/src/cpu/kernel/constants/mod.rs index 1c076040a..853e5500c 100644 --- a/evm_arithmetization/src/cpu/kernel/constants/mod.rs +++ b/evm_arithmetization/src/cpu/kernel/constants/mod.rs @@ -85,6 +85,10 @@ pub(crate) fn evm_constants() -> HashMap { global_exit_root::GLOBAL_EXIT_ROOT_STORAGE_POS.0.into(), U256::from(global_exit_root::GLOBAL_EXIT_ROOT_STORAGE_POS.1), ); + c.insert( + global_exit_root::ADDRESS_SCALABLE_L2.0.into(), + U256::from_big_endian(&global_exit_root::ADDRESS_SCALABLE_L2.1), + ); c.insert( global_exit_root::ADDRESS_SCALABLE_L2_STATE_KEY.0.into(), U256::from_big_endian(&global_exit_root::ADDRESS_SCALABLE_L2_STATE_KEY.1), diff --git a/evm_arithmetization/src/cpu/kernel/interpreter.rs b/evm_arithmetization/src/cpu/kernel/interpreter.rs index 23b4507f0..dd064f09e 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(not(any(feature = "polygon_pos", feature = "cdk_erigon")))] ( GlobalMetadata::BlockBlobGasUsed, metadata.block_blob_gas_used, ), + #[cfg(not(any(feature = "polygon_pos", feature = "cdk_erigon")))] ( GlobalMetadata::BlockExcessBlobGas, metadata.block_excess_blob_gas, ), + #[cfg(not(any(feature = "polygon_pos", feature = "cdk_erigon")))] ( 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..8da8bd826 100644 --- a/evm_arithmetization/src/cpu/kernel/parser.rs +++ b/evm_arithmetization/src/cpu/kernel/parser.rs @@ -91,7 +91,10 @@ 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 + .into_iter() + .filter(|s| !s.is_empty()); match group_rule { FeatureGroupRule::Not => { diff --git a/evm_arithmetization/src/cpu/kernel/tests/add11.rs b/evm_arithmetization/src/cpu/kernel/tests/add11.rs index 9e44c8bfa..6f4ec1ec9 100644 --- a/evm_arithmetization/src/cpu/kernel/tests/add11.rs +++ b/evm_arithmetization/src/cpu/kernel/tests/add11.rs @@ -1,5 +1,3 @@ -#![cfg(not(feature = "cdk_erigon"))] - use std::collections::HashMap; use std::str::FromStr; 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 6219773d0..d95f95a0d 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(not(any(feature = "polygon_pos", feature = "cdk_erigon")))] mod add11; mod balance; mod bignum; mod blake2_f; +#[cfg(not(any(feature = "polygon_pos", feature = "cdk_erigon")))] mod blobhash; mod block_hash; +#[cfg(not(any(feature = "polygon_pos", feature = "cdk_erigon")))] 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 1bfa1607d..3ba9a61d4 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(not(any(feature = "polygon_pos", feature = "cdk_erigon")))] 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 c97bdb946..47109f20f 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 @@ -1034,18 +1032,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, @@ -1184,16 +1185,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, @@ -1368,16 +1372,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. @@ -1806,9 +1813,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, @@ -1882,6 +1888,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)); @@ -2337,7 +2345,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 f9b3bb39a..1970d1233 100644 --- a/evm_arithmetization/src/generation/mod.rs +++ b/evm_arithmetization/src/generation/mod.rs @@ -235,10 +235,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, @@ -259,14 +255,17 @@ fn apply_metadata_and_tries_memops, const D: usize> h2u(inputs.block_hashes.cur_hash), ), (GlobalMetadata::BlockGasUsed, metadata.block_gas_used), + #[cfg(not(any(feature = "polygon_pos", feature = "cdk_erigon")))] ( GlobalMetadata::BlockBlobGasUsed, metadata.block_blob_gas_used, ), + #[cfg(not(any(feature = "polygon_pos", feature = "cdk_erigon")))] ( GlobalMetadata::BlockExcessBlobGas, metadata.block_excess_blob_gas, ), + #[cfg(not(any(feature = "polygon_pos", feature = "cdk_erigon")))] ( GlobalMetadata::ParentBeaconBlockRoot, h2u(metadata.parent_beacon_block_root), @@ -305,7 +304,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..216f8828e 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(not(any(feature = "polygon_pos", feature = "cdk_erigon")))] + { + 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(not(any(feature = "polygon_pos", feature = "cdk_erigon")))] + { + 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/proof.rs b/evm_arithmetization/src/proof.rs index 6c59b9deb..8d9a00cb0 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 2f308898a..95e0fd780 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); @@ -455,6 +454,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::*; @@ -470,9 +483,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 = @@ -527,6 +539,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..b9cf5b6eb 100644 --- a/evm_arithmetization/src/recursive_verifier.rs +++ b/evm_arithmetization/src/recursive_verifier.rs @@ -383,7 +383,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] = [ + const LENGTH: usize = if cfg!(feature = "polygon_pos") || cfg!(feature = "cdk_erigon") { + 4 + } else { + 7 + }; + let block_fields_arrays: [(GlobalMetadata, &[Target]); LENGTH] = [ ( GlobalMetadata::BlockBeneficiary, &public_values.block_metadata.block_beneficiary, @@ -396,14 +401,17 @@ pub(crate) fn get_memory_extra_looking_sum_circuit, GlobalMetadata::BlockBaseFee, &public_values.block_metadata.block_base_fee, ), + #[cfg(not(any(feature = "polygon_pos", feature = "cdk_erigon")))] ( GlobalMetadata::BlockBlobGasUsed, &public_values.block_metadata.block_blob_gas_used, ), + #[cfg(not(any(feature = "polygon_pos", feature = "cdk_erigon")))] ( GlobalMetadata::BlockExcessBlobGas, &public_values.block_metadata.block_excess_blob_gas, ), + #[cfg(not(any(feature = "polygon_pos", feature = "cdk_erigon")))] ( GlobalMetadata::ParentBeaconBlockRoot, &public_values.block_metadata.parent_beacon_block_root, @@ -1046,31 +1054,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(not(any(feature = "polygon_pos", feature = "cdk_erigon")))] + { + // 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 845c58eb5..56ddd595b 100644 --- a/evm_arithmetization/src/verifier.rs +++ b/evm_arithmetization/src/verifier.rs @@ -309,6 +309,7 @@ where GlobalMetadata::BlockBaseFee, public_values.block_metadata.block_base_fee, ), + #[cfg(not(any(feature = "polygon_pos", feature = "cdk_erigon")))] ( GlobalMetadata::ParentBeaconBlockRoot, h2u(public_values.block_metadata.parent_beacon_block_root), @@ -321,10 +322,12 @@ where GlobalMetadata::BlockGasUsed, public_values.block_metadata.block_gas_used, ), + #[cfg(not(any(feature = "polygon_pos", feature = "cdk_erigon")))] ( GlobalMetadata::BlockBlobGasUsed, public_values.block_metadata.block_blob_gas_used, ), + #[cfg(not(any(feature = "polygon_pos", feature = "cdk_erigon")))] ( GlobalMetadata::BlockExcessBlobGas, public_values.block_metadata.block_excess_blob_gas, @@ -494,6 +497,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, @@ -530,14 +540,17 @@ pub(crate) mod debug_utils { GlobalMetadata::BlockGasUsed, public_values.block_metadata.block_gas_used, ), + #[cfg(not(any(feature = "polygon_pos", feature = "cdk_erigon")))] ( GlobalMetadata::BlockBlobGasUsed, public_values.block_metadata.block_blob_gas_used, ), + #[cfg(not(any(feature = "polygon_pos", feature = "cdk_erigon")))] ( GlobalMetadata::BlockExcessBlobGas, public_values.block_metadata.block_excess_blob_gas, ), + #[cfg(not(any(feature = "polygon_pos", feature = "cdk_erigon")))] ( 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 ae5ae6d97..3478cc756 100644 --- a/evm_arithmetization/src/witness/transition.rs +++ b/evm_arithmetization/src/witness/transition.rs @@ -115,7 +115,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(not(any(feature = "polygon_pos", feature = "cdk_erigon")))] (0x49, _) => Ok(Operation::Syscall(opcode, 1, false)), // BLOBHASH + #[cfg(not(any(feature = "polygon_pos", feature = "cdk_erigon")))] (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..19d07db04 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(not(any(feature = "polygon_pos", feature = "cdk_erigon")))] use std::collections::HashMap; use std::str::FromStr; diff --git a/evm_arithmetization/tests/erc20.rs b/evm_arithmetization/tests/erc20.rs index cd16de80f..313d6a67f 100644 --- a/evm_arithmetization/tests/erc20.rs +++ b/evm_arithmetization/tests/erc20.rs @@ -1,4 +1,4 @@ -#![cfg(not(feature = "cdk_erigon"))] +#![cfg(not(any(feature = "polygon_pos", feature = "cdk_erigon")))] use std::str::FromStr; use std::time::Duration; diff --git a/evm_arithmetization/tests/erc721.rs b/evm_arithmetization/tests/erc721.rs index 851560430..8a437eec7 100644 --- a/evm_arithmetization/tests/erc721.rs +++ b/evm_arithmetization/tests/erc721.rs @@ -1,4 +1,4 @@ -#![cfg(not(feature = "cdk_erigon"))] +#![cfg(not(any(feature = "polygon_pos", feature = "cdk_erigon")))] 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..a949ae02b 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(not(any(feature = "polygon_pos", feature = "cdk_erigon")))] use std::collections::HashMap; use std::str::FromStr; diff --git a/evm_arithmetization/tests/selfdestruct.rs b/evm_arithmetization/tests/selfdestruct.rs index 0669486bc..c4b802d7e 100644 --- a/evm_arithmetization/tests/selfdestruct.rs +++ b/evm_arithmetization/tests/selfdestruct.rs @@ -1,4 +1,4 @@ -#![cfg(not(feature = "cdk_erigon"))] +#![cfg(not(any(feature = "polygon_pos", feature = "cdk_erigon")))] 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..fe664097b 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(not(any(feature = "polygon_pos", feature = "cdk_erigon")))] 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 875009d67..386f34ce0 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(not(any(feature = "polygon_pos", feature = "cdk_erigon")))] use ethereum_types::{Address, BigEndianHash, H256}; use evm_arithmetization::fixed_recursive_verifier::{ diff --git a/evm_arithmetization/tests/withdrawals.rs b/evm_arithmetization/tests/withdrawals.rs index 9839c6646..2522b11ab 100644 --- a/evm_arithmetization/tests/withdrawals.rs +++ b/evm_arithmetization/tests/withdrawals.rs @@ -1,4 +1,4 @@ -#![cfg(not(feature = "cdk_erigon"))] +#![cfg(not(any(feature = "polygon_pos", feature = "cdk_erigon")))] use std::collections::HashMap; use std::time::Duration; From 58f1b22a630a89e6a8294ee5ebdcd5e012c9dfc5 Mon Sep 17 00:00:00 2001 From: Robin Salen Date: Thu, 5 Sep 2024 19:42:12 -0400 Subject: [PATCH 08/17] Add default eth_mainnet --- evm_arithmetization/Cargo.toml | 14 +++++--------- evm_arithmetization/src/cpu/kernel/aggregator.rs | 10 +++++----- .../src/cpu/kernel/constants/exc_bitfields.rs | 4 ++-- evm_arithmetization/src/cpu/kernel/interpreter.rs | 6 +++--- evm_arithmetization/src/cpu/kernel/tests/mod.rs | 6 +++--- .../cpu/kernel/tests/transaction_parsing/mod.rs | 2 +- evm_arithmetization/src/generation/mod.rs | 6 +++--- evm_arithmetization/src/get_challenges.rs | 4 ++-- evm_arithmetization/src/lib.rs | 11 +++++++++++ evm_arithmetization/src/recursive_verifier.rs | 14 +++++--------- evm_arithmetization/src/verifier.rs | 12 ++++++------ evm_arithmetization/src/witness/transition.rs | 4 ++-- evm_arithmetization/tests/add11_yml.rs | 2 +- evm_arithmetization/tests/erc20.rs | 2 +- evm_arithmetization/tests/erc721.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 | 6 +++--- evm_arithmetization/tests/withdrawals.rs | 2 +- 20 files changed, 58 insertions(+), 55 deletions(-) diff --git a/evm_arithmetization/Cargo.toml b/evm_arithmetization/Cargo.toml index c18bea130..4fcd03335 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 } @@ -56,15 +56,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 = [] +eth_mainnet = [] [[bin]] name = "assemble" diff --git a/evm_arithmetization/src/cpu/kernel/aggregator.rs b/evm_arithmetization/src/cpu/kernel/aggregator.rs index b360bfc2a..fd48730f3 100644 --- a/evm_arithmetization/src/cpu/kernel/aggregator.rs +++ b/evm_arithmetization/src/cpu/kernel/aggregator.rs @@ -9,12 +9,12 @@ 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 = "polygon_pos") { - 155 +pub const NUMBER_KERNEL_FILES: usize = if cfg!(feature = "eth_mainnet") { + 157 } else if cfg!(feature = "cdk_erigon") { 156 } else { - 157 + 155 }; pub static KERNEL_FILES: [&str; NUMBER_KERNEL_FILES] = [ @@ -62,7 +62,7 @@ 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(not(any(feature = "polygon_pos", feature = "cdk_erigon")))] + #[cfg(feature = "eth_mainnet")] include_str!("asm/core/precompiles/kzg_peval.asm"), // include_str!("asm/curve/bls381/util.asm"), include_str!("asm/curve/bn254/curve_arithmetic/constants.asm"), @@ -171,7 +171,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(not(any(feature = "polygon_pos", feature = "cdk_erigon")))] + #[cfg(feature = "eth_mainnet")] include_str!("asm/transactions/type_3.asm"), include_str!("asm/util/assertions.asm"), include_str!("asm/util/basic_macros.asm"), diff --git a/evm_arithmetization/src/cpu/kernel/constants/exc_bitfields.rs b/evm_arithmetization/src/cpu/kernel/constants/exc_bitfields.rs index c255ff583..5ed5972c1 100644 --- a/evm_arithmetization/src/cpu/kernel/constants/exc_bitfields.rs +++ b/evm_arithmetization/src/cpu/kernel/constants/exc_bitfields.rs @@ -28,7 +28,7 @@ const fn u256_from_set_index_ranges(ranges: &[RangeInclusive U256(res_limbs) } -#[cfg(not(any(feature = "polygon_pos", feature = "cdk_erigon")))] +#[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 @@ -43,7 +43,7 @@ pub(crate) const STACK_LENGTH_INCREASING_OPCODES_USER: U256 = u256_from_set_inde 0x5f..=0x8f, // PUSH*, DUP* ]); -#[cfg(any(feature = "polygon_pos", feature = "cdk_erigon"))] +#[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 diff --git a/evm_arithmetization/src/cpu/kernel/interpreter.rs b/evm_arithmetization/src/cpu/kernel/interpreter.rs index dd064f09e..65e27fb1c 100644 --- a/evm_arithmetization/src/cpu/kernel/interpreter.rs +++ b/evm_arithmetization/src/cpu/kernel/interpreter.rs @@ -283,17 +283,17 @@ impl Interpreter { h2u(inputs.block_hashes.cur_hash), ), (GlobalMetadata::BlockGasUsed, metadata.block_gas_used), - #[cfg(not(any(feature = "polygon_pos", feature = "cdk_erigon")))] + #[cfg(feature = "eth_mainnet")] ( GlobalMetadata::BlockBlobGasUsed, metadata.block_blob_gas_used, ), - #[cfg(not(any(feature = "polygon_pos", feature = "cdk_erigon")))] + #[cfg(feature = "eth_mainnet")] ( GlobalMetadata::BlockExcessBlobGas, metadata.block_excess_blob_gas, ), - #[cfg(not(any(feature = "polygon_pos", feature = "cdk_erigon")))] + #[cfg(feature = "eth_mainnet")] ( GlobalMetadata::ParentBeaconBlockRoot, h2u(metadata.parent_beacon_block_root), diff --git a/evm_arithmetization/src/cpu/kernel/tests/mod.rs b/evm_arithmetization/src/cpu/kernel/tests/mod.rs index d95f95a0d..01cccde9f 100644 --- a/evm_arithmetization/src/cpu/kernel/tests/mod.rs +++ b/evm_arithmetization/src/cpu/kernel/tests/mod.rs @@ -1,13 +1,13 @@ mod account_code; -#[cfg(not(any(feature = "polygon_pos", feature = "cdk_erigon")))] +#[cfg(feature = "eth_mainnet")] mod add11; mod balance; mod bignum; mod blake2_f; -#[cfg(not(any(feature = "polygon_pos", feature = "cdk_erigon")))] +#[cfg(feature = "eth_mainnet")] mod blobhash; mod block_hash; -#[cfg(not(any(feature = "polygon_pos", feature = "cdk_erigon")))] +#[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 3ba9a61d4..58f50e2cd 100644 --- a/evm_arithmetization/src/cpu/kernel/tests/transaction_parsing/mod.rs +++ b/evm_arithmetization/src/cpu/kernel/tests/transaction_parsing/mod.rs @@ -9,7 +9,7 @@ use crate::{ mod parse_type_0_txn; mod parse_type_1_txn; mod parse_type_2_txn; -#[cfg(not(any(feature = "polygon_pos", feature = "cdk_erigon")))] +#[cfg(feature = "eth_mainnet")] mod parse_type_3_txn; pub(crate) fn prepare_interpreter_for_txn_parsing( diff --git a/evm_arithmetization/src/generation/mod.rs b/evm_arithmetization/src/generation/mod.rs index 1970d1233..e6f33b4cd 100644 --- a/evm_arithmetization/src/generation/mod.rs +++ b/evm_arithmetization/src/generation/mod.rs @@ -255,17 +255,17 @@ fn apply_metadata_and_tries_memops, const D: usize> h2u(inputs.block_hashes.cur_hash), ), (GlobalMetadata::BlockGasUsed, metadata.block_gas_used), - #[cfg(not(any(feature = "polygon_pos", feature = "cdk_erigon")))] + #[cfg(feature = "eth_mainnet")] ( GlobalMetadata::BlockBlobGasUsed, metadata.block_blob_gas_used, ), - #[cfg(not(any(feature = "polygon_pos", feature = "cdk_erigon")))] + #[cfg(feature = "eth_mainnet")] ( GlobalMetadata::BlockExcessBlobGas, metadata.block_excess_blob_gas, ), - #[cfg(not(any(feature = "polygon_pos", feature = "cdk_erigon")))] + #[cfg(feature = "eth_mainnet")] ( GlobalMetadata::ParentBeaconBlockRoot, h2u(metadata.parent_beacon_block_root), diff --git a/evm_arithmetization/src/get_challenges.rs b/evm_arithmetization/src/get_challenges.rs index 216f8828e..7a8e25f58 100644 --- a/evm_arithmetization/src/get_challenges.rs +++ b/evm_arithmetization/src/get_challenges.rs @@ -65,7 +65,7 @@ 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)?); - #[cfg(not(any(feature = "polygon_pos", feature = "cdk_erigon")))] + #[cfg(feature = "eth_mainnet")] { let blob_gas_used = u256_to_u64(block_metadata.block_blob_gas_used)?; challenger.observe_element(blob_gas_used.0); @@ -101,7 +101,7 @@ 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); - #[cfg(not(any(feature = "polygon_pos", feature = "cdk_erigon")))] + #[cfg(feature = "eth_mainnet")] { challenger.observe_elements(&block_metadata.block_blob_gas_used); challenger.observe_elements(&block_metadata.block_excess_blob_gas); diff --git a/evm_arithmetization/src/lib.rs b/evm_arithmetization/src/lib.rs index b76953311..ae2aa9317 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/recursive_verifier.rs b/evm_arithmetization/src/recursive_verifier.rs index b9cf5b6eb..b120f1da4 100644 --- a/evm_arithmetization/src/recursive_verifier.rs +++ b/evm_arithmetization/src/recursive_verifier.rs @@ -383,11 +383,7 @@ 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`. - const LENGTH: usize = if cfg!(feature = "polygon_pos") || cfg!(feature = "cdk_erigon") { - 4 - } else { - 7 - }; + const LENGTH: usize = if cfg!(feature = "eth_mainnet") { 7 } else { 4 }; let block_fields_arrays: [(GlobalMetadata, &[Target]); LENGTH] = [ ( GlobalMetadata::BlockBeneficiary, @@ -401,17 +397,17 @@ pub(crate) fn get_memory_extra_looking_sum_circuit, GlobalMetadata::BlockBaseFee, &public_values.block_metadata.block_base_fee, ), - #[cfg(not(any(feature = "polygon_pos", feature = "cdk_erigon")))] + #[cfg(feature = "eth_mainnet")] ( GlobalMetadata::BlockBlobGasUsed, &public_values.block_metadata.block_blob_gas_used, ), - #[cfg(not(any(feature = "polygon_pos", feature = "cdk_erigon")))] + #[cfg(feature = "eth_mainnet")] ( GlobalMetadata::BlockExcessBlobGas, &public_values.block_metadata.block_excess_blob_gas, ), - #[cfg(not(any(feature = "polygon_pos", feature = "cdk_erigon")))] + #[cfg(feature = "eth_mainnet")] ( GlobalMetadata::ParentBeaconBlockRoot, &public_values.block_metadata.parent_beacon_block_root, @@ -1054,7 +1050,7 @@ where block_metadata_target.block_gas_used, u256_to_u32(block_metadata.block_gas_used)?, ); - #[cfg(not(any(feature = "polygon_pos", feature = "cdk_erigon")))] + #[cfg(feature = "eth_mainnet")] { // BlobGasUsed fits in 2 limbs let blob_gas_used = u256_to_u64(block_metadata.block_blob_gas_used)?; diff --git a/evm_arithmetization/src/verifier.rs b/evm_arithmetization/src/verifier.rs index 56ddd595b..e62c59cb1 100644 --- a/evm_arithmetization/src/verifier.rs +++ b/evm_arithmetization/src/verifier.rs @@ -309,7 +309,7 @@ where GlobalMetadata::BlockBaseFee, public_values.block_metadata.block_base_fee, ), - #[cfg(not(any(feature = "polygon_pos", feature = "cdk_erigon")))] + #[cfg(feature = "eth_mainnet")] ( GlobalMetadata::ParentBeaconBlockRoot, h2u(public_values.block_metadata.parent_beacon_block_root), @@ -322,12 +322,12 @@ where GlobalMetadata::BlockGasUsed, public_values.block_metadata.block_gas_used, ), - #[cfg(not(any(feature = "polygon_pos", feature = "cdk_erigon")))] + #[cfg(feature = "eth_mainnet")] ( GlobalMetadata::BlockBlobGasUsed, public_values.block_metadata.block_blob_gas_used, ), - #[cfg(not(any(feature = "polygon_pos", feature = "cdk_erigon")))] + #[cfg(feature = "eth_mainnet")] ( GlobalMetadata::BlockExcessBlobGas, public_values.block_metadata.block_excess_blob_gas, @@ -540,17 +540,17 @@ pub(crate) mod debug_utils { GlobalMetadata::BlockGasUsed, public_values.block_metadata.block_gas_used, ), - #[cfg(not(any(feature = "polygon_pos", feature = "cdk_erigon")))] + #[cfg(feature = "eth_mainnet")] ( GlobalMetadata::BlockBlobGasUsed, public_values.block_metadata.block_blob_gas_used, ), - #[cfg(not(any(feature = "polygon_pos", feature = "cdk_erigon")))] + #[cfg(feature = "eth_mainnet")] ( GlobalMetadata::BlockExcessBlobGas, public_values.block_metadata.block_excess_blob_gas, ), - #[cfg(not(any(feature = "polygon_pos", feature = "cdk_erigon")))] + #[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 3478cc756..794dabd85 100644 --- a/evm_arithmetization/src/witness/transition.rs +++ b/evm_arithmetization/src/witness/transition.rs @@ -115,9 +115,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(not(any(feature = "polygon_pos", feature = "cdk_erigon")))] + #[cfg(feature = "eth_mainnet")] (0x49, _) => Ok(Operation::Syscall(opcode, 1, false)), // BLOBHASH - #[cfg(not(any(feature = "polygon_pos", feature = "cdk_erigon")))] + #[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 19d07db04..a7624a6df 100644 --- a/evm_arithmetization/tests/add11_yml.rs +++ b/evm_arithmetization/tests/add11_yml.rs @@ -1,4 +1,4 @@ -#![cfg(not(any(feature = "polygon_pos", 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 313d6a67f..61bb3f2ef 100644 --- a/evm_arithmetization/tests/erc20.rs +++ b/evm_arithmetization/tests/erc20.rs @@ -1,4 +1,4 @@ -#![cfg(not(any(feature = "polygon_pos", 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 8a437eec7..47d214f9e 100644 --- a/evm_arithmetization/tests/erc721.rs +++ b/evm_arithmetization/tests/erc721.rs @@ -1,4 +1,4 @@ -#![cfg(not(any(feature = "polygon_pos", feature = "cdk_erigon")))] +#![cfg(feature = "eth_mainnet")] use std::str::FromStr; use std::time::Duration; diff --git a/evm_arithmetization/tests/log_opcode.rs b/evm_arithmetization/tests/log_opcode.rs index a949ae02b..0b925ceae 100644 --- a/evm_arithmetization/tests/log_opcode.rs +++ b/evm_arithmetization/tests/log_opcode.rs @@ -1,4 +1,4 @@ -#![cfg(not(any(feature = "polygon_pos", 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 c4b802d7e..271630512 100644 --- a/evm_arithmetization/tests/selfdestruct.rs +++ b/evm_arithmetization/tests/selfdestruct.rs @@ -1,4 +1,4 @@ -#![cfg(not(any(feature = "polygon_pos", 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 fe664097b..81454fb0e 100644 --- a/evm_arithmetization/tests/simple_transfer.rs +++ b/evm_arithmetization/tests/simple_transfer.rs @@ -1,4 +1,4 @@ -#![cfg(not(any(feature = "polygon_pos", 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 386f34ce0..fb734ea00 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(any(feature = "polygon_pos", feature = "cdk_erigon")))] +#![cfg(feature = "eth_mainnet")] use ethereum_types::{Address, BigEndianHash, H256}; use evm_arithmetization::fixed_recursive_verifier::{ @@ -177,10 +177,10 @@ fn test_two_to_one_block_aggregation() -> anyhow::Result<()> { &[ 16..17, 8..9, - 14..15, + 12..13, 9..10, 8..9, - 7..8, + 6..7, 17..18, 17..18, 7..8, diff --git a/evm_arithmetization/tests/withdrawals.rs b/evm_arithmetization/tests/withdrawals.rs index 2522b11ab..4868a2fd4 100644 --- a/evm_arithmetization/tests/withdrawals.rs +++ b/evm_arithmetization/tests/withdrawals.rs @@ -1,4 +1,4 @@ -#![cfg(not(any(feature = "polygon_pos", feature = "cdk_erigon")))] +#![cfg(feature = "eth_mainnet")] use std::collections::HashMap; use std::time::Duration; From 5844a81cb82b54e15d15b7cedf076c49f80ddba2 Mon Sep 17 00:00:00 2001 From: Robin Salen Date: Thu, 5 Sep 2024 19:52:53 -0400 Subject: [PATCH 09/17] fix: update CI --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index f23f911bd..c4d2f7fb1 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -237,7 +237,7 @@ 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: Rustdoc run: cargo doc --all From 62f05e1519d73f3f81eb064cc3f6f7ed20a77135 Mon Sep 17 00:00:00 2001 From: Robin Salen Date: Thu, 5 Sep 2024 19:56:03 -0400 Subject: [PATCH 10/17] Pacify mighty clippy --- evm_arithmetization/src/cpu/kernel/parser.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/evm_arithmetization/src/cpu/kernel/parser.rs b/evm_arithmetization/src/cpu/kernel/parser.rs index 8da8bd826..be80ae5d4 100644 --- a/evm_arithmetization/src/cpu/kernel/parser.rs +++ b/evm_arithmetization/src/cpu/kernel/parser.rs @@ -93,7 +93,6 @@ fn parse_conditional_block(item: Pair, active_features: &HashSet<&str>) -> ) -> bool { let features = features_string .split(&[',', ' ']) // allows for both `foo,bar` and `foo, bar` in ASM - .into_iter() .filter(|s| !s.is_empty()); match group_rule { From c5c62c0006331d176ef12a8d3de71bae7a62d2fa Mon Sep 17 00:00:00 2001 From: Robin Salen Date: Thu, 5 Sep 2024 20:11:52 -0400 Subject: [PATCH 11/17] Use eth_mainnet feature directly in KERNEL --- evm_arithmetization/src/cpu/kernel/aggregator.rs | 5 +++-- evm_arithmetization/src/cpu/kernel/asm/core/exception.asm | 4 ++-- .../src/cpu/kernel/asm/core/precompiles/main.asm | 4 ++-- evm_arithmetization/src/cpu/kernel/asm/core/syscall.asm | 4 ++-- evm_arithmetization/src/cpu/kernel/asm/main.asm | 4 ++-- evm_arithmetization/src/cpu/kernel/asm/memory/metadata.asm | 2 +- .../src/cpu/kernel/asm/transactions/common_decoding.asm | 2 +- .../src/cpu/kernel/asm/transactions/router.asm | 2 +- 8 files changed, 14 insertions(+), 13 deletions(-) diff --git a/evm_arithmetization/src/cpu/kernel/aggregator.rs b/evm_arithmetization/src/cpu/kernel/aggregator.rs index fd48730f3..fded2f0ef 100644 --- a/evm_arithmetization/src/cpu/kernel/aggregator.rs +++ b/evm_arithmetization/src/cpu/kernel/aggregator.rs @@ -190,9 +190,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"); - } - if cfg!(feature = "polygon_pos") { + } 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/core/exception.asm b/evm_arithmetization/src/cpu/kernel/asm/core/exception.asm index ab9f2b54f..925921097 100644 --- a/evm_arithmetization/src/cpu/kernel/asm/core/exception.asm +++ b/evm_arithmetization/src/cpu/kernel/asm/core/exception.asm @@ -327,12 +327,12 @@ min_stack_len_for_opcode: BYTES 0 // 0x46, CHAINID BYTES 0 // 0x47, SELFBALANCE BYTES 0 // 0x48, BASEFEE - #[cfg(not(feature = polygon_pos, cdk_erigon))] + #[cfg(feature = eth_mainnet)] { BYTES 1 // 0x49, BLOBHASH BYTES 0 // 0x4a, BLOBBASEFEE } - #[cfg(any(feature = polygon_pos, cdk_erigon))] + #[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 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 56e0e365c..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,12 +18,12 @@ 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) - #[cfg(not(feature = polygon_pos, cdk_erigon))] + #[cfg(feature = eth_mainnet)] { DUP1 %eq_const(@BLAKE2_F) %jumpi(precompile_blake2_f) %eq_const(@KZG_PEVAL) %jumpi(precompile_kzg_peval) } - #[cfg(any(feature = polygon_pos, cdk_erigon))] + #[cfg(not(feature = eth_mainnet))] { %eq_const(@BLAKE2_F) %jumpi(precompile_blake2_f) } diff --git a/evm_arithmetization/src/cpu/kernel/asm/core/syscall.asm b/evm_arithmetization/src/cpu/kernel/asm/core/syscall.asm index ab48dfa33..7677654e2 100644 --- a/evm_arithmetization/src/cpu/kernel/asm/core/syscall.asm +++ b/evm_arithmetization/src/cpu/kernel/asm/core/syscall.asm @@ -69,12 +69,12 @@ global syscall_jumptable: JUMPTABLE sys_chainid JUMPTABLE sys_selfbalance JUMPTABLE sys_basefee - #[cfg(not(feature = polygon_pos, cdk_erigon))] + #[cfg(feature = eth_mainnet)] { JUMPTABLE sys_blobhash JUMPTABLE sys_blobbasefee } - #[cfg(any(feature = polygon_pos, cdk_erigon))] + #[cfg(not(feature = eth_mainnet))] { JUMPTABLE panic // BLOBHASH is only active on Ethereum mainnet JUMPTABLE panic // BLOBBASEFEE is only active on Ethereum mainnet diff --git a/evm_arithmetization/src/cpu/kernel/asm/main.asm b/evm_arithmetization/src/cpu/kernel/asm/main.asm index d5befe5cd..8d2b09c66 100644 --- a/evm_arithmetization/src/cpu/kernel/asm/main.asm +++ b/evm_arithmetization/src/cpu/kernel/asm/main.asm @@ -127,7 +127,7 @@ global start_txns: %mload_global_metadata(@GLOBAL_METADATA_BLOCK_GAS_USED_BEFORE) // stack: init_gas_used, txn_counter, num_nibbles, txn_nb - #[cfg(not(feature = polygon_pos, cdk_erigon))] + #[cfg(feature = eth_mainnet)] { // If txn_idx == 0, update the beacon_root for Ethereum mainnet. %mload_global_metadata(@GLOBAL_METADATA_TXN_NUMBER_BEFORE) @@ -265,7 +265,7 @@ global check_final_state_trie: PUSH 0 %mstore_txn_field(@TXN_FIELD_CHAIN_ID_PRESENT) PUSH 0 %mstore_txn_field(@TXN_FIELD_TO) - #[cfg(not(feature = polygon_pos, cdk_erigon))] + #[cfg(feature = eth_mainnet)] { %reset_blob_versioned_hashes } diff --git a/evm_arithmetization/src/cpu/kernel/asm/memory/metadata.asm b/evm_arithmetization/src/cpu/kernel/asm/memory/metadata.asm index 1d0ee2f8d..5e94794f6 100644 --- a/evm_arithmetization/src/cpu/kernel/asm/memory/metadata.asm +++ b/evm_arithmetization/src/cpu/kernel/asm/memory/metadata.asm @@ -278,7 +278,7 @@ global sys_basefee: EXIT_KERNEL /// Blob-related macros are only available for Ethereum mainnet. -#[cfg(not(feature = polygon_pos, cdk_erigon))] +#[cfg(feature = eth_mainnet)] { global sys_blobhash: // stack: kexit_info, index 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 a5aee8b08..6ee92ca2b 100644 --- a/evm_arithmetization/src/cpu/kernel/asm/transactions/common_decoding.asm +++ b/evm_arithmetization/src/cpu/kernel/asm/transactions/common_decoding.asm @@ -245,7 +245,7 @@ sload_with_addr: JUMP /// Type-3 transactions specific decoding helper macros. -#[cfg(not(feature = polygon_pos, cdk_erigon))] +#[cfg(feature = eth_mainnet)] { %macro decode_and_store_max_fee_per_blob_gas // stack: rlp_addr diff --git a/evm_arithmetization/src/cpu/kernel/asm/transactions/router.asm b/evm_arithmetization/src/cpu/kernel/asm/transactions/router.asm index 47eb30d19..17108c0ec 100644 --- a/evm_arithmetization/src/cpu/kernel/asm/transactions/router.asm +++ b/evm_arithmetization/src/cpu/kernel/asm/transactions/router.asm @@ -34,7 +34,7 @@ read_txn_from_memory: // stack: rlp_start_addr, retdest // Only Ethereum mainnet supports Blob-transactions. - #[cfg(not(feature = polygon_pos,cdk_erigon))] + #[cfg(feature = eth_mainnet)] { DUP1 MLOAD_GENERAL From fde0be2979dd46e153d1e55b07fb519da05e5d90 Mon Sep 17 00:00:00 2001 From: Robin Salen Date: Fri, 6 Sep 2024 10:39:23 -0400 Subject: [PATCH 12/17] Comment --- evm_arithmetization/src/cpu/kernel/asm/cdk_pre_execution.asm | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/evm_arithmetization/src/cpu/kernel/asm/cdk_pre_execution.asm b/evm_arithmetization/src/cpu/kernel/asm/cdk_pre_execution.asm index 27993d178..a6598517d 100644 --- a/evm_arithmetization/src/cpu/kernel/asm/cdk_pre_execution.asm +++ b/evm_arithmetization/src/cpu/kernel/asm/cdk_pre_execution.asm @@ -72,10 +72,9 @@ global update_scalable_l1blockhash: KECCAK_GENERAL // stack: slot, l1blockhash, retdest %slot_to_storage_key - // stack: slot, 1blockhash, retdest - // stack: storage_key, 1blockhash, retdest + // stack: storage_key, l1blockhash, retdest PUSH @GLOBAL_EXIT_ROOT_MANAGER_L2_STATE_KEY - // stack: state_key, storage_key, 1blockhash, retdest + // stack: state_key, storage_key, l1blockhash, retdest %insert_slot_with_value_from_keys // stack: retdest JUMP From caec9a5cc47b80585d260f07ac8b119e411be5f6 Mon Sep 17 00:00:00 2001 From: Robin Salen Date: Fri, 6 Sep 2024 10:41:37 -0400 Subject: [PATCH 13/17] Add missing fix from feat/feature_gat_chain --- evm_arithmetization/src/cpu/kernel/asm/cdk_pre_execution.asm | 2 +- evm_arithmetization/src/cpu/kernel/constants/mod.rs | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/evm_arithmetization/src/cpu/kernel/asm/cdk_pre_execution.asm b/evm_arithmetization/src/cpu/kernel/asm/cdk_pre_execution.asm index a6598517d..90e76cb60 100644 --- a/evm_arithmetization/src/cpu/kernel/asm/cdk_pre_execution.asm +++ b/evm_arithmetization/src/cpu/kernel/asm/cdk_pre_execution.asm @@ -8,7 +8,7 @@ global pre_block_execution: // stack: (empty) PUSH txn_loop // stack: retdest - PUSH @ADDRESS_SCALABLE_L2_STATE_KEY + PUSH @ADDRESS_SCALABLE_L2 %is_non_existent %jumpi(create_scalable_l2_account) diff --git a/evm_arithmetization/src/cpu/kernel/constants/mod.rs b/evm_arithmetization/src/cpu/kernel/constants/mod.rs index 1c076040a..853e5500c 100644 --- a/evm_arithmetization/src/cpu/kernel/constants/mod.rs +++ b/evm_arithmetization/src/cpu/kernel/constants/mod.rs @@ -85,6 +85,10 @@ pub(crate) fn evm_constants() -> HashMap { global_exit_root::GLOBAL_EXIT_ROOT_STORAGE_POS.0.into(), U256::from(global_exit_root::GLOBAL_EXIT_ROOT_STORAGE_POS.1), ); + c.insert( + global_exit_root::ADDRESS_SCALABLE_L2.0.into(), + U256::from_big_endian(&global_exit_root::ADDRESS_SCALABLE_L2.1), + ); c.insert( global_exit_root::ADDRESS_SCALABLE_L2_STATE_KEY.0.into(), U256::from_big_endian(&global_exit_root::ADDRESS_SCALABLE_L2_STATE_KEY.1), From 05830e78a48f84b5a026dd8d4fa11de1cd01b01d Mon Sep 17 00:00:00 2001 From: Robin Salen Date: Fri, 6 Sep 2024 12:45:15 -0400 Subject: [PATCH 14/17] Clippy --- .github/workflows/ci.yml | 2 +- Cargo.toml | 14 +++++------ .../src/cpu/kernel/aggregator.rs | 5 +++- proof_gen/Cargo.toml | 9 +++++-- trace_decoder/Cargo.toml | 20 +++++++++++++--- zero_bin/common/Cargo.toml | 19 +++++++++++---- zero_bin/leader/Cargo.toml | 15 +++++++++--- zero_bin/ops/Cargo.toml | 23 ++++++++++++++---- zero_bin/prover/Cargo.toml | 24 +++++++++++++++---- zero_bin/rpc/Cargo.toml | 22 +++++++++++++---- zero_bin/verifier/Cargo.toml | 16 +++++++++++-- 11 files changed, 130 insertions(+), 39 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 98051cc55..6f9d24ee7 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -240,7 +240,7 @@ jobs: 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/src/cpu/kernel/aggregator.rs b/evm_arithmetization/src/cpu/kernel/aggregator.rs index fded2f0ef..4ac839659 100644 --- a/evm_arithmetization/src/cpu/kernel/aggregator.rs +++ b/evm_arithmetization/src/cpu/kernel/aggregator.rs @@ -13,8 +13,11 @@ pub const NUMBER_KERNEL_FILES: usize = if cfg!(feature = "eth_mainnet") { 157 } else if cfg!(feature = "cdk_erigon") { 156 -} else { +} else if cfg!(feature = "polygon_pos") { 155 +} else { + // unreachable + 0 }; pub static KERNEL_FILES: [&str; NUMBER_KERNEL_FILES] = [ 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..a715900fc 100644 --- a/zero_bin/common/Cargo.toml +++ b/zero_bin/common/Cargo.toml @@ -14,32 +14,41 @@ 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", +] From e2c9b37240863ee77a93611366be7a66b126bbd7 Mon Sep 17 00:00:00 2001 From: Robin Salen Date: Fri, 6 Sep 2024 13:42:01 -0400 Subject: [PATCH 15/17] Missing worker config --- zero_bin/worker/Cargo.toml | 11 +++++++++++ 1 file changed, 11 insertions(+) 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 From 4aca1a24258104e56462886ec534fcb2044fce23 Mon Sep 17 00:00:00 2001 From: Robin Salen <30937548+Nashtare@users.noreply.github.com> Date: Sat, 7 Sep 2024 04:03:47 +0900 Subject: [PATCH 16/17] Apply suggestion for typed transactions Co-authored-by: Hamy Ratoanina --- evm_arithmetization/src/cpu/kernel/asm/transactions/router.asm | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/evm_arithmetization/src/cpu/kernel/asm/transactions/router.asm b/evm_arithmetization/src/cpu/kernel/asm/transactions/router.asm index 17108c0ec..eaef7efd7 100644 --- a/evm_arithmetization/src/cpu/kernel/asm/transactions/router.asm +++ b/evm_arithmetization/src/cpu/kernel/asm/transactions/router.asm @@ -44,7 +44,7 @@ read_txn_from_memory: // 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) From 530faf44dfc0249449fbbd9b30cd20ab57b90c5f Mon Sep 17 00:00:00 2001 From: Robin Salen Date: Fri, 6 Sep 2024 15:25:09 -0400 Subject: [PATCH 17/17] Misc --- evm_arithmetization/src/recursive_verifier.rs | 7 ++++--- zero_bin/common/Cargo.toml | 1 - 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/evm_arithmetization/src/recursive_verifier.rs b/evm_arithmetization/src/recursive_verifier.rs index b120f1da4..29344ff11 100644 --- a/evm_arithmetization/src/recursive_verifier.rs +++ b/evm_arithmetization/src/recursive_verifier.rs @@ -380,9 +380,10 @@ 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`. + // 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] = [ ( diff --git a/zero_bin/common/Cargo.toml b/zero_bin/common/Cargo.toml index a715900fc..0b389cf9f 100644 --- a/zero_bin/common/Cargo.toml +++ b/zero_bin/common/Cargo.toml @@ -32,7 +32,6 @@ evm_arithmetization = { workspace = true } proof_gen = { workspace = true } trace_decoder = { workspace = true } - [build-dependencies] cargo_metadata = { workspace = true } vergen = { workspace = true }