From 552df72e04187b7809e7897acb48e6bfec8f2bd2 Mon Sep 17 00:00:00 2001 From: Sai Deng Date: Fri, 18 Oct 2024 20:33:01 -0700 Subject: [PATCH 01/12] wip --- .../src/fixed_recursive_verifier.rs | 22 +++++++++-- evm_arithmetization/tests/empty_tables.rs | 38 ++++++++++++------- 2 files changed, 43 insertions(+), 17 deletions(-) diff --git a/evm_arithmetization/src/fixed_recursive_verifier.rs b/evm_arithmetization/src/fixed_recursive_verifier.rs index adde60d1b..b000b9098 100644 --- a/evm_arithmetization/src/fixed_recursive_verifier.rs +++ b/evm_arithmetization/src/fixed_recursive_verifier.rs @@ -9,7 +9,8 @@ use hashbrown::HashMap; use itertools::{zip_eq, Itertools}; use mpt_trie::partial_trie::{HashedPartialTrie, Node, PartialTrie}; use plonky2::field::extension::Extendable; -use plonky2::fri::FriParams; +use plonky2::fri::{FriConfig, FriParams}; +use plonky2::fri::reduction_strategies::FriReductionStrategy; use plonky2::gates::constant::ConstantGate; use plonky2::gates::noop::NoopGate; use plonky2::hash::hash_types::{MerkleCapTarget, RichField, NUM_HASH_OUT_ELTS}; @@ -62,7 +63,7 @@ use crate::verifier::initial_memory_merkle_cap; /// The recursion threshold. We end a chain of recursive proofs once we reach /// this size. -const THRESHOLD_DEGREE_BITS: usize = 13; +const THRESHOLD_DEGREE_BITS: usize = 10; /// An internal proof for a segment execution along with its public values, /// for proper connection with contiguous proofs. @@ -3100,8 +3101,21 @@ where /// gates, we might as well use a narrower witness. fn shrinking_config() -> CircuitConfig { CircuitConfig { - num_routed_wires: 40, - ..CircuitConfig::standard_recursion_config() + num_wires: 135, + num_routed_wires: 80, + num_constants: 2, + use_base_arithmetic_gate: true, + security_bits: 1, + num_challenges: 2, + zero_knowledge: false, + max_quotient_degree_factor: 8, + fri_config: FriConfig { + rate_bits: 3, + cap_height: 4, + proof_of_work_bits: 1, + reduction_strategy: FriReductionStrategy::ConstantArityBits(4, 5), + num_query_rounds: 1, + }, } } diff --git a/evm_arithmetization/tests/empty_tables.rs b/evm_arithmetization/tests/empty_tables.rs index e99c48731..5977a05c9 100644 --- a/evm_arithmetization/tests/empty_tables.rs +++ b/evm_arithmetization/tests/empty_tables.rs @@ -8,6 +8,8 @@ use evm_arithmetization::testing_utils::{init_logger, segment_with_empty_tables} use evm_arithmetization::verifier::testing::verify_all_proofs; use evm_arithmetization::AllStark; use plonky2::field::goldilocks_field::GoldilocksField; +use plonky2::fri::reduction_strategies::FriReductionStrategy; +use plonky2::fri::FriConfig; use plonky2::plonk::config::PoseidonGoldilocksConfig; use plonky2::timed; use plonky2::util::serialization::{DefaultGateSerializer, DefaultGeneratorSerializer}; @@ -24,9 +26,31 @@ fn empty_tables() -> anyhow::Result<()> { init_logger(); let all_stark = AllStark::::default(); - let config = StarkConfig::standard_fast_config(); + let config = StarkConfig { + security_bits: 1, + num_challenges: 1, + fri_config: FriConfig { + rate_bits: 1, + cap_height: 4, + proof_of_work_bits: 1, + reduction_strategy: FriReductionStrategy::ConstantArityBits(4, 5), + num_query_rounds: 1, + }, + }; let timing = &mut TimingTree::new("Empty Table Test", log::Level::Info); + // Process and generate segment proof + let all_circuits = timed!( + timing, + log::Level::Info, + "Create all recursive circuits", + AllRecursiveCircuits::::new( + &all_stark, + &[16..17, 8..9, 7..8, 4..6, 8..9, 4..5, 16..17, 16..17, 16..17], + &config, + ) + ); + // Generate segment data let (payload, mut segment_data) = segment_with_empty_tables()?; @@ -50,18 +74,6 @@ fn empty_tables() -> anyhow::Result<()> { // Verify the generated STARK proofs verify_all_proofs(&all_stark, &proofs, &config)?; - // Process and generate segment proof - let all_circuits = timed!( - timing, - log::Level::Info, - "Create all recursive circuits", - AllRecursiveCircuits::::new( - &all_stark, - &[16..17, 8..9, 7..8, 4..6, 8..9, 4..5, 16..17, 16..17, 16..17], - &config, - ) - ); - let segment_proof = timed!( timing, log::Level::Info, From 25f0269834235797552037375be73f3b6be80865 Mon Sep 17 00:00:00 2001 From: Sai Deng Date: Mon, 21 Oct 2024 11:10:51 -0700 Subject: [PATCH 02/12] update --- .../src/fixed_recursive_verifier.rs | 22 ++++--------------- evm_arithmetization/src/testing_utils.rs | 16 ++++++++++++++ evm_arithmetization/tests/empty_tables.rs | 19 ++++------------ 3 files changed, 24 insertions(+), 33 deletions(-) diff --git a/evm_arithmetization/src/fixed_recursive_verifier.rs b/evm_arithmetization/src/fixed_recursive_verifier.rs index b000b9098..adde60d1b 100644 --- a/evm_arithmetization/src/fixed_recursive_verifier.rs +++ b/evm_arithmetization/src/fixed_recursive_verifier.rs @@ -9,8 +9,7 @@ use hashbrown::HashMap; use itertools::{zip_eq, Itertools}; use mpt_trie::partial_trie::{HashedPartialTrie, Node, PartialTrie}; use plonky2::field::extension::Extendable; -use plonky2::fri::{FriConfig, FriParams}; -use plonky2::fri::reduction_strategies::FriReductionStrategy; +use plonky2::fri::FriParams; use plonky2::gates::constant::ConstantGate; use plonky2::gates::noop::NoopGate; use plonky2::hash::hash_types::{MerkleCapTarget, RichField, NUM_HASH_OUT_ELTS}; @@ -63,7 +62,7 @@ use crate::verifier::initial_memory_merkle_cap; /// The recursion threshold. We end a chain of recursive proofs once we reach /// this size. -const THRESHOLD_DEGREE_BITS: usize = 10; +const THRESHOLD_DEGREE_BITS: usize = 13; /// An internal proof for a segment execution along with its public values, /// for proper connection with contiguous proofs. @@ -3101,21 +3100,8 @@ where /// gates, we might as well use a narrower witness. fn shrinking_config() -> CircuitConfig { CircuitConfig { - num_wires: 135, - num_routed_wires: 80, - num_constants: 2, - use_base_arithmetic_gate: true, - security_bits: 1, - num_challenges: 2, - zero_knowledge: false, - max_quotient_degree_factor: 8, - fri_config: FriConfig { - rate_bits: 3, - cap_height: 4, - proof_of_work_bits: 1, - reduction_strategy: FriReductionStrategy::ConstantArityBits(4, 5), - num_query_rounds: 1, - }, + num_routed_wires: 40, + ..CircuitConfig::standard_recursion_config() } } diff --git a/evm_arithmetization/src/testing_utils.rs b/evm_arithmetization/src/testing_utils.rs index 321e7fe07..b6575765b 100644 --- a/evm_arithmetization/src/testing_utils.rs +++ b/evm_arithmetization/src/testing_utils.rs @@ -11,6 +11,9 @@ use mpt_trie::{ partial_trie::{HashedPartialTrie, Node, PartialTrie}, }; use plonky2::field::goldilocks_field::GoldilocksField; +use plonky2::fri::reduction_strategies::FriReductionStrategy; +use plonky2::fri::FriConfig; +use starky::config::StarkConfig; pub use crate::cpu::kernel::cancun_constants::*; pub use crate::cpu::kernel::constants::global_exit_root::*; @@ -27,6 +30,19 @@ pub const EMPTY_NODE_HASH: H256 = H256(hex!( "56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421" )); +/// A fast STARK config for testing purposes only. +pub const TEST_STARK_CONFIG: StarkConfig = StarkConfig { + security_bits: 1, + num_challenges: 1, + fri_config: FriConfig { + rate_bits: 1, + cap_height: 4, + proof_of_work_bits: 1, + reduction_strategy: FriReductionStrategy::ConstantArityBits(4, 5), + num_query_rounds: 1, + }, +}; + pub fn init_logger() { let _ = try_init_from_env(Env::default().filter_or(DEFAULT_FILTER_ENV, "info")); } diff --git a/evm_arithmetization/tests/empty_tables.rs b/evm_arithmetization/tests/empty_tables.rs index 5977a05c9..924fd10a8 100644 --- a/evm_arithmetization/tests/empty_tables.rs +++ b/evm_arithmetization/tests/empty_tables.rs @@ -4,17 +4,16 @@ use std::time::Duration; use evm_arithmetization::fixed_recursive_verifier::AllRecursiveCircuits; use evm_arithmetization::prover::prove; -use evm_arithmetization::testing_utils::{init_logger, segment_with_empty_tables}; +use evm_arithmetization::testing_utils::{ + init_logger, segment_with_empty_tables, TEST_STARK_CONFIG, +}; use evm_arithmetization::verifier::testing::verify_all_proofs; use evm_arithmetization::AllStark; use plonky2::field::goldilocks_field::GoldilocksField; -use plonky2::fri::reduction_strategies::FriReductionStrategy; -use plonky2::fri::FriConfig; use plonky2::plonk::config::PoseidonGoldilocksConfig; use plonky2::timed; use plonky2::util::serialization::{DefaultGateSerializer, DefaultGeneratorSerializer}; use plonky2::util::timing::TimingTree; -use starky::config::StarkConfig; /// This test focuses on testing zkVM proofs with some empty tables. #[test] @@ -26,17 +25,7 @@ fn empty_tables() -> anyhow::Result<()> { init_logger(); let all_stark = AllStark::::default(); - let config = StarkConfig { - security_bits: 1, - num_challenges: 1, - fri_config: FriConfig { - rate_bits: 1, - cap_height: 4, - proof_of_work_bits: 1, - reduction_strategy: FriReductionStrategy::ConstantArityBits(4, 5), - num_query_rounds: 1, - }, - }; + let config = TEST_STARK_CONFIG; let timing = &mut TimingTree::new("Empty Table Test", log::Level::Info); // Process and generate segment proof From 6eb7c9c969c9e4555a7f5775497aefc0b8de097f Mon Sep 17 00:00:00 2001 From: Sai Deng Date: Mon, 21 Oct 2024 11:15:11 -0700 Subject: [PATCH 03/12] change tests configs in evm_arithmetization --- evm_arithmetization/tests/add11_yml.rs | 4 ++-- evm_arithmetization/tests/empty_tables.rs | 24 +++++++++---------- evm_arithmetization/tests/erc20.rs | 3 ++- evm_arithmetization/tests/erc721.rs | 4 ++-- evm_arithmetization/tests/global_exit_root.rs | 3 ++- evm_arithmetization/tests/log_opcode.rs | 4 ++-- evm_arithmetization/tests/selfdestruct.rs | 4 ++-- evm_arithmetization/tests/simple_transfer.rs | 4 ++-- evm_arithmetization/tests/two_to_one_block.rs | 4 ++-- evm_arithmetization/tests/withdrawals.rs | 4 ++-- 10 files changed, 30 insertions(+), 28 deletions(-) diff --git a/evm_arithmetization/tests/add11_yml.rs b/evm_arithmetization/tests/add11_yml.rs index dd9bfb1ce..5a6b9617b 100644 --- a/evm_arithmetization/tests/add11_yml.rs +++ b/evm_arithmetization/tests/add11_yml.rs @@ -11,7 +11,7 @@ use evm_arithmetization::proof::{BlockHashes, BlockMetadata, TrieRoots}; use evm_arithmetization::prover::testing::prove_all_segments; use evm_arithmetization::testing_utils::{ beacon_roots_account_nibbles, beacon_roots_contract_from_storage, init_logger, - preinitialized_state_and_storage_tries, update_beacon_roots_account_storage, + preinitialized_state_and_storage_tries, update_beacon_roots_account_storage, TEST_STARK_CONFIG, }; use evm_arithmetization::verifier::testing::verify_all_proofs; use evm_arithmetization::{ @@ -208,7 +208,7 @@ fn add11_yml() -> anyhow::Result<()> { init_logger(); let all_stark = AllStark::::default(); - let config = StarkConfig::standard_fast_config(); + let config = TEST_STARK_CONFIG; let inputs = get_generation_inputs(); let max_cpu_len_log = 20; diff --git a/evm_arithmetization/tests/empty_tables.rs b/evm_arithmetization/tests/empty_tables.rs index 924fd10a8..df7087b75 100644 --- a/evm_arithmetization/tests/empty_tables.rs +++ b/evm_arithmetization/tests/empty_tables.rs @@ -28,18 +28,6 @@ fn empty_tables() -> anyhow::Result<()> { let config = TEST_STARK_CONFIG; let timing = &mut TimingTree::new("Empty Table Test", log::Level::Info); - // Process and generate segment proof - let all_circuits = timed!( - timing, - log::Level::Info, - "Create all recursive circuits", - AllRecursiveCircuits::::new( - &all_stark, - &[16..17, 8..9, 7..8, 4..6, 8..9, 4..5, 16..17, 16..17, 16..17], - &config, - ) - ); - // Generate segment data let (payload, mut segment_data) = segment_with_empty_tables()?; @@ -63,6 +51,18 @@ fn empty_tables() -> anyhow::Result<()> { // Verify the generated STARK proofs verify_all_proofs(&all_stark, &proofs, &config)?; + // Process and generate segment proof + let all_circuits = timed!( + timing, + log::Level::Info, + "Create all recursive circuits", + AllRecursiveCircuits::::new( + &all_stark, + &[16..17, 8..9, 7..8, 4..6, 8..9, 4..5, 16..17, 16..17, 16..17], + &config, + ) + ); + let segment_proof = timed!( timing, log::Level::Info, diff --git a/evm_arithmetization/tests/erc20.rs b/evm_arithmetization/tests/erc20.rs index 2baf716e7..3fe66f301 100644 --- a/evm_arithmetization/tests/erc20.rs +++ b/evm_arithmetization/tests/erc20.rs @@ -11,6 +11,7 @@ use evm_arithmetization::prover::testing::prove_all_segments; use evm_arithmetization::testing_utils::{ beacon_roots_account_nibbles, beacon_roots_contract_from_storage, create_account_storage, init_logger, preinitialized_state_and_storage_tries, sd2u, update_beacon_roots_account_storage, + TEST_STARK_CONFIG, }; use evm_arithmetization::verifier::testing::verify_all_proofs; use evm_arithmetization::{AllStark, Node, StarkConfig, EMPTY_CONSOLIDATED_BLOCKHASH}; @@ -52,7 +53,7 @@ fn test_erc20() -> anyhow::Result<()> { init_logger(); let all_stark = AllStark::::default(); - let config = StarkConfig::standard_fast_config(); + let config = TEST_STARK_CONFIG; let beneficiary = hex!("deadbeefdeadbeefdeadbeefdeadbeefdeadbeef"); let sender = hex!("70997970C51812dc3A010C7d01b50e0d17dc79C8"); diff --git a/evm_arithmetization/tests/erc721.rs b/evm_arithmetization/tests/erc721.rs index e416dc87a..9a581039a 100644 --- a/evm_arithmetization/tests/erc721.rs +++ b/evm_arithmetization/tests/erc721.rs @@ -11,7 +11,7 @@ use evm_arithmetization::prover::testing::prove_all_segments; use evm_arithmetization::testing_utils::{ beacon_roots_account_nibbles, beacon_roots_contract_from_storage, create_account_storage, init_logger, preinitialized_state_and_storage_tries, sd2u, sh2u, - update_beacon_roots_account_storage, + update_beacon_roots_account_storage, TEST_STARK_CONFIG, }; use evm_arithmetization::verifier::testing::verify_all_proofs; use evm_arithmetization::{AllStark, Node, StarkConfig, EMPTY_CONSOLIDATED_BLOCKHASH}; @@ -56,7 +56,7 @@ fn test_erc721() -> anyhow::Result<()> { init_logger(); let all_stark = AllStark::::default(); - let config = StarkConfig::standard_fast_config(); + let config = TEST_STARK_CONFIG; let beneficiary = hex!("deadbeefdeadbeefdeadbeefdeadbeefdeadbeef"); let owner = hex!("5B38Da6a701c568545dCfcB03FcB875f56beddC4"); diff --git a/evm_arithmetization/tests/global_exit_root.rs b/evm_arithmetization/tests/global_exit_root.rs index b7e82c7a0..03f3e23e8 100644 --- a/evm_arithmetization/tests/global_exit_root.rs +++ b/evm_arithmetization/tests/global_exit_root.rs @@ -11,6 +11,7 @@ use evm_arithmetization::testing_utils::{ ger_account_nibbles, ger_contract_from_storage, init_logger, scalable_account_nibbles, scalable_contract_from_storage, update_ger_account_storage, update_scalable_account_storage, ADDRESS_SCALABLE_L2_ADDRESS_HASHED, GLOBAL_EXIT_ROOT_ACCOUNT, GLOBAL_EXIT_ROOT_ADDRESS_HASHED, + TEST_STARK_CONFIG, }; use evm_arithmetization::verifier::testing::verify_all_proofs; use evm_arithmetization::{AllStark, Node, StarkConfig, EMPTY_CONSOLIDATED_BLOCKHASH}; @@ -31,7 +32,7 @@ fn test_global_exit_root() -> anyhow::Result<()> { init_logger(); let all_stark = AllStark::::default(); - let config = StarkConfig::standard_fast_config(); + let config = TEST_STARK_CONFIG; let block_metadata = BlockMetadata { block_timestamp: 1.into(), diff --git a/evm_arithmetization/tests/log_opcode.rs b/evm_arithmetization/tests/log_opcode.rs index 81daf588c..d73ca4b01 100644 --- a/evm_arithmetization/tests/log_opcode.rs +++ b/evm_arithmetization/tests/log_opcode.rs @@ -15,7 +15,7 @@ use evm_arithmetization::proof::{BlockHashes, BlockMetadata, TrieRoots}; use evm_arithmetization::prover::testing::prove_all_segments; use evm_arithmetization::testing_utils::{ beacon_roots_account_nibbles, beacon_roots_contract_from_storage, init_logger, - preinitialized_state_and_storage_tries, update_beacon_roots_account_storage, + preinitialized_state_and_storage_tries, update_beacon_roots_account_storage, TEST_STARK_CONFIG, }; use evm_arithmetization::verifier::testing::verify_all_proofs; use evm_arithmetization::{AllStark, Node, StarkConfig, EMPTY_CONSOLIDATED_BLOCKHASH}; @@ -38,7 +38,7 @@ fn test_log_opcodes() -> anyhow::Result<()> { init_logger(); let all_stark = AllStark::::default(); - let config = StarkConfig::standard_fast_config(); + let config = TEST_STARK_CONFIG; let beneficiary = hex!("2adc25665018aa1fe0e6bc666dac8fc2697ff9ba"); let sender = hex!("af1276cbb260bb13deddb4209ae99ae6e497f446"); diff --git a/evm_arithmetization/tests/selfdestruct.rs b/evm_arithmetization/tests/selfdestruct.rs index f97dd41cd..3829171a2 100644 --- a/evm_arithmetization/tests/selfdestruct.rs +++ b/evm_arithmetization/tests/selfdestruct.rs @@ -10,7 +10,7 @@ use evm_arithmetization::proof::{BlockHashes, BlockMetadata, TrieRoots}; use evm_arithmetization::prover::testing::prove_all_segments; use evm_arithmetization::testing_utils::{ beacon_roots_account_nibbles, beacon_roots_contract_from_storage, init_logger, - preinitialized_state_and_storage_tries, update_beacon_roots_account_storage, + preinitialized_state_and_storage_tries, update_beacon_roots_account_storage, TEST_STARK_CONFIG, }; use evm_arithmetization::verifier::testing::verify_all_proofs; use evm_arithmetization::{AllStark, Node, StarkConfig, EMPTY_CONSOLIDATED_BLOCKHASH}; @@ -34,7 +34,7 @@ fn test_selfdestruct() -> anyhow::Result<()> { init_logger(); let all_stark = AllStark::::default(); - let config = StarkConfig::standard_fast_config(); + let config = TEST_STARK_CONFIG; let beneficiary = hex!("deadbeefdeadbeefdeadbeefdeadbeefdeadbeef"); let sender = hex!("5eb96AA102a29fAB267E12A40a5bc6E9aC088759"); diff --git a/evm_arithmetization/tests/simple_transfer.rs b/evm_arithmetization/tests/simple_transfer.rs index a1e7fb655..741e9bf95 100644 --- a/evm_arithmetization/tests/simple_transfer.rs +++ b/evm_arithmetization/tests/simple_transfer.rs @@ -11,7 +11,7 @@ use evm_arithmetization::proof::{BlockHashes, BlockMetadata, TrieRoots}; use evm_arithmetization::prover::testing::prove_all_segments; use evm_arithmetization::testing_utils::{ beacon_roots_account_nibbles, beacon_roots_contract_from_storage, init_logger, - preinitialized_state_and_storage_tries, update_beacon_roots_account_storage, + preinitialized_state_and_storage_tries, update_beacon_roots_account_storage, TEST_STARK_CONFIG, }; use evm_arithmetization::verifier::testing::verify_all_proofs; use evm_arithmetization::{AllStark, Node, StarkConfig, EMPTY_CONSOLIDATED_BLOCKHASH}; @@ -35,7 +35,7 @@ fn test_simple_transfer() -> anyhow::Result<()> { init_logger(); let all_stark = AllStark::::default(); - let config = StarkConfig::standard_fast_config(); + let config = TEST_STARK_CONFIG; let beneficiary = hex!("deadbeefdeadbeefdeadbeefdeadbeefdeadbeef"); let sender = hex!("2c7536e3605d9c16a7a3d7b1898e529396a65c23"); diff --git a/evm_arithmetization/tests/two_to_one_block.rs b/evm_arithmetization/tests/two_to_one_block.rs index e808a33e4..5f63b6c88 100644 --- a/evm_arithmetization/tests/two_to_one_block.rs +++ b/evm_arithmetization/tests/two_to_one_block.rs @@ -10,7 +10,7 @@ use evm_arithmetization::proof::{ }; use evm_arithmetization::testing_utils::{ beacon_roots_account_nibbles, beacon_roots_contract_from_storage, init_logger, - preinitialized_state_and_storage_tries, update_beacon_roots_account_storage, + preinitialized_state_and_storage_tries, update_beacon_roots_account_storage, TEST_STARK_CONFIG, }; use evm_arithmetization::{AllRecursiveCircuits, AllStark, Node, StarkConfig}; use hex_literal::hex; @@ -168,7 +168,7 @@ fn test_two_to_one_block_aggregation() -> anyhow::Result<()> { let some_timestamps = [127, 42, 65, 43]; let all_stark = AllStark::::default(); - let config = StarkConfig::standard_fast_config(); + let config = TEST_STARK_CONFIG; let all_circuits = AllRecursiveCircuits::new( &all_stark, diff --git a/evm_arithmetization/tests/withdrawals.rs b/evm_arithmetization/tests/withdrawals.rs index 01b48c0c6..bee99ae00 100644 --- a/evm_arithmetization/tests/withdrawals.rs +++ b/evm_arithmetization/tests/withdrawals.rs @@ -10,7 +10,7 @@ use evm_arithmetization::proof::{BlockHashes, BlockMetadata, TrieRoots}; use evm_arithmetization::prover::testing::prove_all_segments; use evm_arithmetization::testing_utils::{ beacon_roots_account_nibbles, beacon_roots_contract_from_storage, init_logger, - preinitialized_state_and_storage_tries, update_beacon_roots_account_storage, + preinitialized_state_and_storage_tries, update_beacon_roots_account_storage, TEST_STARK_CONFIG, }; use evm_arithmetization::verifier::testing::verify_all_proofs; use evm_arithmetization::{AllStark, Node, StarkConfig, EMPTY_CONSOLIDATED_BLOCKHASH}; @@ -33,7 +33,7 @@ fn test_withdrawals() -> anyhow::Result<()> { init_logger(); let all_stark = AllStark::::default(); - let config = StarkConfig::standard_fast_config(); + let config = TEST_STARK_CONFIG; let block_metadata = BlockMetadata { block_timestamp: 1.into(), From 42d3715533b8f3ee0f4c6094680cf564b81badb2 Mon Sep 17 00:00:00 2001 From: Sai Deng Date: Mon, 21 Oct 2024 11:20:41 -0700 Subject: [PATCH 04/12] fmt --- evm_arithmetization/tests/add11_yml.rs | 4 +--- evm_arithmetization/tests/erc20.rs | 2 +- evm_arithmetization/tests/erc721.rs | 2 +- evm_arithmetization/tests/log_opcode.rs | 2 +- evm_arithmetization/tests/selfdestruct.rs | 2 +- evm_arithmetization/tests/simple_transfer.rs | 2 +- evm_arithmetization/tests/withdrawals.rs | 2 +- 7 files changed, 7 insertions(+), 9 deletions(-) diff --git a/evm_arithmetization/tests/add11_yml.rs b/evm_arithmetization/tests/add11_yml.rs index 5a6b9617b..5406ebe6a 100644 --- a/evm_arithmetization/tests/add11_yml.rs +++ b/evm_arithmetization/tests/add11_yml.rs @@ -14,9 +14,7 @@ use evm_arithmetization::testing_utils::{ preinitialized_state_and_storage_tries, update_beacon_roots_account_storage, TEST_STARK_CONFIG, }; use evm_arithmetization::verifier::testing::verify_all_proofs; -use evm_arithmetization::{ - AllStark, GenerationInputs, Node, StarkConfig, EMPTY_CONSOLIDATED_BLOCKHASH, -}; +use evm_arithmetization::{AllStark, GenerationInputs, Node, EMPTY_CONSOLIDATED_BLOCKHASH}; use hex_literal::hex; use keccak_hash::keccak; use mpt_trie::nibbles::Nibbles; diff --git a/evm_arithmetization/tests/erc20.rs b/evm_arithmetization/tests/erc20.rs index 3fe66f301..f594c7bd3 100644 --- a/evm_arithmetization/tests/erc20.rs +++ b/evm_arithmetization/tests/erc20.rs @@ -14,7 +14,7 @@ use evm_arithmetization::testing_utils::{ TEST_STARK_CONFIG, }; use evm_arithmetization::verifier::testing::verify_all_proofs; -use evm_arithmetization::{AllStark, Node, StarkConfig, EMPTY_CONSOLIDATED_BLOCKHASH}; +use evm_arithmetization::{AllStark, Node, EMPTY_CONSOLIDATED_BLOCKHASH}; use hex_literal::hex; use keccak_hash::keccak; use mpt_trie::nibbles::Nibbles; diff --git a/evm_arithmetization/tests/erc721.rs b/evm_arithmetization/tests/erc721.rs index 9a581039a..8602a9900 100644 --- a/evm_arithmetization/tests/erc721.rs +++ b/evm_arithmetization/tests/erc721.rs @@ -14,7 +14,7 @@ use evm_arithmetization::testing_utils::{ update_beacon_roots_account_storage, TEST_STARK_CONFIG, }; use evm_arithmetization::verifier::testing::verify_all_proofs; -use evm_arithmetization::{AllStark, Node, StarkConfig, EMPTY_CONSOLIDATED_BLOCKHASH}; +use evm_arithmetization::{AllStark, Node, EMPTY_CONSOLIDATED_BLOCKHASH}; use hex_literal::hex; use keccak_hash::keccak; use mpt_trie::nibbles::Nibbles; diff --git a/evm_arithmetization/tests/log_opcode.rs b/evm_arithmetization/tests/log_opcode.rs index d73ca4b01..4f274b0b9 100644 --- a/evm_arithmetization/tests/log_opcode.rs +++ b/evm_arithmetization/tests/log_opcode.rs @@ -18,7 +18,7 @@ use evm_arithmetization::testing_utils::{ preinitialized_state_and_storage_tries, update_beacon_roots_account_storage, TEST_STARK_CONFIG, }; use evm_arithmetization::verifier::testing::verify_all_proofs; -use evm_arithmetization::{AllStark, Node, StarkConfig, EMPTY_CONSOLIDATED_BLOCKHASH}; +use evm_arithmetization::{AllStark, Node, EMPTY_CONSOLIDATED_BLOCKHASH}; use hex_literal::hex; use keccak_hash::keccak; use mpt_trie::nibbles::Nibbles; diff --git a/evm_arithmetization/tests/selfdestruct.rs b/evm_arithmetization/tests/selfdestruct.rs index 3829171a2..e528ae804 100644 --- a/evm_arithmetization/tests/selfdestruct.rs +++ b/evm_arithmetization/tests/selfdestruct.rs @@ -13,7 +13,7 @@ use evm_arithmetization::testing_utils::{ preinitialized_state_and_storage_tries, update_beacon_roots_account_storage, TEST_STARK_CONFIG, }; use evm_arithmetization::verifier::testing::verify_all_proofs; -use evm_arithmetization::{AllStark, Node, StarkConfig, EMPTY_CONSOLIDATED_BLOCKHASH}; +use evm_arithmetization::{AllStark, Node, EMPTY_CONSOLIDATED_BLOCKHASH}; use hex_literal::hex; use keccak_hash::keccak; use mpt_trie::nibbles::Nibbles; diff --git a/evm_arithmetization/tests/simple_transfer.rs b/evm_arithmetization/tests/simple_transfer.rs index 741e9bf95..6d2cbb6d0 100644 --- a/evm_arithmetization/tests/simple_transfer.rs +++ b/evm_arithmetization/tests/simple_transfer.rs @@ -14,7 +14,7 @@ use evm_arithmetization::testing_utils::{ preinitialized_state_and_storage_tries, update_beacon_roots_account_storage, TEST_STARK_CONFIG, }; use evm_arithmetization::verifier::testing::verify_all_proofs; -use evm_arithmetization::{AllStark, Node, StarkConfig, EMPTY_CONSOLIDATED_BLOCKHASH}; +use evm_arithmetization::{AllStark, Node, EMPTY_CONSOLIDATED_BLOCKHASH}; use hex_literal::hex; use keccak_hash::keccak; use mpt_trie::nibbles::Nibbles; diff --git a/evm_arithmetization/tests/withdrawals.rs b/evm_arithmetization/tests/withdrawals.rs index bee99ae00..f179d7b7e 100644 --- a/evm_arithmetization/tests/withdrawals.rs +++ b/evm_arithmetization/tests/withdrawals.rs @@ -13,7 +13,7 @@ use evm_arithmetization::testing_utils::{ preinitialized_state_and_storage_tries, update_beacon_roots_account_storage, TEST_STARK_CONFIG, }; use evm_arithmetization::verifier::testing::verify_all_proofs; -use evm_arithmetization::{AllStark, Node, StarkConfig, EMPTY_CONSOLIDATED_BLOCKHASH}; +use evm_arithmetization::{AllStark, Node, EMPTY_CONSOLIDATED_BLOCKHASH}; use keccak_hash::keccak; use mpt_trie::nibbles::Nibbles; use mpt_trie::partial_trie::{HashedPartialTrie, PartialTrie}; From acb6eac1f2c4cdef218deefe28545cf1c29d8762 Mon Sep 17 00:00:00 2001 From: Sai Deng Date: Mon, 21 Oct 2024 13:59:13 -0700 Subject: [PATCH 05/12] wip --- .../src/fixed_recursive_verifier.rs | 26 ++++++++++++++----- evm_arithmetization/src/testing_utils.rs | 20 ++++++++++++++ evm_arithmetization/tests/empty_tables.rs | 4 ++- evm_arithmetization/tests/global_exit_root.rs | 2 +- evm_arithmetization/tests/two_to_one_block.rs | 5 +++- zero/src/prover_state/circuit.rs | 2 ++ 6 files changed, 50 insertions(+), 9 deletions(-) diff --git a/evm_arithmetization/src/fixed_recursive_verifier.rs b/evm_arithmetization/src/fixed_recursive_verifier.rs index adde60d1b..6ec64adfb 100644 --- a/evm_arithmetization/src/fixed_recursive_verifier.rs +++ b/evm_arithmetization/src/fixed_recursive_verifier.rs @@ -786,10 +786,16 @@ where all_stark: &AllStark, degree_bits_ranges: &[Range; NUM_TABLES], stark_config: &StarkConfig, + shrinking_circuit_config: Option<&CircuitConfig>, + threshold_degree_bits: Option, ) -> Self { // Sanity check on the provided config assert_eq!(DEFAULT_CAP_LEN, 1 << stark_config.fri_config.cap_height); + let shrinking_config = shrinking_config(); + let shrinking_circuit_config = shrinking_circuit_config.unwrap_or(&shrinking_config); + let threshold_degree_bits = threshold_degree_bits.unwrap_or(THRESHOLD_DEGREE_BITS); + macro_rules! create_recursive_circuit { ($table_enum:expr, $stark_field:ident) => { RecursiveCircuitsForTable::new( @@ -798,6 +804,8 @@ where degree_bits_ranges[*$table_enum].clone(), &all_stark.cross_table_lookups, stark_config, + shrinking_circuit_config, + threshold_degree_bits, ) }; } @@ -2900,6 +2908,8 @@ where degree_bits_range: Range, all_ctls: &[CrossTableLookup], stark_config: &StarkConfig, + shrinking_circuit_config: &CircuitConfig, + threshold_degree_bits: usize, ) -> Self { let by_stark_size = degree_bits_range .map(|degree_bits| { @@ -2911,6 +2921,8 @@ where degree_bits, all_ctls, stark_config, + shrinking_circuit_config, + threshold_degree_bits, ), ) }) @@ -3023,6 +3035,8 @@ where degree_bits: usize, all_ctls: &[CrossTableLookup], stark_config: &StarkConfig, + shrinking_config: &CircuitConfig, + threshold_degree_bits: usize, ) -> Self { let initial_wrapper = recursive_stark_circuit( table, @@ -3030,8 +3044,8 @@ where degree_bits, all_ctls, stark_config, - &shrinking_config(), - THRESHOLD_DEGREE_BITS, + shrinking_config, + threshold_degree_bits, ); let mut shrinking_wrappers = vec![]; @@ -3042,12 +3056,12 @@ where .map(|wrapper: &PlonkWrapperCircuit| &wrapper.circuit) .unwrap_or(&initial_wrapper.circuit); let last_degree_bits = last.common.degree_bits(); - assert!(last_degree_bits >= THRESHOLD_DEGREE_BITS); - if last_degree_bits == THRESHOLD_DEGREE_BITS { + assert!(last_degree_bits >= threshold_degree_bits); + if last_degree_bits == threshold_degree_bits { break; } - let mut builder = CircuitBuilder::new(shrinking_config()); + let mut builder = CircuitBuilder::new(shrinking_config.clone()); let proof_with_pis_target = builder.add_virtual_proof_with_pis(&last.common); let last_vk = builder.constant_verifier_data(&last.verifier_only); builder.verify_proof::(&proof_with_pis_target, &last_vk, &last.common); @@ -3058,7 +3072,7 @@ where assert!( circuit.common.degree_bits() < last_degree_bits, "Couldn't shrink to expected recursion threshold of 2^{}; stalled at 2^{}", - THRESHOLD_DEGREE_BITS, + threshold_degree_bits, circuit.common.degree_bits() ); shrinking_wrappers.push(PlonkWrapperCircuit { diff --git a/evm_arithmetization/src/testing_utils.rs b/evm_arithmetization/src/testing_utils.rs index b6575765b..da1e2565e 100644 --- a/evm_arithmetization/src/testing_utils.rs +++ b/evm_arithmetization/src/testing_utils.rs @@ -13,6 +13,7 @@ use mpt_trie::{ use plonky2::field::goldilocks_field::GoldilocksField; use plonky2::fri::reduction_strategies::FriReductionStrategy; use plonky2::fri::FriConfig; +use plonky2::plonk::circuit_data::CircuitConfig; use starky::config::StarkConfig; pub use crate::cpu::kernel::cancun_constants::*; @@ -43,6 +44,25 @@ pub const TEST_STARK_CONFIG: StarkConfig = StarkConfig { }, }; +/// A fast Circuit config for testing purposes only. +pub const TEST_SHRINKING_CONFIG: CircuitConfig = CircuitConfig { + num_wires: 135, + num_routed_wires: 40, + num_constants: 2, + use_base_arithmetic_gate: true, + security_bits: 1, + num_challenges: 1, + zero_knowledge: false, + max_quotient_degree_factor: 8, + fri_config: FriConfig { + rate_bits: 1, + cap_height: 4, + proof_of_work_bits: 1, + reduction_strategy: FriReductionStrategy::ConstantArityBits(4, 5), + num_query_rounds: 1, + }, +}; + pub fn init_logger() { let _ = try_init_from_env(Env::default().filter_or(DEFAULT_FILTER_ENV, "info")); } diff --git a/evm_arithmetization/tests/empty_tables.rs b/evm_arithmetization/tests/empty_tables.rs index df7087b75..ff91d79c4 100644 --- a/evm_arithmetization/tests/empty_tables.rs +++ b/evm_arithmetization/tests/empty_tables.rs @@ -5,7 +5,7 @@ use std::time::Duration; use evm_arithmetization::fixed_recursive_verifier::AllRecursiveCircuits; use evm_arithmetization::prover::prove; use evm_arithmetization::testing_utils::{ - init_logger, segment_with_empty_tables, TEST_STARK_CONFIG, + init_logger, segment_with_empty_tables, TEST_SHRINKING_CONFIG, TEST_STARK_CONFIG, }; use evm_arithmetization::verifier::testing::verify_all_proofs; use evm_arithmetization::AllStark; @@ -60,6 +60,8 @@ fn empty_tables() -> anyhow::Result<()> { &all_stark, &[16..17, 8..9, 7..8, 4..6, 8..9, 4..5, 16..17, 16..17, 16..17], &config, + Some(&TEST_SHRINKING_CONFIG), + None, ) ); diff --git a/evm_arithmetization/tests/global_exit_root.rs b/evm_arithmetization/tests/global_exit_root.rs index 03f3e23e8..5495d4100 100644 --- a/evm_arithmetization/tests/global_exit_root.rs +++ b/evm_arithmetization/tests/global_exit_root.rs @@ -14,7 +14,7 @@ use evm_arithmetization::testing_utils::{ TEST_STARK_CONFIG, }; use evm_arithmetization::verifier::testing::verify_all_proofs; -use evm_arithmetization::{AllStark, Node, StarkConfig, EMPTY_CONSOLIDATED_BLOCKHASH}; +use evm_arithmetization::{AllStark, Node, EMPTY_CONSOLIDATED_BLOCKHASH}; use keccak_hash::keccak; use mpt_trie::partial_trie::{HashedPartialTrie, PartialTrie}; use plonky2::field::goldilocks_field::GoldilocksField; diff --git a/evm_arithmetization/tests/two_to_one_block.rs b/evm_arithmetization/tests/two_to_one_block.rs index 5f63b6c88..b6f747ee8 100644 --- a/evm_arithmetization/tests/two_to_one_block.rs +++ b/evm_arithmetization/tests/two_to_one_block.rs @@ -10,7 +10,8 @@ use evm_arithmetization::proof::{ }; use evm_arithmetization::testing_utils::{ beacon_roots_account_nibbles, beacon_roots_contract_from_storage, init_logger, - preinitialized_state_and_storage_tries, update_beacon_roots_account_storage, TEST_STARK_CONFIG, + preinitialized_state_and_storage_tries, update_beacon_roots_account_storage, + TEST_SHRINKING_CONFIG, TEST_STARK_CONFIG, }; use evm_arithmetization::{AllRecursiveCircuits, AllStark, Node, StarkConfig}; use hex_literal::hex; @@ -174,6 +175,8 @@ fn test_two_to_one_block_aggregation() -> anyhow::Result<()> { &all_stark, &[16..17, 8..9, 12..13, 8..9, 8..9, 6..7, 17..18, 16..17, 7..8], &config, + Some(&TEST_SHRINKING_CONFIG), + None, ); let bp = some_timestamps diff --git a/zero/src/prover_state/circuit.rs b/zero/src/prover_state/circuit.rs index da9fb367d..312e196fc 100644 --- a/zero/src/prover_state/circuit.rs +++ b/zero/src/prover_state/circuit.rs @@ -248,6 +248,8 @@ impl CircuitConfig { &AllStark::default(), self.as_degree_bits_ranges(), &StarkConfig::standard_fast_config(), + None, + None, ) } } From 15db9c3bcc25ff63f2919899382414b2da8de09f Mon Sep 17 00:00:00 2001 From: Sai Deng Date: Mon, 21 Oct 2024 18:58:47 -0700 Subject: [PATCH 06/12] fixes --- .../src/fixed_recursive_verifier.rs | 72 ++++++++++++++++--- evm_arithmetization/src/testing_utils.rs | 15 +++- evm_arithmetization/tests/empty_tables.rs | 32 +++++---- evm_arithmetization/tests/two_to_one_block.rs | 5 +- zero/src/prover_state/circuit.rs | 1 + 5 files changed, 94 insertions(+), 31 deletions(-) diff --git a/evm_arithmetization/src/fixed_recursive_verifier.rs b/evm_arithmetization/src/fixed_recursive_verifier.rs index 6ec64adfb..d35e81ac0 100644 --- a/evm_arithmetization/src/fixed_recursive_verifier.rs +++ b/evm_arithmetization/src/fixed_recursive_verifier.rs @@ -7,9 +7,9 @@ use std::sync::Arc; use anyhow::anyhow; use hashbrown::HashMap; use itertools::{zip_eq, Itertools}; +use log::info; use mpt_trie::partial_trie::{HashedPartialTrie, Node, PartialTrie}; use plonky2::field::extension::Extendable; -use plonky2::fri::FriParams; use plonky2::gates::constant::ConstantGate; use plonky2::gates::noop::NoopGate; use plonky2::hash::hash_types::{MerkleCapTarget, RichField, NUM_HASH_OUT_ELTS}; @@ -57,6 +57,7 @@ use crate::recursive_verifier::{ recursive_stark_circuit, set_final_public_value_targets, set_public_value_targets, PlonkWrapperCircuit, PublicInputs, StarkWrapperCircuit, }; +use crate::testing_utils::TWO_TO_ONE_BLOCK_CIRCUIT_TEST_THRESHOLD_DEGREE_BITS; use crate::util::h256_limbs; use crate::verifier::initial_memory_merkle_cap; @@ -787,6 +788,7 @@ where degree_bits_ranges: &[Range; NUM_TABLES], stark_config: &StarkConfig, shrinking_circuit_config: Option<&CircuitConfig>, + recursion_circuit_config: Option<&CircuitConfig>, threshold_degree_bits: Option, ) -> Self { // Sanity check on the provided config @@ -794,6 +796,8 @@ where let shrinking_config = shrinking_config(); let shrinking_circuit_config = shrinking_circuit_config.unwrap_or(&shrinking_config); + let circuit_config = CircuitConfig::standard_recursion_config(); + let recursion_circuit_config = recursion_circuit_config.unwrap_or(&circuit_config); let threshold_degree_bits = threshold_degree_bits.unwrap_or(THRESHOLD_DEGREE_BITS); macro_rules! create_recursive_circuit { @@ -837,13 +841,31 @@ where poseidon, ]; - let root = Self::create_segment_circuit(&by_table, stark_config); + let root = Self::create_segment_circuit(&by_table, stark_config, recursion_circuit_config); + info!("root degree bits: {}", root.circuit.common.degree_bits()); let segment_aggregation = Self::create_segment_aggregation_circuit(&root); + info!( + "segment_aggregation degree bits: {}", + root.circuit.common.degree_bits() + ); let batch_aggregation = Self::create_batch_aggregation_circuit(&segment_aggregation, stark_config); + info!( + "batch_aggregation degree bits: {}", + root.circuit.common.degree_bits() + ); let block = Self::create_block_circuit(&batch_aggregation); + info!("block degree bits: {}", root.circuit.common.degree_bits()); let block_wrapper = Self::create_block_wrapper_circuit(&block); + info!( + "block_wrapper degree bits: {}", + root.circuit.common.degree_bits() + ); let two_to_one_block = Self::create_two_to_one_block_circuit(&block_wrapper); + info!( + "two_to_one_block degree bits: {}", + root.circuit.common.degree_bits() + ); let table_dummy_proofs = core::array::from_fn(|i| { if OPTIONAL_TABLE_INDICES.contains(&i) { @@ -905,11 +927,12 @@ where fn create_segment_circuit( by_table: &[RecursiveCircuitsForTable; NUM_TABLES], stark_config: &StarkConfig, + circuit_config: &CircuitConfig, ) -> RootCircuitData { let inner_common_data: [_; NUM_TABLES] = core::array::from_fn(|i| &by_table[i].final_circuits()[0].common); - let mut builder = CircuitBuilder::new(CircuitConfig::standard_recursion_config()); + let mut builder = CircuitBuilder::new(circuit_config.clone()); let table_in_use: [BoolTarget; NUM_TABLES] = core::array::from_fn(|_| builder.add_virtual_bool_target_safe()); @@ -1113,6 +1136,11 @@ where vec![], ); + // Should pad to match the segment_aggregation circuit's degree. + // while log2_ceil(builder.num_gates()) < + // THRESHOLD_SEGMENT_AGG_CIRCUIT_DEGREE_BITS { builder. + // add_gate(NoopGate, vec![]); } + RootCircuitData { circuit: builder.build::(), proof_with_pis: recursive_proofs, @@ -1279,12 +1307,17 @@ where lhs_pv.registers_after, ); + info!("num_gates before padding = {}", builder.num_gates()); + // Pad to match the root circuit's degree. while log2_ceil(builder.num_gates()) < root.circuit.common.degree_bits() { builder.add_gate(NoopGate, vec![]); } + info!("num_gates = {}", builder.num_gates()); let circuit = builder.build::(); + info!("finish build"); + SegmentAggregationCircuitData { circuit, lhs: lhs_segment, @@ -1492,15 +1525,16 @@ where // Here, we have two block proofs and we aggregate them together. // The block circuit is similar to the agg circuit; both verify two inner // proofs. - let expected_common_data = CommonCircuitData { - fri_params: FriParams { - degree_bits: 14, - ..agg.circuit.common.fri_params.clone() - }, - ..agg.circuit.common.clone() - }; + // let expected_common_data = CommonCircuitData { + // fri_params: FriParams { + // degree_bits: expected_block_circuit_degree_bits, + // ..agg.circuit.common.fri_params.clone() + // }, + // ..agg.circuit.common.clone() + // }; + let expected_common_data = agg.circuit.common.clone(); - let mut builder = CircuitBuilder::::new(CircuitConfig::standard_recursion_config()); + let mut builder = CircuitBuilder::::new(agg.circuit.common.config.clone()); let public_values = add_virtual_public_values_public_input(&mut builder); let has_parent_block = builder.add_virtual_bool_target_safe(); let parent_block_proof = builder.add_virtual_proof_with_pis(&expected_common_data); @@ -1575,6 +1609,10 @@ where let agg_verifier_data = builder.constant_verifier_data(&agg.circuit.verifier_only); builder.verify_proof::(&agg_root_proof, &agg_verifier_data, &agg.circuit.common); + while log2_ceil(builder.num_gates()) < agg.circuit.common.degree_bits() { + builder.add_gate(NoopGate, vec![]); + } + let circuit = builder.build::(); BlockCircuitData { circuit, @@ -1751,6 +1789,13 @@ where builder.add_gate(NoopGate, vec![]); } + // When using test configurations, the block circuit's degree is less than the + // 2-to-1 circuit's degree. Therefore, we also need to ensure its size meets + // the 2-to-1 circuit's recursion threshold degree bits. + while log2_ceil(builder.num_gates()) < TWO_TO_ONE_BLOCK_CIRCUIT_TEST_THRESHOLD_DEGREE_BITS { + builder.add_gate(NoopGate, vec![]); + } + let circuit = builder.build::(); BlockWrapperCircuitData { @@ -1834,6 +1879,11 @@ where builder.connect_hashes(mix_hash, mix_hash_virtual); + // Pad to match the block circuit's degree. + while log2_ceil(builder.num_gates()) < block_wrapper_circuit.circuit.common.degree_bits() { + builder.add_gate(NoopGate, vec![]); + } + let circuit = builder.build::(); TwoToOneBlockCircuitData { circuit, diff --git a/evm_arithmetization/src/testing_utils.rs b/evm_arithmetization/src/testing_utils.rs index da1e2565e..1211b074f 100644 --- a/evm_arithmetization/src/testing_utils.rs +++ b/evm_arithmetization/src/testing_utils.rs @@ -31,6 +31,15 @@ pub const EMPTY_NODE_HASH: H256 = H256(hex!( "56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421" )); +/// The recursion threshold when using test configurations +pub const TEST_THRESHOLD_DEGREE_BITS: usize = 10; + +/// The recursion threshold for segment aggregation circuit. +// const THRESHOLD_SEGMENT_AGG_CIRCUIT_DEGREE_BITS: usize = 12; + +/// The recursion threshold for 2-to-1 block circuit. +pub const TWO_TO_ONE_BLOCK_CIRCUIT_TEST_THRESHOLD_DEGREE_BITS: usize = 13; + /// A fast STARK config for testing purposes only. pub const TEST_STARK_CONFIG: StarkConfig = StarkConfig { security_bits: 1, @@ -45,9 +54,9 @@ pub const TEST_STARK_CONFIG: StarkConfig = StarkConfig { }; /// A fast Circuit config for testing purposes only. -pub const TEST_SHRINKING_CONFIG: CircuitConfig = CircuitConfig { +pub const TEST_RECURSION_CONFIG: CircuitConfig = CircuitConfig { num_wires: 135, - num_routed_wires: 40, + num_routed_wires: 80, num_constants: 2, use_base_arithmetic_gate: true, security_bits: 1, @@ -55,7 +64,7 @@ pub const TEST_SHRINKING_CONFIG: CircuitConfig = CircuitConfig { zero_knowledge: false, max_quotient_degree_factor: 8, fri_config: FriConfig { - rate_bits: 1, + rate_bits: 3, cap_height: 4, proof_of_work_bits: 1, reduction_strategy: FriReductionStrategy::ConstantArityBits(4, 5), diff --git a/evm_arithmetization/tests/empty_tables.rs b/evm_arithmetization/tests/empty_tables.rs index ff91d79c4..a06d53f0a 100644 --- a/evm_arithmetization/tests/empty_tables.rs +++ b/evm_arithmetization/tests/empty_tables.rs @@ -5,7 +5,8 @@ use std::time::Duration; use evm_arithmetization::fixed_recursive_verifier::AllRecursiveCircuits; use evm_arithmetization::prover::prove; use evm_arithmetization::testing_utils::{ - init_logger, segment_with_empty_tables, TEST_SHRINKING_CONFIG, TEST_STARK_CONFIG, + init_logger, segment_with_empty_tables, TEST_RECURSION_CONFIG, TEST_STARK_CONFIG, + TEST_THRESHOLD_DEGREE_BITS, }; use evm_arithmetization::verifier::testing::verify_all_proofs; use evm_arithmetization::AllStark; @@ -28,6 +29,21 @@ fn empty_tables() -> anyhow::Result<()> { let config = TEST_STARK_CONFIG; let timing = &mut TimingTree::new("Empty Table Test", log::Level::Info); + // Process and generate segment proof + let all_circuits = timed!( + timing, + log::Level::Info, + "Create all recursive circuits", + AllRecursiveCircuits::::new( + &all_stark, + &[16..17, 8..9, 7..8, 4..6, 8..9, 4..5, 16..17, 16..17, 16..17], + &config, + Some(&TEST_RECURSION_CONFIG), + Some(&TEST_RECURSION_CONFIG), + Some(TEST_THRESHOLD_DEGREE_BITS), + ) + ); + // Generate segment data let (payload, mut segment_data) = segment_with_empty_tables()?; @@ -51,20 +67,6 @@ fn empty_tables() -> anyhow::Result<()> { // Verify the generated STARK proofs verify_all_proofs(&all_stark, &proofs, &config)?; - // Process and generate segment proof - let all_circuits = timed!( - timing, - log::Level::Info, - "Create all recursive circuits", - AllRecursiveCircuits::::new( - &all_stark, - &[16..17, 8..9, 7..8, 4..6, 8..9, 4..5, 16..17, 16..17, 16..17], - &config, - Some(&TEST_SHRINKING_CONFIG), - None, - ) - ); - let segment_proof = timed!( timing, log::Level::Info, diff --git a/evm_arithmetization/tests/two_to_one_block.rs b/evm_arithmetization/tests/two_to_one_block.rs index b6f747ee8..8125b64f5 100644 --- a/evm_arithmetization/tests/two_to_one_block.rs +++ b/evm_arithmetization/tests/two_to_one_block.rs @@ -11,7 +11,7 @@ use evm_arithmetization::proof::{ use evm_arithmetization::testing_utils::{ beacon_roots_account_nibbles, beacon_roots_contract_from_storage, init_logger, preinitialized_state_and_storage_tries, update_beacon_roots_account_storage, - TEST_SHRINKING_CONFIG, TEST_STARK_CONFIG, + TEST_RECURSION_CONFIG, TEST_SHRINKING_CONFIG, TEST_STARK_CONFIG, }; use evm_arithmetization::{AllRecursiveCircuits, AllStark, Node, StarkConfig}; use hex_literal::hex; @@ -175,7 +175,8 @@ fn test_two_to_one_block_aggregation() -> anyhow::Result<()> { &all_stark, &[16..17, 8..9, 12..13, 8..9, 8..9, 6..7, 17..18, 16..17, 7..8], &config, - Some(&TEST_SHRINKING_CONFIG), + Some(&TEST_RECURSION_CONFIG), + Some(&TEST_RECURSION_CONFIG), None, ); diff --git a/zero/src/prover_state/circuit.rs b/zero/src/prover_state/circuit.rs index 312e196fc..2d8918057 100644 --- a/zero/src/prover_state/circuit.rs +++ b/zero/src/prover_state/circuit.rs @@ -250,6 +250,7 @@ impl CircuitConfig { &StarkConfig::standard_fast_config(), None, None, + None, ) } } From b150ade61468a6e46e719ae96774ad2cbc17edba Mon Sep 17 00:00:00 2001 From: Sai Deng Date: Mon, 21 Oct 2024 19:04:20 -0700 Subject: [PATCH 07/12] fix --- evm_arithmetization/tests/empty_tables.rs | 30 +++++++++---------- evm_arithmetization/tests/two_to_one_block.rs | 2 +- 2 files changed, 16 insertions(+), 16 deletions(-) diff --git a/evm_arithmetization/tests/empty_tables.rs b/evm_arithmetization/tests/empty_tables.rs index a06d53f0a..235bbb715 100644 --- a/evm_arithmetization/tests/empty_tables.rs +++ b/evm_arithmetization/tests/empty_tables.rs @@ -29,21 +29,6 @@ fn empty_tables() -> anyhow::Result<()> { let config = TEST_STARK_CONFIG; let timing = &mut TimingTree::new("Empty Table Test", log::Level::Info); - // Process and generate segment proof - let all_circuits = timed!( - timing, - log::Level::Info, - "Create all recursive circuits", - AllRecursiveCircuits::::new( - &all_stark, - &[16..17, 8..9, 7..8, 4..6, 8..9, 4..5, 16..17, 16..17, 16..17], - &config, - Some(&TEST_RECURSION_CONFIG), - Some(&TEST_RECURSION_CONFIG), - Some(TEST_THRESHOLD_DEGREE_BITS), - ) - ); - // Generate segment data let (payload, mut segment_data) = segment_with_empty_tables()?; @@ -67,6 +52,21 @@ fn empty_tables() -> anyhow::Result<()> { // Verify the generated STARK proofs verify_all_proofs(&all_stark, &proofs, &config)?; + // Process and generate segment proof + let all_circuits = timed!( + timing, + log::Level::Info, + "Create all recursive circuits", + AllRecursiveCircuits::::new( + &all_stark, + &[16..17, 8..9, 7..8, 4..6, 8..9, 4..5, 16..17, 16..17, 16..17], + &config, + Some(&TEST_RECURSION_CONFIG), + Some(&TEST_RECURSION_CONFIG), + Some(TEST_THRESHOLD_DEGREE_BITS), + ) + ); + let segment_proof = timed!( timing, log::Level::Info, diff --git a/evm_arithmetization/tests/two_to_one_block.rs b/evm_arithmetization/tests/two_to_one_block.rs index 8125b64f5..1ab6a4fe1 100644 --- a/evm_arithmetization/tests/two_to_one_block.rs +++ b/evm_arithmetization/tests/two_to_one_block.rs @@ -11,7 +11,7 @@ use evm_arithmetization::proof::{ use evm_arithmetization::testing_utils::{ beacon_roots_account_nibbles, beacon_roots_contract_from_storage, init_logger, preinitialized_state_and_storage_tries, update_beacon_roots_account_storage, - TEST_RECURSION_CONFIG, TEST_SHRINKING_CONFIG, TEST_STARK_CONFIG, + TEST_RECURSION_CONFIG, TEST_STARK_CONFIG, }; use evm_arithmetization::{AllRecursiveCircuits, AllStark, Node, StarkConfig}; use hex_literal::hex; From 398bf4da26816b6d6bc7166418ddec170ba42327 Mon Sep 17 00:00:00 2001 From: Sai Deng Date: Mon, 21 Oct 2024 19:10:49 -0700 Subject: [PATCH 08/12] cleanup --- .../src/fixed_recursive_verifier.rs | 39 ------------------- evm_arithmetization/src/testing_utils.rs | 3 -- 2 files changed, 42 deletions(-) diff --git a/evm_arithmetization/src/fixed_recursive_verifier.rs b/evm_arithmetization/src/fixed_recursive_verifier.rs index d35e81ac0..e72a42f29 100644 --- a/evm_arithmetization/src/fixed_recursive_verifier.rs +++ b/evm_arithmetization/src/fixed_recursive_verifier.rs @@ -7,7 +7,6 @@ use std::sync::Arc; use anyhow::anyhow; use hashbrown::HashMap; use itertools::{zip_eq, Itertools}; -use log::info; use mpt_trie::partial_trie::{HashedPartialTrie, Node, PartialTrie}; use plonky2::field::extension::Extendable; use plonky2::gates::constant::ConstantGate; @@ -842,30 +841,12 @@ where ]; let root = Self::create_segment_circuit(&by_table, stark_config, recursion_circuit_config); - info!("root degree bits: {}", root.circuit.common.degree_bits()); let segment_aggregation = Self::create_segment_aggregation_circuit(&root); - info!( - "segment_aggregation degree bits: {}", - root.circuit.common.degree_bits() - ); let batch_aggregation = Self::create_batch_aggregation_circuit(&segment_aggregation, stark_config); - info!( - "batch_aggregation degree bits: {}", - root.circuit.common.degree_bits() - ); let block = Self::create_block_circuit(&batch_aggregation); - info!("block degree bits: {}", root.circuit.common.degree_bits()); let block_wrapper = Self::create_block_wrapper_circuit(&block); - info!( - "block_wrapper degree bits: {}", - root.circuit.common.degree_bits() - ); let two_to_one_block = Self::create_two_to_one_block_circuit(&block_wrapper); - info!( - "two_to_one_block degree bits: {}", - root.circuit.common.degree_bits() - ); let table_dummy_proofs = core::array::from_fn(|i| { if OPTIONAL_TABLE_INDICES.contains(&i) { @@ -1136,11 +1117,6 @@ where vec![], ); - // Should pad to match the segment_aggregation circuit's degree. - // while log2_ceil(builder.num_gates()) < - // THRESHOLD_SEGMENT_AGG_CIRCUIT_DEGREE_BITS { builder. - // add_gate(NoopGate, vec![]); } - RootCircuitData { circuit: builder.build::(), proof_with_pis: recursive_proofs, @@ -1307,17 +1283,12 @@ where lhs_pv.registers_after, ); - info!("num_gates before padding = {}", builder.num_gates()); - // Pad to match the root circuit's degree. while log2_ceil(builder.num_gates()) < root.circuit.common.degree_bits() { builder.add_gate(NoopGate, vec![]); } - info!("num_gates = {}", builder.num_gates()); let circuit = builder.build::(); - info!("finish build"); - SegmentAggregationCircuitData { circuit, lhs: lhs_segment, @@ -1522,16 +1493,6 @@ where fn create_block_circuit( agg: &BatchAggregationCircuitData, ) -> BlockCircuitData { - // Here, we have two block proofs and we aggregate them together. - // The block circuit is similar to the agg circuit; both verify two inner - // proofs. - // let expected_common_data = CommonCircuitData { - // fri_params: FriParams { - // degree_bits: expected_block_circuit_degree_bits, - // ..agg.circuit.common.fri_params.clone() - // }, - // ..agg.circuit.common.clone() - // }; let expected_common_data = agg.circuit.common.clone(); let mut builder = CircuitBuilder::::new(agg.circuit.common.config.clone()); diff --git a/evm_arithmetization/src/testing_utils.rs b/evm_arithmetization/src/testing_utils.rs index 1211b074f..ac3cdcf0f 100644 --- a/evm_arithmetization/src/testing_utils.rs +++ b/evm_arithmetization/src/testing_utils.rs @@ -34,9 +34,6 @@ pub const EMPTY_NODE_HASH: H256 = H256(hex!( /// The recursion threshold when using test configurations pub const TEST_THRESHOLD_DEGREE_BITS: usize = 10; -/// The recursion threshold for segment aggregation circuit. -// const THRESHOLD_SEGMENT_AGG_CIRCUIT_DEGREE_BITS: usize = 12; - /// The recursion threshold for 2-to-1 block circuit. pub const TWO_TO_ONE_BLOCK_CIRCUIT_TEST_THRESHOLD_DEGREE_BITS: usize = 13; From d098b242872414c0db711224e4c92a894fe350fe Mon Sep 17 00:00:00 2001 From: Sai Deng Date: Tue, 22 Oct 2024 09:32:22 -0700 Subject: [PATCH 09/12] add to zero bin --- evm_arithmetization/tests/two_to_one_block.rs | 1 - zero/src/bin/leader.rs | 2 +- zero/src/bin/leader/cli.rs | 4 +++ zero/src/bin/verifier.rs | 2 +- zero/src/bin/verifier/cli.rs | 3 ++ zero/src/bin/worker.rs | 4 ++- zero/src/prover_state/circuit.rs | 32 +++++++++++++------ zero/src/prover_state/mod.rs | 21 ++++++++---- 8 files changed, 49 insertions(+), 20 deletions(-) diff --git a/evm_arithmetization/tests/two_to_one_block.rs b/evm_arithmetization/tests/two_to_one_block.rs index 1ab6a4fe1..573f64876 100644 --- a/evm_arithmetization/tests/two_to_one_block.rs +++ b/evm_arithmetization/tests/two_to_one_block.rs @@ -162,7 +162,6 @@ fn get_test_block_proof( Ok(wrapped_block_proof) } -#[ignore] #[test] fn test_two_to_one_block_aggregation() -> anyhow::Result<()> { init_logger(); diff --git a/zero/src/bin/leader.rs b/zero/src/bin/leader.rs index 6daaf599f..5f7d9853d 100644 --- a/zero/src/bin/leader.rs +++ b/zero/src/bin/leader.rs @@ -79,7 +79,7 @@ async fn main() -> Result<()> { if let paladin::config::Runtime::InMemory = args.paladin.runtime { args.prover_state_config .into_prover_state_manager() - .initialize()?; + .initialize(args.use_test_config)?; } } diff --git a/zero/src/bin/leader/cli.rs b/zero/src/bin/leader/cli.rs index ad9270ee8..eced52225 100644 --- a/zero/src/bin/leader/cli.rs +++ b/zero/src/bin/leader/cli.rs @@ -29,6 +29,10 @@ pub(crate) struct Cli { // Mode to use for worker for setup (affinity or default) #[arg(long = "worker-run-mode", help_heading = WORKER_HELP_HEADING, value_enum, default_value = "default")] pub(crate) worker_run_mode: WorkerRunMode, + + /// Run in an unsafe but fast configuration for testing purposes + #[arg(long)] + pub(crate) use_test_config: bool, } /// Defines the mode for worker setup in terms of job allocation: diff --git a/zero/src/bin/verifier.rs b/zero/src/bin/verifier.rs index d306eed10..96d377e45 100644 --- a/zero/src/bin/verifier.rs +++ b/zero/src/bin/verifier.rs @@ -30,7 +30,7 @@ fn main() -> Result<()> { let verifier = args .prover_state_config .into_prover_state_manager() - .verifier()?; + .verifier(args.use_test_config)?; if input_proofs.into_iter().all(|block_proof| { verifier diff --git a/zero/src/bin/verifier/cli.rs b/zero/src/bin/verifier/cli.rs index 8c046d85c..40e4f6bed 100644 --- a/zero/src/bin/verifier/cli.rs +++ b/zero/src/bin/verifier/cli.rs @@ -13,4 +13,7 @@ pub(crate) struct Cli { /// and the verifier state. #[clap(flatten)] pub(crate) prover_state_config: CliProverStateConfig, + /// Run in an unsafe but fast configuration for testing + #[arg(long)] + pub(crate) use_test_config: bool, } diff --git a/zero/src/bin/worker.rs b/zero/src/bin/worker.rs index 096863a53..67bc1cec3 100644 --- a/zero/src/bin/worker.rs +++ b/zero/src/bin/worker.rs @@ -20,6 +20,8 @@ struct Cli { paladin: paladin::config::Config, #[clap(flatten)] prover_state_config: CliProverStateConfig, + #[arg(long)] + use_test_config: bool, } #[tokio::main] @@ -31,7 +33,7 @@ async fn main() -> Result<()> { args.prover_state_config .into_prover_state_manager() - .initialize()?; + .initialize(args.use_test_config)?; let runtime = WorkerRuntime::from_config(&args.paladin, register()).await?; runtime.main_loop().await?; diff --git a/zero/src/prover_state/circuit.rs b/zero/src/prover_state/circuit.rs index 2d8918057..e4792a1ef 100644 --- a/zero/src/prover_state/circuit.rs +++ b/zero/src/prover_state/circuit.rs @@ -5,6 +5,9 @@ use std::{ str::FromStr, }; +use evm_arithmetization::testing_utils::{ + TEST_RECURSION_CONFIG, TEST_STARK_CONFIG, TEST_THRESHOLD_DEGREE_BITS, +}; pub use evm_arithmetization::NUM_TABLES; use evm_arithmetization::{AllRecursiveCircuits, AllStark, StarkConfig}; @@ -243,15 +246,26 @@ impl CircuitConfig { } /// Build the circuits from the current config. - pub fn as_all_recursive_circuits(&self) -> AllRecursiveCircuits { - AllRecursiveCircuits::new( - &AllStark::default(), - self.as_degree_bits_ranges(), - &StarkConfig::standard_fast_config(), - None, - None, - None, - ) + pub fn as_all_recursive_circuits(&self, use_test_config: bool) -> AllRecursiveCircuits { + if use_test_config { + AllRecursiveCircuits::new( + &AllStark::default(), + self.as_degree_bits_ranges(), + &TEST_STARK_CONFIG, + Some(&TEST_RECURSION_CONFIG), + Some(&TEST_RECURSION_CONFIG), + Some(TEST_THRESHOLD_DEGREE_BITS), + ) + } else { + AllRecursiveCircuits::new( + &AllStark::default(), + self.as_degree_bits_ranges(), + &StarkConfig::standard_fast_config(), + None, + None, + None, + ) + } } } diff --git a/zero/src/prover_state/mod.rs b/zero/src/prover_state/mod.rs index 8cdfb45ce..e56446155 100644 --- a/zero/src/prover_state/mod.rs +++ b/zero/src/prover_state/mod.rs @@ -283,14 +283,16 @@ impl ProverStateManager { } /// Initialize global prover state from the configuration. - pub fn initialize(&self) -> anyhow::Result<()> { + pub fn initialize(&self, use_test_config: bool) -> anyhow::Result<()> { info!("initializing prover state..."); let state = match self.persistence { CircuitPersistence::None => { info!("generating circuits..."); ProverState { - state: self.circuit_config.as_all_recursive_circuits(), + state: self + .circuit_config + .as_all_recursive_circuits(use_test_config), } } CircuitPersistence::Disk(strategy) => { @@ -310,8 +312,9 @@ impl ProverStateManager { } Err(_) => { info!("failed to load preprocessed circuits from disk. generating circuits..."); - let all_recursive_circuits = - self.circuit_config.as_all_recursive_circuits(); + let all_recursive_circuits = self + .circuit_config + .as_all_recursive_circuits(use_test_config); info!("saving preprocessed circuits to disk"); persistence::persist_all_to_disk( &all_recursive_circuits, @@ -343,12 +346,14 @@ impl ProverStateManager { } /// Loads a verifier state from disk or generate it. - pub fn verifier(&self) -> anyhow::Result { + pub fn verifier(&self, use_test_config: bool) -> anyhow::Result { info!("initializing verifier state..."); match self.persistence { CircuitPersistence::None => { info!("generating circuit..."); - let prover_state = self.circuit_config.as_all_recursive_circuits(); + let prover_state = self + .circuit_config + .as_all_recursive_circuits(use_test_config); Ok(VerifierState { state: prover_state.final_verifier_data(), }) @@ -364,7 +369,9 @@ impl ProverStateManager { } Err(_) => { info!("failed to load preprocessed verifier circuit from disk. generating it..."); - let prover_state = self.circuit_config.as_all_recursive_circuits(); + let prover_state = self + .circuit_config + .as_all_recursive_circuits(use_test_config); info!("saving preprocessed verifier circuit to disk"); let state = prover_state.final_verifier_data(); From ba64f01d1b717f463985a7e6b3328bfe78e2460a Mon Sep 17 00:00:00 2001 From: Sai Deng Date: Tue, 22 Oct 2024 09:32:48 -0700 Subject: [PATCH 10/12] Revert "add to zero bin" This reverts commit d098b242872414c0db711224e4c92a894fe350fe. --- evm_arithmetization/tests/two_to_one_block.rs | 1 + zero/src/bin/leader.rs | 2 +- zero/src/bin/leader/cli.rs | 4 --- zero/src/bin/verifier.rs | 2 +- zero/src/bin/verifier/cli.rs | 3 -- zero/src/bin/worker.rs | 4 +-- zero/src/prover_state/circuit.rs | 32 ++++++------------- zero/src/prover_state/mod.rs | 21 ++++-------- 8 files changed, 20 insertions(+), 49 deletions(-) diff --git a/evm_arithmetization/tests/two_to_one_block.rs b/evm_arithmetization/tests/two_to_one_block.rs index 573f64876..1ab6a4fe1 100644 --- a/evm_arithmetization/tests/two_to_one_block.rs +++ b/evm_arithmetization/tests/two_to_one_block.rs @@ -162,6 +162,7 @@ fn get_test_block_proof( Ok(wrapped_block_proof) } +#[ignore] #[test] fn test_two_to_one_block_aggregation() -> anyhow::Result<()> { init_logger(); diff --git a/zero/src/bin/leader.rs b/zero/src/bin/leader.rs index 5f7d9853d..6daaf599f 100644 --- a/zero/src/bin/leader.rs +++ b/zero/src/bin/leader.rs @@ -79,7 +79,7 @@ async fn main() -> Result<()> { if let paladin::config::Runtime::InMemory = args.paladin.runtime { args.prover_state_config .into_prover_state_manager() - .initialize(args.use_test_config)?; + .initialize()?; } } diff --git a/zero/src/bin/leader/cli.rs b/zero/src/bin/leader/cli.rs index eced52225..ad9270ee8 100644 --- a/zero/src/bin/leader/cli.rs +++ b/zero/src/bin/leader/cli.rs @@ -29,10 +29,6 @@ pub(crate) struct Cli { // Mode to use for worker for setup (affinity or default) #[arg(long = "worker-run-mode", help_heading = WORKER_HELP_HEADING, value_enum, default_value = "default")] pub(crate) worker_run_mode: WorkerRunMode, - - /// Run in an unsafe but fast configuration for testing purposes - #[arg(long)] - pub(crate) use_test_config: bool, } /// Defines the mode for worker setup in terms of job allocation: diff --git a/zero/src/bin/verifier.rs b/zero/src/bin/verifier.rs index 96d377e45..d306eed10 100644 --- a/zero/src/bin/verifier.rs +++ b/zero/src/bin/verifier.rs @@ -30,7 +30,7 @@ fn main() -> Result<()> { let verifier = args .prover_state_config .into_prover_state_manager() - .verifier(args.use_test_config)?; + .verifier()?; if input_proofs.into_iter().all(|block_proof| { verifier diff --git a/zero/src/bin/verifier/cli.rs b/zero/src/bin/verifier/cli.rs index 40e4f6bed..8c046d85c 100644 --- a/zero/src/bin/verifier/cli.rs +++ b/zero/src/bin/verifier/cli.rs @@ -13,7 +13,4 @@ pub(crate) struct Cli { /// and the verifier state. #[clap(flatten)] pub(crate) prover_state_config: CliProverStateConfig, - /// Run in an unsafe but fast configuration for testing - #[arg(long)] - pub(crate) use_test_config: bool, } diff --git a/zero/src/bin/worker.rs b/zero/src/bin/worker.rs index 67bc1cec3..096863a53 100644 --- a/zero/src/bin/worker.rs +++ b/zero/src/bin/worker.rs @@ -20,8 +20,6 @@ struct Cli { paladin: paladin::config::Config, #[clap(flatten)] prover_state_config: CliProverStateConfig, - #[arg(long)] - use_test_config: bool, } #[tokio::main] @@ -33,7 +31,7 @@ async fn main() -> Result<()> { args.prover_state_config .into_prover_state_manager() - .initialize(args.use_test_config)?; + .initialize()?; let runtime = WorkerRuntime::from_config(&args.paladin, register()).await?; runtime.main_loop().await?; diff --git a/zero/src/prover_state/circuit.rs b/zero/src/prover_state/circuit.rs index e4792a1ef..2d8918057 100644 --- a/zero/src/prover_state/circuit.rs +++ b/zero/src/prover_state/circuit.rs @@ -5,9 +5,6 @@ use std::{ str::FromStr, }; -use evm_arithmetization::testing_utils::{ - TEST_RECURSION_CONFIG, TEST_STARK_CONFIG, TEST_THRESHOLD_DEGREE_BITS, -}; pub use evm_arithmetization::NUM_TABLES; use evm_arithmetization::{AllRecursiveCircuits, AllStark, StarkConfig}; @@ -246,26 +243,15 @@ impl CircuitConfig { } /// Build the circuits from the current config. - pub fn as_all_recursive_circuits(&self, use_test_config: bool) -> AllRecursiveCircuits { - if use_test_config { - AllRecursiveCircuits::new( - &AllStark::default(), - self.as_degree_bits_ranges(), - &TEST_STARK_CONFIG, - Some(&TEST_RECURSION_CONFIG), - Some(&TEST_RECURSION_CONFIG), - Some(TEST_THRESHOLD_DEGREE_BITS), - ) - } else { - AllRecursiveCircuits::new( - &AllStark::default(), - self.as_degree_bits_ranges(), - &StarkConfig::standard_fast_config(), - None, - None, - None, - ) - } + pub fn as_all_recursive_circuits(&self) -> AllRecursiveCircuits { + AllRecursiveCircuits::new( + &AllStark::default(), + self.as_degree_bits_ranges(), + &StarkConfig::standard_fast_config(), + None, + None, + None, + ) } } diff --git a/zero/src/prover_state/mod.rs b/zero/src/prover_state/mod.rs index e56446155..8cdfb45ce 100644 --- a/zero/src/prover_state/mod.rs +++ b/zero/src/prover_state/mod.rs @@ -283,16 +283,14 @@ impl ProverStateManager { } /// Initialize global prover state from the configuration. - pub fn initialize(&self, use_test_config: bool) -> anyhow::Result<()> { + pub fn initialize(&self) -> anyhow::Result<()> { info!("initializing prover state..."); let state = match self.persistence { CircuitPersistence::None => { info!("generating circuits..."); ProverState { - state: self - .circuit_config - .as_all_recursive_circuits(use_test_config), + state: self.circuit_config.as_all_recursive_circuits(), } } CircuitPersistence::Disk(strategy) => { @@ -312,9 +310,8 @@ impl ProverStateManager { } Err(_) => { info!("failed to load preprocessed circuits from disk. generating circuits..."); - let all_recursive_circuits = self - .circuit_config - .as_all_recursive_circuits(use_test_config); + let all_recursive_circuits = + self.circuit_config.as_all_recursive_circuits(); info!("saving preprocessed circuits to disk"); persistence::persist_all_to_disk( &all_recursive_circuits, @@ -346,14 +343,12 @@ impl ProverStateManager { } /// Loads a verifier state from disk or generate it. - pub fn verifier(&self, use_test_config: bool) -> anyhow::Result { + pub fn verifier(&self) -> anyhow::Result { info!("initializing verifier state..."); match self.persistence { CircuitPersistence::None => { info!("generating circuit..."); - let prover_state = self - .circuit_config - .as_all_recursive_circuits(use_test_config); + let prover_state = self.circuit_config.as_all_recursive_circuits(); Ok(VerifierState { state: prover_state.final_verifier_data(), }) @@ -369,9 +364,7 @@ impl ProverStateManager { } Err(_) => { info!("failed to load preprocessed verifier circuit from disk. generating it..."); - let prover_state = self - .circuit_config - .as_all_recursive_circuits(use_test_config); + let prover_state = self.circuit_config.as_all_recursive_circuits(); info!("saving preprocessed verifier circuit to disk"); let state = prover_state.final_verifier_data(); From 5ef571a313818aede3d844720a62ee9b2d5ec591 Mon Sep 17 00:00:00 2001 From: Sai Deng Date: Thu, 24 Oct 2024 10:09:17 -0700 Subject: [PATCH 11/12] comments --- evm_arithmetization/tests/two_to_one_block.rs | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/evm_arithmetization/tests/two_to_one_block.rs b/evm_arithmetization/tests/two_to_one_block.rs index 1ab6a4fe1..93e26f211 100644 --- a/evm_arithmetization/tests/two_to_one_block.rs +++ b/evm_arithmetization/tests/two_to_one_block.rs @@ -11,7 +11,7 @@ use evm_arithmetization::proof::{ use evm_arithmetization::testing_utils::{ beacon_roots_account_nibbles, beacon_roots_contract_from_storage, init_logger, preinitialized_state_and_storage_tries, update_beacon_roots_account_storage, - TEST_RECURSION_CONFIG, TEST_STARK_CONFIG, + TEST_RECURSION_CONFIG, TEST_STARK_CONFIG, TEST_THRESHOLD_DEGREE_BITS, }; use evm_arithmetization::{AllRecursiveCircuits, AllStark, Node, StarkConfig}; use hex_literal::hex; @@ -162,7 +162,6 @@ fn get_test_block_proof( Ok(wrapped_block_proof) } -#[ignore] #[test] fn test_two_to_one_block_aggregation() -> anyhow::Result<()> { init_logger(); @@ -177,7 +176,7 @@ fn test_two_to_one_block_aggregation() -> anyhow::Result<()> { &config, Some(&TEST_RECURSION_CONFIG), Some(&TEST_RECURSION_CONFIG), - None, + Some(TEST_THRESHOLD_DEGREE_BITS), ); let bp = some_timestamps From d6be107904a6a9bec177ebbcf82d02cee2bef00b Mon Sep 17 00:00:00 2001 From: Sai Deng Date: Mon, 28 Oct 2024 11:21:32 -0700 Subject: [PATCH 12/12] comments --- evm_arithmetization/src/fixed_recursive_verifier.rs | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/evm_arithmetization/src/fixed_recursive_verifier.rs b/evm_arithmetization/src/fixed_recursive_verifier.rs index e72a42f29..2f6a639c6 100644 --- a/evm_arithmetization/src/fixed_recursive_verifier.rs +++ b/evm_arithmetization/src/fixed_recursive_verifier.rs @@ -1,5 +1,6 @@ use core::mem::{self, MaybeUninit}; use core::ops::Range; +use std::cmp::max; use std::collections::BTreeMap; use std::sync::atomic::AtomicBool; use std::sync::Arc; @@ -1746,14 +1747,17 @@ where // Pad to match the (non-existing yet!) 2-to-1 circuit's degree. // We use the block circuit's degree as target reference here, as they end up // having same degree. - while log2_ceil(builder.num_gates()) < block.circuit.common.degree_bits() { - builder.add_gate(NoopGate, vec![]); - } + let degree_bits_to_be_padded = block.circuit.common.degree_bits(); // When using test configurations, the block circuit's degree is less than the // 2-to-1 circuit's degree. Therefore, we also need to ensure its size meets // the 2-to-1 circuit's recursion threshold degree bits. - while log2_ceil(builder.num_gates()) < TWO_TO_ONE_BLOCK_CIRCUIT_TEST_THRESHOLD_DEGREE_BITS { + let degree_bits_to_be_padded = max( + degree_bits_to_be_padded, + TWO_TO_ONE_BLOCK_CIRCUIT_TEST_THRESHOLD_DEGREE_BITS, + ); + + while log2_ceil(builder.num_gates()) < degree_bits_to_be_padded { builder.add_gate(NoopGate, vec![]); }