mirror of
https://github.com/logos-storage/plonky2.git
synced 2026-01-07 16:23:12 +00:00
calculating number of blinding gates needed
This commit is contained in:
parent
30f23fedb9
commit
249c8a8378
@ -18,7 +18,7 @@ use crate::permutation_argument::TargetPartitions;
|
|||||||
use crate::polynomial::commitment::ListPolynomialCommitment;
|
use crate::polynomial::commitment::ListPolynomialCommitment;
|
||||||
use crate::polynomial::polynomial::PolynomialValues;
|
use crate::polynomial::polynomial::PolynomialValues;
|
||||||
use crate::target::Target;
|
use crate::target::Target;
|
||||||
use crate::util::{log2_strict, transpose};
|
use crate::util::{log2_strict, log2_ceil, transpose};
|
||||||
use crate::wire::Wire;
|
use crate::wire::Wire;
|
||||||
|
|
||||||
pub struct CircuitBuilder<F: Extendable<D>, const D: usize> {
|
pub struct CircuitBuilder<F: Extendable<D>, const D: usize> {
|
||||||
@ -203,7 +203,43 @@ impl<F: Extendable<D>, const D: usize> CircuitBuilder<F, D> {
|
|||||||
self.targets_to_constants.get(&target).cloned()
|
self.targets_to_constants.get(&target).cloned()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn num_blinding_gates(&self, degree_estimate: usize) -> usize {
|
||||||
|
let fri_queries = self.config.fri_config.num_query_rounds;
|
||||||
|
let arities: Vec<usize> = self.config.fri_config.reduction_arity_bits.iter().map(|x| 1 << x).collect();
|
||||||
|
let total_fri_folding_points : usize = arities.iter().map(|x| x - 1).sum::<usize>();
|
||||||
|
let final_poly_coeffs : usize = degree_estimate >> arities.iter().sum::<usize>();
|
||||||
|
let fri_openings = fri_queries * (1 + total_fri_folding_points + final_poly_coeffs);
|
||||||
|
|
||||||
|
let regular_poly_openings = D + fri_openings;
|
||||||
|
let z_openings = 2 * D + fri_openings;
|
||||||
|
|
||||||
|
// For most polynomials, we add one random element to offset each opened value.
|
||||||
|
// But blinding Z is separate. For that, we add two random elements with a copy
|
||||||
|
// constraint between them.
|
||||||
|
regular_poly_openings + 2 * z_openings
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/// The number of polynomial values that will be revealed per opening.
|
||||||
|
fn blinding_count(&self) -> usize {
|
||||||
|
let num_gates = self.gates.len();
|
||||||
|
let mut degree_estimate = 1 << log2_ceil(num_gates);
|
||||||
|
|
||||||
|
loop {
|
||||||
|
let blinding_count = self.num_blinding_gates(degree_estimate);
|
||||||
|
|
||||||
|
if num_gates + blinding_count <= degree_estimate {
|
||||||
|
return blinding_count;
|
||||||
|
}
|
||||||
|
|
||||||
|
// The blinding gates do not fit within our estimated degree; increase our estimate.
|
||||||
|
degree_estimate *= 2;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fn blind_and_pad(&mut self) {
|
fn blind_and_pad(&mut self) {
|
||||||
|
let blinding_count = self.blinding_count();
|
||||||
|
|
||||||
// TODO: Blind.
|
// TODO: Blind.
|
||||||
|
|
||||||
while !self.gate_instances.len().is_power_of_two() {
|
while !self.gate_instances.len().is_power_of_two() {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user