Skip to content

Commit

Permalink
Refactor access lists (#30)
Browse files Browse the repository at this point in the history
* Refactor access lists

* Apply suggestions from code review

Co-authored-by: Robin Salen <[email protected]>

* Update evm_arithmetization/src/cpu/kernel/asm/core/access_lists.asm

Co-authored-by: Robin Salen <[email protected]>

* Apply suggestions from code review

Co-authored-by: Robin Salen <[email protected]>

* Address reviews

---------

Co-authored-by: Alonso González <[email protected]>
Co-authored-by: Alonso González <[email protected]>
  • Loading branch information
3 people authored Feb 22, 2024
1 parent c68baf9 commit 735855e
Show file tree
Hide file tree
Showing 8 changed files with 714 additions and 258 deletions.
455 changes: 314 additions & 141 deletions evm_arithmetization/src/cpu/kernel/asm/core/access_lists.asm

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
// struct AccountLoaded { address }

%macro journal_add_account_loaded
// stack: address
%journal_add_1(@JOURNAL_ENTRY_ACCOUNT_LOADED)
// stack: (empty)
%endmacro

global revert_account_loaded:
Expand Down
5 changes: 5 additions & 0 deletions evm_arithmetization/src/cpu/kernel/asm/journal/journal.asm
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
// stack: journal_size
%increment
%mstore_global_metadata(@GLOBAL_METADATA_JOURNAL_LEN)
// stack: (empty)
%endmacro

%macro journal_data_size
Expand Down Expand Up @@ -65,6 +66,7 @@
%append_journal_data
// stack: ptr
%append_journal
// stack: (empty)
%endmacro

%macro journal_add_2(type)
Expand All @@ -78,6 +80,7 @@
SWAP1 %append_journal_data
// stack: ptr
%append_journal
// stack: (empty)
%endmacro

%macro journal_add_3(type)
Expand All @@ -93,6 +96,7 @@
SWAP1 %append_journal_data
// stack: ptr
%append_journal
// stack: (empty)
%endmacro

%macro journal_add_4(type)
Expand All @@ -110,6 +114,7 @@
SWAP1 %append_journal_data
// stack: ptr
%append_journal
// stack: (empty)
%endmacro

%macro journal_load_1
Expand Down
3 changes: 3 additions & 0 deletions evm_arithmetization/src/cpu/kernel/asm/main.asm
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ global main:
// Initialise the shift table
%shift_table_init

// Initialize accessed addresses and storage keys lists
%init_access_lists

// Initialize the RLP DATA pointer to its initial position (ctx == virt == 0, segment = RLP)
PUSH @SEGMENT_RLP_RAW
%mstore_global_metadata(@GLOBAL_METADATA_RLP_DATA_SIZE)
Expand Down
6 changes: 2 additions & 4 deletions evm_arithmetization/src/cpu/kernel/asm/util/assertions.asm
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,8 @@ global panic:
%endmacro

%macro assert_lt
// %assert_zero is cheaper than %assert_nonzero, so we will leverage the
// fact that (x < y) == !(x >= y).
GE
%assert_zero
LT
%assert_nonzero
%endmacro

%macro assert_lt(ret)
Expand Down
18 changes: 18 additions & 0 deletions evm_arithmetization/src/cpu/kernel/tests/account_code.rs
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,12 @@ fn test_extcodecopy() -> Result<()> {
[Segment::ContextMetadata.unscale()]
.set(GasLimit.unscale(), U256::from(1000000000000u64));

// Pre-initialize the accessed addresses list.
let init_accessed_addresses = KERNEL.global_labels["init_access_lists"];
interpreter.generation_state.registers.program_counter = init_accessed_addresses;
interpreter.push(0xdeadbeefu32.into());
interpreter.run()?;

let extcodecopy = KERNEL.global_labels["sys_extcodecopy"];

// Put random data in main memory and the `KernelAccountCode` segment for
Expand Down Expand Up @@ -327,6 +333,12 @@ fn sstore() -> Result<()> {
let initial_stack = vec![];
let mut interpreter: Interpreter<F> = Interpreter::new_with_kernel(0, initial_stack);

// Pre-initialize the accessed addresses list.
let init_accessed_addresses = KERNEL.global_labels["init_access_lists"];
interpreter.generation_state.registers.program_counter = init_accessed_addresses;
interpreter.push(0xdeadbeefu32.into());
interpreter.run()?;

// Prepare the interpreter by inserting the account in the state trie.
prepare_interpreter_all_accounts(&mut interpreter, trie_inputs, addr, &code)?;

Expand Down Expand Up @@ -417,6 +429,12 @@ fn sload() -> Result<()> {
let initial_stack = vec![];
let mut interpreter: Interpreter<F> = Interpreter::new_with_kernel(0, initial_stack);

// Pre-initialize the accessed addresses list.
let init_accessed_addresses = KERNEL.global_labels["init_access_lists"];
interpreter.generation_state.registers.program_counter = init_accessed_addresses;
interpreter.push(0xdeadbeefu32.into());
interpreter.run()?;

// Prepare the interpreter by inserting the account in the state trie.
prepare_interpreter_all_accounts(&mut interpreter, trie_inputs, addr, &code)?;
interpreter.run()?;
Expand Down
Loading

0 comments on commit 735855e

Please sign in to comment.