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