From 8a6a253879ee2eb7b7470731b0062121745c887c Mon Sep 17 00:00:00 2001 From: Alonso Gonzalez Date: Thu, 19 Sep 2024 11:16:19 +0200 Subject: [PATCH] Address review --- .../src/cpu/kernel/interpreter.rs | 6 +-- .../src/cpu/kernel/tests/account_code.rs | 4 +- .../src/generation/linked_list.rs | 4 +- .../src/generation/prover_input.rs | 38 +++++++++---------- .../src/generation/segments.rs | 4 +- evm_arithmetization/src/generation/state.rs | 14 +++---- 6 files changed, 35 insertions(+), 35 deletions(-) diff --git a/evm_arithmetization/src/cpu/kernel/interpreter.rs b/evm_arithmetization/src/cpu/kernel/interpreter.rs index 09a96a4ce..e77f20ae9 100644 --- a/evm_arithmetization/src/cpu/kernel/interpreter.rs +++ b/evm_arithmetization/src/cpu/kernel/interpreter.rs @@ -86,7 +86,7 @@ pub(crate) fn simulate_cpu_and_get_user_jumps( log::debug!("Simulating CPU for jumpdest analysis."); - log::debug!("el bt = {:?}", interpreter.generation_state.access_lists_ptrs.accounts_ptrs); + log::debug!("el bt = {:?}", interpreter.generation_state.access_lists_ptrs.accounts); let _ = interpreter.run(); @@ -237,8 +237,8 @@ impl Interpreter { // Initialize the MPT's pointers. let (trie_root_ptrs, state_leaves, storage_leaves, trie_data) = load_linked_lists_and_txn_and_receipt_mpts( - &mut self.generation_state.state_ptrs.accounts_ptrs, - &mut self.generation_state.state_ptrs.storage_ptrs, + &mut self.generation_state.state_ptrs.accounts, + &mut self.generation_state.state_ptrs.storage, &inputs.tries, ) .expect("Invalid MPT data for preinitialization"); diff --git a/evm_arithmetization/src/cpu/kernel/tests/account_code.rs b/evm_arithmetization/src/cpu/kernel/tests/account_code.rs index 2de81c514..bafcce513 100644 --- a/evm_arithmetization/src/cpu/kernel/tests/account_code.rs +++ b/evm_arithmetization/src/cpu/kernel/tests/account_code.rs @@ -32,8 +32,8 @@ pub(crate) fn initialize_mpts( // Load all MPTs. let (mut trie_root_ptrs, state_leaves, storage_leaves, trie_data) = load_linked_lists_and_txn_and_receipt_mpts( - &mut interpreter.generation_state.state_ptrs.accounts_ptrs, - &mut interpreter.generation_state.state_ptrs.storage_ptrs, + &mut interpreter.generation_state.state_ptrs.accounts, + &mut interpreter.generation_state.state_ptrs.storage, trie_inputs, ) .expect("Invalid MPT data for preinitialization"); diff --git a/evm_arithmetization/src/generation/linked_list.rs b/evm_arithmetization/src/generation/linked_list.rs index 40b8a84b1..ca0257aa5 100644 --- a/evm_arithmetization/src/generation/linked_list.rs +++ b/evm_arithmetization/src/generation/linked_list.rs @@ -51,11 +51,11 @@ pub(crate) struct LinkedListPtrs { /// Each entry contains the pair (key, ptr) where key is the (hashed) key /// of an account in the accounts linked list, and ptr is the respective /// node address in memory. - pub(crate) accounts_ptrs: BTreeMap, + pub(crate) accounts: BTreeMap, /// Each entry contains the pair ((account_key, slot_key), ptr) where /// account_key is the (hashed) key of an account, slot_key is the slot /// key, and ptr is the respective node address in memory. - pub(crate) storage_ptrs: BTreeMap<(U256, U256), usize>, + pub(crate) storage: BTreeMap<(U256, U256), usize>, } pub(crate) fn empty_list_mem(segment: Segment) -> [Option; N] { diff --git a/evm_arithmetization/src/generation/prover_input.rs b/evm_arithmetization/src/generation/prover_input.rs index d725c66a2..ce65f8409 100644 --- a/evm_arithmetization/src/generation/prover_input.rs +++ b/evm_arithmetization/src/generation/prover_input.rs @@ -417,13 +417,13 @@ impl GenerationState { let (&pred_addr, &ptr) = self .access_lists_ptrs - .accounts_ptrs + .accounts .range(..=addr) .next_back() .unwrap_or((&U256::MAX, &(Segment::AccessedAddresses as usize))); if pred_addr != addr { - self.access_lists_ptrs.accounts_ptrs.insert( + self.access_lists_ptrs.accounts.insert( addr, u256_to_usize( self.memory @@ -442,12 +442,12 @@ impl GenerationState { let (_, &ptr) = self .access_lists_ptrs - .accounts_ptrs + .accounts .range(..addr) .next_back() .unwrap_or((&U256::MAX, &(Segment::AccessedAddresses as usize))); self.access_lists_ptrs - .accounts_ptrs + .accounts .remove(&addr) .ok_or(ProgramError::ProverInputError(InvalidInput))?; @@ -462,15 +462,15 @@ impl GenerationState { let (&(pred_addr, pred_slot_key), &ptr) = self .access_lists_ptrs - .storage_ptrs + .storage .range(..=(addr, key)) .next_back() .unwrap_or(( &(U256::MAX, U256::zero()), &(Segment::AccessedStorageKeys as usize), )); - if (pred_addr != addr || pred_slot_key != key) { - self.access_lists_ptrs.storage_ptrs.insert( + if pred_addr != addr || pred_slot_key != key { + self.access_lists_ptrs.storage.insert( (addr, key), u256_to_usize( self.memory @@ -489,7 +489,7 @@ impl GenerationState { let (_, &ptr) = self .access_lists_ptrs - .storage_ptrs + .storage .range(..(addr, key)) .next_back() .unwrap_or(( @@ -497,7 +497,7 @@ impl GenerationState { &(Segment::AccessedStorageKeys as usize), )); self.access_lists_ptrs - .storage_ptrs + .storage .remove(&(addr, key)) .ok_or(ProgramError::ProverInputError(InvalidInput))?; @@ -511,13 +511,13 @@ impl GenerationState { let (&pred_addr, &pred_ptr) = self .state_ptrs - .accounts_ptrs + .accounts .range(..=addr) .next_back() .unwrap_or((&U256::MAX, &(Segment::AccountsLinkedList as usize))); if pred_addr != addr && input_fn.0[1].as_str() == "insert_account" { - self.state_ptrs.accounts_ptrs.insert( + self.state_ptrs.accounts.insert( addr, u256_to_usize( self.memory @@ -539,7 +539,7 @@ impl GenerationState { let (&(pred_addr, pred_slot_key), &pred_ptr) = self .state_ptrs - .storage_ptrs + .storage .range(..=(addr, key)) .next_back() .unwrap_or(( @@ -547,7 +547,7 @@ impl GenerationState { &(Segment::StorageLinkedList as usize), )); if (pred_addr != addr || pred_slot_key != key) && input_fn.0[1] == "insert_slot" { - self.state_ptrs.storage_ptrs.insert( + self.state_ptrs.storage.insert( (addr, key), u256_to_usize( self.memory @@ -568,12 +568,12 @@ impl GenerationState { let (_, &ptr) = self .state_ptrs - .accounts_ptrs + .accounts .range(..addr) .next_back() .unwrap_or((&U256::MAX, &(Segment::AccountsLinkedList as usize))); self.state_ptrs - .accounts_ptrs + .accounts .remove(&addr) .ok_or(ProgramError::ProverInputError(InvalidInput))?; @@ -590,7 +590,7 @@ impl GenerationState { let (_, &ptr) = self .state_ptrs - .storage_ptrs + .storage .range(..(addr, key)) .next_back() .unwrap_or(( @@ -598,7 +598,7 @@ impl GenerationState { &(Segment::StorageLinkedList as usize), )); self.state_ptrs - .storage_ptrs + .storage .remove(&(addr, key)) .ok_or(ProgramError::ProverInputError(InvalidInput))?; @@ -616,7 +616,7 @@ impl GenerationState { let (_, &pred_ptr) = self .state_ptrs - .storage_ptrs + .storage .range(..(addr, U256::zero())) .next_back() .unwrap_or(( @@ -861,7 +861,7 @@ impl GenerationState { ) } - #[allow(dead_code)] + #[allow(dead_code)]git co pub(crate) fn get_storage_keys_access_list( &self, ) -> Result, ProgramError> { diff --git a/evm_arithmetization/src/generation/segments.rs b/evm_arithmetization/src/generation/segments.rs index 40ba2a00b..6ae1321d2 100644 --- a/evm_arithmetization/src/generation/segments.rs +++ b/evm_arithmetization/src/generation/segments.rs @@ -74,8 +74,8 @@ fn build_segment_data( trie_root_ptrs: interpreter.generation_state.trie_root_ptrs.clone(), jumpdest_table: interpreter.generation_state.jumpdest_table.clone(), next_txn_index: interpreter.generation_state.next_txn_index, - accounts: interpreter.generation_state.state_ptrs.accounts_ptrs.clone(), - storage: interpreter.generation_state.state_ptrs.storage_ptrs.clone(), + accounts: interpreter.generation_state.state_ptrs.accounts.clone(), + storage: interpreter.generation_state.state_ptrs.storage.clone(), }, } } diff --git a/evm_arithmetization/src/generation/state.rs b/evm_arithmetization/src/generation/state.rs index 65fa71d34..94617fda0 100644 --- a/evm_arithmetization/src/generation/state.rs +++ b/evm_arithmetization/src/generation/state.rs @@ -1,4 +1,4 @@ -use std::collections::{BTreeMap, HashMap}; +use std::collections::HashMap; use std::mem::size_of; use anyhow::{anyhow, bail}; @@ -400,8 +400,8 @@ impl GenerationState { let generation_state = self.get_mut_generation_state(); let (trie_roots_ptrs, state_leaves, storage_leaves, trie_data) = load_linked_lists_and_txn_and_receipt_mpts( - &mut generation_state.state_ptrs.accounts_ptrs, - &mut generation_state.state_ptrs.storage_ptrs, + &mut generation_state.state_ptrs.accounts, + &mut generation_state.state_ptrs.storage, trie_inputs, ) .expect("Invalid MPT data for preinitialization"); @@ -587,9 +587,9 @@ impl GenerationState { .clone_from(&segment_data.extra_data.trie_root_ptrs); self.jumpdest_table .clone_from(&segment_data.extra_data.jumpdest_table); - self.state_ptrs.accounts_ptrs + self.state_ptrs.accounts .clone_from(&segment_data.extra_data.accounts); - self.state_ptrs.storage_ptrs + self.state_ptrs.storage .clone_from(&segment_data.extra_data.storage); self.next_txn_index = segment_data.extra_data.next_txn_index; self.registers = RegistersState { @@ -605,7 +605,7 @@ impl GenerationState { /// the accounts `BtreeMap`. pub(crate) fn insert_all_slots_in_memory(&mut self) { let storage_mem = self.memory.get_preinit_memory(Segment::StorageLinkedList); - self.state_ptrs.storage_ptrs.extend( + self.state_ptrs.storage.extend( StorageLinkedList::from_mem_and_segment(&storage_mem, Segment::StorageLinkedList) .expect("There must be at least an empty storage linked list") .tuple_windows() @@ -627,7 +627,7 @@ impl GenerationState { pub(crate) fn insert_all_accounts_in_memory(&mut self) { let accounts_mem = self.memory.get_preinit_memory(Segment::AccountsLinkedList); - self.state_ptrs.accounts_ptrs.extend( + self.state_ptrs.accounts.extend( AccountsLinkedList::from_mem_and_segment(&accounts_mem, Segment::AccountsLinkedList) .expect("There must be at least an empty accounts linked list") .tuple_windows()