diff --git a/ecdsa/Cargo.toml b/ecdsa/Cargo.toml index ce00f3dc..522856ef 100644 --- a/ecdsa/Cargo.toml +++ b/ecdsa/Cargo.toml @@ -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"] } + diff --git a/ecdsa/src/curve/curve_adds.rs b/ecdsa/src/curve/curve_adds.rs index 05d9d515..319c5614 100644 --- a/ecdsa/src/curve/curve_adds.rs +++ b/ecdsa/src/curve/curve_adds.rs @@ -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}; diff --git a/ecdsa/src/curve/curve_msm.rs b/ecdsa/src/curve/curve_msm.rs index 400c7ab6..bc04b6cc 100644 --- a/ecdsa/src/curve/curve_msm.rs +++ b/ecdsa/src/curve/curve_msm.rs @@ -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(x: &C::ScalarField, w: usize) -> Vec { #[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] diff --git a/ecdsa/src/curve/curve_multiplication.rs b/ecdsa/src/curve/curve_multiplication.rs index 25c603b5..1f9c653d 100644 --- a/ecdsa/src/curve/curve_multiplication.rs +++ b/ecdsa/src/curve/curve_multiplication.rs @@ -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}; diff --git a/ecdsa/src/curve/curve_summation.rs b/ecdsa/src/curve/curve_summation.rs index 492d7722..7bb633af 100644 --- a/ecdsa/src/curve/curve_summation.rs +++ b/ecdsa/src/curve/curve_summation.rs @@ -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( #[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] diff --git a/ecdsa/src/curve/curve_types.rs b/ecdsa/src/curve/curve_types.rs index 96821672..91047393 100644 --- a/ecdsa/src/curve/curve_types.rs +++ b/ecdsa/src/curve/curve_types.rs @@ -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 PartialEq for AffinePoint { impl Eq for AffinePoint {} impl Hash for AffinePoint { - fn hash(&self, state: &mut H) { + fn hash(&self, state: &mut H) { if self.zero { self.zero.hash(state); } else { diff --git a/ecdsa/src/curve/ecdsa.rs b/ecdsa/src/curve/ecdsa.rs index bbec08b5..131d8b4d 100644 --- a/ecdsa/src/curve/ecdsa.rs +++ b/ecdsa/src/curve/ecdsa.rs @@ -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( #[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; diff --git a/ecdsa/src/curve/glv.rs b/ecdsa/src/curve/glv.rs index 9cf9bc82..7c3e5de0 100644 --- a/ecdsa/src/curve/glv.rs +++ b/ecdsa/src/curve/glv.rs @@ -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, 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}; diff --git a/ecdsa/src/curve/secp256k1.rs b/ecdsa/src/curve/secp256k1.rs index b5ac8931..0b899a71 100644 --- a/ecdsa/src/curve/secp256k1.rs +++ b/ecdsa/src/curve/secp256k1.rs @@ -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; diff --git a/ecdsa/src/gadgets/biguint.rs b/ecdsa/src/gadgets/biguint.rs index ef958bd1..59e48d01 100644 --- a/ecdsa/src/gadgets/biguint.rs +++ b/ecdsa/src/gadgets/biguint.rs @@ -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 = >::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 = >::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 = >::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 = >::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 = >::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(); diff --git a/ecdsa/src/gadgets/curve.rs b/ecdsa/src/gadgets/curve.rs index 0d50ba7f..11075322 100644 --- a/ecdsa/src/gadgets/curve.rs +++ b/ecdsa/src/gadgets/curve.rs @@ -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, const D: usize> CircuitBuilderCurve #[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; diff --git a/ecdsa/src/gadgets/curve_fixed_base.rs b/ecdsa/src/gadgets/curve_fixed_base.rs index 0468fe01..e7656f5c 100644 --- a/ecdsa/src/gadgets/curve_fixed_base.rs +++ b/ecdsa/src/gadgets/curve_fixed_base.rs @@ -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, 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; diff --git a/ecdsa/src/gadgets/curve_msm.rs b/ecdsa/src/gadgets/curve_msm.rs index ba7c5a75..7bb4a6cc 100644 --- a/ecdsa/src/gadgets/curve_msm.rs +++ b/ecdsa/src/gadgets/curve_msm.rs @@ -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, 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; diff --git a/ecdsa/src/gadgets/curve_windowed_mul.rs b/ecdsa/src/gadgets/curve_windowed_mul.rs index dce7a0e2..39fad17c 100644 --- a/ecdsa/src/gadgets/curve_windowed_mul.rs +++ b/ecdsa/src/gadgets/curve_windowed_mul.rs @@ -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, const D: usize> CircuitBuilderWindowedMul Result<()> { @@ -206,7 +204,7 @@ mod tests { }) .collect(); - let mut rng = rand::thread_rng(); + let mut rng = OsRng; let access_index = rng.gen::() % num_points; let access_index_target = builder.constant(F::from_canonical_usize(access_index)); diff --git a/ecdsa/src/gadgets/ecdsa.rs b/ecdsa/src/gadgets/ecdsa.rs index fe2cc397..657ec492 100644 --- a/ecdsa/src/gadgets/ecdsa.rs +++ b/ecdsa/src/gadgets/ecdsa.rs @@ -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, 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; diff --git a/ecdsa/src/gadgets/glv.rs b/ecdsa/src/gadgets/glv.rs index 00cf64d7..063dee35 100644 --- a/ecdsa/src/gadgets/glv.rs +++ b/ecdsa/src/gadgets/glv.rs @@ -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, const D: usize> SimpleGenerator #[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; diff --git a/ecdsa/src/gadgets/nonnative.rs b/ecdsa/src/gadgets/nonnative.rs index ca865807..27dd1c65 100644 --- a/ecdsa/src/gadgets/nonnative.rs +++ b/ecdsa/src/gadgets/nonnative.rs @@ -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, 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; diff --git a/ecdsa/src/gadgets/split_nonnative.rs b/ecdsa/src/gadgets/split_nonnative.rs index 330c2ea1..977912e2 100644 --- a/ecdsa/src/gadgets/split_nonnative.rs +++ b/ecdsa/src/gadgets/split_nonnative.rs @@ -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, const D: usize> CircuitBuilderSplit #[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<()> { diff --git a/ecdsa/src/lib.rs b/ecdsa/src/lib.rs index 92bdb857..bf84913a 100644 --- a/ecdsa/src/lib.rs +++ b/ecdsa/src/lib.rs @@ -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; diff --git a/plonky2/Cargo.toml b/plonky2/Cargo.toml index a9ad3de2..82b82091 100644 --- a/plonky2/Cargo.toml +++ b/plonky2/Cargo.toml @@ -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" diff --git a/plonky2/src/bin/generate_constants.rs b/plonky2/src/bin/generate_constants.rs index c5f8fae2..608df815 100644 --- a/plonky2/src/bin/generate_constants.rs +++ b/plonky2/src/bin/generate_constants.rs @@ -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; diff --git a/plonky2/src/fri/challenges.rs b/plonky2/src/fri/challenges.rs index 3a750dd6..00deda07 100644 --- a/plonky2/src/fri/challenges.rs +++ b/plonky2/src/fri/challenges.rs @@ -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; diff --git a/plonky2/src/fri/oracle.rs b/plonky2/src/fri/oracle.rs index b670944d..cc114d98 100644 --- a/plonky2/src/fri/oracle.rs +++ b/plonky2/src/fri/oracle.rs @@ -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; diff --git a/plonky2/src/fri/proof.rs b/plonky2/src/fri/proof.rs index c3d3ecbb..4c5f65d8 100644 --- a/plonky2/src/fri/proof.rs +++ b/plonky2/src/fri/proof.rs @@ -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}; diff --git a/plonky2/src/fri/prover.rs b/plonky2/src/fri/prover.rs index adbf5e29..f3c8b28e 100644 --- a/plonky2/src/fri/prover.rs +++ b/plonky2/src/fri/prover.rs @@ -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. diff --git a/plonky2/src/fri/recursive_verifier.rs b/plonky2/src/fri/recursive_verifier.rs index a5b50041..822dd559 100644 --- a/plonky2/src/fri/recursive_verifier.rs +++ b/plonky2/src/fri/recursive_verifier.rs @@ -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, const D: usize> CircuitBuilder { diff --git a/plonky2/src/fri/reduction_strategies.rs b/plonky2/src/fri/reduction_strategies.rs index 7035100d..409a0224 100644 --- a/plonky2/src/fri/reduction_strategies.rs +++ b/plonky2/src/fri/reduction_strategies.rs @@ -35,7 +35,6 @@ impl FriReductionStrategy { ) -> Vec { 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) } diff --git a/plonky2/src/fri/validate_shape.rs b/plonky2/src/fri/validate_shape.rs index 0ef85c4c..526da8f7 100644 --- a/plonky2/src/fri/validate_shape.rs +++ b/plonky2/src/fri/validate_shape.rs @@ -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; diff --git a/plonky2/src/fri/verifier.rs b/plonky2/src/fri/verifier.rs index 7060ce95..6644b971 100644 --- a/plonky2/src/fri/verifier.rs +++ b/plonky2/src/fri/verifier.rs @@ -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. diff --git a/plonky2/src/fri/witness_util.rs b/plonky2/src/fri/witness_util.rs index ddf3c401..670319de 100644 --- a/plonky2/src/fri/witness_util.rs +++ b/plonky2/src/fri/witness_util.rs @@ -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; diff --git a/plonky2/src/gadgets/arithmetic.rs b/plonky2/src/gadgets/arithmetic.rs index c18ea034..3e42fa11 100644 --- a/plonky2/src/gadgets/arithmetic.rs +++ b/plonky2/src/gadgets/arithmetic.rs @@ -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; diff --git a/plonky2/src/gadgets/arithmetic_extension.rs b/plonky2/src/gadgets/arithmetic_extension.rs index 6232d7cb..e37d4deb 100644 --- a/plonky2/src/gadgets/arithmetic_extension.rs +++ b/plonky2/src/gadgets/arithmetic_extension.rs @@ -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, const D: usize> CircuitBuilder { pub fn arithmetic_extension( @@ -570,9 +569,9 @@ pub(crate) struct ExtensionArithmeticOperation, 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; diff --git a/plonky2/src/gadgets/hash.rs b/plonky2/src/gadgets/hash.rs index ec235340..2b8bfac5 100644 --- a/plonky2/src/gadgets/hash.rs +++ b/plonky2/src/gadgets/hash.rs @@ -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}; diff --git a/plonky2/src/gadgets/polynomial.rs b/plonky2/src/gadgets/polynomial.rs index bf5c2207..f7a59192 100644 --- a/plonky2/src/gadgets/polynomial.rs +++ b/plonky2/src/gadgets/polynomial.rs @@ -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; diff --git a/plonky2/src/gadgets/random_access.rs b/plonky2/src/gadgets/random_access.rs index a3febec7..d3a3ff1b 100644 --- a/plonky2/src/gadgets/random_access.rs +++ b/plonky2/src/gadgets/random_access.rs @@ -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, const D: usize> CircuitBuilder { /// Checks that a `Target` matches a vector at a non-deterministic index. @@ -57,9 +56,9 @@ impl, const D: usize> CircuitBuilder { #[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}; diff --git a/plonky2/src/gadgets/range_check.rs b/plonky2/src/gadgets/range_check.rs index fd22c17d..22977bc1 100644 --- a/plonky2/src/gadgets/range_check.rs +++ b/plonky2/src/gadgets/range_check.rs @@ -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}; diff --git a/plonky2/src/gadgets/select.rs b/plonky2/src/gadgets/select.rs index 03e18188..c2531488 100644 --- a/plonky2/src/gadgets/select.rs +++ b/plonky2/src/gadgets/select.rs @@ -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, const D: usize> CircuitBuilder { #[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; diff --git a/plonky2/src/gadgets/split_base.rs b/plonky2/src/gadgets/split_base.rs index 43e67cb8..3843cad3 100644 --- a/plonky2/src/gadgets/split_base.rs +++ b/plonky2/src/gadgets/split_base.rs @@ -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 SimpleGenerator for BaseSumGenerator { #[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::::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(); diff --git a/plonky2/src/gadgets/split_join.rs b/plonky2/src/gadgets/split_join.rs index ee4bd7ef..1a1575c0 100644 --- a/plonky2/src/gadgets/split_join.rs +++ b/plonky2/src/gadgets/split_join.rs @@ -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, const D: usize> CircuitBuilder { /// Split the given integer into a list of wires, where each one represents a diff --git a/plonky2/src/gates/arithmetic_base.rs b/plonky2/src/gates/arithmetic_base.rs index 69f2c179..34d6e244 100644 --- a/plonky2/src/gates/arithmetic_base.rs +++ b/plonky2/src/gates/arithmetic_base.rs @@ -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, const D: usize> SimpleGenerator #[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; diff --git a/plonky2/src/gates/arithmetic_extension.rs b/plonky2/src/gates/arithmetic_extension.rs index da686739..ee7f96be 100644 --- a/plonky2/src/gates/arithmetic_extension.rs +++ b/plonky2/src/gates/arithmetic_extension.rs @@ -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, const D: usize> SimpleGenerator #[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; diff --git a/plonky2/src/gates/base_sum.rs b/plonky2/src/gates/base_sum.rs index dd3542e1..27eb2c69 100644 --- a/plonky2/src/gates/base_sum.rs +++ b/plonky2/src/gates/base_sum.rs @@ -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 SimpleGenerator for BaseSplitGenerator #[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}; diff --git a/plonky2/src/gates/constant.rs b/plonky2/src/gates/constant.rs index dcb730af..bf365b04 100644 --- a/plonky2/src/gates/constant.rs +++ b/plonky2/src/gates/constant.rs @@ -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, const D: usize> PackedEvaluableBase 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; diff --git a/plonky2/src/gates/exponentiation.rs b/plonky2/src/gates/exponentiation.rs index f7c2bc60..138ec3c9 100644 --- a/plonky2/src/gates/exponentiation.rs +++ b/plonky2/src/gates/exponentiation.rs @@ -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, const D: usize> SimpleGenerator #[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::>() } - let mut rng = rand::thread_rng(); + let mut rng = OsRng; let base = F::TWO; let power = rng.gen::() % (1 << MAX_POWER_BITS); diff --git a/plonky2/src/gates/gate.rs b/plonky2/src/gates/gate.rs index 7b2db413..34950b76 100644 --- a/plonky2/src/gates/gate.rs +++ b/plonky2/src/gates/gate.rs @@ -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; diff --git a/plonky2/src/gates/gate_testing.rs b/plonky2/src/gates/gate_testing.rs index 0e87c262..c6cae2bb 100644 --- a/plonky2/src/gates/gate_testing.rs +++ b/plonky2/src/gates/gate_testing.rs @@ -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; diff --git a/plonky2/src/gates/high_degree_interpolation.rs b/plonky2/src/gates/high_degree_interpolation.rs index 110ea167..65573898 100644 --- a/plonky2/src/gates/high_degree_interpolation.rs +++ b/plonky2/src/gates/high_degree_interpolation.rs @@ -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, const D: usize> SimpleGenerator #[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() { diff --git a/plonky2/src/gates/interpolation.rs b/plonky2/src/gates/interpolation.rs index 7f4953d5..07179006 100644 --- a/plonky2/src/gates/interpolation.rs +++ b/plonky2/src/gates/interpolation.rs @@ -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, const D: usize> CircuitBuilder { #[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; diff --git a/plonky2/src/gates/low_degree_interpolation.rs b/plonky2/src/gates/low_degree_interpolation.rs index 77a84484..f4f3286c 100644 --- a/plonky2/src/gates/low_degree_interpolation.rs +++ b/plonky2/src/gates/low_degree_interpolation.rs @@ -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, const D: usize> SimpleGenerator #[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; diff --git a/plonky2/src/gates/multiplication_extension.rs b/plonky2/src/gates/multiplication_extension.rs index 5941f978..02243450 100644 --- a/plonky2/src/gates/multiplication_extension.rs +++ b/plonky2/src/gates/multiplication_extension.rs @@ -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, const D: usize> SimpleGenerator #[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] diff --git a/plonky2/src/gates/noop.rs b/plonky2/src/gates/noop.rs index a4d41a5c..f6f9853a 100644 --- a/plonky2/src/gates/noop.rs +++ b/plonky2/src/gates/noop.rs @@ -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, const D: usize> Gate 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}; diff --git a/plonky2/src/gates/packed_util.rs b/plonky2/src/gates/packed_util.rs index 62bc2d54..361eb3a2 100644 --- a/plonky2/src/gates/packed_util.rs +++ b/plonky2/src/gates/packed_util.rs @@ -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; diff --git a/plonky2/src/gates/poseidon.rs b/plonky2/src/gates/poseidon.rs index d491cce6..c644ada5 100644 --- a/plonky2/src/gates/poseidon.rs +++ b/plonky2/src/gates/poseidon.rs @@ -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 + Poseidon, const D: usize> SimpleGenerator #[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; diff --git a/plonky2/src/gates/poseidon_mds.rs b/plonky2/src/gates/poseidon_mds.rs index 880a21ff..dd494328 100644 --- a/plonky2/src/gates/poseidon_mds.rs +++ b/plonky2/src/gates/poseidon_mds.rs @@ -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; diff --git a/plonky2/src/gates/public_input.rs b/plonky2/src/gates/public_input.rs index d2ab2568..10c42f00 100644 --- a/plonky2/src/gates/public_input.rs +++ b/plonky2/src/gates/public_input.rs @@ -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, const D: usize> PackedEvaluableBase 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}; diff --git a/plonky2/src/gates/random_access.rs b/plonky2/src/gates/random_access.rs index dbc3a947..52972cd3 100644 --- a/plonky2/src/gates/random_access.rs +++ b/plonky2/src/gates/random_access.rs @@ -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, const D: usize> SimpleGenerator #[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::>(); let access_indices = (0..num_copies) - .map(|_| thread_rng().gen_range(0..vec_size)) + .map(|_| OsRng.gen_range(0..vec_size)) .collect::>(); let gate = RandomAccessGate:: { bits, diff --git a/plonky2/src/gates/reducing.rs b/plonky2/src/gates/reducing.rs index 12880b28..64a1a986 100644 --- a/plonky2/src/gates/reducing.rs +++ b/plonky2/src/gates/reducing.rs @@ -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, const D: usize> SimpleGenerator 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}; diff --git a/plonky2/src/gates/reducing_extension.rs b/plonky2/src/gates/reducing_extension.rs index f952c0c8..27483e1f 100644 --- a/plonky2/src/gates/reducing_extension.rs +++ b/plonky2/src/gates/reducing_extension.rs @@ -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, const D: usize> SimpleGenerator 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}; diff --git a/plonky2/src/gates/selectors.rs b/plonky2/src/gates/selectors.rs index bfd13073..7c5c6f34 100644 --- a/plonky2/src/gates/selectors.rs +++ b/plonky2/src/gates/selectors.rs @@ -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; diff --git a/plonky2/src/gates/util.rs b/plonky2/src/gates/util.rs index cd6dc9e1..88d77471 100644 --- a/plonky2/src/gates/util.rs +++ b/plonky2/src/gates/util.rs @@ -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 diff --git a/plonky2/src/hash/arch/aarch64/poseidon_goldilocks_neon.rs b/plonky2/src/hash/arch/aarch64/poseidon_goldilocks_neon.rs index 5cf25dce..10d81f28 100644 --- a/plonky2/src/hash/arch/aarch64/poseidon_goldilocks_neon.rs +++ b/plonky2/src/hash/arch/aarch64/poseidon_goldilocks_neon.rs @@ -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 =========================================== diff --git a/plonky2/src/hash/arch/x86_64/poseidon_goldilocks_avx2_bmi2.rs b/plonky2/src/hash/arch/x86_64/poseidon_goldilocks_avx2_bmi2.rs index ae08f568..c7a65f90 100644 --- a/plonky2/src/hash/arch/x86_64/poseidon_goldilocks_avx2_bmi2.rs +++ b/plonky2/src/hash/arch/x86_64/poseidon_goldilocks_avx2_bmi2.rs @@ -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. diff --git a/plonky2/src/hash/hash_types.rs b/plonky2/src/hash/hash_types.rs index e7f29044..b95a2113 100644 --- a/plonky2/src/hash/hash_types.rs +++ b/plonky2/src/hash/hash_types.rs @@ -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; diff --git a/plonky2/src/hash/hashing.rs b/plonky2/src/hash/hashing.rs index ac115152..3e93447a 100644 --- a/plonky2/src/hash/hashing.rs +++ b/plonky2/src/hash/hashing.rs @@ -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; diff --git a/plonky2/src/hash/merkle_proofs.rs b/plonky2/src/hash/merkle_proofs.rs index 01a4a395..69d7299f 100644 --- a/plonky2/src/hash/merkle_proofs.rs +++ b/plonky2/src/hash/merkle_proofs.rs @@ -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, const D: usize> CircuitBuilder { #[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::(n, 7); let tree = MerkleTree::>::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 { diff --git a/plonky2/src/hash/merkle_tree.rs b/plonky2/src/hash/merkle_tree.rs index 6958bb9c..92f1dca0 100644 --- a/plonky2/src/hash/merkle_tree.rs +++ b/plonky2/src/hash/merkle_tree.rs @@ -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> MerkleTree { #[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}; diff --git a/plonky2/src/hash/path_compression.rs b/plonky2/src/hash/path_compression.rs index 7efe3a67..d4f7d5eb 100644 --- a/plonky2/src/hash/path_compression.rs +++ b/plonky2/src/hash/path_compression.rs @@ -114,10 +114,11 @@ pub(crate) fn decompress_merkle_proofs>( #[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::>(); let mt = MerkleTree::>::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::>(); let proofs = indices.iter().map(|&i| mt.prove(i)).collect::>(); diff --git a/plonky2/src/hash/poseidon.rs b/plonky2/src/hash/poseidon.rs index 6a30c2bd..e7436018 100644 --- a/plonky2/src/hash/poseidon.rs +++ b/plonky2/src/hash/poseidon.rs @@ -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 AlgebraicHasher 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; diff --git a/plonky2/src/hash/poseidon_goldilocks.rs b/plonky2/src/hash/poseidon_goldilocks.rs index 001c5900..b6e9bc74 100644 --- a/plonky2/src/hash/poseidon_goldilocks.rs +++ b/plonky2/src/hash/poseidon_goldilocks.rs @@ -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] diff --git a/plonky2/src/iop/challenger.rs b/plonky2/src/iop/challenger.rs index 7b666494..49b30559 100644 --- a/plonky2/src/iop/challenger.rs +++ b/plonky2/src/iop/challenger.rs @@ -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, H: AlgebraicHasher, 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; diff --git a/plonky2/src/iop/ext_target.rs b/plonky2/src/iop/ext_target.rs index 73effa8e..c9929b21 100644 --- a/plonky2/src/iop/ext_target.rs +++ b/plonky2/src/iop/ext_target.rs @@ -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; diff --git a/plonky2/src/iop/generator.rs b/plonky2/src/iop/generator.rs index 522cee18..86a4d923 100644 --- a/plonky2/src/iop/generator.rs +++ b/plonky2/src/iop/generator.rs @@ -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}; diff --git a/plonky2/src/iop/witness.rs b/plonky2/src/iop/witness.rs index a7cdf1f4..218008ac 100644 --- a/plonky2/src/iop/witness.rs +++ b/plonky2/src/iop/witness.rs @@ -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}; diff --git a/plonky2/src/lib.rs b/plonky2/src/lib.rs index 49bc8248..c357c27a 100644 --- a/plonky2/src/lib.rs +++ b/plonky2/src/lib.rs @@ -4,6 +4,7 @@ extern crate alloc; +#[doc(inline)] pub use plonky2_field as field; pub mod fri; diff --git a/plonky2/src/plonk/circuit_builder.rs b/plonky2/src/plonk/circuit_builder.rs index deb46442..f84378b8 100644 --- a/plonky2/src/plonk/circuit_builder.rs +++ b/plonky2/src/plonk/circuit_builder.rs @@ -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, const D: usize> { pub config: CircuitConfig, diff --git a/plonky2/src/plonk/circuit_data.rs b/plonky2/src/plonk/circuit_data.rs index 791160ad..df455a3a 100644 --- a/plonky2/src/plonk/circuit_data.rs +++ b/plonky2/src/plonk/circuit_data.rs @@ -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; diff --git a/plonky2/src/plonk/config.rs b/plonky2/src/plonk/config.rs index ac7399f7..36d29cff 100644 --- a/plonky2/src/plonk/config.rs +++ b/plonky2/src/plonk/config.rs @@ -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; diff --git a/plonky2/src/plonk/get_challenges.rs b/plonky2/src/plonk/get_challenges.rs index 4c4785f8..240d9047 100644 --- a/plonky2/src/plonk/get_challenges.rs +++ b/plonky2/src/plonk/get_challenges.rs @@ -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; diff --git a/plonky2/src/plonk/permutation_argument.rs b/plonky2/src/plonk/permutation_argument.rs index 2400516a..7052cabe 100644 --- a/plonky2/src/plonk/permutation_argument.rs +++ b/plonky2/src/plonk/permutation_argument.rs @@ -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; diff --git a/plonky2/src/plonk/plonk_common.rs b/plonky2/src/plonk/plonk_common.rs index fdd53035..53c75af1 100644 --- a/plonky2/src/plonk/plonk_common.rs +++ b/plonky2/src/plonk/plonk_common.rs @@ -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; diff --git a/plonky2/src/plonk/proof.rs b/plonky2/src/plonk/proof.rs index 065e2328..a5a66e26 100644 --- a/plonky2/src/plonk/proof.rs +++ b/plonky2/src/plonk/proof.rs @@ -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 OpeningSetTarget { #[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; diff --git a/plonky2/src/plonk/prover.rs b/plonky2/src/plonk/prover.rs index 35490d7f..d45fa573 100644 --- a/plonky2/src/plonk/prover.rs +++ b/plonky2/src/plonk/prover.rs @@ -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, C: GenericConfig, const D: usize>( prover_data: &ProverOnlyCircuitData, diff --git a/plonky2/src/plonk/validate_shape.rs b/plonky2/src/plonk/validate_shape.rs index 81f43332..0b4bf4a8 100644 --- a/plonky2/src/plonk/validate_shape.rs +++ b/plonky2/src/plonk/validate_shape.rs @@ -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; diff --git a/plonky2/src/plonk/vanishing_poly.rs b/plonky2/src/plonk/vanishing_poly.rs index f27eba48..30473650 100644 --- a/plonky2/src/plonk/vanishing_poly.rs +++ b/plonky2/src/plonk/vanishing_poly.rs @@ -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; diff --git a/plonky2/src/plonk/vars.rs b/plonky2/src/plonk/vars.rs index 722ebdf1..758018f5 100644 --- a/plonky2/src/plonk/vars.rs +++ b/plonky2/src/plonk/vars.rs @@ -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; diff --git a/plonky2/src/plonk/verifier.rs b/plonky2/src/plonk/verifier.rs index ba477264..893720c6 100644 --- a/plonky2/src/plonk/verifier.rs +++ b/plonky2/src/plonk/verifier.rs @@ -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}; diff --git a/plonky2/src/recursion/conditional_recursive_verifier.rs b/plonky2/src/recursion/conditional_recursive_verifier.rs index fdbff5a0..6cbce94a 100644 --- a/plonky2/src/recursion/conditional_recursive_verifier.rs +++ b/plonky2/src/recursion/conditional_recursive_verifier.rs @@ -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, const D: usize> CircuitBuilder { #[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; diff --git a/plonky2/src/recursion/cyclic_recursion.rs b/plonky2/src/recursion/cyclic_recursion.rs index ab569d27..efc336bc 100644 --- a/plonky2/src/recursion/cyclic_recursion.rs +++ b/plonky2/src/recursion/cyclic_recursion.rs @@ -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; diff --git a/plonky2/src/recursion/recursive_verifier.rs b/plonky2/src/recursion/recursive_verifier.rs index a42494f4..0854dad8 100644 --- a/plonky2/src/recursion/recursive_verifier.rs +++ b/plonky2/src/recursion/recursive_verifier.rs @@ -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}; diff --git a/plonky2/src/util/mod.rs b/plonky2/src/util/mod.rs index 2c61b399..19f3cb74 100644 --- a/plonky2/src/util/mod.rs +++ b/plonky2/src/util/mod.rs @@ -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() { diff --git a/plonky2/src/util/partial_products.rs b/plonky2/src/util/partial_products.rs index c1b2e979..ff2261b8 100644 --- a/plonky2/src/util/partial_products.rs +++ b/plonky2/src/util/partial_products.rs @@ -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( quotient_values: &[F], @@ -108,9 +108,8 @@ pub(crate) fn check_partial_products_circuit, const #[cfg(test)] mod tests { - use plonky2_field::goldilocks_field::GoldilocksField; - use super::*; + use crate::field::goldilocks_field::GoldilocksField; #[test] fn test_partial_products() { diff --git a/plonky2/src/util/reducing.rs b/plonky2/src/util/reducing.rs index b1a179b7..0bed0b84 100644 --- a/plonky2/src/util/reducing.rs +++ b/plonky2/src/util/reducing.rs @@ -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 ReducingFactorTarget { #[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}; diff --git a/plonky2/src/util/serialization.rs b/plonky2/src/util/serialization.rs index b5c7ef5c..1cdfc39c 100644 --- a/plonky2/src/util/serialization.rs +++ b/plonky2/src/util/serialization.rs @@ -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, diff --git a/plonky2/src/util/strided_view.rs b/plonky2/src/util/strided_view.rs index 43fd4894..c165da2c 100644 --- a/plonky2/src/util/strided_view.rs +++ b/plonky2/src/util/strided_view.rs @@ -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). /// diff --git a/u32/Cargo.toml b/u32/Cargo.toml index f0a1d349..af7676ed 100644 --- a/u32/Cargo.toml +++ b/u32/Cargo.toml @@ -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"] } + diff --git a/u32/src/gadgets/arithmetic_u32.rs b/u32/src/gadgets/arithmetic_u32.rs index 7475681c..65f5ac07 100644 --- a/u32/src/gadgets/arithmetic_u32.rs +++ b/u32/src/gadgets/arithmetic_u32.rs @@ -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, const D: usize> SimpleGenerator 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::::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 { diff --git a/u32/src/gadgets/multiple_comparison.rs b/u32/src/gadgets/multiple_comparison.rs index 09ad2eb5..8d82c296 100644 --- a/u32/src/gadgets/multiple_comparison.rs +++ b/u32/src/gadgets/multiple_comparison.rs @@ -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, 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::::new(config); - let mut rng = rand::thread_rng(); + let mut rng = OsRng; let lst1: Vec = (0..size) .map(|_| rng.gen_range(0..(1 << num_bits))) diff --git a/u32/src/gadgets/range_check.rs b/u32/src/gadgets/range_check.rs index fb6a9b1e..9e8cf2ad 100644 --- a/u32/src/gadgets/range_check.rs +++ b/u32/src/gadgets/range_check.rs @@ -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; diff --git a/u32/src/gates/add_many_u32.rs b/u32/src/gates/add_many_u32.rs index 8928b74d..a2bd2dac 100644 --- a/u32/src/gates/add_many_u32.rs +++ b/u32/src/gates/add_many_u32.rs @@ -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, const D: usize> SimpleGenerator #[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> = (0..NUM_U32_ADD_MANY_OPS) .map(|_| (0..NUM_ADDENDS).map(|_| rng.gen::() as u64).collect()) .collect(); diff --git a/u32/src/gates/arithmetic_u32.rs b/u32/src/gates/arithmetic_u32.rs index 8946f9de..3f249d29 100644 --- a/u32/src/gates/arithmetic_u32.rs +++ b/u32/src/gates/arithmetic_u32.rs @@ -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, const D: usize> SimpleGenerator #[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 = >::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::() as u64) .collect(); diff --git a/u32/src/gates/comparison.rs b/u32/src/gates/comparison.rs index b7dc74a8..6cb67106 100644 --- a/u32/src/gates/comparison.rs +++ b/u32/src/gates/comparison.rs @@ -1,5 +1,12 @@ -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 plonky2::field::extension::Extendable; +use plonky2::field::packed::PackedField; +use plonky2::field::types::{Field, Field64}; use plonky2::gates::gate::Gate; use plonky2::gates::packed_util::PackedEvaluableBase; use plonky2::gates::util::StridedConstraintConsumer; @@ -15,10 +22,7 @@ use plonky2::plonk::vars::{ EvaluationTargets, EvaluationVars, EvaluationVarsBase, EvaluationVarsBaseBatch, EvaluationVarsBasePacked, }; -use plonky2_field::extension::Extendable; -use plonky2_field::packed::PackedField; -use plonky2_field::types::{Field, Field64}; -use plonky2_util::{bits_u64, ceil_div_usize}; +use plonky2::util::{bits_u64, ceil_div_usize}; /// A gate for checking that one value is less than or equal to another. #[derive(Clone, Debug)] @@ -512,19 +516,16 @@ impl, const D: usize> SimpleGenerator #[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::{PrimeField64, 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::goldilocks_field::GoldilocksField; - use plonky2_field::types::{Field, PrimeField64, Sample}; + use rand::rngs::OsRng; use rand::Rng; - use crate::gates::comparison::ComparisonGate; + use super::*; #[test] fn wire_indices() { @@ -656,7 +657,7 @@ mod tests { v.iter().map(|&x| x.into()).collect() }; - let mut rng = rand::thread_rng(); + let mut rng = OsRng; let max: u64 = 1 << (num_bits - 1); let first_input_u64 = rng.gen_range(0..max); let second_input_u64 = { diff --git a/u32/src/gates/range_check_u32.rs b/u32/src/gates/range_check_u32.rs index ff99e492..6dd20d48 100644 --- a/u32/src/gates/range_check_u32.rs +++ b/u32/src/gates/range_check_u32.rs @@ -1,5 +1,11 @@ -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 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; @@ -10,9 +16,7 @@ use plonky2::iop::witness::{PartitionWitness, Witness}; use plonky2::plonk::circuit_builder::CircuitBuilder; use plonky2::plonk::plonk_common::{reduce_with_powers, reduce_with_powers_ext_circuit}; 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; /// A gate which can decompose a number into base B little-endian limbs. #[derive(Copy, Clone, Debug)] @@ -201,22 +205,18 @@ impl, const D: usize> SimpleGenerator #[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::{Field, 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 plonky2_util::ceil_div_usize; + use rand::rngs::OsRng; use rand::Rng; - use crate::gates::range_check_u32::U32RangeCheckGate; + use super::*; #[test] fn low_degree() { @@ -290,7 +290,7 @@ mod tests { #[test] fn test_gate_constraint_good() { - let mut rng = rand::thread_rng(); + let mut rng = OsRng; let input_limbs: Vec<_> = (0..8).map(|_| rng.gen::() as u64).collect(); test_gate_constraint(input_limbs); @@ -299,7 +299,7 @@ mod tests { #[test] #[should_panic] fn test_gate_constraint_bad() { - let mut rng = rand::thread_rng(); + let mut rng = OsRng; let input_limbs: Vec<_> = (0..8).map(|_| rng.gen()).collect(); test_gate_constraint(input_limbs); diff --git a/u32/src/gates/subtraction_u32.rs b/u32/src/gates/subtraction_u32.rs index 1657aec1..9a3b1db6 100644 --- a/u32/src/gates/subtraction_u32.rs +++ b/u32/src/gates/subtraction_u32.rs @@ -1,5 +1,12 @@ -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 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; @@ -15,9 +22,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 subtraction on 32-bit limbs: given `x`, `y`, and `borrow`, it returns /// the result `x - y - borrow` and, if this underflows, a new `borrow`. Inputs are not range-checked. @@ -329,20 +333,17 @@ impl, const D: usize> SimpleGenerator #[cfg(test)] mod tests { - use core::marker::PhantomData; - use anyhow::Result; - use plonky2::gates::gate::Gate; + use plonky2::field::extension::quartic::QuarticExtension; + use plonky2::field::goldilocks_field::GoldilocksField; + use plonky2::field::types::{PrimeField64, 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, PrimeField64, Sample}; + use rand::rngs::OsRng; use rand::Rng; - use crate::gates::subtraction_u32::U32SubtractionGate; + use super::*; #[test] fn low_degree() { @@ -414,7 +415,7 @@ mod tests { v0.iter().chain(v1.iter()).map(|&x| x.into()).collect() } - let mut rng = rand::thread_rng(); + let mut rng = OsRng; let inputs_x = (0..NUM_U32_SUBTRACTION_OPS) .map(|_| rng.gen::() as u64) .collect(); diff --git a/u32/src/lib.rs b/u32/src/lib.rs index 0957c7bc..2d8d07f3 100644 --- a/u32/src/lib.rs +++ b/u32/src/lib.rs @@ -1,4 +1,7 @@ #![allow(clippy::needless_range_loop)] +#![no_std] + +extern crate alloc; pub mod gadgets; pub mod gates; diff --git a/u32/src/witness.rs b/u32/src/witness.rs index ddc3432f..004fedc6 100644 --- a/u32/src/witness.rs +++ b/u32/src/witness.rs @@ -1,6 +1,6 @@ +use plonky2::field::types::{Field, PrimeField64}; use plonky2::iop::generator::GeneratedValues; use plonky2::iop::witness::Witness; -use plonky2_field::types::{Field, PrimeField64}; use crate::gadgets::arithmetic_u32::U32Target;