Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Fix hard static analysis errors #18

Merged
merged 1 commit into from
Aug 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions crates/bellman/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#![allow(dead_code, unused_imports, unused_mut, unused_variables, unused_macros, unused_assignments, unreachable_patterns)]
#![cfg_attr(feature = "allocator", feature(allocator_api))]
#![allow(clippy::needless_borrow, clippy::needless_borrows_for_generic_args)]

#[macro_use]
extern crate cfg_if;
Expand All @@ -11,7 +12,7 @@
pub use pairing::*;
pub use smallvec;

use crate::pairing::ff;

Check warning on line 15 in crates/bellman/src/lib.rs

View workflow job for this annotation

GitHub Actions / CI (ubuntu-22.04-github-hosted-16core)

private item shadows public glob re-export

Check warning on line 15 in crates/bellman/src/lib.rs

View workflow job for this annotation

GitHub Actions / CI (macos-13-xlarge)

private item shadows public glob re-export
pub use ff::*;

#[macro_use]
Expand Down
2 changes: 1 addition & 1 deletion crates/bellman/src/log.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#[allow(unused_macros)]
#[allow(clippy::needless_borrow)]

Check warning on line 1 in crates/bellman/src/log.rs

View workflow job for this annotation

GitHub Actions / CI (ubuntu-22.04-github-hosted-16core)

unused attribute `allow`

Check warning on line 1 in crates/bellman/src/log.rs

View workflow job for this annotation

GitHub Actions / CI (macos-13-xlarge)

unused attribute `allow`

cfg_if! {
if #[cfg(feature = "nolog")] {
Expand Down
1 change: 1 addition & 0 deletions crates/bellman/src/plonk/better_better_cs/proof/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -657,6 +657,7 @@ impl<E: Engine, P: PlonkConstraintSystemParams<E>, MG: MainGate<E>, S: Synthesis
grand_products_protos_with_gamma.push(p);
}

#[allow(clippy::redundant_locals)]
let required_domain_size = required_domain_size;
popzxc marked this conversation as resolved.
Show resolved Hide resolved

let domain = Domain::new_for_size(required_domain_size as u64)?;
Expand Down
37 changes: 18 additions & 19 deletions crates/bellman/src/plonk/polynomials/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -740,8 +740,12 @@ impl<F: PrimeField> Polynomial<F, Coefficients> {

// let mut final_values = vec![F::zero(); new_size];

#[allow(clippy::uninit_vec)] // Data is initialized below without being read
let mut final_values = Vec::with_capacity(new_size);
unsafe { final_values.set_len(new_size) };
#[allow(clippy::uninit_vec)] // Data is initialized below without being read
unsafe {
final_values.set_len(new_size)
};

// copy here is more complicated: to have the value in a natural order
// one has to use coset_idx to address the result element
Expand Down Expand Up @@ -1272,27 +1276,14 @@ impl<F: PrimeField> Polynomial<F, Values> {

assert!(subset_factor.is_power_of_two());

let current_size = self.coeffs.len();
let new_size = current_size / subset_factor;

let mut result = Vec::with_capacity(new_size);
unsafe { result.set_len(new_size) };

// copy elements. If factor is 2 then non-reversed we would output only elements that are == 0 mod 2
// If factor is 2 and we are bit-reversed - we need to only output first half of the coefficients
// If factor is 4 then we need to output only the first 4th part
// if factor is 8 - only the first 8th part
let current_size = self.coeffs.len();
let new_size = current_size / subset_factor;

let start = 0;
let end = new_size;

result.copy_from_slice(&self.coeffs[start..end]);

// unsafe { result.set_len(new_size)};
// let copy_to_start_pointer: *mut F = result[..].as_mut_ptr();
// let copy_from_start_pointer: *const F = self.coeffs[start..end].as_ptr();

// unsafe { std::ptr::copy_nonoverlapping(copy_from_start_pointer, copy_to_start_pointer, new_size) };
let result = self.coeffs[..new_size].to_vec();
popzxc marked this conversation as resolved.
Show resolved Hide resolved

Polynomial::from_values(result)
}
Expand Down Expand Up @@ -2087,8 +2078,12 @@ impl<F: PartialTwoBitReductionField> Polynomial<F, Coefficients> {

// let mut results = vec![self.coeffs.clone(); factor];

#[allow(clippy::uninit_vec)] // Data is initialized below without being read
let mut result = Vec::with_capacity(new_size);
unsafe { result.set_len(new_size) };
#[allow(clippy::uninit_vec)] // Data is initialized below without being read
unsafe {
result.set_len(new_size)
};

let r = &mut result[..] as *mut [F];

Expand Down Expand Up @@ -2274,8 +2269,12 @@ impl<F: PrimeField> Polynomial<F, Coefficients> {

// let mut results = vec![self.coeffs.clone(); factor];

#[allow(clippy::uninit_vec)] // Data is initialized below without being read
let mut result = Vec::with_capacity(new_size);
unsafe { result.set_len(new_size) };
#[allow(clippy::uninit_vec)] // Data is initialized below without being read
unsafe {
result.set_len(new_size)
};

let r = &mut result[..] as *mut [F];

Expand Down
1 change: 1 addition & 0 deletions crates/bellman/src/plonk/transparent_engine/proth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use crate::ff::*;
#[derive(Copy, Clone, PartialEq, Eq, Default, Hash, ::serde::Serialize, ::serde::Deserialize)]
pub struct FrRepr(pub [u64; 4usize]);

#[allow(clippy::derived_hash_with_manual_eq)]
#[derive(Hash, ::serde::Serialize, ::serde::Deserialize)]
pub struct Fr(FrRepr);

Expand Down
2 changes: 1 addition & 1 deletion crates/boojum/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Allowed lints
// Whenever add an item here, please write a short yet meaningful comment on why so.
#![allow(
clippy::incorrect_clone_impl_on_copy_type, // False positives in derivative: https://github.com/mcarton/rust-derivative/issues/112
clippy::non_canonical_clone_impl, // False positives in derivative: https://github.com/mcarton/rust-derivative/issues/112
clippy::bool_comparison, // Explicitness is good in critical contexts.
clippy::mut_from_ref, // Triggers on unsafe functions (e.g. ones using `UnsafeCell`).
clippy::type_complexity, // Many types in this create are inherently complex.
Expand Down
2 changes: 1 addition & 1 deletion crates/codegen/src/generate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ fn render(vars: TemplateVars, vk: VerificationKey<Bn256, DummyCircuit>, output_d

let rendered = handlebars.render("contract", &map.inner).unwrap();

writer.write(rendered.as_bytes()).expect("must write to file");
writer.write_all(rendered.as_bytes()).expect("must write to file");
}
}

Expand Down
8 changes: 4 additions & 4 deletions crates/pairing/benches/bls12_381/ec.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
mod g1 {
use rand::{Rand, SeedableRng, XorShiftRng};

use pairing::bls12_381::*;
use pairing::CurveProjective;
use pairing_ce::bls12_381::*;
popzxc marked this conversation as resolved.
Show resolved Hide resolved
use pairing_ce::CurveProjective;

#[bench]
fn bench_g1_mul_assign(b: &mut ::test::Bencher) {
Expand Down Expand Up @@ -59,8 +59,8 @@ mod g1 {
mod g2 {
use rand::{Rand, SeedableRng, XorShiftRng};

use pairing::bls12_381::*;
use pairing::CurveProjective;
use pairing_ce::bls12_381::*;
use pairing_ce::CurveProjective;

#[bench]
fn bench_g2_mul_assign(b: &mut ::test::Bencher) {
Expand Down
2 changes: 1 addition & 1 deletion crates/pairing/benches/bls12_381/fq.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use rand::{Rand, SeedableRng, XorShiftRng};

use ff::{Field, PrimeField, PrimeFieldRepr, SqrtField};
use pairing::bls12_381::*;
use pairing_ce::bls12_381::*;

#[bench]
fn bench_fq_repr_add_nocarry(b: &mut ::test::Bencher) {
Expand Down
2 changes: 1 addition & 1 deletion crates/pairing/benches/bls12_381/fq12.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use rand::{Rand, SeedableRng, XorShiftRng};

use ff::Field;
use pairing::bls12_381::*;
use pairing_ce::bls12_381::*;

#[bench]
fn bench_fq12_add_assign(b: &mut ::test::Bencher) {
Expand Down
2 changes: 1 addition & 1 deletion crates/pairing/benches/bls12_381/fq2.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use rand::{Rand, SeedableRng, XorShiftRng};

use ff::{Field, SqrtField};
use pairing::bls12_381::*;
use pairing_ce::bls12_381::*;

#[bench]
fn bench_fq2_add_assign(b: &mut ::test::Bencher) {
Expand Down
2 changes: 1 addition & 1 deletion crates/pairing/benches/bls12_381/fr.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use rand::{Rand, SeedableRng, XorShiftRng};

use ff::{Field, PrimeField, PrimeFieldRepr, SqrtField};
use pairing::bls12_381::*;
use pairing_ce::bls12_381::*;

#[bench]
fn bench_fr_repr_add_nocarry(b: &mut ::test::Bencher) {
Expand Down
4 changes: 2 additions & 2 deletions crates/pairing/benches/bls12_381/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ mod fr;

use rand::{Rand, SeedableRng, XorShiftRng};

use pairing::bls12_381::*;
use pairing::{CurveAffine, Engine};
use pairing_ce::bls12_381::*;
use pairing_ce::{CurveAffine, Engine};

#[bench]
fn bench_pairing_g1_preparation(b: &mut ::test::Bencher) {
Expand Down
8 changes: 4 additions & 4 deletions crates/pairing/benches/bn256/ec.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
mod g1 {
use rand::{Rand, SeedableRng, XorShiftRng};

use pairing::bn256::*;
use pairing::CurveProjective;
use pairing_ce::bn256::*;
use pairing_ce::CurveProjective;

#[bench]
fn bench_g1_mul_assign(b: &mut ::test::Bencher) {
Expand Down Expand Up @@ -59,8 +59,8 @@ mod g1 {
mod g2 {
use rand::{Rand, SeedableRng, XorShiftRng};

use pairing::bls12_381::*;
use pairing::CurveProjective;
use pairing_ce::bls12_381::*;
use pairing_ce::CurveProjective;

#[bench]
fn bench_g2_mul_assign(b: &mut ::test::Bencher) {
Expand Down
2 changes: 1 addition & 1 deletion crates/pairing/benches/bn256/fq.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use rand::{Rand, SeedableRng, XorShiftRng};

use ff::{Field, PrimeField, PrimeFieldRepr, SqrtField};
use pairing::bn256::*;
use pairing_ce::bn256::*;

#[bench]
fn bench_fq_repr_add_nocarry(b: &mut ::test::Bencher) {
Expand Down
2 changes: 1 addition & 1 deletion crates/pairing/benches/bn256/fq12.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use rand::{Rand, SeedableRng, XorShiftRng};

use ff::Field;
use pairing::bn256::*;
use pairing_ce::bn256::*;

#[bench]
fn bench_fq12_add_assign(b: &mut ::test::Bencher) {
Expand Down
2 changes: 1 addition & 1 deletion crates/pairing/benches/bn256/fq2.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use rand::{Rand, SeedableRng, XorShiftRng};

use ff::{Field, SqrtField};
use pairing::bn256::*;
use pairing_ce::bn256::*;

#[bench]
fn bench_fq2_add_assign(b: &mut ::test::Bencher) {
Expand Down
2 changes: 1 addition & 1 deletion crates/pairing/benches/bn256/fr.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use rand::{Rand, SeedableRng, XorShiftRng};

use ff::{Field, PrimeField, PrimeFieldRepr, SqrtField};
use pairing::bn256::*;
use pairing_ce::bn256::*;

#[bench]
fn bench_fr_repr_add_nocarry(b: &mut ::test::Bencher) {
Expand Down
4 changes: 2 additions & 2 deletions crates/pairing/benches/bn256/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ mod fr;

use rand::{Rand, SeedableRng, XorShiftRng};

use pairing::bn256::*;
use pairing::{CurveAffine, Engine};
use pairing_ce::bn256::*;
use pairing_ce::{CurveAffine, Engine};

#[bench]
fn bench_pairing_g1_preparation(b: &mut ::test::Bencher) {
Expand Down
11 changes: 1 addition & 10 deletions crates/pairing/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,4 @@
// `clippy` is a code linting tool for improving code quality by catching
// common mistakes or strange code patterns. If the `cargo-clippy` feature
// is provided, all compiler warnings are prohibited.
#![cfg_attr(feature = "cargo-clippy", deny(warnings))]
// #![cfg_attr(feature = "cargo-clippy", allow(inline_always))]
// #![cfg_attr(feature = "cargo-clippy", allow(too_many_arguments))]
// #![cfg_attr(feature = "cargo-clippy", allow(unreadable_literal))]
// #![cfg_attr(feature = "cargo-clippy", allow(many_single_char_names))]
// #![cfg_attr(feature = "cargo-clippy", allow(new_without_default_derive))]
// #![cfg_attr(feature = "cargo-clippy", allow(write_literal))]
#![allow(clippy::too_many_arguments, clippy::needless_borrows_for_generic_args)]
// Force public structures to implement Debug
#![deny(missing_debug_implementations)]
// Asm is only available on nightly, with this unstable feature
Expand All @@ -33,7 +24,7 @@
mod base;
pub use self::base::*;

use ff::{Field, PrimeField, PrimeFieldDecodingError, PrimeFieldRepr, ScalarEngine, SqrtField};

Check warning on line 27 in crates/pairing/src/lib.rs

View workflow job for this annotation

GitHub Actions / CI (ubuntu-22.04-github-hosted-16core)

private item shadows public glob re-export

Check warning on line 27 in crates/pairing/src/lib.rs

View workflow job for this annotation

GitHub Actions / CI (ubuntu-22.04-github-hosted-16core)

private item shadows public glob re-export

Check warning on line 27 in crates/pairing/src/lib.rs

View workflow job for this annotation

GitHub Actions / CI (ubuntu-22.04-github-hosted-16core)

private item shadows public glob re-export

Check warning on line 27 in crates/pairing/src/lib.rs

View workflow job for this annotation

GitHub Actions / CI (ubuntu-22.04-github-hosted-16core)

private item shadows public glob re-export

Check warning on line 27 in crates/pairing/src/lib.rs

View workflow job for this annotation

GitHub Actions / CI (ubuntu-22.04-github-hosted-16core)

private item shadows public glob re-export

Check warning on line 27 in crates/pairing/src/lib.rs

View workflow job for this annotation

GitHub Actions / CI (ubuntu-22.04-github-hosted-16core)

private item shadows public glob re-export

Check warning on line 27 in crates/pairing/src/lib.rs

View workflow job for this annotation

GitHub Actions / CI (ubuntu-22.04-github-hosted-16core)

private item shadows public glob re-export

Check warning on line 27 in crates/pairing/src/lib.rs

View workflow job for this annotation

GitHub Actions / CI (macos-13-xlarge)

private item shadows public glob re-export

Check warning on line 27 in crates/pairing/src/lib.rs

View workflow job for this annotation

GitHub Actions / CI (macos-13-xlarge)

private item shadows public glob re-export

Check warning on line 27 in crates/pairing/src/lib.rs

View workflow job for this annotation

GitHub Actions / CI (macos-13-xlarge)

private item shadows public glob re-export

Check warning on line 27 in crates/pairing/src/lib.rs

View workflow job for this annotation

GitHub Actions / CI (macos-13-xlarge)

private item shadows public glob re-export

Check warning on line 27 in crates/pairing/src/lib.rs

View workflow job for this annotation

GitHub Actions / CI (macos-13-xlarge)

private item shadows public glob re-export

Check warning on line 27 in crates/pairing/src/lib.rs

View workflow job for this annotation

GitHub Actions / CI (macos-13-xlarge)

private item shadows public glob re-export

Check warning on line 27 in crates/pairing/src/lib.rs

View workflow job for this annotation

GitHub Actions / CI (macos-13-xlarge)

private item shadows public glob re-export
use std::error::Error;
use std::fmt;

Expand Down
Loading