Skip to content

Commit

Permalink
Fix bench_recursion and a bit of cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
LindaGuiga committed Sep 7, 2024
1 parent 1650fee commit b79391b
Show file tree
Hide file tree
Showing 12 changed files with 546 additions and 180 deletions.
1 change: 0 additions & 1 deletion plonky2/src/fri/witness_util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,6 @@ where
tmp.push((vec![], dummy_proof));
tmp
} else {
println!("we're good");
q.initial_trees_proof.evals_proofs.clone()
};
for (at, a) in qt
Expand Down
22 changes: 20 additions & 2 deletions plonky2/src/iop/witness.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
use alloc::{vec, vec::Vec};
use core::iter::zip;

use anyhow::{anyhow, Result};
use anyhow::{anyhow, ensure, Result};
use hashbrown::HashMap;
use itertools::{zip_eq, Itertools};

Expand Down Expand Up @@ -45,6 +45,24 @@ pub trait WitnessWrite<F: Field> {
Ok(())
}

fn set_opt_cap_target<H: AlgebraicHasher<F>>(
&mut self,
opt_ct: &Option<MerkleCapTarget>,
opt_value: &Option<MerkleCap<F, H>>,
) -> Result<()>
where
F: RichField,
{
ensure!(opt_ct.is_some() == opt_value.is_some());
if let (Some(ct), Some(value)) = (opt_ct, opt_value) {
for (ht, h) in ct.0.iter().zip(&value.0) {
self.set_hash_target(*ht, *h)?;
}
}

Ok(())
}

fn set_extension_target<const D: usize>(
&mut self,
et: ExtensionTarget<D>,
Expand Down Expand Up @@ -128,7 +146,7 @@ pub trait WitnessWrite<F: Field> {
&proof.plonk_zs_partial_products_cap,
)?;
self.set_cap_target(&proof_target.quotient_polys_cap, &proof.quotient_polys_cap)?;
self.set_cap_target(&proof_target.random_r, &proof.random_r)?;
self.set_opt_cap_target(&proof_target.opt_random_r, &proof.opt_random_r)?;

self.set_fri_openings(
&proof_target.openings.to_fri_openings(),
Expand Down
95 changes: 64 additions & 31 deletions plonky2/src/plonk/circuit_data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -576,28 +576,49 @@ impl<F: RichField + Extendable<D>, const D: usize> CommonCircuitData<F, D> {
}

fn fri_oracles(&self) -> Vec<FriOracleInfo> {
vec![
FriOracleInfo {
num_polys: self.num_preprocessed_polys(),
blinding: PlonkOracle::CONSTANTS_SIGMAS.blinding,
},
FriOracleInfo {
num_polys: self.config.num_wires,
blinding: PlonkOracle::WIRES.blinding,
},
FriOracleInfo {
num_polys: self.num_zs_partial_products_polys() + self.num_all_lookup_polys(),
blinding: PlonkOracle::ZS_PARTIAL_PRODUCTS.blinding,
},
FriOracleInfo {
num_polys: self.num_quotient_polys(),
blinding: PlonkOracle::QUOTIENT.blinding,
},
FriOracleInfo {
num_polys: self.num_r_polys(),
blinding: PlonkOracle::R.blinding,
},
]
if self.num_r_polys() > 0 {
vec![
FriOracleInfo {
num_polys: self.num_preprocessed_polys(),
blinding: PlonkOracle::CONSTANTS_SIGMAS.blinding,
},
FriOracleInfo {
num_polys: self.config.num_wires,
blinding: PlonkOracle::WIRES.blinding,
},
FriOracleInfo {
num_polys: self.num_zs_partial_products_polys() + self.num_all_lookup_polys(),
blinding: PlonkOracle::ZS_PARTIAL_PRODUCTS.blinding,
},
FriOracleInfo {
num_polys: self.num_quotient_polys(),
blinding: PlonkOracle::QUOTIENT.blinding,
},
FriOracleInfo {
num_polys: self.num_r_polys(),
blinding: PlonkOracle::R.blinding,
},
]
} else {
vec![
FriOracleInfo {
num_polys: self.num_preprocessed_polys(),
blinding: PlonkOracle::CONSTANTS_SIGMAS.blinding,
},
FriOracleInfo {
num_polys: self.config.num_wires,
blinding: PlonkOracle::WIRES.blinding,
},
FriOracleInfo {
num_polys: self.num_zs_partial_products_polys() + self.num_all_lookup_polys(),
blinding: PlonkOracle::ZS_PARTIAL_PRODUCTS.blinding,
},
FriOracleInfo {
num_polys: self.num_quotient_polys(),
blinding: PlonkOracle::QUOTIENT.blinding,
},
]
}
}

fn fri_preprocessed_polys(&self) -> Vec<FriPolynomialInfo> {
Expand Down Expand Up @@ -667,15 +688,27 @@ impl<F: RichField + Extendable<D>, const D: usize> CommonCircuitData<F, D> {
}

fn fri_all_polys(&self) -> Vec<FriPolynomialInfo> {
[
self.fri_preprocessed_polys(),
self.fri_wire_polys(),
self.fri_zs_partial_products_polys(),
self.fri_quotient_polys(),
self.fri_lookup_polys(),
self.fri_r_polys(),
]
.concat()
let num_r_polys = self.num_r_polys();
if num_r_polys > 0 {
[
self.fri_preprocessed_polys(),
self.fri_wire_polys(),
self.fri_zs_partial_products_polys(),
self.fri_quotient_polys(),
self.fri_lookup_polys(),
self.fri_r_polys(),
]
.concat()
} else {
[
self.fri_preprocessed_polys(),
self.fri_wire_polys(),
self.fri_zs_partial_products_polys(),
self.fri_quotient_polys(),
self.fri_lookup_polys(),
]
.concat()
}
}
}

Expand Down
6 changes: 3 additions & 3 deletions plonky2/src/plonk/get_challenges.rs
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ impl<F: RichField + Extendable<D>, C: GenericConfig<D, F = F>, const D: usize>
wires_cap,
plonk_zs_partial_products_cap,
quotient_polys_cap,
random_r,
opt_random_r,
openings,
opening_proof:
FriProof {
Expand Down Expand Up @@ -154,7 +154,7 @@ impl<F: RichField + Extendable<D>, C: GenericConfig<D, F = F>, const D: usize>
wires_cap,
plonk_zs_partial_products_cap,
quotient_polys_cap,
random_r,
opt_random_r,
openings,
opening_proof:
CompressedFriProof {
Expand Down Expand Up @@ -344,7 +344,7 @@ impl<const D: usize> ProofWithPublicInputsTarget<D> {
wires_cap,
plonk_zs_partial_products_cap,
quotient_polys_cap,
random_r,
opt_random_r,
openings,
opening_proof:
FriProofTarget {
Expand Down
Loading

0 comments on commit b79391b

Please sign in to comment.