Skip to content

Commit

Permalink
start on multi steps
Browse files Browse the repository at this point in the history
  • Loading branch information
sai-deng committed Nov 9, 2024
1 parent dcd973d commit b9c3365
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 12 deletions.
2 changes: 2 additions & 0 deletions plonky2/src/fri/oracle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,7 @@ impl<F: RichField + Extendable<D>, C: GenericConfig<D, F = F>, const D: usize>
challenger: &mut Challenger<F, C::Hasher>,
fri_params: &FriParams,
final_poly_coeff_len: Option<usize>,
query_round_step_count: Option<usize>,
timing: &mut TimingTree,
) -> FriProof<F, C::Hasher, D> {
assert!(D > 1, "Not implemented for D=1.");
Expand Down Expand Up @@ -228,6 +229,7 @@ impl<F: RichField + Extendable<D>, C: GenericConfig<D, F = F>, const D: usize>
challenger,
fri_params,
final_poly_coeff_len,
query_round_step_count,
timing,
);

Expand Down
14 changes: 13 additions & 1 deletion plonky2/src/fri/prover.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use crate::field::extension::{flatten, unflatten, Extendable};
use crate::field::polynomial::{PolynomialCoeffs, PolynomialValues};
use crate::fri::proof::{FriInitialTreeProof, FriProof, FriQueryRound, FriQueryStep};
use crate::fri::{FriConfig, FriParams};
use crate::hash::hash_types::RichField;
use crate::hash::hash_types::{RichField, NUM_HASH_OUT_ELTS};
use crate::hash::hashing::PlonkyPermutation;
use crate::hash::merkle_tree::MerkleTree;
use crate::iop::challenger::Challenger;
Expand All @@ -28,6 +28,7 @@ pub fn fri_proof<F: RichField + Extendable<D>, C: GenericConfig<D, F = F>, const
challenger: &mut Challenger<F, C::Hasher>,
fri_params: &FriParams,
final_poly_coeff_len: Option<usize>,
query_round_step_count: Option<usize>,
timing: &mut TimingTree,
) -> FriProof<F, C::Hasher, D> {
let n = lde_polynomial_values.len();
Expand All @@ -43,6 +44,7 @@ pub fn fri_proof<F: RichField + Extendable<D>, C: GenericConfig<D, F = F>, const
challenger,
fri_params,
final_poly_coeff_len,
query_round_step_count,
)
);

Expand Down Expand Up @@ -83,6 +85,7 @@ fn fri_committed_trees<F: RichField + Extendable<D>, C: GenericConfig<D, F = F>,
challenger: &mut Challenger<F, C::Hasher>,
fri_params: &FriParams,
final_poly_coeff_len: Option<usize>,
query_round_step_count: Option<usize>,
) -> FriCommitedTrees<F, C, D> {
let mut trees = Vec::with_capacity(fri_params.reduction_arity_bits.len());

Expand Down Expand Up @@ -114,6 +117,15 @@ fn fri_committed_trees<F: RichField + Extendable<D>, C: GenericConfig<D, F = F>,
values = coeffs.coset_fft(shift.into())
}

if let Some(step_count) = query_round_step_count {
let cap_len = 1 << fri_params.config.cap_height * NUM_HASH_OUT_ELTS;
let zero_cap = vec![F::ZERO; cap_len];
for _ in step_count..fri_params.reduction_arity_bits.len() {
challenger.observe_elements(&zero_cap);
challenger.get_extension_challenge::<D>();
}
}

// The coefficients being removed here should always be zero.
coeffs
.coeffs
Expand Down
1 change: 1 addition & 0 deletions plonky2/src/plonk/prover.rs
Original file line number Diff line number Diff line change
Expand Up @@ -341,6 +341,7 @@ where
&mut challenger,
&common_data.fri_params,
None,
None,
timing,
)
);
Expand Down
11 changes: 8 additions & 3 deletions starky/src/fibonacci_stark.rs
Original file line number Diff line number Diff line change
Expand Up @@ -271,11 +271,13 @@ mod tests {
fn test_recursive_verifier_with_multiple_degree_bits() -> Result<()> {
init_logger();

let stark_config = StarkConfig::standard_fast_config();
let mut stark_config = StarkConfig::standard_fast_config();
stark_config.fri_config.num_query_rounds = 1;

let min_degree_bits_to_support = 7;
let verifier_degree_bits = 10;
let verifier_degree_bits = 10; // 14;
let degree_bits = min_degree_bits_to_support..=verifier_degree_bits;
let fri_params = stark_config.fri_params(verifier_degree_bits);

// Generate STARK proofs for each degree in `degree_bits`
let proofs: Vec<_> = degree_bits
Expand All @@ -292,13 +294,16 @@ mod tests {
&stark_config,
trace,
&public_inputs,
Some(verifier_degree_bits),
Some(fri_params.clone()),
&mut TimingTree::default(),
)
.unwrap()
})
.collect();

// dbg!(proofs[0].clone());
// dbg!(proofs[7].clone());

// Configure the circuit for recursive verification
let num_rows = 1 << verifier_degree_bits;
let stark = S::new(num_rows);
Expand Down
23 changes: 15 additions & 8 deletions starky/src/prover.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ use plonky2::field::types::Field;
use plonky2::field::zero_poly_coset::ZeroPolyOnCoset;
use plonky2::fri::oracle::PolynomialBatch;
use plonky2::fri::prover::final_poly_coeff_len;
use plonky2::fri::FriParams;
use plonky2::hash::hash_types::RichField;
use plonky2::iop::challenger::Challenger;
use plonky2::plonk::config::GenericConfig;
Expand All @@ -40,7 +41,7 @@ pub fn prove<F, C, S, const D: usize>(
config: &StarkConfig,
trace_poly_values: Vec<PolynomialValues<F>>,
public_inputs: &[F],
verifier_circuit_degree_bits: Option<usize>,
verifier_circuit_fri_params: Option<FriParams>,
timing: &mut TimingTree,
) -> Result<StarkProofWithPublicInputs<F, C, D>>
where
Expand Down Expand Up @@ -76,14 +77,17 @@ where
challenger.observe_elements(public_inputs);
challenger.observe_cap(&trace_cap);

let final_poly_coeff_len =
if let Some(verifier_circuit_degree_bits) = verifier_circuit_degree_bits {
Some(final_poly_coeff_len(
verifier_circuit_degree_bits,
&fri_params.reduction_arity_bits,
))
let (final_poly_coeff_len, query_round_step_count) =
if let Some(verifier_circuit_fri_params) = verifier_circuit_fri_params {
(
Some(final_poly_coeff_len(
verifier_circuit_fri_params.degree_bits,
&fri_params.reduction_arity_bits,
)),
Some(fri_params.reduction_arity_bits.len()),
)
} else {
None
(None, None)
};
prove_with_commitment(
&stark,
Expand All @@ -95,6 +99,7 @@ where
&mut challenger,
public_inputs,
final_poly_coeff_len,
query_round_step_count,
timing,
)
}
Expand All @@ -116,6 +121,7 @@ pub fn prove_with_commitment<F, C, S, const D: usize>(
challenger: &mut Challenger<F, C::Hasher>,
public_inputs: &[F],
final_poly_coeff_len: Option<usize>,
query_round_step_count: Option<usize>,
timing: &mut TimingTree,
) -> Result<StarkProofWithPublicInputs<F, C, D>>
where
Expand Down Expand Up @@ -333,6 +339,7 @@ where
challenger,
&fri_params,
final_poly_coeff_len,
query_round_step_count,
timing,
)
);
Expand Down

0 comments on commit b9c3365

Please sign in to comment.