Skip to content

Commit

Permalink
chore: Fix zkvm CI (zkcrypto#7)
Browse files Browse the repository at this point in the history
* ci: Update clippy, toolchain, dependabot (zkcrypto#5)

* chore: Fix CI
  • Loading branch information
samuelburnham authored Apr 25, 2024
1 parent 7b025c4 commit cc88a3b
Show file tree
Hide file tree
Showing 12 changed files with 240 additions and 274 deletions.
54 changes: 54 additions & 0 deletions .cargo/config.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
[alias]
# Collection of project wide clippy lints. This is done via an alias because
# clippy doesn't currently allow for specifiying project-wide lints in a
# configuration file. This is a similar workaround to the ones presented here:
# <https://github.com/EmbarkStudios/rust-ecosystem/issues/59>
xclippy = [
"clippy", "--workspace", "--all-targets", "--all-features", "--",
"-Wclippy::all",
#"-Wclippy::cast_lossless",
#"-Wclippy::checked_conversions",
#"-Wclippy::dbg_macro",
#"-Wclippy::disallowed_methods",
#"-Wclippy::derive_partial_eq_without_eq",
#"-Wclippy::enum_glob_use",
#"-Wclippy::explicit_into_iter_loop",
#"-Wclippy::fallible_impl_from",
#"-Wclippy::filter_map_next",
#"-Wclippy::flat_map_option",
#"-Wclippy::from_iter_instead_of_collect",
#"-Wclippy::implicit_clone",
#"-Wclippy::inefficient_to_string",
#"-Wclippy::invalid_upcast_comparisons",
#"-Wclippy::large_stack_arrays",
#"-Wclippy::large_types_passed_by_value",
#"-Wclippy::macro_use_imports",
#"-Wclippy::manual_assert",
#"-Wclippy::manual_ok_or",
#"-Wclippy::map_flatten",
#"-Wclippy::map_unwrap_or",
#"-Wclippy::match_same_arms",
#"-Wclippy::match_wild_err_arm",
#"-Wclippy::missing_const_for_fn",
#"-Wclippy::needless_borrow",
#"-Wclippy::needless_continue",
#"-Wclippy::needless_for_each",
#"-Wclippy::needless_pass_by_value",
#"-Wclippy::option_option",
#"-Wclippy::same_functions_in_if_condition",
#"-Wclippy::single_match_else",
#"-Wclippy::trait_duplication_in_bounds",
#"-Wclippy::unnecessary_wraps",
#"-Wclippy::unnested_or_patterns",
#"-Wnonstandard_style",
#"-Wrust_2018_idioms",
#"-Wtrivial_numeric_casts",
#"-Wunused_lifetimes",
#"-Wunreachable_pub",
#"-Wtrivial_numeric_casts",
#"-Wunused_qualifications",
"-Aclippy::needless_borrows_for_generic_args",
"-Aclippy::needless_borrow",
"-Aclippy::clone_on_copy",
"-Aclippy::op_ref",
]
32 changes: 20 additions & 12 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -1,14 +1,22 @@
version: 2
updates:
- package-ecosystem: github-actions
directory: "/"
schedule:
interval: daily
timezone: Etc/UTC
open-pull-requests-limit: 10
reviewers:
- str4d
assignees:
- str4d
labels:
- "A-CI"
- package-ecosystem: cargo
directory: /
pull-request-branch-name:
separator: "-"
schedule:
interval: weekly
groups:
rust-dependencies:
patterns:
- "*"
update-types:
- "minor"
- "patch"
open-pull-requests-limit: 5

- package-ecosystem: "github-actions"
directory: "/"
schedule:
interval: "weekly"

11 changes: 5 additions & 6 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,22 +9,19 @@ jobs:
strategy:
matrix:
os: [ubuntu-latest, windows-latest, macOS-latest]

steps:
- uses: actions/checkout@v3
- name: Run tests
run: cargo test --verbose --release --features experimental,zeroize

no-std:
name: Check no-std target ${{ matrix.target }}
wasm:
name: Check wasm target ${{ matrix.target }}
runs-on: ubuntu-latest
strategy:
matrix:
target:
- thumbv6m-none-eabi
- wasm32-unknown-unknown
- wasm32-wasi

steps:
- uses: actions/checkout@v3
- run: rustup target add ${{ matrix.target }}
Expand Down Expand Up @@ -56,11 +53,13 @@ jobs:
- name: Check intra-doc links
run: cargo doc --document-private-items

fmt:
clippy:
name: Rustfmt
timeout-minutes: 30
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Check formatting
run: cargo fmt --all -- --check
- name: Clippy
run: cargo xclippy
24 changes: 0 additions & 24 deletions .github/workflows/lints-beta.yml

This file was deleted.

18 changes: 0 additions & 18 deletions .github/workflows/lints-stable.yml

This file was deleted.

4 changes: 2 additions & 2 deletions rust-toolchain.toml
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
[toolchain]
channel = "1.56.0"
components = [ "clippy", "rustfmt" ]
channel = "stable"
profile = "default"
4 changes: 3 additions & 1 deletion src/fp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ use subtle::{Choice, ConditionallySelectable, ConstantTimeEq, CtOption};

use crate::util::{adc, mac, sbb};

#[cfg(target_os = "zkvm")]
extern "C" {
fn syscall_bls12381_fp_add(p: *mut u32, q: *const u32);
fn syscall_bls12381_fp_sub(p: *mut u32, q: *const u32);
Expand Down Expand Up @@ -87,6 +88,7 @@ const MODULUS: [u64; 6] = [
const INV: u64 = 0x89f3_fffc_fffc_fffd;

/// R_INV = (2^384)^(-1) mod p
#[cfg(target_os = "zkvm")]
const R_INV: Fp = Fp([
0xf4d38259380b4820,
0x7fe11274d898fafb,
Expand Down Expand Up @@ -655,6 +657,7 @@ impl Fp {
}
}

#[cfg(target_os = "zkvm")]
pub(crate) fn reduce_internal(&self) -> Fp {
// Turn into canonical form by computing
// (a.R) / R = a
Expand All @@ -674,7 +677,6 @@ impl Fp {
}
}


/// Squares this element.
#[inline]
pub fn square(&self) -> Self {
Expand Down
36 changes: 17 additions & 19 deletions src/fp2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ use subtle::{Choice, ConditionallySelectable, ConstantTimeEq, CtOption};

use crate::fp::Fp;

#[cfg(target_os = "zkvm")]
extern "C" {
fn syscall_bls12381_fp2_add(p: *mut u32, q: *const u32);
fn syscall_bls12381_fp2_sub(p: *mut u32, q: *const u32);
Expand Down Expand Up @@ -236,25 +237,22 @@ impl Fp2 {
};
new_out
} else {
let res = {
// F_{p^2} x F_{p^2} multiplication implemented with operand scanning (schoolbook)
// computes the result as:
//
// a·b = (a_0 b_0 + a_1 b_1 β) + (a_0 b_1 + a_1 b_0)i
//
// In BLS12-381's F_{p^2}, our β is -1, so the resulting F_{p^2} element is:
//
// c_0 = a_0 b_0 - a_1 b_1
// c_1 = a_0 b_1 + a_1 b_0
//
// Each of these is a "sum of products", which we can compute efficiently.

Fp2 {
c0: Fp::sum_of_products([self.c0, -self.c1], [rhs.c0, rhs.c1]),
c1: Fp::sum_of_products([self.c0, self.c1], [rhs.c1, rhs.c0]),
}
};
res
// F_{p^2} x F_{p^2} multiplication implemented with operand scanning (schoolbook)
// computes the result as:
//
// a·b = (a_0 b_0 + a_1 b_1 β) + (a_0 b_1 + a_1 b_0)i
//
// In BLS12-381's F_{p^2}, our β is -1, so the resulting F_{p^2} element is:
//
// c_0 = a_0 b_0 - a_1 b_1
// c_1 = a_0 b_1 + a_1 b_0
//
// Each of these is a "sum of products", which we can compute efficiently.

Fp2 {
c0: Fp::sum_of_products([self.c0, -self.c1], [rhs.c0, rhs.c1]),
c1: Fp::sum_of_products([self.c0, self.c1], [rhs.c1, rhs.c0]),
}
}
}
}
Expand Down
1 change: 1 addition & 0 deletions src/g1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ use group::WnafGroup;
use crate::fp::Fp;
use crate::Scalar;

#[cfg(target_os = "zkvm")]
extern "C" {
fn syscall_bls12381_g1_decompress(p: &mut [u8; 96]);
}
Expand Down
4 changes: 2 additions & 2 deletions src/g2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -648,8 +648,8 @@ impl_binops_multiplicative_mixed!(Scalar, G2Projective, G2Projective);

#[inline(always)]
fn mul_by_3b(x: Fp2) -> Fp2 {
let B3: Fp2 = Fp2::add(&Fp2::add(&B, &B), &B); // FIXME
x * B3
let b3: Fp2 = Fp2::add(&Fp2::add(&B, &B), &B); // FIXME
x * b3
}

impl G2Projective {
Expand Down
12 changes: 6 additions & 6 deletions src/hash_to_curve/map_g1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -943,14 +943,14 @@ pub const P_M1_OVER2: Fp = Fp::from_raw_unchecked([

#[test]
fn test_sgn0() {
assert_eq!(bool::from(Fp::zero().sgn0()), false);
assert_eq!(bool::from(Fp::one().sgn0()), true);
assert_eq!(bool::from((-Fp::one()).sgn0()), false);
assert_eq!(bool::from((-Fp::zero()).sgn0()), false);
assert_eq!(bool::from(P_M1_OVER2.sgn0()), true);
assert!(!bool::from(Fp::zero().sgn0()));
assert!(bool::from(Fp::one().sgn0()));
assert!(!bool::from((-Fp::one()).sgn0()));
assert!(!bool::from((-Fp::zero()).sgn0()));
assert!(bool::from(P_M1_OVER2.sgn0()));

let p_p1_over2 = P_M1_OVER2 + Fp::one();
assert_eq!(bool::from(p_p1_over2.sgn0()), false);
assert!(!bool::from(p_p1_over2.sgn0()));

let neg_p_p1_over2 = {
let mut tmp = p_p1_over2;
Expand Down
Loading

0 comments on commit cc88a3b

Please sign in to comment.