diff --git a/ecdsa/src/curve/curve_msm.rs b/ecdsa/src/curve/curve_msm.rs index f681deb2..400c7ab6 100644 --- a/ecdsa/src/curve/curve_msm.rs +++ b/ecdsa/src/curve/curve_msm.rs @@ -1,6 +1,5 @@ use itertools::Itertools; -use plonky2_field::types::Field; -use plonky2_field::types::PrimeField; +use plonky2_field::types::{Field, PrimeField}; use rayon::prelude::*; use crate::curve::curve_summation::affine_multisummation_best; @@ -188,8 +187,7 @@ pub(crate) fn to_digits(x: &C::ScalarField, w: usize) -> Vec { mod tests { use num::BigUint; use plonky2_field::secp256k1_scalar::Secp256K1Scalar; - use plonky2_field::types::Field; - use plonky2_field::types::PrimeField; + use plonky2_field::types::{Field, PrimeField}; use crate::curve::curve_msm::{msm_execute, msm_precompute, to_digits}; use crate::curve::curve_types::Curve; diff --git a/ecdsa/src/curve/curve_multiplication.rs b/ecdsa/src/curve/curve_multiplication.rs index 70e49df6..25c603b5 100644 --- a/ecdsa/src/curve/curve_multiplication.rs +++ b/ecdsa/src/curve/curve_multiplication.rs @@ -1,7 +1,6 @@ use std::ops::Mul; -use plonky2_field::types::Field; -use plonky2_field::types::PrimeField; +use plonky2_field::types::{Field, PrimeField}; use crate::curve::curve_types::{Curve, CurveScalar, ProjectivePoint}; diff --git a/ecdsa/src/curve/secp256k1.rs b/ecdsa/src/curve/secp256k1.rs index 8f7bccf3..b5ac8931 100644 --- a/ecdsa/src/curve/secp256k1.rs +++ b/ecdsa/src/curve/secp256k1.rs @@ -41,8 +41,7 @@ const SECP256K1_GENERATOR_Y: Secp256K1Base = Secp256K1Base([ mod tests { use num::BigUint; use plonky2_field::secp256k1_scalar::Secp256K1Scalar; - use plonky2_field::types::Field; - use plonky2_field::types::PrimeField; + 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 faae365c..ef958bd1 100644 --- a/ecdsa/src/gadgets/biguint.rs +++ b/ecdsa/src/gadgets/biguint.rs @@ -346,11 +346,10 @@ impl, const D: usize> SimpleGenerator mod tests { use anyhow::Result; use num::{BigUint, FromPrimitive, Integer}; + 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::{ - iop::witness::PartialWitness, - plonk::{circuit_builder::CircuitBuilder, circuit_data::CircuitConfig}, - }; use rand::Rng; use crate::gadgets::biguint::{CircuitBuilderBiguint, WitnessBigUint}; diff --git a/ecdsa/src/gadgets/curve_fixed_base.rs b/ecdsa/src/gadgets/curve_fixed_base.rs index 0fd8e841..31292ddb 100644 --- a/ecdsa/src/gadgets/curve_fixed_base.rs +++ b/ecdsa/src/gadgets/curve_fixed_base.rs @@ -71,8 +71,7 @@ mod tests { use plonky2::plonk::circuit_data::CircuitConfig; use plonky2::plonk::config::{GenericConfig, PoseidonGoldilocksConfig}; use plonky2_field::secp256k1_scalar::Secp256K1Scalar; - use plonky2_field::types::Field; - use plonky2_field::types::PrimeField; + use plonky2_field::types::{Field, PrimeField}; use crate::curve::curve_types::{Curve, CurveScalar}; use crate::curve::secp256k1::Secp256K1; diff --git a/ecdsa/src/gadgets/nonnative.rs b/ecdsa/src/gadgets/nonnative.rs index 29520bed..ad6315a1 100644 --- a/ecdsa/src/gadgets/nonnative.rs +++ b/ecdsa/src/gadgets/nonnative.rs @@ -6,8 +6,8 @@ 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::types::PrimeField; -use plonky2_field::{extension::Extendable, types::Field}; +use plonky2_field::extension::Extendable; +use plonky2_field::types::{Field, PrimeField}; use plonky2_u32::gadgets::arithmetic_u32::{CircuitBuilderU32, U32Target}; use plonky2_u32::gadgets::range_check::range_check_u32_circuit; use plonky2_u32::witness::GeneratedValuesU32; diff --git a/evm/src/arithmetic/arithmetic_stark.rs b/evm/src/arithmetic/arithmetic_stark.rs index 08813a3b..5d835e77 100644 --- a/evm/src/arithmetic/arithmetic_stark.rs +++ b/evm/src/arithmetic/arithmetic_stark.rs @@ -6,12 +6,7 @@ use plonky2::field::extension::{Extendable, FieldExtension}; use plonky2::field::packed::PackedField; use plonky2::hash::hash_types::RichField; -use crate::arithmetic::add; -use crate::arithmetic::columns; -use crate::arithmetic::compare; -use crate::arithmetic::modular; -use crate::arithmetic::mul; -use crate::arithmetic::sub; +use crate::arithmetic::{add, columns, compare, modular, mul, sub}; use crate::constraint_consumer::{ConstraintConsumer, RecursiveConstraintConsumer}; use crate::stark::Stark; use crate::vars::{StarkEvaluationTargets, StarkEvaluationVars}; diff --git a/evm/src/arithmetic/modular.rs b/evm/src/arithmetic/modular.rs index d0020166..d19768bf 100644 --- a/evm/src/arithmetic/modular.rs +++ b/evm/src/arithmetic/modular.rs @@ -87,7 +87,8 @@ //! In the case of DIV, we do something similar, except that we "replace" //! the modulus with "2^256" to force the quotient to be zero. -use num::{bigint::Sign, BigInt, One, Zero}; +use num::bigint::Sign; +use num::{BigInt, One, Zero}; use plonky2::field::extension::Extendable; use plonky2::field::packed::PackedField; use plonky2::field::types::Field; diff --git a/evm/src/bin/assemble.rs b/evm/src/bin/assemble.rs index 1cf3a67c..2afd54d7 100644 --- a/evm/src/bin/assemble.rs +++ b/evm/src/bin/assemble.rs @@ -1,5 +1,4 @@ -use std::env; -use std::fs; +use std::{env, fs}; use hex::encode; use plonky2_evm::cpu::kernel::assemble_to_bytes; diff --git a/evm/src/cpu/kernel/assembler.rs b/evm/src/cpu/kernel/assembler.rs index aad2dd53..e06fd784 100644 --- a/evm/src/cpu/kernel/assembler.rs +++ b/evm/src/cpu/kernel/assembler.rs @@ -7,15 +7,12 @@ use plonky2_util::ceil_div_usize; use super::ast::PushTarget; use crate::cpu::kernel::ast::Item::LocalLabelDeclaration; -use crate::cpu::kernel::ast::StackReplacement; +use crate::cpu::kernel::ast::{File, Item, StackReplacement}; use crate::cpu::kernel::keccak_util::hash_kernel; +use crate::cpu::kernel::opcodes::{get_opcode, get_push_opcode}; use crate::cpu::kernel::optimizer::optimize_asm; use crate::cpu::kernel::stack::stack_manipulation::expand_stack_manipulation; use crate::cpu::kernel::utils::u256_to_trimmed_be_bytes; -use crate::cpu::kernel::{ - ast::{File, Item}, - opcodes::{get_opcode, get_push_opcode}, -}; use crate::generation::prover_input::ProverInputFn; use crate::keccak_sponge::columns::KECCAK_RATE_BYTES; @@ -374,8 +371,9 @@ mod tests { use itertools::Itertools; + use crate::cpu::kernel::assembler::*; + use crate::cpu::kernel::ast::*; use crate::cpu::kernel::parser::parse; - use crate::cpu::kernel::{assembler::*, ast::*}; #[test] fn two_files() { diff --git a/evm/src/keccak/round_flags.rs b/evm/src/keccak/round_flags.rs index 920ca4c8..d8c46680 100644 --- a/evm/src/keccak/round_flags.rs +++ b/evm/src/keccak/round_flags.rs @@ -5,11 +5,9 @@ use plonky2::hash::hash_types::RichField; use plonky2::plonk::circuit_builder::CircuitBuilder; use crate::constraint_consumer::{ConstraintConsumer, RecursiveConstraintConsumer}; -use crate::keccak::columns::reg_step; -use crate::keccak::columns::NUM_COLUMNS; +use crate::keccak::columns::{reg_step, NUM_COLUMNS}; use crate::keccak::keccak_stark::NUM_ROUNDS; -use crate::vars::StarkEvaluationTargets; -use crate::vars::StarkEvaluationVars; +use crate::vars::{StarkEvaluationTargets, StarkEvaluationVars}; pub(crate) fn eval_round_flags>( vars: StarkEvaluationVars, diff --git a/evm/src/keccak_memory/keccak_memory_stark.rs b/evm/src/keccak_memory/keccak_memory_stark.rs index 1bbea168..3719fc8e 100644 --- a/evm/src/keccak_memory/keccak_memory_stark.rs +++ b/evm/src/keccak_memory/keccak_memory_stark.rs @@ -15,8 +15,7 @@ use crate::keccak_memory::columns::*; use crate::memory::segments::Segment; use crate::stark::Stark; use crate::util::trace_rows_to_poly_values; -use crate::vars::StarkEvaluationTargets; -use crate::vars::StarkEvaluationVars; +use crate::vars::{StarkEvaluationTargets, StarkEvaluationVars}; pub(crate) fn ctl_looked_data() -> Vec> { Column::singles([COL_CONTEXT, COL_SEGMENT, COL_VIRTUAL, COL_READ_TIMESTAMP]).collect() diff --git a/evm/src/keccak_sponge/keccak_sponge_stark.rs b/evm/src/keccak_sponge/keccak_sponge_stark.rs index 219c0c21..f2af8895 100644 --- a/evm/src/keccak_sponge/keccak_sponge_stark.rs +++ b/evm/src/keccak_sponge/keccak_sponge_stark.rs @@ -21,8 +21,7 @@ use crate::keccak_sponge::columns::*; use crate::memory::segments::Segment; use crate::stark::Stark; use crate::util::trace_rows_to_poly_values; -use crate::vars::StarkEvaluationTargets; -use crate::vars::StarkEvaluationVars; +use crate::vars::{StarkEvaluationTargets, StarkEvaluationVars}; #[allow(unused)] // TODO: Should be used soon. pub(crate) fn ctl_looked_data() -> Vec> { diff --git a/evm/src/prover.rs b/evm/src/prover.rs index 20e8c628..4627784d 100644 --- a/evm/src/prover.rs +++ b/evm/src/prover.rs @@ -27,9 +27,9 @@ use crate::keccak::keccak_stark::KeccakStark; use crate::keccak_memory::keccak_memory_stark::KeccakMemoryStark; use crate::logic::LogicStark; use crate::memory::memory_stark::MemoryStark; -use crate::permutation::PermutationCheckVars; use crate::permutation::{ compute_permutation_z_polys, get_n_grand_product_challenge_sets, GrandProductChallengeSet, + PermutationCheckVars, }; use crate::proof::{AllProof, PublicValues, StarkOpeningSet, StarkProof}; use crate::stark::Stark; diff --git a/evm/src/recursive_verifier.rs b/evm/src/recursive_verifier.rs index 445497f8..999b5e13 100644 --- a/evm/src/recursive_verifier.rs +++ b/evm/src/recursive_verifier.rs @@ -13,13 +13,12 @@ use plonky2::iop::target::Target; use plonky2::iop::witness::Witness; use plonky2::plonk::circuit_builder::CircuitBuilder; use plonky2::plonk::circuit_data::{CircuitConfig, VerifierCircuitData, VerifierCircuitTarget}; -use plonky2::plonk::config::Hasher; -use plonky2::plonk::config::{AlgebraicHasher, GenericConfig}; +use plonky2::plonk::config::{AlgebraicHasher, GenericConfig, Hasher}; use plonky2::plonk::proof::{ProofWithPublicInputs, ProofWithPublicInputsTarget}; use plonky2::util::reducing::ReducingFactorTarget; use plonky2::with_context; -use crate::all_stark::NUM_TABLES; +use crate::all_stark::{AllStark, Table, NUM_TABLES}; use crate::config::StarkConfig; use crate::constraint_consumer::RecursiveConstraintConsumer; use crate::cpu::cpu_stark::CpuStark; @@ -41,13 +40,9 @@ use crate::proof::{ TrieRootsTarget, }; use crate::stark::Stark; -use crate::util::h160_limbs; +use crate::util::{h160_limbs, h256_limbs}; use crate::vanishing_poly::eval_vanishing_poly_circuit; use crate::vars::StarkEvaluationTargets; -use crate::{ - all_stark::{AllStark, Table}, - util::h256_limbs, -}; /// Table-wise recursive proofs of an `AllProof`. pub struct RecursiveAllProof< @@ -850,8 +845,7 @@ pub(crate) mod tests { use plonky2::iop::witness::{PartialWitness, Witness}; use plonky2::plonk::circuit_builder::CircuitBuilder; use plonky2::plonk::circuit_data::{CircuitConfig, VerifierCircuitData}; - use plonky2::plonk::config::Hasher; - use plonky2::plonk::config::{AlgebraicHasher, GenericConfig}; + use plonky2::plonk::config::{AlgebraicHasher, GenericConfig, Hasher}; use plonky2::plonk::proof::ProofWithPublicInputs; use crate::all_stark::{AllStark, Table}; diff --git a/evm/src/stark.rs b/evm/src/stark.rs index 49c5b70b..72cee0ad 100644 --- a/evm/src/stark.rs +++ b/evm/src/stark.rs @@ -13,8 +13,7 @@ use plonky2_util::ceil_div_usize; use crate::config::StarkConfig; use crate::constraint_consumer::{ConstraintConsumer, RecursiveConstraintConsumer}; use crate::permutation::PermutationPair; -use crate::vars::StarkEvaluationTargets; -use crate::vars::StarkEvaluationVars; +use crate::vars::{StarkEvaluationTargets, StarkEvaluationVars}; const TRACE_ORACLE_INDEX: usize = 0; const PERMUTATION_CTL_ORACLE_INDEX: usize = 1; diff --git a/evm/src/stark_testing.rs b/evm/src/stark_testing.rs index 81b0f68f..bd0df385 100644 --- a/evm/src/stark_testing.rs +++ b/evm/src/stark_testing.rs @@ -1,15 +1,12 @@ use anyhow::{ensure, Result}; -use plonky2::field::extension::Extendable; -use plonky2::field::extension::FieldExtension; +use plonky2::field::extension::{Extendable, FieldExtension}; use plonky2::field::polynomial::{PolynomialCoeffs, PolynomialValues}; use plonky2::field::types::Field; use plonky2::hash::hash_types::RichField; -use plonky2::iop::witness::PartialWitness; -use plonky2::iop::witness::Witness; +use plonky2::iop::witness::{PartialWitness, Witness}; use plonky2::plonk::circuit_builder::CircuitBuilder; use plonky2::plonk::circuit_data::CircuitConfig; -use plonky2::plonk::config::GenericConfig; -use plonky2::plonk::config::Hasher; +use plonky2::plonk::config::{GenericConfig, Hasher}; use plonky2::util::transpose; use plonky2_util::{log2_ceil, log2_strict}; diff --git a/field/src/field_testing.rs b/field/src/field_testing.rs index d85ac5e9..5e495311 100644 --- a/field/src/field_testing.rs +++ b/field/src/field_testing.rs @@ -1,5 +1,4 @@ -use crate::extension::Extendable; -use crate::extension::Frobenius; +use crate::extension::{Extendable, Frobenius}; use crate::ops::Square; use crate::types::Field; diff --git a/plonky2/Cargo.toml b/plonky2/Cargo.toml index b3fa5113..73ff55a5 100644 --- a/plonky2/Cargo.toml +++ b/plonky2/Cargo.toml @@ -19,30 +19,31 @@ rand_chacha = ["dep:rand_chacha"] timing = [] [dependencies] +anyhow = "1.0.40" +derivative = { version = "2.2.0", default-features = false, features = ["use_core"] } +itertools = "0.10.0" +keccak-hash = "0.8.0" +log = "0.4.14" +maybe_rayon = { path = "../maybe_rayon" } +num = { version = "0.4", features = [ "rand" ] } plonky2_field = { path = "../field" } plonky2_util = { path = "../util" } -log = "0.4.14" -itertools = "0.10.0" -num = { version = "0.4", features = [ "rand" ] } rand = { version = "0.8.4", optional = true } rand_chacha = { version = "0.3.1", optional = true } -maybe_rayon = { path = "../maybe_rayon" } -unroll = "0.1.5" -anyhow = "1.0.40" serde = { version = "1.0", features = ["derive"] } serde_cbor = "0.11.1" -keccak-hash = "0.8.0" static_assertions = "1.1.0" +unroll = "0.1.5" [dev-dependencies] -rand = "0.8.4" -rand_chacha = "0.3.1" criterion = "0.3.5" env_logger = "0.9.0" -tynm = "0.1.6" -structopt = "0.3.26" num_cpus = "1.13.1" +rand = "0.8.4" +rand_chacha = "0.3.1" rayon = "1.5.1" +structopt = "0.3.26" +tynm = "0.1.6" [target.'cfg(not(target_env = "msvc"))'.dev-dependencies] jemallocator = "0.3.2" diff --git a/plonky2/examples/bench_recursion.rs b/plonky2/examples/bench_recursion.rs index e0d3cff6..6e196ef5 100644 --- a/plonky2/examples/bench_recursion.rs +++ b/plonky2/examples/bench_recursion.rs @@ -5,27 +5,26 @@ #![allow(incomplete_features)] #![feature(generic_const_exprs)] -use core::{num::ParseIntError, ops::RangeInclusive, str::FromStr}; +use core::num::ParseIntError; +use core::ops::RangeInclusive; +use core::str::FromStr; use anyhow::{anyhow, Context as _, Result}; use log::{info, Level, LevelFilter}; -use plonky2::{ - gates::noop::NoopGate, - hash::hash_types::RichField, - iop::witness::{PartialWitness, Witness}, - plonk::{ - circuit_builder::CircuitBuilder, - circuit_data::{ - CircuitConfig, CommonCircuitData, VerifierCircuitTarget, VerifierOnlyCircuitData, - }, - config::{AlgebraicHasher, GenericConfig, Hasher, PoseidonGoldilocksConfig}, - proof::{CompressedProofWithPublicInputs, ProofWithPublicInputs}, - prover::prove, - }, - util::timing::TimingTree, +use plonky2::gates::noop::NoopGate; +use plonky2::hash::hash_types::RichField; +use plonky2::iop::witness::{PartialWitness, Witness}; +use plonky2::plonk::circuit_builder::CircuitBuilder; +use plonky2::plonk::circuit_data::{ + CircuitConfig, CommonCircuitData, VerifierCircuitTarget, VerifierOnlyCircuitData, }; +use plonky2::plonk::config::{AlgebraicHasher, GenericConfig, Hasher, PoseidonGoldilocksConfig}; +use plonky2::plonk::proof::{CompressedProofWithPublicInputs, ProofWithPublicInputs}; +use plonky2::plonk::prover::prove; +use plonky2::util::timing::TimingTree; use plonky2_field::extension::Extendable; -use rand::{rngs::OsRng, RngCore, SeedableRng}; +use rand::rngs::OsRng; +use rand::{RngCore, SeedableRng}; use rand_chacha::ChaCha8Rng; use structopt::StructOpt; diff --git a/plonky2/src/fri/oracle.rs b/plonky2/src/fri/oracle.rs index 75f8847a..10a93a18 100644 --- a/plonky2/src/fri/oracle.rs +++ b/plonky2/src/fri/oracle.rs @@ -14,12 +14,11 @@ use crate::fri::FriParams; use crate::hash::hash_types::RichField; use crate::hash::merkle_tree::MerkleTree; use crate::iop::challenger::Challenger; -use crate::plonk::config::{GenericConfig, Hasher}; +use crate::plonk::config::GenericConfig; use crate::timed; use crate::util::reducing::ReducingFactor; -use crate::util::reverse_bits; use crate::util::timing::TimingTree; -use crate::util::transpose; +use crate::util::{reverse_bits, transpose}; /// Four (~64 bit) field elements gives ~128 bit security. pub const SALT_SIZE: usize = 4; @@ -45,10 +44,7 @@ impl, C: GenericConfig, const D: usize> cap_height: usize, timing: &mut TimingTree, fft_root_table: Option<&FftRootTable>, - ) -> Self - where - [(); C::Hasher::HASH_SIZE]:, - { + ) -> Self { let coeffs = timed!( timing, "IFFT", @@ -73,10 +69,7 @@ impl, C: GenericConfig, const D: usize> cap_height: usize, timing: &mut TimingTree, fft_root_table: Option<&FftRootTable>, - ) -> Self - where - [(); C::Hasher::HASH_SIZE]:, - { + ) -> Self { let degree = polynomials[0].len(); let lde_values = timed!( timing, @@ -169,10 +162,7 @@ impl, C: GenericConfig, const D: usize> challenger: &mut Challenger, fri_params: &FriParams, timing: &mut TimingTree, - ) -> FriProof - where - [(); C::Hasher::HASH_SIZE]:, - { + ) -> FriProof { assert!(D > 1, "Not implemented for D=1."); let alpha = challenger.get_extension_challenge::(); let mut alpha = ReducingFactor::new(alpha); diff --git a/plonky2/src/fri/proof.rs b/plonky2/src/fri/proof.rs index f7945b28..6a8adcf5 100644 --- a/plonky2/src/fri/proof.rs +++ b/plonky2/src/fri/proof.rs @@ -7,8 +7,7 @@ use serde::{Deserialize, Serialize}; use crate::fri::FriParams; use crate::gadgets::polynomial::PolynomialCoeffsExtTarget; -use crate::hash::hash_types::MerkleCapTarget; -use crate::hash::hash_types::RichField; +use crate::hash::hash_types::{MerkleCapTarget, RichField}; use crate::hash::merkle_proofs::{MerkleProof, MerkleProofTarget}; use crate::hash::merkle_tree::MerkleCap; use crate::hash::path_compression::{compress_merkle_proofs, decompress_merkle_proofs}; @@ -245,10 +244,7 @@ impl, H: Hasher, const D: usize> CompressedFriPr challenges: &ProofChallenges, fri_inferred_elements: FriInferredElements, params: &FriParams, - ) -> FriProof - where - [(); H::HASH_SIZE]:, - { + ) -> FriProof { let CompressedFriProof { commit_phase_merkle_caps, query_round_proofs, diff --git a/plonky2/src/fri/prover.rs b/plonky2/src/fri/prover.rs index 71efe98a..32e41ff3 100644 --- a/plonky2/src/fri/prover.rs +++ b/plonky2/src/fri/prover.rs @@ -24,10 +24,7 @@ pub fn fri_proof, C: GenericConfig, const challenger: &mut Challenger, fri_params: &FriParams, timing: &mut TimingTree, -) -> FriProof -where - [(); C::Hasher::HASH_SIZE]:, -{ +) -> FriProof { let n = lde_polynomial_values.len(); assert_eq!(lde_polynomial_coeffs.len(), n); @@ -63,18 +60,17 @@ where } } +type FriCommitedTrees = ( + Vec>::Hasher>>, + PolynomialCoeffs<>::Extension>, +); + fn fri_committed_trees, C: GenericConfig, const D: usize>( mut coeffs: PolynomialCoeffs, mut values: PolynomialValues, challenger: &mut Challenger, fri_params: &FriParams, -) -> ( - Vec>, - PolynomialCoeffs, -) -where - [(); C::Hasher::HASH_SIZE]:, -{ +) -> FriCommitedTrees { let mut trees = Vec::new(); let mut shift = F::MULTIPLICATIVE_GROUP_GENERATOR; diff --git a/plonky2/src/fri/recursive_verifier.rs b/plonky2/src/fri/recursive_verifier.rs index d14420c1..c5cb9f07 100644 --- a/plonky2/src/fri/recursive_verifier.rs +++ b/plonky2/src/fri/recursive_verifier.rs @@ -13,8 +13,7 @@ use crate::gates::high_degree_interpolation::HighDegreeInterpolationGate; use crate::gates::interpolation::InterpolationGate; use crate::gates::low_degree_interpolation::LowDegreeInterpolationGate; use crate::gates::random_access::RandomAccessGate; -use crate::hash::hash_types::MerkleCapTarget; -use crate::hash::hash_types::RichField; +use crate::hash::hash_types::{MerkleCapTarget, RichField}; use crate::iop::ext_target::{flatten_target, ExtensionTarget}; use crate::iop::target::{BoolTarget, Target}; use crate::plonk::circuit_builder::CircuitBuilder; diff --git a/plonky2/src/fri/verifier.rs b/plonky2/src/fri/verifier.rs index 02816000..9d01ef6c 100644 --- a/plonky2/src/fri/verifier.rs +++ b/plonky2/src/fri/verifier.rs @@ -57,17 +57,18 @@ pub(crate) fn fri_verify_proof_of_work, const D: us Ok(()) } -pub fn verify_fri_proof, C: GenericConfig, const D: usize>( +pub fn verify_fri_proof< + F: RichField + Extendable, + C: GenericConfig, + const D: usize, +>( instance: &FriInstanceInfo, openings: &FriOpenings, challenges: &FriChallenges, initial_merkle_caps: &[MerkleCap], proof: &FriProof, params: &FriParams, -) -> Result<()> -where - [(); C::Hasher::HASH_SIZE]:, -{ +) -> Result<()> { validate_fri_proof_shape::(proof, instance, params)?; // Size of the LDE domain. @@ -109,10 +110,7 @@ fn fri_verify_initial_proof>( x_index: usize, proof: &FriInitialTreeProof, initial_merkle_caps: &[MerkleCap], -) -> Result<()> -where - [(); H::HASH_SIZE]:, -{ +) -> Result<()> { for ((evals, merkle_proof), cap) in proof.evals_proofs.iter().zip(initial_merkle_caps) { verify_merkle_proof_to_cap::(evals.clone(), x_index, cap, merkle_proof)?; } @@ -177,10 +175,7 @@ fn fri_verifier_query_round< n: usize, round_proof: &FriQueryRound, params: &FriParams, -) -> Result<()> -where - [(); C::Hasher::HASH_SIZE]:, -{ +) -> Result<()> { fri_verify_initial_proof::( x_index, &round_proof.initial_trees_proof, diff --git a/plonky2/src/gadgets/arithmetic_extension.rs b/plonky2/src/gadgets/arithmetic_extension.rs index e3b31e17..296127b1 100644 --- a/plonky2/src/gadgets/arithmetic_extension.rs +++ b/plonky2/src/gadgets/arithmetic_extension.rs @@ -1,7 +1,6 @@ use core::borrow::Borrow; -use plonky2_field::extension::FieldExtension; -use plonky2_field::extension::{Extendable, OEF}; +use plonky2_field::extension::{Extendable, FieldExtension, OEF}; use plonky2_field::types::{Field, Field64}; use plonky2_util::bits_u64; diff --git a/plonky2/src/gadgets/polynomial.rs b/plonky2/src/gadgets/polynomial.rs index 60bfcca4..d61cf830 100644 --- a/plonky2/src/gadgets/polynomial.rs +++ b/plonky2/src/gadgets/polynomial.rs @@ -14,6 +14,10 @@ impl PolynomialCoeffsExtTarget { self.0.len() } + pub fn is_empty(&self) -> bool { + self.len() == 0 + } + pub fn eval_scalar>( &self, builder: &mut CircuitBuilder, diff --git a/plonky2/src/gates/arithmetic_extension.rs b/plonky2/src/gates/arithmetic_extension.rs index 4aa550c2..da522b9e 100644 --- a/plonky2/src/gates/arithmetic_extension.rs +++ b/plonky2/src/gates/arithmetic_extension.rs @@ -1,7 +1,6 @@ use core::ops::Range; -use plonky2_field::extension::Extendable; -use plonky2_field::extension::FieldExtension; +use plonky2_field::extension::{Extendable, FieldExtension}; use crate::gates::gate::Gate; use crate::gates::util::StridedConstraintConsumer; diff --git a/plonky2/src/gates/gate_testing.rs b/plonky2/src/gates/gate_testing.rs index e9c4c237..8492f385 100644 --- a/plonky2/src/gates/gate_testing.rs +++ b/plonky2/src/gates/gate_testing.rs @@ -5,12 +5,11 @@ use plonky2_field::types::Field; use plonky2_util::log2_ceil; use crate::gates::gate::Gate; -use crate::hash::hash_types::HashOut; -use crate::hash::hash_types::RichField; +use crate::hash::hash_types::{HashOut, RichField}; use crate::iop::witness::{PartialWitness, Witness}; use crate::plonk::circuit_builder::CircuitBuilder; use crate::plonk::circuit_data::CircuitConfig; -use crate::plonk::config::{GenericConfig, Hasher}; +use crate::plonk::config::GenericConfig; use crate::plonk::vars::{EvaluationTargets, EvaluationVars, EvaluationVarsBaseBatch}; use crate::plonk::verifier::verify; use crate::util::transpose; @@ -92,10 +91,7 @@ pub fn test_eval_fns< const D: usize, >( gate: G, -) -> Result<()> -where - [(); C::Hasher::HASH_SIZE]:, -{ +) -> Result<()> { // Test that `eval_unfiltered` and `eval_unfiltered_base` are coherent. let wires_base = F::rand_vec(gate.num_wires()); let constants_base = F::rand_vec(gate.num_constants()); diff --git a/plonky2/src/gates/multiplication_extension.rs b/plonky2/src/gates/multiplication_extension.rs index c158c6a6..97ff538f 100644 --- a/plonky2/src/gates/multiplication_extension.rs +++ b/plonky2/src/gates/multiplication_extension.rs @@ -1,7 +1,6 @@ use core::ops::Range; -use plonky2_field::extension::Extendable; -use plonky2_field::extension::FieldExtension; +use plonky2_field::extension::{Extendable, FieldExtension}; use crate::gates::gate::Gate; use crate::gates::util::StridedConstraintConsumer; diff --git a/plonky2/src/gates/poseidon.rs b/plonky2/src/gates/poseidon.rs index 95678528..0977d7b4 100644 --- a/plonky2/src/gates/poseidon.rs +++ b/plonky2/src/gates/poseidon.rs @@ -23,16 +23,13 @@ use crate::plonk::vars::{EvaluationTargets, EvaluationVars, EvaluationVarsBase}; /// This also has some extra features to make it suitable for efficiently verifying Merkle proofs. /// It has a flag which can be used to swap the first four inputs with the next four, for ordering /// sibling digests. -#[derive(Debug)] -pub struct PoseidonGate, const D: usize> { - _phantom: PhantomData, -} +#[derive(derivative::Derivative)] +#[derivative(Clone, Copy, Debug, Default, Eq, Hash, PartialEq)] +pub struct PoseidonGate, const D: usize>(PhantomData); impl, const D: usize> PoseidonGate { pub fn new() -> Self { - PoseidonGate { - _phantom: PhantomData, - } + Self(PhantomData) } /// The wire index for the `i`th input to the permutation. diff --git a/plonky2/src/gates/poseidon_mds.rs b/plonky2/src/gates/poseidon_mds.rs index f1566e11..d41fdf17 100644 --- a/plonky2/src/gates/poseidon_mds.rs +++ b/plonky2/src/gates/poseidon_mds.rs @@ -2,8 +2,7 @@ use core::marker::PhantomData; use core::ops::Range; use plonky2_field::extension::algebra::ExtensionAlgebra; -use plonky2_field::extension::Extendable; -use plonky2_field::extension::FieldExtension; +use plonky2_field::extension::{Extendable, FieldExtension}; use plonky2_field::types::Field; use crate::gates::gate::Gate; @@ -18,16 +17,14 @@ use crate::iop::witness::{PartitionWitness, Witness}; use crate::plonk::circuit_builder::CircuitBuilder; use crate::plonk::vars::{EvaluationTargets, EvaluationVars, EvaluationVarsBase}; -#[derive(Debug)] -pub struct PoseidonMdsGate + Poseidon, const D: usize> { - _phantom: PhantomData, -} +/// Poseidon MDS Gate +#[derive(derivative::Derivative)] +#[derivative(Clone, Copy, Debug, Default, Eq, Hash, PartialEq)] +pub struct PoseidonMdsGate + Poseidon, const D: usize>(PhantomData); impl + Poseidon, const D: usize> PoseidonMdsGate { pub fn new() -> Self { - PoseidonMdsGate { - _phantom: PhantomData, - } + Self(PhantomData) } pub fn wires_input(i: usize) -> Range { diff --git a/plonky2/src/gates/reducing.rs b/plonky2/src/gates/reducing.rs index bf312b84..c2366558 100644 --- a/plonky2/src/gates/reducing.rs +++ b/plonky2/src/gates/reducing.rs @@ -1,7 +1,6 @@ use core::ops::Range; -use plonky2_field::extension::Extendable; -use plonky2_field::extension::FieldExtension; +use plonky2_field::extension::{Extendable, FieldExtension}; use crate::gates::gate::Gate; use crate::gates::util::StridedConstraintConsumer; diff --git a/plonky2/src/gates/reducing_extension.rs b/plonky2/src/gates/reducing_extension.rs index e7a4fc8f..61377b1b 100644 --- a/plonky2/src/gates/reducing_extension.rs +++ b/plonky2/src/gates/reducing_extension.rs @@ -1,7 +1,6 @@ use core::ops::Range; -use plonky2_field::extension::Extendable; -use plonky2_field::extension::FieldExtension; +use plonky2_field::extension::{Extendable, FieldExtension}; use crate::gates::gate::Gate; use crate::gates::util::StridedConstraintConsumer; diff --git a/plonky2/src/gates/selectors.rs b/plonky2/src/gates/selectors.rs index b2b52b77..d9be7024 100644 --- a/plonky2/src/gates/selectors.rs +++ b/plonky2/src/gates/selectors.rs @@ -28,7 +28,7 @@ impl SelectorsInfo { /// `|G| + max_{g in G} g.degree() <= max_degree`. These groups are constructed greedily from /// the list of gates sorted by degree. /// We build a selector polynomial `S_i` for each group `G_i`, with -/// S_i[j] = +/// S_i\[j\] = /// if j-th row gate=g_k in G_i /// k /// else diff --git a/plonky2/src/hash/hashing.rs b/plonky2/src/hash/hashing.rs index c903201b..e4ba2719 100644 --- a/plonky2/src/hash/hashing.rs +++ b/plonky2/src/hash/hashing.rs @@ -2,8 +2,7 @@ use plonky2_field::extension::Extendable; -use crate::hash::hash_types::RichField; -use crate::hash::hash_types::{HashOut, HashOutTarget}; +use crate::hash::hash_types::{HashOut, HashOutTarget, RichField}; use crate::iop::target::Target; use crate::plonk::circuit_builder::CircuitBuilder; use crate::plonk::config::AlgebraicHasher; diff --git a/plonky2/src/hash/merkle_proofs.rs b/plonky2/src/hash/merkle_proofs.rs index f54793d9..04a7787f 100644 --- a/plonky2/src/hash/merkle_proofs.rs +++ b/plonky2/src/hash/merkle_proofs.rs @@ -2,8 +2,7 @@ use anyhow::{ensure, Result}; use plonky2_field::extension::Extendable; use serde::{Deserialize, Serialize}; -use crate::hash::hash_types::RichField; -use crate::hash::hash_types::{HashOutTarget, MerkleCapTarget}; +use crate::hash::hash_types::{HashOutTarget, MerkleCapTarget, RichField}; use crate::hash::hashing::SPONGE_WIDTH; use crate::hash::merkle_tree::MerkleCap; use crate::iop::target::{BoolTarget, Target}; @@ -21,6 +20,10 @@ impl> MerkleProof { pub fn len(&self) -> usize { self.siblings.len() } + + pub fn is_empty(&self) -> bool { + self.len() == 0 + } } #[derive(Clone, Debug)] @@ -36,10 +39,7 @@ pub fn verify_merkle_proof>( leaf_index: usize, merkle_root: H::Hash, proof: &MerkleProof, -) -> Result<()> -where - [(); H::HASH_SIZE]:, -{ +) -> Result<()> { let merkle_cap = MerkleCap(vec![merkle_root]); verify_merkle_proof_to_cap(leaf_data, leaf_index, &merkle_cap, proof) } @@ -51,10 +51,7 @@ pub fn verify_merkle_proof_to_cap>( leaf_index: usize, merkle_cap: &MerkleCap, proof: &MerkleProof, -) -> Result<()> -where - [(); H::HASH_SIZE]:, -{ +) -> Result<()> { let mut index = leaf_index; let mut current_digest = H::hash_or_noop(&leaf_data); for &sibling_digest in proof.siblings.iter() { diff --git a/plonky2/src/hash/merkle_tree.rs b/plonky2/src/hash/merkle_tree.rs index 19d49f13..c0799d98 100644 --- a/plonky2/src/hash/merkle_tree.rs +++ b/plonky2/src/hash/merkle_tree.rs @@ -7,8 +7,7 @@ use serde::{Deserialize, Serialize}; use crate::hash::hash_types::RichField; use crate::hash::merkle_proofs::MerkleProof; -use crate::plonk::config::GenericHashOut; -use crate::plonk::config::Hasher; +use crate::plonk::config::{GenericHashOut, Hasher}; /// 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. @@ -21,6 +20,10 @@ impl> MerkleCap { self.0.len() } + pub fn is_empty(&self) -> bool { + self.len() == 0 + } + pub fn height(&self) -> usize { log2_strict(self.len()) } @@ -64,10 +67,7 @@ fn capacity_up_to_mut(v: &mut Vec, len: usize) -> &mut [MaybeUninit] { fn fill_subtree>( digests_buf: &mut [MaybeUninit], leaves: &[Vec], -) -> H::Hash -where - [(); H::HASH_SIZE]:, -{ +) -> H::Hash { assert_eq!(leaves.len(), digests_buf.len() / 2 + 1); if digests_buf.is_empty() { H::hash_or_noop(&leaves[0]) @@ -98,9 +98,7 @@ fn fill_digests_buf>( cap_buf: &mut [MaybeUninit], leaves: &[Vec], cap_height: usize, -) where - [(); H::HASH_SIZE]:, -{ +) { // Special case of a tree that's all cap. The usual case will panic because we'll try to split // an empty slice into chunks of `0`. (We would not need this if there was a way to split into // `blah` chunks as opposed to chunks _of_ `blah`.) @@ -132,10 +130,7 @@ fn fill_digests_buf>( } impl> MerkleTree { - pub fn new(leaves: Vec>, cap_height: usize) -> Self - where - [(); H::HASH_SIZE]:, - { + pub fn new(leaves: Vec>, cap_height: usize) -> Self { let log2_leaves_len = log2_strict(leaves.len()); assert!( cap_height <= log2_leaves_len, @@ -222,13 +217,14 @@ mod tests { (0..n).map(|_| F::rand_vec(k)).collect() } - fn verify_all_leaves, C: GenericConfig, const D: usize>( + fn verify_all_leaves< + F: RichField + Extendable, + C: GenericConfig, + const D: usize, + >( leaves: Vec>, cap_height: usize, - ) -> Result<()> - where - [(); C::Hasher::HASH_SIZE]:, - { + ) -> Result<()> { let tree = MerkleTree::::new(leaves.clone(), cap_height); for (i, leaf) in leaves.into_iter().enumerate() { let proof = tree.prove(i); diff --git a/plonky2/src/hash/path_compression.rs b/plonky2/src/hash/path_compression.rs index 2685f723..c57b5e03 100644 --- a/plonky2/src/hash/path_compression.rs +++ b/plonky2/src/hash/path_compression.rs @@ -57,10 +57,7 @@ pub(crate) fn decompress_merkle_proofs>( compressed_proofs: &[MerkleProof], height: usize, cap_height: usize, -) -> Vec> -where - [(); H::HASH_SIZE]:, -{ +) -> Vec> { let num_leaves = 1 << height; let compressed_proofs = compressed_proofs.to_vec(); let mut decompressed_proofs = Vec::with_capacity(compressed_proofs.len()); diff --git a/plonky2/src/hash/poseidon.rs b/plonky2/src/hash/poseidon.rs index 54c2379f..248ab32d 100644 --- a/plonky2/src/hash/poseidon.rs +++ b/plonky2/src/hash/poseidon.rs @@ -1,5 +1,5 @@ //! Implementation of the Poseidon hash function, as described in -//! https://eprint.iacr.org/2019/458.pdf +//! use plonky2_field::extension::{Extendable, FieldExtension}; use plonky2_field::types::{Field, PrimeField64}; diff --git a/plonky2/src/hash/poseidon_goldilocks.rs b/plonky2/src/hash/poseidon_goldilocks.rs index 658b397e..001c5900 100644 --- a/plonky2/src/hash/poseidon_goldilocks.rs +++ b/plonky2/src/hash/poseidon_goldilocks.rs @@ -272,8 +272,7 @@ impl Poseidon for GoldilocksField { #[cfg(test)] mod tests { use plonky2_field::goldilocks_field::GoldilocksField as F; - use plonky2_field::types::Field; - use plonky2_field::types::PrimeField64; + use plonky2_field::types::{Field, PrimeField64}; use crate::hash::poseidon::test_helpers::{check_consistency, check_test_vectors}; diff --git a/plonky2/src/iop/challenger.rs b/plonky2/src/iop/challenger.rs index 34ed4f67..06b7d4ba 100644 --- a/plonky2/src/iop/challenger.rs +++ b/plonky2/src/iop/challenger.rs @@ -3,8 +3,7 @@ use core::marker::PhantomData; use plonky2_field::extension::{Extendable, FieldExtension}; -use crate::hash::hash_types::RichField; -use crate::hash::hash_types::{HashOut, HashOutTarget, MerkleCapTarget}; +use crate::hash::hash_types::{HashOut, HashOutTarget, MerkleCapTarget, RichField}; use crate::hash::hashing::{PlonkyPermutation, SPONGE_RATE, SPONGE_WIDTH}; use crate::hash::merkle_tree::MerkleCap; use crate::iop::ext_target::ExtensionTarget; @@ -170,6 +169,7 @@ pub struct RecursiveChallenger, H: AlgebraicHasher< sponge_state: [Target; SPONGE_WIDTH], input_buffer: Vec, output_buffer: Vec, + __: PhantomData<(F, H)>, } impl, H: AlgebraicHasher, const D: usize> @@ -177,18 +177,20 @@ impl, H: AlgebraicHasher, const D: usize> { pub fn new(builder: &mut CircuitBuilder) -> Self { let zero = builder.zero(); - RecursiveChallenger { + Self { sponge_state: [zero; SPONGE_WIDTH], input_buffer: Vec::new(), output_buffer: Vec::new(), + __: PhantomData, } } pub fn from_state(sponge_state: [Target; SPONGE_WIDTH]) -> Self { - RecursiveChallenger { + Self { sponge_state, input_buffer: vec![], output_buffer: vec![], + __: PhantomData, } } diff --git a/plonky2/src/iop/witness.rs b/plonky2/src/iop/witness.rs index 9a3cb662..99d6313d 100644 --- a/plonky2/src/iop/witness.rs +++ b/plonky2/src/iop/witness.rs @@ -6,9 +6,7 @@ use plonky2_field::types::Field; use crate::fri::structure::{FriOpenings, FriOpeningsTarget}; use crate::fri::witness_util::set_fri_proof_target; -use crate::hash::hash_types::HashOutTarget; -use crate::hash::hash_types::RichField; -use crate::hash::hash_types::{HashOut, MerkleCapTarget}; +use crate::hash::hash_types::{HashOut, HashOutTarget, MerkleCapTarget, RichField}; use crate::hash::merkle_tree::MerkleCap; use crate::iop::ext_target::ExtensionTarget; use crate::iop::target::{BoolTarget, Target}; @@ -250,14 +248,15 @@ impl MatrixWitness { } } -#[derive(Clone, Debug)] +#[derive(derivative::Derivative)] +#[derivative(Clone, Debug, Default(bound = ""))] pub struct PartialWitness { pub(crate) target_values: HashMap, } impl PartialWitness { pub fn new() -> Self { - PartialWitness { + Self { target_values: HashMap::new(), } } diff --git a/plonky2/src/lib.rs b/plonky2/src/lib.rs index 8a517a11..db7a213b 100644 --- a/plonky2/src/lib.rs +++ b/plonky2/src/lib.rs @@ -1,14 +1,5 @@ -#![allow(incomplete_features)] -#![allow(const_evaluatable_unchecked)] -#![allow(clippy::new_without_default)] #![allow(clippy::too_many_arguments)] -#![allow(clippy::type_complexity)] -#![allow(clippy::len_without_is_empty)] #![allow(clippy::needless_range_loop)] -#![allow(clippy::return_self_not_must_use)] -#![feature(generic_const_exprs)] -#![feature(specialization)] -#![feature(stdsimd)] pub use plonky2_field as field; diff --git a/plonky2/src/plonk/circuit_builder.rs b/plonky2/src/plonk/circuit_builder.rs index 3b48f9cf..f071d69c 100644 --- a/plonky2/src/plonk/circuit_builder.rs +++ b/plonky2/src/plonk/circuit_builder.rs @@ -686,10 +686,7 @@ impl, const D: usize> CircuitBuilder { } /// Builds a "full circuit", with both prover and verifier data. - pub fn build>(mut self) -> CircuitData - where - [(); C::Hasher::HASH_SIZE]:, - { + pub fn build>(mut self) -> CircuitData { let mut timing = TimingTree::new("preprocess", Level::Trace); let start = Instant::now(); let rate_bits = self.config.fri_config.rate_bits; @@ -887,20 +884,14 @@ impl, const D: usize> CircuitBuilder { } /// Builds a "prover circuit", with data needed to generate proofs but not verify them. - pub fn build_prover>(self) -> ProverCircuitData - where - [(); C::Hasher::HASH_SIZE]:, - { + pub fn build_prover>(self) -> ProverCircuitData { // TODO: Can skip parts of this. let circuit_data = self.build(); circuit_data.prover_data() } /// Builds a "verifier circuit", with data needed to verify proofs but not generate them. - pub fn build_verifier>(self) -> VerifierCircuitData - where - [(); C::Hasher::HASH_SIZE]:, - { + pub fn build_verifier>(self) -> VerifierCircuitData { // TODO: Can skip parts of this. let circuit_data = self.build(); circuit_data.verifier_data() diff --git a/plonky2/src/plonk/circuit_data.rs b/plonky2/src/plonk/circuit_data.rs index b1dea756..7a0af7b8 100644 --- a/plonky2/src/plonk/circuit_data.rs +++ b/plonky2/src/plonk/circuit_data.rs @@ -112,10 +112,7 @@ pub struct CircuitData, C: GenericConfig, impl, C: GenericConfig, const D: usize> CircuitData { - pub fn prove(&self, inputs: PartialWitness) -> Result> - where - [(); C::Hasher::HASH_SIZE]:, - { + pub fn prove(&self, inputs: PartialWitness) -> Result> { prove( &self.prover_only, &self.common, @@ -124,20 +121,14 @@ impl, C: GenericConfig, const D: usize> ) } - pub fn verify(&self, proof_with_pis: ProofWithPublicInputs) -> Result<()> - where - [(); C::Hasher::HASH_SIZE]:, - { + pub fn verify(&self, proof_with_pis: ProofWithPublicInputs) -> Result<()> { verify(proof_with_pis, &self.verifier_only, &self.common) } pub fn verify_compressed( &self, compressed_proof_with_pis: CompressedProofWithPublicInputs, - ) -> Result<()> - where - [(); C::Hasher::HASH_SIZE]:, - { + ) -> Result<()> { compressed_proof_with_pis.verify(&self.verifier_only, &self.common) } @@ -151,10 +142,7 @@ impl, C: GenericConfig, const D: usize> pub fn decompress( &self, proof: CompressedProofWithPublicInputs, - ) -> Result> - where - [(); C::Hasher::HASH_SIZE]:, - { + ) -> Result> { proof.decompress(&self.verifier_only.circuit_digest, &self.common) } @@ -202,10 +190,7 @@ pub struct ProverCircuitData< impl, C: GenericConfig, const D: usize> ProverCircuitData { - pub fn prove(&self, inputs: PartialWitness) -> Result> - where - [(); C::Hasher::HASH_SIZE]:, - { + pub fn prove(&self, inputs: PartialWitness) -> Result> { prove( &self.prover_only, &self.common, @@ -229,20 +214,14 @@ pub struct VerifierCircuitData< impl, C: GenericConfig, const D: usize> VerifierCircuitData { - pub fn verify(&self, proof_with_pis: ProofWithPublicInputs) -> Result<()> - where - [(); C::Hasher::HASH_SIZE]:, - { + pub fn verify(&self, proof_with_pis: ProofWithPublicInputs) -> Result<()> { verify(proof_with_pis, &self.verifier_only, &self.common) } pub fn verify_compressed( &self, compressed_proof_with_pis: CompressedProofWithPublicInputs, - ) -> Result<()> - where - [(); C::Hasher::HASH_SIZE]:, - { + ) -> Result<()> { compressed_proof_with_pis.verify(&self.verifier_only, &self.common) } } diff --git a/plonky2/src/plonk/config.rs b/plonky2/src/plonk/config.rs index 20de09fb..87395348 100644 --- a/plonky2/src/plonk/config.rs +++ b/plonky2/src/plonk/config.rs @@ -3,10 +3,10 @@ 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, Serialize}; +use serde::de::DeserializeOwned; +use serde::Serialize; -use crate::hash::hash_types::HashOut; -use crate::hash::hash_types::RichField; +use crate::hash::hash_types::{HashOut, RichField}; use crate::hash::hashing::{PlonkyPermutation, SPONGE_WIDTH}; use crate::hash::keccak::KeccakHash; use crate::hash::poseidon::PoseidonHash; @@ -26,6 +26,8 @@ pub trait GenericHashOut: pub trait Hasher: Sized + Clone + Debug + Eq + PartialEq { /// Size of `Hash` in bytes. const HASH_SIZE: usize; + + /// Hash Output type Hash: GenericHashOut; /// Permutation used in the sponge construction. @@ -48,12 +50,9 @@ pub trait Hasher: Sized + Clone + Debug + Eq + PartialEq { /// Hash the slice if necessary to reduce its length to ~256 bits. If it already fits, this is a /// no-op. - fn hash_or_noop(inputs: &[F]) -> Self::Hash - where - [(); Self::HASH_SIZE]:, - { + fn hash_or_noop(inputs: &[F]) -> Self::Hash { if inputs.len() <= 4 { - let mut inputs_bytes = [0u8; Self::HASH_SIZE]; + let mut inputs_bytes = vec![0u8; Self::HASH_SIZE]; for i in 0..inputs.len() { inputs_bytes[i * 8..(i + 1) * 8] .copy_from_slice(&inputs[i].to_canonical_u64().to_le_bytes()); diff --git a/plonky2/src/plonk/permutation_argument.rs b/plonky2/src/plonk/permutation_argument.rs index 3658a12d..44d492d9 100644 --- a/plonky2/src/plonk/permutation_argument.rs +++ b/plonky2/src/plonk/permutation_argument.rs @@ -7,7 +7,7 @@ use plonky2_field::types::Field; use crate::iop::target::Target; use crate::iop::wire::Wire; -/// Disjoint Set Forest data-structure following https://en.wikipedia.org/wiki/Disjoint-set_data_structure. +/// Disjoint Set Forest data-structure following . pub struct Forest { /// A map of parent pointers, stored as indices. pub(crate) parents: Vec, @@ -44,7 +44,7 @@ impl Forest { self.parents.push(index); } - /// Path compression method, see https://en.wikipedia.org/wiki/Disjoint-set_data_structure#Finding_set_representatives. + /// Path compression method, see . pub fn find(&mut self, mut x_index: usize) -> usize { // Note: We avoid recursion here since the chains can be long, causing stack overflows. diff --git a/plonky2/src/plonk/proof.rs b/plonky2/src/plonk/proof.rs index 1a7a26db..d408d900 100644 --- a/plonky2/src/plonk/proof.rs +++ b/plonky2/src/plonk/proof.rs @@ -139,10 +139,7 @@ impl, C: GenericConfig, const D: usize> challenges: &ProofChallenges, fri_inferred_elements: FriInferredElements, params: &FriParams, - ) -> Proof - where - [(); C::Hasher::HASH_SIZE]:, - { + ) -> Proof { let CompressedProof { wires_cap, plonk_zs_partial_products_cap, @@ -179,10 +176,7 @@ impl, C: GenericConfig, const D: usize> self, circuit_digest: &<>::Hasher as Hasher>::Hash, common_data: &CommonCircuitData, - ) -> anyhow::Result> - where - [(); C::Hasher::HASH_SIZE]:, - { + ) -> anyhow::Result> { let challenges = self.get_challenges(self.get_public_inputs_hash(), circuit_digest, common_data)?; let fri_inferred_elements = self.get_inferred_elements(&challenges, common_data); @@ -199,10 +193,7 @@ impl, C: GenericConfig, const D: usize> self, verifier_data: &VerifierOnlyCircuitData, common_data: &CommonCircuitData, - ) -> anyhow::Result<()> - where - [(); C::Hasher::HASH_SIZE]:, - { + ) -> anyhow::Result<()> { ensure!( self.public_inputs.len() == common_data.num_public_inputs, "Number of public inputs doesn't match circuit data." diff --git a/plonky2/src/plonk/prover.rs b/plonky2/src/plonk/prover.rs index c762b5ba..c10febde 100644 --- a/plonky2/src/plonk/prover.rs +++ b/plonky2/src/plonk/prover.rs @@ -1,7 +1,6 @@ use core::mem::swap; -use anyhow::ensure; -use anyhow::Result; +use anyhow::{ensure, Result}; use maybe_rayon::*; use plonky2_field::extension::Extendable; use plonky2_field::polynomial::{PolynomialCoeffs, PolynomialValues}; @@ -17,8 +16,7 @@ use crate::iop::witness::{MatrixWitness, PartialWitness, Witness}; use crate::plonk::circuit_data::{CommonCircuitData, ProverOnlyCircuitData}; use crate::plonk::config::{GenericConfig, Hasher}; use crate::plonk::plonk_common::PlonkOracle; -use crate::plonk::proof::OpeningSet; -use crate::plonk::proof::{Proof, ProofWithPublicInputs}; +use crate::plonk::proof::{OpeningSet, Proof, ProofWithPublicInputs}; use crate::plonk::vanishing_poly::eval_vanishing_poly_base_batch; use crate::plonk::vars::EvaluationVarsBaseBatch; use crate::timed; @@ -31,10 +29,7 @@ pub fn prove, C: GenericConfig, const D: common_data: &CommonCircuitData, inputs: PartialWitness, timing: &mut TimingTree, -) -> Result> -where - [(); C::Hasher::HASH_SIZE]:, -{ +) -> Result> { let config = &common_data.config; let num_challenges = config.num_challenges; let quotient_degree = common_data.quotient_degree(); diff --git a/plonky2/src/plonk/validate_shape.rs b/plonky2/src/plonk/validate_shape.rs index 1e6708cc..81f43332 100644 --- a/plonky2/src/plonk/validate_shape.rs +++ b/plonky2/src/plonk/validate_shape.rs @@ -3,7 +3,7 @@ use plonky2_field::extension::Extendable; use crate::hash::hash_types::RichField; use crate::plonk::circuit_data::CommonCircuitData; -use crate::plonk::config::{GenericConfig, Hasher}; +use crate::plonk::config::GenericConfig; use crate::plonk::proof::{OpeningSet, Proof, ProofWithPublicInputs}; pub(crate) fn validate_proof_with_pis_shape( @@ -13,20 +13,16 @@ pub(crate) fn validate_proof_with_pis_shape( where F: RichField + Extendable, C: GenericConfig, - [(); C::Hasher::HASH_SIZE]:, { let ProofWithPublicInputs { proof, public_inputs, } = proof_with_pis; - validate_proof_shape(proof, common_data)?; - ensure!( public_inputs.len() == common_data.num_public_inputs, "Number of public inputs doesn't match circuit data." ); - Ok(()) } @@ -37,7 +33,6 @@ fn validate_proof_shape( where F: RichField + Extendable, C: GenericConfig, - [(); C::Hasher::HASH_SIZE]:, { let config = &common_data.config; let Proof { @@ -49,7 +44,6 @@ where // validate_fri_proof_shape), so we ignore it here. opening_proof: _, } = proof; - let OpeningSet { constants, plonk_sigmas, @@ -59,12 +53,10 @@ where partial_products, quotient_polys, } = openings; - let cap_height = common_data.fri_params.config.cap_height; ensure!(wires_cap.height() == cap_height); ensure!(plonk_zs_partial_products_cap.height() == cap_height); ensure!(quotient_polys_cap.height() == cap_height); - ensure!(constants.len() == common_data.num_constants); ensure!(plonk_sigmas.len() == config.num_routed_wires); ensure!(wires.len() == config.num_wires); @@ -72,6 +64,5 @@ where ensure!(plonk_zs_next.len() == config.num_challenges); ensure!(partial_products.len() == config.num_challenges * common_data.num_partial_products); ensure!(quotient_polys.len() == common_data.num_quotient_polys()); - Ok(()) } diff --git a/plonky2/src/plonk/vars.rs b/plonky2/src/plonk/vars.rs index 5be573fc..722ebdf1 100644 --- a/plonky2/src/plonk/vars.rs +++ b/plonky2/src/plonk/vars.rs @@ -85,6 +85,10 @@ impl<'a, F: Field> EvaluationVarsBaseBatch<'a, F> { self.batch_size } + pub fn is_empty(&self) -> bool { + self.len() == 0 + } + pub fn view(&self, index: usize) -> EvaluationVarsBase<'a, F> { // We cannot implement `Index` as `EvaluationVarsBase` is a struct, not a reference. assert!(index < self.len()); diff --git a/plonky2/src/plonk/verifier.rs b/plonky2/src/plonk/verifier.rs index 52681558..ba477264 100644 --- a/plonky2/src/plonk/verifier.rs +++ b/plonky2/src/plonk/verifier.rs @@ -16,10 +16,7 @@ pub(crate) fn verify, C: GenericConfig, c proof_with_pis: ProofWithPublicInputs, verifier_data: &VerifierOnlyCircuitData, common_data: &CommonCircuitData, -) -> Result<()> -where - [(); C::Hasher::HASH_SIZE]:, -{ +) -> Result<()> { validate_proof_with_pis_shape(&proof_with_pis, common_data)?; let public_inputs_hash = proof_with_pis.get_public_inputs_hash(); @@ -48,10 +45,7 @@ pub(crate) fn verify_with_challenges< challenges: ProofChallenges, verifier_data: &VerifierOnlyCircuitData, common_data: &CommonCircuitData, -) -> Result<()> -where - [(); C::Hasher::HASH_SIZE]:, -{ +) -> Result<()> { let local_constants = &proof.openings.constants; let local_wires = &proof.openings.wires; let vars = EvaluationVars { diff --git a/plonky2/src/recursion/conditional_recursive_verifier.rs b/plonky2/src/recursion/conditional_recursive_verifier.rs index 6bafc623..c78078e8 100644 --- a/plonky2/src/recursion/conditional_recursive_verifier.rs +++ b/plonky2/src/recursion/conditional_recursive_verifier.rs @@ -17,7 +17,7 @@ use crate::plonk::circuit_builder::CircuitBuilder; use crate::plonk::circuit_data::{ CommonCircuitData, VerifierCircuitTarget, VerifierOnlyCircuitData, }; -use crate::plonk::config::{AlgebraicHasher, GenericConfig, Hasher}; +use crate::plonk::config::{AlgebraicHasher, GenericConfig}; use crate::plonk::proof::{ OpeningSetTarget, ProofTarget, ProofWithPublicInputs, ProofWithPublicInputsTarget, }; @@ -33,10 +33,7 @@ pub(crate) fn dummy_proof< ) -> Result<( ProofWithPublicInputs, VerifierOnlyCircuitData, -)> -where - [(); C::Hasher::HASH_SIZE]:, -{ +)> { let config = common_data.config.clone(); let mut pw = PartialWitness::new(); diff --git a/plonky2/src/recursion/cyclic_recursion.rs b/plonky2/src/recursion/cyclic_recursion.rs index f2ad7eb9..9df74c56 100644 --- a/plonky2/src/recursion/cyclic_recursion.rs +++ b/plonky2/src/recursion/cyclic_recursion.rs @@ -12,7 +12,6 @@ use crate::plonk::circuit_builder::CircuitBuilder; use crate::plonk::circuit_data::{ CommonCircuitData, VerifierCircuitTarget, VerifierOnlyCircuitData, }; -use crate::plonk::config::Hasher; use crate::plonk::config::{AlgebraicHasher, GenericConfig}; use crate::plonk::proof::{ProofWithPublicInputs, ProofWithPublicInputsTarget}; use crate::recursion::conditional_recursive_verifier::dummy_proof; @@ -100,7 +99,6 @@ impl, const D: usize> CircuitBuilder { ) -> Result> where C::Hasher: AlgebraicHasher, - [(); C::Hasher::HASH_SIZE]:, { if self.verifier_data_public_input.is_none() { self.add_verifier_data_public_input(); @@ -179,7 +177,6 @@ pub fn set_cyclic_recursion_data_target< ) -> Result<()> where C::Hasher: AlgebraicHasher, - [(); C::Hasher::HASH_SIZE]:, { if let Some(proof) = cyclic_recursion_data.proof { pw.set_bool_target(cyclic_recursion_data_target.base_case, false); @@ -280,7 +277,6 @@ mod tests { >() -> CommonCircuitData where C::Hasher: AlgebraicHasher, - [(); C::Hasher::HASH_SIZE]:, { let config = CircuitConfig::standard_recursion_config(); let builder = CircuitBuilder::::new(config); diff --git a/plonky2/src/recursion/recursive_verifier.rs b/plonky2/src/recursion/recursive_verifier.rs index 8dbab974..5ddfef01 100644 --- a/plonky2/src/recursion/recursive_verifier.rs +++ b/plonky2/src/recursion/recursive_verifier.rs @@ -323,18 +323,17 @@ mod tests { Ok(()) } + type Proof = ( + ProofWithPublicInputs, + VerifierOnlyCircuitData, + CommonCircuitData, + ); + /// Creates a dummy proof which should have roughly `num_dummy_gates` gates. fn dummy_proof, C: GenericConfig, const D: usize>( config: &CircuitConfig, num_dummy_gates: u64, - ) -> Result<( - ProofWithPublicInputs, - VerifierOnlyCircuitData, - CommonCircuitData, - )> - where - [(); C::Hasher::HASH_SIZE]:, - { + ) -> Result> { let mut builder = CircuitBuilder::::new(config.clone()); for _ in 0..num_dummy_gates { builder.add_gate(NoopGate, vec![]); @@ -361,14 +360,9 @@ mod tests { min_degree_bits: Option, print_gate_counts: bool, print_timing: bool, - ) -> Result<( - ProofWithPublicInputs, - VerifierOnlyCircuitData, - CommonCircuitData, - )> + ) -> Result> where InnerC::Hasher: AlgebraicHasher, - [(); C::Hasher::HASH_SIZE]:, { let mut builder = CircuitBuilder::::new(config.clone()); let mut pw = PartialWitness::new(); @@ -423,10 +417,7 @@ mod tests { proof: &ProofWithPublicInputs, vd: &VerifierOnlyCircuitData, cd: &CommonCircuitData, - ) -> Result<()> - where - [(); C::Hasher::HASH_SIZE]:, - { + ) -> Result<()> { let proof_bytes = proof.to_bytes()?; info!("Proof length: {} bytes", proof_bytes.len()); let proof_from_bytes = ProofWithPublicInputs::from_bytes(proof_bytes, cd)?; diff --git a/plonky2/src/util/reducing.rs b/plonky2/src/util/reducing.rs index 89b4a4ad..9702e196 100644 --- a/plonky2/src/util/reducing.rs +++ b/plonky2/src/util/reducing.rs @@ -19,7 +19,7 @@ use crate::plonk::circuit_builder::CircuitBuilder; /// scale the second one by `a^(r-1-k)`, and add them up. /// This struct abstract away these operations by implementing Horner's method and keeping track /// of the number of multiplications by `a` to compute the scaling factor. -/// See https://github.com/mir-protocol/plonky2/pull/69 for more details and discussions. +/// See for more details and discussions. #[derive(Debug, Clone)] pub struct ReducingFactor { base: F, diff --git a/plonky2/src/util/serialization.rs b/plonky2/src/util/serialization.rs index 076e42f4..de8961ae 100644 --- a/plonky2/src/util/serialization.rs +++ b/plonky2/src/util/serialization.rs @@ -1,6 +1,5 @@ use std::collections::HashMap; -use std::io::Cursor; -use std::io::{Read, Result, Write}; +use std::io::{Cursor, Read, Result, Write}; use plonky2_field::extension::{Extendable, FieldExtension}; use plonky2_field::polynomial::PolynomialCoeffs; @@ -32,6 +31,10 @@ impl Buffer { self.0.get_ref().len() } + pub fn is_empty(&self) -> bool { + self.len() == 0 + } + pub fn bytes(self) -> Vec { self.0.into_inner() } @@ -60,9 +63,7 @@ impl Buffer { fn read_field(&mut self) -> Result { let mut buf = [0; std::mem::size_of::()]; self.0.read_exact(&mut buf)?; - Ok(F::from_canonical_u64(u64::from_le_bytes( - buf.try_into().unwrap(), - ))) + Ok(F::from_canonical_u64(u64::from_le_bytes(buf))) } fn write_field_ext, const D: usize>( diff --git a/plonky2/src/util/strided_view.rs b/plonky2/src/util/strided_view.rs index 851914bf..43fd4894 100644 --- a/plonky2/src/util/strided_view.rs +++ b/plonky2/src/util/strided_view.rs @@ -123,6 +123,11 @@ impl<'a, P: PackedField> PackedStridedView<'a, P> { pub fn len(&self) -> usize { self.length } + + #[inline] + pub fn is_empty(&self) -> bool { + self.len() == 0 + } } impl<'a, P: PackedField> Index for PackedStridedView<'a, P> { diff --git a/rustfmt.toml b/rustfmt.toml index 65106950..4d029471 100644 --- a/rustfmt.toml +++ b/rustfmt.toml @@ -1,2 +1,3 @@ -unstable_features = true group_imports = "StdExternalCrate" +imports_granularity = "Module" +unstable_features = true diff --git a/starky/src/prover.rs b/starky/src/prover.rs index 0d291cf3..c9191f1d 100644 --- a/starky/src/prover.rs +++ b/starky/src/prover.rs @@ -20,9 +20,9 @@ use plonky2_util::{log2_ceil, log2_strict}; use crate::config::StarkConfig; use crate::constraint_consumer::ConstraintConsumer; -use crate::permutation::PermutationCheckVars; use crate::permutation::{ compute_permutation_z_polys, get_n_permutation_challenge_sets, PermutationChallengeSet, + PermutationCheckVars, }; use crate::proof::{StarkOpeningSet, StarkProof, StarkProofWithPublicInputs}; use crate::stark::Stark; diff --git a/starky/src/stark.rs b/starky/src/stark.rs index 8ebca87c..668fc4a2 100644 --- a/starky/src/stark.rs +++ b/starky/src/stark.rs @@ -12,8 +12,7 @@ use plonky2_util::ceil_div_usize; use crate::config::StarkConfig; use crate::constraint_consumer::{ConstraintConsumer, RecursiveConstraintConsumer}; use crate::permutation::PermutationPair; -use crate::vars::StarkEvaluationTargets; -use crate::vars::StarkEvaluationVars; +use crate::vars::{StarkEvaluationTargets, StarkEvaluationVars}; /// Represents a STARK system. pub trait Stark, const D: usize>: Sync { diff --git a/starky/src/stark_testing.rs b/starky/src/stark_testing.rs index b13b90df..2cec5298 100644 --- a/starky/src/stark_testing.rs +++ b/starky/src/stark_testing.rs @@ -6,8 +6,7 @@ use plonky2::hash::hash_types::RichField; use plonky2::iop::witness::{PartialWitness, Witness}; use plonky2::plonk::circuit_builder::CircuitBuilder; use plonky2::plonk::circuit_data::CircuitConfig; -use plonky2::plonk::config::GenericConfig; -use plonky2::plonk::config::Hasher; +use plonky2::plonk::config::{GenericConfig, Hasher}; use plonky2::util::transpose; use plonky2_util::{log2_ceil, log2_strict}; diff --git a/system_zero/src/alu/mod.rs b/system_zero/src/alu/mod.rs index 33f5e902..a02a51e2 100644 --- a/system_zero/src/alu/mod.rs +++ b/system_zero/src/alu/mod.rs @@ -4,8 +4,7 @@ use plonky2::field::types::{Field, PrimeField64}; use plonky2::hash::hash_types::RichField; use plonky2::plonk::circuit_builder::CircuitBuilder; use starky::constraint_consumer::{ConstraintConsumer, RecursiveConstraintConsumer}; -use starky::vars::StarkEvaluationTargets; -use starky::vars::StarkEvaluationVars; +use starky::vars::{StarkEvaluationTargets, StarkEvaluationVars}; use crate::alu::addition::{eval_addition, eval_addition_circuit, generate_addition}; use crate::alu::bitops::{eval_bitop, eval_bitop_circuit, generate_bitop}; diff --git a/system_zero/src/core_registers.rs b/system_zero/src/core_registers.rs index 3cf7843d..210a9971 100644 --- a/system_zero/src/core_registers.rs +++ b/system_zero/src/core_registers.rs @@ -4,8 +4,7 @@ use plonky2::field::types::{Field, PrimeField64}; use plonky2::hash::hash_types::RichField; use plonky2::plonk::circuit_builder::CircuitBuilder; use starky::constraint_consumer::{ConstraintConsumer, RecursiveConstraintConsumer}; -use starky::vars::StarkEvaluationTargets; -use starky::vars::StarkEvaluationVars; +use starky::vars::{StarkEvaluationTargets, StarkEvaluationVars}; use crate::public_input_layout::NUM_PUBLIC_INPUTS; use crate::registers::core::*; diff --git a/system_zero/src/lookup.rs b/system_zero/src/lookup.rs index c4036424..d1d16223 100644 --- a/system_zero/src/lookup.rs +++ b/system_zero/src/lookup.rs @@ -13,8 +13,7 @@ use plonky2::field::types::{Field, PrimeField64}; use plonky2::hash::hash_types::RichField; use plonky2::plonk::circuit_builder::CircuitBuilder; use starky::constraint_consumer::{ConstraintConsumer, RecursiveConstraintConsumer}; -use starky::vars::StarkEvaluationTargets; -use starky::vars::StarkEvaluationVars; +use starky::vars::{StarkEvaluationTargets, StarkEvaluationVars}; use crate::public_input_layout::NUM_PUBLIC_INPUTS; use crate::registers::lookup::*; diff --git a/system_zero/src/permutation_unit.rs b/system_zero/src/permutation_unit.rs index c94e1677..809955ca 100644 --- a/system_zero/src/permutation_unit.rs +++ b/system_zero/src/permutation_unit.rs @@ -5,8 +5,7 @@ use plonky2::hash::hashing::SPONGE_WIDTH; use plonky2::hash::poseidon::{Poseidon, HALF_N_FULL_ROUNDS, N_PARTIAL_ROUNDS}; use plonky2::plonk::circuit_builder::CircuitBuilder; use starky::constraint_consumer::{ConstraintConsumer, RecursiveConstraintConsumer}; -use starky::vars::StarkEvaluationTargets; -use starky::vars::StarkEvaluationVars; +use starky::vars::{StarkEvaluationTargets, StarkEvaluationVars}; use crate::public_input_layout::NUM_PUBLIC_INPUTS; use crate::registers::permutation::*; diff --git a/system_zero/src/system_zero.rs b/system_zero/src/system_zero.rs index 19c2df8c..00673c7e 100644 --- a/system_zero/src/system_zero.rs +++ b/system_zero/src/system_zero.rs @@ -11,8 +11,7 @@ use plonky2::util::transpose; use starky::constraint_consumer::{ConstraintConsumer, RecursiveConstraintConsumer}; use starky::permutation::PermutationPair; use starky::stark::Stark; -use starky::vars::StarkEvaluationTargets; -use starky::vars::StarkEvaluationVars; +use starky::vars::{StarkEvaluationTargets, StarkEvaluationVars}; use crate::alu::{eval_alu, eval_alu_circuit, generate_alu}; use crate::core_registers::{ diff --git a/u32/src/gates/arithmetic_u32.rs b/u32/src/gates/arithmetic_u32.rs index 47889954..575f3055 100644 --- a/u32/src/gates/arithmetic_u32.rs +++ b/u32/src/gates/arithmetic_u32.rs @@ -416,8 +416,7 @@ mod tests { use anyhow::Result; use plonky2::gates::gate::Gate; use plonky2::gates::gate_testing::{test_eval_fns, test_low_degree}; - use plonky2::hash::hash_types::HashOut; - use plonky2::hash::hash_types::RichField; + use plonky2::hash::hash_types::{HashOut, RichField}; use plonky2::plonk::config::{GenericConfig, PoseidonGoldilocksConfig}; use plonky2::plonk::vars::EvaluationVars; use plonky2_field::extension::Extendable; diff --git a/u32/src/gates/comparison.rs b/u32/src/gates/comparison.rs index a2a0cfcf..cbb689e7 100644 --- a/u32/src/gates/comparison.rs +++ b/u32/src/gates/comparison.rs @@ -521,8 +521,7 @@ mod tests { use plonky2::plonk::config::{GenericConfig, PoseidonGoldilocksConfig}; use plonky2::plonk::vars::EvaluationVars; use plonky2_field::goldilocks_field::GoldilocksField; - use plonky2_field::types::Field; - use plonky2_field::types::PrimeField64; + use plonky2_field::types::{Field, PrimeField64}; use rand::Rng; use crate::gates::comparison::ComparisonGate; diff --git a/u32/src/gates/subtraction_u32.rs b/u32/src/gates/subtraction_u32.rs index b08d900b..d29b2348 100644 --- a/u32/src/gates/subtraction_u32.rs +++ b/u32/src/gates/subtraction_u32.rs @@ -339,8 +339,7 @@ mod tests { use plonky2::plonk::vars::EvaluationVars; use plonky2_field::extension::quartic::QuarticExtension; use plonky2_field::goldilocks_field::GoldilocksField; - use plonky2_field::types::Field; - use plonky2_field::types::PrimeField64; + use plonky2_field::types::{Field, PrimeField64}; use rand::Rng; use crate::gates::subtraction_u32::U32SubtractionGate; diff --git a/waksman/src/gates/assert_le.rs b/waksman/src/gates/assert_le.rs index 27242370..7f60fcac 100644 --- a/waksman/src/gates/assert_le.rs +++ b/waksman/src/gates/assert_le.rs @@ -456,8 +456,7 @@ mod tests { use plonky2::plonk::vars::EvaluationVars; use plonky2_field::extension::quartic::QuarticExtension; use plonky2_field::goldilocks_field::GoldilocksField; - use plonky2_field::types::Field; - use plonky2_field::types::PrimeField64; + use plonky2_field::types::{Field, PrimeField64}; use rand::Rng; use crate::gates::assert_le::AssertLessThanGate; diff --git a/waksman/src/permutation.rs b/waksman/src/permutation.rs index 90dc5086..367386c4 100644 --- a/waksman/src/permutation.rs +++ b/waksman/src/permutation.rs @@ -1,7 +1,8 @@ use std::collections::BTreeMap; use std::marker::PhantomData; -use plonky2::field::{extension::Extendable, types::Field}; +use plonky2::field::extension::Extendable; +use plonky2::field::types::Field; use plonky2::hash::hash_types::RichField; use plonky2::iop::generator::{GeneratedValues, SimpleGenerator}; use plonky2::iop::target::Target; @@ -374,7 +375,8 @@ mod tests { use plonky2::iop::witness::PartialWitness; use plonky2::plonk::circuit_data::CircuitConfig; use plonky2::plonk::config::{GenericConfig, PoseidonGoldilocksConfig}; - use rand::{seq::SliceRandom, thread_rng, Rng}; + use rand::seq::SliceRandom; + use rand::{thread_rng, Rng}; use super::*;