Skip to content

Commit

Permalink
chore: Updated clippy (#5)
Browse files Browse the repository at this point in the history
  • Loading branch information
epociask authored Jun 3, 2024
1 parent 8d92ba6 commit 0aabfcb
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 29 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ jobs:
- name: Build
run: cargo build --verbose
- name: Clippy Format test
run: cargo clippy -- -D warnings
run: cargo clippy --all --manifest-path Cargo.toml -- -D warnings
- name: Run tests
run: cargo test --verbose
- name: Run tests with mainnet data
Expand Down
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ This code is unaudited and under construction. This is experimental software and
2. Specify the files in `kzg.setup()` function, leave the `g2_points` empty, and specify the `srs_order` per the guide.
3. Note that this is process will take a few minutes to load since it is a bit intensive.

## Clippy
Linting can be triggered via running `cargo clippy --all --manifest-path Cargo.toml -- -D warnings`.

## Quick Start

1. Check the test in `test_compute_kzg_proof` function to see the end to end usage of the library for quick start.
Expand Down
5 changes: 3 additions & 2 deletions src/helpers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ pub fn lexicographically_largest(z: &Fq) -> bool {
borrow == 0
}

pub fn read_g2_point_from_bytes_be(g2_bytes_be: &Vec<u8>) -> Result<G2Affine, &str> {
pub fn read_g2_point_from_bytes_be(g2_bytes_be: &[u8]) -> Result<G2Affine, &str> {
if g2_bytes_be.len() != SIZE_OF_G2_AFFINE_COMPRESSED {
return Err("not enough bytes for g2 point");
}
Expand Down Expand Up @@ -255,7 +255,7 @@ pub fn read_g2_point_from_bytes_be(g2_bytes_be: &Vec<u8>) -> Result<G2Affine, &s
Ok(point)
}

pub fn read_g1_point_from_bytes_be(g1_bytes_be: &Vec<u8>) -> Result<G1Affine, &str> {
pub fn read_g1_point_from_bytes_be(g1_bytes_be: &[u8]) -> Result<G1Affine, &str> {
if g1_bytes_be.len() != SIZE_OF_G1_AFFINE_COMPRESSED {
return Err("not enough bytes for g1 point");
}
Expand Down Expand Up @@ -301,6 +301,7 @@ pub fn process_chunks<T>(receiver: Receiver<(Vec<u8>, usize)>) -> Vec<(T, usize)
where
T: ReadPointFromBytes,
{
#[allow(clippy::unnecessary_filter_map)]
receiver
.iter()
.map(|(chunk, position)| {
Expand Down
46 changes: 22 additions & 24 deletions src/kzg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,19 +49,17 @@ impl Kzg {
let g1_points =
Self::parallel_read_g1_points(path_to_g1_points.to_owned(), srs_points_to_load)
.map_err(|e| KzgError::SerializationError(e.to_string()))?;

let g2_points: Vec<G2Affine>;
if !path_to_g2_points.is_empty() {
g2_points =
Self::parallel_read_g2_points(path_to_g2_points.to_owned(), srs_points_to_load)
.map_err(|e| KzgError::SerializationError(e.to_string()))?;
} else if !g2_power_of2_path.is_empty() {
g2_points = Self::read_g2_point_on_power_of_2(g2_power_of2_path)?;
} else {
return Err(KzgError::GenericError(

let g2_points_result: Result<Vec<G2Affine>, KzgError> = match (path_to_g2_points.is_empty(), g2_power_of2_path.is_empty()) {
(false, _) => Self::parallel_read_g2_points(path_to_g2_points.to_owned(), srs_points_to_load)
.map_err(|e| KzgError::SerializationError(e.to_string())),
(_, false) => Self::read_g2_point_on_power_of_2(g2_power_of2_path),
(true, true) => return Err(KzgError::GenericError(
"both g2 point files are empty, need the proper file specified".to_string(),
));
}
)),
};

let g2_points = g2_points_result?;

Ok(Self {
g1: g1_points,
Expand Down Expand Up @@ -446,7 +444,7 @@ impl Kzg {
&self,
polynomial: &Polynomial,
index: u64,
root_of_unities: &Vec<Fr>,
root_of_unities: &[Fr],
) -> Result<G1Affine, KzgError> {
if !self.params.completed_setup {
return Err(KzgError::GenericError(
Expand Down Expand Up @@ -520,26 +518,26 @@ impl Kzg {
z_fr: Fr,
eval_fr: &[Fr],
value_fr: Fr,
roots_of_unities: &Vec<Fr>,
roots_of_unities: &[Fr],
) -> Fr {
let mut quotient = Fr::zero();
let mut fi: Fr;
let mut numerator: Fr;
let mut denominator: Fr;
let mut temp: Fr;

for i in 0..roots_of_unities.len() {
let omega_i = roots_of_unities[i];
if omega_i == z_fr {
continue;
let mut fi: Fr = Fr::zero();
let mut numerator: Fr = Fr::zero();
let mut denominator: Fr = Fr::zero();
let mut temp: Fr = Fr::zero();

roots_of_unities.iter().enumerate().for_each(|(i, omega_i)| {
if *omega_i == z_fr {
return;
}
fi = eval_fr[i] - value_fr;
numerator = fi * omega_i;
denominator = z_fr - omega_i;
denominator *= z_fr;
temp = numerator.div(denominator);
quotient += temp;
}
});

quotient
}

Expand Down
4 changes: 2 additions & 2 deletions src/traits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@ pub trait ReadPointFromBytes: AffineRepr {
// Implement this trait for G1Affine and G2Affine
impl ReadPointFromBytes for G1Affine {
fn read_point_from_bytes_be(bytes: &[u8]) -> io::Result<G1Affine> {
helpers::read_g1_point_from_bytes_be(&bytes.to_vec())
helpers::read_g1_point_from_bytes_be(bytes)
.map_err(|e| io::Error::new(io::ErrorKind::InvalidData, e))
}
}

impl ReadPointFromBytes for G2Affine {
fn read_point_from_bytes_be(bytes: &[u8]) -> io::Result<G2Affine> {
helpers::read_g2_point_from_bytes_be(&bytes.to_vec())
helpers::read_g2_point_from_bytes_be(bytes)
.map_err(|e| io::Error::new(io::ErrorKind::InvalidData, e))
}
}

0 comments on commit 0aabfcb

Please sign in to comment.