Skip to content

Commit

Permalink
Merge pull request #15 from mir-protocol/state_hash_hack
Browse files Browse the repository at this point in the history
Temp hack for filling in the expected state trie hash
  • Loading branch information
BGluth authored and dlubarov committed Mar 7, 2023
2 parents bcb11ce + bc4fcdb commit b5e6927
Show file tree
Hide file tree
Showing 6 changed files with 74 additions and 53 deletions.
65 changes: 32 additions & 33 deletions Cargo.lock

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

3 changes: 2 additions & 1 deletion common/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,6 @@ edition = "2021"
ethereum-types = "0.14.0"
eth_trie_utils = "0.4.1"
flexi_logger = { version = "0.25.1", features = ["async"] }
plonky2_evm = { git = "https://github.com/mir-protocol/plonky2.git", rev = "6f2d99c7bce0728aff0374cf6bddff6c08b409ba" }
#plonky2_evm = { git = "https://github.com/mir-protocol/plonky2.git", rev = "6f2d99c7bce0728aff0374cf6bddff6c08b409ba" }
plonky2_evm = { path = "../../plonky2/evm" }
serde = {version = "1.0.147", features = ["derive"] }
3 changes: 2 additions & 1 deletion eth_test_parser/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ edition = "2021"
[dependencies]
common = { path = "../common" }
eth_trie_utils = "0.4.1"
plonky2_evm = { git = "https://github.com/mir-protocol/plonky2.git", rev = "6f2d99c7bce0728aff0374cf6bddff6c08b409ba" }
#plonky2_evm = { git = "https://github.com/mir-protocol/plonky2.git", rev = "6f2d99c7bce0728aff0374cf6bddff6c08b409ba" }
plonky2_evm = { path = "../../plonky2/evm" }

anyhow = { version = "1.0.66", features = ["backtrace"] }
clap = {version = "4.0.19", features = ["derive"] }
Expand Down
5 changes: 4 additions & 1 deletion eth_test_parser/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,14 @@ async fn run(ProgArgs { no_fetch, out_path }: ProgArgs) -> anyhow::Result<()> {
let generation_input_handles = get_deserialized_test_bodies()?.filter_map(|res| {
match res {
Ok((test_dir_entry, test_body)) => Some(tokio::task::spawn_blocking(move || {
// TODO: For now if there are multiple txn variants, we're just going to pick
// the first one. Later we will switch to processing all txns in the test.
let state_trie_hash = test_body.post.merge[0].hash;
(
test_dir_entry,
serde_cbor::to_vec(&ParsedTest {
plonky2_inputs: test_body.into_generation_inputs(),
expected_final_account_states: None,
expected_final_account_states: Some(state_trie_hash),
})
.unwrap(),
)
Expand Down
5 changes: 3 additions & 2 deletions evm_test_runner/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,9 @@ edition = "2021"

[dependencies]
common = { path = "../common" }
plonky2 = { version = "0.1.1", features = ["timing"] }
plonky2_evm = { git = "https://github.com/mir-protocol/plonky2.git", rev = "6f2d99c7bce0728aff0374cf6bddff6c08b409ba" }
plonky2 = { version = "0.1.3", features = ["timing"] }
#plonky2_evm = { git = "https://github.com/mir-protocol/plonky2.git", rev = "6f2d99c7bce0728aff0374cf6bddff6c08b409ba" }
plonky2_evm = { path = "../../plonky2/evm" }

anyhow = { version = "1.0", features = ["backtrace"] }
askama = "0.11.1"
Expand Down
46 changes: 31 additions & 15 deletions evm_test_runner/src/plonky2_runner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -124,22 +124,22 @@ pub(crate) fn run_plonky2_tests(parsed_tests: Vec<ParsedTestGroup>) -> Vec<TestG
.unwrap(),
);

let orig_panic_hook = panic::take_hook();
//let orig_panic_hook = panic::take_hook();

// When we catch panics from `plonky2`, they still print to `stderr` even though
// they are captured. To avoid polluting `stderr`, we temporarily replace the
// hook so that it captures the backtrace so we are able to include this in the
// test output.
panic::set_hook(Box::new(|_| {
let trace = Backtrace::new();
BACKTRACE.with(move |b| b.borrow_mut().replace(trace));
}));
//panic::set_hook(Box::new(|_| {
// let trace = Backtrace::new();
// BACKTRACE.with(move |b| b.borrow_mut().replace(trace));
//}));

let res = parsed_tests
.into_iter()
.map(|g| run_test_group(g, &mut prog_bar))
.collect();
panic::set_hook(orig_panic_hook);
//panic::set_hook(orig_panic_hook);

res
}
Expand Down Expand Up @@ -184,7 +184,7 @@ fn run_test(test: Test, bar: &mut ProgressBar) -> TestRunResult {

/// Run a test against `plonky2` and output a result based on what happens.
fn run_test_and_get_test_result(test: ParsedTest) -> TestStatus {
let proof_run_res = panic::catch_unwind(|| {
let proof_run_res: Result<_, anyhow::Error> = Ok({
let timing = TimingTree::new("prove", log::Level::Debug);

let res = prove::<GoldilocksField, KeccakGoldilocksConfig, 2>(
Expand All @@ -197,26 +197,42 @@ fn run_test_and_get_test_result(test: ParsedTest) -> TestStatus {
timing.filter(Duration::from_millis(100)).print();
res
});
//let proof_run_res = panic::catch_unwind(|| {
// let timing = TimingTree::new("prove", log::Level::Debug);

// let res = prove::<GoldilocksField, KeccakGoldilocksConfig, 2>(
// &AllStark::default(),
// &StarkConfig::standard_fast_config(),
// test.plonky2_inputs,
// &mut TimingTree::default(),
// );

// timing.filter(Duration::from_millis(100)).print();
// res
//});

let proof_run_output = match proof_run_res {
Ok(Ok(res)) => res,
Ok(Err(err)) => return TestStatus::EvmErr(err.to_string()),
Err(err) => {
let panic_str = match err.downcast::<String>() {
Ok(panic_str) => *panic_str,
Err(_) => "Unknown panic reason.".to_string(),
};
panic!("oops");
//let panic_str = match err.downcast::<String>() {
// Ok(panic_str) => *panic_str,
// Err(_) => "Unknown panic reason.".to_string(),
//};

let panic_backtrace = BACKTRACE.with(|b| b.borrow_mut().take()).unwrap();
let panic_with_backtrace_str =
format!("panic: {}\nBacktrace: {:?}", panic_str, panic_backtrace);
//let panic_backtrace = BACKTRACE.with(|b| b.borrow_mut().take()).unwrap();
//let panic_with_backtrace_str =
// format!("panic: {}\nBacktrace: {:?}", panic_str, panic_backtrace);

return TestStatus::EvmPanic(panic_with_backtrace_str);
//return TestStatus::EvmPanic(panic_with_backtrace_str);
}
};

let actual_state_trie_hash = proof_run_output.public_values.trie_roots_after.state_root;

log::info!("Expected {:?}", &test.expected_final_account_states);
log::info!("Actual {:?}", &actual_state_trie_hash);
if let Some(expected_state_trie_hash) = test.expected_final_account_states && actual_state_trie_hash != expected_state_trie_hash {
let trie_diff = TrieFinalStateDiff {
state: TrieComparisonResult::Difference(actual_state_trie_hash, expected_state_trie_hash),
Expand Down

0 comments on commit b5e6927

Please sign in to comment.