From ba69d459c6ae8e649a4c28321e4c710dff11833f Mon Sep 17 00:00:00 2001 From: 0xaatif Date: Mon, 9 Sep 2024 19:05:48 +0100 Subject: [PATCH] wip: check-subsets --- trace_decoder/Cargo.toml | 4 ++++ trace_decoder/src/lib.rs | 2 ++ trace_decoder/tests/check-subsets.rs | 33 ++++++++++++++++++++++++++++ 3 files changed, 39 insertions(+) create mode 100644 trace_decoder/tests/check-subsets.rs diff --git a/trace_decoder/Cargo.toml b/trace_decoder/Cargo.toml index bcb980852..b56d229e6 100644 --- a/trace_decoder/Cargo.toml +++ b/trace_decoder/Cargo.toml @@ -77,3 +77,7 @@ harness = false [[test]] name = "simulate-execution" harness = false + +[[test]] +name = "check-subsets" +harness = false diff --git a/trace_decoder/src/lib.rs b/trace_decoder/src/lib.rs index 88636d877..4a0bdf7b4 100644 --- a/trace_decoder/src/lib.rs +++ b/trace_decoder/src/lib.rs @@ -57,6 +57,8 @@ const _DEVELOPER_DOCS: () = (); mod interface; pub use interface::*; +pub use type1::frontend; +pub use wire::parse; mod type1; // TODO(0xaatif): https://github.com/0xPolygonZero/zk_evm/issues/275 diff --git a/trace_decoder/tests/check-subsets.rs b/trace_decoder/tests/check-subsets.rs new file mode 100644 index 000000000..a9dc4b690 --- /dev/null +++ b/trace_decoder/tests/check-subsets.rs @@ -0,0 +1,33 @@ +use common::{cases, Case}; +use itertools::Itertools; +use mpt_trie::partial_trie::PartialTrie; +use trace_decoder::{BlockTraceTriePreImages, CombinedPreImages}; + +mod common; + +fn main() -> anyhow::Result<()> { + for Case { name, trace, .. } in cases().unwrap() { + println!("{name}"); + let BlockTraceTriePreImages::Combined(CombinedPreImages { compact }) = + trace.trie_pre_images + else { + panic!() + }; + let whole = trace_decoder::frontend(trace_decoder::parse(&compact).unwrap()) + .unwrap() + .state + .as_hashed_partial_trie() + .clone(); + let all_keys = whole.keys().collect::>(); + let len = all_keys.len(); + for n in 0..len { + println!("{n}/{len}"); + for comb in all_keys.iter().copied().combinations(n) { + if let Ok(sub) = mpt_trie::trie_subsets::create_trie_subset(&whole, comb) { + assert_eq!(sub.hash(), whole.hash()) + } + } + } + } + Ok(()) +}