Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
40 changes: 40 additions & 0 deletions .github/workflows/rust.yml
Original file line number Diff line number Diff line change
@@ -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
25 changes: 25 additions & 0 deletions .github/workflows/weekly-check.yml
Original file line number Diff line number Diff line change
@@ -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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
/target
!justfile
21 changes: 13 additions & 8 deletions curve/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@ pub struct Secp256k1Curve;

impl Secp256k1Curve {
pub const A: FieldElement<Secp256k1FieldOrder> = FieldElement::ZERO;
pub const B: FieldElement<Secp256k1FieldOrder> = FieldElement::from_limbs_unchecked([7, 0, 0, 0]);
pub const B: FieldElement<Secp256k1FieldOrder> =
FieldElement::from_limbs_unchecked([7, 0, 0, 0]);

pub const GENERATOR: Point<Secp256k1FieldOrder> = Point::from_affine(
FieldElement::from_limbs_unchecked([
Expand Down Expand Up @@ -151,7 +152,11 @@ impl<F: FieldOrder> Point<F> {
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<F>) -> Self {
Expand Down Expand Up @@ -188,7 +193,11 @@ impl<F: FieldOrder> Point<F> {
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<G: FieldOrder>(&self, scalar: Scalar<G>, a: FieldElement<F>) -> Self {
Expand Down Expand Up @@ -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]
Expand Down
10 changes: 6 additions & 4 deletions field/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -317,7 +315,11 @@ fn wide_mul<L: Limbs>(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;
Expand Down
1 change: 1 addition & 0 deletions isogeny/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

21 changes: 21 additions & 0 deletions justfile
Original file line number Diff line number Diff line change
@@ -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
Loading