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

Resolve conflicts #42

Merged
merged 5 commits into from
Dec 4, 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
74 changes: 74 additions & 0 deletions .github/workflows/rust.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
name: Rust

on:
# Run CI on push only for 'main' branch
push:
branches: [main]
# Run CI on pull request for all branches
pull_request:
branches: ["**"]

concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
cancel-in-progress: true

env:
CARGO_TERM_COLOR: always
RUSTFLAGS: '-D warnings'
RUST_BACKTRACE: 1

jobs:
format:
runs-on: ubuntu-latest
timeout-minutes: 5
steps:
- uses: actions/checkout@v3
- name: Install toolchain
uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: stable
components: rustfmt
- name: Format
run: cargo fmt --all --check

build:
runs-on: ubuntu-latest
timeout-minutes: 5
steps:
- uses: actions/checkout@v3
- name: Install toolchain
uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: stable
- name: Build
run: cargo build --verbose

build-wasm32:
runs-on: ubuntu-latest
timeout-minutes: 5
steps:
- uses: actions/checkout@v3
- name: Install toolchain
uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: stable
target: wasm32-unknown-unknown
- name: Build
run: cargo build --verbose --no-default-features --target wasm32-unknown-unknown

test:
runs-on: ubuntu-latest
timeout-minutes: 5
steps:
- uses: actions/checkout@v3
- name: Install toolchain
uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: stable
- name: Run tests
run: cargo test --release

41 changes: 28 additions & 13 deletions benches/multiexps.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use ark_ec::pairing::Pairing;
use ark_ec::VariableBaseMSM;
use ark_ff::{PrimeField, UniformRand};
use ark_std::test_rng;
use criterion::{BenchmarkId, Criterion, criterion_group, criterion_main};
use criterion::{criterion_group, criterion_main, BenchmarkId, Criterion};

use fflonk::utils::ec;

Expand All @@ -11,8 +11,12 @@ fn small_multiexp_affine<E: Pairing>(c: &mut Criterion) {
let n = 10;

let bases = (0..n).map(|_| E::G1Affine::rand(rng)).collect::<Vec<_>>();
let exps_full = (0..n).map(|_| E::ScalarField::rand(rng)).collect::<Vec<_>>();
let exps_128 = (0..n).map(|_| E::ScalarField::from(u128::rand(rng))).collect::<Vec<_>>();
let exps_full = (0..n)
.map(|_| E::ScalarField::rand(rng))
.collect::<Vec<_>>();
let exps_128 = (0..n)
.map(|_| E::ScalarField::from(u128::rand(rng)))
.collect::<Vec<_>>();

let mut group = c.benchmark_group("small-multiexp-affine");
group.bench_with_input(BenchmarkId::new("small-multiexp-full", n), &n, |b, _n| {
Expand All @@ -35,7 +39,9 @@ fn small_multiexp_proj<E: Pairing>(c: &mut Criterion) {
let n = 10;

let bases = (0..n).map(|_| E::G1::rand(rng)).collect::<Vec<_>>();
let exps_128 = (0..n).map(|_| E::ScalarField::from(u128::rand(rng))).collect::<Vec<_>>();
let exps_128 = (0..n)
.map(|_| E::ScalarField::from(u128::rand(rng)))
.collect::<Vec<_>>();

let mut group = c.benchmark_group("small-multiexp-proj");
group.bench_with_input(BenchmarkId::new("in_affine", n), &n, |b, _n| {
Expand All @@ -54,12 +60,21 @@ fn small_multiexp_vs_msm<E: Pairing>(c: &mut Criterion) {
for n in [10, 20] {
let bases = (0..n).map(|_| E::G1Affine::rand(rng)).collect::<Vec<_>>();

let exps_full = (0..n).map(|_| E::ScalarField::rand(rng)).collect::<Vec<_>>();
let exps_128 = (0..n).map(|_| E::ScalarField::from(u128::rand(rng))).collect::<Vec<_>>();

let exps_full_repr = exps_full.iter().map(|exp| exp.into_bigint()).collect::<Vec<_>>();
let exps_128_repr = exps_128.iter().map(|exp| exp.into_bigint()).collect::<Vec<_>>();

let exps_full = (0..n)
.map(|_| E::ScalarField::rand(rng))
.collect::<Vec<_>>();
let exps_128 = (0..n)
.map(|_| E::ScalarField::from(u128::rand(rng)))
.collect::<Vec<_>>();

let exps_full_repr = exps_full
.iter()
.map(|exp| exp.into_bigint())
.collect::<Vec<_>>();
let exps_128_repr = exps_128
.iter()
.map(|exp| exp.into_bigint())
.collect::<Vec<_>>();

group.bench_with_input(BenchmarkId::new("small-multiexp-full", n), &n, |b, _n| {
b.iter(|| ec::small_multiexp_affine(&exps_full, &bases))
Expand All @@ -78,10 +93,10 @@ fn small_multiexp_vs_msm<E: Pairing>(c: &mut Criterion) {
group.finish();
}


criterion_group!(benches,
criterion_group!(
benches,
small_multiexp_affine::<ark_bw6_761::BW6_761>,
small_multiexp_proj::<ark_bw6_761::BW6_761>,
small_multiexp_vs_msm::<ark_bw6_761::BW6_761>,
);
criterion_main!(benches);
criterion_main!(benches);
24 changes: 15 additions & 9 deletions benches/primitives.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
use std::ops::Mul;

use ark_bw6_761::BW6_761;
use ark_ec::{AffineRepr, CurveGroup, Group};
use ark_ec::pairing::Pairing;
use ark_ec::{AffineRepr, CurveGroup, Group};
use ark_ff::UniformRand;
use ark_std::test_rng;
use criterion::{Criterion, criterion_group, criterion_main};
use criterion::{criterion_group, criterion_main, Criterion};

use fflonk::utils::curve_name;

Expand All @@ -24,26 +24,28 @@ fn scalar_mul<E: Pairing>(c: &mut Criterion) {
let _res: E::G1 = bases_affine[0].mul(exps[0]); // result of affine mul is projective

let mut i = 0;
group.bench_function("proj", |b|
group.bench_function("proj", |b| {
b.iter_with_setup(
|| {
let pair = (bases_projective[i], exps[i]);
i = (i + 1) % n;
pair
},
|(base, exp)| base.mul(exp),
));
)
});

let mut i = 0;
group.bench_function("aff", |b|
group.bench_function("aff", |b| {
b.iter_with_setup(
|| {
let pair = (bases_affine[i], exps[i]);
i = (i + 1) % n;
pair
},
|(base, exp)| base.mul(exp),
));
)
});

group.finish();
}
Expand Down Expand Up @@ -73,6 +75,10 @@ fn additions<E: Pairing>(c: &mut Criterion) {
group.finish();
}


criterion_group!(benches, scalar_mul::<BW6_761>, coordinates_conversion::<BW6_761>, additions::<BW6_761>);
criterion_main!(benches);
criterion_group!(
benches,
scalar_mul::<BW6_761>,
coordinates_conversion::<BW6_761>,
additions::<BW6_761>
);
criterion_main!(benches);
2 changes: 1 addition & 1 deletion src/aggregation/merlin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,4 @@ impl<F: PrimeField, CS: PCS<F>> Transcript<F, CS> for merlin::Transcript {
self.challenge_bytes(b"zeta", &mut buf);
F::from_random_bytes(&buf).unwrap()
}
}
}
4 changes: 2 additions & 2 deletions src/aggregation/mod.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
pub mod single;
pub mod multiple;
pub mod merlin;
pub mod multiple;
pub mod single;
Loading
Loading