Skip to content

Commit

Permalink
feat: NIVC support for the REPL
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 committed Feb 12, 2024
1 parent 35a17ea commit 02464b4
Show file tree
Hide file tree
Showing 6 changed files with 229 additions and 126 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
4 changes: 3 additions & 1 deletion src/cli/backend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,14 @@ use crate::field::LanguageField;
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 +24,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
Loading

0 comments on commit 02464b4

Please sign in to comment.