Skip to content

Commit

Permalink
Clippy
Browse files Browse the repository at this point in the history
  • Loading branch information
porcuquine committed Jan 21, 2022
1 parent 1e95f58 commit 9aba397
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 17 deletions.
2 changes: 1 addition & 1 deletion src/circuit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,7 @@ where
let index = self.current_round - sparse_offset - 1;
let sparse_matrix = &self.constants.sparse_matrixes[index];

self.product_mds_with_sparse_matrix::<CS>(&sparse_matrix)?;
self.product_mds_with_sparse_matrix::<CS>(sparse_matrix)?;
} else {
self.product_mds_m::<CS>()?;
}
Expand Down
14 changes: 7 additions & 7 deletions src/matrix.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ pub fn mat_mul<F: PrimeField>(a: &Matrix<F>, b: &Matrix<F>) -> Option<Matrix<F>>
.iter()
.map(|input_row| {
b_t.iter()
.map(|transposed_column| vec_mul(&input_row, &transposed_column))
.map(|transposed_column| vec_mul(input_row, transposed_column))
.collect()
})
.collect();
Expand Down Expand Up @@ -251,7 +251,7 @@ fn eliminate<F: PrimeField>(
let mut factor = val;
factor.mul_assign(&inv_pivot);

let scaled_pivot = scalar_vec_mul(factor, &pivot);
let scaled_pivot = scalar_vec_mul(factor, pivot);
let eliminated = vec_sub(row, &scaled_pivot);
result.push(eliminated);

Expand All @@ -271,7 +271,7 @@ fn eliminate<F: PrimeField>(
// `matrix` must be square.
fn upper_triangular<F: PrimeField>(
matrix: &Matrix<F>,
mut shadow: &mut Matrix<F>,
shadow: &mut Matrix<F>,
) -> Option<Matrix<F>> {
assert!(is_square(matrix));
let mut result = Vec::with_capacity(matrix.len());
Expand All @@ -282,7 +282,7 @@ fn upper_triangular<F: PrimeField>(
while curr.len() > 1 {
let initial_rows = curr.len();

curr = eliminate(&curr, column, &mut shadow)?;
curr = eliminate(&curr, column, shadow)?;
result.push(curr[0].clone());
shadow_result.push(shadow[0].clone());
column += 1;
Expand Down Expand Up @@ -323,8 +323,8 @@ fn reduce_to_identity<F: PrimeField>(
inv.unwrap()
};

let mut normalized = scalar_vec_mul(inv, &row);
let mut shadow_normalized = scalar_vec_mul(inv, &shadow_row);
let mut normalized = scalar_vec_mul(inv, row);
let mut shadow_normalized = scalar_vec_mul(inv, shadow_row);

for j in 0..i {
let idx = size - j - 1;
Expand All @@ -350,7 +350,7 @@ fn reduce_to_identity<F: PrimeField>(
//
pub(crate) fn invert<F: PrimeField>(matrix: &Matrix<F>) -> Option<Matrix<F>> {
let mut shadow = make_identity(columns(matrix));
let ut = upper_triangular(&matrix, &mut shadow);
let ut = upper_triangular(matrix, &mut shadow);

ut.and_then(|x| reduce_to_identity(&x, &mut shadow))
.and(Some(shadow))
Expand Down
2 changes: 1 addition & 1 deletion src/mds.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ impl<F: PrimeField> SparseMatrix<F> {
}

pub fn is_sparse_matrix(m: &Matrix<F>) -> bool {
is_square(&m) && is_identity(&minor(&m, 0, 0))
is_square(m) && is_identity(&minor(m, 0, 0))
}

pub fn size(&self) -> usize {
Expand Down
10 changes: 5 additions & 5 deletions src/poseidon.rs
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,7 @@ where
/// Panics if the provided slice is bigger than the arity.
pub fn set_preimage(&mut self, preimage: &[F]) {
self.reset();
self.elements[1..].copy_from_slice(&preimage);
self.elements[1..].copy_from_slice(preimage);
self.pos = self.elements.len();
}

Expand Down Expand Up @@ -497,7 +497,7 @@ where
let index = self.current_round - sparse_offset - 1;
let sparse_matrix = &self.constants.sparse_matrixes[index];

self.product_mds_with_sparse_matrix(&sparse_matrix);
self.product_mds_with_sparse_matrix(sparse_matrix);
} else {
self.product_mds();
}
Expand Down Expand Up @@ -606,7 +606,7 @@ where
pub fn encrypt(&mut self, key: &[F], plaintext: &[F]) -> Result<(Vec<F>, F), Error> {
// https://link.springer.com/content/pdf/10.1007%2F978-3-642-28496-0_19.pdf
let arity = A::to_usize();
assert!(key.len() > 0);
assert!(!key.is_empty());

self.shared_initialize(key, plaintext.len())?;

Expand All @@ -625,7 +625,7 @@ where

pub fn decrypt(&mut self, key: &[F], ciphertext: &[F], tag: &F) -> Result<Vec<F>, Error> {
let arity = A::to_usize();
assert!(key.len() > 0);
assert!(!key.is_empty());

self.shared_initialize(key, ciphertext.len())?;
let mut plaintext = Vec::with_capacity(ciphertext.len());
Expand Down Expand Up @@ -682,7 +682,7 @@ where
fn hash(&mut self, preimages: &[GenericArray<Fr, A>]) -> Result<Vec<Fr>, Error> {
Ok(preimages
.iter()
.map(|preimage| Poseidon::new_with_preimage(&preimage, &self.constants).hash())
.map(|preimage| Poseidon::new_with_preimage(preimage, &self.constants).hash())
.collect())
}

Expand Down
6 changes: 3 additions & 3 deletions src/preprocessing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ pub(crate) fn compress_round_constants<F: PrimeField>(
partial_keys.push(inverted[0]);
inverted[0] = F::zero();

vec_add(&previous_round_keys, &inverted)
vec_add(previous_round_keys, &inverted)
});

// Everything in here is dev-driven testing.
Expand Down Expand Up @@ -95,7 +95,7 @@ pub(crate) fn compress_round_constants<F: PrimeField>(
inv[0] = F::zero();

// (M^-1(T) - pk) - I
let result_key = vec_add(&initial_round_keys, &inv);
let result_key = vec_add(initial_round_keys, &inv);

assert_eq!(&result_key, &round_acc, "Acc assumption failed.");
assert_eq!(pk, partial_keys[0], "Partial-key assumption failed.");
Expand Down Expand Up @@ -144,7 +144,7 @@ pub(crate) fn compress_round_constants<F: PrimeField>(

quintic_s_box(&mut p_state[0], None, Some(&pk));

let preprocessed_result = apply_matrix(&mds_matrix, &p_state);
let preprocessed_result = apply_matrix(mds_matrix, &p_state);

assert_eq!(
plain_result, preprocessed_result,
Expand Down

0 comments on commit 9aba397

Please sign in to comment.