Skip to content

Commit

Permalink
some enhancements
Browse files Browse the repository at this point in the history
  • Loading branch information
tcoratger committed Nov 26, 2024
1 parent 141906a commit f95e47a
Show file tree
Hide file tree
Showing 23 changed files with 273 additions and 198 deletions.
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 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
2 changes: 1 addition & 1 deletion ff/src/fields/models/cubic_extension.rs
Original file line number Diff line number Diff line change
Expand Up @@ -457,7 +457,7 @@ impl<P: CubicExtConfig> From<i8> for CubicExtField<P> {
}

impl<P: CubicExtConfig> From<bool> for CubicExtField<P> {
#[allow(clippy::suspicious_arithmetic_impl)]
#[allow(clippy::unconditional_recursion)]
fn from(other: bool) -> Self {
other.into()
}
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
2 changes: 1 addition & 1 deletion poly/benches/sparse_multilinear.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ fn arithmetic_op_bench<F: Field>(c: &mut Criterion) {

let mut group = c.benchmark_group("SparseMultilinear");
for nv in NUM_VARIABLES_RANGE {
let num_nonzero_entries = 1 << (dbg!(nv) / 2);
let num_nonzero_entries = 1 << (nv / 2);
group.bench_with_input(
BenchmarkId::new(format!("Add with num_vars = {nv}"), num_nonzero_entries),
&num_nonzero_entries,
Expand Down
10 changes: 3 additions & 7 deletions poly/src/domain/mixed_radix.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ impl<F: FftField> EvaluationDomain<F> for MixedRadixEvaluationDomain<F> {
let size_as_field_element = F::from(size);
let size_inv = size_as_field_element.inverse()?;

Some(MixedRadixEvaluationDomain {
Some(Self {
size,
log_size_of_group,
size_as_field_element,
Expand All @@ -103,7 +103,7 @@ impl<F: FftField> EvaluationDomain<F> for MixedRadixEvaluationDomain<F> {
}

fn get_coset(&self, offset: F) -> Option<Self> {
Some(MixedRadixEvaluationDomain {
Some(Self {
offset,
offset_inv: offset.inverse()?,
offset_pow_size: offset.pow([self.size]),
Expand All @@ -124,11 +124,7 @@ impl<F: FftField> EvaluationDomain<F> for MixedRadixEvaluationDomain<F> {
let two_adicity = k_adicity(2, num_coeffs);
let two_part = 2u64.checked_pow(two_adicity)?;

if num_coeffs == q_part * two_part {
Some(num_coeffs as usize)
} else {
None
}
(num_coeffs == q_part * two_part).then_some(num_coeffs as usize)
}

#[inline]
Expand Down
2 changes: 1 addition & 1 deletion poly/src/domain/radix2/fft.rs
Original file line number Diff line number Diff line change
Expand Up @@ -366,7 +366,7 @@ const MIN_INPUT_SIZE_FOR_PARALLELIZATION: usize = 1 << 10;
const LOG_ROOTS_OF_UNITY_PARALLEL_SIZE: u32 = 7;

#[inline]
fn bitrev(a: u64, log_len: u32) -> u64 {
const fn bitrev(a: u64, log_len: u32) -> u64 {
a.reverse_bits().wrapping_shr(64 - log_len)
}

Expand Down
4 changes: 2 additions & 2 deletions poly/src/domain/radix2/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ impl<F: FftField> EvaluationDomain<F> for Radix2EvaluationDomain<F> {
let size_as_field_element = F::from(size);
let size_inv = size_as_field_element.inverse()?;

Some(Radix2EvaluationDomain {
Some(Self {
size,
log_size_of_group,
size_as_field_element,
Expand All @@ -87,7 +87,7 @@ impl<F: FftField> EvaluationDomain<F> for Radix2EvaluationDomain<F> {
}

fn get_coset(&self, offset: F) -> Option<Self> {
Some(Radix2EvaluationDomain {
Some(Self {
offset,
offset_inv: offset.inverse()?,
offset_pow_size: offset.pow([self.size]),
Expand Down
2 changes: 1 addition & 1 deletion poly/src/domain/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ pub(crate) fn compute_powers<F: Field>(size: usize, g: F) -> Vec<F> {
}

#[cfg(feature = "parallel")]
fn log2_floor(num: usize) -> u32 {
const fn log2_floor(num: usize) -> u32 {
if num == 0 {
0
} else {
Expand Down
Loading

0 comments on commit f95e47a

Please sign in to comment.