Skip to content

Commit

Permalink
Merge pull request #68 from 0xPolygonZero/evm-runner-continuations
Browse files Browse the repository at this point in the history
Tracking v0.7.0 - add continuations support in runner
  • Loading branch information
Nashtare authored Dec 2, 2024
2 parents 8842ec2 + 00906bd commit 998a38d
Show file tree
Hide file tree
Showing 11 changed files with 2,812 additions and 612 deletions.
3,347 changes: 2,758 additions & 589 deletions Cargo.lock

Large diffs are not rendered by default.

8 changes: 4 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,12 @@ keccak-hash = "0.10.0"
log = "0.4.17"
serde = "1.0.163"
serde_cbor = "0.11.2"
tokio = { version = "1.28.1" }
tokio = { version = "1.38" }

# zk-evm dependencies
plonky2 = "0.2.2"
mpt_trie = { git = "https://github.com/0xPolygonZero/zk_evm", tag = "v0.6.0" }
evm_arithmetization = { git = "https://github.com/0xPolygonZero/zk_evm", tag = "v0.6.0" }
plonky2 = "1.0.0"
mpt_trie = "0.5.0"
evm_arithmetization = "0.5.0"

[profile.release]
opt-level = 3
Expand Down
3 changes: 3 additions & 0 deletions cancun_heavy_tests_blacklist.txt
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,9 @@ randomStatetest476_d0g0v0_Cancun
randomStatetest48_d0g0v0_Cancun
randomStatetest547_d0g0v0_Cancun
randomStatetest583_d0g0v0_Cancun
shiftSignedCombinations_d0g0v0_Cancun
sar_2^254_254_d0g0v0_Cancun
shr_2^255_1_d0g0v0_Cancun
stateRevert_d4g0v0_Cancun
static_Call1MB1024Calldepth_d1g0v0_Cancun
static_Call50000_d1g0v0_Cancun
Expand Down
1 change: 1 addition & 0 deletions common/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,5 @@ ethereum-types = { workspace = true }
mpt_trie = { workspace = true }
flexi_logger = { workspace = true }
evm_arithmetization = { workspace = true }
plonky2 = { workspace = true }
serde = { workspace = true, features = ["derive"] }
16 changes: 11 additions & 5 deletions common/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,14 @@ use std::{

use anyhow::{anyhow, Context};
use ethereum_types::{Address, H256, U256};
use evm_arithmetization::proof::{BlockHashes, TrieRoots};
use evm_arithmetization::{generation::TrieInputs, proof::BlockMetadata};
use evm_arithmetization::{
generation::{GenerationInputs, TrieInputs},
proof::BlockMetadata,
proof::{BlockHashes, TrieRoots},
GenerationInputs,
};
use plonky2::{
field::{goldilocks_field::GoldilocksField, types::Field},
hash::hash_types::NUM_HASH_OUT_ELTS,
};
use serde::{Deserialize, Serialize};

Expand Down Expand Up @@ -46,7 +50,7 @@ impl ParsedTestManifest {
receipts_root: t_var.final_roots.receipts_trie_root_hash,
};
let gen_inputs = GenerationInputs {
signed_txn: Some(t_var.txn_bytes),
signed_txns: vec![t_var.txn_bytes],
tries: t_var.plonky2_metadata.tries.clone(),
trie_roots_after,
checkpoint_state_trie_root: t_var.plonky2_metadata.genesis_state_root,
Expand All @@ -57,7 +61,9 @@ impl ParsedTestManifest {
gas_used_after: t_var.plonky2_metadata.block_metadata.block_gas_used,
withdrawals: t_var.plonky2_metadata.withdrawals,
block_hashes: BlockHashes::default(),
global_exit_roots: vec![], // not part of Ethereum tests
ger_data: None,
burn_addr: None,
checkpoint_consolidated_hash: [GoldilocksField::ZERO; NUM_HASH_OUT_ELTS],
};

TestVariantRunInfo {
Expand Down
1 change: 1 addition & 0 deletions eth_test_parser/src/fs_scaffolding.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ pub(crate) fn prepare_output_dir(out_path: &Path) -> Result<()> {

/// Generate an iterator containing the deserialized test bodies (`TestBody`)
/// and their `DirEntry`s.
#[allow(clippy::type_complexity)]
pub(crate) fn get_deserialized_test_bodies(
) -> Result<impl Iterator<Item = Result<(DirEntry, Vec<TestBody>), (String, String)>>> {
Ok(get_test_files()?.map(|entry| {
Expand Down
4 changes: 4 additions & 0 deletions evm_test_runner/src/arg_parsing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,10 @@ pub(crate) struct ProgArgs {
#[arg(short = 'f', long)]
pub(crate) test_filter: Option<String>,

/// An optional max CPU log length for each segment to be generated.
#[arg(short = 'c', long)]
pub(crate) max_cpu_log_len: Option<usize>,

/// Do not run tests that have already passed in the past or that are
/// ignored.
#[arg(short = 'p', long)]
Expand Down
2 changes: 2 additions & 0 deletions evm_test_runner/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ async fn run() -> anyhow::Result<bool> {
variant_filter,
skip_passed,
witness_only,
max_cpu_log_len,
test_timeout,
blacklist_path,
simple_progress_indicator,
Expand Down Expand Up @@ -144,6 +145,7 @@ async fn run() -> anyhow::Result<bool> {
&mut persistent_test_state,
abort_recv,
witness_only,
max_cpu_log_len,
test_timeout.map(|t| t.into()),
) {
Ok(r) => r,
Expand Down
2 changes: 1 addition & 1 deletion evm_test_runner/src/persistent_run_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ pub(crate) enum PassState {

impl PassState {
// Utility method to filter out passed tests from previous runs.
fn get_passed_status(&self, witness_only: bool) -> bool {
const fn get_passed_status(&self, witness_only: bool) -> bool {
if witness_only {
matches!(
self,
Expand Down
34 changes: 24 additions & 10 deletions evm_test_runner/src/plonky2_runner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ use std::{
use common::types::TestVariantRunInfo;
use ethereum_types::U256;
use evm_arithmetization::{
prover::{prove, testing::simulate_execution},
verifier::verify_proof,
prover::testing::{prove_all_segments, simulate_execution_all_segments},
verifier::testing::verify_all_proofs,
AllStark, StarkConfig,
};
use futures::executor::block_on;
Expand Down Expand Up @@ -94,7 +94,7 @@ impl Display for TestStatus {
}

impl TestStatus {
pub(crate) fn passed(&self) -> bool {
pub(crate) const fn passed(&self) -> bool {
matches!(self, Self::PassedProof | Self::PassedWitness)
}
}
Expand Down Expand Up @@ -134,6 +134,7 @@ struct TestRunState<'a> {
persistent_test_state: &'a mut TestRunEntries,
process_aborted_recv: ProcessAbortedRecv,
witness_only: bool,
max_cpu_log_len: Option<usize>,
test_timeout: Duration,
}

Expand All @@ -143,6 +144,7 @@ pub(crate) fn run_plonky2_tests(
persistent_test_state: &mut TestRunEntries,
process_aborted: ProcessAbortedRecv,
witness_only: bool,
max_cpu_log_len: Option<usize>,
test_timeout: Option<Duration>,
) -> RunnerResult<Vec<TestGroupRunResults>> {
let num_tests = num_tests_in_groups(parsed_tests.iter());
Expand All @@ -158,6 +160,7 @@ pub(crate) fn run_plonky2_tests(
persistent_test_state,
process_aborted_recv: process_aborted,
witness_only,
max_cpu_log_len,
test_timeout,
};

Expand Down Expand Up @@ -239,7 +242,9 @@ fn run_test_or_fail_on_timeout(
t_state: &mut TestRunState,
) -> RunnerResult<TestStatus> {
block_on(async {
let proof_gen_fut = async { run_test_and_get_test_result(test, t_state.witness_only) };
let proof_gen_fut = async {
run_test_and_get_test_result(test, t_state.witness_only, t_state.max_cpu_log_len)
};
let proof_gen_with_timeout_fut = timeout(t_state.test_timeout, proof_gen_fut);
let process_aborted_fut = t_state.process_aborted_recv.recv();

Expand All @@ -257,15 +262,23 @@ fn run_test_or_fail_on_timeout(
}

/// Run a test against `plonky2` and output a result based on what happens.
fn run_test_and_get_test_result(test: TestVariantRunInfo, witness_only: bool) -> TestStatus {
fn run_test_and_get_test_result(
test: TestVariantRunInfo,
witness_only: bool,
max_cpu_log_len: Option<usize>,
) -> TestStatus {
let timing = TimingTree::new("prove", log::Level::Debug);
let max_cpu_log_len = max_cpu_log_len.unwrap_or(32); // 32 being the default maximum

match witness_only {
true => {
let res = simulate_execution::<GoldilocksField>(test.gen_inputs);
let res = simulate_execution_all_segments::<GoldilocksField>(
test.gen_inputs,
max_cpu_log_len,
);

if let Err(evm_err) = res {
return handle_evm_err(evm_err, false, "witness generation");
return handle_evm_err(evm_err.into(), false, "witness generation");
}

return TestStatus::PassedWitness;
Expand All @@ -284,10 +297,11 @@ fn run_test_and_get_test_result(test: TestVariantRunInfo, witness_only: bool) ->
inputs.block_metadata.block_gaslimit = U256::from(u32::MAX);
}

let proof_run_res = prove::<GoldilocksField, KeccakGoldilocksConfig, 2>(
let proof_run_res = prove_all_segments::<GoldilocksField, KeccakGoldilocksConfig, 2>(
&AllStark::default(),
&StarkConfig::standard_fast_config(),
inputs,
max_cpu_log_len,
&mut TimingTree::default(),
None,
);
Expand All @@ -299,9 +313,9 @@ fn run_test_and_get_test_result(test: TestVariantRunInfo, witness_only: bool) ->
Err(evm_err) => return handle_evm_err(evm_err, is_gaslimit_changed, "Proving"),
};

let verif_output = verify_proof(
let verif_output = verify_all_proofs(
&AllStark::default(),
proof_run_output,
&proof_run_output,
&StarkConfig::standard_fast_config(),
);
if verif_output.is_err() {
Expand Down
6 changes: 3 additions & 3 deletions evm_test_runner/src/test_dir_reading.rs
Original file line number Diff line number Diff line change
Expand Up @@ -157,14 +157,14 @@ async fn parse_test_sub_group(
}

fn blacklisted(blacklist: Option<&HashSet<String>>, t_name: &str) -> bool {
blacklist.map_or(false, |b_list| b_list.contains(t_name))
blacklist.is_some_and(|b_list| b_list.contains(t_name))
}

fn test_is_not_in_filter_str(filter_str: &Option<String>, file_path: &Path) -> bool {
filter_str.as_ref().map_or(false, |f_str| {
filter_str.as_ref().is_some_and(|f_str| {
file_path
.to_str()
.map_or(false, |p_str| !p_str.contains(f_str))
.is_some_and(|p_str| !p_str.contains(f_str))
})
}

Expand Down

0 comments on commit 998a38d

Please sign in to comment.