Skip to content

Commit

Permalink
Fix trie_data_length mismatch
Browse files Browse the repository at this point in the history
  • Loading branch information
4l0n50 committed Sep 12, 2024
1 parent 409c563 commit 9afab40
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 32 deletions.
9 changes: 2 additions & 7 deletions evm_arithmetization/src/cpu/kernel/asm/main.asm
Original file line number Diff line number Diff line change
Expand Up @@ -220,27 +220,22 @@ global check_state_trie:
%mstore_global_metadata(@GLOBAL_METADATA_STATE_TRIE_ROOT)

PROVER_INPUT(trie_ptr::trie_data_size)
global debug_setting_the_trie_data_size:
%mstore_global_metadata(@GLOBAL_METADATA_TRIE_DATA_SIZE)

// stack: trie_data_len
%set_initial_state_trie
// stack: delta_trie_data_len, trie_data_len
global debug_la_delta:
POP
// stack: trie_data_len

PUSH @INITIAL_RLP_ADDR
// stack: rlp_start, trie_data_len
global debug_trie_data_len:
%mpt_hash_state_trie

// stack: init_state_hash, trie_data_len
// Check that the initial trie is correct.
%mload_global_metadata(@GLOBAL_METADATA_STATE_TRIE_DIGEST_BEFORE)
%assert_eq
// Check that the stored trie data length is correct.
%mload_global_metadata(@GLOBAL_METADATA_TRIE_DATA_SIZE)
global debug_me_equivoque_en_el_trie_data_size:
%mload_global_metadata(@GLOBAL_METADATA_TRIE_DATA_SIZE)
%assert_eq

// We set a dummy value as an initial trie data length,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,13 @@

global set_initial_state_trie:
%get_trie_data_size
PUSH set_initial_state_trie_after
%first_initial_slot // Skip the first node.
%mload_global_metadata(@GLOBAL_METADATA_STATE_TRIE_ROOT)
%first_initial_account // Skip the first node.
%jump(insert_all_initial_accounts)
set_initial_state_trie_after:
//stack: new_state_root, trie_data_size
//stack: new_state_root
%mstore_global_metadata(@GLOBAL_METADATA_STATE_TRIE_ROOT)
%get_trie_data_size
SUB
global debug_cuanta_mas_trie_data:
SWAP1
JUMP

%macro set_initial_state_trie
Expand All @@ -26,7 +21,7 @@ global debug_cuanta_mas_trie_data:
// the accounts_linked_list starting at `account_ptr_ptr` as well as the
// respective initial storage slots in `storage_ptr_ptr`.
// Pre stack: account_ptr_ptr, root_ptr, storage_ptr_ptr, retdest
// Post stack: new_root_ptr. // shouldn't change
// Post stack: new_root_ptr. // The value of new_root_ptr shouldn't change
global insert_all_initial_accounts:
// stack: account_ptr_ptr, root_ptr, storage_ptr_ptr, retdest
SWAP2
Expand All @@ -42,6 +37,7 @@ global insert_all_initial_accounts:
DUP2
PUSH 64
DUP6
// stack: root_ptr, nibbles, key, after_mpt_read, key, storage_ptr_ptr, root_ptr, account_ptr_ptr, retdest
%jump(mpt_read)
after_mpt_read:
//stack: trie_account_ptr_ptr, key, storage_ptr_ptr, root_ptr, account_ptr_ptr, retdest
Expand Down Expand Up @@ -114,15 +110,19 @@ insert_next_slot:
// If the value is 0, then payload_ptr = 0, and we don't need to insert a value in the `TrieData` segment.
DUP1 ISZERO %jumpi(insert_with_payload_ptr)
%get_trie_data_size // payload_ptr
SWAP1 %append_to_trie_data // append the value to the trie data segment
SWAP1
%append_to_trie_data // append the value to the trie data segment
insert_with_payload_ptr:
%stack (payload_ptr, key, addr, storage_ptr_ptr, root_ptr) -> (root_ptr, 64, key, payload_ptr, after_insert_slot, storage_ptr_ptr, addr)
%jump(mpt_insert)
%stack
(payload_ptr, key, addr, storage_ptr_ptr, root_ptr) ->
(root_ptr, 64, key, after_insert_slot, payload_ptr, storage_ptr_ptr, addr, root_ptr)
%jump(mpt_read)
after_insert_slot:
// stack: root_ptr', storage_ptr_ptr, addr, retdest
SWAP1
// stack: slot_ptr_ptr, payload_ptr, storage_ptr_ptr, addr, root_ptr, retdest
%mstore_trie_data
// stack: storage_ptr_ptr, addr, root_ptr, retdest
%next_initial_slot
// stack: storage_ptr_ptr', root_ptr', addr
%stack (storage_ptr_ptr_p, root_ptr_p, addr) -> (addr, storage_ptr_ptr_p, root_ptr_p)
// stack: storage_ptr_ptr', addr, root_ptr, retdest
SWAP1
%jump(insert_all_initial_slots)

18 changes: 7 additions & 11 deletions trace_decoder/tests/simulate-execution.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ mod common;

use anyhow::Context as _;
use common::{cases, Case};
use evm_arithmetization::testing_utils::init_logger;
use libtest_mimic::{Arguments, Trial};
use plonky2::field::goldilocks_field::GoldilocksField;

Expand All @@ -24,19 +23,16 @@ fn main() -> anyhow::Result<()> {
format!("error in `trace_decoder` for {name} at batch size {batch_size}"),
)?;
for (ix, gi) in gen_inputs.into_iter().enumerate() {
if ix == 0 && batch_size == 1 && name == "b19807080_main" {
trials.push(Trial::test(
format!("{name}@{batch_size}/{ix}"),
move || {
init_logger();
evm_arithmetization::prover::testing::simulate_execution_all_segments::<
trials.push(Trial::test(
format!("{name}@{batch_size}/{ix}"),
move || {
evm_arithmetization::prover::testing::simulate_execution_all_segments::<
GoldilocksField,
>(gi, 19)
.map_err(|e| format!("{e:?}"))?; // get the full error chain
Ok(())
},
))
}
Ok(())
},
))
}
}
}
Expand Down

0 comments on commit 9afab40

Please sign in to comment.