Skip to content

Commit

Permalink
feat: expand trace decoder tests
Browse files Browse the repository at this point in the history
  • Loading branch information
atanmarko committed Jul 15, 2024
1 parent 3cdecff commit a47498b
Show file tree
Hide file tree
Showing 10 changed files with 413 additions and 12 deletions.
2 changes: 2 additions & 0 deletions Cargo.lock

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

2 changes: 2 additions & 0 deletions trace_decoder/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ winnow = { workspace = true }
criterion = { workspace = true }
pretty_env_logger = { workspace = true }
serde_json = { workspace = true }
prover = { workspace = true }
serde_path_to_error = { workspace = true }

[[bench]]
name = "block_processing"
Expand Down
16 changes: 10 additions & 6 deletions trace_decoder/src/type1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -428,12 +428,13 @@ fn iter_leaves(node: Node) -> Box<dyn Iterator<Item = (Vec<U4>, IterLeaf)>> {
}

#[test]
fn test() {
for (ix, case) in
serde_json::from_str::<Vec<super::Case>>(include_str!("test_cases/zero_jerigon.json"))
.unwrap()
.into_iter()
.enumerate()
fn test_tries() {
for (ix, case) in serde_json::from_str::<Vec<super::Case>>(include_str!(
"../tests/data/tries/zero_jerigon.json"
))
.unwrap()
.into_iter()
.enumerate()
{
println!("case {}", ix);
let instructions = crate::wire::parse(&case.bytes).unwrap();
Expand All @@ -454,3 +455,6 @@ fn test() {
}
}
}

#[test]
fn test_witness_processing() {}
13 changes: 7 additions & 6 deletions trace_decoder/src/type2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -224,12 +224,13 @@ fn iter_leaves(node: Node) -> Box<dyn Iterator<Item = (BitVec, Either<[u8; 32],
}

#[test]
fn test() {
for (ix, case) in
serde_json::from_str::<Vec<super::Case>>(include_str!("test_cases/hermez_cdk_erigon.json"))
.unwrap()
.into_iter()
.enumerate()
fn test_tries() {
for (ix, case) in serde_json::from_str::<Vec<super::Case>>(include_str!(
"../tests/data/tries/hermez_cdk_erigon.json"
))
.unwrap()
.into_iter()
.enumerate()
{
println!("case {}", ix);
let instructions = crate::wire::parse(&case.bytes).unwrap();
Expand Down
File renamed without changes.

Large diffs are not rendered by default.

69 changes: 69 additions & 0 deletions trace_decoder/tests/inputs_generation.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
use std::{fs, path::PathBuf};

use evm_arithmetization::GenerationInputs;
use mpt_trie::partial_trie::PartialTrie;
use prover::BlockProverInput;
use trace_decoder::{OtherBlockData};

fn verify_generation_inputs(
other: OtherBlockData,
generation_inputs: Vec<GenerationInputs>,
) -> anyhow::Result<()> {
assert_eq!(
other.checkpoint_state_trie_root,
generation_inputs.first().unwrap().tries.state_trie.hash()
);
println!(">>>>>>>>> Generation inputs size: {}", generation_inputs.len());
assert!(generation_inputs
.windows(2)
.map(|inputs| {
println!(
"Checkpoint previous {} next: {} result {}",
inputs[0].trie_roots_after.state_root,
inputs[1].tries.state_trie.hash(),
inputs[0].trie_roots_after.state_root == inputs[1].tries.state_trie.hash());
inputs[0].trie_roots_after.state_root == inputs[1].tries.state_trie.hash()
})
.all(|it| it == true));
// println!(
// "Checkpoint {} first one: {}",
// other.checkpoint_state_trie_root,
// generation_inputs[0].tries.state_trie.hash()
// );
Ok(())
}

fn process_witness_files(witness_files: &[PathBuf]) -> Result<(), Box<dyn std::error::Error>> {
for file in witness_files {
let witness = fs::File::open(file)?;
let mut reader = std::io::BufReader::new(witness);
let block_prover_inputs: Vec<BlockProverInput> = serde_json::from_reader(&mut reader)?;

for block in block_prover_inputs {
let generation_inputs = trace_decoder::entrypoint(
block.block_trace,
block.other_data.clone(),
|_| unimplemented!(),
)?;
verify_generation_inputs(block.other_data, generation_inputs)?;
}
}
Ok(())
}

#[test]
fn test_jerigon_inputs_generation() -> Result<(), Box<dyn std::error::Error>> {
let jerigon_witnesses: Result<Vec<_>, _> = fs::read_dir("tests/data/witnesses/zero_jerigon")?
.map(|dir_entry| dir_entry.map(|it| it.path()))
.collect();
let jerigon_witnesses = jerigon_witnesses?;
process_witness_files(&jerigon_witnesses)
}

// #[test]
// fn test_cdk_erigon_inputs_generation() -> Result<(), Box<dyn std::error::Error>> {
// let cdk_erigon_witnesses = fs::read_dir("tests/data/witnesses/hermez_cdk_erigon")?
// .map(|it| it?.path())
// .collect();
// process_witness_files(cdk_erigon_witnesses)
// }
322 changes: 322 additions & 0 deletions witness_0xf.json

Large diffs are not rendered by default.

0 comments on commit a47498b

Please sign in to comment.