1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
pub mod errors;
pub mod key;
pub mod srs;
pub use key::{CommitKey, OpeningKey};
pub use srs::PublicParameters;
use crate::transcript::TranscriptProtocol;
use crate::util::powers_of;
use dusk_bls12_381::{G1Affine, G1Projective, Scalar};
use merlin::Transcript;
#[derive(Copy, Clone, Debug)]
pub struct Proof {
pub commitment_to_witness: Commitment,
pub evaluated_point: Scalar,
pub commitment_to_polynomial: Commitment,
}
#[derive(Debug)]
pub struct AggregateProof {
pub commitment_to_witness: Commitment,
pub evaluated_points: Vec<Scalar>,
pub commitments_to_polynomials: Vec<Commitment>,
}
impl AggregateProof {
pub fn with_witness(witness: Commitment) -> AggregateProof {
AggregateProof {
commitment_to_witness: witness,
evaluated_points: Vec::new(),
commitments_to_polynomials: Vec::new(),
}
}
pub fn add_part(&mut self, part: (Scalar, Commitment)) {
self.evaluated_points.push(part.0);
self.commitments_to_polynomials.push(part.1);
}
pub fn flatten(&self, transcript: &mut Transcript) -> Proof {
let challenge = transcript.challenge_scalar(b"aggregate_witness");
let powers = powers_of(&challenge, self.commitments_to_polynomials.len() - 1);
let flattened_poly_commitments: G1Projective = self
.commitments_to_polynomials
.iter()
.zip(powers.iter())
.map(|(poly, challenge)| poly.0 * challenge)
.sum();
let flattened_poly_evaluations: Scalar = self
.evaluated_points
.iter()
.zip(powers.iter())
.map(|(eval, challenge)| eval * challenge)
.fold(Scalar::zero(), |acc, current_val| acc + current_val);
Proof {
commitment_to_witness: self.commitment_to_witness,
evaluated_point: flattened_poly_evaluations,
commitment_to_polynomial: Commitment::from_projective(flattened_poly_commitments),
}
}
}
#[derive(Copy, Clone, Debug, Eq, PartialEq)]
pub struct Commitment(
pub G1Affine,
);
impl Commitment {
pub fn from_projective(g: G1Projective) -> Self {
Self(g.into())
}
pub fn from_affine(g: G1Affine) -> Self {
Self(g)
}
pub fn empty() -> Self {
Commitment(G1Affine::identity())
}
}
impl Default for Commitment {
fn default() -> Self {
Commitment::empty()
}
}