Skip to content

Commit

Permalink
update: trie diff main
Browse files Browse the repository at this point in the history
  • Loading branch information
atanmarko committed Sep 17, 2024
1 parent 89f7445 commit 9f951c9
Show file tree
Hide file tree
Showing 8 changed files with 50 additions and 31 deletions.
26 changes: 0 additions & 26 deletions Cargo.lock

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

1 change: 1 addition & 0 deletions trace_decoder/src/core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -485,6 +485,7 @@ fn middle<StateTrieT: StateTrie + Clone>(
// the transaction calling them reverted.
}

println!("Txn index: {}", txn_ix);
if do_increment_txn_ix {
txn_ix += 1;
}
Expand Down
6 changes: 6 additions & 0 deletions trace_decoder/src/observer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,12 @@ impl<StateTrieT> Observer<StateTrieT> for TriesObserver<StateTrieT> {
}
}

impl<StateTrieT> Default for TriesObserver<StateTrieT> {
fn default() -> Self {
Self::new()
}
}

/// Dummy observer which does not collect any data.
#[derive(Default, Debug)]
pub struct DefaultObserver<StateTrieT> {
Expand Down
3 changes: 2 additions & 1 deletion trace_decoder/tests/simulate-execution.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ use anyhow::Context as _;
use common::{cases, Case};
use libtest_mimic::{Arguments, Trial};
use plonky2::field::goldilocks_field::GoldilocksField;
use trace_decoder::observer::DefaultObserver;

fn main() -> anyhow::Result<()> {
let mut trials = vec![];
Expand All @@ -19,7 +20,7 @@ fn main() -> anyhow::Result<()> {
other,
} in cases()?
{
let gen_inputs = trace_decoder::entrypoint(trace, other, batch_size).context(
let gen_inputs = trace_decoder::entrypoint(trace, other, batch_size, &mut DefaultObserver::new()).context(
format!("error in `trace_decoder` for {name} at batch size {batch_size}"),
)?;
for (ix, gi) in gen_inputs.into_iter().enumerate() {
Expand Down
2 changes: 2 additions & 0 deletions zero_bin/trie_diff/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,12 @@ compat = { workspace = true }
evm_arithmetization = { workspace = true }
mpt_trie = { workspace = true }
ops = { workspace = true }
proof_gen = {workspace = true}
prover = { workspace = true }
trace_decoder = { workspace = true }
zero_bin_common = { workspace = true }


[build-dependencies]
cargo_metadata = { workspace = true }
vergen = { workspace = true }
Expand Down
6 changes: 6 additions & 0 deletions zero_bin/trie_diff/src/diff.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
use prover::BlockProverInput;
use trace_decoder::observer::TriesObserverElement;

pub fn compare_tries<StateTrieT>(_block_prover_input: BlockProverInput, _left: TriesObserverElement<StateTrieT>, _right: TriesObserverElement<StateTrieT>) {
todo!("Perform the trie diff and show differences")
}
2 changes: 1 addition & 1 deletion zero_bin/trie_diff/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1 +1 @@

pub mod diff;
35 changes: 32 additions & 3 deletions zero_bin/trie_diff/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
use std::io::Read;
use std::iter::repeat;
use std::path::PathBuf;
use std::sync::Arc;

use anyhow::Result;
use clap::{Parser, ValueHint};
use futures::{future, TryStreamExt};
use ops::register;
use paladin::directive::{Directive, IndexedStream};
use paladin::runtime::Runtime;
use prover::cli::CliProverConfig;
use prover::{BlockProverInput, ProverConfig};
Expand Down Expand Up @@ -46,7 +49,7 @@ async fn main() -> Result<()> {
runtime: paladin::config::Runtime::InMemory,
..Default::default()
};
let _runtime = Arc::new(Runtime::from_config(&paladin_config, register()).await?);
let runtime = Arc::new(Runtime::from_config(&paladin_config, register()).await?);

// Tries are computed in the kernel so no need to run proving, test_only mode is
// enough. We hardcode prover arguments that we need for trie diff computation.
Expand All @@ -56,21 +59,47 @@ async fn main() -> Result<()> {
..args.prover_config.into()
});

let seg_ops = ops::SegmentProofTestOnly {
save_inputs_on_error: prover_config.save_inputs_on_error,
};

let des = &mut serde_json::Deserializer::from_str(&buffer);
let block_prover_inputs = serde_path_to_error::deserialize::<_, Vec<BlockProverInput>>(des)?
.into_iter()
.collect::<Vec<_>>();

for block in block_prover_inputs {
let mut observer = TriesObserver::new();
let _block_generation_inputs = trace_decoder::entrypoint(
let block_generation_inputs = trace_decoder::entrypoint(
block.block_trace,
block.other_data,
prover_config.batch_size,
&mut observer,
)?;

println!("Collected batch execution tries: {}", observer.data.len());
// println!("Collected batch execution tries: {}", observer.data.len());
// println!(">>> tries: {:?}", observer.data);

let simulation = Directive::map(
IndexedStream::from(
block_generation_inputs
.into_iter()
.zip(repeat(prover_config.max_cpu_len_log)),
),
&seg_ops,
);

if let Err(e2) = simulation
.run(&runtime)
.await
.inspect_err(|e1| println!("This is error 1! {e1}"))?
.try_for_each(|_| future::ok(()))
.await
{
println!("This is error 2 {e2}");
}

//trie_diff::diff::compare_tries(block_generation_inputs, ... )
}

Ok(())
Expand Down

0 comments on commit 9f951c9

Please sign in to comment.