mirror of
https://github.com/logos-storage/plonky2.git
synced 2026-01-06 15:53:10 +00:00
Clippy
This commit is contained in:
parent
288a0b7cf8
commit
7a2afb5119
@ -3,6 +3,7 @@
|
||||
use criterion::{criterion_group, criterion_main, BatchSize, Criterion};
|
||||
use plonky2::field::goldilocks_field::GoldilocksField;
|
||||
use plonky2::hash::gmimc::GMiMC;
|
||||
use plonky2::hash::hashing::SPONGE_WIDTH;
|
||||
use plonky2::hash::poseidon::Poseidon;
|
||||
use tynm::type_name;
|
||||
|
||||
@ -16,22 +17,22 @@ pub(crate) fn bench_gmimc<F: GMiMC<WIDTH>, const WIDTH: usize>(c: &mut Criterion
|
||||
});
|
||||
}
|
||||
|
||||
pub(crate) fn bench_poseidon<F: Poseidon<WIDTH>, const WIDTH: usize>(c: &mut Criterion)
|
||||
where
|
||||
[(); WIDTH - 1]:,
|
||||
{
|
||||
c.bench_function(&format!("poseidon<{}, {}>", type_name::<F>(), WIDTH), |b| {
|
||||
b.iter_batched(
|
||||
|| F::rand_arr::<WIDTH>(),
|
||||
|state| F::poseidon(state),
|
||||
BatchSize::SmallInput,
|
||||
)
|
||||
});
|
||||
pub(crate) fn bench_poseidon<F: Poseidon>(c: &mut Criterion) {
|
||||
c.bench_function(
|
||||
&format!("poseidon<{}, {}>", type_name::<F>(), SPONGE_WIDTH),
|
||||
|b| {
|
||||
b.iter_batched(
|
||||
|| F::rand_arr::<SPONGE_WIDTH>(),
|
||||
|state| F::poseidon(state),
|
||||
BatchSize::SmallInput,
|
||||
)
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
fn criterion_benchmark(c: &mut Criterion) {
|
||||
bench_gmimc::<GoldilocksField, 12>(c);
|
||||
bench_poseidon::<GoldilocksField, 12>(c);
|
||||
bench_poseidon::<GoldilocksField>(c);
|
||||
}
|
||||
|
||||
criterion_group!(benches, criterion_benchmark);
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
use std::borrow::Borrow;
|
||||
|
||||
use crate::field::extension_field::Extendable;
|
||||
use crate::field::field_types::{PrimeField, RichField};
|
||||
use crate::field::field_types::PrimeField;
|
||||
use crate::gates::arithmetic_base::ArithmeticGate;
|
||||
use crate::gates::exponentiation::ExponentiationGate;
|
||||
use crate::iop::target::{BoolTarget, Target};
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
use crate::field::extension_field::target::{ExtensionAlgebraTarget, ExtensionTarget};
|
||||
use crate::field::extension_field::FieldExtension;
|
||||
use crate::field::extension_field::{Extendable, OEF};
|
||||
use crate::field::field_types::{Field, PrimeField, RichField};
|
||||
use crate::field::field_types::{Field, PrimeField};
|
||||
use crate::gates::arithmetic_extension::ArithmeticExtensionGate;
|
||||
use crate::gates::multiplication_extension::MulExtensionGate;
|
||||
use crate::iop::generator::{GeneratedValues, SimpleGenerator};
|
||||
@ -553,7 +553,6 @@ mod tests {
|
||||
use anyhow::Result;
|
||||
|
||||
use crate::field::extension_field::algebra::ExtensionAlgebra;
|
||||
use crate::field::extension_field::quartic::QuarticExtension;
|
||||
use crate::field::extension_field::target::ExtensionAlgebraTarget;
|
||||
use crate::field::field_types::Field;
|
||||
use crate::iop::witness::{PartialWitness, Witness};
|
||||
|
||||
@ -250,7 +250,6 @@ mod tests {
|
||||
use crate::iop::witness::Witness;
|
||||
use crate::plonk::config::{GenericConfig, PoseidonGoldilocksConfig};
|
||||
use crate::{
|
||||
field::goldilocks_field::GoldilocksField,
|
||||
iop::witness::PartialWitness,
|
||||
plonk::{circuit_builder::CircuitBuilder, circuit_data::CircuitConfig, verifier::verify},
|
||||
};
|
||||
@ -260,7 +259,6 @@ mod tests {
|
||||
const D: usize = 2;
|
||||
type C = PoseidonGoldilocksConfig;
|
||||
type F = <C as GenericConfig<D>>::F;
|
||||
type FF = <C as GenericConfig<D>>::FE;
|
||||
let mut rng = rand::thread_rng();
|
||||
|
||||
let x_value = BigUint::from_u128(rng.gen()).unwrap();
|
||||
@ -291,7 +289,6 @@ mod tests {
|
||||
const D: usize = 2;
|
||||
type C = PoseidonGoldilocksConfig;
|
||||
type F = <C as GenericConfig<D>>::F;
|
||||
type FF = <C as GenericConfig<D>>::FE;
|
||||
let mut rng = rand::thread_rng();
|
||||
|
||||
let mut x_value = BigUint::from_u128(rng.gen()).unwrap();
|
||||
@ -322,7 +319,6 @@ mod tests {
|
||||
const D: usize = 2;
|
||||
type C = PoseidonGoldilocksConfig;
|
||||
type F = <C as GenericConfig<D>>::F;
|
||||
type FF = <C as GenericConfig<D>>::FE;
|
||||
let mut rng = rand::thread_rng();
|
||||
|
||||
let x_value = BigUint::from_u128(rng.gen()).unwrap();
|
||||
@ -353,7 +349,6 @@ mod tests {
|
||||
const D: usize = 2;
|
||||
type C = PoseidonGoldilocksConfig;
|
||||
type F = <C as GenericConfig<D>>::F;
|
||||
type FF = <C as GenericConfig<D>>::FE;
|
||||
let mut rng = rand::thread_rng();
|
||||
|
||||
let x_value = BigUint::from_u128(rng.gen()).unwrap();
|
||||
@ -380,7 +375,6 @@ mod tests {
|
||||
const D: usize = 2;
|
||||
type C = PoseidonGoldilocksConfig;
|
||||
type F = <C as GenericConfig<D>>::F;
|
||||
type FF = <C as GenericConfig<D>>::FE;
|
||||
let mut rng = rand::thread_rng();
|
||||
|
||||
let mut x_value = BigUint::from_u128(rng.gen()).unwrap();
|
||||
|
||||
@ -180,7 +180,6 @@ mod tests {
|
||||
use crate::curve::curve_types::{AffinePoint, Curve, CurveScalar};
|
||||
use crate::curve::secp256k1::Secp256K1;
|
||||
use crate::field::field_types::Field;
|
||||
use crate::field::goldilocks_field::GoldilocksField;
|
||||
use crate::field::secp256k1_base::Secp256K1Base;
|
||||
use crate::field::secp256k1_scalar::Secp256K1Scalar;
|
||||
use crate::iop::witness::PartialWitness;
|
||||
@ -194,7 +193,6 @@ mod tests {
|
||||
const D: usize = 2;
|
||||
type C = PoseidonGoldilocksConfig;
|
||||
type F = <C as GenericConfig<D>>::F;
|
||||
type FF = <C as GenericConfig<D>>::FE;
|
||||
|
||||
let config = CircuitConfig::standard_recursion_config();
|
||||
|
||||
@ -220,7 +218,6 @@ mod tests {
|
||||
const D: usize = 2;
|
||||
type C = PoseidonGoldilocksConfig;
|
||||
type F = <C as GenericConfig<D>>::F;
|
||||
type FF = <C as GenericConfig<D>>::FE;
|
||||
|
||||
let config = CircuitConfig::standard_recursion_config();
|
||||
|
||||
@ -248,7 +245,6 @@ mod tests {
|
||||
const D: usize = 2;
|
||||
type C = PoseidonGoldilocksConfig;
|
||||
type F = <C as GenericConfig<D>>::F;
|
||||
type FF = <C as GenericConfig<D>>::FE;
|
||||
|
||||
let config = CircuitConfig::standard_recursion_config();
|
||||
|
||||
@ -286,7 +282,6 @@ mod tests {
|
||||
const D: usize = 2;
|
||||
type C = PoseidonGoldilocksConfig;
|
||||
type F = <C as GenericConfig<D>>::F;
|
||||
type FF = <C as GenericConfig<D>>::FE;
|
||||
|
||||
let config = CircuitConfig::standard_recursion_config();
|
||||
|
||||
@ -318,7 +313,6 @@ mod tests {
|
||||
const D: usize = 2;
|
||||
type C = PoseidonGoldilocksConfig;
|
||||
type F = <C as GenericConfig<D>>::F;
|
||||
type FF = <C as GenericConfig<D>>::FE;
|
||||
|
||||
let config = CircuitConfig {
|
||||
num_routed_wires: 33,
|
||||
@ -354,7 +348,6 @@ mod tests {
|
||||
const D: usize = 2;
|
||||
type C = PoseidonGoldilocksConfig;
|
||||
type F = <C as GenericConfig<D>>::F;
|
||||
type FF = <C as GenericConfig<D>>::FE;
|
||||
|
||||
let config = CircuitConfig {
|
||||
num_routed_wires: 33,
|
||||
|
||||
@ -108,7 +108,6 @@ impl<F: RichField + Extendable<D>, const D: usize> CircuitBuilder<F, D> {
|
||||
mod tests {
|
||||
use anyhow::Result;
|
||||
|
||||
use crate::field::extension_field::quadratic::QuadraticExtension;
|
||||
use crate::field::extension_field::FieldExtension;
|
||||
use crate::field::field_types::Field;
|
||||
use crate::field::interpolation::interpolant;
|
||||
|
||||
@ -72,7 +72,6 @@ mod tests {
|
||||
use rand::Rng;
|
||||
|
||||
use crate::field::field_types::Field;
|
||||
use crate::field::goldilocks_field::GoldilocksField;
|
||||
use crate::iop::witness::PartialWitness;
|
||||
use crate::plonk::circuit_builder::CircuitBuilder;
|
||||
use crate::plonk::circuit_data::CircuitConfig;
|
||||
@ -83,7 +82,6 @@ mod tests {
|
||||
const D: usize = 2;
|
||||
type C = PoseidonGoldilocksConfig;
|
||||
type F = <C as GenericConfig<D>>::F;
|
||||
type FF = <C as GenericConfig<D>>::FE;
|
||||
let config = CircuitConfig::standard_recursion_config();
|
||||
let pw = PartialWitness::new();
|
||||
let mut builder = CircuitBuilder::<F, D>::new(config);
|
||||
|
||||
@ -214,7 +214,6 @@ mod tests {
|
||||
use anyhow::Result;
|
||||
|
||||
use crate::field::field_types::Field;
|
||||
use crate::field::goldilocks_field::GoldilocksField;
|
||||
use crate::field::secp256k1_base::Secp256K1Base;
|
||||
use crate::iop::witness::PartialWitness;
|
||||
use crate::plonk::circuit_builder::CircuitBuilder;
|
||||
|
||||
@ -3,9 +3,8 @@ use std::marker::PhantomData;
|
||||
use itertools::izip;
|
||||
|
||||
use crate::field::extension_field::Extendable;
|
||||
use crate::field::field_types::{Field, RichField};
|
||||
use crate::field::field_types::Field;
|
||||
use crate::gates::assert_le::AssertLessThanGate;
|
||||
use crate::gates::comparison::ComparisonGate;
|
||||
use crate::iop::generator::{GeneratedValues, SimpleGenerator};
|
||||
use crate::iop::target::{BoolTarget, Target};
|
||||
use crate::iop::witness::{PartitionWitness, Witness};
|
||||
|
||||
@ -211,6 +211,6 @@ mod tests {
|
||||
type C = PoseidonGoldilocksConfig;
|
||||
type F = <C as GenericConfig<D>>::F;
|
||||
let gate = ArithmeticGate::new_from_config(&CircuitConfig::standard_recursion_config());
|
||||
test_eval_fns::<GoldilocksField, C, _, D>(gate)
|
||||
test_eval_fns::<F, C, _, D>(gate)
|
||||
}
|
||||
}
|
||||
|
||||
@ -347,7 +347,7 @@ mod tests {
|
||||
const D: usize = 2;
|
||||
type C = PoseidonGoldilocksConfig;
|
||||
type F = <C as GenericConfig<D>>::F;
|
||||
test_eval_fns::<GoldilocksField, C, _, D>(U32ArithmeticGate::<GoldilocksField, D> {
|
||||
test_eval_fns::<F, C, _, D>(U32ArithmeticGate::<GoldilocksField, D> {
|
||||
num_ops: 3,
|
||||
_phantom: PhantomData,
|
||||
})
|
||||
|
||||
@ -488,9 +488,7 @@ mod tests {
|
||||
let num_bits = 20;
|
||||
let num_chunks = 4;
|
||||
|
||||
test_eval_fns::<GoldilocksField, C, _, D>(AssertLessThanGate::<_, D>::new(
|
||||
num_bits, num_chunks,
|
||||
))
|
||||
test_eval_fns::<F, C, _, D>(AssertLessThanGate::<_, D>::new(num_bits, num_chunks))
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
||||
@ -224,7 +224,6 @@ mod tests {
|
||||
use log::info;
|
||||
|
||||
use super::*;
|
||||
use crate::field::goldilocks_field::GoldilocksField;
|
||||
use crate::gadgets::interpolation::InterpolationGate;
|
||||
use crate::gates::arithmetic_extension::ArithmeticExtensionGate;
|
||||
use crate::gates::base_sum::BaseSumGate;
|
||||
|
||||
@ -406,7 +406,7 @@ mod tests {
|
||||
const D: usize = 2;
|
||||
type C = PoseidonGoldilocksConfig;
|
||||
type F = <C as GenericConfig<D>>::F;
|
||||
test_eval_fns::<GoldilocksField, C, _, D>(LowDegreeInterpolationGate::new(4))
|
||||
test_eval_fns::<F, C, _, D>(LowDegreeInterpolationGate::new(4))
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
||||
@ -203,6 +203,6 @@ mod tests {
|
||||
type C = PoseidonGoldilocksConfig;
|
||||
type F = <C as GenericConfig<D>>::F;
|
||||
let gate = MulExtensionGate::new_from_config(&CircuitConfig::standard_recursion_config());
|
||||
test_eval_fns::<GoldilocksField, C, _, D>(gate)
|
||||
test_eval_fns::<F, C, _, D>(gate)
|
||||
}
|
||||
}
|
||||
|
||||
@ -230,10 +230,8 @@ impl<F: RichField + Extendable<D> + Poseidon, const D: usize> SimpleGenerator<F>
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use crate::field::goldilocks_field::GoldilocksField;
|
||||
use crate::gates::gate_testing::{test_eval_fns, test_low_degree};
|
||||
use crate::gates::poseidon_mds::PoseidonMdsGate;
|
||||
use crate::hash::hashing::SPONGE_WIDTH;
|
||||
use crate::plonk::config::{GenericConfig, PoseidonGoldilocksConfig};
|
||||
|
||||
#[test]
|
||||
|
||||
@ -221,6 +221,6 @@ mod tests {
|
||||
const D: usize = 2;
|
||||
type C = PoseidonGoldilocksConfig;
|
||||
type F = <C as GenericConfig<D>>::F;
|
||||
test_eval_fns::<GoldilocksField, C, _, D>(ReducingExtensionGate::new(22))
|
||||
test_eval_fns::<F, C, _, D>(ReducingExtensionGate::new(22))
|
||||
}
|
||||
}
|
||||
|
||||
@ -337,7 +337,7 @@ mod tests {
|
||||
const D: usize = 2;
|
||||
type C = PoseidonGoldilocksConfig;
|
||||
type F = <C as GenericConfig<D>>::F;
|
||||
test_eval_fns::<GoldilocksField, C, _, D>(U32SubtractionGate::<GoldilocksField, D> {
|
||||
test_eval_fns::<F, C, _, D>(U32SubtractionGate::<GoldilocksField, D> {
|
||||
num_ops: 3,
|
||||
_phantom: PhantomData,
|
||||
})
|
||||
|
||||
@ -126,7 +126,7 @@ pub struct MerkleCapTarget(pub Vec<HashOutTarget>);
|
||||
#[derive(Eq, PartialEq, Copy, Clone, Debug)]
|
||||
pub struct BytesHash<const N: usize>(pub [u8; N]);
|
||||
impl<const N: usize> Serialize for BytesHash<N> {
|
||||
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
|
||||
fn serialize<S>(&self, _serializer: S) -> Result<S::Ok, S::Error>
|
||||
where
|
||||
S: Serializer,
|
||||
{
|
||||
@ -134,7 +134,7 @@ impl<const N: usize> Serialize for BytesHash<N> {
|
||||
}
|
||||
}
|
||||
impl<'de, const N: usize> Deserialize<'de> for BytesHash<N> {
|
||||
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
|
||||
fn deserialize<D>(_deserializer: D) -> Result<Self, D::Error>
|
||||
where
|
||||
D: Deserializer<'de>,
|
||||
{
|
||||
|
||||
@ -174,7 +174,6 @@ pub trait Poseidon: PrimeField {
|
||||
let mut res = 0u128;
|
||||
|
||||
// This is a hacky way of fully unrolling the loop.
|
||||
assert!(WIDTH <= 12);
|
||||
for i in 0..12 {
|
||||
if i < WIDTH {
|
||||
res += (v[(i + r) % WIDTH] as u128) << Self::MDS_MATRIX_EXPS[i];
|
||||
@ -230,7 +229,6 @@ pub trait Poseidon: PrimeField {
|
||||
}
|
||||
|
||||
// This is a hacky way of fully unrolling the loop.
|
||||
assert!(WIDTH <= 12);
|
||||
for r in 0..12 {
|
||||
if r < WIDTH {
|
||||
let sum = Self::mds_row_shf(r, &state);
|
||||
@ -296,7 +294,6 @@ pub trait Poseidon: PrimeField {
|
||||
fn partial_first_constant_layer<F: FieldExtension<D, BaseField = Self>, const D: usize>(
|
||||
state: &mut [F; WIDTH],
|
||||
) {
|
||||
assert!(WIDTH <= 12);
|
||||
for i in 0..12 {
|
||||
if i < WIDTH {
|
||||
state[i] += F::from_canonical_u64(Self::FAST_PARTIAL_FIRST_ROUND_CONSTANT[i]);
|
||||
@ -331,10 +328,8 @@ pub trait Poseidon: PrimeField {
|
||||
// c = 0
|
||||
result[0] = state[0];
|
||||
|
||||
assert!(WIDTH <= 12);
|
||||
for r in 1..12 {
|
||||
if r < WIDTH {
|
||||
assert!(WIDTH <= 12);
|
||||
for c in 1..12 {
|
||||
if c < WIDTH {
|
||||
// NB: FAST_PARTIAL_ROUND_INITIAL_MATRIX is stored in
|
||||
@ -388,7 +383,6 @@ pub trait Poseidon: PrimeField {
|
||||
// Set d = [M_00 | w^] dot [state]
|
||||
|
||||
let mut d_sum = (0u128, 0u32); // u160 accumulator
|
||||
assert!(WIDTH <= 12);
|
||||
for i in 1..12 {
|
||||
if i < WIDTH {
|
||||
let t = Self::FAST_PARTIAL_ROUND_W_HATS[r][i - 1] as u128;
|
||||
@ -403,7 +397,6 @@ pub trait Poseidon: PrimeField {
|
||||
// result = [d] concat [state[0] * v + state[shift up by 1]]
|
||||
let mut result = [Self::ZERO; WIDTH];
|
||||
result[0] = d;
|
||||
assert!(WIDTH <= 12);
|
||||
for i in 1..12 {
|
||||
if i < WIDTH {
|
||||
let t = Self::from_canonical_u64(Self::FAST_PARTIAL_ROUND_VS[r][i - 1]);
|
||||
@ -470,7 +463,6 @@ pub trait Poseidon: PrimeField {
|
||||
#[inline(always)]
|
||||
#[unroll_for_loops]
|
||||
fn constant_layer(state: &mut [Self; WIDTH], round_ctr: usize) {
|
||||
assert!(WIDTH <= 12);
|
||||
for i in 0..12 {
|
||||
if i < WIDTH {
|
||||
let round_constant = ALL_ROUND_CONSTANTS[i + WIDTH * round_ctr];
|
||||
@ -531,7 +523,6 @@ pub trait Poseidon: PrimeField {
|
||||
#[inline(always)]
|
||||
#[unroll_for_loops]
|
||||
fn sbox_layer(state: &mut [Self; WIDTH]) {
|
||||
assert!(WIDTH <= 12);
|
||||
for i in 0..12 {
|
||||
if i < WIDTH {
|
||||
state[i] = Self::sbox_monomial(state[i]);
|
||||
|
||||
@ -285,7 +285,7 @@ mod tests {
|
||||
let neg_one: u64 = F::NEG_ONE.to_canonical_u64();
|
||||
|
||||
#[rustfmt::skip]
|
||||
let test_vectors8: Vec<([u64; 8], [u64; 8])> = vec![
|
||||
let _test_vectors8: Vec<([u64; 8], [u64; 8])> = vec![
|
||||
([0, 0, 0, 0, 0, 0, 0, 0, ],
|
||||
[0x649eec3229475d06, 0x72afe85b8b600222, 0x816d0a50ddd39228, 0x5083133a721a187c,
|
||||
0xbb69bd7d90c490a6, 0xea1d33a65d0a3287, 0xb4d27542d2fba3bc, 0xf9756d565d90c20a, ]),
|
||||
|
||||
@ -2,6 +2,7 @@
|
||||
#![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)]
|
||||
#![feature(asm_sym)]
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user