Skip to content

Commit

Permalink
chore: migrate from Bn256Engine to Bn256EngineKGZ (#1093)
Browse files Browse the repository at this point in the history
* chore: migrate from Bn256Engine to Bn256EngineKGZ

* chore: migrate benchmarks to Bn256 field

* feat: activate asm feature for nova/arecibo dependency

* chore: include the LanguageField in the cached public params file names
  • Loading branch information
arthurpaulino authored Feb 6, 2024
1 parent 222255f commit 50e977c
Show file tree
Hide file tree
Showing 9 changed files with 85 additions and 82 deletions.
6 changes: 5 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ lurk-metrics = { version = "0.2.0", path = "lurk-metrics" }
neptune = { workspace = true, features = ["arity2", "arity4", "arity8", "arity16", "pasta"] }
nom = "7.1.3"
nom_locate = "4.1.0"
nova = { workspace = true }
num-bigint = "0.4.3"
num_cpus = "1.10.1"
num-integer = "0.1.45"
Expand Down Expand Up @@ -68,6 +67,11 @@ elsa = { version = "1.9.0", git = "https://github.com/lurk-lab/elsa", branch = "
arc-swap = "1.6.0"
halo2curves = { version = "0.6.0", features = ["bits", "derive_serde"] }

[target.'cfg(not(target_arch = "x86_64"))'.dependencies]
nova = { workspace = true }
[target.'cfg(target_arch = "x86_64")'.dependencies]
nova = { workspace = true, features = ["asm"] }

[target.'cfg(not(target_arch = "wasm32"))'.dependencies]
pprof = { version = "0.13", optional = true} # only used in tests, under feature "flamegraph"
proptest = { workspace = true }
Expand Down
4 changes: 2 additions & 2 deletions benches/common/fib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,12 +96,12 @@ fn compute_coeffs<F: LurkField>(store: &Store<F>) -> (usize, usize) {
}

pub(crate) fn test_coeffs() {
let store = Store::<pasta_curves::Fq>::default();
let store = Store::<halo2curves::bn256::Fr>::default();
assert_eq!(compute_coeffs(&store), (LIN_COEF, ANG_COEF));
}

pub(crate) fn test_fib_io_matches() {
let store = Store::<pasta_curves::Fq>::default();
let store = Store::<halo2curves::bn256::Fr>::default();
let fib_9 = store.num_u64(34);
let fib_10 = store.num_u64(55);
let fib_11 = store.num_u64(89);
Expand Down
100 changes: 47 additions & 53 deletions benches/end2end.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use criterion::{
black_box, criterion_group, criterion_main, BatchSize, BenchmarkId, Criterion, SamplingMode,
};
use pasta_curves::pallas::Scalar as Fq;
use halo2curves::bn256::Fr as Bn;
use std::{cell::RefCell, rc::Rc, sync::Arc, time::Duration};

use lurk::{
Expand Down Expand Up @@ -59,20 +59,14 @@ fn end2end_benchmark(c: &mut Criterion) {
let reduction_count = DEFAULT_REDUCTION_COUNT;

// setup
let lang_pallas = Lang::<Fq>::new();
let lang_pallas_rc = Arc::new(lang_pallas.clone());
let lang = Lang::<Bn>::new();
let lang_rc = Arc::new(lang.clone());

let store = Store::default();
let prover: NovaProver<'_, Fq, Coproc<Fq>> =
NovaProver::new(reduction_count, lang_pallas_rc.clone());
let prover: NovaProver<'_, Bn, Coproc<Bn>> = NovaProver::new(reduction_count, lang_rc.clone());

// use cached public params
let instance = Instance::new(
reduction_count,
lang_pallas_rc,
true,
Kind::NovaPublicParams,
);
let instance = Instance::new(reduction_count, lang_rc, true, Kind::NovaPublicParams);
let pp = public_parameters::public_params(&instance).unwrap();

let size = (10, 0);
Expand All @@ -82,8 +76,8 @@ fn end2end_benchmark(c: &mut Criterion) {

group.bench_with_input(benchmark_id, &size, |b, &s| {
b.iter(|| {
let ptr = go_base::<Fq>(&store, state.clone(), s.0, s.1);
let frames = evaluate::<Fq, Coproc<Fq>>(None, ptr, &store, limit).unwrap();
let ptr = go_base::<Bn>(&store, state.clone(), s.0, s.1);
let frames = evaluate::<Bn, Coproc<Bn>>(None, ptr, &store, limit).unwrap();
let _result = prover.prove_from_frames(&pp, &frames, &store).unwrap();
})
});
Expand All @@ -100,7 +94,7 @@ fn store_benchmark(c: &mut Criterion) {
.measurement_time(Duration::from_secs(5))
.sample_size(60);

let pallas_store = Store::<Fq>::default();
let store = Store::<Bn>::default();

let state = State::init_lurk_state().rccell();

Expand All @@ -109,10 +103,10 @@ fn store_benchmark(c: &mut Criterion) {
for size in sizes {
let parameter_string = format!("_{}_{}", size.0, size.1);

let pasta_id = BenchmarkId::new("store_go_base_pallas", &parameter_string);
let pasta_id = BenchmarkId::new("store_go_base", &parameter_string);
group.bench_with_input(pasta_id, &size, |b, &s| {
b.iter(|| {
let result = go_base::<Fq>(&pallas_store, state.clone(), s.0, s.1);
let result = go_base::<Bn>(&store, state.clone(), s.0, s.1);
black_box(result)
})
});
Expand All @@ -130,7 +124,7 @@ fn hydration_benchmark(c: &mut Criterion) {
.measurement_time(Duration::from_secs(5))
.sample_size(60);

let pallas_store = Store::<Fq>::default();
let store = Store::<Bn>::default();

let state = State::init_lurk_state().rccell();

Expand All @@ -140,10 +134,10 @@ fn hydration_benchmark(c: &mut Criterion) {
let parameter_string = format!("_{}_{}", size.0, size.1);

{
let benchmark_id = BenchmarkId::new("hydration_go_base_pallas", &parameter_string);
let benchmark_id = BenchmarkId::new("hydration_go_base", &parameter_string);
group.bench_with_input(benchmark_id, &size, |b, &s| {
let _ptr = go_base::<Fq>(&pallas_store, state.clone(), s.0, s.1);
b.iter(|| pallas_store.hydrate_z_cache())
let _ptr = go_base::<Bn>(&store, state.clone(), s.0, s.1);
b.iter(|| store.hydrate_z_cache())
});
}
}
Expand All @@ -161,7 +155,7 @@ fn eval_benchmark(c: &mut Criterion) {
.sample_size(60);

let limit = 1_000_000_000;
let pallas_store = Store::default();
let store = Store::default();

let state = State::init_lurk_state().rccell();

Expand All @@ -170,10 +164,10 @@ fn eval_benchmark(c: &mut Criterion) {
for size in sizes {
let parameter_string = format!("_{}_{}", size.0, size.1);
{
let benchmark_id = BenchmarkId::new("eval_go_base_pallas", &parameter_string);
let benchmark_id = BenchmarkId::new("eval_go_base", &parameter_string);
group.bench_with_input(benchmark_id, &size, |b, &s| {
let ptr = go_base::<Fq>(&pallas_store, state.clone(), s.0, s.1);
b.iter(|| evaluate_simple::<Fq, Coproc<Fq>>(None, ptr, &pallas_store, limit))
let ptr = go_base::<Bn>(&store, state.clone(), s.0, s.1);
b.iter(|| evaluate_simple::<Bn, Coproc<Bn>>(None, ptr, &store, limit))
});
}
}
Expand All @@ -188,25 +182,25 @@ fn eval_benchmark(c: &mut Criterion) {
// .sample_size(60);

// let limit = 1_000_000_000;
// let _lang_pallas = Lang::<Fq, Coproc<Fq>>::new();
// let lang_pallas = Lang::<Fq, Coproc<Fq>>::new();
// let _lang = Lang::<Bn, Coproc<Bn>>::new();
// let lang = Lang::<Bn, Coproc<Bn>>::new();

// let reduction_count = DEFAULT_REDUCTION_COUNT;

// group.bench_function("circuit_generation_go_base_10_16_nova", |b| {
// let mut store = Store::default();
// let env = empty_sym_env(&store);
// let ptr = go_base::<Fq>(&mut store, black_box(10), black_box(16));
// let prover = NovaProver::new(reduction_count, lang_pallas.clone());
// let ptr = go_base::<Bn>(&mut store, black_box(10), black_box(16));
// let prover = NovaProver::new(reduction_count, lang.clone());

// let pp = public_parameters::public_params(reduction_count).unwrap();
// let frames = prover
// .get_evaluation_frames(ptr, env, &mut store, limit, &lang_pallas)
// .get_evaluation_frames(ptr, env, &mut store, limit, &lang)
// .unwrap();

// b.iter(|| {
// let result = prover
// .prove(&pp, frames.clone(), &mut store, &lang_pallas)
// .prove(&pp, frames.clone(), &mut store, &lang)
// .unwrap();
// black_box(result);
// })
Expand Down Expand Up @@ -234,23 +228,23 @@ fn prove_benchmark(c: &mut Criterion) {

let state = State::init_lurk_state().rccell();

let lang_pallas = Lang::<Fq>::new();
let lang_pallas_rc = Arc::new(lang_pallas.clone());
let lang = Lang::<Bn>::new();
let lang_rc = Arc::new(lang.clone());

// use cached public params
let instance = Instance::new(
reduction_count,
lang_pallas_rc.clone(),
lang_rc.clone(),
true,
Kind::NovaPublicParams,
);
let pp = public_parameters::public_params(&instance).unwrap();

group.bench_with_input(benchmark_id, &size, |b, &s| {
let ptr = go_base::<Fq>(&store, state.clone(), s.0, s.1);
let prover: NovaProver<'_, Fq, Coproc<Fq>> =
NovaProver::new(reduction_count, lang_pallas_rc.clone());
let frames = evaluate::<Fq, Coproc<Fq>>(None, ptr, &store, limit).unwrap();
let ptr = go_base::<Bn>(&store, state.clone(), s.0, s.1);
let prover: NovaProver<'_, Bn, Coproc<Bn>> =
NovaProver::new(reduction_count, lang_rc.clone());
let frames = evaluate::<Bn, Coproc<Bn>>(None, ptr, &store, limit).unwrap();

b.iter(|| {
let result = prover.prove_from_frames(&pp, &frames, &store).unwrap();
Expand Down Expand Up @@ -282,22 +276,22 @@ fn prove_compressed_benchmark(c: &mut Criterion) {

let state = State::init_lurk_state().rccell();

let lang_pallas = Lang::<Fq>::new();
let lang_pallas_rc = Arc::new(lang_pallas.clone());
let lang = Lang::<Bn>::new();
let lang_rc = Arc::new(lang.clone());

// use cached public params
let instance = Instance::new(
reduction_count,
lang_pallas_rc.clone(),
lang_rc.clone(),
true,
Kind::NovaPublicParams,
);
let pp = public_parameters::public_params(&instance).unwrap();

group.bench_with_input(benchmark_id, &size, |b, &s| {
let ptr = go_base::<Fq>(&store, state.clone(), s.0, s.1);
let prover = NovaProver::new(reduction_count, lang_pallas_rc.clone());
let frames = evaluate::<Fq, Coproc<Fq>>(None, ptr, &store, limit).unwrap();
let ptr = go_base::<Bn>(&store, state.clone(), s.0, s.1);
let prover = NovaProver::new(reduction_count, lang_rc.clone());
let frames = evaluate::<Bn, Coproc<Bn>>(None, ptr, &store, limit).unwrap();

b.iter(|| {
let (proof, _, _, _) = prover.prove_from_frames(&pp, &frames, &store).unwrap();
Expand All @@ -324,13 +318,13 @@ fn verify_benchmark(c: &mut Criterion) {

let state = State::init_lurk_state().rccell();

let lang_pallas = Lang::<Fq>::new();
let lang_pallas_rc = Arc::new(lang_pallas.clone());
let lang = Lang::<Bn>::new();
let lang_rc = Arc::new(lang.clone());

// use cached public params
let instance = Instance::new(
reduction_count,
lang_pallas_rc.clone(),
lang_rc.clone(),
true,
Kind::NovaPublicParams,
);
Expand All @@ -342,8 +336,8 @@ fn verify_benchmark(c: &mut Criterion) {
let benchmark_id = BenchmarkId::new("verify_go_base_nova", &parameter_string);
group.bench_with_input(benchmark_id, &size, |b, &s| {
let ptr = go_base(&store, state.clone(), s.0, s.1);
let prover = NovaProver::new(reduction_count, lang_pallas_rc.clone());
let frames = evaluate::<Fq, Coproc<Fq>>(None, ptr, &store, limit).unwrap();
let prover = NovaProver::new(reduction_count, lang_rc.clone());
let frames = evaluate::<Bn, Coproc<Bn>>(None, ptr, &store, limit).unwrap();
let (proof, z0, zi, _num_steps) =
prover.prove_from_frames(&pp, &frames, &store).unwrap();

Expand Down Expand Up @@ -377,13 +371,13 @@ fn verify_compressed_benchmark(c: &mut Criterion) {

let state = State::init_lurk_state().rccell();

let lang_pallas = Lang::<Fq>::new();
let lang_pallas_rc = Arc::new(lang_pallas.clone());
let lang = Lang::<Bn>::new();
let lang_rc = Arc::new(lang.clone());

// use cached public params
let instance = Instance::new(
reduction_count,
lang_pallas_rc.clone(),
lang_rc.clone(),
true,
Kind::NovaPublicParams,
);
Expand All @@ -395,8 +389,8 @@ fn verify_compressed_benchmark(c: &mut Criterion) {
let benchmark_id = BenchmarkId::new("verify_compressed_go_base_nova", &parameter_string);
group.bench_with_input(benchmark_id, &size, |b, &s| {
let ptr = go_base(&store, state.clone(), s.0, s.1);
let prover = NovaProver::new(reduction_count, lang_pallas_rc.clone());
let frames = evaluate::<Fq, Coproc<Fq>>(None, ptr, &store, limit).unwrap();
let prover = NovaProver::new(reduction_count, lang_rc.clone());
let frames = evaluate::<Bn, Coproc<Bn>>(None, ptr, &store, limit).unwrap();
let (proof, z0, zi, _num_steps) =
prover.prove_from_frames(&pp, &frames, &store).unwrap();

Expand Down
12 changes: 5 additions & 7 deletions benches/fibonacci.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use criterion::{
black_box, criterion_group, criterion_main, measurement, BatchSize, BenchmarkGroup,
BenchmarkId, Criterion, SamplingMode,
};
use pasta_curves::pallas;
use halo2curves::bn256::Fr as Bn;
use std::{sync::Arc, time::Duration};

use lurk::{
Expand Down Expand Up @@ -80,8 +80,8 @@ fn fibonacci_prove<M: measurement::Measurement>(
c: &mut BenchmarkGroup<'_, M>,
) {
let limit = fib_limit(prove_params.fib_n, prove_params.reduction_count);
let lang_pallas = Lang::<pallas::Scalar>::new();
let lang_rc = Arc::new(lang_pallas.clone());
let lang = Lang::<Bn>::new();
let lang_rc = Arc::new(lang.clone());

// use cached public params
let instance = Instance::new(
Expand All @@ -104,12 +104,10 @@ fn fibonacci_prove<M: measurement::Measurement>(
BenchmarkId::new(name, params),
&prove_params,
|b, prove_params| {
let ptr = fib_expr::<pasta_curves::Fq>(&store);
let ptr = fib_expr::<Bn>(&store);
let prover = NovaProver::new(prove_params.reduction_count, lang_rc.clone());

let frames =
&evaluate::<pasta_curves::Fq, Coproc<pasta_curves::Fq>>(None, ptr, &store, limit)
.unwrap();
let frames = &evaluate::<Bn, Coproc<Bn>>(None, ptr, &store, limit).unwrap();

b.iter_batched(
|| frames,
Expand Down
6 changes: 3 additions & 3 deletions benches/public_params.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@ const DEFAULT_REDUCTION_COUNT: usize = 10;
fn public_params_benchmark(c: &mut Criterion) {
let mut group = c.benchmark_group("public_params_benchmark");
group.sampling_mode(SamplingMode::Flat);
let lang_pallas = Lang::<pasta_curves::pallas::Scalar>::new();
let lang_pallas_rc = Arc::new(lang_pallas);
let lang = Lang::<halo2curves::bn256::Fr>::new();
let lang_rc = Arc::new(lang);

let reduction_count = DEFAULT_REDUCTION_COUNT;

group.bench_function("public_params_nova", |b| {
b.iter(|| {
let result = nova::public_params(reduction_count, lang_pallas_rc.clone());
let result = nova::public_params(reduction_count, lang_rc.clone());
black_box(result)
})
});
Expand Down
Loading

1 comment on commit 50e977c

@github-actions
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Benchmarks

Table of Contents

Overview

This benchmark report shows the Fibonacci GPU benchmark.
NVIDIA L4
Intel(R) Xeon(R) CPU @ 2.20GHz
32 vCPUs
125 GB RAM
Workflow run: https://github.com/lurk-lab/lurk-rs/actions/runs/7806786959

Benchmark Results

LEM Fibonacci Prove - rc = 100

ref=222255f9cff68bbdc1661467c8c95cf04e18772e ref=50e977c87041711fec0a4c9c199696084d93710e
num-100 1.72 s (✅ 1.00x) 1.45 s (✅ 1.19x faster)
num-200 3.33 s (✅ 1.00x) 2.78 s (✅ 1.20x faster)

LEM Fibonacci Prove - rc = 600

ref=222255f9cff68bbdc1661467c8c95cf04e18772e ref=50e977c87041711fec0a4c9c199696084d93710e
num-100 2.06 s (✅ 1.00x) 1.85 s (✅ 1.11x faster)
num-200 3.37 s (✅ 1.00x) 3.05 s (✅ 1.10x faster)

Made with criterion-table

Please sign in to comment.