Skip to content

Commit

Permalink
Address review
Browse files Browse the repository at this point in the history
  • Loading branch information
4l0n50 committed Sep 19, 2024
1 parent bc0d67b commit 8a6a253
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 35 deletions.
6 changes: 3 additions & 3 deletions evm_arithmetization/src/cpu/kernel/interpreter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ pub(crate) fn simulate_cpu_and_get_user_jumps<F: RichField>(

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();

Expand Down Expand Up @@ -237,8 +237,8 @@ impl<F: RichField> Interpreter<F> {
// 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");
Expand Down
4 changes: 2 additions & 2 deletions evm_arithmetization/src/cpu/kernel/tests/account_code.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ pub(crate) fn initialize_mpts<F: RichField>(
// 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");
Expand Down
4 changes: 2 additions & 2 deletions evm_arithmetization/src/generation/linked_list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<U256, usize>,
pub(crate) accounts: BTreeMap<U256, usize>,
/// 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<const N: usize>(segment: Segment) -> [Option<U256>; N] {
Expand Down
38 changes: 19 additions & 19 deletions evm_arithmetization/src/generation/prover_input.rs
Original file line number Diff line number Diff line change
Expand Up @@ -417,13 +417,13 @@ impl<F: RichField> GenerationState<F> {

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
Expand All @@ -442,12 +442,12 @@ impl<F: RichField> GenerationState<F> {

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))?;

Expand All @@ -462,15 +462,15 @@ impl<F: RichField> GenerationState<F> {

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
Expand All @@ -489,15 +489,15 @@ impl<F: RichField> GenerationState<F> {

let (_, &ptr) = self
.access_lists_ptrs
.storage_ptrs
.storage
.range(..(addr, key))
.next_back()
.unwrap_or((
&(U256::MAX, U256::zero()),
&(Segment::AccessedStorageKeys as usize),
));
self.access_lists_ptrs
.storage_ptrs
.storage
.remove(&(addr, key))
.ok_or(ProgramError::ProverInputError(InvalidInput))?;

Expand All @@ -511,13 +511,13 @@ impl<F: RichField> GenerationState<F> {

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
Expand All @@ -539,15 +539,15 @@ impl<F: RichField> GenerationState<F> {

let (&(pred_addr, pred_slot_key), &pred_ptr) = self
.state_ptrs
.storage_ptrs
.storage
.range(..=(addr, key))
.next_back()
.unwrap_or((
&(U256::MAX, U256::zero()),
&(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
Expand All @@ -568,12 +568,12 @@ impl<F: RichField> GenerationState<F> {

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))?;

Expand All @@ -590,15 +590,15 @@ impl<F: RichField> GenerationState<F> {

let (_, &ptr) = self
.state_ptrs
.storage_ptrs
.storage
.range(..(addr, key))
.next_back()
.unwrap_or((
&(U256::MAX, U256::zero()),
&(Segment::StorageLinkedList as usize),
));
self.state_ptrs
.storage_ptrs
.storage
.remove(&(addr, key))
.ok_or(ProgramError::ProverInputError(InvalidInput))?;

Expand All @@ -616,7 +616,7 @@ impl<F: RichField> GenerationState<F> {

let (_, &pred_ptr) = self
.state_ptrs
.storage_ptrs
.storage
.range(..(addr, U256::zero()))
.next_back()
.unwrap_or((
Expand Down Expand Up @@ -861,7 +861,7 @@ impl<F: RichField> GenerationState<F> {
)
}

#[allow(dead_code)]
#[allow(dead_code)]git co
pub(crate) fn get_storage_keys_access_list(
&self,
) -> Result<LinkedList<STORAGE_KEYS_ACCESS_LIST_LEN>, ProgramError> {
Expand Down
4 changes: 2 additions & 2 deletions evm_arithmetization/src/generation/segments.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,8 @@ fn build_segment_data<F: RichField>(
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(),
},
}
}
Expand Down
14 changes: 7 additions & 7 deletions evm_arithmetization/src/generation/state.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use std::collections::{BTreeMap, HashMap};
use std::collections::HashMap;
use std::mem::size_of;

use anyhow::{anyhow, bail};
Expand Down Expand Up @@ -400,8 +400,8 @@ impl<F: RichField> GenerationState<F> {
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");
Expand Down Expand Up @@ -587,9 +587,9 @@ impl<F: RichField> GenerationState<F> {
.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 {
Expand All @@ -605,7 +605,7 @@ impl<F: RichField> GenerationState<F> {
/// 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()
Expand All @@ -627,7 +627,7 @@ impl<F: RichField> GenerationState<F> {

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()
Expand Down

0 comments on commit 8a6a253

Please sign in to comment.