mirror of
https://github.com/serai-dex/serai.git
synced 2025-12-08 20:29:23 +00:00
Further expand clippy workspace lints
Achieves a notable amount of reduced async and clones.
This commit is contained in:
@@ -102,7 +102,7 @@ where
|
||||
#[allow(non_snake_case)]
|
||||
pub(crate) fn prove<R: RngCore + CryptoRng, T: Clone + Transcript>(
|
||||
rng: &mut R,
|
||||
transcript: T,
|
||||
transcript: &T,
|
||||
generators: (Generators<G0>, Generators<G1>),
|
||||
ring: &[(G0, G1)],
|
||||
mut actual: usize,
|
||||
@@ -122,7 +122,7 @@ where
|
||||
#[allow(non_snake_case)]
|
||||
let mut R = original_R;
|
||||
|
||||
for i in ((actual + 1) .. (actual + RING_LEN + 1)).map(|i| i % RING_LEN) {
|
||||
for i in ((actual + 1) ..= (actual + RING_LEN)).map(|i| i % RING_LEN) {
|
||||
let e = Self::nonces(transcript.clone(), R);
|
||||
if i == 0 {
|
||||
match Re_0 {
|
||||
@@ -144,11 +144,10 @@ where
|
||||
r.0.zeroize();
|
||||
r.1.zeroize();
|
||||
break;
|
||||
// Generate a decoy response
|
||||
} else {
|
||||
s[i] = (G0::Scalar::random(&mut *rng), G1::Scalar::random(&mut *rng));
|
||||
}
|
||||
|
||||
// Generate a decoy response
|
||||
s[i] = (G0::Scalar::random(&mut *rng), G1::Scalar::random(&mut *rng));
|
||||
R = Self::R(generators, s[i], ring[i], e);
|
||||
}
|
||||
|
||||
@@ -159,7 +158,7 @@ where
|
||||
pub(crate) fn verify<R: RngCore + CryptoRng, T: Clone + Transcript>(
|
||||
&self,
|
||||
rng: &mut R,
|
||||
transcript: T,
|
||||
transcript: &T,
|
||||
generators: (Generators<G0>, Generators<G1>),
|
||||
batch: &mut (BatchVerifier<(), G0>, BatchVerifier<(), G1>),
|
||||
ring: &[(G0, G1)],
|
||||
|
||||
@@ -47,10 +47,8 @@ impl BitSignature {
|
||||
|
||||
pub(crate) const fn bits(&self) -> u8 {
|
||||
match self {
|
||||
BitSignature::ClassicLinear => 1,
|
||||
BitSignature::ConciseLinear => 2,
|
||||
BitSignature::EfficientLinear => 1,
|
||||
BitSignature::CompromiseLinear => 2,
|
||||
BitSignature::ClassicLinear | BitSignature::EfficientLinear => 1,
|
||||
BitSignature::ConciseLinear | BitSignature::CompromiseLinear => 2,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -60,10 +58,8 @@ impl BitSignature {
|
||||
|
||||
fn aos_form<G0: PrimeGroup, G1: PrimeGroup>(&self) -> Re<G0, G1> {
|
||||
match self {
|
||||
BitSignature::ClassicLinear => Re::e_default(),
|
||||
BitSignature::ConciseLinear => Re::e_default(),
|
||||
BitSignature::EfficientLinear => Re::R_default(),
|
||||
BitSignature::CompromiseLinear => Re::R_default(),
|
||||
BitSignature::ClassicLinear | BitSignature::ConciseLinear => Re::e_default(),
|
||||
BitSignature::EfficientLinear | BitSignature::CompromiseLinear => Re::R_default(),
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -129,7 +125,7 @@ where
|
||||
|
||||
let signature = Aos::prove(
|
||||
rng,
|
||||
transcript.clone(),
|
||||
transcript,
|
||||
generators,
|
||||
&Self::ring(*pow_2, commitments),
|
||||
usize::from(bits),
|
||||
@@ -155,7 +151,7 @@ where
|
||||
|
||||
self.signature.verify(
|
||||
rng,
|
||||
transcript.clone(),
|
||||
transcript,
|
||||
generators,
|
||||
batch,
|
||||
&Self::ring(*pow_2, self.commitments),
|
||||
|
||||
@@ -408,10 +408,8 @@ where
|
||||
Self::transcript(transcript, generators, keys);
|
||||
|
||||
let batch_capacity = match BitSignature::from(SIGNATURE) {
|
||||
BitSignature::ClassicLinear => 3,
|
||||
BitSignature::ConciseLinear => 3,
|
||||
BitSignature::EfficientLinear => (self.bits.len() + 1) * 3,
|
||||
BitSignature::CompromiseLinear => (self.bits.len() + 1) * 3,
|
||||
BitSignature::ClassicLinear | BitSignature::ConciseLinear => 3,
|
||||
BitSignature::EfficientLinear | BitSignature::CompromiseLinear => (self.bits.len() + 1) * 3,
|
||||
};
|
||||
let mut batch = (BatchVerifier::new(batch_capacity), BatchVerifier::new(batch_capacity));
|
||||
|
||||
|
||||
@@ -11,14 +11,14 @@ use crate::{
|
||||
|
||||
#[allow(non_snake_case)]
|
||||
#[cfg(feature = "serialize")]
|
||||
fn test_aos_serialization<const RING_LEN: usize>(proof: Aos<G0, G1, RING_LEN>, Re_0: Re<G0, G1>) {
|
||||
fn test_aos_serialization<const RING_LEN: usize>(proof: &Aos<G0, G1, RING_LEN>, Re_0: Re<G0, G1>) {
|
||||
let mut buf = vec![];
|
||||
proof.write(&mut buf).unwrap();
|
||||
let deserialized = Aos::read::<&[u8]>(&mut buf.as_ref(), Re_0).unwrap();
|
||||
assert_eq!(proof, deserialized);
|
||||
assert_eq!(proof, &deserialized);
|
||||
}
|
||||
|
||||
fn test_aos<const RING_LEN: usize>(default: Re<G0, G1>) {
|
||||
fn test_aos<const RING_LEN: usize>(default: &Re<G0, G1>) {
|
||||
let generators = generators();
|
||||
|
||||
let mut ring_keys = [(<G0 as Group>::Scalar::ZERO, <G1 as Group>::Scalar::ZERO); RING_LEN];
|
||||
@@ -34,7 +34,7 @@ fn test_aos<const RING_LEN: usize>(default: Re<G0, G1>) {
|
||||
for (actual, key) in ring_keys.iter_mut().enumerate() {
|
||||
let proof = Aos::<_, _, RING_LEN>::prove(
|
||||
&mut OsRng,
|
||||
transcript(),
|
||||
&transcript(),
|
||||
generators,
|
||||
&ring,
|
||||
actual,
|
||||
@@ -43,25 +43,25 @@ fn test_aos<const RING_LEN: usize>(default: Re<G0, G1>) {
|
||||
);
|
||||
|
||||
let mut batch = (BatchVerifier::new(0), BatchVerifier::new(0));
|
||||
proof.verify(&mut OsRng, transcript(), generators, &mut batch, &ring).unwrap();
|
||||
proof.verify(&mut OsRng, &transcript(), generators, &mut batch, &ring).unwrap();
|
||||
// For e, these should have nothing. For R, these should have 6 elements each which sum to 0
|
||||
assert!(batch.0.verify_vartime());
|
||||
assert!(batch.1.verify_vartime());
|
||||
|
||||
#[cfg(feature = "serialize")]
|
||||
test_aos_serialization(proof, default.clone());
|
||||
test_aos_serialization(&proof, default.clone());
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_aos_e() {
|
||||
test_aos::<2>(Re::e_default());
|
||||
test_aos::<4>(Re::e_default());
|
||||
test_aos::<2>(&Re::e_default());
|
||||
test_aos::<4>(&Re::e_default());
|
||||
}
|
||||
|
||||
#[allow(non_snake_case)]
|
||||
#[test]
|
||||
fn test_aos_R() {
|
||||
// Batch verification appreciates the longer vectors, which means not batching bits
|
||||
test_aos::<2>(Re::R_default());
|
||||
test_aos::<2>(&Re::R_default());
|
||||
}
|
||||
|
||||
@@ -117,7 +117,7 @@ fn test_multi_dleq() {
|
||||
// 0: 0
|
||||
// 1: 1, 2
|
||||
// 2: 2, 3, 4
|
||||
let key_generators = generators[i .. (i + i + 1)].to_vec();
|
||||
let key_generators = generators[i ..= (i + i)].to_vec();
|
||||
let mut these_pub_keys = vec![];
|
||||
for generator in &key_generators {
|
||||
these_pub_keys.push(generator * key.deref());
|
||||
|
||||
Reference in New Issue
Block a user