Skip to content

Commit

Permalink
supernova public params
Browse files Browse the repository at this point in the history
  • Loading branch information
winston-h-zhang committed Sep 19, 2023
1 parent 5f4b6e1 commit 5d96b48
Show file tree
Hide file tree
Showing 19 changed files with 406 additions and 146 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ clap = "4.3.17"
ff = "0.13"
metrics = "0.21.1"
neptune = { git = "https://github.com/lurk-lab/neptune", branch = "dev" }
nova = { git = "https://github.com/lurk-lab/arecibo", branch = "dev", package = "nova-snark" }
nova = { git = "https://github.com/lurk-lab/arecibo", branch = "supernova-digest", package = "nova-snark" }
once_cell = "1.18.0"
pairing = { version = "0.23" }
pasta_curves = { git = "https://github.com/lurk-lab/pasta_curves", branch = "dev" }
Expand Down
15 changes: 9 additions & 6 deletions benches/end2end.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,10 @@ use lurk::{
proof::nova::NovaProver,
proof::Prover,
ptr::Ptr,
public_parameters::{self, instance::Instance},
public_parameters::{
self,
instance::{Instance, Kind},
},
state::State,
store::Store,
};
Expand Down Expand Up @@ -70,7 +73,7 @@ fn end2end_benchmark(c: &mut Criterion) {
let prover = NovaProver::new(reduction_count, lang_pallas);

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

Expand Down Expand Up @@ -286,7 +289,7 @@ 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 instance = Instance::new(reduction_count, lang_pallas_rc.clone(), true);
let instance = Instance::new(reduction_count, lang_pallas_rc.clone(), true, Kind::IVC);
let pp =
public_parameters::public_params(&instance, Utf8Path::new(PUBLIC_PARAMS_PATH)).unwrap();
let frames = prover
Expand Down Expand Up @@ -335,7 +338,7 @@ fn prove_compressed_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 instance = Instance::new(reduction_count, lang_pallas_rc.clone(), true);
let instance = Instance::new(reduction_count, lang_pallas_rc.clone(), true, Kind::IVC);
let pp =
public_parameters::public_params(&instance, Utf8Path::new(PUBLIC_PARAMS_PATH)).unwrap();
let frames = prover
Expand Down Expand Up @@ -383,7 +386,7 @@ 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 instance = Instance::new(reduction_count, lang_pallas_rc.clone(), true);
let instance = Instance::new(reduction_count, lang_pallas_rc.clone(), true, Kind::IVC);
let pp = public_parameters::public_params(&instance, Utf8Path::new(PUBLIC_PARAMS_PATH))
.unwrap();
let frames = prover
Expand Down Expand Up @@ -437,7 +440,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 instance = Instance::new(reduction_count, lang_pallas_rc.clone(), true);
let instance = Instance::new(reduction_count, lang_pallas_rc.clone(), true, Kind::IVC);
let pp = public_parameters::public_params(&instance, Utf8Path::new(PUBLIC_PARAMS_PATH))
.unwrap();
let frames = prover
Expand Down
2 changes: 1 addition & 1 deletion benches/fibonacci.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ fn fibo_prove<M: measurement::Measurement>(
let lang_rc = Arc::new(lang_pallas.clone());

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

c.bench_with_input(
Expand Down
6 changes: 3 additions & 3 deletions benches/sha256_ivc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
//! that's easier to play with and run.

use lurk::circuit::gadgets::data::GlobalAllocations;
use lurk::public_parameters::instance::Instance;
use lurk::public_parameters::instance::{Instance, Kind};
use lurk::state::user_sym;
use lurk::{circuit::gadgets::pointer::AllocatedContPtr, tag::Tag};
use std::{cell::RefCell, marker::PhantomData, rc::Rc, sync::Arc, time::Duration};
Expand Down Expand Up @@ -228,7 +228,7 @@ fn sha256_ivc_prove<M: measurement::Measurement>(

// use cached public params

let instance = Instance::new(reduction_count, lang_rc.clone(), true);
let instance = Instance::new(reduction_count, lang_rc.clone(), true, Kind::IVC);
let pp = public_params(&instance, Utf8Path::new(PUBLIC_PARAMS_PATH)).unwrap();

c.bench_with_input(
Expand Down Expand Up @@ -306,7 +306,7 @@ fn sha256_ivc_prove_compressed<M: measurement::Measurement>(
let lang_rc = Arc::new(lang.clone());

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

c.bench_with_input(
Expand Down
8 changes: 4 additions & 4 deletions clutch/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use fcomm::{
PtrEvaluation,
};
use lurk::lurk_sym_ptr;
use lurk::public_parameters::instance::Instance;
use lurk::public_parameters::instance::{Instance, Kind};
use lurk::public_parameters::public_params;

use lurk::state::State;
Expand Down Expand Up @@ -147,7 +147,7 @@ impl ReplTrait<F, Coproc<F>> for ClutchState<F, Coproc<F>> {
});

let lang_rc = Arc::new(lang.clone());
let instance = Instance::new(reduction_count, lang_rc, true);
let instance = Instance::new(reduction_count, lang_rc, true, Kind::IVC);
// Load params from disk cache, or generate them in the background.
thread::spawn(move || public_params(&instance, &public_param_dir()));

Expand Down Expand Up @@ -534,7 +534,7 @@ impl ClutchState<F, Coproc<F>> {
let (proof_in_expr, _rest1) = store.car_cdr(&rest)?;

let prover = NovaProver::<F, Coproc<F>>::new(self.reduction_count, (*self.lang()).clone());
let instance = Instance::new(self.reduction_count, self.lang(), true);
let instance = Instance::new(self.reduction_count, self.lang(), true, Kind::IVC);
let pp = public_params(&instance, &public_param_dir())?;

let proof = if rest.is_nil() {
Expand Down Expand Up @@ -594,7 +594,7 @@ impl ClutchState<F, Coproc<F>> {
.get(&zptr_string)
.ok_or_else(|| anyhow!("proof not found: {zptr_string}"))?;

let instance = Instance::new(self.reduction_count, self.lang(), true);
let instance = Instance::new(self.reduction_count, self.lang(), true, Kind::IVC);
let pp = public_params(&instance, &public_param_dir())?;
let result = proof.verify(&pp, &self.lang()).unwrap();

Expand Down
4 changes: 2 additions & 2 deletions examples/sha256.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use lurk::eval::{empty_sym_env, lang::Lang};
use lurk::field::LurkField;
use lurk::proof::{nova::NovaProver, Prover};
use lurk::ptr::Ptr;
use lurk::public_parameters::instance::Instance;
use lurk::public_parameters::instance::{Instance, Kind};
use lurk::public_parameters::{public_params, public_params_default_dir};
use lurk::state::user_sym;
use lurk::store::Store;
Expand Down Expand Up @@ -187,7 +187,7 @@ fn main() {
let pp_start = Instant::now();

let pp = tracing_texray::examine(tracing::info_span!("pp start!")).in_scope(|| {
let instance = Instance::new(REDUCTION_COUNT, lang_rc.clone(), true);
let instance = Instance::new(REDUCTION_COUNT, lang_rc.clone(), true, Kind::IVC);
public_params::<_, Sha256Coproc<Fr>>(&instance, &public_params_default_dir()).unwrap()
});
let pp_end = pp_start.elapsed();
Expand Down
51 changes: 24 additions & 27 deletions examples/sha256_ivc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ use lurk::eval::{empty_sym_env, lang::Lang};
use lurk::field::LurkField;
use lurk::proof::{nova::NovaProver, Prover};
use lurk::ptr::Ptr;
use lurk::public_parameters::instance::Instance;
use lurk::public_parameters::with_public_params;
use lurk::public_parameters::instance::{Instance, Kind};
use lurk::public_parameters::{public_params, public_params_default_dir};
use lurk::state::user_sym;
use lurk::store::Store;
use lurk::tag::{ExprTag, Tag};
Expand Down Expand Up @@ -199,36 +199,33 @@ fn main() {
println!("Setting up public parameters (rc = {REDUCTION_COUNT})...");

let pp_start = Instant::now();

let instance = Instance::new(REDUCTION_COUNT, lang_rc.clone(), true);
let instance = Instance::new(REDUCTION_COUNT, lang_rc.clone(), true, Kind::IVC);
// see the documentation on `with_public_params`
with_public_params(&instance, |pp| {
let pp_end = pp_start.elapsed();
println!("Public parameters took {:?}", pp_end);
let pp = public_params(&instance, &public_params_default_dir()).unwrap();
let pp_end = pp_start.elapsed();
println!("Public parameters took {:?}", pp_end);

println!("Beginning proof step...");
let proof_start = Instant::now();
let (proof, z0, zi, num_steps) = nova_prover
.evaluate_and_prove(pp, call, empty_sym_env(store), store, 10000, lang_rc)
.unwrap();
let proof_end = proof_start.elapsed();
println!("Beginning proof step...");
let proof_start = Instant::now();
let (proof, z0, zi, num_steps) = nova_prover
.evaluate_and_prove(&pp, call, empty_sym_env(store), store, 10000, lang_rc)
.unwrap();
let proof_end = proof_start.elapsed();

println!("Proofs took {:?}", proof_end);
println!("Proofs took {:?}", proof_end);

println!("Verifying proof...");
println!("Verifying proof...");

let verify_start = Instant::now();
let res = proof.verify(pp, num_steps, &z0, &zi).unwrap();
let verify_end = verify_start.elapsed();
let verify_start = Instant::now();
let res = proof.verify(&pp, num_steps, &z0, &zi).unwrap();
let verify_end = verify_start.elapsed();

println!("Verify took {:?}", verify_end);
println!("Verify took {:?}", verify_end);

if res {
println!(
"Congratulations! You proved and verified a SHA256 hash calculation in {:?} time!",
pp_end + proof_end + verify_end
);
}
})
.unwrap();
if res {
println!(
"Congratulations! You proved and verified a SHA256 hash calculation in {:?} time!",
pp_end + proof_end + verify_end
);
}
}
29 changes: 22 additions & 7 deletions examples/sha256_nivc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ use lurk::field::LurkField;
use lurk::proof::{supernova::SuperNovaProver, Prover};
use lurk::ptr::Ptr;

use lurk::public_parameters::instance::{Instance, Kind};
use lurk::public_parameters::{public_params_default_dir, running_claim_params};
use lurk::state::user_sym;
use lurk::store::Store;
use lurk::tag::{ExprTag, Tag};
Expand Down Expand Up @@ -182,19 +184,32 @@ fn main() {

let supernova_prover = SuperNovaProver::<Fr, Sha256Coproc<Fr>>::new(REDUCTION_COUNT, lang);

// println!("Setting up public parameters (rc = {REDUCTION_COUNT})...");

println!("Setting up running claim parameters (rc = {REDUCTION_COUNT})...");
let pp_start = Instant::now();

// // see the documentation on `with_public_params`
// with_public_params(REDUCTION_COUNT, lang_rc.clone(), |pp| {
let instance_primary = Instance::new(
REDUCTION_COUNT,
lang_rc.clone(),
true,
Kind::NIVC { circuit_index: 0 },
);
let running_claim_params =
running_claim_params(&instance_primary, &public_params_default_dir()).unwrap();

let pp_end = pp_start.elapsed();
// println!("Public parameters took {:?}", pp_end);
println!("Running claim parameters took {:?}", pp_end);

println!("Beginning proof+public-parameters step...");
println!("Beginning proof step...");
let proof_start = Instant::now();
let (_proof, _z0, _zi, _num_steps) = supernova_prover
.evaluate_and_prove(None, call, empty_sym_env(store), store, 10000, lang_rc)
.evaluate_and_prove(
&running_claim_params,
call,
empty_sym_env(store),
store,
10000,
lang_rc,
)
.unwrap();
let proof_end = proof_start.elapsed();

Expand Down
8 changes: 4 additions & 4 deletions fcomm/src/bin/fcomm.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use abomonation::Abomonation;
use lurk::lurk_sym_ptr;
use lurk::proof::nova::{CurveCycleEquipped, G1, G2};
use lurk::public_parameters::instance::Instance;
use lurk::public_parameters::instance::{Instance, Kind};
use nova::traits::Group;
use std::convert::TryFrom;
use std::env;
Expand Down Expand Up @@ -234,7 +234,7 @@ impl Open {
let rc = ReductionCount::try_from(self.reduction_count).expect("reduction count");
let prover = NovaProver::<S1, Coproc<S1>>::new(rc.count(), lang.clone());
let lang_rc = Arc::new(lang.clone());
let instance = Instance::new(rc.count(), lang_rc, true);
let instance = Instance::new(rc.count(), lang_rc, true, Kind::IVC);
let pp = public_params(&instance, &public_param_dir()).expect("public params");
let function_map = committed_expression_store();

Expand Down Expand Up @@ -339,7 +339,7 @@ impl Prove {
let rc = ReductionCount::try_from(self.reduction_count).unwrap();
let prover = NovaProver::<S1, Coproc<S1>>::new(rc.count(), lang.clone());
let lang_rc = Arc::new(lang.clone());
let instance = Instance::new(rc.count(), lang_rc.clone(), true);
let instance = Instance::new(rc.count(), lang_rc.clone(), true, Kind::IVC);
let pp = public_params(&instance, &public_param_dir()).unwrap();

let proof = match &self.claim {
Expand Down Expand Up @@ -386,7 +386,7 @@ impl Verify {
fn verify(&self, cli_error: bool, lang: &Lang<S1, Coproc<S1>>) {
let proof = proof(Some(&self.proof)).unwrap();
let lang_rc = Arc::new(lang.clone());
let instance = Instance::new(proof.reduction_count.count(), lang_rc, true);
let instance = Instance::new(proof.reduction_count.count(), lang_rc, true, Kind::IVC);
let pp = public_params(&instance, &public_param_dir()).unwrap();
let result = proof.verify(&pp, lang).unwrap();

Expand Down
4 changes: 2 additions & 2 deletions fcomm/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1102,7 +1102,7 @@ mod test {
use crate::file_map::FileStore;
use camino::Utf8Path;
use insta::assert_json_snapshot;
use lurk::public_parameters::instance::Instance;
use lurk::public_parameters::instance::{Instance, Kind};
use std::path::Path;
use std::sync::Arc;
use tempfile::Builder;
Expand Down Expand Up @@ -1212,7 +1212,7 @@ mod test {
let lang = Lang::new();
let lang_rc = Arc::new(lang.clone());
let rc = ReductionCount::One;
let instance = Instance::new(rc.count(), lang_rc.clone(), true);
let instance = Instance::new(reduction_count, lang_rc.clone(), true, Kind::IVC);
let pp =
public_params(&instance, &fcomm_path_val.join("public_params")).expect("public params");
let chained = true;
Expand Down
7 changes: 5 additions & 2 deletions src/cli/lurk_proof.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,10 @@ use crate::{
eval::lang::{Coproc, Lang},
field::LurkField,
proof::nova::{self, CurveCycleEquipped, G1, G2},
public_parameters::{instance::Instance, public_params},
public_parameters::{
instance::{Instance, Kind},
public_params,
},
z_ptr::{ZContPtr, ZExprPtr},
z_store::ZStore,
};
Expand Down Expand Up @@ -107,7 +110,7 @@ impl<'a> LurkProof<'a, Scalar> {
lang,
} => {
tracing::info!("Loading public parameters");
let instance = Instance::new(rc, Arc::new(lang), true);
let instance = Instance::new(rc, Arc::new(lang), true, Kind::IVC);
let pp = public_params(&instance, &public_params_dir())?;
Ok(proof.verify(&pp, num_steps, &public_inputs, &public_outputs)?)
}
Expand Down
4 changes: 3 additions & 1 deletion src/cli/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -563,8 +563,8 @@ impl PublicParamArgs {
}

fn run(&self) -> Result<()> {
let metadata = self.get_metadata()?;
if self.list {
let metadata = self.get_metadata()?;
for (_path, data) in metadata.iter() {
println!(
"{: <9} {: >4} {: >6} {: >35}",
Expand All @@ -576,6 +576,7 @@ impl PublicParamArgs {
}
}
if let Some(key) = &self.remove {
let metadata = self.get_metadata()?;
if let Some((json_path, _)) = metadata
.iter()
.find(|(_, data)| &data.circuit_digest[2..10] == key)
Expand All @@ -587,6 +588,7 @@ impl PublicParamArgs {
}
}
if let Some(key) = &self.show {
let metadata = self.get_metadata()?;
if let Some((json_path, data)) = metadata
.iter()
.find(|(_, data)| &data.circuit_digest[2..10] == key)
Expand Down
7 changes: 5 additions & 2 deletions src/cli/repl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,10 @@ use crate::{
lurk_sym_ptr, parser,
proof::{nova::NovaProver, Prover},
ptr::Ptr,
public_parameters::{instance::Instance, public_params},
public_parameters::{
instance::{Instance, Kind},
public_params,
},
state::State,
store::Store,
tag::{ContTag, ExprTag},
Expand Down Expand Up @@ -230,7 +233,7 @@ impl Repl<F> {
info!("Proof not cached");

info!("Loading public parameters");
let instance = Instance::new(self.rc, self.lang.clone(), true);
let instance = Instance::new(self.rc, self.lang.clone(), true, Kind::IVC);
let pp = public_params(&instance, &public_params_dir())?;

let prover = NovaProver::new(self.rc, (*self.lang).clone());
Expand Down
Loading

0 comments on commit 5d96b48

Please sign in to comment.