mirror of
https://github.com/logos-storage/plonky2.git
synced 2026-01-04 23:03:08 +00:00
Address some clippy warnings
This commit is contained in:
parent
c684193033
commit
af4c8734ce
@ -14,8 +14,8 @@ const EXPONENT: usize = 1000000000;
|
||||
|
||||
fn main() {
|
||||
let mut bases = [F::ZERO; WIDTH];
|
||||
for i in 0..WIDTH {
|
||||
bases[i] = F::rand();
|
||||
for base_i in bases.iter_mut() {
|
||||
*base_i = F::rand();
|
||||
}
|
||||
let mut state = [F::ONE; WIDTH];
|
||||
|
||||
|
||||
@ -3,9 +3,8 @@ use std::time::Instant;
|
||||
use rayon::prelude::*;
|
||||
|
||||
use plonky2::field::crandall_field::CrandallField;
|
||||
use plonky2::field::fft;
|
||||
use plonky2::field::field::Field;
|
||||
use plonky2::polynomial::polynomial::{PolynomialCoeffs, PolynomialValues};
|
||||
use plonky2::polynomial::polynomial::PolynomialValues;
|
||||
|
||||
type F = CrandallField;
|
||||
|
||||
@ -18,9 +17,9 @@ fn main() {
|
||||
|
||||
let start = Instant::now();
|
||||
(0usize..PROVER_POLYS).into_par_iter().for_each(|i| {
|
||||
let mut values = vec![CrandallField::ZERO; DEGREE];
|
||||
let mut values = vec![F::ZERO; DEGREE];
|
||||
for j in 0usize..DEGREE {
|
||||
values[j] = CrandallField((i * j) as u64);
|
||||
values[j] = F::from_canonical_u64((i * j) as u64);
|
||||
}
|
||||
let poly_values = PolynomialValues::new(values);
|
||||
let start = Instant::now();
|
||||
|
||||
@ -1,24 +1,14 @@
|
||||
use std::thread;
|
||||
use std::time::Instant;
|
||||
|
||||
use env_logger::Env;
|
||||
use rayon::prelude::*;
|
||||
|
||||
use plonky2::circuit_builder::CircuitBuilder;
|
||||
use plonky2::circuit_data::CircuitConfig;
|
||||
use plonky2::field::crandall_field::CrandallField;
|
||||
use plonky2::field::fft;
|
||||
use plonky2::field::field::Field;
|
||||
use plonky2::gates::constant::ConstantGate;
|
||||
use plonky2::gates::gmimc::GMiMCGate;
|
||||
use plonky2::gmimc::gmimc_permute_array;
|
||||
use plonky2::hash::{GMIMC_CONSTANTS, GMIMC_ROUNDS};
|
||||
use plonky2::polynomial::polynomial::PolynomialCoeffs;
|
||||
use plonky2::hash::GMIMC_ROUNDS;
|
||||
use plonky2::witness::PartialWitness;
|
||||
|
||||
// 113 wire polys, 3 Z polys, 4 parts of quotient poly.
|
||||
const PROVER_POLYS: usize = 113 + 3 + 4;
|
||||
|
||||
fn main() {
|
||||
// Set the default log filter. This can be overridden using the `RUST_LOG` environment variable,
|
||||
// e.g. `RUST_LOG=debug`.
|
||||
|
||||
@ -53,5 +53,5 @@ fn is_prime(n: u64) -> bool {
|
||||
d += 2;
|
||||
}
|
||||
|
||||
return true;
|
||||
true
|
||||
}
|
||||
|
||||
@ -69,6 +69,7 @@ impl Field for CrandallField {
|
||||
*self * *self * *self
|
||||
}
|
||||
|
||||
#[allow(clippy::many_single_char_names)] // The names are from the paper.
|
||||
fn try_inverse(&self) -> Option<Self> {
|
||||
if self.is_zero() {
|
||||
return None;
|
||||
@ -164,6 +165,7 @@ impl Add for CrandallField {
|
||||
type Output = Self;
|
||||
|
||||
#[inline]
|
||||
#[allow(clippy::suspicious_arithmetic_impl)]
|
||||
fn add(self, rhs: Self) -> Self {
|
||||
let (sum, over) = self.0.overflowing_add(rhs.0);
|
||||
Self(sum.overflowing_sub((over as u64) * Self::ORDER).0)
|
||||
@ -180,6 +182,7 @@ impl Sub for CrandallField {
|
||||
type Output = Self;
|
||||
|
||||
#[inline]
|
||||
#[allow(clippy::suspicious_arithmetic_impl)]
|
||||
fn sub(self, rhs: Self) -> Self {
|
||||
let (diff, under) = self.0.overflowing_sub(rhs.0);
|
||||
Self(diff.overflowing_add((under as u64) * Self::ORDER).0)
|
||||
@ -212,6 +215,7 @@ impl MulAssign for CrandallField {
|
||||
impl Div for CrandallField {
|
||||
type Output = Self;
|
||||
|
||||
#[allow(clippy::suspicious_arithmetic_impl)]
|
||||
fn div(self, rhs: Self) -> Self::Output {
|
||||
self * rhs.inverse()
|
||||
}
|
||||
|
||||
@ -66,8 +66,8 @@ pub(crate) fn ifft_with_precomputation_power_of_2<F: Field>(
|
||||
fft_with_precomputation_power_of_2(PolynomialCoeffs { coeffs: values }, precomputation);
|
||||
|
||||
// We reverse all values except the first, and divide each by n.
|
||||
result[0] = result[0] * n_inv;
|
||||
result[n / 2] = result[n / 2] * n_inv;
|
||||
result[0] *= n_inv;
|
||||
result[n / 2] *= n_inv;
|
||||
for i in 1..(n / 2) {
|
||||
let j = n - i;
|
||||
let result_i = result[j] * n_inv;
|
||||
|
||||
@ -105,7 +105,7 @@ pub trait Field:
|
||||
let mut current = Self::ONE;
|
||||
for _i in 0..order {
|
||||
subgroup.push(current);
|
||||
current = current * generator;
|
||||
current *= generator;
|
||||
}
|
||||
subgroup
|
||||
}
|
||||
@ -149,7 +149,7 @@ pub trait Field:
|
||||
|
||||
for j in 0..power.bits() {
|
||||
if (power.to_canonical_u64() >> j & 1) != 0 {
|
||||
product = product * current;
|
||||
product *= current;
|
||||
}
|
||||
current = current.square();
|
||||
}
|
||||
|
||||
28
src/fri.rs
28
src/fri.rs
@ -126,13 +126,12 @@ fn fri_proof_of_work<F: Field>(current_hash: Hash<F>, config: &FriConfig) -> F {
|
||||
(0u64..)
|
||||
.find(|&i| {
|
||||
hash_n_to_1(
|
||||
Vec::from_iter(
|
||||
current_hash
|
||||
.elements
|
||||
.iter()
|
||||
.copied()
|
||||
.chain(Some(F::from_canonical_u64(i))),
|
||||
),
|
||||
current_hash
|
||||
.elements
|
||||
.iter()
|
||||
.copied()
|
||||
.chain(Some(F::from_canonical_u64(i)))
|
||||
.collect(),
|
||||
false,
|
||||
)
|
||||
.to_canonical_u64()
|
||||
@ -149,14 +148,13 @@ fn fri_verify_proof_of_work<F: Field>(
|
||||
config: &FriConfig,
|
||||
) -> Result<()> {
|
||||
let hash = hash_n_to_1(
|
||||
Vec::from_iter(
|
||||
challenger
|
||||
.get_hash()
|
||||
.elements
|
||||
.iter()
|
||||
.copied()
|
||||
.chain(Some(proof.pow_witness)),
|
||||
),
|
||||
challenger
|
||||
.get_hash()
|
||||
.elements
|
||||
.iter()
|
||||
.copied()
|
||||
.chain(Some(proof.pow_witness))
|
||||
.collect(),
|
||||
false,
|
||||
);
|
||||
ensure!(
|
||||
|
||||
@ -91,10 +91,8 @@ impl<F: Field> CircuitBuilder<F> {
|
||||
return Some(self.constant(x + y));
|
||||
}
|
||||
|
||||
if first_term_zero {
|
||||
if const_1.is_one() {
|
||||
return Some(addend);
|
||||
}
|
||||
if first_term_zero && const_1.is_one() {
|
||||
return Some(addend);
|
||||
}
|
||||
|
||||
if second_term_zero {
|
||||
|
||||
@ -35,7 +35,7 @@ pub fn gmimc_compress<F: Field, const R: usize>(
|
||||
F::ZERO,
|
||||
F::ZERO,
|
||||
];
|
||||
let state_1 = gmimc_permute::<F, 12, R>(state_0, constants.clone());
|
||||
let state_1 = gmimc_permute::<F, 12, R>(state_0, constants);
|
||||
[state_1[0], state_1[1], state_1[2], state_1[3]]
|
||||
}
|
||||
|
||||
@ -96,7 +96,7 @@ pub fn gmimc_permute_naive<F: Field, const W: usize, const R: usize>(
|
||||
let f = (xs[active] + constants[r]).cube();
|
||||
for i in 0..W {
|
||||
if i != active {
|
||||
xs[i] = xs[i] + f;
|
||||
xs[i] += f;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -173,9 +173,7 @@ impl<F: Field> CircuitBuilder<F> {
|
||||
// Overwrite the first r elements with the inputs. This differs from a standard sponge,
|
||||
// where we would xor or add in the inputs. This is a well-known variant, though,
|
||||
// sometimes called "overwrite mode".
|
||||
for i in 0..input_chunk.len() {
|
||||
state[i] = input_chunk[i];
|
||||
}
|
||||
state[..input_chunk.len()].copy_from_slice(input_chunk);
|
||||
state = self.permute(state);
|
||||
}
|
||||
|
||||
@ -268,10 +266,7 @@ pub(crate) fn merkle_root<F: Field>(vecs: Vec<Vec<F>>) -> Hash<F> {
|
||||
}
|
||||
|
||||
pub(crate) fn merkle_root_inner<F: Field>(vecs: Vec<Vec<F>>) -> Hash<F> {
|
||||
let mut hashes = vecs
|
||||
.into_iter()
|
||||
.map(|leaf_set| hash_or_noop(leaf_set))
|
||||
.collect::<Vec<_>>();
|
||||
let mut hashes = vecs.into_iter().map(hash_or_noop).collect::<Vec<_>>();
|
||||
while hashes.len() > 1 {
|
||||
hashes = hashes
|
||||
.chunks(2)
|
||||
|
||||
@ -107,6 +107,12 @@ impl<F: Field> Challenger<F> {
|
||||
}
|
||||
}
|
||||
|
||||
impl<F: Field> Default for Challenger<F> {
|
||||
fn default() -> Self {
|
||||
Self::new()
|
||||
}
|
||||
}
|
||||
|
||||
/// A recursive version of `Challenger`.
|
||||
pub(crate) struct RecursiveChallenger {
|
||||
sponge_state: [Target; SPONGE_WIDTH],
|
||||
|
||||
@ -9,15 +9,15 @@ use crate::util::log2_strict;
|
||||
pub(crate) fn divide_by_z_h<F: Field>(mut a: PolynomialCoeffs<F>, n: usize) -> PolynomialCoeffs<F> {
|
||||
// TODO: Is this special case needed?
|
||||
if a.coeffs.iter().all(|p| *p == F::ZERO) {
|
||||
return a.clone();
|
||||
return a;
|
||||
}
|
||||
|
||||
let g = F::MULTIPLICATIVE_GROUP_GENERATOR;
|
||||
let mut g_pow = F::ONE;
|
||||
// Multiply the i-th coefficient of `a` by `g^i`. Then `new_a(w^j) = old_a(g.w^j)`.
|
||||
a.coeffs.iter_mut().for_each(|x| {
|
||||
*x = (*x) * g_pow;
|
||||
g_pow = g * g_pow;
|
||||
*x *= g_pow;
|
||||
g_pow *= g;
|
||||
});
|
||||
|
||||
let root = F::primitive_root_of_unity(log2_strict(a.len()));
|
||||
@ -43,7 +43,7 @@ pub(crate) fn divide_by_z_h<F: Field>(mut a: PolynomialCoeffs<F>, n: usize) -> P
|
||||
.iter_mut()
|
||||
.zip(denominators_inv.iter())
|
||||
.for_each(|(x, &d)| {
|
||||
*x = (*x) * d;
|
||||
*x *= d;
|
||||
});
|
||||
// `p` is the interpolating polynomial of `a_eval` on `{w^i}`.
|
||||
let mut p = ifft(a_eval);
|
||||
@ -52,8 +52,8 @@ pub(crate) fn divide_by_z_h<F: Field>(mut a: PolynomialCoeffs<F>, n: usize) -> P
|
||||
let g_inv = g.inverse();
|
||||
let mut g_inv_pow = F::ONE;
|
||||
p.coeffs.iter_mut().for_each(|x| {
|
||||
*x = (*x) * g_inv_pow;
|
||||
g_inv_pow = g_inv_pow * g_inv;
|
||||
*x *= g_inv_pow;
|
||||
g_inv_pow *= g_inv;
|
||||
});
|
||||
p
|
||||
}
|
||||
|
||||
@ -31,7 +31,7 @@ impl<F: Field> PolynomialValues<F> {
|
||||
}
|
||||
|
||||
pub fn lde(self, rate_bits: usize) -> Self {
|
||||
let mut coeffs = ifft(self).lde(rate_bits);
|
||||
let coeffs = ifft(self).lde(rate_bits);
|
||||
fft(coeffs)
|
||||
}
|
||||
}
|
||||
@ -88,7 +88,7 @@ impl<F: Field> PolynomialCoeffs<F> {
|
||||
polys.into_iter().map(|p| p.lde(rate_bits)).collect()
|
||||
}
|
||||
|
||||
pub(crate) fn lde(mut self, rate_bits: usize) -> Self {
|
||||
pub(crate) fn lde(self, rate_bits: usize) -> Self {
|
||||
let original_size = self.len();
|
||||
let lde_size = original_size << rate_bits;
|
||||
let Self { mut coeffs } = self;
|
||||
|
||||
@ -79,3 +79,9 @@ impl<F: Field> PartialWitness<F> {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<F: Field> Default for PartialWitness<F> {
|
||||
fn default() -> Self {
|
||||
Self::new()
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user