Clippy cleanup

This commit is contained in:
Daniel Sanchez Quiros 2024-04-17 13:04:47 +02:00
parent 2b34669d33
commit 4ac06df819
4 changed files with 18 additions and 16 deletions

View File

@ -133,7 +133,6 @@ pub fn build_attestation_message(
}
pub fn commitment_to_bytes(commitment: &Commitment) -> Vec<u8> {
use ark_serialize::CanonicalSerialize;
let mut buff = Cursor::new(vec![]);
commitment
.serialize_uncompressed(&mut buff)

View File

@ -1,8 +1,7 @@
// std
use ark_ff::{BigInteger, PrimeField};
use std::ops::Div;
// crates
use ark_ff::{BigInteger, PrimeField};
// internal
use crate::common::{hash_column_and_commitment, Chunk, ChunksMatrix, Row};
use crate::global::{DOMAIN, GLOBAL_PARAMETERS};
@ -18,7 +17,7 @@ pub struct DaEncoderParams {
}
impl DaEncoderParams {
const MAX_BLS12_381_ENCODING_CHUNK_SIZE: usize = 31;
pub const MAX_BLS12_381_ENCODING_CHUNK_SIZE: usize = 31;
const fn default_with(column_count: usize) -> Self {
Self { column_count }
@ -63,6 +62,7 @@ impl DaEncoder {
.collect()
}
#[allow(clippy::type_complexity)]
fn compute_kzg_row_commitments(
matrix: &ChunksMatrix,
) -> Result<Vec<((Evaluations, Polynomial), Commitment)>, KzgRsError> {
@ -106,6 +106,7 @@ impl DaEncoder {
.collect()
}
#[allow(clippy::type_complexity)]
fn compute_kzg_column_commitments(
matrix: &ChunksMatrix,
) -> Result<Vec<((Evaluations, Polynomial), Commitment)>, KzgRsError> {

View File

@ -1,6 +1,6 @@
// std
// crates
use crate::BYTES_PER_FIELD_ELEMENT;
use crate::{FieldElement, BYTES_PER_FIELD_ELEMENT};
use ark_bls12_381::fr::Fr;
use ark_ff::Zero;
use ark_poly::domain::general::GeneralEvaluationDomain;
@ -32,12 +32,11 @@ pub fn bytes_to_evaluations<const CHUNK_SIZE: usize>(
assert!((data.len() % CHUNK_SIZE).is_zero());
Evaluations::from_vec_and_domain(
data.chunks(CHUNK_SIZE)
.map(|e| {
.map(
// use little endian for convenience as shortening 1 byte (<32 supported)
// do not matter in this endianness
let bui = BigUint::from_bytes_le(e);
Fr::from(bui)
})
field_element_from_bytes_le,
)
.collect(),
domain,
)
@ -78,6 +77,15 @@ pub fn bytes_to_polynomial_unchecked<const CHUNK_SIZE: usize>(
(evals, coefficients)
}
/// Transform arbitrary bytes into a field element
/// This transformation is bounds unchecked, it's up to the caller to know if
/// data fits within the bls modulus.
/// Data len cannot be higher than `BYTES_PER_FIELD_ELEMENT`
pub fn field_element_from_bytes_le(b: &[u8]) -> FieldElement {
assert!(b.len() <= BYTES_PER_FIELD_ELEMENT);
FieldElement::from(BigUint::from_bytes_le(b))
}
#[cfg(test)]
mod test {
use super::{bytes_to_evaluations, bytes_to_polynomial, KzgRsError};

View File

@ -36,13 +36,7 @@ pub fn decode(
let (points, roots_of_unity): (Vec<Fr>, Vec<Fr>) = points
.iter()
.enumerate()
.flat_map(|(i, e)| {
if let Some(e) = e {
Some((*e, domain.element(i)))
} else {
None
}
})
.flat_map(|(i, e)| e.map(|e| (e, domain.element(i))))
.unzip();
let coeffs = lagrange_interpolate(&points, &roots_of_unity);
Evaluations::from_vec_and_domain(