wip: start plonky2_u32 and plonky2_ecdsa no-std impl

Signed-off-by: Brandon H. Gomes <bhgomes@pm.me>
This commit is contained in:
Brandon H. Gomes 2022-11-03 10:58:55 -07:00
parent e2cdd5a954
commit 703d2c3c95
No known key found for this signature in database
GPG Key ID: 773D44E6A904B222
105 changed files with 464 additions and 505 deletions

View File

@ -3,16 +3,15 @@ name = "plonky2_ecdsa"
version = "0.1.0"
edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
plonky2 = { path = "../plonky2" }
plonky2_util = { path = "../util" }
plonky2_field = { path = "../field" }
plonky2_u32 = { path = "../u32" }
num = "0.4.0"
itertools = "0.10.0"
rayon = "1.5.1"
anyhow = { version = "1.0.40", default-features = false }
itertools = { version = "0.10.0", default-features = false }
maybe_rayon = { path = "../maybe_rayon", default-features = false }
num = { version = "0.4.0", default-features = false }
plonky2 = { path = "../plonky2", default-features = false }
plonky2_u32 = { path = "../u32", default-features = false }
serde = { version = "1.0", default-features = false, features = ["derive"] }
anyhow = "1.0.40"
rand = "0.8.4"
[dev-dependencies]
rand = { version = "0.8.4", default-features = false, features = ["getrandom"] }

View File

@ -1,7 +1,7 @@
use std::ops::Add;
use core::ops::Add;
use plonky2_field::ops::Square;
use plonky2_field::types::Field;
use plonky2::field::ops::Square;
use plonky2::field::types::Field;
use crate::curve::curve_types::{AffinePoint, Curve, ProjectivePoint};

View File

@ -1,6 +1,8 @@
use alloc::vec::Vec;
use itertools::Itertools;
use plonky2_field::types::{Field, PrimeField};
use rayon::prelude::*;
use maybe_rayon::{MaybeIntoParIter, MaybeParChunks};
use plonky2::field::types::{Field, PrimeField};
use crate::curve::curve_summation::affine_multisummation_best;
use crate::curve::curve_types::{AffinePoint, Curve, ProjectivePoint};
@ -185,12 +187,12 @@ pub(crate) fn to_digits<C: Curve>(x: &C::ScalarField, w: usize) -> Vec<usize> {
#[cfg(test)]
mod tests {
use num::BigUint;
use plonky2_field::secp256k1_scalar::Secp256K1Scalar;
use plonky2_field::types::{Field, PrimeField};
use alloc::vec;
use crate::curve::curve_msm::{msm_execute, msm_precompute, to_digits};
use crate::curve::curve_types::Curve;
use num::BigUint;
use plonky2::field::secp256k1_scalar::Secp256K1Scalar;
use super::*;
use crate::curve::secp256k1::Secp256K1;
#[test]

View File

@ -1,6 +1,7 @@
use std::ops::Mul;
use alloc::vec::Vec;
use core::ops::Mul;
use plonky2_field::types::{Field, PrimeField};
use plonky2::field::types::{Field, PrimeField};
use crate::curve::curve_types::{Curve, CurveScalar, ProjectivePoint};

View File

@ -1,7 +1,9 @@
use std::iter::Sum;
use alloc::vec;
use alloc::vec::Vec;
use core::iter::Sum;
use plonky2_field::ops::Square;
use plonky2_field::types::Field;
use plonky2::field::ops::Square;
use plonky2::field::types::Field;
use crate::curve::curve_types::{AffinePoint, Curve, ProjectivePoint};
@ -188,10 +190,7 @@ pub fn affine_multisummation_batch_inversion<C: Curve>(
#[cfg(test)]
mod tests {
use crate::curve::curve_summation::{
affine_summation_batch_inversion, affine_summation_pairwise,
};
use crate::curve::curve_types::{Curve, ProjectivePoint};
use super::*;
use crate::curve::secp256k1::Secp256K1;
#[test]

View File

@ -1,9 +1,10 @@
use std::fmt::Debug;
use std::hash::Hash;
use std::ops::Neg;
use alloc::vec::Vec;
use core::fmt::Debug;
use core::hash::{Hash, Hasher};
use core::ops::Neg;
use plonky2_field::ops::Square;
use plonky2_field::types::{Field, PrimeField};
use plonky2::field::ops::Square;
use plonky2::field::types::{Field, PrimeField};
use serde::{Deserialize, Serialize};
// To avoid implementation conflicts from associated types,
@ -123,7 +124,7 @@ impl<C: Curve> PartialEq for AffinePoint<C> {
impl<C: Curve> Eq for AffinePoint<C> {}
impl<C: Curve> Hash for AffinePoint<C> {
fn hash<H: std::hash::Hasher>(&self, state: &mut H) {
fn hash<H: Hasher>(&self, state: &mut H) {
if self.zero {
self.zero.hash(state);
} else {

View File

@ -1,4 +1,4 @@
use plonky2_field::types::{Field, Sample};
use plonky2::field::types::{Field, Sample};
use serde::{Deserialize, Serialize};
use crate::curve::curve_msm::msm_parallel;
@ -63,8 +63,8 @@ pub fn verify_message<C: Curve>(
#[cfg(test)]
mod tests {
use plonky2_field::secp256k1_scalar::Secp256K1Scalar;
use plonky2_field::types::Sample;
use plonky2::field::secp256k1_scalar::Secp256K1Scalar;
use plonky2::field::types::Sample;
use crate::curve::ecdsa::{sign_message, verify_message, ECDSASecretKey};
use crate::curve::secp256k1::Secp256K1;

View File

@ -1,8 +1,8 @@
use num::rational::Ratio;
use num::BigUint;
use plonky2_field::secp256k1_base::Secp256K1Base;
use plonky2_field::secp256k1_scalar::Secp256K1Scalar;
use plonky2_field::types::{Field, PrimeField};
use plonky2::field::secp256k1_base::Secp256K1Base;
use plonky2::field::secp256k1_scalar::Secp256K1Scalar;
use plonky2::field::types::{Field, PrimeField};
use crate::curve::curve_msm::msm_parallel;
use crate::curve::curve_types::{AffinePoint, ProjectivePoint};
@ -102,8 +102,8 @@ pub fn glv_mul(p: ProjectivePoint<Secp256K1>, k: Secp256K1Scalar) -> ProjectiveP
#[cfg(test)]
mod tests {
use anyhow::Result;
use plonky2_field::secp256k1_scalar::Secp256K1Scalar;
use plonky2_field::types::{Field, Sample};
use plonky2::field::secp256k1_scalar::Secp256K1Scalar;
use plonky2::field::types::{Field, Sample};
use crate::curve::curve_types::{Curve, CurveScalar};
use crate::curve::glv::{decompose_secp256k1_scalar, glv_mul, GLV_S};

View File

@ -1,6 +1,6 @@
use plonky2_field::secp256k1_base::Secp256K1Base;
use plonky2_field::secp256k1_scalar::Secp256K1Scalar;
use plonky2_field::types::Field;
use plonky2::field::secp256k1_base::Secp256K1Base;
use plonky2::field::secp256k1_scalar::Secp256K1Scalar;
use plonky2::field::types::Field;
use serde::{Deserialize, Serialize};
use crate::curve::curve_types::{AffinePoint, Curve};
@ -40,8 +40,8 @@ const SECP256K1_GENERATOR_Y: Secp256K1Base = Secp256K1Base([
#[cfg(test)]
mod tests {
use num::BigUint;
use plonky2_field::secp256k1_scalar::Secp256K1Scalar;
use plonky2_field::types::{Field, PrimeField};
use plonky2::field::secp256k1_scalar::Secp256K1Scalar;
use plonky2::field::types::{Field, PrimeField};
use crate::curve::curve_types::{AffinePoint, Curve, ProjectivePoint};
use crate::curve::secp256k1::Secp256K1;

View File

@ -1,13 +1,15 @@
use std::marker::PhantomData;
use alloc::vec;
use alloc::vec::Vec;
use core::marker::PhantomData;
use num::{BigUint, Integer, Zero};
use plonky2::field::extension::Extendable;
use plonky2::field::types::{PrimeField, PrimeField64};
use plonky2::hash::hash_types::RichField;
use plonky2::iop::generator::{GeneratedValues, SimpleGenerator};
use plonky2::iop::target::{BoolTarget, Target};
use plonky2::iop::witness::{PartitionWitness, Witness};
use plonky2::plonk::circuit_builder::CircuitBuilder;
use plonky2_field::extension::Extendable;
use plonky2_field::types::{PrimeField, PrimeField64};
use plonky2_u32::gadgets::arithmetic_u32::{CircuitBuilderU32, U32Target};
use plonky2_u32::gadgets::multiple_comparison::list_le_u32_circuit;
use plonky2_u32::witness::{GeneratedValuesU32, WitnessU32};
@ -350,6 +352,7 @@ mod tests {
use plonky2::plonk::circuit_builder::CircuitBuilder;
use plonky2::plonk::circuit_data::CircuitConfig;
use plonky2::plonk::config::{GenericConfig, PoseidonGoldilocksConfig};
use rand::rngs::OsRng;
use rand::Rng;
use crate::gadgets::biguint::{CircuitBuilderBiguint, WitnessBigUint};
@ -359,7 +362,7 @@ mod tests {
const D: usize = 2;
type C = PoseidonGoldilocksConfig;
type F = <C as GenericConfig<D>>::F;
let mut rng = rand::thread_rng();
let mut rng = OsRng;
let x_value = BigUint::from_u128(rng.gen()).unwrap();
let y_value = BigUint::from_u128(rng.gen()).unwrap();
@ -389,7 +392,7 @@ mod tests {
const D: usize = 2;
type C = PoseidonGoldilocksConfig;
type F = <C as GenericConfig<D>>::F;
let mut rng = rand::thread_rng();
let mut rng = OsRng;
let mut x_value = BigUint::from_u128(rng.gen()).unwrap();
let mut y_value = BigUint::from_u128(rng.gen()).unwrap();
@ -419,7 +422,7 @@ mod tests {
const D: usize = 2;
type C = PoseidonGoldilocksConfig;
type F = <C as GenericConfig<D>>::F;
let mut rng = rand::thread_rng();
let mut rng = OsRng;
let x_value = BigUint::from_u128(rng.gen()).unwrap();
let y_value = BigUint::from_u128(rng.gen()).unwrap();
@ -449,7 +452,7 @@ mod tests {
const D: usize = 2;
type C = PoseidonGoldilocksConfig;
type F = <C as GenericConfig<D>>::F;
let mut rng = rand::thread_rng();
let mut rng = OsRng;
let x_value = BigUint::from_u128(rng.gen()).unwrap();
let y_value = BigUint::from_u128(rng.gen()).unwrap();
@ -475,7 +478,7 @@ mod tests {
const D: usize = 2;
type C = PoseidonGoldilocksConfig;
type F = <C as GenericConfig<D>>::F;
let mut rng = rand::thread_rng();
let mut rng = OsRng;
let mut x_value = BigUint::from_u128(rng.gen()).unwrap();
let mut y_value = BigUint::from_u128(rng.gen()).unwrap();

View File

@ -1,8 +1,11 @@
use alloc::vec;
use alloc::vec::Vec;
use plonky2::field::extension::Extendable;
use plonky2::field::types::Sample;
use plonky2::hash::hash_types::RichField;
use plonky2::iop::target::BoolTarget;
use plonky2::plonk::circuit_builder::CircuitBuilder;
use plonky2_field::extension::Extendable;
use plonky2_field::types::Sample;
use crate::curve::curve_types::{AffinePoint, Curve, CurveScalar};
use crate::gadgets::nonnative::{CircuitBuilderNonNative, NonNativeTarget};
@ -254,16 +257,16 @@ impl<F: RichField + Extendable<D>, const D: usize> CircuitBuilderCurve<F, D>
#[cfg(test)]
mod tests {
use std::ops::Neg;
use core::ops::Neg;
use anyhow::Result;
use plonky2::field::secp256k1_base::Secp256K1Base;
use plonky2::field::secp256k1_scalar::Secp256K1Scalar;
use plonky2::field::types::{Field, Sample};
use plonky2::iop::witness::PartialWitness;
use plonky2::plonk::circuit_builder::CircuitBuilder;
use plonky2::plonk::circuit_data::CircuitConfig;
use plonky2::plonk::config::{GenericConfig, PoseidonGoldilocksConfig};
use plonky2_field::secp256k1_base::Secp256K1Base;
use plonky2_field::secp256k1_scalar::Secp256K1Scalar;
use plonky2_field::types::{Field, Sample};
use crate::curve::curve_types::{AffinePoint, Curve, CurveScalar};
use crate::curve::secp256k1::Secp256K1;

View File

@ -1,10 +1,12 @@
use alloc::vec::Vec;
use num::BigUint;
use plonky2::field::extension::Extendable;
use plonky2::field::types::Field;
use plonky2::hash::hash_types::RichField;
use plonky2::hash::keccak::KeccakHash;
use plonky2::plonk::circuit_builder::CircuitBuilder;
use plonky2::plonk::config::{GenericHashOut, Hasher};
use plonky2_field::extension::Extendable;
use plonky2_field::types::Field;
use crate::curve::curve_types::{AffinePoint, Curve, CurveScalar};
use crate::gadgets::curve::{AffinePointTarget, CircuitBuilderCurve};
@ -66,12 +68,12 @@ pub fn fixed_base_curve_mul_circuit<C: Curve, F: RichField + Extendable<D>, cons
#[cfg(test)]
mod tests {
use anyhow::Result;
use plonky2::field::secp256k1_scalar::Secp256K1Scalar;
use plonky2::field::types::{PrimeField, Sample};
use plonky2::iop::witness::PartialWitness;
use plonky2::plonk::circuit_builder::CircuitBuilder;
use plonky2::plonk::circuit_data::CircuitConfig;
use plonky2::plonk::config::{GenericConfig, PoseidonGoldilocksConfig};
use plonky2_field::secp256k1_scalar::Secp256K1Scalar;
use plonky2_field::types::{PrimeField, Sample};
use crate::curve::curve_types::{Curve, CurveScalar};
use crate::curve::secp256k1::Secp256K1;

View File

@ -1,10 +1,12 @@
use alloc::vec;
use num::BigUint;
use plonky2::field::extension::Extendable;
use plonky2::field::types::Field;
use plonky2::hash::hash_types::RichField;
use plonky2::hash::keccak::KeccakHash;
use plonky2::plonk::circuit_builder::CircuitBuilder;
use plonky2::plonk::config::{GenericHashOut, Hasher};
use plonky2_field::extension::Extendable;
use plonky2_field::types::Field;
use crate::curve::curve_types::{Curve, CurveScalar};
use crate::gadgets::curve::{AffinePointTarget, CircuitBuilderCurve};
@ -79,12 +81,12 @@ pub fn curve_msm_circuit<C: Curve, F: RichField + Extendable<D>, const D: usize>
#[cfg(test)]
mod tests {
use anyhow::Result;
use plonky2::field::secp256k1_scalar::Secp256K1Scalar;
use plonky2::field::types::Sample;
use plonky2::iop::witness::PartialWitness;
use plonky2::plonk::circuit_builder::CircuitBuilder;
use plonky2::plonk::circuit_data::CircuitConfig;
use plonky2::plonk::config::{GenericConfig, PoseidonGoldilocksConfig};
use plonky2_field::secp256k1_scalar::Secp256K1Scalar;
use plonky2_field::types::Sample;
use crate::curve::curve_types::{Curve, CurveScalar};
use crate::curve::secp256k1::Secp256K1;

View File

@ -1,13 +1,15 @@
use alloc::vec;
use alloc::vec::Vec;
use core::marker::PhantomData;
use num::BigUint;
use plonky2::field::extension::Extendable;
use plonky2::field::types::{Field, Sample};
use plonky2::hash::hash_types::RichField;
use plonky2::hash::keccak::KeccakHash;
use plonky2::iop::target::{BoolTarget, Target};
use plonky2::plonk::circuit_builder::CircuitBuilder;
use plonky2::plonk::config::{GenericHashOut, Hasher};
use plonky2_field::extension::Extendable;
use plonky2_field::types::{Field, Sample};
use plonky2_u32::gadgets::arithmetic_u32::{CircuitBuilderU32, U32Target};
use crate::curve::curve_types::{Curve, CurveScalar};
@ -169,22 +171,18 @@ impl<F: RichField + Extendable<D>, const D: usize> CircuitBuilderWindowedMul<F,
#[cfg(test)]
mod tests {
use std::ops::Neg;
use core::ops::Neg;
use anyhow::Result;
use plonky2::field::secp256k1_scalar::Secp256K1Scalar;
use plonky2::iop::witness::PartialWitness;
use plonky2::plonk::circuit_builder::CircuitBuilder;
use plonky2::plonk::circuit_data::CircuitConfig;
use plonky2::plonk::config::{GenericConfig, PoseidonGoldilocksConfig};
use plonky2_field::secp256k1_scalar::Secp256K1Scalar;
use plonky2_field::types::{Field, Sample};
use rand::rngs::OsRng;
use rand::Rng;
use crate::curve::curve_types::{Curve, CurveScalar};
use super::*;
use crate::curve::secp256k1::Secp256K1;
use crate::gadgets::curve::CircuitBuilderCurve;
use crate::gadgets::curve_windowed_mul::CircuitBuilderWindowedMul;
use crate::gadgets::nonnative::CircuitBuilderNonNative;
#[test]
fn test_random_access_curve_points() -> Result<()> {
@ -206,7 +204,7 @@ mod tests {
})
.collect();
let mut rng = rand::thread_rng();
let mut rng = OsRng;
let access_index = rng.gen::<usize>() % num_points;
let access_index_target = builder.constant(F::from_canonical_usize(access_index));

View File

@ -1,9 +1,9 @@
use std::marker::PhantomData;
use core::marker::PhantomData;
use plonky2::field::extension::Extendable;
use plonky2::field::secp256k1_scalar::Secp256K1Scalar;
use plonky2::hash::hash_types::RichField;
use plonky2::plonk::circuit_builder::CircuitBuilder;
use plonky2_field::extension::Extendable;
use plonky2_field::secp256k1_scalar::Secp256K1Scalar;
use crate::curve::curve_types::Curve;
use crate::curve::secp256k1::Secp256K1;
@ -52,20 +52,14 @@ pub fn verify_message_circuit<F: RichField + Extendable<D>, const D: usize>(
#[cfg(test)]
mod tests {
use anyhow::Result;
use plonky2::field::types::Sample;
use plonky2::iop::witness::PartialWitness;
use plonky2::plonk::circuit_builder::CircuitBuilder;
use plonky2::plonk::circuit_data::CircuitConfig;
use plonky2::plonk::config::{GenericConfig, PoseidonGoldilocksConfig};
use plonky2_field::secp256k1_scalar::Secp256K1Scalar;
use plonky2_field::types::Sample;
use super::{ECDSAPublicKeyTarget, ECDSASignatureTarget};
use crate::curve::curve_types::{Curve, CurveScalar};
use super::*;
use crate::curve::curve_types::CurveScalar;
use crate::curve::ecdsa::{sign_message, ECDSAPublicKey, ECDSASecretKey, ECDSASignature};
use crate::curve::secp256k1::Secp256K1;
use crate::gadgets::curve::CircuitBuilderCurve;
use crate::gadgets::ecdsa::verify_message_circuit;
use crate::gadgets::nonnative::CircuitBuilderNonNative;
fn test_ecdsa_circuit_with_config(config: CircuitConfig) -> Result<()> {
const D: usize = 2;

View File

@ -1,14 +1,15 @@
use std::marker::PhantomData;
use alloc::vec::Vec;
use core::marker::PhantomData;
use plonky2::field::extension::Extendable;
use plonky2::field::secp256k1_base::Secp256K1Base;
use plonky2::field::secp256k1_scalar::Secp256K1Scalar;
use plonky2::field::types::{Field, PrimeField};
use plonky2::hash::hash_types::RichField;
use plonky2::iop::generator::{GeneratedValues, SimpleGenerator};
use plonky2::iop::target::{BoolTarget, Target};
use plonky2::iop::witness::PartitionWitness;
use plonky2::plonk::circuit_builder::CircuitBuilder;
use plonky2_field::extension::Extendable;
use plonky2_field::secp256k1_base::Secp256K1Base;
use plonky2_field::secp256k1_scalar::Secp256K1Scalar;
use plonky2_field::types::{Field, PrimeField};
use crate::curve::glv::{decompose_secp256k1_scalar, GLV_BETA, GLV_S};
use crate::curve::secp256k1::Secp256K1;
@ -132,12 +133,12 @@ impl<F: RichField + Extendable<D>, const D: usize> SimpleGenerator<F>
#[cfg(test)]
mod tests {
use anyhow::Result;
use plonky2::field::secp256k1_scalar::Secp256K1Scalar;
use plonky2::field::types::Sample;
use plonky2::iop::witness::PartialWitness;
use plonky2::plonk::circuit_builder::CircuitBuilder;
use plonky2::plonk::circuit_data::CircuitConfig;
use plonky2::plonk::config::{GenericConfig, PoseidonGoldilocksConfig};
use plonky2_field::secp256k1_scalar::Secp256K1Scalar;
use plonky2_field::types::Sample;
use crate::curve::curve_types::{Curve, CurveScalar};
use crate::curve::glv::glv_mul;

View File

@ -1,17 +1,19 @@
use std::marker::PhantomData;
use alloc::vec;
use alloc::vec::Vec;
use core::marker::PhantomData;
use num::{BigUint, Integer, One, Zero};
use plonky2::field::extension::Extendable;
use plonky2::field::types::{Field, PrimeField};
use plonky2::hash::hash_types::RichField;
use plonky2::iop::generator::{GeneratedValues, SimpleGenerator};
use plonky2::iop::target::{BoolTarget, Target};
use plonky2::iop::witness::PartitionWitness;
use plonky2::plonk::circuit_builder::CircuitBuilder;
use plonky2_field::extension::Extendable;
use plonky2_field::types::{Field, PrimeField};
use plonky2::util::ceil_div_usize;
use plonky2_u32::gadgets::arithmetic_u32::{CircuitBuilderU32, U32Target};
use plonky2_u32::gadgets::range_check::range_check_u32_circuit;
use plonky2_u32::witness::GeneratedValuesU32;
use plonky2_util::ceil_div_usize;
use crate::gadgets::biguint::{
BigUintTarget, CircuitBuilderBiguint, GeneratedValuesBigUint, WitnessBigUint,
@ -642,12 +644,12 @@ impl<F: RichField + Extendable<D>, const D: usize, FF: PrimeField> SimpleGenerat
#[cfg(test)]
mod tests {
use anyhow::Result;
use plonky2::field::secp256k1_base::Secp256K1Base;
use plonky2::field::types::{Field, PrimeField, Sample};
use plonky2::iop::witness::PartialWitness;
use plonky2::plonk::circuit_builder::CircuitBuilder;
use plonky2::plonk::circuit_data::CircuitConfig;
use plonky2::plonk::config::{GenericConfig, PoseidonGoldilocksConfig};
use plonky2_field::secp256k1_base::Secp256K1Base;
use plonky2_field::types::{Field, PrimeField, Sample};
use crate::gadgets::nonnative::CircuitBuilderNonNative;

View File

@ -1,11 +1,12 @@
use std::marker::PhantomData;
use alloc::vec::Vec;
use core::marker::PhantomData;
use itertools::Itertools;
use plonky2::field::extension::Extendable;
use plonky2::field::types::Field;
use plonky2::hash::hash_types::RichField;
use plonky2::iop::target::Target;
use plonky2::plonk::circuit_builder::CircuitBuilder;
use plonky2_field::extension::Extendable;
use plonky2_field::types::Field;
use plonky2_u32::gadgets::arithmetic_u32::{CircuitBuilderU32, U32Target};
use crate::gadgets::biguint::BigUintTarget;
@ -96,15 +97,14 @@ impl<F: RichField + Extendable<D>, const D: usize> CircuitBuilderSplit<F, D>
#[cfg(test)]
mod tests {
use anyhow::Result;
use plonky2::field::secp256k1_scalar::Secp256K1Scalar;
use plonky2::field::types::Sample;
use plonky2::iop::witness::PartialWitness;
use plonky2::plonk::circuit_builder::CircuitBuilder;
use plonky2::plonk::circuit_data::CircuitConfig;
use plonky2::plonk::config::{GenericConfig, PoseidonGoldilocksConfig};
use plonky2_field::secp256k1_scalar::Secp256K1Scalar;
use plonky2_field::types::Sample;
use super::*;
use crate::gadgets::nonnative::{CircuitBuilderNonNative, NonNativeTarget};
use crate::gadgets::split_nonnative::CircuitBuilderSplit;
#[test]
fn test_split_nonnative() -> Result<()> {

View File

@ -1,7 +1,7 @@
#![allow(clippy::needless_range_loop)]
// Below lint is currently broken and produces false positives.
// TODO: Remove this override when Clippy is patched.
#![allow(clippy::derive_partial_eq_without_eq)]
#![cfg_attr(not(test), no_std)]
extern crate alloc;
pub mod curve;
pub mod gadgets;

View File

@ -36,15 +36,15 @@ static_assertions = { version = "1.1.0", default-features = false }
unroll = { version = "0.1.5", default-features = false }
[dev-dependencies]
criterion = "0.3.5"
env_logger = "0.9.0"
num_cpus = "1.13.1"
criterion = { version = "0.3.5", default-features = false }
env_logger = { version = "0.9.0", default-features = false }
num_cpus = { version = "1.13.1", default-features = false }
plonky2 = { path = "." }
rand = "0.8.4"
rand_chacha = "0.3.1"
rayon = "1.5.1"
structopt = "0.3.26"
tynm = "0.1.6"
rand = { version = "0.8.4", default-features = false, features = ["getrandom"] }
rand_chacha = { version = "0.3.1", default-features = false }
rayon = { version = "1.5.1", default-features = false }
structopt = { version = "0.3.26", default-features = false }
tynm = { version = "0.1.6", default-features = false }
[target.'cfg(not(target_env = "msvc"))'.dev-dependencies]
jemallocator = "0.3.2"

View File

@ -2,8 +2,8 @@
#![allow(clippy::needless_range_loop)]
use plonky2_field::goldilocks_field::GoldilocksField;
use plonky2_field::types::Field64;
use plonky2::field::goldilocks_field::GoldilocksField;
use plonky2::field::types::Field64;
use rand::{Rng, SeedableRng};
use rand_chacha::ChaCha8Rng;

View File

@ -1,8 +1,7 @@
use alloc::vec::Vec;
use plonky2_field::extension::Extendable;
use plonky2_field::polynomial::PolynomialCoeffs;
use crate::field::extension::Extendable;
use crate::field::polynomial::PolynomialCoeffs;
use crate::fri::proof::{FriChallenges, FriChallengesTarget};
use crate::fri::structure::{FriOpenings, FriOpeningsTarget};
use crate::fri::FriConfig;

View File

@ -3,13 +3,12 @@ use alloc::vec::Vec;
use itertools::Itertools;
use maybe_rayon::*;
use plonky2_field::extension::Extendable;
use plonky2_field::fft::FftRootTable;
use plonky2_field::packed::PackedField;
use plonky2_field::polynomial::{PolynomialCoeffs, PolynomialValues};
use plonky2_field::types::Field;
use plonky2_util::{log2_strict, reverse_index_bits_in_place};
use crate::field::extension::Extendable;
use crate::field::fft::FftRootTable;
use crate::field::packed::PackedField;
use crate::field::polynomial::{PolynomialCoeffs, PolynomialValues};
use crate::field::types::Field;
use crate::fri::proof::FriProof;
use crate::fri::prover::fri_proof;
use crate::fri::structure::{FriBatchInfo, FriInstanceInfo};
@ -21,7 +20,7 @@ use crate::plonk::config::GenericConfig;
use crate::timed;
use crate::util::reducing::ReducingFactor;
use crate::util::timing::TimingTree;
use crate::util::{reverse_bits, transpose};
use crate::util::{log2_strict, reverse_bits, reverse_index_bits_in_place, transpose};
/// Four (~64 bit) field elements gives ~128 bit security.
pub const SALT_SIZE: usize = 4;

View File

@ -3,10 +3,10 @@ use alloc::vec::Vec;
use hashbrown::HashMap;
use itertools::izip;
use plonky2_field::extension::{flatten, unflatten, Extendable};
use plonky2_field::polynomial::PolynomialCoeffs;
use serde::{Deserialize, Serialize};
use crate::field::extension::{flatten, unflatten, Extendable};
use crate::field::polynomial::PolynomialCoeffs;
use crate::fri::FriParams;
use crate::gadgets::polynomial::PolynomialCoeffsExtTarget;
use crate::hash::hash_types::{MerkleCapTarget, RichField};

View File

@ -2,10 +2,9 @@ use alloc::vec::Vec;
use itertools::Itertools;
use maybe_rayon::*;
use plonky2_field::extension::{flatten, unflatten, Extendable};
use plonky2_field::polynomial::{PolynomialCoeffs, PolynomialValues};
use plonky2_util::reverse_index_bits_in_place;
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::{HashOut, RichField};
@ -14,6 +13,7 @@ use crate::iop::challenger::Challenger;
use crate::plonk::config::{GenericConfig, Hasher};
use crate::plonk::plonk_common::reduce_with_powers;
use crate::timed;
use crate::util::reverse_index_bits_in_place;
use crate::util::timing::TimingTree;
/// Builds a FRI proof.

View File

@ -2,9 +2,8 @@ use alloc::vec::Vec;
use alloc::{format, vec};
use itertools::Itertools;
use plonky2_field::extension::Extendable;
use plonky2_util::{log2_strict, reverse_index_bits_in_place};
use crate::field::extension::Extendable;
use crate::fri::proof::{
FriChallengesTarget, FriInitialTreeProofTarget, FriProofTarget, FriQueryRoundTarget,
FriQueryStepTarget,
@ -22,6 +21,7 @@ use crate::iop::target::{BoolTarget, Target};
use crate::plonk::circuit_builder::CircuitBuilder;
use crate::plonk::config::{AlgebraicHasher, GenericConfig};
use crate::util::reducing::ReducingFactorTarget;
use crate::util::{log2_strict, reverse_index_bits_in_place};
use crate::with_context;
impl<F: RichField + Extendable<D>, const D: usize> CircuitBuilder<F, D> {

View File

@ -35,7 +35,6 @@ impl FriReductionStrategy {
) -> Vec<usize> {
match self {
FriReductionStrategy::Fixed(reduction_arity_bits) => reduction_arity_bits.to_vec(),
&FriReductionStrategy::ConstantArityBits(arity_bits, final_poly_bits) => {
let mut result = Vec::new();
while degree_bits > final_poly_bits
@ -48,7 +47,6 @@ impl FriReductionStrategy {
result.shrink_to_fit();
result
}
FriReductionStrategy::MinSize(opt_max_arity_bits) => {
min_size_arity_bits(degree_bits, rate_bits, num_queries, *opt_max_arity_bits)
}

View File

@ -1,6 +1,6 @@
use anyhow::ensure;
use plonky2_field::extension::Extendable;
use crate::field::extension::Extendable;
use crate::fri::proof::{FriProof, FriQueryRound, FriQueryStep};
use crate::fri::structure::FriInstanceInfo;
use crate::fri::FriParams;

View File

@ -1,11 +1,10 @@
use alloc::vec::Vec;
use anyhow::{ensure, Result};
use plonky2_field::extension::{flatten, Extendable, FieldExtension};
use plonky2_field::interpolation::{barycentric_weights, interpolate};
use plonky2_field::types::Field;
use plonky2_util::{log2_strict, reverse_index_bits_in_place};
use crate::field::extension::{flatten, Extendable, FieldExtension};
use crate::field::interpolation::{barycentric_weights, interpolate};
use crate::field::types::Field;
use crate::fri::proof::{FriChallenges, FriInitialTreeProof, FriProof, FriQueryRound};
use crate::fri::structure::{FriBatchInfo, FriInstanceInfo, FriOpenings};
use crate::fri::validate_shape::validate_fri_proof_shape;
@ -15,7 +14,7 @@ use crate::hash::merkle_proofs::verify_merkle_proof_to_cap;
use crate::hash::merkle_tree::MerkleCap;
use crate::plonk::config::{GenericConfig, Hasher};
use crate::util::reducing::ReducingFactor;
use crate::util::reverse_bits;
use crate::util::{log2_strict, reverse_bits, reverse_index_bits_in_place};
/// 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.

View File

@ -1,6 +1,6 @@
use itertools::Itertools;
use plonky2_field::extension::Extendable;
use crate::field::extension::Extendable;
use crate::fri::proof::{FriProof, FriProofTarget};
use crate::hash::hash_types::RichField;
use crate::iop::witness::Witness;

View File

@ -2,9 +2,8 @@ use alloc::vec;
use alloc::vec::Vec;
use core::borrow::Borrow;
use plonky2_field::extension::Extendable;
use plonky2_field::types::Field64;
use crate::field::extension::Extendable;
use crate::field::types::Field64;
use crate::gates::arithmetic_base::ArithmeticGate;
use crate::gates::exponentiation::ExponentiationGate;
use crate::hash::hash_types::RichField;

View File

@ -2,10 +2,8 @@ use alloc::vec;
use alloc::vec::Vec;
use core::borrow::Borrow;
use plonky2_field::extension::{Extendable, FieldExtension, OEF};
use plonky2_field::types::{Field, Field64};
use plonky2_util::bits_u64;
use crate::field::extension::{Extendable, FieldExtension, OEF};
use crate::field::types::{Field, Field64};
use crate::gates::arithmetic_extension::ArithmeticExtensionGate;
use crate::gates::multiplication_extension::MulExtensionGate;
use crate::hash::hash_types::RichField;
@ -14,6 +12,7 @@ use crate::iop::generator::{GeneratedValues, SimpleGenerator};
use crate::iop::target::Target;
use crate::iop::witness::{PartitionWitness, Witness};
use crate::plonk::circuit_builder::CircuitBuilder;
use crate::util::bits_u64;
impl<F: RichField + Extendable<D>, const D: usize> CircuitBuilder<F, D> {
pub fn arithmetic_extension(
@ -570,9 +569,9 @@ pub(crate) struct ExtensionArithmeticOperation<F: Field64 + Extendable<D>, const
#[cfg(test)]
mod tests {
use anyhow::Result;
use plonky2_field::extension::algebra::ExtensionAlgebra;
use plonky2_field::types::Sample;
use crate::field::extension::algebra::ExtensionAlgebra;
use crate::field::types::Sample;
use crate::iop::ext_target::ExtensionAlgebraTarget;
use crate::iop::witness::{PartialWitness, Witness};
use crate::plonk::circuit_builder::CircuitBuilder;

View File

@ -1,5 +1,4 @@
use plonky2_field::extension::Extendable;
use crate::field::extension::Extendable;
use crate::hash::hash_types::RichField;
use crate::hash::hashing::SPONGE_WIDTH;
use crate::iop::target::{BoolTarget, Target};

View File

@ -1,7 +1,6 @@
use alloc::vec::Vec;
use plonky2_field::extension::Extendable;
use crate::field::extension::Extendable;
use crate::hash::hash_types::RichField;
use crate::iop::ext_target::{ExtensionAlgebraTarget, ExtensionTarget};
use crate::iop::target::Target;

View File

@ -1,13 +1,12 @@
use alloc::vec::Vec;
use plonky2_field::extension::Extendable;
use plonky2_util::log2_strict;
use crate::field::extension::Extendable;
use crate::gates::random_access::RandomAccessGate;
use crate::hash::hash_types::RichField;
use crate::iop::ext_target::ExtensionTarget;
use crate::iop::target::Target;
use crate::plonk::circuit_builder::CircuitBuilder;
use crate::util::log2_strict;
impl<F: RichField + Extendable<D>, const D: usize> CircuitBuilder<F, D> {
/// Checks that a `Target` matches a vector at a non-deterministic index.
@ -57,9 +56,9 @@ impl<F: RichField + Extendable<D>, const D: usize> CircuitBuilder<F, D> {
#[cfg(test)]
mod tests {
use anyhow::Result;
use plonky2_field::types::{Field, Sample};
use super::*;
use crate::field::types::{Field, Sample};
use crate::iop::witness::PartialWitness;
use crate::plonk::circuit_data::CircuitConfig;
use crate::plonk::config::{GenericConfig, PoseidonGoldilocksConfig};

View File

@ -1,8 +1,7 @@
use alloc::vec;
use alloc::vec::Vec;
use plonky2_field::extension::Extendable;
use crate::field::extension::Extendable;
use crate::hash::hash_types::RichField;
use crate::iop::generator::{GeneratedValues, SimpleGenerator};
use crate::iop::target::{BoolTarget, Target};

View File

@ -1,5 +1,4 @@
use plonky2_field::extension::Extendable;
use crate::field::extension::Extendable;
use crate::hash::hash_types::RichField;
use crate::iop::ext_target::ExtensionTarget;
use crate::iop::target::{BoolTarget, Target};
@ -40,8 +39,8 @@ impl<F: RichField + Extendable<D>, const D: usize> CircuitBuilder<F, D> {
#[cfg(test)]
mod tests {
use anyhow::Result;
use plonky2_field::types::Sample;
use crate::field::types::Sample;
use crate::iop::witness::{PartialWitness, Witness};
use crate::plonk::circuit_builder::CircuitBuilder;
use crate::plonk::circuit_data::CircuitConfig;

View File

@ -3,9 +3,9 @@ use alloc::vec::Vec;
use core::borrow::Borrow;
use itertools::Itertools;
use plonky2_field::extension::Extendable;
use plonky2_field::types::Field;
use crate::field::extension::Extendable;
use crate::field::types::Field;
use crate::gates::base_sum::BaseSumGate;
use crate::hash::hash_types::RichField;
use crate::iop::generator::{GeneratedValues, SimpleGenerator};
@ -101,11 +101,11 @@ impl<F: Field, const B: usize> SimpleGenerator<F> for BaseSumGenerator<B> {
#[cfg(test)]
mod tests {
use anyhow::Result;
use plonky2_field::types::Field;
use rand::{thread_rng, Rng};
use rand::rngs::OsRng;
use rand::Rng;
use super::*;
use crate::iop::witness::PartialWitness;
use crate::plonk::circuit_builder::CircuitBuilder;
use crate::plonk::circuit_data::CircuitConfig;
use crate::plonk::config::{GenericConfig, PoseidonGoldilocksConfig};
use crate::plonk::verifier::verify;
@ -147,7 +147,7 @@ mod tests {
let pw = PartialWitness::new();
let mut builder = CircuitBuilder::<F, D>::new(config);
let n = thread_rng().gen_range(0..(1 << 30));
let n = OsRng.gen_range(0..(1 << 30));
let x = builder.constant(F::from_canonical_usize(n));
let zero = builder._false();

View File

@ -1,15 +1,14 @@
use alloc::vec;
use alloc::vec::Vec;
use plonky2_field::extension::Extendable;
use plonky2_util::ceil_div_usize;
use crate::field::extension::Extendable;
use crate::gates::base_sum::BaseSumGate;
use crate::hash::hash_types::RichField;
use crate::iop::generator::{GeneratedValues, SimpleGenerator};
use crate::iop::target::{BoolTarget, Target};
use crate::iop::witness::{PartitionWitness, Witness};
use crate::plonk::circuit_builder::CircuitBuilder;
use crate::util::ceil_div_usize;
impl<F: RichField + Extendable<D>, const D: usize> CircuitBuilder<F, D> {
/// Split the given integer into a list of wires, where each one represents a

View File

@ -3,9 +3,8 @@ use alloc::format;
use alloc::string::String;
use alloc::vec::Vec;
use plonky2_field::extension::Extendable;
use plonky2_field::packed::PackedField;
use crate::field::extension::Extendable;
use crate::field::packed::PackedField;
use crate::gates::gate::Gate;
use crate::gates::packed_util::PackedEvaluableBase;
use crate::gates::util::StridedConstraintConsumer;
@ -214,8 +213,8 @@ impl<F: RichField + Extendable<D>, const D: usize> SimpleGenerator<F>
#[cfg(test)]
mod tests {
use anyhow::Result;
use plonky2_field::goldilocks_field::GoldilocksField;
use crate::field::goldilocks_field::GoldilocksField;
use crate::gates::arithmetic_base::ArithmeticGate;
use crate::gates::gate_testing::{test_eval_fns, test_low_degree};
use crate::plonk::circuit_data::CircuitConfig;

View File

@ -4,8 +4,7 @@ use alloc::string::String;
use alloc::vec::Vec;
use core::ops::Range;
use plonky2_field::extension::{Extendable, FieldExtension};
use crate::field::extension::{Extendable, FieldExtension};
use crate::gates::gate::Gate;
use crate::gates::util::StridedConstraintConsumer;
use crate::hash::hash_types::RichField;
@ -207,8 +206,8 @@ impl<F: RichField + Extendable<D>, const D: usize> SimpleGenerator<F>
#[cfg(test)]
mod tests {
use anyhow::Result;
use plonky2_field::goldilocks_field::GoldilocksField;
use crate::field::goldilocks_field::GoldilocksField;
use crate::gates::arithmetic_extension::ArithmeticExtensionGate;
use crate::gates::gate_testing::{test_eval_fns, test_low_degree};
use crate::plonk::circuit_data::CircuitConfig;

View File

@ -4,11 +4,9 @@ use alloc::vec::Vec;
use alloc::{format, vec};
use core::ops::Range;
use plonky2_field::extension::Extendable;
use plonky2_field::packed::PackedField;
use plonky2_field::types::{Field, Field64};
use plonky2_util::log_floor;
use crate::field::extension::Extendable;
use crate::field::packed::PackedField;
use crate::field::types::{Field, Field64};
use crate::gates::gate::Gate;
use crate::gates::packed_util::PackedEvaluableBase;
use crate::gates::util::StridedConstraintConsumer;
@ -24,6 +22,7 @@ use crate::plonk::vars::{
EvaluationTargets, EvaluationVars, EvaluationVarsBase, EvaluationVarsBaseBatch,
EvaluationVarsBasePacked,
};
use crate::util::log_floor;
/// A gate which can decompose a number into base B little-endian limbs.
#[derive(Copy, Clone, Debug)]
@ -201,8 +200,8 @@ impl<F: RichField, const B: usize> SimpleGenerator<F> for BaseSplitGenerator<B>
#[cfg(test)]
mod tests {
use anyhow::Result;
use plonky2_field::goldilocks_field::GoldilocksField;
use crate::field::goldilocks_field::GoldilocksField;
use crate::gates::base_sum::BaseSumGate;
use crate::gates::gate_testing::{test_eval_fns, test_low_degree};
use crate::plonk::config::{GenericConfig, PoseidonGoldilocksConfig};

View File

@ -3,9 +3,8 @@ use alloc::string::String;
use alloc::vec::Vec;
use alloc::{format, vec};
use plonky2_field::extension::Extendable;
use plonky2_field::packed::PackedField;
use crate::field::extension::Extendable;
use crate::field::packed::PackedField;
use crate::gates::gate::Gate;
use crate::gates::packed_util::PackedEvaluableBase;
use crate::gates::util::StridedConstraintConsumer;
@ -118,8 +117,8 @@ impl<F: RichField + Extendable<D>, const D: usize> PackedEvaluableBase<F, D> for
#[cfg(test)]
mod tests {
use anyhow::Result;
use plonky2_field::goldilocks_field::GoldilocksField;
use crate::field::goldilocks_field::GoldilocksField;
use crate::gates::constant::ConstantGate;
use crate::gates::gate_testing::{test_eval_fns, test_low_degree};
use crate::plonk::circuit_data::CircuitConfig;

View File

@ -4,11 +4,10 @@ use alloc::vec::Vec;
use alloc::{format, vec};
use core::marker::PhantomData;
use plonky2_field::extension::Extendable;
use plonky2_field::ops::Square;
use plonky2_field::packed::PackedField;
use plonky2_field::types::Field;
use crate::field::extension::Extendable;
use crate::field::ops::Square;
use crate::field::packed::PackedField;
use crate::field::types::Field;
use crate::gates::gate::Gate;
use crate::gates::packed_util::PackedEvaluableBase;
use crate::gates::util::StridedConstraintConsumer;
@ -286,21 +285,17 @@ impl<F: RichField + Extendable<D>, const D: usize> SimpleGenerator<F>
#[cfg(test)]
mod tests {
use core::marker::PhantomData;
use anyhow::Result;
use plonky2_field::goldilocks_field::GoldilocksField;
use plonky2_field::types::{Field, Sample};
use plonky2_util::log2_ceil;
use rand::rngs::OsRng;
use rand::Rng;
use crate::gates::exponentiation::ExponentiationGate;
use crate::gates::gate::Gate;
use super::*;
use crate::field::goldilocks_field::GoldilocksField;
use crate::field::types::Sample;
use crate::gates::gate_testing::{test_eval_fns, test_low_degree};
use crate::hash::hash_types::HashOut;
use crate::plonk::circuit_data::CircuitConfig;
use crate::plonk::config::{GenericConfig, PoseidonGoldilocksConfig};
use crate::plonk::vars::EvaluationVars;
use crate::util::log2_ceil;
const MAX_POWER_BITS: usize = 17;
@ -383,7 +378,7 @@ mod tests {
v.iter().map(|&x| x.into()).collect::<Vec<_>>()
}
let mut rng = rand::thread_rng();
let mut rng = OsRng;
let base = F::TWO;
let power = rng.gen::<usize>() % (1 << MAX_POWER_BITS);

View File

@ -8,10 +8,10 @@ use core::hash::{Hash, Hasher};
use core::ops::Range;
use hashbrown::HashMap;
use plonky2_field::batch_util::batch_multiply_inplace;
use plonky2_field::extension::{Extendable, FieldExtension};
use plonky2_field::types::Field;
use crate::field::batch_util::batch_multiply_inplace;
use crate::field::extension::{Extendable, FieldExtension};
use crate::field::types::Field;
use crate::gates::selectors::UNUSED_SELECTOR;
use crate::gates::util::StridedConstraintConsumer;
use crate::hash::hash_types::RichField;

View File

@ -2,11 +2,10 @@ use alloc::vec;
use alloc::vec::Vec;
use anyhow::{ensure, Result};
use plonky2_field::extension::{Extendable, FieldExtension};
use plonky2_field::polynomial::{PolynomialCoeffs, PolynomialValues};
use plonky2_field::types::{Field, Sample};
use plonky2_util::log2_ceil;
use crate::field::extension::{Extendable, FieldExtension};
use crate::field::polynomial::{PolynomialCoeffs, PolynomialValues};
use crate::field::types::{Field, Sample};
use crate::gates::gate::Gate;
use crate::hash::hash_types::{HashOut, RichField};
use crate::iop::witness::{PartialWitness, Witness};
@ -15,7 +14,7 @@ use crate::plonk::circuit_data::CircuitConfig;
use crate::plonk::config::GenericConfig;
use crate::plonk::vars::{EvaluationTargets, EvaluationVars, EvaluationVarsBaseBatch};
use crate::plonk::verifier::verify;
use crate::util::transpose;
use crate::util::{log2_ceil, transpose};
const WITNESS_SIZE: usize = 1 << 5;
const WITNESS_DEGREE: usize = WITNESS_SIZE - 1;

View File

@ -5,11 +5,10 @@ use alloc::{format, vec};
use core::marker::PhantomData;
use core::ops::Range;
use plonky2_field::extension::algebra::PolynomialCoeffsAlgebra;
use plonky2_field::extension::{Extendable, FieldExtension};
use plonky2_field::interpolation::interpolant;
use plonky2_field::polynomial::PolynomialCoeffs;
use crate::field::extension::algebra::PolynomialCoeffsAlgebra;
use crate::field::extension::{Extendable, FieldExtension};
use crate::field::interpolation::interpolant;
use crate::field::polynomial::PolynomialCoeffs;
use crate::gadgets::polynomial::PolynomialCoeffsExtAlgebraTarget;
use crate::gates::gate::Gate;
use crate::gates::interpolation::InterpolationGate;
@ -274,20 +273,14 @@ impl<F: RichField + Extendable<D>, const D: usize> SimpleGenerator<F>
#[cfg(test)]
mod tests {
use core::marker::PhantomData;
use anyhow::Result;
use plonky2_field::goldilocks_field::GoldilocksField;
use plonky2_field::polynomial::PolynomialCoeffs;
use plonky2_field::types::{Field, Sample};
use crate::gates::gate::Gate;
use super::*;
use crate::field::goldilocks_field::GoldilocksField;
use crate::field::types::{Field, Sample};
use crate::gates::gate_testing::{test_eval_fns, test_low_degree};
use crate::gates::high_degree_interpolation::HighDegreeInterpolationGate;
use crate::gates::interpolation::InterpolationGate;
use crate::hash::hash_types::HashOut;
use crate::plonk::config::{GenericConfig, PoseidonGoldilocksConfig};
use crate::plonk::vars::EvaluationVars;
#[test]
fn wire_indices() {

View File

@ -1,8 +1,7 @@
use alloc::vec;
use core::ops::Range;
use plonky2_field::extension::Extendable;
use crate::field::extension::Extendable;
use crate::gates::gate::Gate;
use crate::hash::hash_types::RichField;
use crate::iop::ext_target::ExtensionTarget;
@ -106,10 +105,10 @@ impl<F: RichField + Extendable<D>, const D: usize> CircuitBuilder<F, D> {
#[cfg(test)]
mod tests {
use anyhow::Result;
use plonky2_field::extension::FieldExtension;
use plonky2_field::interpolation::interpolant;
use plonky2_field::types::{Field, Sample};
use crate::field::extension::FieldExtension;
use crate::field::interpolation::interpolant;
use crate::field::types::{Field, Sample};
use crate::gates::high_degree_interpolation::HighDegreeInterpolationGate;
use crate::gates::low_degree_interpolation::LowDegreeInterpolationGate;
use crate::iop::witness::PartialWitness;

View File

@ -5,12 +5,11 @@ use alloc::{format, vec};
use core::marker::PhantomData;
use core::ops::Range;
use plonky2_field::extension::algebra::PolynomialCoeffsAlgebra;
use plonky2_field::extension::{Extendable, FieldExtension};
use plonky2_field::interpolation::interpolant;
use plonky2_field::polynomial::PolynomialCoeffs;
use plonky2_field::types::Field;
use crate::field::extension::algebra::PolynomialCoeffsAlgebra;
use crate::field::extension::{Extendable, FieldExtension};
use crate::field::interpolation::interpolant;
use crate::field::polynomial::PolynomialCoeffs;
use crate::field::types::Field;
use crate::gadgets::polynomial::PolynomialCoeffsExtAlgebraTarget;
use crate::gates::gate::Gate;
use crate::gates::interpolation::InterpolationGate;
@ -387,11 +386,11 @@ impl<F: RichField + Extendable<D>, const D: usize> SimpleGenerator<F>
#[cfg(test)]
mod tests {
use anyhow::Result;
use plonky2_field::extension::quadratic::QuadraticExtension;
use plonky2_field::goldilocks_field::GoldilocksField;
use plonky2_field::polynomial::PolynomialCoeffs;
use plonky2_field::types::{Field, Sample};
use crate::field::extension::quadratic::QuadraticExtension;
use crate::field::goldilocks_field::GoldilocksField;
use crate::field::polynomial::PolynomialCoeffs;
use crate::field::types::{Field, Sample};
use crate::gates::gate::Gate;
use crate::gates::gate_testing::{test_eval_fns, test_low_degree};
use crate::gates::interpolation::InterpolationGate;

View File

@ -4,8 +4,7 @@ use alloc::string::String;
use alloc::vec::Vec;
use core::ops::Range;
use plonky2_field::extension::{Extendable, FieldExtension};
use crate::field::extension::{Extendable, FieldExtension};
use crate::gates::gate::Gate;
use crate::gates::util::StridedConstraintConsumer;
use crate::hash::hash_types::RichField;
@ -184,11 +183,10 @@ impl<F: RichField + Extendable<D>, const D: usize> SimpleGenerator<F>
#[cfg(test)]
mod tests {
use anyhow::Result;
use plonky2_field::goldilocks_field::GoldilocksField;
use super::*;
use crate::field::goldilocks_field::GoldilocksField;
use crate::gates::gate_testing::{test_eval_fns, test_low_degree};
use crate::gates::multiplication_extension::MulExtensionGate;
use crate::plonk::circuit_data::CircuitConfig;
use crate::plonk::config::{GenericConfig, PoseidonGoldilocksConfig};
#[test]

View File

@ -2,8 +2,7 @@ use alloc::boxed::Box;
use alloc::string::String;
use alloc::vec::Vec;
use plonky2_field::extension::Extendable;
use crate::field::extension::Extendable;
use crate::gates::gate::Gate;
use crate::hash::hash_types::RichField;
use crate::iop::ext_target::ExtensionTarget;
@ -58,8 +57,7 @@ impl<F: RichField + Extendable<D>, const D: usize> Gate<F, D> for NoopGate {
#[cfg(test)]
mod tests {
use plonky2_field::goldilocks_field::GoldilocksField;
use crate::field::goldilocks_field::GoldilocksField;
use crate::gates::gate_testing::{test_eval_fns, test_low_degree};
use crate::gates::noop::NoopGate;
use crate::plonk::config::{GenericConfig, PoseidonGoldilocksConfig};

View File

@ -1,10 +1,9 @@
use alloc::vec;
use alloc::vec::Vec;
use plonky2_field::extension::Extendable;
use plonky2_field::packable::Packable;
use plonky2_field::packed::PackedField;
use crate::field::extension::Extendable;
use crate::field::packable::Packable;
use crate::field::packed::PackedField;
use crate::gates::gate::Gate;
use crate::gates::util::StridedConstraintConsumer;
use crate::hash::hash_types::RichField;

View File

@ -4,9 +4,8 @@ use alloc::vec::Vec;
use alloc::{format, vec};
use core::marker::PhantomData;
use plonky2_field::extension::Extendable;
use plonky2_field::types::Field;
use crate::field::extension::Extendable;
use crate::field::types::Field;
use crate::gates::gate::Gate;
use crate::gates::poseidon_mds::PoseidonMdsGate;
use crate::gates::util::StridedConstraintConsumer;
@ -507,9 +506,9 @@ impl<F: RichField + Extendable<D> + Poseidon, const D: usize> SimpleGenerator<F>
#[cfg(test)]
mod tests {
use anyhow::Result;
use plonky2_field::goldilocks_field::GoldilocksField;
use plonky2_field::types::Field;
use crate::field::goldilocks_field::GoldilocksField;
use crate::field::types::Field;
use crate::gates::gate_testing::{test_eval_fns, test_low_degree};
use crate::gates::poseidon::PoseidonGate;
use crate::hash::hashing::SPONGE_WIDTH;

View File

@ -5,10 +5,9 @@ use alloc::{format, vec};
use core::marker::PhantomData;
use core::ops::Range;
use plonky2_field::extension::algebra::ExtensionAlgebra;
use plonky2_field::extension::{Extendable, FieldExtension};
use plonky2_field::types::Field;
use crate::field::extension::algebra::ExtensionAlgebra;
use crate::field::extension::{Extendable, FieldExtension};
use crate::field::types::Field;
use crate::gates::gate::Gate;
use crate::gates::util::StridedConstraintConsumer;
use crate::hash::hash_types::RichField;

View File

@ -3,9 +3,8 @@ use alloc::string::String;
use alloc::vec::Vec;
use core::ops::Range;
use plonky2_field::extension::Extendable;
use plonky2_field::packed::PackedField;
use crate::field::extension::Extendable;
use crate::field::packed::PackedField;
use crate::gates::gate::Gate;
use crate::gates::packed_util::PackedEvaluableBase;
use crate::gates::util::StridedConstraintConsumer;
@ -102,8 +101,7 @@ impl<F: RichField + Extendable<D>, const D: usize> PackedEvaluableBase<F, D> for
#[cfg(test)]
mod tests {
use plonky2_field::goldilocks_field::GoldilocksField;
use crate::field::goldilocks_field::GoldilocksField;
use crate::gates::gate_testing::{test_eval_fns, test_low_degree};
use crate::gates::public_input::PublicInputGate;
use crate::plonk::config::{GenericConfig, PoseidonGoldilocksConfig};

View File

@ -5,10 +5,10 @@ use alloc::{format, vec};
use core::marker::PhantomData;
use itertools::Itertools;
use plonky2_field::extension::Extendable;
use plonky2_field::packed::PackedField;
use plonky2_field::types::Field;
use crate::field::extension::Extendable;
use crate::field::packed::PackedField;
use crate::field::types::Field;
use crate::gates::gate::Gate;
use crate::gates::packed_util::PackedEvaluableBase;
use crate::gates::util::StridedConstraintConsumer;
@ -380,19 +380,16 @@ impl<F: RichField + Extendable<D>, const D: usize> SimpleGenerator<F>
#[cfg(test)]
mod tests {
use core::marker::PhantomData;
use anyhow::Result;
use plonky2_field::goldilocks_field::GoldilocksField;
use plonky2_field::types::{Field, Sample};
use rand::{thread_rng, Rng};
use rand::rngs::OsRng;
use rand::Rng;
use crate::gates::gate::Gate;
use super::*;
use crate::field::goldilocks_field::GoldilocksField;
use crate::field::types::Sample;
use crate::gates::gate_testing::{test_eval_fns, test_low_degree};
use crate::gates::random_access::RandomAccessGate;
use crate::hash::hash_types::HashOut;
use crate::plonk::config::{GenericConfig, PoseidonGoldilocksConfig};
use crate::plonk::vars::EvaluationVars;
#[test]
fn low_degree() {
@ -453,7 +450,7 @@ mod tests {
.map(|_| F::rand_vec(vec_size))
.collect::<Vec<_>>();
let access_indices = (0..num_copies)
.map(|_| thread_rng().gen_range(0..vec_size))
.map(|_| OsRng.gen_range(0..vec_size))
.collect::<Vec<_>>();
let gate = RandomAccessGate::<F, D> {
bits,

View File

@ -4,8 +4,7 @@ use alloc::vec::Vec;
use alloc::{format, vec};
use core::ops::Range;
use plonky2_field::extension::{Extendable, FieldExtension};
use crate::field::extension::{Extendable, FieldExtension};
use crate::gates::gate::Gate;
use crate::gates::util::StridedConstraintConsumer;
use crate::hash::hash_types::RichField;
@ -213,8 +212,8 @@ impl<F: RichField + Extendable<D>, const D: usize> SimpleGenerator<F> for Reduci
#[cfg(test)]
mod tests {
use anyhow::Result;
use plonky2_field::goldilocks_field::GoldilocksField;
use crate::field::goldilocks_field::GoldilocksField;
use crate::gates::gate_testing::{test_eval_fns, test_low_degree};
use crate::gates::reducing::ReducingGate;
use crate::plonk::config::{GenericConfig, PoseidonGoldilocksConfig};

View File

@ -4,8 +4,7 @@ use alloc::vec::Vec;
use alloc::{format, vec};
use core::ops::Range;
use plonky2_field::extension::{Extendable, FieldExtension};
use crate::field::extension::{Extendable, FieldExtension};
use crate::gates::gate::Gate;
use crate::gates::util::StridedConstraintConsumer;
use crate::hash::hash_types::RichField;
@ -207,8 +206,8 @@ impl<F: RichField + Extendable<D>, const D: usize> SimpleGenerator<F> for Reduci
#[cfg(test)]
mod tests {
use anyhow::Result;
use plonky2_field::goldilocks_field::GoldilocksField;
use crate::field::goldilocks_field::GoldilocksField;
use crate::gates::gate_testing::{test_eval_fns, test_low_degree};
use crate::gates::reducing_extension::ReducingExtensionGate;
use crate::plonk::config::{GenericConfig, PoseidonGoldilocksConfig};

View File

@ -2,9 +2,8 @@ use alloc::vec;
use alloc::vec::Vec;
use core::ops::Range;
use plonky2_field::extension::Extendable;
use plonky2_field::polynomial::PolynomialValues;
use crate::field::extension::Extendable;
use crate::field::polynomial::PolynomialValues;
use crate::gates::gate::{GateInstance, GateRef};
use crate::hash::hash_types::RichField;

View File

@ -1,6 +1,6 @@
use core::marker::PhantomData;
use plonky2_field::packed::PackedField;
use crate::field::packed::PackedField;
/// Writes constraints yielded by a gate to a buffer, with a given stride.
/// Permits us to abstract the underlying memory layout. In particular, we can make a matrix of

View File

@ -4,12 +4,12 @@ use core::arch::aarch64::*;
use core::arch::asm;
use core::mem::transmute;
use plonky2_field::goldilocks_field::GoldilocksField;
use plonky2_util::branch_hint;
use static_assertions::const_assert;
use unroll::unroll_for_loops;
use crate::field::goldilocks_field::GoldilocksField;
use crate::hash::poseidon::Poseidon;
use crate::util::branch_hint;
// ========================================== CONSTANTS ===========================================

View File

@ -2,14 +2,14 @@ use core::arch::asm;
use core::arch::x86_64::*;
use core::mem::size_of;
use plonky2_field::goldilocks_field::GoldilocksField;
use plonky2_field::types::Field;
use plonky2_util::branch_hint;
use static_assertions::const_assert;
use crate::field::goldilocks_field::GoldilocksField;
use crate::field::types::Field;
use crate::hash::poseidon::{
Poseidon, ALL_ROUND_CONSTANTS, HALF_N_FULL_ROUNDS, N_PARTIAL_ROUNDS, N_ROUNDS,
};
use crate::util::branch_hint;
// WARNING: This code contains tricks that work for the current MDS matrix and round constants, but
// are not guaranteed to work if those are changed.

View File

@ -1,9 +1,9 @@
use alloc::vec::Vec;
use plonky2_field::goldilocks_field::GoldilocksField;
use plonky2_field::types::{Field, PrimeField64, Sample};
use serde::{Deserialize, Deserializer, Serialize, Serializer};
use crate::field::goldilocks_field::GoldilocksField;
use crate::field::types::{Field, PrimeField64, Sample};
use crate::hash::poseidon::Poseidon;
use crate::iop::target::Target;
use crate::plonk::config::GenericHashOut;

View File

@ -2,8 +2,7 @@
use alloc::vec::Vec;
use plonky2_field::extension::Extendable;
use crate::field::extension::Extendable;
use crate::hash::hash_types::{HashOut, HashOutTarget, RichField};
use crate::iop::target::Target;
use crate::plonk::circuit_builder::CircuitBuilder;

View File

@ -2,9 +2,9 @@ use alloc::vec;
use alloc::vec::Vec;
use anyhow::{ensure, Result};
use plonky2_field::extension::Extendable;
use serde::{Deserialize, Serialize};
use crate::field::extension::Extendable;
use crate::hash::hash_types::{HashOutTarget, MerkleCapTarget, RichField};
use crate::hash::hashing::SPONGE_WIDTH;
use crate::hash::merkle_tree::MerkleCap;
@ -150,10 +150,11 @@ impl<F: RichField + Extendable<D>, const D: usize> CircuitBuilder<F, D> {
#[cfg(test)]
mod tests {
use anyhow::Result;
use plonky2_field::types::Field;
use rand::{thread_rng, Rng};
use rand::rngs::OsRng;
use rand::Rng;
use super::*;
use crate::field::types::Field;
use crate::hash::merkle_tree::MerkleTree;
use crate::iop::witness::{PartialWitness, Witness};
use crate::plonk::circuit_builder::CircuitBuilder;
@ -179,7 +180,7 @@ mod tests {
let cap_height = 1;
let leaves = random_data::<F>(n, 7);
let tree = MerkleTree::<F, <C as GenericConfig<D>>::Hasher>::new(leaves, cap_height);
let i: usize = thread_rng().gen_range(0..n);
let i: usize = OsRng.gen_range(0..n);
let proof = tree.prove(i);
let proof_t = MerkleProofTarget {

View File

@ -3,12 +3,12 @@ use core::mem::MaybeUninit;
use core::slice;
use maybe_rayon::*;
use plonky2_util::log2_strict;
use serde::{Deserialize, Serialize};
use crate::hash::hash_types::RichField;
use crate::hash::merkle_proofs::MerkleProof;
use crate::plonk::config::{GenericHashOut, Hasher};
use crate::util::log2_strict;
/// The Merkle cap of height `h` of a Merkle tree is the `h`-th layer (from the root) of the tree.
/// It can be used in place of the root to verify Merkle paths, which are `h` elements shorter.
@ -208,9 +208,9 @@ impl<F: RichField, H: Hasher<F>> MerkleTree<F, H> {
#[cfg(test)]
mod tests {
use anyhow::Result;
use plonky2_field::extension::Extendable;
use super::*;
use crate::field::extension::Extendable;
use crate::hash::merkle_proofs::verify_merkle_proof_to_cap;
use crate::plonk::config::{GenericConfig, PoseidonGoldilocksConfig};

View File

@ -114,10 +114,11 @@ pub(crate) fn decompress_merkle_proofs<F: RichField, H: Hasher<F>>(
#[cfg(test)]
mod tests {
use plonky2_field::types::Sample;
use rand::{thread_rng, Rng};
use rand::rngs::OsRng;
use rand::Rng;
use super::*;
use crate::field::types::Sample;
use crate::hash::merkle_tree::MerkleTree;
use crate::plonk::config::{GenericConfig, PoseidonGoldilocksConfig};
@ -131,7 +132,7 @@ mod tests {
let vs = (0..1 << h).map(|_| vec![F::rand()]).collect::<Vec<_>>();
let mt = MerkleTree::<F, <C as GenericConfig<D>>::Hasher>::new(vs.clone(), cap_height);
let mut rng = thread_rng();
let mut rng = OsRng;
let k = rng.gen_range(1..=1 << h);
let indices = (0..k).map(|_| rng.gen_range(0..1 << h)).collect::<Vec<_>>();
let proofs = indices.iter().map(|&i| mt.prove(i)).collect::<Vec<_>>();

View File

@ -4,10 +4,10 @@
use alloc::vec;
use alloc::vec::Vec;
use plonky2_field::extension::{Extendable, FieldExtension};
use plonky2_field::types::{Field, PrimeField64};
use unroll::unroll_for_loops;
use crate::field::extension::{Extendable, FieldExtension};
use crate::field::types::{Field, PrimeField64};
use crate::gates::gate::Gate;
use crate::gates::poseidon::PoseidonGate;
use crate::gates::poseidon_mds::PoseidonMdsGate;
@ -687,8 +687,7 @@ impl<F: RichField> AlgebraicHasher<F> for PoseidonHash {
#[cfg(test)]
pub(crate) mod test_helpers {
use plonky2_field::types::Field;
use crate::field::types::Field;
use crate::hash::hashing::SPONGE_WIDTH;
use crate::hash::poseidon::Poseidon;

View File

@ -4,8 +4,7 @@
//! `poseidon_constants.sage` script in the `mir-protocol/hash-constants`
//! repository.
use plonky2_field::goldilocks_field::GoldilocksField;
use crate::field::goldilocks_field::GoldilocksField;
use crate::hash::poseidon::{Poseidon, N_PARTIAL_ROUNDS};
#[rustfmt::skip]
@ -271,9 +270,8 @@ impl Poseidon for GoldilocksField {
#[cfg(test)]
mod tests {
use plonky2_field::goldilocks_field::GoldilocksField as F;
use plonky2_field::types::{Field, PrimeField64};
use crate::field::goldilocks_field::GoldilocksField as F;
use crate::field::types::{Field, PrimeField64};
use crate::hash::poseidon::test_helpers::{check_consistency, check_test_vectors};
#[test]

View File

@ -2,8 +2,7 @@ use alloc::vec;
use alloc::vec::Vec;
use core::marker::PhantomData;
use plonky2_field::extension::{Extendable, FieldExtension};
use crate::field::extension::{Extendable, FieldExtension};
use crate::hash::hash_types::{HashOut, HashOutTarget, MerkleCapTarget, RichField};
use crate::hash::hashing::{PlonkyPermutation, SPONGE_RATE, SPONGE_WIDTH};
use crate::hash::merkle_tree::MerkleCap;
@ -301,8 +300,7 @@ impl<F: RichField + Extendable<D>, H: AlgebraicHasher<F>, const D: usize>
#[cfg(test)]
mod tests {
use plonky2_field::types::Sample;
use crate::field::types::Sample;
use crate::iop::challenger::{Challenger, RecursiveChallenger};
use crate::iop::generator::generate_partial_witness;
use crate::iop::target::Target;

View File

@ -1,10 +1,9 @@
use alloc::vec::Vec;
use core::ops::Range;
use plonky2_field::extension::algebra::ExtensionAlgebra;
use plonky2_field::extension::{Extendable, FieldExtension, OEF};
use plonky2_field::types::Field;
use crate::field::extension::algebra::ExtensionAlgebra;
use crate::field::extension::{Extendable, FieldExtension, OEF};
use crate::field::types::Field;
use crate::hash::hash_types::RichField;
use crate::iop::target::Target;
use crate::plonk::circuit_builder::CircuitBuilder;

View File

@ -3,9 +3,8 @@ use alloc::vec::Vec;
use core::fmt::Debug;
use core::marker::PhantomData;
use plonky2_field::extension::{Extendable, FieldExtension};
use plonky2_field::types::Field;
use crate::field::extension::{Extendable, FieldExtension};
use crate::field::types::Field;
use crate::hash::hash_types::{HashOut, HashOutTarget, RichField};
use crate::iop::ext_target::ExtensionTarget;
use crate::iop::target::{BoolTarget, Target};

View File

@ -3,9 +3,9 @@ use alloc::vec::Vec;
use hashbrown::HashMap;
use itertools::Itertools;
use plonky2_field::extension::{Extendable, FieldExtension};
use plonky2_field::types::Field;
use crate::field::extension::{Extendable, FieldExtension};
use crate::field::types::Field;
use crate::fri::structure::{FriOpenings, FriOpeningsTarget};
use crate::fri::witness_util::set_fri_proof_target;
use crate::hash::hash_types::{HashOut, HashOutTarget, MerkleCapTarget, RichField};

View File

@ -4,6 +4,7 @@
extern crate alloc;
#[doc(inline)]
pub use plonky2_field as field;
pub mod fri;

View File

@ -9,13 +9,12 @@ use std::time::Instant;
use hashbrown::{HashMap, HashSet};
use itertools::Itertools;
use log::{debug, info, Level};
use plonky2_field::cosets::get_unique_coset_shifts;
use plonky2_field::extension::{Extendable, FieldExtension};
use plonky2_field::fft::fft_root_table;
use plonky2_field::polynomial::PolynomialValues;
use plonky2_field::types::Field;
use plonky2_util::{log2_ceil, log2_strict};
use crate::field::cosets::get_unique_coset_shifts;
use crate::field::extension::{Extendable, FieldExtension};
use crate::field::fft::fft_root_table;
use crate::field::polynomial::PolynomialValues;
use crate::field::types::Field;
use crate::fri::oracle::PolynomialBatch;
use crate::fri::{FriConfig, FriParams};
use crate::gadgets::arithmetic::BaseArithmeticOperation;
@ -49,7 +48,7 @@ use crate::timed;
use crate::util::context_tree::ContextTree;
use crate::util::partial_products::num_partial_products;
use crate::util::timing::TimingTree;
use crate::util::{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 config: CircuitConfig,

View File

@ -5,9 +5,9 @@ use alloc::vec::Vec;
use core::ops::{Range, RangeFrom};
use anyhow::Result;
use plonky2_field::extension::Extendable;
use plonky2_field::fft::FftRootTable;
use crate::field::extension::Extendable;
use crate::field::fft::FftRootTable;
use crate::field::types::Field;
use crate::fri::oracle::PolynomialBatch;
use crate::fri::reduction_strategies::FriReductionStrategy;

View File

@ -2,12 +2,12 @@ use alloc::vec;
use alloc::vec::Vec;
use core::fmt::Debug;
use plonky2_field::extension::quadratic::QuadraticExtension;
use plonky2_field::extension::{Extendable, FieldExtension};
use plonky2_field::goldilocks_field::GoldilocksField;
use serde::de::DeserializeOwned;
use serde::Serialize;
use crate::field::extension::quadratic::QuadraticExtension;
use crate::field::extension::{Extendable, FieldExtension};
use crate::field::goldilocks_field::GoldilocksField;
use crate::hash::hash_types::{HashOut, RichField};
use crate::hash::hashing::{PlonkyPermutation, SPONGE_WIDTH};
use crate::hash::keccak::KeccakHash;

View File

@ -2,9 +2,9 @@ use alloc::vec;
use alloc::vec::Vec;
use hashbrown::HashSet;
use plonky2_field::extension::Extendable;
use plonky2_field::polynomial::PolynomialCoeffs;
use crate::field::extension::Extendable;
use crate::field::polynomial::PolynomialCoeffs;
use crate::fri::proof::{CompressedFriProof, FriChallenges, FriProof, FriProofTarget};
use crate::fri::verifier::{compute_evaluation, fri_combine_initial, PrecomputedReducedOpenings};
use crate::gadgets::polynomial::PolynomialCoeffsExtTarget;

View File

@ -2,9 +2,9 @@ use alloc::vec::Vec;
use hashbrown::HashMap;
use maybe_rayon::*;
use plonky2_field::polynomial::PolynomialValues;
use plonky2_field::types::Field;
use crate::field::polynomial::PolynomialValues;
use crate::field::types::Field;
use crate::iop::target::Target;
use crate::iop::wire::Wire;

View File

@ -1,10 +1,9 @@
use alloc::vec;
use alloc::vec::Vec;
use plonky2_field::extension::Extendable;
use plonky2_field::packed::PackedField;
use plonky2_field::types::Field;
use crate::field::extension::Extendable;
use crate::field::packed::PackedField;
use crate::field::types::Field;
use crate::fri::oracle::SALT_SIZE;
use crate::gates::arithmetic_base::ArithmeticGate;
use crate::hash::hash_types::RichField;

View File

@ -3,9 +3,9 @@ use alloc::vec::Vec;
use anyhow::ensure;
use maybe_rayon::*;
use plonky2_field::extension::Extendable;
use serde::{Deserialize, Serialize};
use crate::field::extension::Extendable;
use crate::fri::oracle::PolynomialBatch;
use crate::fri::proof::{
CompressedFriProof, FriChallenges, FriChallengesTarget, FriProof, FriProofTarget,
@ -383,8 +383,8 @@ impl<const D: usize> OpeningSetTarget<D> {
#[cfg(test)]
mod tests {
use anyhow::Result;
use plonky2_field::types::Sample;
use crate::field::types::Sample;
use crate::fri::reduction_strategies::FriReductionStrategy;
use crate::gates::noop::NoopGate;
use crate::iop::witness::PartialWitness;

View File

@ -4,12 +4,11 @@ use core::mem::swap;
use anyhow::{ensure, Result};
use maybe_rayon::*;
use plonky2_field::extension::Extendable;
use plonky2_field::polynomial::{PolynomialCoeffs, PolynomialValues};
use plonky2_field::zero_poly_coset::ZeroPolyOnCoset;
use plonky2_util::{ceil_div_usize, log2_ceil};
use crate::field::extension::Extendable;
use crate::field::polynomial::{PolynomialCoeffs, PolynomialValues};
use crate::field::types::Field;
use crate::field::zero_poly_coset::ZeroPolyOnCoset;
use crate::fri::oracle::PolynomialBatch;
use crate::hash::hash_types::RichField;
use crate::iop::challenger::Challenger;
@ -24,7 +23,7 @@ use crate::plonk::vars::EvaluationVarsBaseBatch;
use crate::timed;
use crate::util::partial_products::{partial_products_and_z_gx, quotient_chunk_products};
use crate::util::timing::TimingTree;
use crate::util::transpose;
use crate::util::{ceil_div_usize, log2_ceil, transpose};
pub fn prove<F: RichField + Extendable<D>, C: GenericConfig<D, F = F>, const D: usize>(
prover_data: &ProverOnlyCircuitData<F, C, D>,

View File

@ -1,6 +1,6 @@
use anyhow::ensure;
use plonky2_field::extension::Extendable;
use crate::field::extension::Extendable;
use crate::hash::hash_types::RichField;
use crate::plonk::circuit_data::CommonCircuitData;
use crate::plonk::config::GenericConfig;

View File

@ -1,11 +1,10 @@
use alloc::vec::Vec;
use alloc::{format, vec};
use plonky2_field::batch_util::batch_add_inplace;
use plonky2_field::extension::{Extendable, FieldExtension};
use plonky2_field::types::Field;
use plonky2_field::zero_poly_coset::ZeroPolyOnCoset;
use crate::field::batch_util::batch_add_inplace;
use crate::field::extension::{Extendable, FieldExtension};
use crate::field::types::Field;
use crate::field::zero_poly_coset::ZeroPolyOnCoset;
use crate::hash::hash_types::RichField;
use crate::iop::ext_target::ExtensionTarget;
use crate::iop::target::Target;

View File

@ -1,10 +1,9 @@
use core::ops::Range;
use plonky2_field::extension::algebra::ExtensionAlgebra;
use plonky2_field::extension::{Extendable, FieldExtension};
use plonky2_field::packed::PackedField;
use plonky2_field::types::Field;
use crate::field::extension::algebra::ExtensionAlgebra;
use crate::field::extension::{Extendable, FieldExtension};
use crate::field::packed::PackedField;
use crate::field::types::Field;
use crate::hash::hash_types::{HashOut, HashOutTarget, RichField};
use crate::iop::ext_target::{ExtensionAlgebraTarget, ExtensionTarget};
use crate::util::strided_view::PackedStridedView;

View File

@ -1,7 +1,7 @@
use anyhow::{ensure, Result};
use plonky2_field::extension::Extendable;
use plonky2_field::types::Field;
use crate::field::extension::Extendable;
use crate::field::types::Field;
use crate::fri::verifier::verify_fri_proof;
use crate::hash::hash_types::RichField;
use crate::plonk::circuit_data::{CommonCircuitData, VerifierOnlyCircuitData};

View File

@ -3,9 +3,8 @@ use alloc::vec::Vec;
use anyhow::{ensure, Result};
use itertools::Itertools;
use plonky2_field::extension::Extendable;
use plonky2_util::ceil_div_usize;
use crate::field::extension::Extendable;
use crate::fri::proof::{
FriInitialTreeProofTarget, FriProofTarget, FriQueryRoundTarget, FriQueryStepTarget,
};
@ -24,6 +23,7 @@ use crate::plonk::config::{AlgebraicHasher, GenericConfig};
use crate::plonk::proof::{
OpeningSetTarget, ProofTarget, ProofWithPublicInputs, ProofWithPublicInputsTarget,
};
use crate::util::ceil_div_usize;
use crate::with_context;
/// Generate a proof having a given `CommonCircuitData`.
@ -369,9 +369,9 @@ impl<F: RichField + Extendable<D>, const D: usize> CircuitBuilder<F, D> {
#[cfg(test)]
mod tests {
use anyhow::Result;
use plonky2_field::types::Sample;
use super::*;
use crate::field::types::Sample;
use crate::gates::noop::NoopGate;
use crate::iop::witness::{PartialWitness, Witness};
use crate::plonk::circuit_data::CircuitConfig;

View File

@ -4,8 +4,8 @@ use alloc::vec;
use anyhow::{ensure, Result};
use itertools::Itertools;
use plonky2_field::extension::Extendable;
use crate::field::extension::Extendable;
use crate::gates::noop::NoopGate;
use crate::hash::hash_types::{HashOut, HashOutTarget, MerkleCapTarget, RichField};
use crate::hash::merkle_tree::MerkleCap;
@ -254,12 +254,10 @@ where
#[cfg(test)]
mod tests {
use anyhow::Result;
use plonky2_field::extension::Extendable;
use plonky2_field::types::PrimeField64;
use crate::field::types::Field;
use crate::field::extension::Extendable;
use crate::field::types::{Field, PrimeField64};
use crate::gates::noop::NoopGate;
use crate::hash::hash_types::RichField;
use crate::hash::hashing::hash_n_to_hash_no_pad;

View File

@ -1,5 +1,4 @@
use plonky2_field::extension::Extendable;
use crate::field::extension::Extendable;
use crate::hash::hash_types::{HashOutTarget, RichField};
use crate::plonk::circuit_builder::CircuitBuilder;
use crate::plonk::circuit_data::{CommonCircuitData, VerifierCircuitTarget};

View File

@ -1,8 +1,11 @@
use alloc::vec;
use alloc::vec::Vec;
use plonky2_field::polynomial::PolynomialValues;
use plonky2_field::types::Field;
#[doc(inline)]
pub use plonky2_util::*;
use crate::field::polynomial::PolynomialValues;
use crate::field::types::Field;
pub(crate) mod context_tree;
pub(crate) mod partial_products;
@ -61,9 +64,7 @@ pub(crate) fn reverse_bits(n: usize, num_bits: usize) -> usize {
#[cfg(test)]
mod tests {
use plonky2_util::{reverse_index_bits, reverse_index_bits_in_place};
use crate::util::reverse_bits;
use super::*;
#[test]
fn test_reverse_bits() {

View File

@ -2,13 +2,13 @@ use alloc::vec::Vec;
use core::iter;
use itertools::Itertools;
use plonky2_field::extension::Extendable;
use plonky2_field::types::Field;
use plonky2_util::ceil_div_usize;
use crate::field::extension::Extendable;
use crate::field::types::Field;
use crate::hash::hash_types::RichField;
use crate::iop::ext_target::ExtensionTarget;
use crate::plonk::circuit_builder::CircuitBuilder;
use crate::util::ceil_div_usize;
pub(crate) fn quotient_chunk_products<F: Field>(
quotient_values: &[F],
@ -108,9 +108,8 @@ pub(crate) fn check_partial_products_circuit<F: RichField + Extendable<D>, const
#[cfg(test)]
mod tests {
use plonky2_field::goldilocks_field::GoldilocksField;
use super::*;
use crate::field::goldilocks_field::GoldilocksField;
#[test]
fn test_partial_products() {

View File

@ -2,11 +2,10 @@ use alloc::vec;
use alloc::vec::Vec;
use core::borrow::Borrow;
use plonky2_field::extension::{Extendable, FieldExtension};
use plonky2_field::packed::PackedField;
use plonky2_field::polynomial::PolynomialCoeffs;
use plonky2_field::types::Field;
use crate::field::extension::{Extendable, FieldExtension};
use crate::field::packed::PackedField;
use crate::field::polynomial::PolynomialCoeffs;
use crate::field::types::Field;
use crate::gates::arithmetic_extension::ArithmeticExtensionGate;
use crate::gates::reducing::ReducingGate;
use crate::gates::reducing_extension::ReducingExtensionGate;
@ -276,9 +275,9 @@ impl<const D: usize> ReducingFactorTarget<D> {
#[cfg(test)]
mod tests {
use anyhow::Result;
use plonky2_field::types::Sample;
use super::*;
use crate::field::types::Sample;
use crate::iop::witness::{PartialWitness, Witness};
use crate::plonk::circuit_data::CircuitConfig;
use crate::plonk::config::{GenericConfig, PoseidonGoldilocksConfig};

View File

@ -5,10 +5,10 @@ use core::convert::Infallible;
use std::io::{self, Cursor, Read as _, Write as _};
use hashbrown::HashMap;
use plonky2_field::extension::{Extendable, FieldExtension};
use plonky2_field::polynomial::PolynomialCoeffs;
use plonky2_field::types::{Field64, PrimeField64};
use crate::field::extension::{Extendable, FieldExtension};
use crate::field::polynomial::PolynomialCoeffs;
use crate::field::types::{Field64, PrimeField64};
use crate::fri::proof::{
CompressedFriProof, CompressedFriQueryRounds, FriInitialTreeProof, FriProof, FriQueryRound,
FriQueryStep,

View File

@ -2,7 +2,7 @@ use core::marker::PhantomData;
use core::mem::size_of;
use core::ops::{Index, Range, RangeFrom, RangeFull, RangeInclusive, RangeTo, RangeToInclusive};
use plonky2_field::packed::PackedField;
use crate::field::packed::PackedField;
/// Imagine a slice, but with a stride (a la a NumPy array).
///

View File

@ -3,13 +3,13 @@ name = "plonky2_u32"
version = "0.1.0"
edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
anyhow = "1.0.40"
rand = "0.8.4"
num = { version = "0.4", features = [ "rand" ] }
itertools = "0.10.0"
plonky2 = { path = "../plonky2" }
plonky2_util = { path = "../util" }
plonky2_field = { path = "../field" }
anyhow = { version = "1.0.40", default-features = false }
itertools = { version = "0.10.0", default-features = false }
num = { version = "0.4", default-features = false }
plonky2 = { path = "../plonky2", default-features = false }
[dev-dependencies]
plonky2 = { path = "../plonky2", default-features = false, features = ["gate_testing"] }
rand = { version = "0.8.4", default-features = false, features = ["getrandom"] }

View File

@ -1,11 +1,13 @@
use std::marker::PhantomData;
use alloc::vec;
use alloc::vec::Vec;
use core::marker::PhantomData;
use plonky2::field::extension::Extendable;
use plonky2::hash::hash_types::RichField;
use plonky2::iop::generator::{GeneratedValues, SimpleGenerator};
use plonky2::iop::target::Target;
use plonky2::iop::witness::{PartitionWitness, Witness};
use plonky2::plonk::circuit_builder::CircuitBuilder;
use plonky2_field::extension::Extendable;
use crate::gates::add_many_u32::U32AddManyGate;
use crate::gates::arithmetic_u32::U32ArithmeticGate;
@ -258,12 +260,12 @@ impl<F: RichField + Extendable<D>, const D: usize> SimpleGenerator<F>
mod tests {
use anyhow::Result;
use plonky2::iop::witness::PartialWitness;
use plonky2::plonk::circuit_builder::CircuitBuilder;
use plonky2::plonk::circuit_data::CircuitConfig;
use plonky2::plonk::config::{GenericConfig, PoseidonGoldilocksConfig};
use rand::{thread_rng, Rng};
use rand::rngs::OsRng;
use rand::Rng;
use crate::gadgets::arithmetic_u32::CircuitBuilderU32;
use super::*;
#[test]
pub fn test_add_many_u32s() -> Result<()> {
@ -278,7 +280,7 @@ mod tests {
let pw = PartialWitness::new();
let mut builder = CircuitBuilder::<F, D>::new(config);
let mut rng = thread_rng();
let mut rng = OsRng;
let mut to_add = Vec::new();
let mut sum = 0u64;
for _ in 0..NUM_ADDENDS {

View File

@ -1,10 +1,13 @@
use alloc::vec;
use alloc::vec::Vec;
use plonky2::field::extension::Extendable;
use plonky2::hash::hash_types::RichField;
use plonky2::iop::target::{BoolTarget, Target};
use plonky2::plonk::circuit_builder::CircuitBuilder;
use plonky2_field::extension::Extendable;
use plonky2_util::ceil_div_usize;
use plonky2::util::ceil_div_usize;
use super::arithmetic_u32::U32Target;
use crate::gadgets::arithmetic_u32::U32Target;
use crate::gates::comparison::ComparisonGate;
/// Returns true if a is less than or equal to b, considered as base-`2^num_bits` limbs of a large value.
@ -78,14 +81,14 @@ pub fn list_le_u32_circuit<F: RichField + Extendable<D>, const D: usize>(
mod tests {
use anyhow::Result;
use num::BigUint;
use plonky2::field::types::Field;
use plonky2::iop::witness::PartialWitness;
use plonky2::plonk::circuit_builder::CircuitBuilder;
use plonky2::plonk::circuit_data::CircuitConfig;
use plonky2::plonk::config::{GenericConfig, PoseidonGoldilocksConfig};
use plonky2_field::types::Field;
use rand::rngs::OsRng;
use rand::Rng;
use crate::gadgets::multiple_comparison::list_le_circuit;
use super::*;
fn test_list_le(size: usize, num_bits: usize) -> Result<()> {
const D: usize = 2;
@ -95,7 +98,7 @@ mod tests {
let pw = PartialWitness::new();
let mut builder = CircuitBuilder::<F, D>::new(config);
let mut rng = rand::thread_rng();
let mut rng = OsRng;
let lst1: Vec<u64> = (0..size)
.map(|_| rng.gen_range(0..(1 << num_bits)))

View File

@ -1,7 +1,10 @@
use alloc::vec;
use alloc::vec::Vec;
use plonky2::field::extension::Extendable;
use plonky2::hash::hash_types::RichField;
use plonky2::iop::target::Target;
use plonky2::plonk::circuit_builder::CircuitBuilder;
use plonky2_field::extension::Extendable;
use crate::gadgets::arithmetic_u32::U32Target;
use crate::gates::range_check_u32::U32RangeCheckGate;

View File

@ -1,6 +1,12 @@
use std::marker::PhantomData;
use alloc::boxed::Box;
use alloc::format;
use alloc::string::String;
use alloc::vec::Vec;
use core::marker::PhantomData;
use itertools::unfold;
use plonky2::field::extension::Extendable;
use plonky2::field::types::Field;
use plonky2::gates::gate::Gate;
use plonky2::gates::util::StridedConstraintConsumer;
use plonky2::hash::hash_types::RichField;
@ -12,9 +18,7 @@ use plonky2::iop::witness::{PartitionWitness, Witness};
use plonky2::plonk::circuit_builder::CircuitBuilder;
use plonky2::plonk::circuit_data::CircuitConfig;
use plonky2::plonk::vars::{EvaluationTargets, EvaluationVars, EvaluationVarsBase};
use plonky2_field::extension::Extendable;
use plonky2_field::types::Field;
use plonky2_util::ceil_div_usize;
use plonky2::util::ceil_div_usize;
const LOG2_MAX_NUM_ADDENDS: usize = 4;
const MAX_NUM_ADDENDS: usize = 16;
@ -340,21 +344,17 @@ impl<F: RichField + Extendable<D>, const D: usize> SimpleGenerator<F>
#[cfg(test)]
mod tests {
use core::marker::PhantomData;
use anyhow::Result;
use itertools::unfold;
use plonky2::gates::gate::Gate;
use plonky2::field::extension::quartic::QuarticExtension;
use plonky2::field::goldilocks_field::GoldilocksField;
use plonky2::field::types::Sample;
use plonky2::gates::gate_testing::{test_eval_fns, test_low_degree};
use plonky2::hash::hash_types::HashOut;
use plonky2::plonk::config::{GenericConfig, PoseidonGoldilocksConfig};
use plonky2::plonk::vars::EvaluationVars;
use plonky2_field::extension::quartic::QuarticExtension;
use plonky2_field::goldilocks_field::GoldilocksField;
use plonky2_field::types::{Field, Sample};
use rand::rngs::OsRng;
use rand::Rng;
use crate::gates::add_many_u32::U32AddManyGate;
use super::*;
#[test]
fn low_degree() {
@ -428,7 +428,7 @@ mod tests {
v0.iter().chain(v1.iter()).map(|&x| x.into()).collect()
}
let mut rng = rand::thread_rng();
let mut rng = OsRng;
let addends: Vec<Vec<_>> = (0..NUM_U32_ADD_MANY_OPS)
.map(|_| (0..NUM_ADDENDS).map(|_| rng.gen::<u32>() as u64).collect())
.collect();

View File

@ -1,6 +1,13 @@
use std::marker::PhantomData;
use alloc::boxed::Box;
use alloc::string::String;
use alloc::vec::Vec;
use alloc::{format, vec};
use core::marker::PhantomData;
use itertools::unfold;
use plonky2::field::extension::Extendable;
use plonky2::field::packed::PackedField;
use plonky2::field::types::Field;
use plonky2::gates::gate::Gate;
use plonky2::gates::packed_util::PackedEvaluableBase;
use plonky2::gates::util::StridedConstraintConsumer;
@ -16,9 +23,6 @@ use plonky2::plonk::vars::{
EvaluationTargets, EvaluationVars, EvaluationVarsBase, EvaluationVarsBaseBatch,
EvaluationVarsBasePacked,
};
use plonky2_field::extension::Extendable;
use plonky2_field::packed::PackedField;
use plonky2_field::types::Field;
/// A gate to perform a basic mul-add on 32-bit values (we assume they are range-checked beforehand).
#[derive(Copy, Clone, Debug)]
@ -411,20 +415,16 @@ impl<F: RichField + Extendable<D>, const D: usize> SimpleGenerator<F>
#[cfg(test)]
mod tests {
use core::marker::PhantomData;
use anyhow::Result;
use plonky2::gates::gate::Gate;
use plonky2::field::goldilocks_field::GoldilocksField;
use plonky2::field::types::Sample;
use plonky2::gates::gate_testing::{test_eval_fns, test_low_degree};
use plonky2::hash::hash_types::{HashOut, RichField};
use plonky2::hash::hash_types::HashOut;
use plonky2::plonk::config::{GenericConfig, PoseidonGoldilocksConfig};
use plonky2::plonk::vars::EvaluationVars;
use plonky2_field::extension::Extendable;
use plonky2_field::goldilocks_field::GoldilocksField;
use plonky2_field::types::{Field, Sample};
use rand::rngs::OsRng;
use rand::Rng;
use crate::gates::arithmetic_u32::U32ArithmeticGate;
use super::*;
#[test]
fn low_degree() {
@ -506,7 +506,7 @@ mod tests {
type FF = <C as GenericConfig<D>>::FE;
const NUM_U32_ARITHMETIC_OPS: usize = 3;
let mut rng = rand::thread_rng();
let mut rng = OsRng;
let multiplicands_0: Vec<_> = (0..NUM_U32_ARITHMETIC_OPS)
.map(|_| rng.gen::<u32>() as u64)
.collect();

Some files were not shown because too many files have changed in this diff Show More