Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Linked lists for the state trie #402

Merged
merged 138 commits into from
Aug 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
138 commits
Select commit Hold shift + click to select a range
a50e2db
[WIP] add account to linked list
4l0n50 May 3, 2024
52dc55d
Add account linked list and some unit tests
4l0n50 May 3, 2024
d242757
Modify tests for insetions and fix bugs
4l0n50 May 6, 2024
4558a38
Fix deletion test
4l0n50 May 6, 2024
c369aa5
[WIP] Getting trie data without leaves
4l0n50 May 7, 2024
ecf0e86
[WIP] changes during the flights
4l0n50 May 22, 2024
65773d8
Fix storage ll error
4l0n50 May 24, 2024
c9e3b4f
Add missing file
4l0n50 May 24, 2024
ba87c79
[WIP] checking consistency between linked list and state trie
4l0n50 May 24, 2024
6fc8c22
[WIP] addr 0x798c6047767c10f653ca157a7f66a592a1d6ca550cae352912be0b07…
4l0n50 May 27, 2024
31a850f
[WIP] add missing nibbles to key
4l0n50 May 27, 2024
d1df4c5
Fix accounts insertions
4l0n50 May 28, 2024
7689629
Check storage reads
4l0n50 May 28, 2024
29b79b1
Add segments to preinitialization
hratoanina May 29, 2024
edfc137
[WIP] Unreasonable offset
4l0n50 May 29, 2024
796087b
[WIP] Erc721 error
4l0n50 May 29, 2024
566ccb5
[WIP] uncomment ll reads
4l0n50 May 29, 2024
12e63ea
[WIP] Fixing iterator
4l0n50 May 30, 2024
c1f47dd
Fix unit tests
4l0n50 May 31, 2024
9a9323d
Fix erc721 error
4l0n50 May 31, 2024
6c93057
mend
4l0n50 May 31, 2024
48d1cfe
Remove debug info
May 31, 2024
c938cad
mend
May 31, 2024
dba0967
[WIP] hashing
4l0n50 Jun 3, 2024
8a386f9
Provide constants non-deterministically
hratoanina Jun 3, 2024
5deb97d
Update journaling
LindaGuiga Jun 4, 2024
fbb216b
Update search_account and read_accounts_linked_lists
LindaGuiga Jun 4, 2024
8c3ac79
Constraint state and storage leaves
Jun 4, 2024
1232b9a
Update slot and account search methods in linked_lists and update rev…
LindaGuiga Jun 4, 2024
5d43ff4
Fix asm
LindaGuiga Jun 5, 2024
bd1215d
Some fixes and debugging
LindaGuiga Jun 7, 2024
c4f410d
Fix hash mismatch
Jun 7, 2024
f650e8a
Fix bug while setting storage payloads
Jun 7, 2024
55255f6
Merge remote-tracking branch 'refs/remotes/origin/linked_lists' into …
Jun 7, 2024
128f614
Add functions for updating final trie
Jun 10, 2024
95e3001
[WIP] eliminating trie call
4l0n50 Jun 11, 2024
660a4f4
[WIP] Fix kexit_data issue
4l0n50 Jun 11, 2024
b9e2307
Merge with journaling branch
4l0n50 Jun 11, 2024
287cddd
Merge with journaling branch
4l0n50 Jun 11, 2024
9915fed
[WIP] set final tries
4l0n50 Jun 11, 2024
9a28eb5
Mutate storage payload on insertions
4l0n50 Jun 12, 2024
09a03b2
Fix deletions in final trie computation
4l0n50 Jun 12, 2024
7661bce
Remove double hashing of the initial state trie
4l0n50 Jun 12, 2024
2b666db
Merge branch 'develop' into linked_lists
Nashtare Jun 12, 2024
a144892
Misc
Nashtare Jun 12, 2024
dbc5a6a
trace_decoder/Cargo.toml
4l0n50 Jun 13, 2024
6bea276
Fix return from read_storage_linked_list_w_addr
Nashtare Jun 13, 2024
7660051
[WIP] debugging unit tests
4l0n50 Jun 13, 2024
67fd5cb
Merge remote-tracking branch 'refs/remotes/origin/linked_lists' into …
4l0n50 Jun 13, 2024
f0068aa
Fix set_payload_storage_extension and bring back final gas check
Nashtare Jun 13, 2024
885fe35
Merge remote-tracking branch 'refs/remotes/origin/linked_lists' into …
4l0n50 Jun 13, 2024
a4c3f91
Fix failing shanghai blocks
4l0n50 Jun 14, 2024
3922c06
Fix run_next_addresses_remove and some revertions
LindaGuiga Jun 21, 2024
24e6e6b
Some journaling fixes
LindaGuiga Jun 24, 2024
4355a51
FIx revert_storage_change and revert_account_created
LindaGuiga Jun 24, 2024
33235a9
Fix delete account
4l0n50 Jun 24, 2024
f54864a
[WIP] fixing LoopCallsDepthThenRevert3_d0g0v0_Shanghai.json
4l0n50 Jun 24, 2024
8945002
Add an overwrite version of account insertion and use it for mpt_inse…
LindaGuiga Jun 25, 2024
87b0c63
Fix final state trie hash mismatch
4l0n50 Jun 25, 2024
ef231c0
Fix insert_new_slot_with_value
LindaGuiga Jun 25, 2024
44e316e
Debugging variedContext_d10g0v0_Shanghai.json
4l0n50 Jun 26, 2024
29ca9df
Fix variedContext_d10g0v0_Shanghai
4l0n50 Jun 26, 2024
bf91f44
[WIP] Fixing vitalikTransactionTestParis_d0g0v0_Shanghai
4l0n50 Jun 26, 2024
c7ac311
Merge with develop
4l0n50 Jun 26, 2024
bc7341d
Merge remote-tracking branch 'origin/develop' into linked_lists
4l0n50 Jun 26, 2024
f34c4ed
Merge remote-tracking branch 'origin/develop' into linked_lists
Nashtare Jun 27, 2024
b83871d
Delete all associated slots when an account is deleted
LindaGuiga Jun 27, 2024
c6fed71
Fix run_next_remove_address_slots
LindaGuiga Jun 27, 2024
268604e
Copy initial accounts and slots
4l0n50 Jun 27, 2024
7e99b14
Fix find condition in run_next_remove_address_slots
LindaGuiga Jun 27, 2024
f769fa6
Fix erc721
4l0n50 Jul 1, 2024
cc71c4b
Deep copy of accounts and slots
4l0n50 Jul 1, 2024
5d4737d
Merge remote-tracking branch 'origin/linked_lists' into linked_lists_…
4l0n50 Jul 2, 2024
8111883
[WIP] Testing evm test suite
4l0n50 Jul 2, 2024
05d75ab
Fix most unit tests and fix revert_account_created
LindaGuiga Jul 2, 2024
f35c2c8
FIx linked list test and a bit of cleanup
LindaGuiga Jul 2, 2024
9bed611
Start merge
LindaGuiga Jul 2, 2024
244c9a8
[WIP] Debugging /stExample/basefeeExample_d0g0v0_Shanghai
4l0n50 Jul 3, 2024
54b360a
Fix merge and add batch sizes to the benchmark
LindaGuiga Jul 3, 2024
da7902b
Fix test_only in zero_bin
LindaGuiga Jul 3, 2024
1f8d853
Merge branch 'develop' into merge-continuations-develop
LindaGuiga Jul 3, 2024
ca490c1
Fix rlp pointers error
4l0n50 Jul 3, 2024
a9dc130
Minor
4l0n50 Jul 3, 2024
c07c4a4
Remove panic
Nashtare Jul 3, 2024
cb93551
Remove outdated counter update in insert_account_with_overwrite
4l0n50 Jul 3, 2024
53708dd
Merge remote-tracking branch 'refs/remotes/origin/linked_lists_late_h…
4l0n50 Jul 4, 2024
c1d8b4c
[WIP] Debugging InitCollisionParis_d2g0v0_Shanghai
4l0n50 Jul 4, 2024
eaddcc1
[WIP] Debugging stCallCodes/callcallcodecallcode_011_SuicideEnd_d0g0v…
4l0n50 Jul 4, 2024
29c23a9
Fix remove_all_slots
LindaGuiga Jul 4, 2024
9c2a58b
Merge Linda's callcallcodecallcode_011_SuicideEnd_d0g0v0_Shanghai
4l0n50 Jul 4, 2024
d1a647e
Merge remote-tracking branch 'refs/remotes/origin/linked_lists_late_h…
4l0n50 Jul 4, 2024
71e3eee
Clean code
4l0n50 Jul 4, 2024
352767f
Fix account code initialize mpts
4l0n50 Jul 4, 2024
a31692a
Apply comments and fix CI.
LindaGuiga Jul 4, 2024
2ce9465
Improve remove_all_slots_loop
LindaGuiga Jul 4, 2024
9d6072b
Fix stack comment
Nashtare Jul 5, 2024
899d471
Misc, faster get_valid_slot_ptr
Nashtare Jul 5, 2024
c9ad38e
[WIP] Debugging erc20
4l0n50 Jul 5, 2024
e4adcb0
Remove counter update and cold_access
Nashtare Jul 5, 2024
5717dbc
Merge branch 'merge-continuations-develop' into linked_lists_continua…
LindaGuiga Jul 5, 2024
bb4e2d2
Fix log_opcode circuit sizes
LindaGuiga Jul 5, 2024
99d0b8a
Fix stack comment and remove ctr update
Nashtare Jul 5, 2024
e59e282
Fix preinitialization
LindaGuiga Jul 8, 2024
ac6f85e
Fix unit tests
4l0n50 Jul 9, 2024
74c55a6
Debugging stShift/shr01_d0g0v0_Shanghai
4l0n50 Jul 10, 2024
6aeb8d3
Fixing shiftSignedCombinations_d0g0v0_Shanghai
4l0n50 Jul 10, 2024
6a10adc
Remove counter assertions from linked_lists tests
LindaGuiga Jul 11, 2024
af1c2c0
Merge branch 'linked_lists' into linked_lists_late_hash
LindaGuiga Jul 11, 2024
e395474
Merge branch 'linked_lists_continuations' into linked_lists_late_hash
LindaGuiga Jul 11, 2024
5074895
Fix preinitialization and start cleanup
LindaGuiga Jul 11, 2024
6e043f9
Fix test_process_receipt
LindaGuiga Jul 11, 2024
09a4967
Merge remote-tracking branch 'origin/feat/continuations' into late_ha…
Nashtare Jul 11, 2024
439b4a0
Fix MPT insert tests
Nashtare Jul 11, 2024
d3dd09a
Add check in mpt_insert tests
LindaGuiga Jul 12, 2024
b9b8c5c
Additional fixes
LindaGuiga Jul 12, 2024
9d994c1
Pass preinitialized_segments when necessary
LindaGuiga Jul 15, 2024
1756b03
Fix all unit tests
LindaGuiga Jul 15, 2024
19aa264
Cleanup
LindaGuiga Jul 16, 2024
e725678
More comments cleanup
LindaGuiga Jul 16, 2024
6436d12
Do not store memory content as vec
Nashtare Jul 13, 2024
dcf0575
Prevent needless conversion
Nashtare Jul 13, 2024
97b21af
Remove needless copy
Nashtare Jul 13, 2024
94a61e7
Remove needless checks
Nashtare Jul 13, 2024
3c915f3
Use tuple_windows instead
Nashtare Jul 13, 2024
526c456
Typo
Nashtare Jul 14, 2024
b992e9e
Remove leftover
Nashtare Jul 16, 2024
d9840d4
Remove unrelated changes
Nashtare Jul 16, 2024
b0c4248
Fix clone_slot
LindaGuiga Jul 16, 2024
80212ae
Remove assert 0 from clone_slot
LindaGuiga Jul 16, 2024
7445d53
Fix next_node_ok_with_value
LindaGuiga Jul 16, 2024
b46da0e
Apply comments and cleanup
LindaGuiga Jul 18, 2024
04ab8f7
Fix next_node_ok_with_value and tiny cleanup
LindaGuiga Jul 22, 2024
90cb9d1
Start addressing comments
LindaGuiga Jul 23, 2024
f92c4eb
Remove unnecessary linked_lists methods and payload_ptr
LindaGuiga Jul 23, 2024
c0f8886
Start applying comments
LindaGuiga Jul 26, 2024
7e7deb0
Change global metadata names and check linked lists lengths
LindaGuiga Jul 26, 2024
b7e9d6c
Cleanup comments
LindaGuiga Jul 26, 2024
3b1fe8a
Apply comments
LindaGuiga Aug 1, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions evm_arithmetization/src/cpu/kernel/aggregator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,9 @@ pub(crate) fn combined_kernel() -> Kernel {
include_str!("asm/mpt/insert/insert_extension.asm"),
include_str!("asm/mpt/insert/insert_leaf.asm"),
include_str!("asm/mpt/insert/insert_trie_specific.asm"),
include_str!("asm/mpt/linked_list/linked_list.asm"),
include_str!("asm/mpt/linked_list/initial_tries.asm"),
include_str!("asm/mpt/linked_list/final_tries.asm"),
include_str!("asm/mpt/read.asm"),
include_str!("asm/mpt/storage/storage_read.asm"),
include_str!("asm/mpt/storage/storage_write.asm"),
Expand Down
12 changes: 4 additions & 8 deletions evm_arithmetization/src/cpu/kernel/asm/core/access_lists.asm
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,7 @@ global init_access_lists:
// Store @U256_MAX at the beginning of the segment
PUSH @SEGMENT_ACCESSED_ADDRESSES // ctx == virt == 0
DUP1
PUSH @U256_MAX
MSTORE_GENERAL
%mstore_u256_max
// Store @SEGMENT_ACCESSED_ADDRESSES at address 1
%increment
DUP1
Expand All @@ -38,8 +37,7 @@ global init_access_lists:
// Store @U256_MAX at the beginning of the segment
PUSH @SEGMENT_ACCESSED_STORAGE_KEYS // ctx == virt == 0
DUP1
PUSH @U256_MAX
MSTORE_GENERAL
%mstore_u256_max
// Store @SEGMENT_ACCESSED_STORAGE_KEYS at address 3
%add_const(3)
DUP1
Expand Down Expand Up @@ -201,8 +199,7 @@ global remove_accessed_addresses:
MLOAD_GENERAL
// stack: next_next_ptr, next_next_ptr_ptr, next_ptr_ptr, addr, retdest
SWAP1
PUSH @U256_MAX
MSTORE_GENERAL
%mstore_u256_max
// stack: next_next_ptr, next_ptr_ptr, addr, retdest
MSTORE_GENERAL
POP
Expand Down Expand Up @@ -385,8 +382,7 @@ global remove_accessed_storage_keys:
MLOAD_GENERAL
// stack: next_next_ptr, next_next_ptr_ptr, next_ptr_ptr, addr, key, retdest
SWAP1
PUSH @U256_MAX
MSTORE_GENERAL
%mstore_u256_max
// stack: next_next_ptr, next_ptr_ptr, addr, key, retdest
MSTORE_GENERAL
%pop2
Expand Down
6 changes: 6 additions & 0 deletions evm_arithmetization/src/cpu/kernel/asm/core/util.asm
Original file line number Diff line number Diff line change
Expand Up @@ -93,3 +93,9 @@
SET_CONTEXT
// stack: (empty)
%endmacro

%macro mstore_u256_max
// stack: addr
PUSH @U256_MAX
MSTORE_GENERAL
%endmacro
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,10 @@ revert_account_destroyed_contd:
SWAP1
// Remove `prev_balance` from `target`'s balance.
// stack: target, address, prev_balance, retdest
%mpt_read_state_trie
%read_accounts_linked_list
// stack: target_payload_ptr, address, prev_balance, retdest
DUP1
%assert_nonzero
%add_const(1)
// stack: target_balance_ptr, address, prev_balance, retdest
DUP3
Expand All @@ -25,8 +28,12 @@ revert_account_destroyed_contd:
SUB SWAP1 %mstore_trie_data
// Set `address`'s balance to `prev_balance`.
LindaGuiga marked this conversation as resolved.
Show resolved Hide resolved
// stack: address, prev_balance, retdest
%mpt_read_state_trie
%add_const(1)
%read_accounts_linked_list
// stack: account_payload_ptr, prev_balance, retdest
DUP1
%assert_nonzero
%increment
// stack: account_balance_payload_ptr, prev_balance, retdest
%mstore_trie_data
JUMP

Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@ global revert_code_change:
POP
%journal_load_2
// stack: address, prev_codehash, retdest
%mpt_read_state_trie
%read_accounts_linked_list
// stack: account_ptr, prev_codehash, retdest
DUP1 %assert_nonzero
// stack: account_ptr, prev_codehash, retdest
%add_const(3)
// stack: codehash_ptr, prev_codehash, retdest
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,10 @@ global revert_nonce_change:
POP
%journal_load_2
// stack: address, prev_nonce, retdest
%mpt_read_state_trie
// stack: nonce_ptr, prev_nonce retdest
%read_accounts_linked_list
// stack: payload_ptr, prev_nonce, retdest
DUP1 %assert_nonzero
// stack: nonce_ptr, prev_nonce, retdest
%mstore_trie_data
// stack: retdest
JUMP
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,47 +11,16 @@ global revert_storage_change:
// stack: address, slot, prev_value, retdest
DUP3 ISZERO %jumpi(delete)
// stack: address, slot, prev_value, retdest
SWAP1 %slot_to_storage_key
// stack: storage_key, address, prev_value, retdest
PUSH 64 // storage_key has 64 nibbles
// stack: 64, storage_key, address, prev_value, retdest
DUP3 %mpt_read_state_trie
DUP1 ISZERO %jumpi(panic)
// stack: account_ptr, 64, storage_key, address, prev_value, retdest
%add_const(2)
// stack: storage_root_ptr_ptr, 64, storage_key, address, prev_value, retdest
%mload_trie_data
%get_trie_data_size
DUP6 %append_to_trie_data
%stack (prev_value_ptr, storage_root_ptr, num_nibbles, storage_key, address, prev_value, retdest) ->
(storage_root_ptr, num_nibbles, storage_key, prev_value_ptr, new_storage_root, address, retdest)
%jump(mpt_insert)
%insert_slot_with_value
// stack: value_ptr
POP
JUMP

delete:
// stack: address, slot, prev_value, retdest
SWAP2 POP
%stack (slot, address, retdest) -> (slot, new_storage_root, address, retdest)
// stack: slot, address, retdest
%slot_to_storage_key
// stack: storage_key, new_storage_root, address, retdest
PUSH 64 // storage_key has 64 nibbles
// stack: 64, storage_key, new_storage_root, address, retdest
DUP4 %mpt_read_state_trie
DUP1 ISZERO %jumpi(panic)
// stack: account_ptr, 64, storage_key, new_storage_root, address, retdest
%add_const(2)
// stack: storage_root_ptr_ptr, 64, storage_key, new_storage_root, address, retdest
%mload_trie_data
// stack: storage_root_ptr, 64, storage_key, new_storage_root, address, retdest
%jump(mpt_delete)

new_storage_root:
// stack: new_storage_root_ptr, address, retdest
DUP2 %mpt_read_state_trie
// stack: account_ptr, new_storage_root_ptr, address, retdest

// Update account with our new storage root pointer.
%add_const(2)
// stack: account_storage_root_ptr_ptr, new_storage_root_ptr, address, retdest
%mstore_trie_data
// stack: address, retdest
POP JUMP
SWAP1 %addr_to_state_key
// stack: addr_key, slot_key, retdest
%jump(remove_slot)
Nashtare marked this conversation as resolved.
Show resolved Hide resolved
42 changes: 33 additions & 9 deletions evm_arithmetization/src/cpu/kernel/asm/main.asm
Original file line number Diff line number Diff line change
Expand Up @@ -67,14 +67,23 @@ global main:
// Initialize the RLP DATA pointer to its initial position,
// skipping over the preinitialized empty node.
PUSH @INITIAL_TXN_RLP_ADDR
%add_const(@MAX_RLP_BLOB_SIZE)
%mstore_global_metadata(@GLOBAL_METADATA_RLP_DATA_SIZE)

// Encode constant nodes
%initialize_rlp_segment

// Initialize trie data size.
PROVER_INPUT(trie_ptr::trie_data_size)
%mstore_global_metadata(@GLOBAL_METADATA_TRIE_DATA_SIZE)

global store_initial:
// Store the initial accounts and slots for hashing later
%store_initial_accounts
%store_initial_slots

// Initialize the state, transaction and receipt trie root pointers.
PROVER_INPUT(trie_ptr::state)
%mstore_global_metadata(@GLOBAL_METADATA_STATE_TRIE_ROOT)
global after_store_initial:
// Initialize the transaction and receipt trie root pointers.
PROVER_INPUT(trie_ptr::txn)
%mstore_global_metadata(@GLOBAL_METADATA_TXN_TRIE_ROOT)
PROVER_INPUT(trie_ptr::receipt)
Expand All @@ -83,16 +92,16 @@ global main:
global hash_initial_tries:
// We compute the length of the trie data segment in `mpt_hash` so that we
// can check the value provided by the prover.
// We initialize the segment length with 1 because the segment contains
// the null pointer `0` when the tries are empty.
PUSH 1
%mpt_hash_state_trie %mload_global_metadata(@GLOBAL_METADATA_STATE_TRIE_DIGEST_BEFORE) %assert_eq
// The trie data segment is already written by the linked lists
%get_trie_data_size

// stack: trie_data_len
%mpt_hash_txn_trie %mload_global_metadata(@GLOBAL_METADATA_TXN_TRIE_DIGEST_BEFORE) %assert_eq
// stack: trie_data_len
%mpt_hash_receipt_trie %mload_global_metadata(@GLOBAL_METADATA_RECEIPT_TRIE_DIGEST_BEFORE) %assert_eq
// stack: trie_data_full_len
%mstore_global_metadata(@GLOBAL_METADATA_TRIE_DATA_SIZE)

%set_trie_data_size

global start_txns:
// stack: (empty)
Expand Down Expand Up @@ -144,10 +153,25 @@ global perform_final_checks:
// stack: cum_gas, txn_counter, num_nibbles, txn_nb
// Check that we end up with the correct `cum_gas`, `txn_nb` and bloom filter.
%mload_global_metadata(@GLOBAL_METADATA_BLOCK_GAS_USED_AFTER) %assert_eq
DUP3 %mload_global_metadata(@GLOBAL_METADATA_TXN_NUMBER_AFTER) %assert_eq
DUP3
%mload_global_metadata(@GLOBAL_METADATA_TXN_NUMBER_AFTER) %assert_eq
%pop3

PROVER_INPUT(trie_ptr::state)

%mstore_global_metadata(@GLOBAL_METADATA_STATE_TRIE_ROOT)
%set_initial_tries
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we can make use of this call to validate the initial value of @GLOBAL_METADATA_ACCOUNTS_LINKED_LIST_LEN, if we store it somewhere?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Or maybe it would be easier to check it in store_initial_accounts (resp. `store_initial_slots) since we're iterating over the accounts (resp. slots) there?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I removed the PROVER_INPUT calls and computed the lengths in store_initial_accounts and store_initial_slots directly

%get_trie_data_size
%mpt_hash_state_trie

SWAP1 %set_trie_data_size
%mload_global_metadata(@GLOBAL_METADATA_STATE_TRIE_DIGEST_BEFORE)
%assert_eq

PUSH 1 // initial trie data length

global check_state_trie:
%set_final_tries
%mpt_hash_state_trie %mload_global_metadata(@GLOBAL_METADATA_STATE_TRIE_DIGEST_AFTER) %assert_eq
global check_txn_trie:
%mpt_hash_txn_trie %mload_global_metadata(@GLOBAL_METADATA_TXN_TRIE_DIGEST_AFTER) %assert_eq
Expand Down
41 changes: 41 additions & 0 deletions evm_arithmetization/src/cpu/kernel/asm/mpt/accounts.asm
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,44 @@
%mload_trie_data
// stack: storage_root_ptr
%endmacro

%macro clone_account
// stack: account_ptr
%get_trie_data_size
// stack: cloned_account_ptr, account_ptr
SWAP1
DUP1
// stack: nonce_ptr, account_ptr, cloned_account_ptr
// Nonce
%mload_trie_data
%append_to_trie_data
// stack: account_ptr, cloned_account_ptr
%increment
// Balance
DUP1
%mload_trie_data
%append_to_trie_data
// Storage trie root
%increment
DUP1
%mload_trie_data
%append_to_trie_data
// Codehash
%increment
%mload_trie_data
%append_to_trie_data
// stack: cloned_account_ptr
%endmacro

// The slot_ptr cannot be 0, because `insert_slot`
// is only called in `revert_storage_change` (where the case `slot_ptr = 0`
// is dealt with differently), and in `storage_write`,
// where writing 0 actually corresponds to a `delete`.
%macro clone_slot
// stack: slot_ptr
%get_trie_data_size
// stack: cloned_slot_ptr, slot_ptr
SWAP1
%mload_trie_data
%append_to_trie_data
%endmacro
16 changes: 6 additions & 10 deletions evm_arithmetization/src/cpu/kernel/asm/mpt/delete/delete.asm
Original file line number Diff line number Diff line change
Expand Up @@ -24,17 +24,13 @@ mpt_delete_leaf:
SWAP1 JUMP

global delete_account:
%stack (address, retdest) -> (address, delete_account_save, retdest)
%addr_to_state_key
// stack: key, delete_account_save, retdest
PUSH 64
// stack: 64, key, delete_account_save, retdest
%mload_global_metadata(@GLOBAL_METADATA_STATE_TRIE_ROOT)
// stack: state_root_prt, 64, key, delete_account_save, retdest
%jump(mpt_delete)
delete_account_save:
// stack: updated_state_root_ptr, retdest
%mstore_global_metadata(@GLOBAL_METADATA_STATE_TRIE_ROOT)
DUP1
%remove_account_from_linked_list
// stack: addr_to_state_key, retdest

// Now we also need to remove all the storage nodes associated with the deleted account.
%remove_all_account_slots
JUMP

%macro delete_account
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,10 +101,6 @@ global encode_account:
DUP3 %add_const(2) %mload_trie_data // storage_root_ptr = value[2]
// stack: storage_root_ptr, cur_len, rlp_pos_5, value_ptr, cur_len, retdest


PUSH debug_after_hash_storage_trie
POP

// Hash storage trie.
%mpt_hash_storage_trie
// stack: storage_root_digest, new_len, rlp_pos_5, value_ptr, cur_len, retdest
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,7 @@
// TODO: Have this take an address and do %mpt_insert_state_trie? To match mpt_read_state_trie.
global mpt_insert_state_trie:
// stack: key, value_ptr, retdest
%stack (key, value_ptr)
-> (key, value_ptr, mpt_insert_state_trie_save)
PUSH 64 // num_nibbles
%mload_global_metadata(@GLOBAL_METADATA_STATE_TRIE_ROOT)
// stack: state_root_ptr, num_nibbles, key, value_ptr, mpt_insert_state_trie_save, retdest
%jump(mpt_insert)
mpt_insert_state_trie_save:
// stack: updated_node_ptr, retdest
%mstore_global_metadata(@GLOBAL_METADATA_STATE_TRIE_ROOT)
%insert_account_with_overwrite
JUMP

%macro mpt_insert_state_trie
Expand Down
Loading
Loading