Skip to content

Commit

Permalink
refactor: remove requirement for nightly in CI and fix nightly clippy
Browse files Browse the repository at this point in the history
  • Loading branch information
han0110 committed Jun 21, 2023
1 parent 0db03bf commit 421537b
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 48 deletions.
25 changes: 4 additions & 21 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,11 @@ jobs:
strategy:
matrix:
include:
- rust: 1.63.0
feature: default
- rust: nightly
feature: asm

- feature: default
- feature: asm
steps:
- uses: actions/checkout@v2
- uses: actions-rs/toolchain@v1
with:
override: true
toolchain: ${{ matrix.rust }}
- name: Build
uses: actions-rs/cargo@v1
with:
Expand All @@ -37,17 +31,11 @@ jobs:
strategy:
matrix:
include:
- rust: 1.63.0
feature: default
- rust: nightly
feature: asm

- feature: default
- feature: asm
steps:
- uses: actions/checkout@v2
- uses: actions-rs/toolchain@v1
with:
override: true
toolchain: ${{ matrix.rust }}
- name: Test
uses: actions-rs/cargo@v1
with:
Expand Down Expand Up @@ -79,8 +67,6 @@ jobs:
- uses: actions/checkout@v2
- uses: actions-rs/toolchain@v1
with:
override: true
toolchain: nightly
components: clippy
- name: Run clippy
uses: actions-rs/cargo@v1
Expand All @@ -96,9 +82,6 @@ jobs:
steps:
- uses: actions/checkout@v2
- uses: actions-rs/toolchain@v1
with:
override: true
toolchain: nightly
- name: Bench arithmetic
uses: actions-rs/cargo@v1
with:
Expand Down
4 changes: 2 additions & 2 deletions src/bn256/fr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -463,8 +463,8 @@ mod test {
let mut rng = ark_std::test_rng();
let base = (0..repeat).map(|_| (rng.next_u32() % (1 << 16)) as u64);

let timer = start_timer!(|| format!("generate {} Bn256 scalar field elements", repeat));
let _res: Vec<_> = base.map(|b| Fr::from(b)).collect();
let timer = start_timer!(|| format!("generate {repeat} Bn256 scalar field elements"));
let _res: Vec<_> = base.map(Fr::from).collect();

end_timer!(timer);
}
Expand Down
2 changes: 0 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
#![cfg_attr(feature = "asm", feature(asm_const))]

mod arithmetic;
pub mod hash_to_curve;
pub mod pairing;
Expand Down
4 changes: 2 additions & 2 deletions src/secp256r1/fp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ impl ff::Field for Fp {

/// Computes the square root of this element, if it exists.
fn sqrt(&self) -> CtOption<Self> {
let tmp = self.pow(&[
let tmp = self.pow([
0x0000000000000000,
0x0000000040000000,
0x4000000000000000,
Expand All @@ -200,7 +200,7 @@ impl ff::Field for Fp {
/// Computes the multiplicative inverse of this element,
/// failing if the element is zero.
fn invert(&self) -> CtOption<Self> {
let tmp = self.pow_vartime(&[
let tmp = self.pow_vartime([
0xfffffffffffffffd,
0x00000000ffffffff,
0x0000000000000000,
Expand Down
14 changes: 4 additions & 10 deletions src/secp256r1/fq.rs
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ impl ff::Field for Fq {
/// Computes the multiplicative inverse of this element,
/// failing if the element is zero.
fn invert(&self) -> CtOption<Self> {
let tmp = self.pow_vartime(&[
let tmp = self.pow_vartime([
0xf3b9cac2fc63254f,
0xbce6faada7179e84,
0xffffffffffffffff,
Expand Down Expand Up @@ -214,7 +214,7 @@ impl ff::Field for Fq {
0x7fffffff8000000,
];

ff::helpers::sqrt_tonelli_shanks(self, &tm1d2)
ff::helpers::sqrt_tonelli_shanks(self, tm1d2)
}

fn sqrt_ratio(num: &Self, div: &Self) -> (Choice, Self) {
Expand Down Expand Up @@ -344,18 +344,12 @@ mod test {

#[test]
fn test_delta() {
assert_eq!(
Fq::DELTA,
Fq::MULTIPLICATIVE_GENERATOR.pow(&[1u64 << Fq::S, 0, 0, 0])
);
assert_eq!(Fq::DELTA, Fq::MULTIPLICATIVE_GENERATOR.pow([1u64 << Fq::S]));
}

#[test]
fn test_root_of_unity() {
assert_eq!(
Fq::ROOT_OF_UNITY.pow_vartime(&[1 << Fq::S, 0, 0, 0]),
Fq::one()
);
assert_eq!(Fq::ROOT_OF_UNITY.pow_vartime([1 << Fq::S]), Fq::one());
}

#[test]
Expand Down
22 changes: 11 additions & 11 deletions src/tests/field.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ pub fn random_field_tests<F: Field>(type_name: String) {
}

fn random_multiplication_tests<F: Field, R: RngCore>(mut rng: R, type_name: String) {
let _message = format!("multiplication {}", type_name);
let _message = format!("multiplication {type_name}");
let start = start_timer!(|| _message);
for _ in 0..1000000 {
let a = F::random(&mut rng);
Expand All @@ -74,7 +74,7 @@ fn random_multiplication_tests<F: Field, R: RngCore>(mut rng: R, type_name: Stri
}

fn random_addition_tests<F: Field, R: RngCore>(mut rng: R, type_name: String) {
let _message = format!("addition {}", type_name);
let _message = format!("addition {type_name}");
let start = start_timer!(|| _message);
for _ in 0..1000000 {
let a = F::random(&mut rng);
Expand All @@ -100,7 +100,7 @@ fn random_addition_tests<F: Field, R: RngCore>(mut rng: R, type_name: String) {
}

fn random_subtraction_tests<F: Field, R: RngCore>(mut rng: R, type_name: String) {
let _message = format!("subtraction {}", type_name);
let _message = format!("subtraction {type_name}");
let start = start_timer!(|| _message);
for _ in 0..1000000 {
let a = F::random(&mut rng);
Expand All @@ -121,7 +121,7 @@ fn random_subtraction_tests<F: Field, R: RngCore>(mut rng: R, type_name: String)
}

fn random_negation_tests<F: Field, R: RngCore>(mut rng: R, type_name: String) {
let _message = format!("negation {}", type_name);
let _message = format!("negation {type_name}");
let start = start_timer!(|| _message);
for _ in 0..1000000 {
let a = F::random(&mut rng);
Expand All @@ -135,7 +135,7 @@ fn random_negation_tests<F: Field, R: RngCore>(mut rng: R, type_name: String) {
}

fn random_doubling_tests<F: Field, R: RngCore>(mut rng: R, type_name: String) {
let _message = format!("doubling {}", type_name);
let _message = format!("doubling {type_name}");
let start = start_timer!(|| _message);
for _ in 0..1000000 {
let mut a = F::random(&mut rng);
Expand All @@ -149,7 +149,7 @@ fn random_doubling_tests<F: Field, R: RngCore>(mut rng: R, type_name: String) {
}

fn random_squaring_tests<F: Field, R: RngCore>(mut rng: R, type_name: String) {
let _message = format!("squaring {}", type_name);
let _message = format!("squaring {type_name}");
let start = start_timer!(|| _message);
for _ in 0..1000000 {
let mut a = F::random(&mut rng);
Expand All @@ -165,7 +165,7 @@ fn random_squaring_tests<F: Field, R: RngCore>(mut rng: R, type_name: String) {
fn random_inversion_tests<F: Field, R: RngCore>(mut rng: R, type_name: String) {
assert!(bool::from(F::ZERO.invert().is_none()));

let _message = format!("inversion {}", type_name);
let _message = format!("inversion {type_name}");
let start = start_timer!(|| _message);
for _ in 0..1000000 {
let mut a = F::random(&mut rng);
Expand All @@ -178,7 +178,7 @@ fn random_inversion_tests<F: Field, R: RngCore>(mut rng: R, type_name: String) {
}

fn random_expansion_tests<F: Field, R: RngCore>(mut rng: R, type_name: String) {
let _message = format!("expansion {}", type_name);
let _message = format!("expansion {type_name}");
let start = start_timer!(|| _message);
for _ in 0..1000000 {
// Compare (a + b)(c + d) and (a*c + b*c + a*d + b*d)
Expand Down Expand Up @@ -218,7 +218,7 @@ pub fn random_bits_tests<F: ff::PrimeFieldBits>(type_name: String) {
0x59, 0x62, 0xbe, 0x5d, 0x76, 0x3d, 0x31, 0x8d, 0x17, 0xdb, 0x37, 0x32, 0x54, 0x06, 0xbc,
0xe5,
]);
let _message = format!("to_le_bits {}", type_name);
let _message = format!("to_le_bits {type_name}");
let start = start_timer!(|| _message);
for _ in 0..1000000 {
let a = F::random(&mut rng);
Expand All @@ -236,7 +236,7 @@ pub fn random_serialization_test<F: Field + SerdeObject>(type_name: String) {
0x59, 0x62, 0xbe, 0x5d, 0x76, 0x3d, 0x31, 0x8d, 0x17, 0xdb, 0x37, 0x32, 0x54, 0x06, 0xbc,
0xe5,
]);
let _message = format!("serialization with SerdeObject {}", type_name);
let _message = format!("serialization with SerdeObject {type_name}");
let start = start_timer!(|| _message);
for _ in 0..1000000 {
let a = F::random(&mut rng);
Expand All @@ -260,7 +260,7 @@ where
0x59, 0x62, 0xbe, 0x5d, 0x76, 0x3d, 0x31, 0x8d, 0x17, 0xdb, 0x37, 0x32, 0x54, 0x06, 0xbc,
0xe5,
]);
let _message = format!("serialization with serde {}", type_name);
let _message = format!("serialization with serde {type_name}");
let start = start_timer!(|| _message);
for _ in 0..1000000 {
let a = F::random(&mut rng);
Expand Down

0 comments on commit 421537b

Please sign in to comment.