Skip to content

Commit

Permalink
Use tree based structures in EVM handler (#839)
Browse files Browse the repository at this point in the history
* use btree structures instead of hash based map and set

* put print in execute mode for cycles. (dont want to deal with traces sometimes)
  • Loading branch information
eyusufatik authored Jul 2, 2024
1 parent dca67fd commit 295bdca
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
8 changes: 4 additions & 4 deletions crates/evm/src/evm/handler.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use std::cmp::Ordering;
use std::collections::{HashMap, HashSet};
use std::collections::{BTreeMap, BTreeSet};
use std::mem::size_of;
use std::sync::Arc;

Expand Down Expand Up @@ -64,7 +64,7 @@ impl<T: CitreaExternalExt> CitreaExternalExt for &mut T {
pub(crate) struct CitreaExternal {
l1_fee_rate: u128,
current_tx_hash: Option<B256>,
tx_infos: HashMap<B256, TxInfo>,
tx_infos: BTreeMap<B256, TxInfo>,
}

impl CitreaExternal {
Expand Down Expand Up @@ -391,10 +391,10 @@ fn calc_diff_size<EXT, DB: Database>(
nonce_changed: bool,
code_changed: bool,
balance_changed: bool,
storage_changes: HashSet<&'a U256>,
storage_changes: BTreeSet<&'a U256>,
}

let mut account_changes: HashMap<&Address, AccountChange<'_>> = HashMap::new();
let mut account_changes: BTreeMap<&Address, AccountChange<'_>> = BTreeMap::new();

for entry in &journal {
match entry {
Expand Down
7 changes: 7 additions & 0 deletions crates/sovereign-sdk/adapters/risc0-bonsai/src/host.rs
Original file line number Diff line number Diff line change
Expand Up @@ -381,6 +381,13 @@ impl<'a> ZkvmHost for Risc0BonsaiHost<'a> {
let mut executor = ExecutorImpl::from_elf(env, self.elf)?;

let session = executor.run()?;
// don't delete useful while benchmarking
// println!(
// "user cycles: {}\ntotal cycles: {}\nsegments: {}",
// session.user_cycles,
// session.total_cycles,
// session.segments.len()
// );
let data = bincode::serialize(&session.journal.expect("Journal shouldn't be empty"))?;

Ok(Proof::PublicInput(data))
Expand Down

0 comments on commit 295bdca

Please sign in to comment.