mirror of
https://github.com/logos-storage/plonky2.git
synced 2026-01-07 16:23:12 +00:00
Remove RichField
This commit is contained in:
parent
3d74abba8a
commit
7482e7b613
@ -16,14 +16,11 @@ impl<const D: usize> ExtensionTarget<D> {
|
|||||||
self.0
|
self.0
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn frobenius<F: RichField + Extendable<D>>(
|
pub fn frobenius<F: Extendable<D>>(&self, builder: &mut CircuitBuilder<F, D>) -> Self {
|
||||||
&self,
|
|
||||||
builder: &mut CircuitBuilder<F, D>,
|
|
||||||
) -> Self {
|
|
||||||
self.repeated_frobenius(1, builder)
|
self.repeated_frobenius(1, builder)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn repeated_frobenius<F: RichField + Extendable<D>>(
|
pub fn repeated_frobenius<F: Extendable<D>>(
|
||||||
&self,
|
&self,
|
||||||
count: usize,
|
count: usize,
|
||||||
builder: &mut CircuitBuilder<F, D>,
|
builder: &mut CircuitBuilder<F, D>,
|
||||||
@ -74,7 +71,7 @@ impl<const D: usize> ExtensionAlgebraTarget<D> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<F: RichField + Extendable<D>, const D: usize> CircuitBuilder<F, D> {
|
impl<F: Extendable<D>, const D: usize> CircuitBuilder<F, D> {
|
||||||
pub fn constant_extension(&mut self, c: F::Extension) -> ExtensionTarget<D> {
|
pub fn constant_extension(&mut self, c: F::Extension) -> ExtensionTarget<D> {
|
||||||
let c_parts = c.to_basefield_array();
|
let c_parts = c.to_basefield_array();
|
||||||
let mut parts = [self.zero(); D];
|
let mut parts = [self.zero(); D];
|
||||||
|
|||||||
@ -18,7 +18,7 @@ use crate::util::reducing::ReducingFactorTarget;
|
|||||||
use crate::util::{log2_strict, reverse_index_bits_in_place};
|
use crate::util::{log2_strict, reverse_index_bits_in_place};
|
||||||
use crate::with_context;
|
use crate::with_context;
|
||||||
|
|
||||||
impl<F: RichField + Extendable<D>, const D: usize> CircuitBuilder<F, D> {
|
impl<F: Extendable<D>, const D: usize> CircuitBuilder<F, D> {
|
||||||
/// Computes P'(x^arity) from {P(x*g^i)}_(i=0..arity), where g is a `arity`-th root of unity
|
/// Computes P'(x^arity) from {P(x*g^i)}_(i=0..arity), where g is a `arity`-th root of unity
|
||||||
/// and P' is the FRI reduced polynomial.
|
/// and P' is the FRI reduced polynomial.
|
||||||
fn compute_evaluation(
|
fn compute_evaluation(
|
||||||
|
|||||||
@ -6,7 +6,7 @@ use crate::gates::exponentiation::ExponentiationGate;
|
|||||||
use crate::iop::target::{BoolTarget, Target};
|
use crate::iop::target::{BoolTarget, Target};
|
||||||
use crate::plonk::circuit_builder::CircuitBuilder;
|
use crate::plonk::circuit_builder::CircuitBuilder;
|
||||||
|
|
||||||
impl<F: RichField + Extendable<D>, const D: usize> CircuitBuilder<F, D> {
|
impl<F: Extendable<D>, const D: usize> CircuitBuilder<F, D> {
|
||||||
/// Computes `-x`.
|
/// Computes `-x`.
|
||||||
pub fn neg(&mut self, x: Target) -> Target {
|
pub fn neg(&mut self, x: Target) -> Target {
|
||||||
let neg_one = self.neg_one();
|
let neg_one = self.neg_one();
|
||||||
|
|||||||
@ -11,7 +11,7 @@ use crate::iop::witness::{PartitionWitness, Witness};
|
|||||||
use crate::plonk::circuit_builder::CircuitBuilder;
|
use crate::plonk::circuit_builder::CircuitBuilder;
|
||||||
use crate::util::bits_u64;
|
use crate::util::bits_u64;
|
||||||
|
|
||||||
impl<F: RichField + Extendable<D>, const D: usize> CircuitBuilder<F, D> {
|
impl<F: Extendable<D>, const D: usize> CircuitBuilder<F, D> {
|
||||||
/// Finds the last available arithmetic gate with the given constants or add one if there aren't any.
|
/// Finds the last available arithmetic gate with the given constants or add one if there aren't any.
|
||||||
/// Returns `(g,i)` such that there is an arithmetic gate with the given constants at index
|
/// Returns `(g,i)` such that there is an arithmetic gate with the given constants at index
|
||||||
/// `g` and the gate's `i`-th operation is available.
|
/// `g` and the gate's `i`-th operation is available.
|
||||||
@ -490,9 +490,7 @@ struct QuotientGeneratorExtension<const D: usize> {
|
|||||||
quotient: ExtensionTarget<D>,
|
quotient: ExtensionTarget<D>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<F: RichField + Extendable<D>, const D: usize> SimpleGenerator<F>
|
impl<F: Extendable<D>, const D: usize> SimpleGenerator<F> for QuotientGeneratorExtension<D> {
|
||||||
for QuotientGeneratorExtension<D>
|
|
||||||
{
|
|
||||||
fn dependencies(&self) -> Vec<Target> {
|
fn dependencies(&self) -> Vec<Target> {
|
||||||
let mut deps = self.numerator.to_target_array().to_vec();
|
let mut deps = self.numerator.to_target_array().to_vec();
|
||||||
deps.extend(&self.denominator.to_target_array());
|
deps.extend(&self.denominator.to_target_array());
|
||||||
@ -515,7 +513,7 @@ pub struct PowersTarget<const D: usize> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl<const D: usize> PowersTarget<D> {
|
impl<const D: usize> PowersTarget<D> {
|
||||||
pub fn next<F: RichField + Extendable<D>>(
|
pub fn next<F: Extendable<D>>(
|
||||||
&mut self,
|
&mut self,
|
||||||
builder: &mut CircuitBuilder<F, D>,
|
builder: &mut CircuitBuilder<F, D>,
|
||||||
) -> ExtensionTarget<D> {
|
) -> ExtensionTarget<D> {
|
||||||
@ -524,7 +522,7 @@ impl<const D: usize> PowersTarget<D> {
|
|||||||
result
|
result
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn repeated_frobenius<F: RichField + Extendable<D>>(
|
pub fn repeated_frobenius<F: Extendable<D>>(
|
||||||
self,
|
self,
|
||||||
k: usize,
|
k: usize,
|
||||||
builder: &mut CircuitBuilder<F, D>,
|
builder: &mut CircuitBuilder<F, D>,
|
||||||
@ -537,7 +535,7 @@ impl<const D: usize> PowersTarget<D> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<F: RichField + Extendable<D>, const D: usize> CircuitBuilder<F, D> {
|
impl<F: Extendable<D>, const D: usize> CircuitBuilder<F, D> {
|
||||||
pub fn powers(&mut self, base: ExtensionTarget<D>) -> PowersTarget<D> {
|
pub fn powers(&mut self, base: ExtensionTarget<D>) -> PowersTarget<D> {
|
||||||
PowersTarget {
|
PowersTarget {
|
||||||
base,
|
base,
|
||||||
|
|||||||
@ -5,7 +5,7 @@ use crate::gates::interpolation::InterpolationGate;
|
|||||||
use crate::iop::target::Target;
|
use crate::iop::target::Target;
|
||||||
use crate::plonk::circuit_builder::CircuitBuilder;
|
use crate::plonk::circuit_builder::CircuitBuilder;
|
||||||
|
|
||||||
impl<F: RichField + Extendable<D>, const D: usize> CircuitBuilder<F, D> {
|
impl<F: Extendable<D>, const D: usize> CircuitBuilder<F, D> {
|
||||||
/// Interpolate a list of point/evaluation pairs at a given point.
|
/// Interpolate a list of point/evaluation pairs at a given point.
|
||||||
/// Returns the evaluation of the interpolated polynomial at `evaluation_point`.
|
/// Returns the evaluation of the interpolated polynomial at `evaluation_point`.
|
||||||
pub fn interpolate(
|
pub fn interpolate(
|
||||||
|
|||||||
@ -10,7 +10,7 @@ use crate::iop::witness::{PartitionWitness, Witness};
|
|||||||
use crate::plonk::circuit_builder::CircuitBuilder;
|
use crate::plonk::circuit_builder::CircuitBuilder;
|
||||||
use crate::util::bimap::bimap_from_lists;
|
use crate::util::bimap::bimap_from_lists;
|
||||||
|
|
||||||
impl<F: RichField + Extendable<D>, const D: usize> CircuitBuilder<F, D> {
|
impl<F: Extendable<D>, const D: usize> CircuitBuilder<F, D> {
|
||||||
/// Assert that two lists of expressions evaluate to permutations of one another.
|
/// Assert that two lists of expressions evaluate to permutations of one another.
|
||||||
pub fn assert_permutation(&mut self, a: Vec<Vec<Target>>, b: Vec<Vec<Target>>) {
|
pub fn assert_permutation(&mut self, a: Vec<Vec<Target>>, b: Vec<Vec<Target>>) {
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
|
|||||||
@ -12,7 +12,7 @@ impl<const D: usize> PolynomialCoeffsExtTarget<D> {
|
|||||||
self.0.len()
|
self.0.len()
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn eval_scalar<F: RichField + Extendable<D>>(
|
pub fn eval_scalar<F: Extendable<D>>(
|
||||||
&self,
|
&self,
|
||||||
builder: &mut CircuitBuilder<F, D>,
|
builder: &mut CircuitBuilder<F, D>,
|
||||||
point: Target,
|
point: Target,
|
||||||
@ -22,7 +22,7 @@ impl<const D: usize> PolynomialCoeffsExtTarget<D> {
|
|||||||
point.reduce(&self.0, builder)
|
point.reduce(&self.0, builder)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn eval<F: RichField + Extendable<D>>(
|
pub fn eval<F: Extendable<D>>(
|
||||||
&self,
|
&self,
|
||||||
builder: &mut CircuitBuilder<F, D>,
|
builder: &mut CircuitBuilder<F, D>,
|
||||||
point: ExtensionTarget<D>,
|
point: ExtensionTarget<D>,
|
||||||
@ -41,7 +41,7 @@ impl<const D: usize> PolynomialCoeffsExtAlgebraTarget<D> {
|
|||||||
point: ExtensionTarget<D>,
|
point: ExtensionTarget<D>,
|
||||||
) -> ExtensionAlgebraTarget<D>
|
) -> ExtensionAlgebraTarget<D>
|
||||||
where
|
where
|
||||||
F: RichField + Extendable<D>,
|
F: Extendable<D>,
|
||||||
{
|
{
|
||||||
let mut acc = builder.zero_ext_algebra();
|
let mut acc = builder.zero_ext_algebra();
|
||||||
for &c in self.0.iter().rev() {
|
for &c in self.0.iter().rev() {
|
||||||
@ -56,7 +56,7 @@ impl<const D: usize> PolynomialCoeffsExtAlgebraTarget<D> {
|
|||||||
point: ExtensionAlgebraTarget<D>,
|
point: ExtensionAlgebraTarget<D>,
|
||||||
) -> ExtensionAlgebraTarget<D>
|
) -> ExtensionAlgebraTarget<D>
|
||||||
where
|
where
|
||||||
F: RichField + Extendable<D>,
|
F: Extendable<D>,
|
||||||
{
|
{
|
||||||
let mut acc = builder.zero_ext_algebra();
|
let mut acc = builder.zero_ext_algebra();
|
||||||
for &c in self.0.iter().rev() {
|
for &c in self.0.iter().rev() {
|
||||||
|
|||||||
@ -5,7 +5,7 @@ use crate::gates::random_access::RandomAccessGate;
|
|||||||
use crate::iop::target::Target;
|
use crate::iop::target::Target;
|
||||||
use crate::plonk::circuit_builder::CircuitBuilder;
|
use crate::plonk::circuit_builder::CircuitBuilder;
|
||||||
|
|
||||||
impl<F: RichField + Extendable<D>, const D: usize> CircuitBuilder<F, D> {
|
impl<F: Extendable<D>, const D: usize> CircuitBuilder<F, D> {
|
||||||
/// Finds the last available random access gate with the given `vec_size` or add one if there aren't any.
|
/// Finds the last available random access gate with the given `vec_size` or add one if there aren't any.
|
||||||
/// Returns `(g,i)` such that there is a random access gate with the given `vec_size` at index
|
/// Returns `(g,i)` such that there is a random access gate with the given `vec_size` at index
|
||||||
/// `g` and the gate's `i`-th random access is available.
|
/// `g` and the gate's `i`-th random access is available.
|
||||||
|
|||||||
@ -5,7 +5,7 @@ use crate::iop::target::{BoolTarget, Target};
|
|||||||
use crate::iop::witness::{PartitionWitness, Witness};
|
use crate::iop::witness::{PartitionWitness, Witness};
|
||||||
use crate::plonk::circuit_builder::CircuitBuilder;
|
use crate::plonk::circuit_builder::CircuitBuilder;
|
||||||
|
|
||||||
impl<F: RichField + Extendable<D>, const D: usize> CircuitBuilder<F, D> {
|
impl<F: Extendable<D>, const D: usize> CircuitBuilder<F, D> {
|
||||||
/// Checks that `x < 2^n_log` using a `BaseSumGate`.
|
/// Checks that `x < 2^n_log` using a `BaseSumGate`.
|
||||||
pub fn range_check(&mut self, x: Target, n_log: usize) {
|
pub fn range_check(&mut self, x: Target, n_log: usize) {
|
||||||
self.split_le(x, n_log);
|
self.split_le(x, n_log);
|
||||||
|
|||||||
@ -4,7 +4,7 @@ use crate::field::field_types::RichField;
|
|||||||
use crate::iop::target::{BoolTarget, Target};
|
use crate::iop::target::{BoolTarget, Target};
|
||||||
use crate::plonk::circuit_builder::CircuitBuilder;
|
use crate::plonk::circuit_builder::CircuitBuilder;
|
||||||
|
|
||||||
impl<F: RichField + Extendable<D>, const D: usize> CircuitBuilder<F, D> {
|
impl<F: Extendable<D>, const D: usize> CircuitBuilder<F, D> {
|
||||||
/// Selects `x` or `y` based on `b`, i.e., this returns `if b { x } else { y }`.
|
/// Selects `x` or `y` based on `b`, i.e., this returns `if b { x } else { y }`.
|
||||||
pub fn select_ext(
|
pub fn select_ext(
|
||||||
&mut self,
|
&mut self,
|
||||||
|
|||||||
@ -26,7 +26,7 @@ pub struct MemoryOpTarget {
|
|||||||
value: Target,
|
value: Target,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<F: RichField + Extendable<D>, const D: usize> CircuitBuilder<F, D> {
|
impl<F: Extendable<D>, const D: usize> CircuitBuilder<F, D> {
|
||||||
pub fn assert_permutation_memory_ops(&mut self, a: &[MemoryOpTarget], b: &[MemoryOpTarget]) {
|
pub fn assert_permutation_memory_ops(&mut self, a: &[MemoryOpTarget], b: &[MemoryOpTarget]) {
|
||||||
let a_chunks: Vec<Vec<Target>> = a
|
let a_chunks: Vec<Vec<Target>> = a
|
||||||
.iter()
|
.iter()
|
||||||
@ -116,15 +116,13 @@ impl<F: RichField + Extendable<D>, const D: usize> CircuitBuilder<F, D> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
struct MemoryOpSortGenerator<F: RichField + Extendable<D>, const D: usize> {
|
struct MemoryOpSortGenerator<F: Extendable<D>, const D: usize> {
|
||||||
input_ops: Vec<MemoryOpTarget>,
|
input_ops: Vec<MemoryOpTarget>,
|
||||||
output_ops: Vec<MemoryOpTarget>,
|
output_ops: Vec<MemoryOpTarget>,
|
||||||
_phantom: PhantomData<F>,
|
_phantom: PhantomData<F>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<F: RichField + Extendable<D>, const D: usize> SimpleGenerator<F>
|
impl<F: Extendable<D>, const D: usize> SimpleGenerator<F> for MemoryOpSortGenerator<F, D> {
|
||||||
for MemoryOpSortGenerator<F, D>
|
|
||||||
{
|
|
||||||
fn dependencies(&self) -> Vec<Target> {
|
fn dependencies(&self) -> Vec<Target> {
|
||||||
self.input_ops
|
self.input_ops
|
||||||
.iter()
|
.iter()
|
||||||
|
|||||||
@ -8,7 +8,7 @@ use crate::iop::target::{BoolTarget, Target};
|
|||||||
use crate::iop::witness::{PartitionWitness, Witness};
|
use crate::iop::witness::{PartitionWitness, Witness};
|
||||||
use crate::plonk::circuit_builder::CircuitBuilder;
|
use crate::plonk::circuit_builder::CircuitBuilder;
|
||||||
|
|
||||||
impl<F: RichField + Extendable<D>, const D: usize> CircuitBuilder<F, D> {
|
impl<F: Extendable<D>, const D: usize> CircuitBuilder<F, D> {
|
||||||
/// Split the given element into a list of targets, where each one represents a
|
/// Split the given element into a list of targets, where each one represents a
|
||||||
/// base-B limb of the element, with little-endian ordering.
|
/// base-B limb of the element, with little-endian ordering.
|
||||||
pub fn split_le_base<const B: usize>(&mut self, x: Target, num_limbs: usize) -> Vec<Target> {
|
pub fn split_le_base<const B: usize>(&mut self, x: Target, num_limbs: usize) -> Vec<Target> {
|
||||||
|
|||||||
@ -46,7 +46,7 @@ impl<const D: usize> ArithmeticExtensionGate<D> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<F: RichField + Extendable<D>, const D: usize> Gate<F, D> for ArithmeticExtensionGate<D> {
|
impl<F: Extendable<D>, const D: usize> Gate<F, D> for ArithmeticExtensionGate<D> {
|
||||||
fn id(&self) -> String {
|
fn id(&self) -> String {
|
||||||
format!("{:?}", self)
|
format!("{:?}", self)
|
||||||
}
|
}
|
||||||
@ -155,16 +155,14 @@ impl<F: RichField + Extendable<D>, const D: usize> Gate<F, D> for ArithmeticExte
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone, Debug)]
|
#[derive(Clone, Debug)]
|
||||||
struct ArithmeticExtensionGenerator<F: RichField + Extendable<D>, const D: usize> {
|
struct ArithmeticExtensionGenerator<F: Extendable<D>, const D: usize> {
|
||||||
gate_index: usize,
|
gate_index: usize,
|
||||||
const_0: F,
|
const_0: F,
|
||||||
const_1: F,
|
const_1: F,
|
||||||
i: usize,
|
i: usize,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<F: RichField + Extendable<D>, const D: usize> SimpleGenerator<F>
|
impl<F: Extendable<D>, const D: usize> SimpleGenerator<F> for ArithmeticExtensionGenerator<F, D> {
|
||||||
for ArithmeticExtensionGenerator<F, D>
|
|
||||||
{
|
|
||||||
fn dependencies(&self) -> Vec<Target> {
|
fn dependencies(&self) -> Vec<Target> {
|
||||||
ArithmeticExtensionGate::<D>::wires_ith_multiplicand_0(self.i)
|
ArithmeticExtensionGate::<D>::wires_ith_multiplicand_0(self.i)
|
||||||
.chain(ArithmeticExtensionGate::<D>::wires_ith_multiplicand_1(
|
.chain(ArithmeticExtensionGate::<D>::wires_ith_multiplicand_1(
|
||||||
|
|||||||
@ -18,11 +18,11 @@ pub const NUM_U32_ARITHMETIC_OPS: usize = 3;
|
|||||||
|
|
||||||
/// A gate to perform a basic mul-add on 32-bit values (we assume they are range-checked beforehand).
|
/// A gate to perform a basic mul-add on 32-bit values (we assume they are range-checked beforehand).
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub struct U32ArithmeticGate<F: RichField + Extendable<D>, const D: usize> {
|
pub struct U32ArithmeticGate<F: Extendable<D>, const D: usize> {
|
||||||
_phantom: PhantomData<F>,
|
_phantom: PhantomData<F>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<F: RichField + Extendable<D>, const D: usize> U32ArithmeticGate<F, D> {
|
impl<F: Extendable<D>, const D: usize> U32ArithmeticGate<F, D> {
|
||||||
pub fn wire_ith_multiplicand_0(i: usize) -> usize {
|
pub fn wire_ith_multiplicand_0(i: usize) -> usize {
|
||||||
debug_assert!(i < NUM_U32_ARITHMETIC_OPS);
|
debug_assert!(i < NUM_U32_ARITHMETIC_OPS);
|
||||||
5 * i
|
5 * i
|
||||||
@ -59,7 +59,7 @@ impl<F: RichField + Extendable<D>, const D: usize> U32ArithmeticGate<F, D> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<F: RichField + Extendable<D>, const D: usize> Gate<F, D> for U32ArithmeticGate<F, D> {
|
impl<F: Extendable<D>, const D: usize> Gate<F, D> for U32ArithmeticGate<F, D> {
|
||||||
fn id(&self) -> String {
|
fn id(&self) -> String {
|
||||||
format!("{:?}", self)
|
format!("{:?}", self)
|
||||||
}
|
}
|
||||||
@ -243,15 +243,13 @@ impl<F: RichField + Extendable<D>, const D: usize> Gate<F, D> for U32ArithmeticG
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone, Debug)]
|
#[derive(Clone, Debug)]
|
||||||
struct U32ArithmeticGenerator<F: RichField + Extendable<D>, const D: usize> {
|
struct U32ArithmeticGenerator<F: Extendable<D>, const D: usize> {
|
||||||
gate_index: usize,
|
gate_index: usize,
|
||||||
i: usize,
|
i: usize,
|
||||||
_phantom: PhantomData<F>,
|
_phantom: PhantomData<F>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<F: RichField + Extendable<D>, const D: usize> SimpleGenerator<F>
|
impl<F: Extendable<D>, const D: usize> SimpleGenerator<F> for U32ArithmeticGenerator<F, D> {
|
||||||
for U32ArithmeticGenerator<F, D>
|
|
||||||
{
|
|
||||||
fn dependencies(&self) -> Vec<Target> {
|
fn dependencies(&self) -> Vec<Target> {
|
||||||
let local_target = |input| Target::wire(self.gate_index, input);
|
let local_target = |input| Target::wire(self.gate_index, input);
|
||||||
|
|
||||||
|
|||||||
@ -38,7 +38,7 @@ impl<const B: usize> BaseSumGate<B> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<F: RichField + Extendable<D>, const D: usize, const B: usize> Gate<F, D> for BaseSumGate<B> {
|
impl<F: Extendable<D>, const D: usize, const B: usize> Gate<F, D> for BaseSumGate<B> {
|
||||||
fn id(&self) -> String {
|
fn id(&self) -> String {
|
||||||
format!("{:?} + Base: {}", self, B)
|
format!("{:?} + Base: {}", self, B)
|
||||||
}
|
}
|
||||||
|
|||||||
@ -21,7 +21,7 @@ pub struct ComparisonGate<F: PrimeField + Extendable<D>, const D: usize> {
|
|||||||
_phantom: PhantomData<F>,
|
_phantom: PhantomData<F>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<F: RichField + Extendable<D>, const D: usize> ComparisonGate<F, D> {
|
impl<F: Extendable<D>, const D: usize> ComparisonGate<F, D> {
|
||||||
pub fn new(num_bits: usize, num_chunks: usize) -> Self {
|
pub fn new(num_bits: usize, num_chunks: usize) -> Self {
|
||||||
debug_assert!(num_bits < bits_u64(F::ORDER));
|
debug_assert!(num_bits < bits_u64(F::ORDER));
|
||||||
Self {
|
Self {
|
||||||
@ -73,7 +73,7 @@ impl<F: RichField + Extendable<D>, const D: usize> ComparisonGate<F, D> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<F: RichField + Extendable<D>, const D: usize> Gate<F, D> for ComparisonGate<F, D> {
|
impl<F: Extendable<D>, const D: usize> Gate<F, D> for ComparisonGate<F, D> {
|
||||||
fn id(&self) -> String {
|
fn id(&self) -> String {
|
||||||
format!("{:?}<D={}>", self, D)
|
format!("{:?}<D={}>", self, D)
|
||||||
}
|
}
|
||||||
@ -327,14 +327,12 @@ impl<F: RichField + Extendable<D>, const D: usize> Gate<F, D> for ComparisonGate
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
struct ComparisonGenerator<F: RichField + Extendable<D>, const D: usize> {
|
struct ComparisonGenerator<F: Extendable<D>, const D: usize> {
|
||||||
gate_index: usize,
|
gate_index: usize,
|
||||||
gate: ComparisonGate<F, D>,
|
gate: ComparisonGate<F, D>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<F: RichField + Extendable<D>, const D: usize> SimpleGenerator<F>
|
impl<F: Extendable<D>, const D: usize> SimpleGenerator<F> for ComparisonGenerator<F, D> {
|
||||||
for ComparisonGenerator<F, D>
|
|
||||||
{
|
|
||||||
fn dependencies(&self) -> Vec<Target> {
|
fn dependencies(&self) -> Vec<Target> {
|
||||||
let local_target = |input| Target::wire(self.gate_index, input);
|
let local_target = |input| Target::wire(self.gate_index, input);
|
||||||
|
|
||||||
|
|||||||
@ -27,7 +27,7 @@ impl ConstantGate {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<F: RichField + Extendable<D>, const D: usize> Gate<F, D> for ConstantGate {
|
impl<F: Extendable<D>, const D: usize> Gate<F, D> for ConstantGate {
|
||||||
fn id(&self) -> String {
|
fn id(&self) -> String {
|
||||||
format!("{:?}", self)
|
format!("{:?}", self)
|
||||||
}
|
}
|
||||||
|
|||||||
@ -14,12 +14,12 @@ use crate::plonk::vars::{EvaluationTargets, EvaluationVars, EvaluationVarsBase};
|
|||||||
|
|
||||||
/// A gate for raising a value to a power.
|
/// A gate for raising a value to a power.
|
||||||
#[derive(Clone, Debug)]
|
#[derive(Clone, Debug)]
|
||||||
pub(crate) struct ExponentiationGate<F: RichField + Extendable<D>, const D: usize> {
|
pub(crate) struct ExponentiationGate<F: Extendable<D>, const D: usize> {
|
||||||
pub num_power_bits: usize,
|
pub num_power_bits: usize,
|
||||||
pub _phantom: PhantomData<F>,
|
pub _phantom: PhantomData<F>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<F: RichField + Extendable<D>, const D: usize> ExponentiationGate<F, D> {
|
impl<F: Extendable<D>, const D: usize> ExponentiationGate<F, D> {
|
||||||
pub fn new(num_power_bits: usize) -> Self {
|
pub fn new(num_power_bits: usize) -> Self {
|
||||||
Self {
|
Self {
|
||||||
num_power_bits,
|
num_power_bits,
|
||||||
@ -59,7 +59,7 @@ impl<F: RichField + Extendable<D>, const D: usize> ExponentiationGate<F, D> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<F: RichField + Extendable<D>, const D: usize> Gate<F, D> for ExponentiationGate<F, D> {
|
impl<F: Extendable<D>, const D: usize> Gate<F, D> for ExponentiationGate<F, D> {
|
||||||
fn id(&self) -> String {
|
fn id(&self) -> String {
|
||||||
format!("{:?}<D={}>", self, D)
|
format!("{:?}<D={}>", self, D)
|
||||||
}
|
}
|
||||||
@ -205,14 +205,12 @@ impl<F: RichField + Extendable<D>, const D: usize> Gate<F, D> for Exponentiation
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
struct ExponentiationGenerator<F: RichField + Extendable<D>, const D: usize> {
|
struct ExponentiationGenerator<F: Extendable<D>, const D: usize> {
|
||||||
gate_index: usize,
|
gate_index: usize,
|
||||||
gate: ExponentiationGate<F, D>,
|
gate: ExponentiationGate<F, D>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<F: RichField + Extendable<D>, const D: usize> SimpleGenerator<F>
|
impl<F: Extendable<D>, const D: usize> SimpleGenerator<F> for ExponentiationGenerator<F, D> {
|
||||||
for ExponentiationGenerator<F, D>
|
|
||||||
{
|
|
||||||
fn dependencies(&self) -> Vec<Target> {
|
fn dependencies(&self) -> Vec<Target> {
|
||||||
let local_target = |input| Target::wire(self.gate_index, input);
|
let local_target = |input| Target::wire(self.gate_index, input);
|
||||||
|
|
||||||
|
|||||||
@ -11,7 +11,7 @@ use crate::plonk::circuit_builder::CircuitBuilder;
|
|||||||
use crate::plonk::vars::{EvaluationTargets, EvaluationVars, EvaluationVarsBase};
|
use crate::plonk::vars::{EvaluationTargets, EvaluationVars, EvaluationVarsBase};
|
||||||
|
|
||||||
/// A custom gate.
|
/// A custom gate.
|
||||||
pub trait Gate<F: RichField + Extendable<D>, const D: usize>: 'static + Send + Sync {
|
pub trait Gate<F: Extendable<D>, const D: usize>: 'static + Send + Sync {
|
||||||
fn id(&self) -> String;
|
fn id(&self) -> String;
|
||||||
|
|
||||||
fn eval_unfiltered(&self, vars: EvaluationVars<F, D>) -> Vec<F::Extension>;
|
fn eval_unfiltered(&self, vars: EvaluationVars<F, D>) -> Vec<F::Extension>;
|
||||||
@ -120,9 +120,9 @@ pub trait Gate<F: RichField + Extendable<D>, const D: usize>: 'static + Send + S
|
|||||||
|
|
||||||
/// A wrapper around an `Rc<Gate>` which implements `PartialEq`, `Eq` and `Hash` based on gate IDs.
|
/// A wrapper around an `Rc<Gate>` which implements `PartialEq`, `Eq` and `Hash` based on gate IDs.
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
pub struct GateRef<F: RichField + Extendable<D>, const D: usize>(pub(crate) Arc<dyn Gate<F, D>>);
|
pub struct GateRef<F: Extendable<D>, const D: usize>(pub(crate) Arc<dyn Gate<F, D>>);
|
||||||
|
|
||||||
impl<F: RichField + Extendable<D>, const D: usize> GateRef<F, D> {
|
impl<F: Extendable<D>, const D: usize> GateRef<F, D> {
|
||||||
pub fn new<G: Gate<F, D>>(gate: G) -> GateRef<F, D> {
|
pub fn new<G: Gate<F, D>>(gate: G) -> GateRef<F, D> {
|
||||||
GateRef(Arc::new(gate))
|
GateRef(Arc::new(gate))
|
||||||
}
|
}
|
||||||
|
|||||||
@ -19,17 +19,11 @@ use crate::plonk::vars::{EvaluationTargets, EvaluationVars, EvaluationVarsBase};
|
|||||||
/// It has a flag which can be used to swap the first four inputs with the next four, for ordering
|
/// It has a flag which can be used to swap the first four inputs with the next four, for ordering
|
||||||
/// sibling digests.
|
/// sibling digests.
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub struct GMiMCGate<
|
pub struct GMiMCGate<F: Extendable<D> + GMiMC<WIDTH>, const D: usize, const WIDTH: usize> {
|
||||||
F: RichField + Extendable<D> + GMiMC<WIDTH>,
|
|
||||||
const D: usize,
|
|
||||||
const WIDTH: usize,
|
|
||||||
> {
|
|
||||||
_phantom: PhantomData<F>,
|
_phantom: PhantomData<F>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<F: RichField + Extendable<D> + GMiMC<WIDTH>, const D: usize, const WIDTH: usize>
|
impl<F: Extendable<D> + GMiMC<WIDTH>, const D: usize, const WIDTH: usize> GMiMCGate<F, D, WIDTH> {
|
||||||
GMiMCGate<F, D, WIDTH>
|
|
||||||
{
|
|
||||||
pub fn new() -> Self {
|
pub fn new() -> Self {
|
||||||
GMiMCGate {
|
GMiMCGate {
|
||||||
_phantom: PhantomData,
|
_phantom: PhantomData,
|
||||||
@ -61,7 +55,7 @@ impl<F: RichField + Extendable<D> + GMiMC<WIDTH>, const D: usize, const WIDTH: u
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<F: RichField + Extendable<D> + GMiMC<WIDTH>, const D: usize, const WIDTH: usize> Gate<F, D>
|
impl<F: Extendable<D> + GMiMC<WIDTH>, const D: usize, const WIDTH: usize> Gate<F, D>
|
||||||
for GMiMCGate<F, D, WIDTH>
|
for GMiMCGate<F, D, WIDTH>
|
||||||
{
|
{
|
||||||
fn id(&self) -> String {
|
fn id(&self) -> String {
|
||||||
@ -242,17 +236,13 @@ impl<F: RichField + Extendable<D> + GMiMC<WIDTH>, const D: usize, const WIDTH: u
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
struct GMiMCGenerator<
|
struct GMiMCGenerator<F: Extendable<D> + GMiMC<WIDTH>, const D: usize, const WIDTH: usize> {
|
||||||
F: RichField + Extendable<D> + GMiMC<WIDTH>,
|
|
||||||
const D: usize,
|
|
||||||
const WIDTH: usize,
|
|
||||||
> {
|
|
||||||
gate_index: usize,
|
gate_index: usize,
|
||||||
_phantom: PhantomData<F>,
|
_phantom: PhantomData<F>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<F: RichField + Extendable<D> + GMiMC<WIDTH>, const D: usize, const WIDTH: usize>
|
impl<F: Extendable<D> + GMiMC<WIDTH>, const D: usize, const WIDTH: usize> SimpleGenerator<F>
|
||||||
SimpleGenerator<F> for GMiMCGenerator<F, D, WIDTH>
|
for GMiMCGenerator<F, D, WIDTH>
|
||||||
{
|
{
|
||||||
fn dependencies(&self) -> Vec<Target> {
|
fn dependencies(&self) -> Vec<Target> {
|
||||||
let mut dep_input_indices = Vec::with_capacity(WIDTH + 1);
|
let mut dep_input_indices = Vec::with_capacity(WIDTH + 1);
|
||||||
|
|||||||
@ -15,12 +15,12 @@ use crate::plonk::vars::{EvaluationTargets, EvaluationVars, EvaluationVarsBase};
|
|||||||
|
|
||||||
/// A gate for inserting a value into a list at a non-deterministic location.
|
/// A gate for inserting a value into a list at a non-deterministic location.
|
||||||
#[derive(Clone, Debug)]
|
#[derive(Clone, Debug)]
|
||||||
pub(crate) struct InsertionGate<F: RichField + Extendable<D>, const D: usize> {
|
pub(crate) struct InsertionGate<F: Extendable<D>, const D: usize> {
|
||||||
pub vec_size: usize,
|
pub vec_size: usize,
|
||||||
_phantom: PhantomData<F>,
|
_phantom: PhantomData<F>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<F: RichField + Extendable<D>, const D: usize> InsertionGate<F, D> {
|
impl<F: Extendable<D>, const D: usize> InsertionGate<F, D> {
|
||||||
pub fn new(vec_size: usize) -> Self {
|
pub fn new(vec_size: usize) -> Self {
|
||||||
Self {
|
Self {
|
||||||
vec_size,
|
vec_size,
|
||||||
@ -70,7 +70,7 @@ impl<F: RichField + Extendable<D>, const D: usize> InsertionGate<F, D> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<F: RichField + Extendable<D>, const D: usize> Gate<F, D> for InsertionGate<F, D> {
|
impl<F: Extendable<D>, const D: usize> Gate<F, D> for InsertionGate<F, D> {
|
||||||
fn id(&self) -> String {
|
fn id(&self) -> String {
|
||||||
format!("{:?}<D={}>", self, D)
|
format!("{:?}<D={}>", self, D)
|
||||||
}
|
}
|
||||||
|
|||||||
@ -23,12 +23,12 @@ use crate::polynomial::polynomial::PolynomialCoeffs;
|
|||||||
/// to evaluate the interpolant at. It computes the interpolant and outputs its evaluation at the
|
/// to evaluate the interpolant at. It computes the interpolant and outputs its evaluation at the
|
||||||
/// given point.
|
/// given point.
|
||||||
#[derive(Clone, Debug)]
|
#[derive(Clone, Debug)]
|
||||||
pub(crate) struct InterpolationGate<F: RichField + Extendable<D>, const D: usize> {
|
pub(crate) struct InterpolationGate<F: Extendable<D>, const D: usize> {
|
||||||
pub num_points: usize,
|
pub num_points: usize,
|
||||||
_phantom: PhantomData<F>,
|
_phantom: PhantomData<F>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<F: RichField + Extendable<D>, const D: usize> InterpolationGate<F, D> {
|
impl<F: Extendable<D>, const D: usize> InterpolationGate<F, D> {
|
||||||
pub fn new(num_points: usize) -> Self {
|
pub fn new(num_points: usize) -> Self {
|
||||||
Self {
|
Self {
|
||||||
num_points,
|
num_points,
|
||||||
@ -100,7 +100,7 @@ impl<F: RichField + Extendable<D>, const D: usize> InterpolationGate<F, D> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<F: RichField + Extendable<D>, const D: usize> Gate<F, D> for InterpolationGate<F, D> {
|
impl<F: Extendable<D>, const D: usize> Gate<F, D> for InterpolationGate<F, D> {
|
||||||
fn id(&self) -> String {
|
fn id(&self) -> String {
|
||||||
format!("{:?}<D={}>", self, D)
|
format!("{:?}<D={}>", self, D)
|
||||||
}
|
}
|
||||||
@ -221,15 +221,13 @@ impl<F: RichField + Extendable<D>, const D: usize> Gate<F, D> for InterpolationG
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
struct InterpolationGenerator<F: RichField + Extendable<D>, const D: usize> {
|
struct InterpolationGenerator<F: Extendable<D>, const D: usize> {
|
||||||
gate_index: usize,
|
gate_index: usize,
|
||||||
gate: InterpolationGate<F, D>,
|
gate: InterpolationGate<F, D>,
|
||||||
_phantom: PhantomData<F>,
|
_phantom: PhantomData<F>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<F: RichField + Extendable<D>, const D: usize> SimpleGenerator<F>
|
impl<F: Extendable<D>, const D: usize> SimpleGenerator<F> for InterpolationGenerator<F, D> {
|
||||||
for InterpolationGenerator<F, D>
|
|
||||||
{
|
|
||||||
fn dependencies(&self) -> Vec<Target> {
|
fn dependencies(&self) -> Vec<Target> {
|
||||||
let local_target = |input| {
|
let local_target = |input| {
|
||||||
Target::Wire(Wire {
|
Target::Wire(Wire {
|
||||||
|
|||||||
@ -9,7 +9,7 @@ use crate::plonk::vars::{EvaluationTargets, EvaluationVars, EvaluationVarsBase};
|
|||||||
/// A gate which does nothing.
|
/// A gate which does nothing.
|
||||||
pub struct NoopGate;
|
pub struct NoopGate;
|
||||||
|
|
||||||
impl<F: RichField + Extendable<D>, const D: usize> Gate<F, D> for NoopGate {
|
impl<F: Extendable<D>, const D: usize> Gate<F, D> for NoopGate {
|
||||||
fn id(&self) -> String {
|
fn id(&self) -> String {
|
||||||
"NoopGate".into()
|
"NoopGate".into()
|
||||||
}
|
}
|
||||||
|
|||||||
@ -22,11 +22,11 @@ use crate::plonk::vars::{EvaluationTargets, EvaluationVars, EvaluationVarsBase};
|
|||||||
/// It has a flag which can be used to swap the first four inputs with the next four, for ordering
|
/// It has a flag which can be used to swap the first four inputs with the next four, for ordering
|
||||||
/// sibling digests.
|
/// sibling digests.
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub struct PoseidonGate<F: RichField + Extendable<D>, const D: usize> {
|
pub struct PoseidonGate<F: Extendable<D>, const D: usize> {
|
||||||
_phantom: PhantomData<F>,
|
_phantom: PhantomData<F>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<F: RichField + Extendable<D>, const D: usize> PoseidonGate<F, D> {
|
impl<F: Extendable<D>, const D: usize> PoseidonGate<F, D> {
|
||||||
pub fn new() -> Self {
|
pub fn new() -> Self {
|
||||||
PoseidonGate {
|
PoseidonGate {
|
||||||
_phantom: PhantomData,
|
_phantom: PhantomData,
|
||||||
@ -82,7 +82,7 @@ impl<F: RichField + Extendable<D>, const D: usize> PoseidonGate<F, D> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<F: RichField + Extendable<D>, const D: usize> Gate<F, D> for PoseidonGate<F, D> {
|
impl<F: Extendable<D>, const D: usize> Gate<F, D> for PoseidonGate<F, D> {
|
||||||
fn id(&self) -> String {
|
fn id(&self) -> String {
|
||||||
format!("{:?}<SPONGE_WIDTH={}>", self, SPONGE_WIDTH)
|
format!("{:?}<SPONGE_WIDTH={}>", self, SPONGE_WIDTH)
|
||||||
}
|
}
|
||||||
@ -375,7 +375,7 @@ impl<F: RichField + Extendable<D>, const D: usize> Gate<F, D> for PoseidonGate<F
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
struct PoseidonGenerator<F: RichField + Extendable<D> + Poseidon, const D: usize> {
|
struct PoseidonGenerator<F: Extendable<D> + Poseidon, const D: usize> {
|
||||||
gate_index: usize,
|
gate_index: usize,
|
||||||
_phantom: PhantomData<F>,
|
_phantom: PhantomData<F>,
|
||||||
}
|
}
|
||||||
|
|||||||
@ -17,11 +17,11 @@ use crate::plonk::circuit_builder::CircuitBuilder;
|
|||||||
use crate::plonk::vars::{EvaluationTargets, EvaluationVars, EvaluationVarsBase};
|
use crate::plonk::vars::{EvaluationTargets, EvaluationVars, EvaluationVarsBase};
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub struct PoseidonMdsGate<F: RichField + Extendable<D> + Poseidon, const D: usize> {
|
pub struct PoseidonMdsGate<F: Extendable<D> + Poseidon, const D: usize> {
|
||||||
_phantom: PhantomData<F>,
|
_phantom: PhantomData<F>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<F: RichField + Extendable<D> + Poseidon, const D: usize> PoseidonMdsGate<F, D> {
|
impl<F: Extendable<D> + Poseidon, const D: usize> PoseidonMdsGate<F, D> {
|
||||||
pub fn new() -> Self {
|
pub fn new() -> Self {
|
||||||
PoseidonMdsGate {
|
PoseidonMdsGate {
|
||||||
_phantom: PhantomData,
|
_phantom: PhantomData,
|
||||||
@ -103,7 +103,7 @@ impl<F: RichField + Extendable<D> + Poseidon, const D: usize> PoseidonMdsGate<F,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<F: RichField + Extendable<D> + Poseidon, const D: usize> Gate<F, D> for PoseidonMdsGate<F, D> {
|
impl<F: Extendable<D> + Poseidon, const D: usize> Gate<F, D> for PoseidonMdsGate<F, D> {
|
||||||
fn id(&self) -> String {
|
fn id(&self) -> String {
|
||||||
format!("{:?}<WIDTH={}>", self, SPONGE_WIDTH)
|
format!("{:?}<WIDTH={}>", self, SPONGE_WIDTH)
|
||||||
}
|
}
|
||||||
@ -195,9 +195,7 @@ struct PoseidonMdsGenerator<const D: usize> {
|
|||||||
gate_index: usize,
|
gate_index: usize,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<F: RichField + Extendable<D> + Poseidon, const D: usize> SimpleGenerator<F>
|
impl<F: Extendable<D> + Poseidon, const D: usize> SimpleGenerator<F> for PoseidonMdsGenerator<D> {
|
||||||
for PoseidonMdsGenerator<D>
|
|
||||||
{
|
|
||||||
fn dependencies(&self) -> Vec<Target> {
|
fn dependencies(&self) -> Vec<Target> {
|
||||||
(0..SPONGE_WIDTH)
|
(0..SPONGE_WIDTH)
|
||||||
.flat_map(|i| {
|
.flat_map(|i| {
|
||||||
|
|||||||
@ -17,7 +17,7 @@ impl PublicInputGate {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<F: RichField + Extendable<D>, const D: usize> Gate<F, D> for PublicInputGate {
|
impl<F: Extendable<D>, const D: usize> Gate<F, D> for PublicInputGate {
|
||||||
fn id(&self) -> String {
|
fn id(&self) -> String {
|
||||||
"PublicInputGate".into()
|
"PublicInputGate".into()
|
||||||
}
|
}
|
||||||
|
|||||||
@ -14,13 +14,13 @@ use crate::plonk::vars::{EvaluationTargets, EvaluationVars, EvaluationVarsBase};
|
|||||||
|
|
||||||
/// A gate for checking that a particular element of a list matches a given value.
|
/// A gate for checking that a particular element of a list matches a given value.
|
||||||
#[derive(Copy, Clone, Debug)]
|
#[derive(Copy, Clone, Debug)]
|
||||||
pub(crate) struct RandomAccessGate<F: RichField + Extendable<D>, const D: usize> {
|
pub(crate) struct RandomAccessGate<F: Extendable<D>, const D: usize> {
|
||||||
pub vec_size: usize,
|
pub vec_size: usize,
|
||||||
pub num_copies: usize,
|
pub num_copies: usize,
|
||||||
_phantom: PhantomData<F>,
|
_phantom: PhantomData<F>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<F: RichField + Extendable<D>, const D: usize> RandomAccessGate<F, D> {
|
impl<F: Extendable<D>, const D: usize> RandomAccessGate<F, D> {
|
||||||
pub fn new(num_copies: usize, vec_size: usize) -> Self {
|
pub fn new(num_copies: usize, vec_size: usize) -> Self {
|
||||||
Self {
|
Self {
|
||||||
vec_size,
|
vec_size,
|
||||||
@ -87,7 +87,7 @@ impl<F: RichField + Extendable<D>, const D: usize> RandomAccessGate<F, D> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<F: RichField + Extendable<D>, const D: usize> Gate<F, D> for RandomAccessGate<F, D> {
|
impl<F: Extendable<D>, const D: usize> Gate<F, D> for RandomAccessGate<F, D> {
|
||||||
fn id(&self) -> String {
|
fn id(&self) -> String {
|
||||||
format!("{:?}<D={}>", self, D)
|
format!("{:?}<D={}>", self, D)
|
||||||
}
|
}
|
||||||
@ -224,15 +224,13 @@ impl<F: RichField + Extendable<D>, const D: usize> Gate<F, D> for RandomAccessGa
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
struct RandomAccessGenerator<F: RichField + Extendable<D>, const D: usize> {
|
struct RandomAccessGenerator<F: Extendable<D>, const D: usize> {
|
||||||
gate_index: usize,
|
gate_index: usize,
|
||||||
gate: RandomAccessGate<F, D>,
|
gate: RandomAccessGate<F, D>,
|
||||||
copy: usize,
|
copy: usize,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<F: RichField + Extendable<D>, const D: usize> SimpleGenerator<F>
|
impl<F: Extendable<D>, const D: usize> SimpleGenerator<F> for RandomAccessGenerator<F, D> {
|
||||||
for RandomAccessGenerator<F, D>
|
|
||||||
{
|
|
||||||
fn dependencies(&self) -> Vec<Target> {
|
fn dependencies(&self) -> Vec<Target> {
|
||||||
let local_target = |input| Target::wire(self.gate_index, input);
|
let local_target = |input| Target::wire(self.gate_index, input);
|
||||||
|
|
||||||
|
|||||||
@ -16,13 +16,13 @@ use crate::plonk::vars::{EvaluationTargets, EvaluationVars, EvaluationVarsBase};
|
|||||||
|
|
||||||
/// A gate for conditionally swapping input values based on a boolean.
|
/// A gate for conditionally swapping input values based on a boolean.
|
||||||
#[derive(Clone, Debug)]
|
#[derive(Clone, Debug)]
|
||||||
pub(crate) struct SwitchGate<F: RichField + Extendable<D>, const D: usize> {
|
pub(crate) struct SwitchGate<F: Extendable<D>, const D: usize> {
|
||||||
pub(crate) chunk_size: usize,
|
pub(crate) chunk_size: usize,
|
||||||
pub(crate) num_copies: usize,
|
pub(crate) num_copies: usize,
|
||||||
_phantom: PhantomData<F>,
|
_phantom: PhantomData<F>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<F: RichField + Extendable<D>, const D: usize> SwitchGate<F, D> {
|
impl<F: Extendable<D>, const D: usize> SwitchGate<F, D> {
|
||||||
pub fn new(num_copies: usize, chunk_size: usize) -> Self {
|
pub fn new(num_copies: usize, chunk_size: usize) -> Self {
|
||||||
Self {
|
Self {
|
||||||
chunk_size,
|
chunk_size,
|
||||||
@ -66,7 +66,7 @@ impl<F: RichField + Extendable<D>, const D: usize> SwitchGate<F, D> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<F: RichField + Extendable<D>, const D: usize> Gate<F, D> for SwitchGate<F, D> {
|
impl<F: Extendable<D>, const D: usize> Gate<F, D> for SwitchGate<F, D> {
|
||||||
fn id(&self) -> String {
|
fn id(&self) -> String {
|
||||||
format!("{:?}<D={}>", self, D)
|
format!("{:?}<D={}>", self, D)
|
||||||
}
|
}
|
||||||
@ -194,13 +194,13 @@ impl<F: RichField + Extendable<D>, const D: usize> Gate<F, D> for SwitchGate<F,
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
struct SwitchGenerator<F: RichField + Extendable<D>, const D: usize> {
|
struct SwitchGenerator<F: Extendable<D>, const D: usize> {
|
||||||
gate_index: usize,
|
gate_index: usize,
|
||||||
gate: SwitchGate<F, D>,
|
gate: SwitchGate<F, D>,
|
||||||
copy: usize,
|
copy: usize,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<F: RichField + Extendable<D>, const D: usize> SwitchGenerator<F, D> {
|
impl<F: Extendable<D>, const D: usize> SwitchGenerator<F, D> {
|
||||||
fn in_out_dependencies(&self) -> Vec<Target> {
|
fn in_out_dependencies(&self) -> Vec<Target> {
|
||||||
let local_target = |input| Target::wire(self.gate_index, input);
|
let local_target = |input| Target::wire(self.gate_index, input);
|
||||||
|
|
||||||
@ -287,7 +287,7 @@ impl<F: RichField + Extendable<D>, const D: usize> SwitchGenerator<F, D> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<F: RichField + Extendable<D>, const D: usize> WitnessGenerator<F> for SwitchGenerator<F, D> {
|
impl<F: Extendable<D>, const D: usize> WitnessGenerator<F> for SwitchGenerator<F, D> {
|
||||||
fn watch_list(&self) -> Vec<Target> {
|
fn watch_list(&self) -> Vec<Target> {
|
||||||
self.in_out_dependencies()
|
self.in_out_dependencies()
|
||||||
.union(self.in_switch_dependencies())
|
.union(self.in_switch_dependencies())
|
||||||
|
|||||||
@ -23,7 +23,7 @@ pub fn hash_or_noop<F: RichField, P: PlonkyPermutation<F>>(inputs: Vec<F>) -> Ha
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<F: RichField + Extendable<D>, const D: usize> CircuitBuilder<F, D> {
|
impl<F: Extendable<D>, const D: usize> CircuitBuilder<F, D> {
|
||||||
pub fn hash_or_noop<H: AlgebraicHasher<F>>(&mut self, inputs: Vec<Target>) -> HashOutTarget {
|
pub fn hash_or_noop<H: AlgebraicHasher<F>>(&mut self, inputs: Vec<Target>) -> HashOutTarget {
|
||||||
let zero = self.zero();
|
let zero = self.zero();
|
||||||
if inputs.len() <= 4 {
|
if inputs.len() <= 4 {
|
||||||
|
|||||||
@ -52,7 +52,7 @@ pub(crate) fn verify_merkle_proof<F: RichField, H: Hasher<F>>(
|
|||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<F: RichField + Extendable<D>, const D: usize> CircuitBuilder<F, D> {
|
impl<F: Extendable<D>, const D: usize> CircuitBuilder<F, D> {
|
||||||
/// Verifies that the given leaf data is present at the given index in the Merkle tree with the
|
/// Verifies that the given leaf data is present at the given index in the Merkle tree with the
|
||||||
/// given cap. The index is given by it's little-endian bits.
|
/// given cap. The index is given by it's little-endian bits.
|
||||||
pub(crate) fn verify_merkle_proof<H: AlgebraicHasher<F>>(
|
pub(crate) fn verify_merkle_proof<H: AlgebraicHasher<F>>(
|
||||||
|
|||||||
@ -208,7 +208,7 @@ pub trait Poseidon: PrimeField {
|
|||||||
v: &[ExtensionTarget<D>; WIDTH],
|
v: &[ExtensionTarget<D>; WIDTH],
|
||||||
) -> ExtensionTarget<D>
|
) -> ExtensionTarget<D>
|
||||||
where
|
where
|
||||||
Self: RichField + Extendable<D>,
|
Self: Extendable<D>,
|
||||||
{
|
{
|
||||||
debug_assert!(r < WIDTH);
|
debug_assert!(r < WIDTH);
|
||||||
let mut res = builder.zero_extension();
|
let mut res = builder.zero_extension();
|
||||||
@ -264,7 +264,7 @@ pub trait Poseidon: PrimeField {
|
|||||||
state: &[ExtensionTarget<D>; WIDTH],
|
state: &[ExtensionTarget<D>; WIDTH],
|
||||||
) -> [ExtensionTarget<D>; WIDTH]
|
) -> [ExtensionTarget<D>; WIDTH]
|
||||||
where
|
where
|
||||||
Self: RichField + Extendable<D>,
|
Self: Extendable<D>,
|
||||||
{
|
{
|
||||||
// If we have enough routed wires, we will use PoseidonMdsGate.
|
// If we have enough routed wires, we will use PoseidonMdsGate.
|
||||||
let mds_gate = PoseidonMdsGate::<Self, D>::new();
|
let mds_gate = PoseidonMdsGate::<Self, D>::new();
|
||||||
@ -311,7 +311,7 @@ pub trait Poseidon: PrimeField {
|
|||||||
builder: &mut CircuitBuilder<Self, D>,
|
builder: &mut CircuitBuilder<Self, D>,
|
||||||
state: &mut [ExtensionTarget<D>; WIDTH],
|
state: &mut [ExtensionTarget<D>; WIDTH],
|
||||||
) where
|
) where
|
||||||
Self: RichField + Extendable<D>,
|
Self: Extendable<D>,
|
||||||
{
|
{
|
||||||
for i in 0..WIDTH {
|
for i in 0..WIDTH {
|
||||||
let c = <Self as Poseidon>::FAST_PARTIAL_FIRST_ROUND_CONSTANT[i];
|
let c = <Self as Poseidon>::FAST_PARTIAL_FIRST_ROUND_CONSTANT[i];
|
||||||
@ -359,7 +359,7 @@ pub trait Poseidon: PrimeField {
|
|||||||
state: &[ExtensionTarget<D>; WIDTH],
|
state: &[ExtensionTarget<D>; WIDTH],
|
||||||
) -> [ExtensionTarget<D>; WIDTH]
|
) -> [ExtensionTarget<D>; WIDTH]
|
||||||
where
|
where
|
||||||
Self: RichField + Extendable<D>,
|
Self: Extendable<D>,
|
||||||
{
|
{
|
||||||
let mut result = [builder.zero_extension(); WIDTH];
|
let mut result = [builder.zero_extension(); WIDTH];
|
||||||
|
|
||||||
@ -444,7 +444,7 @@ pub trait Poseidon: PrimeField {
|
|||||||
r: usize,
|
r: usize,
|
||||||
) -> [ExtensionTarget<D>; WIDTH]
|
) -> [ExtensionTarget<D>; WIDTH]
|
||||||
where
|
where
|
||||||
Self: RichField + Extendable<D>,
|
Self: Extendable<D>,
|
||||||
{
|
{
|
||||||
let s0 = state[0];
|
let s0 = state[0];
|
||||||
let mut d = builder.mul_const_extension(
|
let mut d = builder.mul_const_extension(
|
||||||
@ -498,7 +498,7 @@ pub trait Poseidon: PrimeField {
|
|||||||
state: &mut [ExtensionTarget<D>; WIDTH],
|
state: &mut [ExtensionTarget<D>; WIDTH],
|
||||||
round_ctr: usize,
|
round_ctr: usize,
|
||||||
) where
|
) where
|
||||||
Self: RichField + Extendable<D>,
|
Self: Extendable<D>,
|
||||||
{
|
{
|
||||||
for i in 0..WIDTH {
|
for i in 0..WIDTH {
|
||||||
let c = ALL_ROUND_CONSTANTS[i + WIDTH * round_ctr];
|
let c = ALL_ROUND_CONSTANTS[i + WIDTH * round_ctr];
|
||||||
@ -523,7 +523,7 @@ pub trait Poseidon: PrimeField {
|
|||||||
x: ExtensionTarget<D>,
|
x: ExtensionTarget<D>,
|
||||||
) -> ExtensionTarget<D>
|
) -> ExtensionTarget<D>
|
||||||
where
|
where
|
||||||
Self: RichField + Extendable<D>,
|
Self: Extendable<D>,
|
||||||
{
|
{
|
||||||
// x |--> x^7
|
// x |--> x^7
|
||||||
builder.exp_u64_extension(x, 7)
|
builder.exp_u64_extension(x, 7)
|
||||||
@ -554,7 +554,7 @@ pub trait Poseidon: PrimeField {
|
|||||||
builder: &mut CircuitBuilder<Self, D>,
|
builder: &mut CircuitBuilder<Self, D>,
|
||||||
state: &mut [ExtensionTarget<D>; WIDTH],
|
state: &mut [ExtensionTarget<D>; WIDTH],
|
||||||
) where
|
) where
|
||||||
Self: RichField + Extendable<D>,
|
Self: Extendable<D>,
|
||||||
{
|
{
|
||||||
for i in 0..WIDTH {
|
for i in 0..WIDTH {
|
||||||
state[i] = <Self as Poseidon>::sbox_monomial_recursive(builder, state[i]);
|
state[i] = <Self as Poseidon>::sbox_monomial_recursive(builder, state[i]);
|
||||||
|
|||||||
@ -42,7 +42,7 @@ use crate::util::partial_products::num_partial_products;
|
|||||||
use crate::util::timing::TimingTree;
|
use crate::util::timing::TimingTree;
|
||||||
use crate::util::{log2_ceil, log2_strict, transpose, transpose_poly_values};
|
use crate::util::{log2_ceil, log2_strict, transpose, transpose_poly_values};
|
||||||
|
|
||||||
pub struct CircuitBuilder<F: RichField + Extendable<D>, const D: usize> {
|
pub struct CircuitBuilder<F: Extendable<D>, const D: usize> {
|
||||||
pub(crate) config: CircuitConfig,
|
pub(crate) config: CircuitConfig,
|
||||||
|
|
||||||
/// The types of gates used in this circuit.
|
/// The types of gates used in this circuit.
|
||||||
@ -91,7 +91,7 @@ pub struct CircuitBuilder<F: RichField + Extendable<D>, const D: usize> {
|
|||||||
free_constant: Option<(usize, usize)>,
|
free_constant: Option<(usize, usize)>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<F: RichField + Extendable<D>, const D: usize> CircuitBuilder<F, D> {
|
impl<F: Extendable<D>, const D: usize> CircuitBuilder<F, D> {
|
||||||
pub fn new(config: CircuitConfig) -> Self {
|
pub fn new(config: CircuitConfig) -> Self {
|
||||||
let builder = CircuitBuilder {
|
let builder = CircuitBuilder {
|
||||||
config,
|
config,
|
||||||
|
|||||||
@ -217,7 +217,7 @@ impl<F: Extendable<D>, C: GenericConfig<D, F = F>, const D: usize>
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) struct ProofChallenges<F: RichField + Extendable<D>, const D: usize> {
|
pub(crate) struct ProofChallenges<F: Extendable<D>, const D: usize> {
|
||||||
// Random values used in Plonk's permutation argument.
|
// Random values used in Plonk's permutation argument.
|
||||||
pub plonk_betas: Vec<F>,
|
pub plonk_betas: Vec<F>,
|
||||||
|
|
||||||
@ -243,9 +243,7 @@ pub(crate) struct ProofChallenges<F: RichField + Extendable<D>, const D: usize>
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Coset elements that can be inferred in the FRI reduction steps.
|
/// Coset elements that can be inferred in the FRI reduction steps.
|
||||||
pub(crate) struct FriInferredElements<F: RichField + Extendable<D>, const D: usize>(
|
pub(crate) struct FriInferredElements<F: Extendable<D>, const D: usize>(pub Vec<F::Extension>);
|
||||||
pub Vec<F::Extension>,
|
|
||||||
);
|
|
||||||
|
|
||||||
pub struct ProofWithPublicInputsTarget<const D: usize> {
|
pub struct ProofWithPublicInputsTarget<const D: usize> {
|
||||||
pub proof: ProofTarget<D>,
|
pub proof: ProofTarget<D>,
|
||||||
|
|||||||
@ -234,7 +234,7 @@ pub(crate) fn eval_vanishing_poly_base_batch<
|
|||||||
/// `num_gate_constraints` is the largest number of constraints imposed by any gate. It is not
|
/// `num_gate_constraints` is the largest number of constraints imposed by any gate. It is not
|
||||||
/// strictly necessary, but it helps performance by ensuring that we allocate a vector with exactly
|
/// strictly necessary, but it helps performance by ensuring that we allocate a vector with exactly
|
||||||
/// the capacity that we need.
|
/// the capacity that we need.
|
||||||
pub fn evaluate_gate_constraints<F: RichField + Extendable<D>, const D: usize>(
|
pub fn evaluate_gate_constraints<F: Extendable<D>, const D: usize>(
|
||||||
gates: &[PrefixedGate<F, D>],
|
gates: &[PrefixedGate<F, D>],
|
||||||
num_gate_constraints: usize,
|
num_gate_constraints: usize,
|
||||||
vars: EvaluationVars<F, D>,
|
vars: EvaluationVars<F, D>,
|
||||||
@ -258,7 +258,7 @@ pub fn evaluate_gate_constraints<F: RichField + Extendable<D>, const D: usize>(
|
|||||||
/// Returns a vector of num_gate_constraints * vars_batch.len() field elements. The constraints
|
/// Returns a vector of num_gate_constraints * vars_batch.len() field elements. The constraints
|
||||||
/// corresponding to vars_batch[i] are found in
|
/// corresponding to vars_batch[i] are found in
|
||||||
/// result[num_gate_constraints * i..num_gate_constraints * (i + 1)].
|
/// result[num_gate_constraints * i..num_gate_constraints * (i + 1)].
|
||||||
pub fn evaluate_gate_constraints_base_batch<F: RichField + Extendable<D>, const D: usize>(
|
pub fn evaluate_gate_constraints_base_batch<F: Extendable<D>, const D: usize>(
|
||||||
gates: &[PrefixedGate<F, D>],
|
gates: &[PrefixedGate<F, D>],
|
||||||
num_gate_constraints: usize,
|
num_gate_constraints: usize,
|
||||||
vars_batch: &[EvaluationVarsBase<F>],
|
vars_batch: &[EvaluationVarsBase<F>],
|
||||||
@ -287,7 +287,7 @@ pub fn evaluate_gate_constraints_base_batch<F: RichField + Extendable<D>, const
|
|||||||
constraints_batch
|
constraints_batch
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn evaluate_gate_constraints_recursively<F: RichField + Extendable<D>, const D: usize>(
|
pub fn evaluate_gate_constraints_recursively<F: Extendable<D>, const D: usize>(
|
||||||
builder: &mut CircuitBuilder<F, D>,
|
builder: &mut CircuitBuilder<F, D>,
|
||||||
gates: &[PrefixedGate<F, D>],
|
gates: &[PrefixedGate<F, D>],
|
||||||
num_gate_constraints: usize,
|
num_gate_constraints: usize,
|
||||||
|
|||||||
@ -61,7 +61,7 @@ pub fn check_partial_products<T: Product + Copy + Sub<Output = T>>(
|
|||||||
res
|
res
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn check_partial_products_recursively<F: RichField + Extendable<D>, const D: usize>(
|
pub fn check_partial_products_recursively<F: Extendable<D>, const D: usize>(
|
||||||
builder: &mut CircuitBuilder<F, D>,
|
builder: &mut CircuitBuilder<F, D>,
|
||||||
v: &[ExtensionTarget<D>],
|
v: &[ExtensionTarget<D>],
|
||||||
partials: &[ExtensionTarget<D>],
|
partials: &[ExtensionTarget<D>],
|
||||||
|
|||||||
@ -100,7 +100,7 @@ impl<const D: usize> ReducingFactorTarget<D> {
|
|||||||
builder: &mut CircuitBuilder<F, D>,
|
builder: &mut CircuitBuilder<F, D>,
|
||||||
) -> ExtensionTarget<D>
|
) -> ExtensionTarget<D>
|
||||||
where
|
where
|
||||||
F: RichField + Extendable<D>,
|
F: Extendable<D>,
|
||||||
{
|
{
|
||||||
let max_coeffs_len = ReducingGate::<D>::max_coeffs_len(
|
let max_coeffs_len = ReducingGate::<D>::max_coeffs_len(
|
||||||
builder.config.num_wires,
|
builder.config.num_wires,
|
||||||
@ -143,7 +143,7 @@ impl<const D: usize> ReducingFactorTarget<D> {
|
|||||||
builder: &mut CircuitBuilder<F, D>,
|
builder: &mut CircuitBuilder<F, D>,
|
||||||
) -> ExtensionTarget<D>
|
) -> ExtensionTarget<D>
|
||||||
where
|
where
|
||||||
F: RichField + Extendable<D>,
|
F: Extendable<D>,
|
||||||
{
|
{
|
||||||
let l = terms.len();
|
let l = terms.len();
|
||||||
self.count += l as u64;
|
self.count += l as u64;
|
||||||
@ -164,7 +164,7 @@ impl<const D: usize> ReducingFactorTarget<D> {
|
|||||||
builder: &mut CircuitBuilder<F, D>,
|
builder: &mut CircuitBuilder<F, D>,
|
||||||
) -> ExtensionTarget<D>
|
) -> ExtensionTarget<D>
|
||||||
where
|
where
|
||||||
F: RichField + Extendable<D>,
|
F: Extendable<D>,
|
||||||
{
|
{
|
||||||
let exp = builder.exp_u64_extension(self.base, self.count);
|
let exp = builder.exp_u64_extension(self.base, self.count);
|
||||||
self.count = 0;
|
self.count = 0;
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user