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