From 206d072d1239fad76eb9f46a89b6a6f20efb2ba4 Mon Sep 17 00:00:00 2001 From: rustaceanrob Date: Tue, 7 Jul 2026 17:23:38 +0100 Subject: [PATCH] Add justfile and CI --- .github/workflows/rust.yml | 40 ++++++++++++++++++++++++++++++ .github/workflows/weekly-check.yml | 25 +++++++++++++++++++ .gitignore | 1 + curve/src/lib.rs | 21 ++++++++++------ field/src/lib.rs | 10 +++++--- isogeny/src/lib.rs | 1 + justfile | 21 ++++++++++++++++ 7 files changed, 107 insertions(+), 12 deletions(-) create mode 100644 .github/workflows/rust.yml create mode 100644 .github/workflows/weekly-check.yml create mode 100644 justfile diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml new file mode 100644 index 0000000..c5671f9 --- /dev/null +++ b/.github/workflows/rust.yml @@ -0,0 +1,40 @@ +# A few guiding principles. +# +# * Always use actions-rust-lang/setup-rust-toolchain for its built-in caching. +# * Complexity lives in the justfile, this runner is as light as possible. + +name: CI + +# Run on direct commits to master, including merges, and any pull requests against master. +on: + push: + branches: + - master + pull_request: + branches: + - master + +jobs: + # Quick canary of code as well as potential issues with upcoming toolchains. + check: + strategy: + matrix: + toolchain: [stable, beta, nightly] + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: extractions/setup-just@v3 + - uses: actions-rust-lang/setup-rust-toolchain@v1 + with: + toolchain: ${{ matrix.toolchain }} + components: clippy,rustfmt + - run: just check + # Build and test the code across platforms. + test: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: extractions/setup-just@v3 + - uses: actions-rust-lang/setup-rust-toolchain@v1 + - name: "Run test suite" + run: just test diff --git a/.github/workflows/weekly-check.yml b/.github/workflows/weekly-check.yml new file mode 100644 index 0000000..86f77a7 --- /dev/null +++ b/.github/workflows/weekly-check.yml @@ -0,0 +1,25 @@ +# Attempt to detect any upcoming breaking changes if CI hasn't been run in awhile. +name: Weekly Check + +on: + # Allows manual triggering. + workflow_dispatch: + schedule: + # Run at midnight on Sundays. + - cron: "0 0 * * 0" + +jobs: + # Quick canary of code as well as potential issues with upcoming toolchains. + check: + strategy: + matrix: + toolchain: [stable, beta, nightly] + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: extractions/setup-just@v3 + - uses: actions-rust-lang/setup-rust-toolchain@v1 + with: + toolchain: ${{ matrix.toolchain }} + components: clippy,rustfmt + - run: just check diff --git a/.gitignore b/.gitignore index ea8c4bf..f51e948 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ /target +!justfile diff --git a/curve/src/lib.rs b/curve/src/lib.rs index 89d7180..12af534 100644 --- a/curve/src/lib.rs +++ b/curve/src/lib.rs @@ -41,7 +41,8 @@ pub struct Secp256k1Curve; impl Secp256k1Curve { pub const A: FieldElement = FieldElement::ZERO; - pub const B: FieldElement = FieldElement::from_limbs_unchecked([7, 0, 0, 0]); + pub const B: FieldElement = + FieldElement::from_limbs_unchecked([7, 0, 0, 0]); pub const GENERATOR: Point = Point::from_affine( FieldElement::from_limbs_unchecked([ @@ -151,7 +152,11 @@ impl Point { let y3 = m * (s - t) - eight_yyyy; let y_plus_z = self.y + self.z; let z3 = y_plus_z * y_plus_z - yy - zz; - Self { x: x3, y: y3, z: z3 } + Self { + x: x3, + y: y3, + z: z3, + } } fn add(&self, other: &Self, a: FieldElement) -> Self { @@ -188,7 +193,11 @@ impl Point { let y3 = r * (v - x3) - two_s1_j; let z1_plus_z2 = self.z + other.z; let z3 = (z1_plus_z2 * z1_plus_z2 - z1z1 - z2z2) * h; - Self { x: x3, y: y3, z: z3 } + Self { + x: x3, + y: y3, + z: z3, + } } fn mul(&self, scalar: Scalar, a: FieldElement) -> Self { @@ -389,11 +398,7 @@ mod tests { #[test] fn mul_by_zero_is_infinity() { - assert!( - CURVE - .multiply(Sc::from_u128(0), generator()) - .is_infinity() - ); + assert!(CURVE.multiply(Sc::from_u128(0), generator()).is_infinity()); } #[test] diff --git a/field/src/lib.rs b/field/src/lib.rs index d12763a..df8e0da 100644 --- a/field/src/lib.rs +++ b/field/src/lib.rs @@ -3,9 +3,7 @@ use core::hash::Hash; use core::marker::PhantomData; use core::ops::{Add, AddAssign, Mul, MulAssign, Sub, SubAssign}; -pub trait Limbs: - Copy + fmt::Debug + PartialEq + Eq + Hash + AsRef<[u64]> + AsMut<[u64]> -{ +pub trait Limbs: Copy + fmt::Debug + PartialEq + Eq + Hash + AsRef<[u64]> + AsMut<[u64]> { const ZERO: Self; const ONE: Self; const TWO: Self; @@ -317,7 +315,11 @@ fn wide_mul(a: &L, b: &L) -> (L, L) { let mut carry = 0u64; for (j, &bj) in b_slice.iter().enumerate() { let idx = i + j; - let cell = if idx < n { lo_slice[idx] } else { hi_slice[idx - n] }; + let cell = if idx < n { + lo_slice[idx] + } else { + hi_slice[idx - n] + }; let (product, new_carry) = a_slice[i].carrying_mul_add(bj, cell, carry); if idx < n { lo_slice[idx] = product; diff --git a/isogeny/src/lib.rs b/isogeny/src/lib.rs index e69de29..8b13789 100644 --- a/isogeny/src/lib.rs +++ b/isogeny/src/lib.rs @@ -0,0 +1 @@ + diff --git a/justfile b/justfile new file mode 100644 index 0000000..fadf8ec --- /dev/null +++ b/justfile @@ -0,0 +1,21 @@ +check: + cargo fmt -- --check + cargo clippy --all-targets -- -D warnings + cargo check --all-features + +# Run a test suite: unit, msrv, min-versions +test suite="workspace": + just _test-{{suite}} + +_test-workspace: + cargo test --workspace + +# Delete unused files or branches: data, lockfile, branches +delete item="branches": + just _delete-{{item}} + +_delete-lockfile: + rm -f Cargo.lock + +_delete-branches: + git branch --merged | grep -v \* | xargs git branch -d