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

feat: prove through a Multiframe trait #709

Merged
merged 4 commits into from
Sep 28, 2023
Merged
Show file tree
Hide file tree
Changes from 2 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
106 changes: 52 additions & 54 deletions benches/end2end.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,15 @@ use criterion::{
};

use lurk::{
circuit::circuit_frame::MultiFrame,
eval::{
empty_sym_env,
lang::{Coproc, Lang},
Evaluator,
},
field::LurkField,
proof::nova::NovaProver,
proof::Prover,
proof::{nova::NovaProver, MultiFrameTrait},
ptr::Ptr,
public_parameters,
state::State,
Expand Down Expand Up @@ -70,7 +71,7 @@ fn end2end_benchmark(c: &mut Criterion) {
let prover = NovaProver::new(reduction_count, lang_pallas);

// use cached public params
let pp = public_parameters::public_params(
let pp = public_parameters::public_params::<_, _, MultiFrame<'_, _, Coproc<pallas::Scalar>>>(
reduction_count,
true,
lang_pallas_rc.clone(),
Expand All @@ -87,7 +88,7 @@ fn end2end_benchmark(c: &mut Criterion) {
b.iter(|| {
let ptr = go_base::<pallas::Scalar>(&mut store, state.clone(), s.0, s.1);
let _result = prover
.evaluate_and_prove(&pp, ptr, env, &mut store, limit, lang_pallas_rc.clone())
.evaluate_and_prove(&pp, ptr, env, &mut store, limit, &lang_pallas_rc)
.unwrap();
})
});
Expand Down Expand Up @@ -290,27 +291,26 @@ fn prove_benchmark(c: &mut Criterion) {
group.bench_with_input(benchmark_id, &size, |b, &s| {
let ptr = go_base::<pallas::Scalar>(&mut store, state.clone(), s.0, s.1);
let prover = NovaProver::new(reduction_count, lang_pallas.clone());
let pp = public_parameters::public_params(
reduction_count,
true,
lang_pallas_rc.clone(),
Utf8Path::new(PUBLIC_PARAMS_PATH),
)
.unwrap();
let frames = prover
.get_evaluation_frames(
ptr,
empty_sym_env(&store),
&mut store,
limit,
let pp =
public_parameters::public_params::<_, _, MultiFrame<'_, _, Coproc<pallas::Scalar>>>(
reduction_count,
true,
lang_pallas_rc.clone(),
Utf8Path::new(PUBLIC_PARAMS_PATH),
)
.unwrap();
let frames = MultiFrame::get_evaluation_frames(
|count| prover.needs_frame_padding(count),
ptr,
empty_sym_env(&store),
&store,
limit,
&lang_pallas,
)
.unwrap();

b.iter(|| {
let result = prover
.prove(&pp, &frames, &store, lang_pallas_rc.clone())
.unwrap();
let result = prover.prove(&pp, &frames, &store, &lang_pallas_rc).unwrap();
black_box(result);
})
});
Expand Down Expand Up @@ -340,30 +340,30 @@ fn prove_compressed_benchmark(c: &mut Criterion) {

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

let pp = public_parameters::public_params::<_, _, MultiFrame<'_, _, _>>(
reduction_count,
true,
lang_pallas_rc.clone(),
Utf8Path::new(PUBLIC_PARAMS_PATH),
)
.unwrap();

group.bench_with_input(benchmark_id, &size, |b, &s| {
let ptr = go_base::<pallas::Scalar>(&mut store, state.clone(), s.0, s.1);
let prover = NovaProver::new(reduction_count, lang_pallas.clone());
let pp = public_parameters::public_params(
reduction_count,
true,
lang_pallas_rc.clone(),
Utf8Path::new(PUBLIC_PARAMS_PATH),

let frames = MultiFrame::get_evaluation_frames(
|count| prover.needs_frame_padding(count),
ptr,
empty_sym_env(&store),
&store,
limit,
&lang_pallas,
)
.unwrap();
let frames = prover
.get_evaluation_frames(
ptr,
empty_sym_env(&store),
&mut store,
limit,
lang_pallas_rc.clone(),
)
.unwrap();

b.iter(|| {
let (proof, _, _, _) = prover
.prove(&pp, &frames, &store, lang_pallas_rc.clone())
.unwrap();
let (proof, _, _, _) = prover.prove(&pp, &frames, &store, &lang_pallas_rc).unwrap();

let compressed_result = proof.compress(&pp).unwrap();
black_box(compressed_result);
Expand Down Expand Up @@ -395,25 +395,24 @@ fn verify_benchmark(c: &mut Criterion) {
group.bench_with_input(benchmark_id, &size, |b, &s| {
let ptr = go_base(&mut store, state.clone(), s.0, s.1);
let prover = NovaProver::new(reduction_count, lang_pallas.clone());
let pp = public_parameters::public_params(
let pp = public_parameters::public_params::<_, _, MultiFrame<'_, _, _>>(
reduction_count,
true,
lang_pallas_rc.clone(),
Utf8Path::new(PUBLIC_PARAMS_PATH),
)
.unwrap();
let frames = prover
.get_evaluation_frames(
ptr,
empty_sym_env(&store),
&mut store,
limit,
lang_pallas_rc.clone(),
)
.unwrap();
let (proof, z0, zi, num_steps) = prover
.prove(&pp, &frames, &store, lang_pallas_rc.clone())
.unwrap();
let frames = MultiFrame::get_evaluation_frames(
|count| prover.needs_frame_padding(count),
ptr,
empty_sym_env(&store),
&store,
limit,
&lang_pallas,
)
.unwrap();
let (proof, z0, zi, num_steps) =
prover.prove(&pp, &frames, &store, &lang_pallas_rc).unwrap();

b.iter_batched(
|| z0.clone(),
Expand Down Expand Up @@ -453,7 +452,7 @@ fn verify_compressed_benchmark(c: &mut Criterion) {
group.bench_with_input(benchmark_id, &size, |b, &s| {
let ptr = go_base(&mut store, state.clone(), s.0, s.1);
let prover = NovaProver::new(reduction_count, lang_pallas.clone());
let pp = public_parameters::public_params(
let pp = public_parameters::public_params::<_, _, MultiFrame<'_, _, _>>(
reduction_count,
true,
lang_pallas_rc.clone(),
Expand All @@ -464,14 +463,13 @@ fn verify_compressed_benchmark(c: &mut Criterion) {
.get_evaluation_frames(
ptr,
empty_sym_env(&store),
&mut store,
&store,
limit,
lang_pallas_rc.clone(),
)
.unwrap();
let (proof, z0, zi, num_steps) = prover
.prove(&pp, &frames, &store, lang_pallas_rc.clone())
.unwrap();
let (proof, z0, zi, num_steps) =
prover.prove(&pp, &frames, &store, &lang_pallas_rc).unwrap();

let compressed_proof = proof.compress(&pp).unwrap();

Expand Down
7 changes: 4 additions & 3 deletions benches/fibonacci.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ use criterion::{
use pasta_curves::pallas;

use lurk::{
circuit::circuit_frame::MultiFrame,
eval::{
empty_sym_env,
lang::{Coproc, Lang},
Expand Down Expand Up @@ -75,7 +76,7 @@ fn fibo_prove<M: measurement::Measurement>(
let lang_rc = Arc::new(lang_pallas.clone());

// use cached public params
let pp = public_params(
let pp = public_params::<_, _, MultiFrame<'_, _, _>>(
prove_params.reduction_count,
true,
lang_rc.clone(),
Expand All @@ -98,13 +99,13 @@ fn fibo_prove<M: measurement::Measurement>(
let prover = NovaProver::new(prove_params.reduction_count, lang_pallas.clone());

let frames = &prover
.get_evaluation_frames(ptr, env, &mut store, limit, lang_rc.clone())
.get_evaluation_frames(ptr, env, &store, limit, lang_rc.clone())
.unwrap();

b.iter_batched(
|| (frames, lang_rc.clone()),
|(frames, lang_rc)| {
let result = prover.prove(&pp, frames, &store, lang_rc);
let result = prover.prove(&pp, frames, &store, &lang_rc);
let _ = black_box(result);
},
BatchSize::LargeInput,
Expand Down
18 changes: 15 additions & 3 deletions benches/public_params.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use blstrs::Scalar as Fr;
use criterion::{black_box, criterion_group, criterion_main, Criterion, SamplingMode};
use lurk::{
circuit::circuit_frame::MultiFrame,
eval::lang::{Coproc, Lang},
proof::groth16::Groth16Prover,
proof::nova,
Expand All @@ -26,15 +27,26 @@ fn public_params_benchmark(c: &mut Criterion) {

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::<_, _, MultiFrame<'_, _, _>>(
reduction_count,
lang_pallas_rc.clone(),
);
black_box(result)
})
});

group.bench_function("public_params_groth", |b| {
b.iter(|| {
let result =
Groth16Prover::create_groth_params(DEFAULT_REDUCTION_COUNT, lang_bls_rc.clone());
let result = Groth16Prover::<
_,
Coproc<Fr>,
Fr,
MultiFrame<'_, Fr, Coproc<Fr>>,
>::create_groth_params(
DEFAULT_REDUCTION_COUNT,
lang_bls_rc.clone(),
)
.unwrap();
black_box(result)
})
});
Expand Down
9 changes: 5 additions & 4 deletions benches/sha256_ivc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
//! Note: The example [example/sha256_ivc.rs] is this same benchmark but as an example
//! that's easier to play with and run.

use lurk::circuit::circuit_frame::MultiFrame;
use lurk::circuit::gadgets::data::GlobalAllocations;
use lurk::state::user_sym;
use lurk::{circuit::gadgets::pointer::AllocatedContPtr, tag::Tag};
Expand Down Expand Up @@ -226,7 +227,7 @@ fn sha256_ivc_prove<M: measurement::Measurement>(
let lang_rc = Arc::new(lang.clone());

// use cached public params
let pp = public_params(
let pp = public_params::<_, _, MultiFrame<'_, _, _>>(
reduction_count,
true,
lang_rc.clone(),
Expand Down Expand Up @@ -256,7 +257,7 @@ fn sha256_ivc_prove<M: measurement::Measurement>(
b.iter_batched(
|| (frames, lang_rc.clone()),
|(frames, lang_rc)| {
let result = prover.prove(&pp, frames, store, lang_rc);
let result = prover.prove(&pp, frames, store, &lang_rc);
let _ = black_box(result);
},
BatchSize::LargeInput,
Expand Down Expand Up @@ -309,7 +310,7 @@ fn sha256_ivc_prove_compressed<M: measurement::Measurement>(
let lang_rc = Arc::new(lang.clone());

// use cached public params
let pp = public_params(
let pp = public_params::<_, _, MultiFrame<'_, _, _>>(
reduction_count,
true,
lang_rc.clone(),
Expand Down Expand Up @@ -339,7 +340,7 @@ fn sha256_ivc_prove_compressed<M: measurement::Measurement>(
b.iter_batched(
|| (frames, lang_rc.clone()),
|(frames, lang_rc)| {
let (proof, _, _, _) = prover.prove(&pp, frames, store, lang_rc).unwrap();
let (proof, _, _, _) = prover.prove(&pp, frames, store, &lang_rc).unwrap();
let compressed_result = proof.compress(&pp).unwrap();

let _ = black_box(compressed_result);
Expand Down
7 changes: 5 additions & 2 deletions benches/synthesis.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,13 @@ fn synthesize<M: measurement::Measurement>(
let env = empty_sym_env(&store);
let fib_n = (reduction_count / 3) as u64; // Heuristic, since one fib is 35 iterations.
let ptr = fib::<pasta_curves::Fq>(&mut store, state.clone(), black_box(fib_n));
let prover = NovaProver::new(*reduction_count, lang_pallas.clone());
let prover = NovaProver::<_, _, MultiFrame<'_, _, _>>::new(
*reduction_count,
lang_pallas.clone(),
);

let frames = prover
.get_evaluation_frames(ptr, env, &mut store, limit, lang_rc.clone())
.get_evaluation_frames(ptr, env, &store, limit, lang_rc.clone())
.unwrap();
let folding_config =
Arc::new(FoldingConfig::new_ivc(lang_rc.clone(), *reduction_count));
Expand Down
15 changes: 13 additions & 2 deletions clutch/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ use fcomm::{
CommittedExpression, CommittedExpressionMap, LurkCont, LurkPtr, NovaProofCache, Opening, Proof,
PtrEvaluation,
};
use lurk::circuit::circuit_frame::MultiFrame;
use lurk::lurk_sym_ptr;
use lurk::public_parameters::public_params;

Expand Down Expand Up @@ -147,7 +148,14 @@ impl ReplTrait<F, Coproc<F>> for ClutchState<F, Coproc<F>> {

let lang_rc = Arc::new(lang.clone());
// Load params from disk cache, or generate them in the background.
thread::spawn(move || public_params(reduction_count, true, lang_rc, &public_param_dir()));
thread::spawn(move || {
public_params::<_, _, MultiFrame<'_, _, Coproc<_>>>(
reduction_count,
true,
lang_rc,
&public_param_dir(),
)
});

Self {
repl_state: ReplState::new(s, limit, command, lang),
Expand Down Expand Up @@ -531,7 +539,10 @@ impl ClutchState<F, Coproc<F>> {
fn prove(&mut self, store: &mut Store<F>, rest: Ptr<F>) -> Result<Option<Ptr<F>>> {
let (proof_in_expr, _rest1) = store.car_cdr(&rest)?;

let prover = NovaProver::<F, Coproc<F>>::new(self.reduction_count, (*self.lang()).clone());
let prover = NovaProver::<'_, F, Coproc<F>, MultiFrame<'_, F, Coproc<F>>>::new(
self.reduction_count,
(*self.lang()).clone(),
);
let pp = public_params(self.reduction_count, true, self.lang(), &public_param_dir())?;

let proof = if rest.is_nil() {
Expand Down
10 changes: 7 additions & 3 deletions examples/circom.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ use std::marker::PhantomData;
use std::sync::Arc;
use std::time::Instant;

use lurk::circuit::circuit_frame::MultiFrame;
use lurk::circuit::gadgets::circom::CircomGadget;
use lurk::circuit::gadgets::pointer::AllocatedPtr;

Expand Down Expand Up @@ -114,13 +115,16 @@ fn main() {
let expr = format!("({coproc_expr})");
let ptr = store.read(&expr).unwrap();

let nova_prover = NovaProver::<Fr, Sha256Coproc<Fr>>::new(REDUCTION_COUNT, lang.clone());
let nova_prover = NovaProver::<Fr, Sha256Coproc<Fr>, MultiFrame<'_, _, _>>::new(
REDUCTION_COUNT,
lang.clone(),
);
let lang_rc = Arc::new(lang);

println!("Setting up public parameters...");

let pp_start = Instant::now();
let pp = public_params::<_, Sha256Coproc<Fr>>(
let pp = public_params::<_, Sha256Coproc<Fr>, MultiFrame<'_, _, _>>(
REDUCTION_COUNT,
true,
lang_rc.clone(),
Expand All @@ -135,7 +139,7 @@ fn main() {

let proof_start = Instant::now();
let (proof, z0, zi, num_steps) = nova_prover
.evaluate_and_prove(&pp, ptr, empty_sym_env(store), store, 10000, lang_rc)
.evaluate_and_prove(&pp, ptr, empty_sym_env(store), store, 10000, &lang_rc)
.unwrap();
let proof_end = proof_start.elapsed();

Expand Down
Loading
Loading