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

chore: small adjustments #894

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 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
98 changes: 96 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ resolver = "2"

[workspace.package]
version = "0.5.0"
authors = [ "arkworks contributors" ]
authors = ["arkworks contributors"]
homepage = "https://arkworks.rs"
repository = "https://github.com/arkworks-rs/algebra"
categories = ["cryptography"]
Expand All @@ -41,6 +41,100 @@ rustdoc-args = ["--html-in-header katex-header.html"]
[workspace.metadata.release]
dependent-version = "fix"

[workspace.lints]
rust.rust_2018_idioms = { level = "deny", priority = -1 }
rust.unreachable_pub = "warn"
rust.unused_must_use = "deny"
rustdoc.all = "warn"
# rust.unnameable-types = "warn"

[workspace.lints.clippy]
# These are some of clippy's nursery (i.e., experimental) lints that we like.
# By default, nursery lints are allowed. Some of the lints below have made good
# suggestions which we fixed. The others didn't have any findings, so we can
# assume they don't have that many false positives. Let's enable them to
# prevent future problems.
borrow_as_ptr = "warn"
branches_sharing_code = "warn"
clear_with_drain = "warn"
cloned_instead_of_copied = "warn"
collection_is_never_read = "warn"
dbg_macro = "warn"
derive_partial_eq_without_eq = "warn"
empty_line_after_doc_comments = "warn"
empty_line_after_outer_attr = "warn"
enum_glob_use = "warn"
equatable_if_let = "warn"
explicit_into_iter_loop = "warn"
explicit_iter_loop = "warn"
flat_map_option = "warn"
from_iter_instead_of_collect = "warn"
if_not_else = "warn"
if_then_some_else_none = "warn"
implicit_clone = "warn"
imprecise_flops = "warn"
iter_on_empty_collections = "warn"
iter_on_single_items = "warn"
iter_with_drain = "warn"
iter_without_into_iter = "warn"
large_stack_frames = "warn"
manual_assert = "warn"
manual_clamp = "warn"
manual_is_variant_and = "warn"
manual_string_new = "warn"
match_same_arms = "warn"
missing_const_for_fn = "warn"
mutex_integer = "warn"
naive_bytecount = "warn"
needless_bitwise_bool = "warn"
needless_continue = "warn"
needless_for_each = "warn"
needless_pass_by_ref_mut = "warn"
nonstandard_macro_braces = "warn"
option_as_ref_cloned = "warn"
or_fun_call = "warn"
path_buf_push_overwrite = "warn"
read_zero_byte_vec = "warn"
redundant_clone = "warn"
redundant_else = "warn"
single_char_pattern = "warn"
string_lit_as_bytes = "warn"
string_lit_chars_any = "warn"
suboptimal_flops = "warn"
suspicious_operation_groupings = "warn"
trailing_empty_array = "warn"
trait_duplication_in_bounds = "warn"
transmute_undefined_repr = "warn"
trivial_regex = "warn"
tuple_array_conversions = "warn"
type_repetition_in_bounds = "warn"
uninhabited_references = "warn"
unnecessary_self_imports = "warn"
unnecessary_struct_initialization = "warn"
unnested_or_patterns = "warn"
unused_peekable = "warn"
unused_rounding = "warn"
use_self = "warn"
useless_let_if_seq = "warn"
while_float = "warn"
zero_sized_map_values = "warn"

# These are nursery lints which have findings. Allow them for now. Some are not
# quite mature enough for use in our codebase and some we don't really want.
# Explicitly listing should make it easier to fix in the future.
as_ptr_cast_mut = "allow"
cognitive_complexity = "allow"
debug_assert_with_mut_call = "allow"
doc_markdown = "allow"
fallible_impl_from = "allow"
future_not_send = "allow"
needless_collect = "allow"
non_send_fields_in_send_ty = "allow"
redundant_pub_crate = "allow"
significant_drop_in_scrutinee = "allow"
significant_drop_tightening = "allow"
too_long_first_doc_paragraph = "allow"

[workspace.dependencies]
ark-ec = { version = "0.5.0", path = "./ec", default-features = false }
ark-ff = { version = "0.5.0", path = "./ff", default-features = false }
Expand All @@ -51,7 +145,7 @@ ark-serialize = { version = "0.5.0", path = "./serialize", default-features = fa
ark-serialize-derive = { version = "0.5.0", path = "./serialize-derive" }
ark-std = { version = "0.5.0", default-features = false }

ark-algebra-bench-templates = { version = "0.5.0", path = "./bench-templates", default-features = false }
ark-algebra-bench-templates = { version = "0.5.0", path = "./bench-templates", default-features = false }
ark-algebra-test-templates = { version = "0.5.0", path = "./test-templates", default-features = false }
ark-test-curves = { version = "0.5.0", path = "./test-curves", default-features = false }

Expand Down
1 change: 1 addition & 0 deletions ec/src/hashing/tests.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#![allow(clippy::bool_assert_comparison)]
use crate::hashing::curve_maps::parity;
use ark_test_curves::bls12_381::{Fq, Fq2, Fq6};

Expand Down
12 changes: 6 additions & 6 deletions ff/src/biginteger/arithmetic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -291,20 +291,20 @@ mod tests {
#[test]
fn test_adc_no_carry() {
// Test addition without initial carry
let mut carry = 0;
let result = adc_no_carry(5u64, 10u64, &mut carry);
let carry = 0;
let result = adc_no_carry(5u64, 10u64, &carry);
assert_eq!(result, 15); // 5 + 10 = 15
assert_eq!(carry, 0); // No carry should be generated

// Test addition with a non-zero initial carry
let mut carry = 1;
let result = adc_no_carry(5u64, 10u64, &mut carry);
let carry = 1;
let result = adc_no_carry(5u64, 10u64, &carry);
assert_eq!(result, 16); // 5 + 10 + 1 = 16
assert_eq!(carry, 1); // No overflow, so carry remains 1

// Test addition that causes a carry
let mut carry = 1;
let result = adc_no_carry(u64::MAX, 1u64, &mut carry);
let carry = 1;
let result = adc_no_carry(u64::MAX, 1u64, &carry);
assert_eq!(result, 1); // u64::MAX + 1 + 1 -> 1
assert_eq!(carry, 1); // Carry is 1 due to overflow
}
Expand Down
1 change: 1 addition & 0 deletions ff/src/biginteger/tests.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#![allow(clippy::bool_assert_comparison)]
use crate::{biginteger::BigInteger, UniformRand};
use num_bigint::BigUint;

Expand Down
1 change: 1 addition & 0 deletions ff/src/fields/field_hashers/expander/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ fn expander() {
}

#[derive(Copy, Clone)]
#[allow(clippy::upper_case_acronyms)]
pub enum ExpID {
XMD(HashID),
XOF(XofID),
Expand Down
4 changes: 2 additions & 2 deletions ff/src/fields/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -371,8 +371,8 @@ pub fn batch_inversion_and_mul<F: Field>(v: &mut [F], coeff: &F) {
let num_elem_per_thread = max(num_elems / num_cpus_available, min_elements_per_thread);

// Batch invert in parallel, without copying the vector
v.par_chunks_mut(num_elem_per_thread).for_each(|mut chunk| {
serial_batch_inversion_and_mul(&mut chunk, coeff);
v.par_chunks_mut(num_elem_per_thread).for_each(|chunk| {
serial_batch_inversion_and_mul(chunk, coeff);
});
}

Expand Down
2 changes: 2 additions & 0 deletions ff/src/fields/models/cubic_extension.rs
Original file line number Diff line number Diff line change
Expand Up @@ -457,6 +457,7 @@ impl<P: CubicExtConfig> From<i8> for CubicExtField<P> {
}

impl<P: CubicExtConfig> From<bool> for CubicExtField<P> {
#[allow(clippy::unconditional_recursion)]
fn from(other: bool) -> Self {
other.into()
}
Expand Down Expand Up @@ -518,6 +519,7 @@ impl<P: CubicExtConfig> Div<&CubicExtField<P>> for CubicExtField<P> {
type Output = Self;

#[inline]
#[allow(clippy::suspicious_arithmetic_impl)]
fn div(mut self, other: &Self) -> Self {
self *= &other.inverse().unwrap();
self
Expand Down
1 change: 1 addition & 0 deletions ff/src/fields/models/fp/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -720,6 +720,7 @@ impl<P: FpConfig<N>, const N: usize> Div<&Fp<P, N>> for Fp<P, N> {
/// Returns `self * other.inverse()` if `other.inverse()` is `Some`, and
/// panics otherwise.
#[inline]
#[allow(clippy::suspicious_arithmetic_impl)]
fn div(mut self, other: &Self) -> Self {
self *= &other.inverse().unwrap();
self
Expand Down
1 change: 1 addition & 0 deletions ff/src/fields/models/quadratic_extension.rs
Original file line number Diff line number Diff line change
Expand Up @@ -619,6 +619,7 @@ impl<P: QuadExtConfig> Div<&QuadExtField<P>> for QuadExtField<P> {
type Output = Self;

#[inline]
#[allow(clippy::suspicious_arithmetic_impl)]
fn div(mut self, other: &Self) -> Self {
self *= &other.inverse().unwrap();
self
Expand Down
21 changes: 17 additions & 4 deletions poly/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ metadata.docs.rs.workspace = true
package.metadata.release.workspace = true
keywords = ["cryptography", "finite-fields", "fft", "polynomials"]

[lints]
workspace = true

[dependencies]
ark-ff.workspace = true
ark-serialize = { workspace = true, features = ["derive"] }
Expand All @@ -24,20 +27,30 @@ educe.workspace = true
hashbrown.workspace = true

[target.'cfg(all(target_has_atomic = "8", target_has_atomic = "16", target_has_atomic = "32", target_has_atomic = "64", target_has_atomic = "ptr"))'.dependencies]
ahash = { version = "0.8", default-features = false}
ahash = { version = "0.8", default-features = false }

[target.'cfg(not(all(target_has_atomic = "8", target_has_atomic = "16", target_has_atomic = "32", target_has_atomic = "64", target_has_atomic = "ptr")))'.dependencies]
fnv = { version = "1.0", default-features = false }

[dev-dependencies]
ark-test-curves = { path = "../test-curves", default-features = false, features = [ "bls12_381_curve", "bn384_small_two_adicity_curve", "mnt4_753_curve"] }
ark-test-curves = { path = "../test-curves", default-features = false, features = [
"bls12_381_curve",
"bn384_small_two_adicity_curve",
"mnt4_753_curve",
] }
criterion = "0.5.1"


[features]
default = []
std = [ "ark-std/std", "ark-ff/std", "ark-serialize/std" ]
parallel = [ "std", "ark-ff/parallel", "rayon", "ark-std/parallel", "ark-serialize/parallel" ]
std = ["ark-std/std", "ark-ff/std", "ark-serialize/std"]
parallel = [
"std",
"ark-ff/parallel",
"rayon",
"ark-std/parallel",
"ark-serialize/parallel",
]


[[bench]]
Expand Down
3 changes: 2 additions & 1 deletion poly/benches/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
/// * `interval = log_interval`
/// * `min = ceil(log_2(min_degree))`
/// * `max = ceil(log_2(max_degree))`
pub fn size_range(
#[allow(dead_code)]
pub(crate) fn size_range(
log_interval: usize,
min_degree: usize,
max_degree: usize,
Expand Down
15 changes: 7 additions & 8 deletions poly/benches/dense_uv_polynomial.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
extern crate criterion;
mod common;

use ark_ff::{FftField, Field};
Expand Down Expand Up @@ -33,15 +32,15 @@ fn default_size_range() -> Vec<usize> {
)
}

fn setup_bench(c: &mut Criterion, name: &str, bench_fn: fn(&mut Bencher, &usize)) {
fn setup_bench(c: &mut Criterion, name: &str, bench_fn: fn(&mut Bencher<'_>, &usize)) {
let mut group = c.benchmark_group(name);
for degree in default_size_range().iter() {
for degree in &default_size_range() {
group.bench_with_input(BenchmarkId::from_parameter(degree), degree, bench_fn);
}
group.finish();
}

fn bench_sparse_poly_evaluate<F: Field>(b: &mut Bencher, non_zero_entries: &usize) {
fn bench_sparse_poly_evaluate<F: Field>(b: &mut Bencher<'_>, non_zero_entries: &usize) {
const MAX_DEGREE: usize = 1 << 15;
// Per benchmark setup
let mut rng = &mut ark_std::test_rng();
Expand All @@ -56,7 +55,7 @@ fn bench_sparse_poly_evaluate<F: Field>(b: &mut Bencher, non_zero_entries: &usiz
});
}

fn bench_poly_evaluate<F: Field>(b: &mut Bencher, degree: &usize) {
fn bench_poly_evaluate<F: Field>(b: &mut Bencher<'_>, degree: &usize) {
// Per benchmark setup
let mut rng = &mut ark_std::test_rng();
let poly = DensePolynomial::<F>::rand(*degree, &mut rng);
Expand All @@ -67,7 +66,7 @@ fn bench_poly_evaluate<F: Field>(b: &mut Bencher, degree: &usize) {
});
}

fn bench_poly_add<F: Field>(b: &mut Bencher, degree: &usize) {
fn bench_poly_add<F: Field>(b: &mut Bencher<'_>, degree: &usize) {
// Per benchmark setup
let mut rng = &mut ark_std::test_rng();
let poly_one = DensePolynomial::<F>::rand(*degree, &mut rng);
Expand All @@ -78,7 +77,7 @@ fn bench_poly_add<F: Field>(b: &mut Bencher, degree: &usize) {
});
}

fn bench_poly_add_assign<F: Field>(b: &mut Bencher, degree: &usize) {
fn bench_poly_add_assign<F: Field>(b: &mut Bencher<'_>, degree: &usize) {
// Per benchmark setup
let mut rng = &mut ark_std::test_rng();
let mut poly_one = DensePolynomial::<F>::rand(*degree, &mut rng);
Expand All @@ -89,7 +88,7 @@ fn bench_poly_add_assign<F: Field>(b: &mut Bencher, degree: &usize) {
});
}

fn bench_div_by_vanishing_poly<F: FftField>(b: &mut Bencher, degree: &usize) {
fn bench_div_by_vanishing_poly<F: FftField>(b: &mut Bencher<'_>, degree: &usize) {
// Per benchmark setup
let mut rng = &mut ark_std::test_rng();
let p = DensePolynomial::<F>::rand(*degree, &mut rng);
Expand Down
21 changes: 13 additions & 8 deletions poly/benches/fft.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
extern crate criterion;
mod common;

use ark_ff::FftField;
Expand Down Expand Up @@ -43,11 +42,11 @@ fn default_size_range_mnt6_753() -> Vec<usize> {
fn setup_bench(
c: &mut Criterion,
name: &str,
bench_fn: fn(&mut Bencher, &usize),
bench_fn: fn(&mut Bencher<'_>, &usize),
size_range: &[usize],
) {
let mut group = c.benchmark_group(name);
for degree in size_range.iter() {
for degree in size_range {
group.bench_with_input(BenchmarkId::from_parameter(degree), degree, bench_fn);
}
group.finish();
Expand All @@ -69,7 +68,7 @@ fn fft_setup_with_domain_size<F: FftField, D: EvaluationDomain<F>>(
(domain, a)
}

fn bench_fft_in_place<F: FftField, D: EvaluationDomain<F>>(b: &mut Bencher, degree: &usize) {
fn bench_fft_in_place<F: FftField, D: EvaluationDomain<F>>(b: &mut Bencher<'_>, degree: &usize) {
// Per benchmark setup
let (domain, mut a) = fft_setup::<F, D>(*degree);
b.iter(|| {
Expand All @@ -79,7 +78,7 @@ fn bench_fft_in_place<F: FftField, D: EvaluationDomain<F>>(b: &mut Bencher, degr
}

fn bench_large_domain_fft_in_place<F: FftField, D: EvaluationDomain<F>>(
b: &mut Bencher,
b: &mut Bencher<'_>,
degree: &usize,
) {
// Per benchmark setup
Expand All @@ -90,7 +89,7 @@ fn bench_large_domain_fft_in_place<F: FftField, D: EvaluationDomain<F>>(
});
}

fn bench_ifft_in_place<F: FftField, D: EvaluationDomain<F>>(b: &mut Bencher, degree: &usize) {
fn bench_ifft_in_place<F: FftField, D: EvaluationDomain<F>>(b: &mut Bencher<'_>, degree: &usize) {
// Per benchmark setup
let (domain, mut a) = fft_setup::<F, D>(*degree);
b.iter(|| {
Expand All @@ -99,7 +98,10 @@ fn bench_ifft_in_place<F: FftField, D: EvaluationDomain<F>>(b: &mut Bencher, deg
});
}

fn bench_coset_fft_in_place<F: FftField, D: EvaluationDomain<F>>(b: &mut Bencher, degree: &usize) {
fn bench_coset_fft_in_place<F: FftField, D: EvaluationDomain<F>>(
b: &mut Bencher<'_>,
degree: &usize,
) {
// Per benchmark setup
let (domain, mut a) = fft_setup::<F, D>(*degree);
let coset_domain = domain.get_coset(F::GENERATOR).unwrap();
Expand All @@ -109,7 +111,10 @@ fn bench_coset_fft_in_place<F: FftField, D: EvaluationDomain<F>>(b: &mut Bencher
});
}

fn bench_coset_ifft_in_place<F: FftField, D: EvaluationDomain<F>>(b: &mut Bencher, degree: &usize) {
fn bench_coset_ifft_in_place<F: FftField, D: EvaluationDomain<F>>(
b: &mut Bencher<'_>,
degree: &usize,
) {
// Per benchmark setup
let (domain, mut a) = fft_setup::<F, D>(*degree);
let coset_domain = domain.get_coset(F::GENERATOR).unwrap();
Expand Down
Loading
Loading