Skip to content

Commit

Permalink
feat: NIVC support for the REPL (#1119)
Browse files Browse the repository at this point in the history
* Extend LurkProof and ProtocolProof to encode SuperNova proofs as well
* Add a new Backend::SuperNova variant
* Code the plumbing for SuperNova proof generation
* Extend the protocol API to handle a backend argument so it can use
  SuperNova as well
  • Loading branch information
arthurpaulino authored Feb 14, 2024
1 parent ffb4071 commit fc1e8dc
Show file tree
Hide file tree
Showing 8 changed files with 237 additions and 132 deletions.
1 change: 1 addition & 0 deletions demo/protocol.lurk
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
(list6 (mk-open-expr hash) (empty-env) :outermost pair (empty-env) :terminal)
nil)
(lambda () (> (car pair) 10))))
:backend "nova"
:rc 10
:descr "demo protocol")

Expand Down
5 changes: 4 additions & 1 deletion src/cli/backend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,18 @@ use serde::Deserialize;
use crate::field::LanguageField;

#[derive(Clone, Default, Debug, Deserialize, ValueEnum, PartialEq, Eq)]
#[clap(rename_all = "lowercase")]
pub(crate) enum Backend {
#[default]
Nova,
SuperNova,
}

impl std::fmt::Display for Backend {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
Self::Nova => write!(f, "Nova"),
Self::SuperNova => write!(f, "SuperNova"),
}
}
}
Expand All @@ -22,7 +25,7 @@ impl Backend {
fn compatible_fields(&self) -> Vec<LanguageField> {
use LanguageField::{Pallas, BN256};
match self {
Self::Nova => vec![BN256, Pallas],
Self::Nova | Self::SuperNova => vec![BN256, Pallas],
}
}

Expand Down
61 changes: 40 additions & 21 deletions src/cli/lurk_proof.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@ use crate::{
lem::{pointers::ZPtr, store::Store},
proof::{
nova::{self, CurveCycleEquipped, Dual, C1LEM},
RecursiveSNARKTrait,
supernova, RecursiveSNARKTrait,
},
public_parameters::{
instance::{Instance, Kind},
public_params,
public_params, supernova_public_params,
},
state::{initial_lurk_state, State},
};
Expand Down Expand Up @@ -118,22 +118,32 @@ impl<F: LurkField + DeserializeOwned> LurkProofMeta<F> {
}
}

#[non_exhaustive]
#[derive(Serialize, Deserialize)]
#[serde(bound(serialize = "F: Serialize", deserialize = "F: DeserializeOwned"))]
pub(crate) enum LurkProofWrapper<
'a,
F: CurveCycleEquipped,
C: Coprocessor<F> + Serialize + DeserializeOwned,
> {
Nova(nova::Proof<F, C1LEM<'a, F, C>>),
SuperNova(supernova::Proof<F, C1LEM<'a, F, C>>),
}

/// Minimal data structure containing just enough for proof verification
#[non_exhaustive]
#[derive(Serialize, Deserialize)]
#[serde(bound(serialize = "F: Serialize", deserialize = "F: DeserializeOwned"))]
pub(crate) enum LurkProof<
pub(crate) struct LurkProof<
'a,
F: CurveCycleEquipped,
C: Coprocessor<F> + Serialize + DeserializeOwned,
> {
Nova {
proof: nova::Proof<F, C1LEM<'a, F, C>>,
public_inputs: Vec<F>,
public_outputs: Vec<F>,
rc: usize,
lang: Lang<F, C>,
},
pub(crate) proof: LurkProofWrapper<'a, F, C>,
pub(crate) public_inputs: Vec<F>,
pub(crate) public_outputs: Vec<F>,
pub(crate) rc: usize,
pub(crate) lang: Lang<F, C>,
}

impl<'a, F: CurveCycleEquipped, C: Coprocessor<F> + 'a + Serialize + DeserializeOwned>
Expand Down Expand Up @@ -185,19 +195,28 @@ where
}

fn verify(&self) -> Result<bool> {
match self {
Self::Nova {
proof,
public_inputs,
public_outputs,
rc,
lang,
} => {
match &self.proof {
LurkProofWrapper::Nova(proof) => {
tracing::info!("Loading public parameters");
let instance =
Instance::new(*rc, Arc::new(lang.clone()), true, Kind::NovaPublicParams);
let instance = Instance::new(
self.rc,
Arc::new(self.lang.clone()),
true,
Kind::NovaPublicParams,
);
let pp = public_params(&instance)?;
Ok(proof.verify(&pp, public_inputs, public_outputs)?)
Ok(proof.verify(&pp, &self.public_inputs, &self.public_outputs)?)
}
LurkProofWrapper::SuperNova(proof) => {
tracing::info!("Loading public parameters");
let instance = Instance::new(
self.rc,
Arc::new(self.lang.clone()),
true,
Kind::SuperNovaAuxParams,
);
let pp = supernova_public_params(&instance)?;
Ok(proof.verify(&pp, &self.public_inputs, &self.public_outputs)?)
}
}
}
Expand Down
12 changes: 6 additions & 6 deletions src/cli/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,11 +90,11 @@ struct LoadArgs {
#[clap(long, value_parser)]
limit: Option<usize>,

/// Prover backend (defaults to "Nova")
/// Prover backend (defaults to "nova")
#[clap(long, value_enum)]
backend: Option<Backend>,

/// Arithmetic field (defaults to "BN256")
/// Arithmetic field (defaults to "bn256")
#[clap(long, value_enum)]
field: Option<LanguageField>,

Expand Down Expand Up @@ -203,11 +203,11 @@ struct ReplArgs {
#[clap(long, value_parser)]
limit: Option<usize>,

/// Prover backend (defaults to "Nova")
/// Prover backend (defaults to "nova")
#[clap(long, value_enum)]
backend: Option<Backend>,

/// Arithmetic field (defaults to "BN256")
/// Arithmetic field (defaults to "bn256")
#[clap(long, value_enum)]
field: Option<LanguageField>,

Expand Down Expand Up @@ -422,7 +422,7 @@ struct VerifyArgs {
#[clap(value_parser)]
proof_key: String,

/// Arithmetic field (defaults to "BN256")
/// Arithmetic field (defaults to "bn256")
#[clap(long, value_enum)]
field: Option<LanguageField>,

Expand All @@ -445,7 +445,7 @@ struct InspectArgs {
#[clap(value_parser)]
proof_key: String,

/// Arithmetic field (defaults to "BN256")
/// Arithmetic field (defaults to "bn256")
#[clap(long, value_enum)]
field: Option<LanguageField>,

Expand Down
Loading

1 comment on commit fc1e8dc

@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/7902604820

Benchmark Results

LEM Fibonacci Prove - rc = 100

ref=ffb4071b7aa5bd5955b59afb1835635a8a59b65c ref=fc1e8dc677879ded3d551fa10593a0d6bd34197b
num-100 1.45 s (✅ 1.00x) 1.46 s (✅ 1.00x slower)
num-200 2.77 s (✅ 1.00x) 2.78 s (✅ 1.00x slower)

LEM Fibonacci Prove - rc = 600

ref=ffb4071b7aa5bd5955b59afb1835635a8a59b65c ref=fc1e8dc677879ded3d551fa10593a0d6bd34197b
num-100 1.84 s (✅ 1.00x) 1.85 s (✅ 1.01x slower)
num-200 3.03 s (✅ 1.00x) 3.07 s (✅ 1.01x slower)

Made with criterion-table

Please sign in to comment.