Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: add doc check to lint #1119

Merged
merged 3 commits into from
Dec 19, 2024
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
4 changes: 2 additions & 2 deletions .github/workflows/docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,13 @@ jobs:
run: cargo check

- name: Build documentation
run: cargo doc --workspace
run: cargo doc --workspace --exclude "openvm-benchmarks" --exclude "*-tests" --exclude "*-test"

# We only want the index page to display workspace crates, so we build
# separately and copy over the index as a hack
- name: Build index page
run: |
cargo doc --workspace --no-deps --exclude "openvm-benchmarks" --target-dir target/doc-nodeps
cargo doc --workspace --no-deps --exclude "openvm-benchmarks" --exclude "*-tests" --exclude "*-test" --target-dir target/doc-nodeps
cp target/doc-nodeps/doc/index.html target/doc/
cp target/doc-nodeps/doc/crates.js target/doc/
env:
Expand Down
35 changes: 12 additions & 23 deletions .github/workflows/ecc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ jobs:
tests:
runs-on:
- runs-on=${{ github.run_id }}
- runner=32cpu-linux-arm64
- runner=64cpu-linux-arm64

steps:
- uses: actions/checkout@v4
Expand All @@ -35,40 +35,29 @@ jobs:
cache-on-failure: true
- uses: taiki-e/install-action@nextest

- name: Run pairing-guest crate tests
working-directory: extensions/pairing/guest
run: |
cargo nextest run --cargo-profile=fast --features=bn254,bls12_381,halo2curves

- name: Run ecc-circuits crate tests
working-directory: extensions/ecc/circuit
run: |
cargo nextest run --cargo-profile=fast

- name: Run ecc integration tests
working-directory: extensions/ecc/tests
run: |
rustup component add rust-src --toolchain nightly-2024-10-30
cargo nextest run --cargo-profile=fast

- name: Run pairing-circuits crate tests
working-directory: extensions/pairing/circuit
run: |
RUST_MIN_STACK=8388608 cargo nextest run --cargo-profile=fast

- name: Run pairing-guest crate tests
working-directory: extensions/pairing/guest
run: |
cargo nextest run --cargo-profile=fast --features=bn254,bls12_381,halo2curves

- name: Run pairing integration tests
working-directory: extensions/pairing/tests
run: |
rustup component add rust-src --toolchain nightly-2024-10-30
RUST_MIN_STACK=8388608 cargo nextest run --cargo-profile=fast

- name: Install cargo-openvm
working-directory: crates/cli
run: |
rustup component add rust-src --toolchain nightly-2024-10-30
cargo install --force --locked --path .

- name: Build openvm-ecc-guest crate for openvm
working-directory: extensions/ecc/guest
run: |
cargo openvm build --no-transpile

- name: Run ecc integration tests
working-directory: extensions/ecc/tests
run: |
rustup component add rust-src --toolchain nightly-2024-10-30
cargo nextest run --cargo-profile=fast
4 changes: 4 additions & 0 deletions .github/workflows/lints.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ jobs:
with:
cache-on-failure: true

- name: Generate docs
run: |
cargo doc --workspace --exclude "openvm-benchmarks" --exclude "*-tests" --exclude "*-test"

- name: Run fmt
run: |
cargo fmt --all -- --check
Expand Down
43 changes: 8 additions & 35 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -175,8 +175,7 @@ snark-verifier-sdk = { git = "https://github.com/axiom-crypto/snark-verifier", b
"display",
] }
zkhash = { git = "https://github.com/HorizenLabs/poseidon2.git", rev = "bb476b9" }
# for testing only:
halo2curves-axiom = { git = "https://github.com/axiom-crypto/halo2curves.git", branch = "test/visibility" }
halo2curves-axiom = "0.5.3"

rayon = "1.10"
parking_lot = "0.12.2"
Expand Down
5 changes: 2 additions & 3 deletions extensions/pairing/guest/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,8 @@ openvm-algebra-complex-macros = { workspace = true }
openvm-rv32im-guest = { workspace = true }

# Used for `halo2curves` feature
# TODO[yj]: Integrate with halo2curves-axiom first before transitioning to PSE halo2curves
# TODO[yj]: transition to PSE halo2curves
halo2curves-axiom = { workspace = true, optional = true }
# halo2curves = { version = "0.7.0", optional = true }
group = "0.13.0"

[target.'cfg(not(target_os = "zkvm"))'.dependencies]
Expand All @@ -41,7 +40,7 @@ subtle = "2.6.1"
[features]
default = []
std = ["openvm/std"]
# TODO[yj]: Switch to `halo2curves`
# TODO[yj]: Switch to PSE `halo2curves`
halo2curves = ["bls12_381", "bn254", "dep:halo2curves-axiom"]
# features to enable specific curves in guest programs
# only enable for the curves you use as it affects the init! macro
Expand Down
28 changes: 9 additions & 19 deletions extensions/pairing/guest/src/bls12_381/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,12 @@ fn test_fp_one() {
assert_eq!(fp_one, convert_bls12381_halo2_fq_to_fp(fq_one));
}

// Gt(Fq12) is not public
fn assert_miller_results_eq(a: MillerLoopResult, b: Fp12) {
let b = convert_bls12381_fp12_to_halo2_fq12(b);
crate::halo2curves_shims::bls12_381::tests::assert_miller_results_eq(a, b);
}

#[test]
fn test_bls12381_miller_loop() {
let mut rng = StdRng::seed_from_u64(65);
Expand All @@ -205,14 +211,8 @@ fn test_bls12381_miller_loop() {
let h2c_q_prepared = G2Prepared::from(h2c_q);
let compare_miller =
halo2curves_axiom::bls12_381::multi_miller_loop(&[(&h2c_p, &h2c_q_prepared)]);
let compare_final = compare_miller.final_exponentiation();

let f = Bls12_381::multi_miller_loop(&[p], &[q]);
let f_fq12 = convert_bls12381_fp12_to_halo2_fq12(f);
let wrapped_f = MillerLoopResult(f_fq12);
let final_f = wrapped_f.final_exponentiation();

assert_eq!(final_f, compare_final);
assert_miller_results_eq(compare_miller, f);
}

#[test]
Expand All @@ -231,16 +231,11 @@ fn test_bls12381_miller_loop_identity() {
};

let f = Bls12_381::multi_miller_loop(&[p], &[q]);
let f_fq12 = convert_bls12381_fp12_to_halo2_fq12(f);
let wrapped_f = MillerLoopResult(f_fq12);
let final_f = wrapped_f.final_exponentiation();

// halo2curves implementation
let h2c_q_prepared = G2Prepared::from(h2c_q);
let compare_miller =
halo2curves_axiom::bls12_381::multi_miller_loop(&[(&h2c_p, &h2c_q_prepared)]);
let compare_final = compare_miller.final_exponentiation();
assert_eq!(final_f, compare_final);
assert_miller_results_eq(compare_miller, f);
}

#[test]
Expand All @@ -258,14 +253,9 @@ fn test_bls12381_miller_loop_identity_2() {
};

let f = Bls12_381::multi_miller_loop(&[p], &[q]);
let f_fq12 = convert_bls12381_fp12_to_halo2_fq12(f);
let wrapped_f = MillerLoopResult(f_fq12);
let final_f = wrapped_f.final_exponentiation();

// halo2curves implementation
let h2c_q_prepared = G2Prepared::from(h2c_q);
let compare_miller =
halo2curves_axiom::bls12_381::multi_miller_loop(&[(&h2c_p, &h2c_q_prepared)]);
let compare_final = compare_miller.final_exponentiation();
assert_eq!(final_f, compare_final);
assert_miller_results_eq(compare_miller, f);
}
16 changes: 8 additions & 8 deletions extensions/pairing/guest/src/bn254/mod.rs
Original file line number Diff line number Diff line change
@@ -1,28 +1,28 @@
use core::ops::{Add, AddAssign, Neg};

use hex_literal::hex;
#[cfg(not(target_os = "zkvm"))]
use lazy_static::lazy_static;
#[cfg(not(target_os = "zkvm"))]
use num_bigint_dig::BigUint;
use openvm_algebra_guest::{Field, IntMod};
use openvm_algebra_moduli_setup::moduli_declare;
use openvm_ecc_guest::{
weierstrass::{CachedMulTable, IntrinsicCurve},
CyclicGroup, Group,
};

use crate::pairing::PairingIntrinsics;

mod fp12;
mod fp2;
pub mod pairing;

pub use fp12::*;
pub use fp2::*;
use hex_literal::hex;
#[cfg(not(target_os = "zkvm"))]
use lazy_static::lazy_static;
#[cfg(not(target_os = "zkvm"))]
use num_bigint_dig::BigUint;

use crate::pairing::PairingIntrinsics;

#[cfg(all(test, feature = "halo2curves", not(target_os = "zkvm")))]
mod tests;
pub mod tests;

#[cfg(not(target_os = "zkvm"))]
lazy_static! {
Expand Down
33 changes: 11 additions & 22 deletions extensions/pairing/guest/src/bn254/tests.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
use alloc::vec::Vec;

use group::{ff::Field, prime::PrimeCurveAffine};
use halo2curves_axiom::{
bn256::{Fq, Fq12, Fq2, Fq6, G1Affine, G2Affine, G2Prepared, Gt, FROBENIUS_COEFF_FQ12_C1},
pairing::MillerLoopResult,
use halo2curves_axiom::bn256::{
Fq, Fq12, Fq2, Fq6, G1Affine, G2Affine, G2Prepared, Gt, FROBENIUS_COEFF_FQ12_C1,
};
use openvm_algebra_guest::{field::FieldExtension, IntMod};
use openvm_ecc_guest::AffinePoint;
Expand Down Expand Up @@ -176,6 +175,12 @@ fn test_fp_one() {
assert_eq!(fp_one, convert_bn254_halo2_fq_to_fp(fq_one));
}

// Gt(Fq12) is not public
fn assert_miller_results_eq(a: Gt, b: Fp12) {
let b = convert_bn254_fp12_to_halo2_fq12(b);
crate::halo2curves_shims::bn254::tests::assert_miller_results_eq(a, b);
}

#[test]
fn test_bn254_miller_loop() {
let mut rng = StdRng::seed_from_u64(53);
Expand All @@ -194,14 +199,8 @@ fn test_bn254_miller_loop() {
// Compare against halo2curves implementation
let h2c_q_prepared = G2Prepared::from(h2c_q);
let compare_miller = halo2curves_axiom::bn256::multi_miller_loop(&[(&h2c_p, &h2c_q_prepared)]);
let compare_final = compare_miller.final_exponentiation();

let f = Bn254::multi_miller_loop(&[p], &[q]);
let f_fq12 = convert_bn254_fp12_to_halo2_fq12(f);
let wrapped_f = Gt(f_fq12);
let final_f = wrapped_f.final_exponentiation();

assert_eq!(final_f, compare_final);
assert_miller_results_eq(compare_miller, f);
}

#[test]
Expand All @@ -220,15 +219,10 @@ fn test_bn254_miller_loop_identity() {
};

let f = Bn254::multi_miller_loop(&[p], &[q]);
let f_fq12 = convert_bn254_fp12_to_halo2_fq12(f);
let wrapped_f = Gt(f_fq12);
let final_f = wrapped_f.final_exponentiation();

// halo2curves implementation
let h2c_q_prepared = G2Prepared::from(h2c_q);
let compare_miller = halo2curves_axiom::bn256::multi_miller_loop(&[(&h2c_p, &h2c_q_prepared)]);
let compare_final = compare_miller.final_exponentiation();
assert_eq!(final_f, compare_final);
assert_miller_results_eq(compare_miller, f);
}

#[test]
Expand All @@ -246,13 +240,8 @@ fn test_bn254_miller_loop_identity_2() {
};

let f = Bn254::multi_miller_loop(&[p], &[q]);
let f_fq12 = convert_bn254_fp12_to_halo2_fq12(f);
let wrapped_f = Gt(f_fq12);
let final_f = wrapped_f.final_exponentiation();

// halo2curves implementation
let h2c_q_prepared = G2Prepared::from(h2c_q);
let compare_miller = halo2curves_axiom::bn256::multi_miller_loop(&[(&h2c_p, &h2c_q_prepared)]);
let compare_final = compare_miller.final_exponentiation();
assert_eq!(final_f, compare_final);
assert_miller_results_eq(compare_miller, f);
}
Loading