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

Lazy commitment zktrie #39

Merged
merged 5 commits into from
Sep 2, 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
5 changes: 3 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 13 additions & 4 deletions crates/core/src/executor/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -193,30 +193,35 @@ impl EvmExecutor<'_> {
let storage_root_before = acc_data.storage_root;
// get storage tire
cycle_tracker_start!("update storage_tire");
let mut storage_tire = zktrie_state
let mut storage_trie = zktrie_state
.zk_db
.new_trie(storage_root_before.as_fixed_bytes())
.expect("unable to get storage trie");
for (key, value) in db_acc.storage.iter() {
if !value.is_zero() {
cycle_track!(
storage_tire
storage_trie
.update_store(&key.to_be_bytes::<32>(), &value.to_be_bytes())
.expect("failed to update storage"),
"Zktrie::update_store"
);
} else {
cycle_track!(
storage_tire.delete(&key.to_be_bytes::<32>()),
storage_trie.delete(&key.to_be_bytes::<32>()),
"Zktrie::delete"
);
}

#[cfg(feature = "debug-storage")]
debug_recorder.record_storage(*addr, *key, *value);
}

if storage_trie.is_trie_dirty() {
storage_trie.prepare_root();
}

cycle_tracker_end!("update storage_tire");
acc_data.storage_root = H256::from(storage_tire.root());
acc_data.storage_root = H256::from(storage_trie.root());

#[cfg(feature = "debug-storage")]
debug_recorder.record_storage_root(*addr, acc_data.storage_root);
Expand Down Expand Up @@ -256,6 +261,10 @@ impl EvmExecutor<'_> {
cycle_tracker_end!("commit account {}", addr);
}

if zktrie.is_trie_dirty() {
zktrie.prepare_root();
}

let root_after = zktrie.root();

zktrie_state.switch_to(root_after);
Expand Down