diff --git a/crates/prover/src/core/prover/mod.rs b/crates/prover/src/core/prover/mod.rs index e08a7fc3e..60ddeaefb 100644 --- a/crates/prover/src/core/prover/mod.rs +++ b/crates/prover/src/core/prover/mod.rs @@ -71,7 +71,8 @@ pub fn evaluate_and_commit_on_trace>( Ok((commitment_scheme, interaction_elements)) } -pub fn generate_proof>( +// TODO(spapini): Rename to prove, and rename prover to prove_and_commit. +pub fn prove_without_commit>( air: &impl AirProver, channel: &mut Channel, interaction_elements: &InteractionElements, @@ -161,7 +162,7 @@ pub fn prove>( let (mut commitment_scheme, interaction_elements) = evaluate_and_commit_on_trace(air, channel, &twiddles, trace)?; - generate_proof( + prove_without_commit( air.to_air_prover(), channel, &interaction_elements, @@ -185,6 +186,22 @@ pub fn verify( commitment_scheme.commit(proof.commitments[1], &column_log_sizes[1], channel); } + verify_without_commit( + air, + channel, + &interaction_elements, + &mut commitment_scheme, + proof, + ) +} + +pub fn verify_without_commit( + air: &impl Air, + channel: &mut Blake2sChannel, + interaction_elements: &InteractionElements, + commitment_scheme: &mut CommitmentSchemeVerifier, + proof: StarkProof, +) -> Result<(), VerificationError> { let random_coeff = channel.draw_felt(); // Read composition polynomial commitment. @@ -214,7 +231,7 @@ pub fn verify( oods_point, &trace_oods_values, random_coeff, - &interaction_elements, + interaction_elements, ) { return Err(VerificationError::OodsNotMatching); diff --git a/crates/prover/src/examples/poseidon/mod.rs b/crates/prover/src/examples/poseidon/mod.rs index 60c67c5be..fd4107af0 100644 --- a/crates/prover/src/examples/poseidon/mod.rs +++ b/crates/prover/src/examples/poseidon/mod.rs @@ -414,15 +414,20 @@ mod tests { use tracing::{span, Level}; use super::N_LOG_INSTANCES_PER_ROW; + use crate::core::air::AirExt; use crate::core::backend::simd::SimdBackend; use crate::core::channel::{Blake2sChannel, Channel}; use crate::core::fields::m31::BaseField; use crate::core::fields::IntoSlice; - use crate::core::prover::{prove, verify}; + use crate::core::pcs::{CommitmentSchemeProver, CommitmentSchemeVerifier}; + use crate::core::poly::circle::{CanonicCoset, PolyOps}; + use crate::core::prover::{prove_without_commit, verify_without_commit, LOG_BLOWUP_FACTOR}; use crate::core::vcs::blake2_hash::Blake2sHasher; use crate::core::vcs::hasher::Hasher; + use crate::core::InteractionElements; use crate::examples::poseidon::{ apply_internal_round_matrix, apply_m4, gen_trace, PoseidonAir, PoseidonComponent, + LOG_EXPAND, }; use crate::math::matrix::{RowMajorMatrix, SquareMatrix}; @@ -476,16 +481,55 @@ mod tests { .parse::() .unwrap(); let log_n_rows = log_n_instances - N_LOG_INSTANCES_PER_ROW as u32; - let component = PoseidonComponent { log_n_rows }; - let span = span!(Level::INFO, "Trace generation").entered(); - let trace = gen_trace(component.log_column_size()); + + // Precompute twiddles. + let span = span!(Level::INFO, "Precompute twiddles").entered(); + let twiddles = SimdBackend::precompute_twiddles( + CanonicCoset::new(log_n_rows + LOG_EXPAND + LOG_BLOWUP_FACTOR) + .circle_domain() + .half_coset, + ); span.exit(); + // Setup protocol. let channel = &mut Blake2sChannel::new(Blake2sHasher::hash(BaseField::into_slice(&[]))); - let air = PoseidonAir { component }; - let proof = prove::(&air, channel, trace).unwrap(); + let commitment_scheme = &mut CommitmentSchemeProver::new(LOG_BLOWUP_FACTOR); + + // Trace. + let span = span!(Level::INFO, "Trace").entered(); + let span1 = span!(Level::INFO, "Generation").entered(); + let trace = gen_trace(log_n_rows); + span1.exit(); + commitment_scheme.commit_on_evals(trace, channel, &twiddles); + span.exit(); + // Prove constraints. + let component = PoseidonComponent { log_n_rows }; + let air = PoseidonAir { component }; + let proof = prove_without_commit::( + &air, + channel, + &InteractionElements::default(), + &twiddles, + commitment_scheme, + ) + .unwrap(); + + // Verify. let channel = &mut Blake2sChannel::new(Blake2sHasher::hash(BaseField::into_slice(&[]))); - verify(proof, &air, channel).unwrap(); + let commitment_scheme = &mut CommitmentSchemeVerifier::new(); + + // Decommit. + let sizes = air.column_log_sizes(); + commitment_scheme.commit(proof.commitments[0], &sizes[0], channel); + + verify_without_commit( + &air, + channel, + &InteractionElements::default(), + commitment_scheme, + proof, + ) + .unwrap(); } }