From ab5d5f03647fbe36ad915ce15bba8edafe5e8042 Mon Sep 17 00:00:00 2001 From: Sai Deng Date: Mon, 18 Nov 2024 16:42:59 -0800 Subject: [PATCH] build --- Cargo.lock | 13 +- Cargo.toml | 6 +- .../src/fixed_recursive_verifier.rs | 373 ++---------------- evm_arithmetization/src/get_challenges.rs | 3 + evm_arithmetization/src/proof.rs | 12 - evm_arithmetization/src/prover.rs | 2 + evm_arithmetization/src/public_types.rs | 11 +- evm_arithmetization/src/recursive_verifier.rs | 6 + evm_arithmetization/src/verifier.rs | 21 +- zero/src/lib.rs | 1 - zero/src/parsing.rs | 117 ------ zero/src/prover_state/circuit.rs | 114 +----- zero/src/prover_state/cli.rs | 25 +- zero/src/prover_state/mod.rs | 155 +------- zero/src/prover_state/persistence.rs | 19 +- 15 files changed, 118 insertions(+), 760 deletions(-) delete mode 100644 zero/src/parsing.rs diff --git a/Cargo.lock b/Cargo.lock index 2c78e2031..7cfcf5d1a 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3692,7 +3692,6 @@ checksum = "d231b230927b5e4ad203db57bbcbee2802f6bce620b1e4a9024a07d94e2907ec" [[package]] name = "plonky2" version = "0.2.2" -source = "git+https://github.com/0xPolygonZero/plonky2.git?rev=2488cdacd49ede15737bc1172546d82e9521b79b#2488cdacd49ede15737bc1172546d82e9521b79b" dependencies = [ "ahash", "anyhow", @@ -3703,7 +3702,7 @@ dependencies = [ "log", "num", "plonky2_field", - "plonky2_maybe_rayon 0.2.0 (git+https://github.com/0xPolygonZero/plonky2.git?rev=2488cdacd49ede15737bc1172546d82e9521b79b)", + "plonky2_maybe_rayon 0.2.0", "plonky2_util", "rand", "rand_chacha", @@ -3716,7 +3715,6 @@ dependencies = [ [[package]] name = "plonky2_field" version = "0.2.2" -source = "git+https://github.com/0xPolygonZero/plonky2.git?rev=2488cdacd49ede15737bc1172546d82e9521b79b#2488cdacd49ede15737bc1172546d82e9521b79b" dependencies = [ "anyhow", "itertools 0.11.0", @@ -3731,8 +3729,6 @@ dependencies = [ [[package]] name = "plonky2_maybe_rayon" version = "0.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "92ff44a90aaca13e10e7ddf8fab815ba1b404c3f7c3ca82aaf11c46beabaa923" dependencies = [ "rayon", ] @@ -3740,7 +3736,8 @@ dependencies = [ [[package]] name = "plonky2_maybe_rayon" version = "0.2.0" -source = "git+https://github.com/0xPolygonZero/plonky2.git?rev=2488cdacd49ede15737bc1172546d82e9521b79b#2488cdacd49ede15737bc1172546d82e9521b79b" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "92ff44a90aaca13e10e7ddf8fab815ba1b404c3f7c3ca82aaf11c46beabaa923" dependencies = [ "rayon", ] @@ -3748,7 +3745,6 @@ dependencies = [ [[package]] name = "plonky2_util" version = "0.2.0" -source = "git+https://github.com/0xPolygonZero/plonky2.git?rev=2488cdacd49ede15737bc1172546d82e9521b79b#2488cdacd49ede15737bc1172546d82e9521b79b" [[package]] name = "plotters" @@ -4735,7 +4731,6 @@ checksum = "8acdd7dbfcfb5dd6e46c63512508bf71c2043f70b8f143813ad75cb5e8a589f2" [[package]] name = "starky" version = "0.4.0" -source = "git+https://github.com/0xPolygonZero/plonky2.git?rev=2488cdacd49ede15737bc1172546d82e9521b79b#2488cdacd49ede15737bc1172546d82e9521b79b" dependencies = [ "ahash", "anyhow", @@ -4744,7 +4739,7 @@ dependencies = [ "log", "num-bigint", "plonky2", - "plonky2_maybe_rayon 0.2.0 (git+https://github.com/0xPolygonZero/plonky2.git?rev=2488cdacd49ede15737bc1172546d82e9521b79b)", + "plonky2_maybe_rayon 0.2.0", "plonky2_util", "serde", ] diff --git a/Cargo.toml b/Cargo.toml index cadf0a13a..9c0c486ce 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -112,10 +112,10 @@ zk_evm_proc_macro = { path = "proc_macro", version = "0.1.0" } zero = { path = "zero", default-features = false } # plonky2-related dependencies -plonky2 = { git = "https://github.com/0xPolygonZero/plonky2.git", rev = "2488cdacd49ede15737bc1172546d82e9521b79b" } +plonky2 = { path = "../plonky2/plonky2" } plonky2_maybe_rayon = "0.2.0" -plonky2_util = { git = "https://github.com/0xPolygonZero/plonky2.git", rev = "2488cdacd49ede15737bc1172546d82e9521b79b" } -starky = { git = "https://github.com/0xPolygonZero/plonky2.git", rev = "2488cdacd49ede15737bc1172546d82e9521b79b" } +plonky2_util = { path = "../plonky2/util" } +starky = { path = "../plonky2/starky" } [workspace.lints.clippy] too_long_first_doc_paragraph = "allow" diff --git a/evm_arithmetization/src/fixed_recursive_verifier.rs b/evm_arithmetization/src/fixed_recursive_verifier.rs index 54b47a8f2..43205b609 100644 --- a/evm_arithmetization/src/fixed_recursive_verifier.rs +++ b/evm_arithmetization/src/fixed_recursive_verifier.rs @@ -1,11 +1,7 @@ -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; -use anyhow::anyhow; use hashbrown::HashMap; use itertools::{zip_eq, Itertools}; use mpt_trie::partial_trie::{HashedPartialTrie, Node, PartialTrie}; @@ -55,7 +51,7 @@ use crate::recursive_verifier::{ add_common_recursion_gates, add_virtual_final_public_values_public_input, add_virtual_public_values_public_input, get_memory_extra_looking_sum_circuit, recursive_stark_circuit, set_final_public_value_targets, set_public_value_targets, - PlonkWrapperCircuit, PublicInputs, StarkWrapperCircuit, + PlonkWrapperCircuit, PublicInputs, StarkWrapperCircuit, MAX_DEGREE_BITS_TO_SUPPORT, }; use crate::testing_utils::{ TEST_RECURSION_CONFIG, TEST_STARK_CONFIG, TEST_THRESHOLD_DEGREE_BITS, @@ -133,8 +129,7 @@ where /// The two-to-one block aggregation circuit, which verifies two unrelated /// block proofs. pub two_to_one_block: TwoToOneBlockCircuitData, - /// Holds chains of circuits for each table and for each initial - /// `degree_bits`. + /// Holds chains of circuits for each table. pub by_table: [RecursiveCircuitsForTable; NUM_TABLES], /// Dummy proofs of each table for the root circuit. pub table_dummy_proofs: [Option>; NUM_TABLES], @@ -150,10 +145,6 @@ where { pub circuit: CircuitData, proof_with_pis: [ProofWithPublicInputsTarget; NUM_TABLES], - /// For each table, various inner circuits may be used depending on the - /// initial table size. This target holds the index of the circuit - /// (within `final_circuits()`) that was used. - index_verifier_data: [Target; NUM_TABLES], /// Public inputs containing public values. public_values: PublicValuesTarget, /// Public inputs used for cyclic verification. These aren't actually used @@ -179,9 +170,6 @@ where for proof in &self.proof_with_pis { buffer.write_target_proof_with_public_inputs(proof)?; } - for index in self.index_verifier_data { - buffer.write_target(index)?; - } self.public_values.to_buffer(buffer)?; buffer.write_target_verifier_circuit(&self.cyclic_vk)?; for table_in_use in self.table_in_use { @@ -200,10 +188,6 @@ where for _ in 0..NUM_TABLES { proof_with_pis.push(buffer.read_target_proof_with_public_inputs()?); } - let mut index_verifier_data = Vec::with_capacity(NUM_TABLES); - for _ in 0..NUM_TABLES { - index_verifier_data.push(buffer.read_target()?); - } let public_values = PublicValuesTarget::from_buffer(buffer)?; let cyclic_vk = buffer.read_target_verifier_circuit()?; let mut table_in_use = Vec::with_capacity(NUM_TABLES); @@ -214,7 +198,6 @@ where Ok(Self { circuit, proof_with_pis: proof_with_pis.try_into().unwrap(), - index_verifier_data: index_verifier_data.try_into().unwrap(), public_values, cyclic_vk, table_in_use: table_in_use.try_into().unwrap(), @@ -664,21 +647,15 @@ where /// /// # Arguments /// - /// - `skip_tables`: a boolean indicating whether to serialize only the - /// upper circuits or the entire prover state, including recursive - /// circuits to shrink STARK proofs. /// - `gate_serializer`: a custom gate serializer needed to serialize /// recursive circuits common data. /// - `generator_serializer`: a custom generator serializer needed to /// serialize recursive circuits proving data. pub fn to_bytes( &self, - skip_tables: bool, gate_serializer: &dyn GateSerializer, generator_serializer: &dyn WitnessGeneratorSerializer, ) -> IoResult> { - // TODO: would be better to initialize it dynamically based on the supported max - // degree. let mut buffer = Vec::with_capacity(1 << 34); self.root .to_buffer(&mut buffer, gate_serializer, generator_serializer)?; @@ -692,10 +669,8 @@ where .to_buffer(&mut buffer, gate_serializer, generator_serializer)?; self.two_to_one_block .to_buffer(&mut buffer, gate_serializer, generator_serializer)?; - if !skip_tables { - for table in &self.by_table { - table.to_buffer(&mut buffer, gate_serializer, generator_serializer)?; - } + for table in &self.by_table { + table.to_buffer(&mut buffer, gate_serializer, generator_serializer)?; } for table in &self.table_dummy_proofs { match table { @@ -724,7 +699,6 @@ where /// serialize recursive circuits proving data. pub fn from_bytes( bytes: &[u8], - skip_tables: bool, gate_serializer: &dyn GateSerializer, generator_serializer: &dyn WitnessGeneratorSerializer, ) -> IoResult { @@ -754,35 +728,14 @@ where generator_serializer, )?; - let by_table = match skip_tables { - true => (0..NUM_TABLES) - .map(|_| RecursiveCircuitsForTable { - by_stark_size: BTreeMap::default(), - }) - .collect_vec() - .try_into() - .unwrap(), - false => { - // Tricky use of MaybeUninit to remove the need for implementing Debug - // for all underlying types, necessary to convert a by_table Vec to an array. - let mut by_table: [MaybeUninit>; NUM_TABLES] = - unsafe { MaybeUninit::uninit().assume_init() }; - for table in &mut by_table[..] { - let value = RecursiveCircuitsForTable::from_buffer( - &mut buffer, - gate_serializer, - generator_serializer, - )?; - *table = MaybeUninit::new(value); - } - unsafe { - mem::transmute::< - [std::mem::MaybeUninit>; NUM_TABLES], - [RecursiveCircuitsForTable; NUM_TABLES], - >(by_table) - } - } - }; + let by_table = core::array::from_fn(|_| { + RecursiveCircuitsForTable::from_buffer( + &mut buffer, + gate_serializer, + generator_serializer, + ) + .unwrap() + }); let table_dummy_proofs = core::array::from_fn(|_| { if buffer.read_bool().ok()? { @@ -823,11 +776,7 @@ where /// - `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, - degree_bits_ranges: &[Range; NUM_TABLES], - config: RecursionConfig, - ) -> Self { + pub fn new(all_stark: &AllStark, config: RecursionConfig) -> Self { let stark_config = &config.stark_config; // Sanity check on the provided config @@ -838,7 +787,7 @@ where RecursiveCircuitsForTable::new( $table_enum, &all_stark.$stark_field, - degree_bits_ranges[*$table_enum].clone(), + MAX_DEGREE_BITS_TO_SUPPORT, &all_stark.cross_table_lookups, stark_config, &config.shrinking_circuit_config, @@ -885,11 +834,7 @@ where let table_dummy_proofs = core::array::from_fn(|i| { if OPTIONAL_TABLE_INDICES.contains(&i) { - let init_degree = degree_bits_ranges[i].start; - let chain = by_table[i] - .by_stark_size - .get(&init_degree) - .expect("Unable to get the shrinking circuits"); + let chain = &by_table[i]; let common_circuit_data = chain .shrinking_wrappers .last() @@ -946,7 +891,7 @@ where circuit_config: &CircuitConfig, ) -> RootCircuitData { let inner_common_data: [_; NUM_TABLES] = - core::array::from_fn(|i| &by_table[i].final_circuits()[0].common); + core::array::from_fn(|i| &by_table[i].final_circuits().common); let mut builder = CircuitBuilder::new(circuit_config.clone()); @@ -964,7 +909,6 @@ where stark_config, ) }); - let index_verifier_data = core::array::from_fn(|_i| builder.add_virtual_target()); let mut challenger = RecursiveChallenger::::new(&mut builder); for pi in &pis { @@ -1093,40 +1037,20 @@ where ); for (i, table_circuits) in by_table.iter().enumerate() { - let final_circuits = table_circuits.final_circuits(); - for final_circuit in &final_circuits { - assert_eq!( - &final_circuit.common, inner_common_data[i], - "common_data mismatch" - ); - } - let mut possible_vks = final_circuits - .into_iter() - .map(|c| builder.constant_verifier_data(&c.verifier_only)) - .collect_vec(); - // random_access_verifier_data expects a vector whose length is a power of two. - // To satisfy this, we will just add some duplicates of the first VK. - while !possible_vks.len().is_power_of_two() { - possible_vks.push(possible_vks[0].clone()); - } - let inner_verifier_data = - builder.random_access_verifier_data(index_verifier_data[i], possible_vks); + let final_circuit = table_circuits.final_circuits(); + let vk = builder.constant_verifier_data(&final_circuit.verifier_only); if OPTIONAL_TABLE_INDICES.contains(&i) { builder .conditionally_verify_proof_or_dummy::( table_in_use[i], &recursive_proofs[i], - &inner_verifier_data, + &vk, inner_common_data[i], ) .expect("Unable conditionally verify Keccak proofs in the root circuit"); } else { - builder.verify_proof::( - &recursive_proofs[i], - &inner_verifier_data, - inner_common_data[i], - ); + builder.verify_proof::(&recursive_proofs[i], &vk, inner_common_data[i]); } } @@ -1155,7 +1079,6 @@ where RootCircuitData { circuit: builder.build::(), proof_with_pis: recursive_proofs, - index_verifier_data, public_values, cyclic_vk, table_in_use, @@ -2068,13 +1991,12 @@ where timing, abort_signal.clone(), )?; - self.prove_segment_with_all_proofs(&all_proof, config, abort_signal.clone()) + self.prove_segment_with_all_proofs(&all_proof, abort_signal.clone()) } pub fn prove_segment_with_all_proofs( &self, all_proof: &AllProof, - config: &StarkConfig, abort_signal: Option>, ) -> anyhow::Result> { let mut root_inputs = PartialWitness::new(); @@ -2085,27 +2007,8 @@ where let stark_proof = &all_proof.multi_proof.stark_proofs[table] .as_ref() .ok_or_else(|| anyhow::format_err!("Unable to get stark proof"))?; - let original_degree_bits = stark_proof.proof.recover_degree_bits(config); - let shrunk_proof = table_circuits - .by_stark_size - .get(&original_degree_bits) - .ok_or_else(|| { - anyhow!(format!( - "Missing preprocessed circuits for {:?} table with size {}.", - Table::all()[table], - original_degree_bits, - )) - })? - .shrink(stark_proof, &all_proof.multi_proof.ctl_challenges)?; - let index_verifier_data = table_circuits - .by_stark_size - .keys() - .position(|&size| size == original_degree_bits) - .unwrap(); - root_inputs.set_target( - self.root.index_verifier_data[table], - F::from_canonical_usize(index_verifier_data), - )?; + let shrunk_proof = + table_circuits.shrink(stark_proof, &all_proof.multi_proof.ctl_challenges)?; root_inputs .set_proof_with_pis_target(&self.root.proof_with_pis[table], &shrunk_proof)?; } else { @@ -2113,7 +2016,6 @@ where let dummy_proof_data = self.table_dummy_proofs[table] .as_ref() .ok_or_else(|| anyhow::format_err!("No dummy_proof_data"))?; - root_inputs.set_target(self.root.index_verifier_data[table], F::ZERO)?; root_inputs.set_proof_with_pis_target( &self.root.proof_with_pis[table], &dummy_proof_data.proof, @@ -2155,123 +2057,6 @@ where }) } - /// From an initial set of STARK proofs passed with their associated - /// recursive table circuits, generate a recursive transaction proof. - /// It is aimed at being used when preprocessed table circuits have not been - /// loaded to memory. - /// - /// **Note**: - /// The type of the `table_circuits` passed as arguments is - /// `&[(RecursiveCircuitsForTableSize, u8); NUM_TABLES]`. In - /// particular, for each STARK proof contained within the `AllProof` - /// object provided to this method, we need to pass a tuple - /// of [`RecursiveCircuitsForTableSize`] and a [`u8`]. The former - /// is the recursive chain corresponding to the initial degree size of - /// the associated STARK proof. The latter is the index of this degree - /// in the range that was originally passed when constructing the entire - /// prover state. - /// - /// # Usage - /// - /// ```ignore - /// // Load a prover state without its recursive table circuits. - /// let gate_serializer = DefaultGateSerializer; - /// let generator_serializer = DefaultGeneratorSerializer::::new(); - /// let initial_ranges = [16..25, 10..20, 12..25, 14..25, 9..20, 12..20, 17..30]; - /// let prover_state = AllRecursiveCircuits::::new( - /// &all_stark, - /// &initial_ranges, - /// &config, - /// ); - /// - /// // Generate a proof from the provided inputs. - /// let stark_proof = prove::(&all_stark, &config, inputs, &mut timing, abort_signal).unwrap(); - /// - /// // Read the degrees of the internal STARK proofs. - /// // Indices to be passed along the recursive tables - /// // can be easily recovered as `initial_ranges[i]` - `degrees[i]`. - /// let degrees = proof.degree_bits(&config); - /// - /// // Retrieve the corresponding recursive table circuits for each table with the corresponding degree. - /// let table_circuits = { ... }; - /// - /// // Finally shrink the STARK proof. - /// let (proof, public_values) = prove_segment_after_initial_stark( - /// &all_stark, - /// &config, - /// &stark_proof, - /// &table_circuits, - /// &mut timing, - /// abort_signal, - /// ).unwrap(); - /// ``` - pub fn prove_segment_after_initial_stark( - &self, - all_proof: AllProof, - table_circuits: &[Option<(RecursiveCircuitsForTableSize, u8)>; NUM_TABLES], - abort_signal: Option>, - ) -> anyhow::Result> { - let mut root_inputs = PartialWitness::new(); - - for table in 0..NUM_TABLES { - if all_proof.table_in_use[table] { - let (table_circuit, index_verifier_data) = &table_circuits[table] - .as_ref() - .ok_or_else(|| anyhow::format_err!("Unable to get circuits"))?; - root_inputs.set_target( - self.root.index_verifier_data[table], - F::from_canonical_u8(*index_verifier_data), - )?; - let stark_proof = all_proof.multi_proof.stark_proofs[table] - .as_ref() - .ok_or_else(|| anyhow::format_err!("Unable to get stark proof"))?; - let shrunk_proof = - table_circuit.shrink(stark_proof, &all_proof.multi_proof.ctl_challenges)?; - root_inputs - .set_proof_with_pis_target(&self.root.proof_with_pis[table], &shrunk_proof)?; - } else { - assert!(OPTIONAL_TABLE_INDICES.contains(&table)); - let dummy_proof = self.table_dummy_proofs[table] - .as_ref() - .ok_or_else(|| anyhow::format_err!("Unable to get dummpy proof"))?; - root_inputs.set_target(self.root.index_verifier_data[table], F::ZERO)?; - root_inputs.set_proof_with_pis_target( - &self.root.proof_with_pis[table], - &dummy_proof.proof, - )?; - } - - check_abort_signal(abort_signal.clone())?; - } - - root_inputs.set_verifier_data_target( - &self.root.cyclic_vk, - &self.segment_aggregation.circuit.verifier_only, - )?; - - set_public_value_targets( - &mut root_inputs, - &self.root.public_values, - &all_proof.public_values, - ) - .map_err(|_| { - anyhow::Error::msg("Invalid conversion when setting public values targets.") - })?; - - self.root - .table_in_use - .iter() - .zip(all_proof.table_in_use.iter()) - .try_for_each(|(target, value)| root_inputs.set_bool_target(*target, *value))?; - - let root_proof = self.root.circuit.prove(root_inputs)?; - - Ok(ProofWithPublicValues { - public_values: all_proof.public_values, - intern: root_proof, - }) - } - /// Create a segment aggregation proof, combining two contiguous proofs into /// a single one. The combined proofs are segment proofs: they are /// proofs of some parts of one execution. @@ -2896,111 +2681,10 @@ where } } -/// A map between initial degree sizes and their associated shrinking recursion -/// circuits. -#[derive(Eq, PartialEq, Debug)] -pub struct RecursiveCircuitsForTable -where - F: RichField + Extendable, - C: GenericConfig, - C::Hasher: AlgebraicHasher, -{ - /// A map from `log_2(height)` to a chain of shrinking recursion circuits - /// starting at that height. - pub by_stark_size: BTreeMap>, -} - -impl RecursiveCircuitsForTable -where - F: RichField + Extendable, - C: GenericConfig, - C::Hasher: AlgebraicHasher, -{ - fn to_buffer( - &self, - buffer: &mut Vec, - gate_serializer: &dyn GateSerializer, - generator_serializer: &dyn WitnessGeneratorSerializer, - ) -> IoResult<()> { - buffer.write_usize(self.by_stark_size.len())?; - for (&size, table) in &self.by_stark_size { - buffer.write_usize(size)?; - table.to_buffer(buffer, gate_serializer, generator_serializer)?; - } - - Ok(()) - } - - fn from_buffer( - buffer: &mut Buffer, - gate_serializer: &dyn GateSerializer, - generator_serializer: &dyn WitnessGeneratorSerializer, - ) -> IoResult { - let length = buffer.read_usize()?; - let mut by_stark_size = BTreeMap::new(); - for _ in 0..length { - let key = buffer.read_usize()?; - let table = RecursiveCircuitsForTableSize::from_buffer( - buffer, - gate_serializer, - generator_serializer, - )?; - by_stark_size.insert(key, table); - } - - Ok(Self { by_stark_size }) - } - - fn new>( - table: Table, - stark: &S, - 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| { - ( - degree_bits, - RecursiveCircuitsForTableSize::new::( - table, - stark, - degree_bits, - all_ctls, - stark_config, - shrinking_circuit_config, - threshold_degree_bits, - ), - ) - }) - .collect(); - - Self { by_stark_size } - } - - /// For each initial `degree_bits`, get the final circuit at the end of that - /// shrinking chain. Each of these final circuits should have degree - /// `THRESHOLD_DEGREE_BITS`. - fn final_circuits(&self) -> Vec<&CircuitData> { - self.by_stark_size - .values() - .map(|chain| { - chain - .shrinking_wrappers - .last() - .map(|wrapper| &wrapper.circuit) - .unwrap_or(&chain.initial_wrapper.circuit) - }) - .collect() - } -} - /// A chain of shrinking wrapper circuits, ending with a final circuit with /// `degree_bits` `THRESHOLD_DEGREE_BITS`. #[derive(Eq, PartialEq, Debug)] -pub struct RecursiveCircuitsForTableSize +pub struct RecursiveCircuitsForTable where F: RichField + Extendable, C: GenericConfig, @@ -3010,7 +2694,7 @@ where shrinking_wrappers: Vec>, } -impl RecursiveCircuitsForTableSize +impl RecursiveCircuitsForTable where F: RichField + Extendable, C: GenericConfig, @@ -3177,6 +2861,13 @@ where } Ok(proof) } + + fn final_circuits(&self) -> &CircuitData { + self.shrinking_wrappers + .last() + .map(|wrapper| &wrapper.circuit) + .unwrap_or(&self.initial_wrapper.circuit) + } } /// Our usual recursion threshold is 2^12 gates, but for these shrinking diff --git a/evm_arithmetization/src/get_challenges.rs b/evm_arithmetization/src/get_challenges.rs index 23a46d5c5..d7296988c 100644 --- a/evm_arithmetization/src/get_challenges.rs +++ b/evm_arithmetization/src/get_challenges.rs @@ -247,6 +247,7 @@ pub(crate) fn observe_public_values_target< pub mod testing { use plonky2::field::extension::Extendable; + use plonky2::fri::FriParams; use plonky2::hash::hash_types::{RichField, NUM_HASH_OUT_ELTS}; use plonky2::iop::challenger::Challenger; use plonky2::plonk::config::GenericConfig; @@ -273,6 +274,7 @@ pub mod testing { pub(crate) fn get_challenges( &self, config: &StarkConfig, + verifier_circuit_fri_params: Option, ) -> Result, ProgramError> { let mut challenger = Challenger::::new(); @@ -303,6 +305,7 @@ pub mod testing { Some(&ctl_challenges), true, config, + verifier_circuit_fri_params.clone(), )) } else { None diff --git a/evm_arithmetization/src/proof.rs b/evm_arithmetization/src/proof.rs index f501a96d3..f3bab2713 100644 --- a/evm_arithmetization/src/proof.rs +++ b/evm_arithmetization/src/proof.rs @@ -10,7 +10,6 @@ use plonky2::plonk::circuit_builder::CircuitBuilder; use plonky2::plonk::config::{GenericConfig, GenericHashOut, Hasher}; use plonky2::util::serialization::{Buffer, IoResult, Read, Write}; use serde::{Deserialize, Serialize}; -use starky::config::StarkConfig; use starky::lookup::GrandProductChallengeSet; use starky::proof::StarkProofWithMetadata; @@ -53,17 +52,6 @@ pub struct AllProof, C: GenericConfig, co pub table_in_use: [bool; NUM_TABLES], } -impl, C: GenericConfig, const D: usize> AllProof { - /// Returns the degree (i.e. the trace length) of each STARK. - pub fn degree_bits(&self, config: &StarkConfig) -> [Option; NUM_TABLES] { - core::array::from_fn(|i| { - self.multi_proof.stark_proofs[i] - .as_ref() - .map(|proof| proof.proof.recover_degree_bits(config)) - }) - } -} - /// Memory values which are public. #[derive(Debug, Clone, Default, PartialEq, Eq, Deserialize, Serialize)] #[serde(bound = "")] diff --git a/evm_arithmetization/src/prover.rs b/evm_arithmetization/src/prover.rs index 698c23934..41007d61b 100644 --- a/evm_arithmetization/src/prover.rs +++ b/evm_arithmetization/src/prover.rs @@ -328,6 +328,8 @@ where Some(ctl_challenges), challenger, &[], + None, + None, timing, ) .map(|proof_with_pis| StarkProofWithMetadata { diff --git a/evm_arithmetization/src/public_types.rs b/evm_arithmetization/src/public_types.rs index dd38d55fa..9ae36e71c 100644 --- a/evm_arithmetization/src/public_types.rs +++ b/evm_arithmetization/src/public_types.rs @@ -62,12 +62,11 @@ pub type AllRecursiveCircuits = /// A type alias for the recursive chains of circuits needed to shrink EVM STARK /// proofs. -pub type RecursiveCircuitsForTableSize = - crate::fixed_recursive_verifier::RecursiveCircuitsForTableSize< - Field, - RecursionConfig, - { EXTENSION_DEGREE }, - >; +pub type RecursiveCircuitsForTableSize = crate::fixed_recursive_verifier::RecursiveCircuitsForTable< + Field, + RecursionConfig, + { EXTENSION_DEGREE }, +>; /// A type alias for the verifier data necessary to verify succinct block /// proofs. diff --git a/evm_arithmetization/src/recursive_verifier.rs b/evm_arithmetization/src/recursive_verifier.rs index f70b9f166..f56c5e00a 100644 --- a/evm_arithmetization/src/recursive_verifier.rs +++ b/evm_arithmetization/src/recursive_verifier.rs @@ -44,6 +44,9 @@ use crate::proof::{ use crate::util::{h256_limbs, u256_limbs, u256_to_u32, u256_to_u64}; use crate::witness::errors::ProgramError; +pub const MIN_DEGREE_BITS_TO_SUPPORT: usize = 4; +pub const MAX_DEGREE_BITS_TO_SUPPORT: usize = 30; + pub(crate) struct PublicInputs> { pub(crate) trace_cap: Vec>, @@ -155,6 +158,7 @@ where &mut inputs, &self.stark_proof_target, &proof_with_metadata.proof, + proof_with_metadata.proof.degree_bits, self.zero_target, )?; @@ -298,6 +302,8 @@ where challenges, Some(&ctl_vars), inner_config, + MAX_DEGREE_BITS_TO_SUPPORT, + Some(MIN_DEGREE_BITS_TO_SUPPORT), ); add_common_recursion_gates(&mut builder); diff --git a/evm_arithmetization/src/verifier.rs b/evm_arithmetization/src/verifier.rs index 1d4fdf387..69fc03511 100644 --- a/evm_arithmetization/src/verifier.rs +++ b/evm_arithmetization/src/verifier.rs @@ -83,6 +83,7 @@ pub mod testing { use hashbrown::HashMap; use itertools::Itertools; use plonky2::field::extension::Extendable; + use plonky2::fri::FriParams; use plonky2::hash::hash_types::RichField; use plonky2::plonk::config::{GenericConfig, GenericHashOut}; use starky::config::StarkConfig; @@ -178,12 +179,13 @@ pub mod testing { all_proof: AllProof, config: &StarkConfig, is_initial: bool, + verifier_circuit_fri_params: Option, ) -> Result<()> { let AllProofChallenges { stark_challenges, ctl_challenges, } = all_proof - .get_challenges(config) + .get_challenges(config, verifier_circuit_fri_params) .map_err(|_| anyhow::Error::msg("Invalid sampling of proof challenges."))?; let num_lookup_columns = all_stark.num_lookups_helper_columns(config); @@ -519,13 +521,26 @@ pub mod testing { all_stark: &AllStark, all_proofs: &[AllProof], config: &StarkConfig, + verifier_circuit_fri_params: Option, ) -> Result<()> { assert!(!all_proofs.is_empty()); - verify_proof(all_stark, all_proofs[0].clone(), config, true)?; + verify_proof( + all_stark, + all_proofs[0].clone(), + config, + true, + verifier_circuit_fri_params.clone(), + )?; for all_proof in &all_proofs[1..] { - verify_proof(all_stark, all_proof.clone(), config, false)?; + verify_proof( + all_stark, + all_proof.clone(), + config, + false, + verifier_circuit_fri_params.clone(), + )?; } Ok(()) diff --git a/zero/src/lib.rs b/zero/src/lib.rs index c2ca63f6a..76a3e4601 100644 --- a/zero/src/lib.rs +++ b/zero/src/lib.rs @@ -5,7 +5,6 @@ pub mod debug_utils; pub mod env; pub mod fs; pub mod ops; -pub mod parsing; pub mod pre_checks; pub mod proof_types; pub mod prover; diff --git a/zero/src/parsing.rs b/zero/src/parsing.rs deleted file mode 100644 index 5643f82f5..000000000 --- a/zero/src/parsing.rs +++ /dev/null @@ -1,117 +0,0 @@ -//! Parsing utilities. -use std::{fmt::Display, ops::Add, ops::Range, str::FromStr}; - -use thiserror::Error; - -#[derive(Error, Debug, PartialEq)] -pub enum RangeParseError -where - T: FromStr + Display, - T::Err: Display, -{ - #[error("empty input")] - EmptyInput, - #[error("failed to parse right hand side of range: {0}")] - RhsParseError(T::Err), - #[error("failed to parse left hand side of range: {0}. ")] - LhsParseError(T::Err), - #[error("missing left hand size of range. expecting `start..end`")] - LhsMissing, - #[error("missing right hand side of range. expecting `start..end`")] - RhsMissing, -} - -/// Parse an exclusive range from a string. -/// -/// A valid range is of the form `lhs..rhs`, where `lhs` and `rhs` are numbers. -pub(crate) fn parse_range_exclusive( - s: &str, -) -> Result, RangeParseError> -where - NumberT: Display + FromStr + From + Add, - NumberT::Err: Display, -{ - parse_range_gen(s, "..", false) -} - -pub(crate) fn parse_range_gen( - s: &str, - separator: SeparatorT, - inclusive: bool, -) -> Result, RangeParseError> -where - NumberT: Display + FromStr + From + Add, - NumberT::Err: Display, - SeparatorT: AsRef, -{ - let mut pairs = s.split(separator.as_ref()); - match (pairs.next(), pairs.next()) { - // Empty input, "" - (Some(""), None) => Err(RangeParseError::EmptyInput), - // RHS missing, e.g., "10.." or "10" - (Some(_), None | Some("")) => Err(RangeParseError::RhsMissing), - // LHS missing, e.g., "..10" - (Some(""), _) => Err(RangeParseError::LhsMissing), - (Some(lhs), Some(rhs)) => { - let lhs = lhs.parse().map_err(RangeParseError::LhsParseError)?; - let rhs = rhs.parse().map_err(RangeParseError::RhsParseError)?; - if inclusive { - Ok(lhs..(rhs + NumberT::from(1u8))) - } else { - Ok(lhs..rhs) - } - } - // (None, _) is not possible, because split always returns at least one element. - _ => unreachable!(), - } -} - -#[cfg(test)] -mod test { - use super::*; - - #[test] - fn it_parses_exclusive_ranges() { - assert_eq!(parse_range_exclusive::("0..10"), Ok(0..10)); - } - - #[test] - fn it_handles_missing_lhs() { - assert_eq!( - parse_range_exclusive::("..10").unwrap_err(), - RangeParseError::LhsMissing - ); - } - - #[test] - fn it_handles_missing_rhs() { - assert_eq!( - parse_range_exclusive::("10..").unwrap_err(), - RangeParseError::RhsMissing - ); - } - - #[test] - fn it_handles_empty_input() { - assert_eq!( - parse_range_exclusive::("").unwrap_err(), - RangeParseError::EmptyInput - ); - } - - #[test] - fn it_handles_rhs_parse_error() { - assert_eq!( - parse_range_exclusive::("10..f").unwrap_err(), - RangeParseError::RhsParseError("f".parse::().unwrap_err()) - ); - } - - #[test] - fn it_handles_lhs_parse_error() { - assert_eq!( - parse_range_exclusive::("hello..10").unwrap_err(), - RangeParseError::LhsParseError("hello".parse::().unwrap_err()) - ); - } -} diff --git a/zero/src/prover_state/circuit.rs b/zero/src/prover_state/circuit.rs index 9c12738f0..0ebeea89e 100644 --- a/zero/src/prover_state/circuit.rs +++ b/zero/src/prover_state/circuit.rs @@ -1,57 +1,12 @@ //! [`AllRecursiveCircuits`] dynamic circuit configuration. -use std::{ - fmt::Display, - ops::{Deref, Range}, - str::FromStr, -}; +use std::fmt::Display; use evm_arithmetization::fixed_recursive_verifier::RecursionConfig; +use evm_arithmetization::recursive_verifier::MAX_DEGREE_BITS_TO_SUPPORT; pub use evm_arithmetization::NUM_TABLES; use evm_arithmetization::{AllRecursiveCircuits, AllStark}; -use crate::parsing::{parse_range_exclusive, RangeParseError}; - -/// New type wrapper for [`Range`] that implements [`FromStr`] and [`Display`]. -/// -/// Useful for using in clap arguments. -#[derive(Debug, Clone, PartialEq, Eq)] -pub struct CircuitSize(pub Range); - -impl Deref for CircuitSize { - type Target = Range; - - fn deref(&self) -> &Self::Target { - &self.0 - } -} - -impl Display for CircuitSize { - fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - write!(f, "{}..{}", self.start, self.end) - } -} - -impl From> for CircuitSize { - fn from(item: Range) -> Self { - Self(item) - } -} - -impl From for Range { - fn from(item: CircuitSize) -> Self { - item.0 - } -} - -impl FromStr for CircuitSize { - type Err = RangeParseError; - - fn from_str(s: &str) -> Result { - Ok(CircuitSize(parse_range_exclusive(s)?)) - } -} - -/// All possible plonky2 table circuits. +/// All possible Plonky2 table circuits. #[repr(usize)] #[derive(Debug, Clone, Copy)] pub enum Circuit { @@ -76,20 +31,8 @@ impl Display for Circuit { impl Circuit { /// Get the default size for the circuit. - pub const fn default_size(&self) -> Range { - match self { - Circuit::Arithmetic => 16..23, - Circuit::BytePacking => 9..21, - Circuit::Cpu => 12..25, - Circuit::Keccak => 14..20, - Circuit::KeccakSponge => 9..15, - Circuit::Logic => 12..18, - Circuit::Memory => 17..28, - Circuit::MemoryBefore => 7..23, - Circuit::MemoryAfter => 7..27, - #[cfg(feature = "cdk_erigon")] - Circuit::Poseidon => 4..22, - } + pub const fn default_size(&self) -> usize { + MAX_DEGREE_BITS_TO_SUPPORT } /// Get the environment variable key for the circuit. @@ -165,12 +108,12 @@ impl From for Circuit { #[derive(Debug, Clone)] pub struct CircuitConfig { - circuits: [Range; NUM_TABLES], + circuits: [usize; NUM_TABLES], pub use_test_config: bool, } impl std::ops::Index for CircuitConfig { - type Output = Range; + type Output = usize; fn index(&self, index: usize) -> &Self::Output { &self.circuits[index] @@ -178,7 +121,7 @@ impl std::ops::Index for CircuitConfig { } impl std::ops::Index for CircuitConfig { - type Output = Range; + type Output = usize; fn index(&self, index: Circuit) -> &Self::Output { &self.circuits[index as usize] @@ -208,34 +151,32 @@ impl Default for CircuitConfig { impl CircuitConfig { /// Get all circuits specified in the config. - pub fn iter(&self) -> std::slice::Iter<'_, Range> { + pub fn iter(&self) -> std::slice::Iter<'_, usize> { self.circuits.iter() } /// Get all circuits specified in the config with their [`Circuit`] index. - pub fn enumerate(&self) -> impl Iterator)> { + pub fn enumerate(&self) -> impl Iterator { self.circuits .iter() .enumerate() - .map(|(index, range)| (index.into(), range)) + .map(|(index, deg)| (index.into(), deg)) } - /// Set the size of a the given [`Circuit`]. - pub fn set_circuit_size>>(&mut self, key: Circuit, size: T) { - self.circuits[key as usize] = size.into(); + /// Set size of the given [`Circuit`]. + pub fn set_circuit_size(&mut self, key: Circuit, size: usize) { + self.circuits[key as usize] = size; } /// Get all circuits specified in the config. - pub const fn as_degree_bits_ranges(&self) -> &[Range; NUM_TABLES] { + pub const fn as_degree_bits(&self) -> &[usize; NUM_TABLES] { &self.circuits } /// Get a unique string representation of the config. pub fn get_configuration_digest(&self) -> String { self.enumerate() - .map(|(circuit, range)| { - format!("{}_{}-{}", circuit.as_short_str(), range.start, range.end) - }) + .map(|(circuit, deg)| format!("{}-{}", circuit.as_short_str(), deg)) .fold(String::new(), |mut acc, s| { if !acc.is_empty() { acc.push('_'); @@ -248,35 +189,18 @@ impl CircuitConfig { /// Build the circuits from the current config. pub fn as_all_recursive_circuits(&self) -> AllRecursiveCircuits { if self.use_test_config { - AllRecursiveCircuits::new( - &AllStark::default(), - self.as_degree_bits_ranges(), - RecursionConfig::test_config(), - ) + AllRecursiveCircuits::new(&AllStark::default(), RecursionConfig::test_config()) } else { - AllRecursiveCircuits::new( - &AllStark::default(), - self.as_degree_bits_ranges(), - RecursionConfig::default(), - ) + AllRecursiveCircuits::new(&AllStark::default(), RecursionConfig::default()) } } } impl IntoIterator for CircuitConfig { - type Item = Range; + type Item = usize; type IntoIter = std::array::IntoIter; fn into_iter(self) -> Self::IntoIter { self.circuits.into_iter() } } - -impl<'a> IntoIterator for &'a CircuitConfig { - type Item = &'a Range; - type IntoIter = std::slice::Iter<'a, Range>; - - fn into_iter(self) -> Self::IntoIter { - self.circuits.iter() - } -} diff --git a/zero/src/prover_state/cli.rs b/zero/src/prover_state/cli.rs index ce0457dec..6bc7c4fce 100644 --- a/zero/src/prover_state/cli.rs +++ b/zero/src/prover_state/cli.rs @@ -5,8 +5,8 @@ use std::fmt::Display; use clap::{Args, ValueEnum}; use super::{ - circuit::{Circuit, CircuitConfig, CircuitSize}, - ProverStateManager, TableLoadStrategy, + circuit::{Circuit, CircuitConfig}, + ProverStateManager, }; /// The help heading for the circuit arguments. @@ -32,18 +32,6 @@ pub enum CircuitPersistence { Disk, } -impl CircuitPersistence { - pub const fn with_load_strategy( - self, - load_strategy: TableLoadStrategy, - ) -> super::CircuitPersistence { - match self { - CircuitPersistence::None => super::CircuitPersistence::None, - CircuitPersistence::Disk => super::CircuitPersistence::Disk(load_strategy), - } - } -} - impl Display for CircuitPersistence { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { match self { @@ -60,8 +48,6 @@ macro_rules! gen_prover_state_config { pub struct CliProverStateConfig { #[clap(long, help_heading = HEADING, default_value_t = CircuitPersistence::Disk)] pub persistence: CircuitPersistence, - #[clap(long, help_heading = HEADING, default_value_t = TableLoadStrategy::OnDemand)] - pub load_strategy: TableLoadStrategy, /// Run with a low-security but fast STARK configuration. Enable this only for testing. #[arg(long)] pub use_test_config: bool, @@ -74,7 +60,7 @@ macro_rules! gen_prover_state_config { env = $circuit.as_env_key(), help = circuit_arg_desc($circuit.as_str()), )] - pub $name: Option, + pub $name: Option, )* } }; @@ -117,7 +103,10 @@ impl CliProverStateConfig { pub fn into_prover_state_manager(self) -> ProverStateManager { ProverStateManager { - persistence: self.persistence.with_load_strategy(self.load_strategy), + persistence: match self.persistence { + CircuitPersistence::None => super::CircuitPersistence::None, + CircuitPersistence::Disk => super::CircuitPersistence::Disk, + }, circuit_config: self.into_circuit_config(), } } diff --git a/zero/src/prover_state/mod.rs b/zero/src/prover_state/mod.rs index f9d72c82f..b78f87546 100644 --- a/zero/src/prover_state/mod.rs +++ b/zero/src/prover_state/mod.rs @@ -14,25 +14,20 @@ use std::borrow::Borrow; use std::sync::atomic::AtomicBool; use std::sync::Arc; -use std::{fmt::Display, sync::OnceLock}; +use std::sync::OnceLock; -use clap::ValueEnum; use evm_arithmetization::testing_utils::TEST_STARK_CONFIG; use evm_arithmetization::{ - fixed_recursive_verifier::ProverOutputData, prover::prove, AllProof, AllRecursiveCircuits, - AllStark, GenerationSegmentData, RecursiveCircuitsForTableSize, StarkConfig, - TrimmedGenerationInputs, + fixed_recursive_verifier::ProverOutputData, AllRecursiveCircuits, AllStark, + GenerationSegmentData, StarkConfig, TrimmedGenerationInputs, }; use evm_arithmetization::{ProofWithPublicInputs, ProofWithPublicValues, VerifierData}; use plonky2::recursion::cyclic_recursion::check_cyclic_proof_verifier_data; use plonky2::util::timing::TimingTree; use tracing::info; -use self::circuit::{CircuitConfig, NUM_TABLES}; -use crate::prover_state::persistence::{ - BaseProverResource, DiskResource, MonolithicProverResource, RecursiveCircuitResource, - VerifierResource, -}; +use self::circuit::CircuitConfig; +use crate::prover_state::persistence::{DiskResource, MonolithicProverResource, VerifierResource}; pub mod circuit; pub mod cli; @@ -105,41 +100,18 @@ pub fn p_manager() -> &'static ProverStateManager { .expect("Prover state manager is not initialized") } -/// Specifies how to load the table circuits. -#[derive(Debug, Clone, Copy, Default, ValueEnum)] -pub enum TableLoadStrategy { - #[default] - /// Load the circuit tables as needed for shrinking STARK proofs. - /// - /// - Generate a STARK proof. - /// - Compute the degree bits. - /// - Load the necessary table circuits. - OnDemand, - /// Load all the table circuits into a monolithic bundle. - Monolithic, -} - -impl Display for TableLoadStrategy { - fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - match self { - TableLoadStrategy::OnDemand => write!(f, "on-demand"), - TableLoadStrategy::Monolithic => write!(f, "monolithic"), - } - } -} - /// Specifies whether to persist the processed circuits. #[derive(Debug, Clone, Copy)] pub enum CircuitPersistence { /// Do not persist the processed circuits. None, /// Persist the processed circuits to disk. - Disk(TableLoadStrategy), + Disk, } impl Default for CircuitPersistence { fn default() -> Self { - CircuitPersistence::Disk(TableLoadStrategy::default()) + CircuitPersistence::Disk } } @@ -154,87 +126,6 @@ pub struct ProverStateManager { } impl ProverStateManager { - pub const fn with_load_strategy(self, load_strategy: TableLoadStrategy) -> Self { - match self.persistence { - CircuitPersistence::None => self, - CircuitPersistence::Disk(_) => Self { - circuit_config: self.circuit_config, - persistence: CircuitPersistence::Disk(load_strategy), - }, - } - } - - /// Load the table circuits necessary to shrink the STARK proof. - /// - /// [`AllProof`] provides the necessary degree bits for each circuit via the - /// [`AllProof::degree_bits`] method. - /// Using this information, for each circuit, a tuple is returned, - /// containing: - /// 1. The loaded table circuit at the specified size. - /// 2. An offset indicating the position of the specified size within the - /// configured range used when pre-generating the circuits. - fn load_table_circuits( - &self, - config: &StarkConfig, - all_proof: &AllProof, - ) -> anyhow::Result<[Option<(RecursiveCircuitsForTableSize, u8)>; NUM_TABLES]> { - let degrees = all_proof.degree_bits(config); - - // Given a recursive circuit index (e.g., Arithmetic / 0), return a - // tuple containing the loaded table at the specified size and - // its offset relative to the configured range used to pre-process the - // circuits. - let circuits = core::array::from_fn(|i| match degrees[i] { - Some(size) => RecursiveCircuitResource::get(&(i.into(), size)) - .map(|circuit_resource| { - Some(( - circuit_resource, - (size - self.circuit_config[i].start) as u8, - )) - }) - .map_err(|e| { - anyhow::Error::from(e) - .context(format!("Attempting to load circuit: {i} at size: {size}")) - }) - .unwrap_or(None), - None => None, - }); - - Ok(circuits) - } - - /// Generate a segment proof using the specified input, loading - /// the circuit tables as needed to shrink the individual STARK proofs, - /// and finally aggregating them to a final transaction proof. - fn segment_proof_on_demand( - &self, - input: TrimmedGenerationInputs, - segment_data: &mut GenerationSegmentData, - config: &StarkConfig, - abort_signal: Option>, - ) -> anyhow::Result { - let all_stark = AllStark::default(); - - let all_proof = prove( - &all_stark, - config, - input, - segment_data, - &mut TimingTree::default(), - abort_signal.clone(), - )?; - - let table_circuits = self.load_table_circuits(config, &all_proof)?; - - let proof_with_pvs = p_state().state.prove_segment_after_initial_stark( - all_proof, - &table_circuits, - abort_signal, - )?; - - Ok(proof_with_pvs) - } - /// Generate a segment proof using the specified input on the monolithic /// circuit. fn segment_proof_monolithic( @@ -283,26 +174,7 @@ impl ProverStateManager { StarkConfig::standard_fast_config() }; - match self.persistence { - CircuitPersistence::None | CircuitPersistence::Disk(TableLoadStrategy::Monolithic) => { - info!("using monolithic circuit {:?}", self); - self.segment_proof_monolithic( - generation_inputs, - &mut segment_data, - &config, - abort_signal, - ) - } - CircuitPersistence::Disk(TableLoadStrategy::OnDemand) => { - info!("using on demand circuit {:?}", self); - self.segment_proof_on_demand( - generation_inputs, - &mut segment_data, - &config, - abort_signal, - ) - } - } + self.segment_proof_monolithic(generation_inputs, &mut segment_data, &config, abort_signal) } /// Initialize global prover state from the configuration. @@ -316,15 +188,10 @@ impl ProverStateManager { state: self.circuit_config.as_all_recursive_circuits(), } } - CircuitPersistence::Disk(strategy) => { + CircuitPersistence::Disk => { info!("attempting to load preprocessed circuits from disk..."); - let disk_state = match strategy { - TableLoadStrategy::OnDemand => BaseProverResource::get(&self.circuit_config), - TableLoadStrategy::Monolithic => { - MonolithicProverResource::get(&self.circuit_config) - } - }; + let disk_state = MonolithicProverResource::get(&self.circuit_config); match disk_state { Ok(circuits) => { @@ -376,7 +243,7 @@ impl ProverStateManager { state: prover_state.final_verifier_data(), }) } - CircuitPersistence::Disk(_) => { + CircuitPersistence::Disk => { info!("attempting to load preprocessed verifier circuit from disk..."); let disk_state = VerifierResource::get(&self.circuit_config); diff --git a/zero/src/prover_state/persistence.rs b/zero/src/prover_state/persistence.rs index fbd7be2d0..75b57a029 100644 --- a/zero/src/prover_state/persistence.rs +++ b/zero/src/prover_state/persistence.rs @@ -142,13 +142,13 @@ impl DiskResource for BaseProverResource { r // Note we are using the `true` flag to write only the upper circuits. // The individual circuit tables are written separately below. - .to_bytes(true, &gate_serializer, &witness_serializer) + .to_bytes(&gate_serializer, &witness_serializer) .map_err(DiskResourceError::Serialization) } fn deserialize(bytes: &[u8]) -> Result> { let (gate_serializer, witness_serializer) = get_serializers(); - AllRecursiveCircuits::from_bytes(bytes, true, &gate_serializer, &witness_serializer) + AllRecursiveCircuits::from_bytes(bytes, &gate_serializer, &witness_serializer) .map_err(DiskResourceError::Serialization) } } @@ -177,13 +177,13 @@ impl DiskResource for MonolithicProverResource { r // Note we are using the `false` flag to write all circuits. - .to_bytes(false, &gate_serializer, &witness_serializer) + .to_bytes(&gate_serializer, &witness_serializer) .map_err(DiskResourceError::Serialization) } fn deserialize(bytes: &[u8]) -> Result> { let (gate_serializer, witness_serializer) = get_serializers(); - AllRecursiveCircuits::from_bytes(bytes, false, &gate_serializer, &witness_serializer) + AllRecursiveCircuits::from_bytes(bytes, &gate_serializer, &witness_serializer) .map_err(DiskResourceError::Serialization) } } @@ -195,16 +195,15 @@ pub(crate) struct RecursiveCircuitResource; impl DiskResource for RecursiveCircuitResource { type Resource = RecursiveCircuitsForTableSize; type Error = IoError; - type PathConstrutor = (Circuit, usize); + type PathConstrutor = Circuit; - fn path((circuit_type, size): &Self::PathConstrutor) -> impl AsRef { + fn path(circuit_type: &Self::PathConstrutor) -> impl AsRef { format!( - "{}/{}_{}_{}_{}", + "{}/{}_{}_{}", circuit_dir(), PROVER_STATE_FILE_PREFIX, *KERNEL_HASH, circuit_type.as_short_str(), - size ) } @@ -321,9 +320,7 @@ fn prover_to_disk( // allows us to load only the necessary tables when needed. for (circuit_type, tables) in circuits.by_table.iter().enumerate() { let circuit_type: Circuit = circuit_type.into(); - for (size, table) in tables.by_stark_size.iter() { - RecursiveCircuitResource::put(&(circuit_type, *size), table)?; - } + RecursiveCircuitResource::put(&circuit_type, tables)?; } Ok(())