Skip to content

Commit

Permalink
Merge pull request #20 from WizardOfMenlo/main
Browse files Browse the repository at this point in the history
Fix some clippy warnings
  • Loading branch information
WizardOfMenlo authored Nov 29, 2024
2 parents b28eb12 + ab0ce9f commit 9cc8bb1
Show file tree
Hide file tree
Showing 11 changed files with 27 additions and 24 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,4 @@ ark-serialize = { git = "https://github.com/arkworks-rs/algebra" }
ark-bls12-381 = { git = "https://github.com/arkworks-rs/algebra" }
ark-curve25519 = { git = "https://github.com/arkworks-rs/algebra" }
ark-pallas = { git = "https://github.com/arkworks-rs/algebra" }
ark-vesta = { git = "https://github.com/arkworks-rs/algebra" }
ark-vesta = { git = "https://github.com/arkworks-rs/algebra" }
1 change: 0 additions & 1 deletion nimue-anemoi/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
//!
//! The main reason for this code not being deployed is that [anemoi](https://anemoi-hash.github.io/)'s Rust implementation
//! is not published as a crate and thus `nimue` cannot publish it along with a new release.
use anemoi;
use ark_ff::{Field, PrimeField};
use zeroize::Zeroize;

Expand Down
7 changes: 4 additions & 3 deletions nimue-poseidon/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,12 +53,12 @@ impl<const NAME: u32, F: PrimeField, const R: usize, const N: usize> PoseidonSpo
// Full rounds apply the S Box (x^alpha) to every element of state
if is_full_round {
for elem in state {
*elem = elem.pow(&[self.alpha]);
*elem = elem.pow([self.alpha]);
}
}
// Partial rounds apply the S Box (x^alpha) to just the first element of state
else {
state[0] = state[0].pow(&[self.alpha]);
state[0] = state[0].pow([self.alpha]);
}
}

Expand All @@ -69,6 +69,7 @@ impl<const NAME: u32, F: PrimeField, const R: usize, const N: usize> PoseidonSpo
});
}

#[allow(clippy::needless_range_loop)]
fn apply_mds(&self, state: &mut [F]) {
let mut new_state = [F::ZERO; N];
for i in 0..N {
Expand Down Expand Up @@ -108,7 +109,7 @@ where

fn permute(&mut self) {
let full_rounds_over_2 = self.full_rounds / 2;
let mut state = self.state.clone();
let mut state = self.state;
for i in 0..full_rounds_over_2 {
self.apply_ark(&mut state, i);
self.apply_s_box(&mut state, true);
Expand Down
2 changes: 1 addition & 1 deletion nimue-pow/src/blake3.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ impl PowStrategy for Blake3PoW {
// Use atomics to find the unique deterministic lowest satisfying nonce.
let global_min = AtomicU64::new(u64::MAX);
let _ = broadcast(|ctx| {
let mut worker = self.clone();
let mut worker = *self;
let nonces = ((MAX_SIMD_DEGREE * ctx.index()) as u64..)
.step_by(MAX_SIMD_DEGREE * ctx.num_threads());
for nonce in nonces {
Expand Down
4 changes: 4 additions & 0 deletions nimue/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -58,3 +58,7 @@ required-features = ["ark"]
[[example]]
name = "bulletproof"
required-features = ["ark"]

[lints.clippy]
too_long_first_doc_paragraph = "allow"
doc_lazy_continuation = "allow"
4 changes: 2 additions & 2 deletions nimue/examples/bulletproof.rs
Original file line number Diff line number Diff line change
Expand Up @@ -107,8 +107,8 @@ where
{
let mut g = generators.0.to_vec();
let mut h = generators.1.to_vec();
let u = generators.2.clone();
let mut statement = statement.clone();
let u = *generators.2;
let mut statement = *statement;

while n != 1 {
let [left, right]: [G; 2] = arthur.next_points().unwrap();
Expand Down
1 change: 1 addition & 0 deletions nimue/src/arthur.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ use crate::traits::{ByteReader, UnitTranscript};
use crate::DefaultHash;

/// [`Arthur`] contains the verifier state.
///
/// Internally, it is a wrapper around a SAFE sponge.
/// Given as input an [`IOPattern`] and a protocol transcript, it allows to
/// de-serialize elements from the transcript and make them available to the zero-knowledge verifier.
Expand Down
8 changes: 4 additions & 4 deletions nimue/src/hash/legacy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ impl<D: BlockSizeUser + Digest + Clone + Reset> DigestBridge<D> {
// and the current digest
let byte_count = count * Self::DIGEST_SIZE - self.leftovers.len();
let mut squeeze_hasher = D::new();
Digest::update(&mut squeeze_hasher, &Self::mask_squeeze_end());
Digest::update(&mut squeeze_hasher, Self::mask_squeeze_end());
Digest::update(&mut squeeze_hasher, &self.cv);
Digest::update(&mut squeeze_hasher, byte_count.to_be_bytes());
self.cv = Digest::finalize(squeeze_hasher);
Expand Down Expand Up @@ -127,7 +127,7 @@ impl<D: BlockSizeUser + Digest + Clone + FixedOutputReset> DuplexHash<u8> for Di

if self.mode == Mode::Start {
self.mode = Mode::Absorb;
Digest::update(&mut self.hasher, &Self::mask_absorb());
Digest::update(&mut self.hasher, Self::mask_absorb());
Digest::update(&mut self.hasher, &self.cv);
}

Expand All @@ -138,7 +138,7 @@ impl<D: BlockSizeUser + Digest + Clone + FixedOutputReset> DuplexHash<u8> for Di
fn ratchet_unchecked(&mut self) -> &mut Self {
self.squeeze_end();
// Double hash
self.cv = <D as Digest>::digest(&self.hasher.finalize_reset());
self.cv = <D as Digest>::digest(self.hasher.finalize_reset());
// Restart the rest of the data
self.leftovers.zeroize();
self.leftovers.clear();
Expand All @@ -150,7 +150,7 @@ impl<D: BlockSizeUser + Digest + Clone + FixedOutputReset> DuplexHash<u8> for Di
if self.mode == Mode::Start {
self.mode = Mode::Squeeze(0);
// create the prefix hash
Digest::update(&mut self.hasher, &Self::mask_squeeze());
Digest::update(&mut self.hasher, Self::mask_squeeze());
Digest::update(&mut self.hasher, &self.cv);
self.squeeze_unchecked(output)
// If Absorbing, ratchet
Expand Down
18 changes: 8 additions & 10 deletions nimue/src/plugins/ark/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,9 +109,8 @@ where

fn public_scalars(&mut self, input: &[F]) -> ProofResult<Self::Repr> {
let flattened: Vec<_> = input
.into_iter()
.map(|f| f.to_base_prime_field_elements())
.flatten()
.iter()
.flat_map(|f| f.to_base_prime_field_elements())
.collect();
self.public_units(&flattened)?;
Ok(())
Expand Down Expand Up @@ -147,9 +146,8 @@ where

fn public_scalars(&mut self, input: &[F]) -> ProofResult<Self::Repr> {
let flattened: Vec<_> = input
.into_iter()
.map(|f| f.to_base_prime_field_elements())
.flatten()
.iter()
.flat_map(|f| f.to_base_prime_field_elements())
.collect();
self.public_units(&flattened)?;
Ok(())
Expand Down Expand Up @@ -206,7 +204,7 @@ where
}
}

impl<'a, H, R, C, const N: usize> BytePublic for Merlin<H, Fp<C, N>, R>
impl<H, R, C, const N: usize> BytePublic for Merlin<H, Fp<C, N>, R>
where
C: FpConfig<N>,
H: DuplexHash<Fp<C, N>>,
Expand All @@ -220,14 +218,14 @@ where
}
}

impl<'a, H, R, C, const N: usize> ByteChallenges for Merlin<H, Fp<C, N>, R>
impl<H, R, C, const N: usize> ByteChallenges for Merlin<H, Fp<C, N>, R>
where
C: FpConfig<N>,
H: DuplexHash<Fp<C, N>>,
R: CryptoRng + rand::RngCore,
{
fn fill_challenge_bytes(&mut self, output: &mut [u8]) -> Result<(), IOPatternError> {
if output == &[] {
if output.is_empty() {
Ok(())
} else {
let len_good = usize::min(
Expand All @@ -252,7 +250,7 @@ where
H: DuplexHash<Fp<C, N>>,
{
fn fill_challenge_bytes(&mut self, output: &mut [u8]) -> Result<(), IOPatternError> {
if output == &[] {
if output.is_empty() {
Ok(())
} else {
let len_good = usize::min(
Expand Down
2 changes: 1 addition & 1 deletion nimue/src/plugins/ark/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ pub fn swap_field<F1: ark_ff::PrimeField, F2: ark_ff::PrimeField>(a_f1: F1) -> P
let a_f2 = F2::from_le_bytes_mod_order(&a_f1.into_bigint().to_bytes_le());
let a_f1_control = F1::from_le_bytes_mod_order(&a_f2.into_bigint().to_bytes_le());
(a_f1 == a_f1_control)
.then(|| a_f2)
.then_some(a_f2)
.ok_or(ProofError::SerializationError)
}

Expand Down
2 changes: 1 addition & 1 deletion nimue/src/plugins/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ pub(super) fn random_bits_in_random_modp<const N: usize>(b: ark_ff::BigInt<N>) -
// compute the remainder of b by 2^n
let r_bits = &b.to_bits_le()[..n as usize];
let r = BigInt::<N>::from_bits_le(r_bits);
let log2_a_minus_r = r_bits.into_iter().rev().skip_while(|&&bit| bit).count() as u32;
let log2_a_minus_r = r_bits.iter().rev().skip_while(|&&bit| bit).count() as u32;
if b.num_bits() + n - 1 - r.num_bits() - log2_a_minus_r >= 128 {
return n as usize;
}
Expand Down

0 comments on commit 9cc8bb1

Please sign in to comment.