mirror of
https://github.com/arnaucube/Nova.git
synced 2026-01-12 00:51:28 +01:00
simplify trait requirements (#143)
* simplify trait requirements * update version
This commit is contained in:
@@ -1,6 +1,6 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "nova-snark"
|
name = "nova-snark"
|
||||||
version = "0.14.0"
|
version = "0.15.0"
|
||||||
authors = ["Srinath Setty <srinath@microsoft.com>"]
|
authors = ["Srinath Setty <srinath@microsoft.com>"]
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
description = "Recursive zkSNARKs without trusted setup"
|
description = "Recursive zkSNARKs without trusted setup"
|
||||||
|
|||||||
@@ -44,7 +44,7 @@ use r1cs::{
|
|||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use traits::{
|
use traits::{
|
||||||
circuit::StepCircuit,
|
circuit::StepCircuit,
|
||||||
commitment::{CommitmentEngineTrait, CompressedCommitmentTrait},
|
commitment::{CommitmentEngineTrait, CommitmentTrait},
|
||||||
snark::RelaxedR1CSSNARKTrait,
|
snark::RelaxedR1CSSNARKTrait,
|
||||||
AbsorbInROTrait, Group, ROConstants, ROConstantsCircuit, ROConstantsTrait, ROTrait,
|
AbsorbInROTrait, Group, ROConstants, ROConstantsCircuit, ROConstantsTrait, ROTrait,
|
||||||
};
|
};
|
||||||
@@ -317,7 +317,7 @@ where
|
|||||||
Some(r_snark.zi_primary.clone()),
|
Some(r_snark.zi_primary.clone()),
|
||||||
Some(r_snark.r_U_secondary.clone()),
|
Some(r_snark.r_U_secondary.clone()),
|
||||||
Some(r_snark.l_u_secondary.clone()),
|
Some(r_snark.l_u_secondary.clone()),
|
||||||
Some(nifs_secondary.comm_T.decompress()?),
|
Some(Commitment::<G2>::decompress(&nifs_secondary.comm_T)?),
|
||||||
);
|
);
|
||||||
|
|
||||||
let circuit_primary: NovaAugmentedCircuit<G2, C1> = NovaAugmentedCircuit::new(
|
let circuit_primary: NovaAugmentedCircuit<G2, C1> = NovaAugmentedCircuit::new(
|
||||||
@@ -351,7 +351,7 @@ where
|
|||||||
Some(r_snark.zi_secondary.clone()),
|
Some(r_snark.zi_secondary.clone()),
|
||||||
Some(r_snark.r_U_primary.clone()),
|
Some(r_snark.r_U_primary.clone()),
|
||||||
Some(l_u_primary.clone()),
|
Some(l_u_primary.clone()),
|
||||||
Some(nifs_primary.comm_T.decompress()?),
|
Some(Commitment::<G1>::decompress(&nifs_primary.comm_T)?),
|
||||||
);
|
);
|
||||||
|
|
||||||
let circuit_secondary: NovaAugmentedCircuit<G1, C2> = NovaAugmentedCircuit::new(
|
let circuit_secondary: NovaAugmentedCircuit<G1, C2> = NovaAugmentedCircuit::new(
|
||||||
@@ -727,7 +727,7 @@ where
|
|||||||
|
|
||||||
type CommitmentGens<G> = <<G as traits::Group>::CE as CommitmentEngineTrait<G>>::CommitmentGens;
|
type CommitmentGens<G> = <<G as traits::Group>::CE as CommitmentEngineTrait<G>>::CommitmentGens;
|
||||||
type Commitment<G> = <<G as Group>::CE as CommitmentEngineTrait<G>>::Commitment;
|
type Commitment<G> = <<G as Group>::CE as CommitmentEngineTrait<G>>::Commitment;
|
||||||
type CompressedCommitment<G> = <<G as Group>::CE as CommitmentEngineTrait<G>>::CompressedCommitment;
|
type CompressedCommitment<G> = <<<G as Group>::CE as CommitmentEngineTrait<G>>::Commitment as CommitmentTrait<G>>::CompressedCommitment;
|
||||||
type CE<G> = <G as Group>::CE;
|
type CE<G> = <G as Group>::CE;
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
|
|||||||
@@ -6,11 +6,8 @@ use crate::{
|
|||||||
constants::{NUM_CHALLENGE_BITS, NUM_FE_FOR_RO},
|
constants::{NUM_CHALLENGE_BITS, NUM_FE_FOR_RO},
|
||||||
errors::NovaError,
|
errors::NovaError,
|
||||||
r1cs::{R1CSGens, R1CSInstance, R1CSShape, R1CSWitness, RelaxedR1CSInstance, RelaxedR1CSWitness},
|
r1cs::{R1CSGens, R1CSInstance, R1CSShape, R1CSWitness, RelaxedR1CSInstance, RelaxedR1CSWitness},
|
||||||
traits::{
|
traits::{commitment::CommitmentTrait, AbsorbInROTrait, Group, ROTrait},
|
||||||
commitment::{CommitmentTrait, CompressedCommitmentTrait},
|
Commitment, CompressedCommitment,
|
||||||
AbsorbInROTrait, Group, ROTrait,
|
|
||||||
},
|
|
||||||
CompressedCommitment,
|
|
||||||
};
|
};
|
||||||
use core::marker::PhantomData;
|
use core::marker::PhantomData;
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
@@ -101,7 +98,7 @@ impl<G: Group> NIFS<G> {
|
|||||||
U2.absorb_in_ro(&mut ro);
|
U2.absorb_in_ro(&mut ro);
|
||||||
|
|
||||||
// append `comm_T` to the transcript and obtain a challenge
|
// append `comm_T` to the transcript and obtain a challenge
|
||||||
let comm_T = self.comm_T.decompress()?;
|
let comm_T = Commitment::<G>::decompress(&self.comm_T)?;
|
||||||
comm_T.absorb_in_ro(&mut ro);
|
comm_T.absorb_in_ro(&mut ro);
|
||||||
|
|
||||||
// compute a challenge from the RO
|
// compute a challenge from the RO
|
||||||
|
|||||||
@@ -190,8 +190,8 @@ macro_rules! impl_traits {
|
|||||||
Some($name_curve::from_bytes(&self.repr).unwrap())
|
Some($name_curve::from_bytes(&self.repr).unwrap())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn as_bytes(&self) -> &[u8] {
|
fn as_bytes(&self) -> Vec<u8> {
|
||||||
&self.repr
|
self.repr.to_vec()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -2,9 +2,7 @@
|
|||||||
use crate::{
|
use crate::{
|
||||||
errors::NovaError,
|
errors::NovaError,
|
||||||
traits::{
|
traits::{
|
||||||
commitment::{
|
commitment::{CommitmentEngineTrait, CommitmentGensTrait, CommitmentTrait},
|
||||||
CommitmentEngineTrait, CommitmentGensTrait, CommitmentTrait, CompressedCommitmentTrait,
|
|
||||||
},
|
|
||||||
AbsorbInROTrait, AppendToTranscriptTrait, CompressedGroup, Group, ROTrait,
|
AbsorbInROTrait, AppendToTranscriptTrait, CompressedGroup, Group, ROTrait,
|
||||||
TranscriptEngineTrait,
|
TranscriptEngineTrait,
|
||||||
},
|
},
|
||||||
@@ -35,13 +33,12 @@ pub struct Commitment<G: Group> {
|
|||||||
/// A type that holds a compressed commitment
|
/// A type that holds a compressed commitment
|
||||||
#[derive(Clone, Copy, Debug, PartialEq, Eq, Serialize, Deserialize)]
|
#[derive(Clone, Copy, Debug, PartialEq, Eq, Serialize, Deserialize)]
|
||||||
#[serde(bound = "")]
|
#[serde(bound = "")]
|
||||||
pub struct CompressedCommitment<C: CompressedGroup> {
|
pub struct CompressedCommitment<G: Group> {
|
||||||
comm: C,
|
comm: G::CompressedGroupElement,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<G: Group> CommitmentGensTrait<G> for CommitmentGens<G> {
|
impl<G: Group> CommitmentGensTrait<G> for CommitmentGens<G> {
|
||||||
type Commitment = Commitment<G>;
|
type Commitment = Commitment<G>;
|
||||||
type CompressedCommitment = CompressedCommitment<G::CompressedGroupElement>;
|
|
||||||
|
|
||||||
fn new(label: &'static [u8], n: usize) -> Self {
|
fn new(label: &'static [u8], n: usize) -> Self {
|
||||||
CommitmentGens {
|
CommitmentGens {
|
||||||
@@ -63,9 +60,9 @@ impl<G: Group> CommitmentGensTrait<G> for CommitmentGens<G> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl<G: Group> CommitmentTrait<G> for Commitment<G> {
|
impl<G: Group> CommitmentTrait<G> for Commitment<G> {
|
||||||
type CompressedCommitment = CompressedCommitment<G::CompressedGroupElement>;
|
type CompressedCommitment = CompressedCommitment<G>;
|
||||||
|
|
||||||
fn compress(&self) -> CompressedCommitment<G::CompressedGroupElement> {
|
fn compress(&self) -> Self::CompressedCommitment {
|
||||||
CompressedCommitment {
|
CompressedCommitment {
|
||||||
comm: self.comm.compress(),
|
comm: self.comm.compress(),
|
||||||
}
|
}
|
||||||
@@ -74,19 +71,9 @@ impl<G: Group> CommitmentTrait<G> for Commitment<G> {
|
|||||||
fn to_coordinates(&self) -> (G::Base, G::Base, bool) {
|
fn to_coordinates(&self) -> (G::Base, G::Base, bool) {
|
||||||
self.comm.to_coordinates()
|
self.comm.to_coordinates()
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
impl<G: Group> Default for Commitment<G> {
|
fn decompress(c: &Self::CompressedCommitment) -> Result<Self, NovaError> {
|
||||||
fn default() -> Self {
|
let comm = c.comm.decompress();
|
||||||
Commitment { comm: G::zero() }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<C: CompressedGroup> CompressedCommitmentTrait<C> for CompressedCommitment<C> {
|
|
||||||
type Commitment = Commitment<C::GroupElement>;
|
|
||||||
|
|
||||||
fn decompress(&self) -> Result<Self::Commitment, NovaError> {
|
|
||||||
let comm = self.comm.decompress();
|
|
||||||
if comm.is_none() {
|
if comm.is_none() {
|
||||||
return Err(NovaError::DecompressionError);
|
return Err(NovaError::DecompressionError);
|
||||||
}
|
}
|
||||||
@@ -96,6 +83,12 @@ impl<C: CompressedGroup> CompressedCommitmentTrait<C> for CompressedCommitment<C
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl<G: Group> Default for Commitment<G> {
|
||||||
|
fn default() -> Self {
|
||||||
|
Commitment { comm: G::zero() }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl<G: Group> AppendToTranscriptTrait<G> for Commitment<G> {
|
impl<G: Group> AppendToTranscriptTrait<G> for Commitment<G> {
|
||||||
fn append_to_transcript(&self, label: &'static [u8], transcript: &mut G::TE) {
|
fn append_to_transcript(&self, label: &'static [u8], transcript: &mut G::TE) {
|
||||||
let (x, y, is_infinity) = self.comm.to_coordinates();
|
let (x, y, is_infinity) = self.comm.to_coordinates();
|
||||||
@@ -123,16 +116,9 @@ impl<G: Group> AbsorbInROTrait<G> for Commitment<G> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<C: CompressedGroup> AppendToTranscriptTrait<C::GroupElement> for CompressedCommitment<C> {
|
impl<G: Group> AppendToTranscriptTrait<G> for CompressedCommitment<G> {
|
||||||
fn append_to_transcript(
|
fn append_to_transcript(&self, label: &'static [u8], transcript: &mut G::TE) {
|
||||||
&self,
|
transcript.absorb_bytes(label, &self.comm.as_bytes());
|
||||||
label: &'static [u8],
|
|
||||||
transcript: &mut <C::GroupElement as Group>::TE,
|
|
||||||
) {
|
|
||||||
let comm = self.decompress().unwrap();
|
|
||||||
<Commitment<C::GroupElement> as AppendToTranscriptTrait<C::GroupElement>>::append_to_transcript(
|
|
||||||
&comm, label, transcript,
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -225,7 +211,6 @@ pub struct CommitmentEngine<G: Group> {
|
|||||||
impl<G: Group> CommitmentEngineTrait<G> for CommitmentEngine<G> {
|
impl<G: Group> CommitmentEngineTrait<G> for CommitmentEngine<G> {
|
||||||
type CommitmentGens = CommitmentGens<G>;
|
type CommitmentGens = CommitmentGens<G>;
|
||||||
type Commitment = Commitment<G>;
|
type Commitment = Commitment<G>;
|
||||||
type CompressedCommitment = CompressedCommitment<G::CompressedGroupElement>;
|
|
||||||
|
|
||||||
fn commit(gens: &Self::CommitmentGens, v: &[G::Scalar]) -> Self::Commitment {
|
fn commit(gens: &Self::CommitmentGens, v: &[G::Scalar]) -> Self::Commitment {
|
||||||
gens.commit(v)
|
gens.commit(v)
|
||||||
@@ -251,7 +236,7 @@ pub(crate) trait CommitmentGensExtTrait<G: Group>: CommitmentGensTrait<G> {
|
|||||||
|
|
||||||
/// Reinterprets commitments as commitment keys
|
/// Reinterprets commitments as commitment keys
|
||||||
fn reinterpret_commitments_as_gens(
|
fn reinterpret_commitments_as_gens(
|
||||||
c: &[<<Self as CommitmentGensExtTrait<G>>::CE as CommitmentEngineTrait<G>>::CompressedCommitment],
|
c: &[<<<Self as CommitmentGensExtTrait<G>>::CE as CommitmentEngineTrait<G>>::Commitment as CommitmentTrait<G>>::CompressedCommitment],
|
||||||
) -> Result<Self, NovaError>
|
) -> Result<Self, NovaError>
|
||||||
where
|
where
|
||||||
Self: Sized;
|
Self: Sized;
|
||||||
@@ -320,12 +305,10 @@ impl<G: Group> CommitmentGensExtTrait<G> for CommitmentGens<G> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// reinterprets a vector of commitments as a set of generators
|
/// reinterprets a vector of commitments as a set of generators
|
||||||
fn reinterpret_commitments_as_gens(
|
fn reinterpret_commitments_as_gens(c: &[CompressedCommitment<G>]) -> Result<Self, NovaError> {
|
||||||
c: &[CompressedCommitment<G::CompressedGroupElement>],
|
|
||||||
) -> Result<Self, NovaError> {
|
|
||||||
let d = (0..c.len())
|
let d = (0..c.len())
|
||||||
.into_par_iter()
|
.into_par_iter()
|
||||||
.map(|i| c[i].decompress())
|
.map(|i| Commitment::<G>::decompress(&c[i]))
|
||||||
.collect::<Result<Vec<Commitment<G>>, NovaError>>()?;
|
.collect::<Result<Vec<Commitment<G>>, NovaError>>()?;
|
||||||
let gens = (0..d.len())
|
let gens = (0..d.len())
|
||||||
.into_par_iter()
|
.into_par_iter()
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
//! We require the commitment engine to provide a commitment to vectors with a single group element
|
//! We require the commitment engine to provide a commitment to vectors with a single group element
|
||||||
use crate::{
|
use crate::{
|
||||||
errors::NovaError,
|
errors::NovaError,
|
||||||
traits::{AbsorbInROTrait, AppendToTranscriptTrait, CompressedGroup, Group},
|
traits::{AbsorbInROTrait, AppendToTranscriptTrait, Group},
|
||||||
};
|
};
|
||||||
use core::{
|
use core::{
|
||||||
fmt::Debug,
|
fmt::Debug,
|
||||||
@@ -18,9 +18,6 @@ pub trait CommitmentGensTrait<G: Group>:
|
|||||||
/// Holds the type of the commitment that can be produced
|
/// Holds the type of the commitment that can be produced
|
||||||
type Commitment;
|
type Commitment;
|
||||||
|
|
||||||
/// Holds the type of the compressed commitment
|
|
||||||
type CompressedCommitment;
|
|
||||||
|
|
||||||
/// Samples a new commitment key of a specified size
|
/// Samples a new commitment key of a specified size
|
||||||
fn new(label: &'static [u8], n: usize) -> Self;
|
fn new(label: &'static [u8], n: usize) -> Self;
|
||||||
|
|
||||||
@@ -77,32 +74,24 @@ pub trait CommitmentTrait<G: Group>:
|
|||||||
+ ScalarMul<G::Scalar>
|
+ ScalarMul<G::Scalar>
|
||||||
{
|
{
|
||||||
/// Holds the type of the compressed commitment
|
/// Holds the type of the compressed commitment
|
||||||
type CompressedCommitment;
|
type CompressedCommitment: Clone
|
||||||
|
+ Debug
|
||||||
|
+ PartialEq
|
||||||
|
+ Eq
|
||||||
|
+ Send
|
||||||
|
+ Sync
|
||||||
|
+ Serialize
|
||||||
|
+ for<'de> Deserialize<'de>
|
||||||
|
+ AppendToTranscriptTrait<G>;
|
||||||
|
|
||||||
/// Compresses self into a compressed commitment
|
/// Compresses self into a compressed commitment
|
||||||
fn compress(&self) -> Self::CompressedCommitment;
|
fn compress(&self) -> Self::CompressedCommitment;
|
||||||
|
|
||||||
/// Returns the coordinate representation of the commitment
|
/// Returns the coordinate representation of the commitment
|
||||||
fn to_coordinates(&self) -> (G::Base, G::Base, bool);
|
fn to_coordinates(&self) -> (G::Base, G::Base, bool);
|
||||||
}
|
|
||||||
|
|
||||||
/// This trait defines the behavior of a compressed commitment
|
/// Decompresses a compressed commitment into a commitment
|
||||||
pub trait CompressedCommitmentTrait<C: CompressedGroup>:
|
fn decompress(c: &Self::CompressedCommitment) -> Result<Self, NovaError>;
|
||||||
Clone
|
|
||||||
+ Debug
|
|
||||||
+ PartialEq
|
|
||||||
+ Eq
|
|
||||||
+ Send
|
|
||||||
+ Sync
|
|
||||||
+ Serialize
|
|
||||||
+ for<'de> Deserialize<'de>
|
|
||||||
+ AppendToTranscriptTrait<C::GroupElement>
|
|
||||||
{
|
|
||||||
/// Holds the type of the commitment that can be decompressed into
|
|
||||||
type Commitment;
|
|
||||||
|
|
||||||
/// Decompresses self into a commitment
|
|
||||||
fn decompress(&self) -> Result<Self::Commitment, NovaError>;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// A trait that ties different pieces of the commitment generation together
|
/// A trait that ties different pieces of the commitment generation together
|
||||||
@@ -110,20 +99,10 @@ pub trait CommitmentEngineTrait<G: Group>:
|
|||||||
Clone + Send + Sync + Serialize + for<'de> Deserialize<'de>
|
Clone + Send + Sync + Serialize + for<'de> Deserialize<'de>
|
||||||
{
|
{
|
||||||
/// Holds the type of the commitment key
|
/// Holds the type of the commitment key
|
||||||
type CommitmentGens: CommitmentGensTrait<
|
type CommitmentGens: CommitmentGensTrait<G, Commitment = Self::Commitment>;
|
||||||
G,
|
|
||||||
Commitment = Self::Commitment,
|
|
||||||
CompressedCommitment = Self::CompressedCommitment,
|
|
||||||
>;
|
|
||||||
|
|
||||||
/// Holds the type of the commitment
|
/// Holds the type of the commitment
|
||||||
type Commitment: CommitmentTrait<G, CompressedCommitment = Self::CompressedCommitment>;
|
type Commitment: CommitmentTrait<G>;
|
||||||
|
|
||||||
/// Holds the type of the compressed commitment
|
|
||||||
type CompressedCommitment: CompressedCommitmentTrait<
|
|
||||||
G::CompressedGroupElement,
|
|
||||||
Commitment = Self::Commitment,
|
|
||||||
>;
|
|
||||||
|
|
||||||
/// Commits to the provided vector using the provided generators
|
/// Commits to the provided vector using the provided generators
|
||||||
fn commit(gens: &Self::CommitmentGens, v: &[G::Scalar]) -> Self::Commitment;
|
fn commit(gens: &Self::CommitmentGens, v: &[G::Scalar]) -> Self::Commitment;
|
||||||
|
|||||||
@@ -106,7 +106,7 @@ pub trait CompressedGroup:
|
|||||||
fn decompress(&self) -> Option<Self::GroupElement>;
|
fn decompress(&self) -> Option<Self::GroupElement>;
|
||||||
|
|
||||||
/// Returns a byte array representing the compressed group element
|
/// Returns a byte array representing the compressed group element
|
||||||
fn as_bytes(&self) -> &[u8];
|
fn as_bytes(&self) -> Vec<u8>;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// A helper trait to absorb different objects in RO
|
/// A helper trait to absorb different objects in RO
|
||||||
|
|||||||
Reference in New Issue
Block a user