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: NIVC support for the REPL #1119

Merged
merged 1 commit into from
Feb 14, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
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