mirror of
https://github.com/logos-storage/plonky2.git
synced 2026-01-02 22:03:07 +00:00
Merge branch 'main' into exp_gate_config
This commit is contained in:
commit
95503ff7fa
@ -4,7 +4,6 @@ use std::hash::{Hash, Hasher};
|
||||
use std::iter::{Product, Sum};
|
||||
use std::ops::{Add, AddAssign, Div, DivAssign, Mul, MulAssign, Neg, Sub, SubAssign};
|
||||
|
||||
use itertools::Itertools;
|
||||
use num::bigint::BigUint;
|
||||
use num::Integer;
|
||||
use rand::Rng;
|
||||
|
||||
@ -3,7 +3,6 @@ use std::hash::Hash;
|
||||
use std::iter::{Product, Sum};
|
||||
use std::ops::{Add, AddAssign, Div, DivAssign, Mul, MulAssign, Neg, Sub, SubAssign};
|
||||
|
||||
use itertools::Itertools;
|
||||
use num::bigint::BigUint;
|
||||
use rand::Rng;
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
@ -3,7 +3,6 @@ use std::hash::Hash;
|
||||
use std::iter::{Product, Sum};
|
||||
use std::ops::{Add, AddAssign, Div, DivAssign, Mul, MulAssign, Neg, Sub, SubAssign};
|
||||
|
||||
use itertools::Itertools;
|
||||
use num::bigint::BigUint;
|
||||
use num::traits::Pow;
|
||||
use rand::Rng;
|
||||
|
||||
@ -151,7 +151,7 @@ macro_rules! test_field_arithmetic {
|
||||
($field:ty) => {
|
||||
mod field_arithmetic {
|
||||
use num::{bigint::BigUint, One, Zero};
|
||||
use rand::{thread_rng, Rng};
|
||||
use rand::Rng;
|
||||
|
||||
use crate::field::field::Field;
|
||||
|
||||
|
||||
@ -181,11 +181,7 @@ impl<F: Extendable<D>, const D: usize> CircuitBuilder<F, D> {
|
||||
let gate = ExponentiationGate::new(self.config.clone());
|
||||
let gate_index = self.add_gate(gate.clone(), vec![]);
|
||||
|
||||
let two = self.constant(F::TWO);
|
||||
let exponent = reduce_with_powers_recursive(self, &exp_bits_vec[..], two);
|
||||
|
||||
self.route(base, Target::wire(gate_index, gate.wire_base()));
|
||||
self.route(exponent, Target::wire(gate_index, gate.wire_power()));
|
||||
exp_bits_vec.iter().enumerate().for_each(|(i, bit)| {
|
||||
self.route(*bit, Target::wire(gate_index, gate.wire_power_bit(i)));
|
||||
});
|
||||
|
||||
@ -1,5 +1,3 @@
|
||||
use std::marker::PhantomData;
|
||||
|
||||
use crate::circuit_builder::CircuitBuilder;
|
||||
use crate::field::extension_field::target::ExtensionTarget;
|
||||
use crate::field::extension_field::Extendable;
|
||||
|
||||
@ -4,7 +4,7 @@ use crate::circuit_builder::CircuitBuilder;
|
||||
use crate::field::extension_field::target::ExtensionTarget;
|
||||
use crate::field::extension_field::Extendable;
|
||||
use crate::field::field::Field;
|
||||
use crate::gates::gate::{Gate, GateRef};
|
||||
use crate::gates::gate::Gate;
|
||||
use crate::generator::{GeneratedValues, SimpleGenerator, WitnessGenerator};
|
||||
use crate::plonk_common::{reduce_with_powers, reduce_with_powers_ext_recursive};
|
||||
use crate::target::Target;
|
||||
@ -186,7 +186,6 @@ impl<F: Field, const B: usize> SimpleGenerator<F> for BaseSplitGenerator<B> {
|
||||
mod tests {
|
||||
use crate::field::crandall_field::CrandallField;
|
||||
use crate::gates::base_sum::BaseSumGate;
|
||||
use crate::gates::gate::GateRef;
|
||||
use crate::gates::gate_testing::test_low_degree;
|
||||
|
||||
#[test]
|
||||
|
||||
@ -2,7 +2,7 @@ use crate::circuit_builder::CircuitBuilder;
|
||||
use crate::field::extension_field::target::ExtensionTarget;
|
||||
use crate::field::extension_field::Extendable;
|
||||
use crate::field::field::Field;
|
||||
use crate::gates::gate::{Gate, GateRef};
|
||||
use crate::gates::gate::Gate;
|
||||
use crate::generator::{GeneratedValues, SimpleGenerator, WitnessGenerator};
|
||||
use crate::target::Target;
|
||||
use crate::vars::{EvaluationTargets, EvaluationVars, EvaluationVarsBase};
|
||||
|
||||
@ -39,23 +39,19 @@ impl<F: Extendable<D>, const D: usize> ExponentiationGate<F, D> {
|
||||
0
|
||||
}
|
||||
|
||||
pub fn wire_power(&self) -> usize {
|
||||
1
|
||||
}
|
||||
|
||||
/// The `i`th bit of the exponent, in little-endian order.
|
||||
pub fn wire_power_bit(&self, i: usize) -> usize {
|
||||
debug_assert!(i < self.num_power_bits);
|
||||
2 + i
|
||||
1 + i
|
||||
}
|
||||
|
||||
pub fn wire_output(&self) -> usize {
|
||||
2 + self.num_power_bits
|
||||
1 + self.num_power_bits
|
||||
}
|
||||
|
||||
pub fn wire_intermediate_value(&self, i: usize) -> usize {
|
||||
debug_assert!(i < self.num_power_bits);
|
||||
3 + self.num_power_bits + i
|
||||
2 + self.num_power_bits + i
|
||||
}
|
||||
}
|
||||
|
||||
@ -66,7 +62,6 @@ impl<F: Extendable<D>, const D: usize> Gate<F, D> for ExponentiationGate<F, D> {
|
||||
|
||||
fn eval_unfiltered(&self, vars: EvaluationVars<F, D>) -> Vec<F::Extension> {
|
||||
let base = vars.local_wires[self.wire_base()];
|
||||
let power = vars.local_wires[self.wire_power()];
|
||||
|
||||
let power_bits: Vec<_> = (0..self.num_power_bits)
|
||||
.map(|i| vars.local_wires[self.wire_power_bit(i)])
|
||||
@ -79,9 +74,6 @@ impl<F: Extendable<D>, const D: usize> Gate<F, D> for ExponentiationGate<F, D> {
|
||||
|
||||
let mut constraints = Vec::new();
|
||||
|
||||
let computed_power = reduce_with_powers(&power_bits, F::Extension::TWO);
|
||||
constraints.push(power - computed_power);
|
||||
|
||||
for i in 0..self.num_power_bits {
|
||||
let prev_intermediate_value = if i == 0 {
|
||||
F::Extension::ONE
|
||||
@ -105,7 +97,6 @@ impl<F: Extendable<D>, const D: usize> Gate<F, D> for ExponentiationGate<F, D> {
|
||||
|
||||
fn eval_unfiltered_base(&self, vars: EvaluationVarsBase<F>) -> Vec<F> {
|
||||
let base = vars.local_wires[self.wire_base()];
|
||||
let power = vars.local_wires[self.wire_power()];
|
||||
|
||||
let power_bits: Vec<_> = (0..self.num_power_bits)
|
||||
.map(|i| vars.local_wires[self.wire_power_bit(i)])
|
||||
@ -118,9 +109,6 @@ impl<F: Extendable<D>, const D: usize> Gate<F, D> for ExponentiationGate<F, D> {
|
||||
|
||||
let mut constraints = Vec::new();
|
||||
|
||||
let computed_power = reduce_with_powers(&power_bits, F::TWO);
|
||||
constraints.push(power - computed_power);
|
||||
|
||||
for i in 0..self.num_power_bits {
|
||||
let prev_intermediate_value = if i == 0 {
|
||||
F::ONE
|
||||
@ -148,7 +136,6 @@ impl<F: Extendable<D>, const D: usize> Gate<F, D> for ExponentiationGate<F, D> {
|
||||
vars: EvaluationTargets<D>,
|
||||
) -> Vec<ExtensionTarget<D>> {
|
||||
let base = vars.local_wires[self.wire_base()];
|
||||
let power = vars.local_wires[self.wire_power()];
|
||||
|
||||
let power_bits: Vec<_> = (0..self.num_power_bits)
|
||||
.map(|i| vars.local_wires[self.wire_power_bit(i)])
|
||||
@ -161,11 +148,6 @@ impl<F: Extendable<D>, const D: usize> Gate<F, D> for ExponentiationGate<F, D> {
|
||||
|
||||
let mut constraints = Vec::new();
|
||||
|
||||
let two = builder.constant(F::TWO);
|
||||
let computed_power = reduce_with_powers_ext_recursive(builder, &power_bits, two);
|
||||
let power_diff = builder.sub_extension(power, computed_power);
|
||||
constraints.push(power_diff);
|
||||
|
||||
let one = builder.constant_extension(F::Extension::ONE);
|
||||
for i in 0..self.num_power_bits {
|
||||
let prev_intermediate_value = if i == 0 {
|
||||
@ -216,7 +198,7 @@ impl<F: Extendable<D>, const D: usize> Gate<F, D> for ExponentiationGate<F, D> {
|
||||
}
|
||||
|
||||
fn num_constraints(&self) -> usize {
|
||||
self.num_power_bits + 2
|
||||
self.num_power_bits + 1
|
||||
}
|
||||
}
|
||||
|
||||
@ -232,7 +214,6 @@ impl<F: Extendable<D>, const D: usize> SimpleGenerator<F> for ExponentiationGene
|
||||
|
||||
let mut deps = Vec::with_capacity(self.gate.num_power_bits + 2);
|
||||
deps.push(local_target(self.gate.wire_base()));
|
||||
deps.push(local_target(self.gate.wire_power()));
|
||||
for i in 0..self.gate.num_power_bits {
|
||||
deps.push(local_target(self.gate.wire_power_bit(i)));
|
||||
}
|
||||
@ -281,7 +262,7 @@ impl<F: Extendable<D>, const D: usize> SimpleGenerator<F> for ExponentiationGene
|
||||
mod tests {
|
||||
use std::marker::PhantomData;
|
||||
|
||||
use rand::{thread_rng, Rng};
|
||||
use rand::Rng;
|
||||
|
||||
use crate::circuit_data::CircuitConfig;
|
||||
use crate::field::crandall_field::CrandallField;
|
||||
@ -305,12 +286,11 @@ mod tests {
|
||||
};
|
||||
|
||||
assert_eq!(gate.wire_base(), 0);
|
||||
assert_eq!(gate.wire_power(), 1);
|
||||
assert_eq!(gate.wire_power_bit(0), 2);
|
||||
assert_eq!(gate.wire_power_bit(4), 6);
|
||||
assert_eq!(gate.wire_output(), 7);
|
||||
assert_eq!(gate.wire_intermediate_value(0), 8);
|
||||
assert_eq!(gate.wire_intermediate_value(4), 12);
|
||||
assert_eq!(gate.wire_power_bit(0), 1);
|
||||
assert_eq!(gate.wire_power_bit(4), 5);
|
||||
assert_eq!(gate.wire_output(), 6);
|
||||
assert_eq!(gate.wire_intermediate_value(0), 7);
|
||||
assert_eq!(gate.wire_intermediate_value(4), 11);
|
||||
}
|
||||
|
||||
#[test]
|
||||
@ -350,7 +330,6 @@ mod tests {
|
||||
|
||||
let num_power_bits = power_bits.len();
|
||||
|
||||
let power_F = F::from_canonical_u64(power);
|
||||
let power_bits_F: Vec<_> = power_bits
|
||||
.iter()
|
||||
.map(|b| F::from_canonical_u64(*b))
|
||||
@ -358,7 +337,6 @@ mod tests {
|
||||
|
||||
let mut v = Vec::new();
|
||||
v.push(base);
|
||||
v.push(power_F);
|
||||
v.extend(power_bits_F.clone());
|
||||
|
||||
let mut intermediate_values = Vec::new();
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
use crate::field::extension_field::Extendable;
|
||||
use crate::field::field::Field;
|
||||
use crate::gates::gate::{Gate, GateRef};
|
||||
use crate::gates::gate::Gate;
|
||||
use crate::polynomial::polynomial::{PolynomialCoeffs, PolynomialValues};
|
||||
use crate::proof::Hash;
|
||||
use crate::util::{log2_ceil, transpose};
|
||||
|
||||
@ -334,7 +334,7 @@ mod tests {
|
||||
use crate::field::crandall_field::CrandallField;
|
||||
use crate::field::extension_field::quartic::QuarticCrandallField;
|
||||
use crate::field::field::Field;
|
||||
use crate::gates::gate::{Gate, GateRef};
|
||||
use crate::gates::gate::Gate;
|
||||
use crate::gates::gate_testing::test_low_degree;
|
||||
use crate::gates::gmimc::{GMiMCGate, W};
|
||||
use crate::generator::generate_partial_witness;
|
||||
|
||||
@ -8,7 +8,7 @@ use crate::field::extension_field::target::ExtensionTarget;
|
||||
use crate::field::extension_field::{Extendable, FieldExtension};
|
||||
use crate::field::interpolation::interpolant;
|
||||
use crate::gadgets::polynomial::PolynomialCoeffsExtAlgebraTarget;
|
||||
use crate::gates::gate::{Gate, GateRef};
|
||||
use crate::gates::gate::Gate;
|
||||
use crate::generator::{GeneratedValues, SimpleGenerator, WitnessGenerator};
|
||||
use crate::polynomial::polynomial::PolynomialCoeffs;
|
||||
use crate::target::Target;
|
||||
@ -288,7 +288,6 @@ mod tests {
|
||||
|
||||
use crate::field::crandall_field::CrandallField;
|
||||
use crate::field::extension_field::quartic::QuarticCrandallField;
|
||||
use crate::field::extension_field::FieldExtension;
|
||||
use crate::field::field::Field;
|
||||
use crate::gates::gate::Gate;
|
||||
use crate::gates::gate_testing::test_low_degree;
|
||||
@ -319,7 +318,6 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn low_degree() {
|
||||
type F = CrandallField;
|
||||
test_low_degree::<CrandallField, _, 4>(InterpolationGate::new(4));
|
||||
}
|
||||
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
use crate::circuit_builder::CircuitBuilder;
|
||||
use crate::field::extension_field::target::ExtensionTarget;
|
||||
use crate::field::extension_field::Extendable;
|
||||
use crate::gates::gate::{Gate, GateRef};
|
||||
use crate::gates::gate::Gate;
|
||||
use crate::generator::WitnessGenerator;
|
||||
use crate::vars::{EvaluationTargets, EvaluationVars, EvaluationVarsBase};
|
||||
|
||||
|
||||
@ -3,7 +3,7 @@ use std::ops::Range;
|
||||
use crate::circuit_builder::CircuitBuilder;
|
||||
use crate::field::extension_field::target::ExtensionTarget;
|
||||
use crate::field::extension_field::Extendable;
|
||||
use crate::gates::gate::{Gate, GateRef};
|
||||
use crate::gates::gate::Gate;
|
||||
use crate::generator::WitnessGenerator;
|
||||
use crate::vars::{EvaluationTargets, EvaluationVars, EvaluationVarsBase};
|
||||
|
||||
|
||||
@ -219,7 +219,6 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn low_degree() {
|
||||
type F = CrandallField;
|
||||
test_low_degree::<CrandallField, _, 4>(ReducingGate::new(22));
|
||||
}
|
||||
}
|
||||
|
||||
@ -129,7 +129,7 @@ pub(crate) fn prove<F: Extendable<D>, const D: usize>(
|
||||
&gammas,
|
||||
&alphas,
|
||||
),
|
||||
"to compute vanishing polys"
|
||||
"to compute quotient polys"
|
||||
);
|
||||
|
||||
// Compute the quotient polynomials, aka `t` in the Plonk paper.
|
||||
@ -146,7 +146,7 @@ pub(crate) fn prove<F: Extendable<D>, const D: usize>(
|
||||
quotient_poly.chunks(degree)
|
||||
})
|
||||
.collect(),
|
||||
"to compute quotient polys"
|
||||
"to split up quotient polys"
|
||||
);
|
||||
|
||||
let quotient_polys_commitment = timed!(
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user