Skip to content

Commit

Permalink
Refactor recursion params (#769)
Browse files Browse the repository at this point in the history
* init

* do not use option

* add test

* polish tests

* remove test for now, since it is too slow

* revert

* revert

* Update evm_arithmetization/src/fixed_recursive_verifier.rs

Co-authored-by: Robin Salen <[email protected]>

* comments

* Pacify clippy

---------

Co-authored-by: Robin Salen <[email protected]>
Co-authored-by: Robin Salen <[email protected]>
  • Loading branch information
3 people authored Nov 5, 2024
1 parent 51cf498 commit deba488
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 42 deletions.
66 changes: 50 additions & 16 deletions evm_arithmetization/src/fixed_recursive_verifier.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,10 @@ 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::testing_utils::{
TEST_RECURSION_CONFIG, TEST_STARK_CONFIG, TEST_THRESHOLD_DEGREE_BITS,
TWO_TO_ONE_BLOCK_CIRCUIT_TEST_THRESHOLD_DEGREE_BITS,
};
use crate::util::h256_limbs;
use crate::verifier::initial_memory_merkle_cap;

Expand Down Expand Up @@ -615,6 +618,42 @@ impl<F: RichField + Extendable<D>, C: GenericConfig<D, F = F>, const D: usize>
}
}

/// A struct containing the parameters for configuration of
/// `AllRecursiveCircuits`.
pub struct RecursionConfig {
/// The configuration to be used for the STARK table prover.
pub stark_config: StarkConfig,
/// The configuration for the shrinking circuit.
pub shrinking_circuit_config: CircuitConfig,
/// The configuration for the recursion circuits.
pub recursion_circuit_config: CircuitConfig,
/// The recursion threshold in degree bits.
pub threshold_degree_bits: usize,
}

impl Default for RecursionConfig {
fn default() -> Self {
RecursionConfig {
stark_config: StarkConfig::standard_fast_config(),
shrinking_circuit_config: shrinking_config(),
recursion_circuit_config: CircuitConfig::standard_recursion_config(),
threshold_degree_bits: THRESHOLD_DEGREE_BITS,
}
}
}

impl RecursionConfig {
/// Returns a test configuration for `RecursionConfig`.
pub fn test_config() -> Self {
RecursionConfig {
stark_config: TEST_STARK_CONFIG,
shrinking_circuit_config: TEST_RECURSION_CONFIG,
recursion_circuit_config: TEST_RECURSION_CONFIG,
threshold_degree_bits: TEST_THRESHOLD_DEGREE_BITS,
}
}
}

impl<F, C, const D: usize> AllRecursiveCircuits<F, C, D>
where
F: RichField + Extendable<D>,
Expand Down Expand Up @@ -781,25 +820,19 @@ where
/// starting from that length, for each `degree_bits` in the range specified
/// for this STARK module. Specifying a wide enough range allows a
/// prover to cover all possible scenarios.
/// - `stark_config`: the configuration to be used for the STARK prover. It
/// will usually be a fast one yielding large proofs.
/// - `config`: the set of configurations to be used for the different proof
/// layers. It will usually be a fast one yielding large proofs for the
/// base STARK prover, and a more flexible one for the recursive layers.
pub fn new(
all_stark: &AllStark<F, D>,
degree_bits_ranges: &[Range<usize>; NUM_TABLES],
stark_config: &StarkConfig,
shrinking_circuit_config: Option<&CircuitConfig>,
recursion_circuit_config: Option<&CircuitConfig>,
threshold_degree_bits: Option<usize>,
config: RecursionConfig,
) -> Self {
let stark_config = &config.stark_config;

// 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 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 {
($table_enum:expr, $stark_field:ident) => {
RecursiveCircuitsForTable::new(
Expand All @@ -808,8 +841,8 @@ where
degree_bits_ranges[*$table_enum].clone(),
&all_stark.cross_table_lookups,
stark_config,
shrinking_circuit_config,
threshold_degree_bits,
&config.shrinking_circuit_config,
config.threshold_degree_bits,
)
};
}
Expand Down Expand Up @@ -841,7 +874,8 @@ where
poseidon,
];

let root = Self::create_segment_circuit(&by_table, stark_config, recursion_circuit_config);
let root =
Self::create_segment_circuit(&by_table, stark_config, &config.recursion_circuit_config);
let segment_aggregation = Self::create_segment_aggregation_circuit(&root);
let batch_aggregation =
Self::create_batch_aggregation_circuit(&segment_aggregation, stark_config);
Expand Down
10 changes: 3 additions & 7 deletions evm_arithmetization/tests/empty_tables.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,10 @@

use std::time::Duration;

use evm_arithmetization::fixed_recursive_verifier::AllRecursiveCircuits;
use evm_arithmetization::fixed_recursive_verifier::{AllRecursiveCircuits, RecursionConfig};
use evm_arithmetization::prover::prove;
use evm_arithmetization::testing_utils::{
init_logger, segment_with_empty_tables, TEST_RECURSION_CONFIG, TEST_STARK_CONFIG,
TEST_THRESHOLD_DEGREE_BITS,
init_logger, segment_with_empty_tables, TEST_STARK_CONFIG,
};
use evm_arithmetization::verifier::testing::verify_all_proofs;
use evm_arithmetization::AllStark;
Expand Down Expand Up @@ -60,10 +59,7 @@ fn empty_tables() -> anyhow::Result<()> {
AllRecursiveCircuits::<F, C, D>::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),
RecursionConfig::test_config(),
)
);

Expand Down
10 changes: 3 additions & 7 deletions evm_arithmetization/tests/two_to_one_block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,15 @@

use ethereum_types::{Address, BigEndianHash, H256};
use evm_arithmetization::fixed_recursive_verifier::{
extract_block_final_public_values, extract_two_to_one_block_hash,
extract_block_final_public_values, extract_two_to_one_block_hash, RecursionConfig,
};
use evm_arithmetization::generation::{GenerationInputs, TrieInputs};
use evm_arithmetization::proof::{
BlockMetadata, FinalPublicValues, PublicValues, TrieRoots, EMPTY_CONSOLIDATED_BLOCKHASH,
};
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_THRESHOLD_DEGREE_BITS,
preinitialized_state_and_storage_tries, update_beacon_roots_account_storage, TEST_STARK_CONFIG,
};
use evm_arithmetization::{AllRecursiveCircuits, AllStark, Node, StarkConfig};
use hex_literal::hex;
Expand Down Expand Up @@ -173,10 +172,7 @@ fn test_two_to_one_block_aggregation() -> anyhow::Result<()> {
let all_circuits = AllRecursiveCircuits::new(
&all_stark,
&[16..17, 8..9, 12..13, 8..9, 8..9, 6..7, 17..18, 16..17, 7..8],
&config,
Some(&TEST_RECURSION_CONFIG),
Some(&TEST_RECURSION_CONFIG),
Some(TEST_THRESHOLD_DEGREE_BITS),
RecursionConfig::test_config(),
);

let bp = some_timestamps
Expand Down
16 changes: 4 additions & 12 deletions zero/src/prover_state/circuit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,9 @@ use std::{
str::FromStr,
};

use evm_arithmetization::testing_utils::{
TEST_RECURSION_CONFIG, TEST_STARK_CONFIG, TEST_THRESHOLD_DEGREE_BITS,
};
use evm_arithmetization::fixed_recursive_verifier::RecursionConfig;
pub use evm_arithmetization::NUM_TABLES;
use evm_arithmetization::{AllRecursiveCircuits, AllStark, StarkConfig};
use evm_arithmetization::{AllRecursiveCircuits, AllStark};

use crate::parsing::{parse_range_exclusive, RangeParseError};

Expand Down Expand Up @@ -253,19 +251,13 @@ impl CircuitConfig {
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),
RecursionConfig::test_config(),
)
} else {
AllRecursiveCircuits::new(
&AllStark::default(),
self.as_degree_bits_ranges(),
&StarkConfig::standard_fast_config(),
None,
None,
None,
RecursionConfig::default(),
)
}
}
Expand Down

0 comments on commit deba488

Please sign in to comment.