Skip to content

Commit

Permalink
Automatically test fq8 in CI using --cfg tiny_poly (#25)
Browse files Browse the repository at this point in the history
  • Loading branch information
teor2345 committed Apr 8, 2024
1 parent 66c3dc5 commit 3b99d2f
Show file tree
Hide file tree
Showing 11 changed files with 111 additions and 41 deletions.
34 changes: 19 additions & 15 deletions .github/workflows/ci-bench.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: 'Rust Benchmarks'
name: 'Benchmarks'

on:
workflow_dispatch:
Expand All @@ -16,19 +16,23 @@ concurrency:

jobs:
bench:
name: Rust Benchmarks

# Benchmarks have custom code to compare different functions, so we don't need to have a matrix here.
runs-on: ubuntu-latest

steps:
- name: Checkout
uses: actions/checkout@v4

- name: Build Benchmarks
run: |
export RUSTFLAGS="-D warnings"
cargo bench --no-run --all-features --all-targets
- name: Run Tests
run: |
export RUSTFLAGS="-D warnings"
echo "Warning: benchmark timings are unreliable in CI due to virtualization"
cargo bench --all-features --all-targets
echo "Warning: benchmark timings are unreliable in CI due to virtualization"
- name: Checkout
uses: actions/checkout@v4

- name: Build Benchmarks
run: |
export RUSTFLAGS="-D warnings"
cargo bench --no-run --features benchmark --all-targets
- name: Run Benchmarks
run: |
export RUSTFLAGS="-D warnings"
echo "Warning: benchmark timings are unreliable in CI due to virtualization"
cargo bench --features benchmark --all-targets
echo "Warning: benchmark timings are unreliable in CI due to virtualization"
24 changes: 17 additions & 7 deletions .github/workflows/ci-build.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: 'Build and Run Rust Binaries'
name: 'Build and Run'

on:
workflow_dispatch:
Expand All @@ -16,17 +16,27 @@ concurrency:

jobs:
build:
name: Rust Build and Run

strategy:
matrix:
# rustc config options
cfg: ["", "--cfg tiny_poly"]
# cargo feature options
features: ["", "--no-default-features", "--all-features"]

runs-on: ubuntu-latest

steps:
- name: Checkout
uses: actions/checkout@v4

- name: Build
- name: Build All Targets
run: |
export RUSTFLAGS="-D warnings"
cargo build --release --all-features --all-targets
export RUSTFLAGS="-D warnings ${{ matrix.cfg}}"
cargo build --release --all-targets ${{ matrix.features}}
- name: Run
- name: Run Binaries
run: |
export RUSTFLAGS="-D warnings"
cargo run --release --all-features
export RUSTFLAGS="-D warnings ${{ matrix.cfg}}"
cargo run --release ${{ matrix.features}}
24 changes: 17 additions & 7 deletions .github/workflows/ci-test.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: 'Rust Tests'
name: 'Tests'

on:
workflow_dispatch:
Expand All @@ -16,23 +16,33 @@ concurrency:

jobs:
test:
name: Rust Tests

strategy:
matrix:
# rustc config options
cfg: ["", "--cfg tiny_poly"]
# cargo feature options
features: ["", "--no-default-features", "--all-features"]

runs-on: ubuntu-latest

steps:
- name: Checkout
uses: actions/checkout@v4

- name: Build Tests
run: |
export RUSTFLAGS="-D warnings"
cargo test --no-run --all-features --all-targets
export RUSTFLAGS="-D warnings ${{ matrix.cfg}}"
cargo test --no-run --all-targets ${{ matrix.features}}
- name: Run Tests
run: |
export RUSTFLAGS="-D warnings"
cargo test --all-features --all-targets
export RUSTFLAGS="-D warnings ${{ matrix.cfg}}"
cargo test --all-targets ${{ matrix.features}}
# For historical reasons, Rust documentation tests are not run by `cargo test`.
- name: Run Doc Tests
run: |
export RUSTFLAGS="-D warnings"
cargo test --doc --all-features
export RUSTFLAGS="-D warnings ${{ matrix.cfg}}"
cargo test --doc ${{ matrix.features}}
14 changes: 12 additions & 2 deletions .github/workflows/lint-clippy.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: 'Rust Clippy Lints'
name: 'Clippy Lints'

on:
workflow_dispatch:
Expand All @@ -16,7 +16,17 @@ concurrency:

jobs:
clippy:
name: Rust Lints

strategy:
matrix:
# rustc config options
cfg: ["", "--cfg tiny_poly"]
# cargo feature options
features: ["", "--no-default-features", "--all-features"]

runs-on: ubuntu-latest

steps:
- name: Checkout
uses: actions/checkout@v4
Expand All @@ -25,4 +35,4 @@ jobs:
uses: actions-rs/clippy-check@v1
with:
token: ${{ secrets.GITHUB_TOKEN }}
args: --all-features --all-targets -- -D warnings
args: --all-targets ${{ matrix.features}} -- -D warnings ${{ matrix.cfg}}
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,15 @@
# eyelid

Private iris matching

## Testing

Temporarily switch to a tiny field to make test errors easier to debug:
```sh
RUSTFLAGS="--cfg tiny_poly" cargo test
RUSTFLAGS="--cfg tiny_poly" cargo bench --features benchmark
```

## Future Work

Benchmark Rust futures with `criterion` by enabling the [`async_tokio` feature](https://bheisler.github.io/criterion.rs/book/user_guide/benchmarking_async.html).
Expand Down
4 changes: 4 additions & 0 deletions eyelid-match-ops/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ benchmark = [
"rand",
]

# Temporarily switch to a tiny field to make test errors easier to debug:
# RUSTFLAGS="--cfg tiny_poly" cargo test
# RUSTFLAGS="--cfg tiny_poly" cargo bench --features benchmark

[dependencies]
ark-ff.workspace = true
ark-poly.workspace = true
Expand Down
16 changes: 6 additions & 10 deletions eyelid-match-ops/src/primitives/poly.rs
Original file line number Diff line number Diff line change
@@ -1,24 +1,20 @@
//! Cyclotomic polynomial operations using ark-poly

use crate::primitives::poly::fq79::Fq79;
use std::ops::{Add, Sub};

use ark_ff::{One, Zero};
use ark_poly::polynomial::{
univariate::{DenseOrSparsePolynomial, DensePolynomial},
Polynomial,
};
use lazy_static::lazy_static;
use std::ops::Add;
use std::ops::Sub;

pub mod fq79;
pub mod fq8;
pub mod fq;

#[cfg(any(test, feature = "benchmark"))]
pub mod test;

pub use fq79::{Coeff, MAX_POLY_DEGREE};
// Temporarily switch to this tiny field to make test errors easier to debug.
//pub use fq8::{Coeff, MAX_POLY_DEGREE};
pub use fq::{Coeff,MAX_POLY_DEGREE};

/// A modular polynomial with coefficients in [`Coeff`],
/// and maximum degree [`MAX_POLY_DEGREE`].
Expand Down Expand Up @@ -149,7 +145,7 @@ pub fn karatsuba_mul(a: &Poly, b: &Poly) -> Poly {
res = res.sub(&arbr);
let halfn = n / 2;
let mut xnb2 = zero_poly(halfn);
xnb2.coeffs[halfn] = Fq79::one();
xnb2.coeffs[halfn] = Coeff::one();
res = cyclotomic_mul(&res.clone(), &xnb2);
res = res.add(albl);
if n >= MAX_POLY_DEGREE {
Expand All @@ -158,7 +154,7 @@ pub fn karatsuba_mul(a: &Poly, b: &Poly) -> Poly {
} else {
// Otherwise proceed as usual
let mut xn = zero_poly(n);
xn.coeffs[n] = Fq79::one();
xn.coeffs[n] = Coeff::one();
let aux = cyclotomic_mul(&arbr, &xn);
res = res.add(aux);
}
Expand Down
18 changes: 18 additions & 0 deletions eyelid-match-ops/src/primitives/poly/fq.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
//! The underlying integer field.
//!
//! Outside this module, use [`fq::Coeff`] and [`fq::MAX_POLY_DEGREE`] instead of `fq79` or `fq8`.
//! This automatically enables tests on both fields.

mod fq79;
mod fq8;

#[cfg(not(tiny_poly))]
pub use fq79::{Coeff, MAX_POLY_DEGREE};

// Temporarily switch to this tiny field to make test errors easier to debug:
// ```no_run
// RUSTFLAGS="--cfg tiny_poly" cargo test
// RUSTFLAGS="--cfg tiny_poly" cargo bench --features benchmark
// ```
#[cfg(tiny_poly)]
pub use fq8::{Coeff, MAX_POLY_DEGREE};
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
//! These are the parameters for full resolution, according to the Inversed Tech report.
//! t = 2ˆ15, q = 2ˆ79, N = 2048

#![cfg_attr(tiny_poly, allow(dead_code))]

use ark_ff::{Fp128, MontBackend, MontConfig};

/// The maximum exponent in the polynomial.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
//! These test parameters are specifically chosen to make failing tests easy to read and diagnose.
//! q = 2ˆ8, N = 4

#![cfg_attr(not(tiny_poly), allow(dead_code))]

use ark_ff::{Fp64, MontBackend, MontConfig};

/// The maximum exponent in the test-only polynomial.
Expand Down
5 changes: 5 additions & 0 deletions eyelid-match-ops/src/primitives/poly/test/mul.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,11 @@ fn test_cyclotomic_mul_max_degree() {
);

for i in 0..=MAX_POLY_DEGREE {
// This test is slow, so skip most values.
if i % 101 != 0 && ![0, 1, MAX_POLY_DEGREE/2 - 1, MAX_POLY_DEGREE/2, MAX_POLY_DEGREE/2 + 1, MAX_POLY_DEGREE - 1, MAX_POLY_DEGREE].contains(&i) {
continue;
}

// X^i * X^{MAX_POLY_DEGREE - i} = X^MAX_POLY_DEGREE
let mut p1 = zero_poly(i);
p1[i] = Coeff::one();
Expand Down

0 comments on commit 3b99d2f

Please sign in to comment.