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

Process state trie at the end #476

Merged
merged 1 commit into from
Aug 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
16 changes: 9 additions & 7 deletions evm_arithmetization/src/cpu/kernel/asm/main.asm
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,14 @@ global perform_final_checks:
%mload_global_metadata(@GLOBAL_METADATA_TXN_NUMBER_AFTER) %assert_eq
%pop3

PUSH 1 // initial trie data length

global check_txn_trie:
%mpt_hash_txn_trie %mload_global_metadata(@GLOBAL_METADATA_TXN_TRIE_DIGEST_AFTER) %assert_eq
global check_receipt_trie:
%mpt_hash_receipt_trie %mload_global_metadata(@GLOBAL_METADATA_RECEIPT_TRIE_DIGEST_AFTER) %assert_eq
global check_state_trie:
// First, check initial trie.
PROVER_INPUT(trie_ptr::state)

%mstore_global_metadata(@GLOBAL_METADATA_STATE_TRIE_ROOT)
Expand All @@ -172,15 +180,9 @@ global perform_final_checks:
%mload_global_metadata(@GLOBAL_METADATA_STATE_TRIE_DIGEST_BEFORE)
%assert_eq

PUSH 1 // initial trie data length

global check_state_trie:
global check_final_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
global check_receipt_trie:
%mpt_hash_receipt_trie %mload_global_metadata(@GLOBAL_METADATA_RECEIPT_TRIE_DIGEST_AFTER) %assert_eq
// We don't need the trie data length here.
POP

Expand Down
8 changes: 3 additions & 5 deletions evm_arithmetization/src/cpu/kernel/tests/account_code.rs
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ pub(crate) fn prepare_interpreter<F: Field>(
account: &AccountRlp,
) -> Result<()> {
let mpt_insert_state_trie = KERNEL.global_labels["mpt_insert_state_trie"];
let check_state_trie = KERNEL.global_labels["check_state_trie"];
let check_state_trie = KERNEL.global_labels["check_final_state_trie"];
Copy link
Collaborator

Choose a reason for hiding this comment

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

I don't think this is even being used? It was probably aimed at being the halt offset but is being overwritten in tests

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It is used as the initial offset for hashing, is it not? check_txn_trie was used as a halt offset, and I should indeed remove it now, though

let mut state_trie: HashedPartialTrie = HashedPartialTrie::from(Node::Empty);
let trie_inputs = TrieInputs {
state_trie: HashedPartialTrie::from(Node::Empty),
Expand Down Expand Up @@ -527,11 +527,9 @@ fn sstore() -> Result<()> {
GlobalMetadata::StateTrieRootDigestAfter,
h2u(expected_state_trie_hash),
);
interpreter
.halt_offsets
.push(KERNEL.global_labels["check_txn_trie"]);

// Now, execute `mpt_hash_state_trie` and check that the hash is correct.
let mpt_hash_state_trie = KERNEL.global_labels["check_state_trie"];
let mpt_hash_state_trie = KERNEL.global_labels["check_final_state_trie"];
interpreter.generation_state.registers.program_counter = mpt_hash_state_trie;
interpreter.set_is_kernel(true);
interpreter.set_context(0);
Expand Down
2 changes: 1 addition & 1 deletion evm_arithmetization/src/cpu/kernel/tests/mpt/insert.rs
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ fn test_state_trie(
storage_tries: vec![],
};
let mpt_insert_state_trie = KERNEL.global_labels["mpt_insert_state_trie"];
let check_state_trie = KERNEL.global_labels["check_state_trie"];
let check_state_trie = KERNEL.global_labels["check_final_state_trie"];

let initial_stack = vec![];
let mut interpreter: Interpreter<F> = Interpreter::new(0, initial_stack, None);
Expand Down
Loading