|
@ -2,7 +2,7 @@ |
|
|
use crate::{
|
|
|
use crate::{
|
|
|
errors::NovaError,
|
|
|
errors::NovaError,
|
|
|
traits::{
|
|
|
traits::{
|
|
|
commitment::{CommitmentEngineTrait, CommitmentKeyTrait, CommitmentTrait},
|
|
|
|
|
|
|
|
|
commitment::{CommitmentEngineTrait, CommitmentTrait},
|
|
|
AbsorbInROTrait, CompressedGroup, Group, ROTrait, TranscriptReprTrait,
|
|
|
AbsorbInROTrait, CompressedGroup, Group, ROTrait, TranscriptReprTrait,
|
|
|
},
|
|
|
},
|
|
|
};
|
|
|
};
|
|
@ -36,28 +36,6 @@ pub struct CompressedCommitment { |
|
|
comm: G::CompressedGroupElement,
|
|
|
comm: G::CompressedGroupElement,
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
impl<G: Group> CommitmentKeyTrait<G> for CommitmentKey<G> {
|
|
|
|
|
|
type Commitment = Commitment<G>;
|
|
|
|
|
|
|
|
|
|
|
|
fn new(label: &'static [u8], n: usize) -> Self {
|
|
|
|
|
|
CommitmentKey {
|
|
|
|
|
|
ck: G::from_label(label, n.next_power_of_two()),
|
|
|
|
|
|
_p: Default::default(),
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
fn len(&self) -> usize {
|
|
|
|
|
|
self.ck.len()
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
fn commit(&self, v: &[G::Scalar]) -> Self::Commitment {
|
|
|
|
|
|
assert!(self.ck.len() >= v.len());
|
|
|
|
|
|
Commitment {
|
|
|
|
|
|
comm: G::vartime_multiscalar_mul(v, &self.ck[..v.len()]),
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
impl<G: Group> CommitmentTrait<G> for Commitment<G> {
|
|
|
impl<G: Group> CommitmentTrait<G> for Commitment<G> {
|
|
|
type CompressedCommitment = CompressedCommitment<G>;
|
|
|
type CompressedCommitment = CompressedCommitment<G>;
|
|
|
|
|
|
|
|
@ -210,12 +188,22 @@ impl CommitmentEngineTrait for CommitmentEngine { |
|
|
type CommitmentKey = CommitmentKey<G>;
|
|
|
type CommitmentKey = CommitmentKey<G>;
|
|
|
type Commitment = Commitment<G>;
|
|
|
type Commitment = Commitment<G>;
|
|
|
|
|
|
|
|
|
|
|
|
fn setup(label: &'static [u8], n: usize) -> Self::CommitmentKey {
|
|
|
|
|
|
Self::CommitmentKey {
|
|
|
|
|
|
ck: G::from_label(label, n.next_power_of_two()),
|
|
|
|
|
|
_p: Default::default(),
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
fn commit(ck: &Self::CommitmentKey, v: &[G::Scalar]) -> Self::Commitment {
|
|
|
fn commit(ck: &Self::CommitmentKey, v: &[G::Scalar]) -> Self::Commitment {
|
|
|
ck.commit(v)
|
|
|
|
|
|
|
|
|
assert!(ck.ck.len() >= v.len());
|
|
|
|
|
|
Commitment {
|
|
|
|
|
|
comm: G::vartime_multiscalar_mul(v, &ck.ck[..v.len()]),
|
|
|
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
pub(crate) trait CommitmentKeyExtTrait<G: Group>: CommitmentKeyTrait<G> {
|
|
|
|
|
|
|
|
|
pub(crate) trait CommitmentKeyExtTrait<G: Group> {
|
|
|
type CE: CommitmentEngineTrait<G>;
|
|
|
type CE: CommitmentEngineTrait<G>;
|
|
|
|
|
|
|
|
|
/// Splits the commitment key into two pieces at a specified point
|
|
|
/// Splits the commitment key into two pieces at a specified point
|
|
@ -271,9 +259,9 @@ impl CommitmentKeyExtTrait for CommitmentKey { |
|
|
// combines the left and right halves of `self` using `w1` and `w2` as the weights
|
|
|
// combines the left and right halves of `self` using `w1` and `w2` as the weights
|
|
|
fn fold(&self, w1: &G::Scalar, w2: &G::Scalar) -> CommitmentKey<G> {
|
|
|
fn fold(&self, w1: &G::Scalar, w2: &G::Scalar) -> CommitmentKey<G> {
|
|
|
let w = vec![*w1, *w2];
|
|
|
let w = vec![*w1, *w2];
|
|
|
let (L, R) = self.split_at(self.len() / 2);
|
|
|
|
|
|
|
|
|
let (L, R) = self.split_at(self.ck.len() / 2);
|
|
|
|
|
|
|
|
|
let ck = (0..self.len() / 2)
|
|
|
|
|
|
|
|
|
let ck = (0..self.ck.len() / 2)
|
|
|
.into_par_iter()
|
|
|
.into_par_iter()
|
|
|
.map(|i| {
|
|
|
.map(|i| {
|
|
|
let bases = [L.ck[i].clone(), R.ck[i].clone()].to_vec();
|
|
|
let bases = [L.ck[i].clone(), R.ck[i].clone()].to_vec();
|
|
|