Skip to content

Commit 4af51a5

Browse files
committed
Update Merlin to 1.1
1 parent 0f2fed9 commit 4af51a5

File tree

7 files changed

+70
-84
lines changed

7 files changed

+70
-84
lines changed

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ byteorder = "1"
2121
serde = "1"
2222
serde_derive = "1"
2323
failure = "0.1"
24-
merlin = "1"
24+
merlin = "1.1"
2525
clear_on_drop = "0.2"
2626

2727
[dev-dependencies]

src/inner_product_proof.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -107,8 +107,8 @@ impl InnerProductProof {
107107
L_vec.push(L);
108108
R_vec.push(R);
109109

110-
transcript.commit_point(b"L", &L);
111-
transcript.commit_point(b"R", &R);
110+
transcript.append_point(b"L", &L);
111+
transcript.append_point(b"R", &R);
112112

113113
let u = transcript.challenge_scalar(b"u");
114114
let u_inv = u.invert();
@@ -154,8 +154,8 @@ impl InnerProductProof {
154154
L_vec.push(L);
155155
R_vec.push(R);
156156

157-
transcript.commit_point(b"L", &L);
158-
transcript.commit_point(b"R", &R);
157+
transcript.append_point(b"L", &L);
158+
transcript.append_point(b"R", &R);
159159

160160
let u = transcript.challenge_scalar(b"u");
161161
let u_inv = u.invert();
@@ -205,8 +205,8 @@ impl InnerProductProof {
205205

206206
let mut challenges = Vec::with_capacity(lg_n);
207207
for (L, R) in self.L_vec.iter().zip(self.R_vec.iter()) {
208-
transcript.validate_and_commit_point(b"L", L)?;
209-
transcript.validate_and_commit_point(b"R", R)?;
208+
transcript.validate_and_append_point(b"L", L)?;
209+
transcript.validate_and_append_point(b"R", R)?;
210210
challenges.push(transcript.challenge_scalar(b"u"));
211211
}
212212

src/r1cs/prover.rs

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@ impl<'a, 'b> Prover<'a, 'b> {
204204

205205
// Add the commitment to the transcript.
206206
let V = self.cs.pc_gens.commit(v, v_blinding).compress();
207-
self.cs.transcript.commit_point(b"V", &V);
207+
self.cs.transcript.append_point(b"V", &V);
208208

209209
(V, Variable::Committed(i))
210210
}
@@ -216,7 +216,7 @@ impl<'a, 'b> Prover<'a, 'b> {
216216
// We cannot do this in advance because user can commit variables one-by-one,
217217
// but this suffix provides safe disambiguation because each variable
218218
// is prefixed with a separate label.
219-
self.cs.transcript.commit_u64(b"m", self.m);
219+
self.cs.transcript.append_u64(b"m", self.m);
220220
self.cs
221221
}
222222
}
@@ -368,9 +368,9 @@ impl<'a, 'b> ProverCS<'a, 'b> {
368368
)
369369
.compress();
370370

371-
self.transcript.commit_point(b"A_I", &A_I);
372-
self.transcript.commit_point(b"A_O", &A_O);
373-
self.transcript.commit_point(b"S", &S);
371+
self.transcript.append_point(b"A_I", &A_I);
372+
self.transcript.append_point(b"A_O", &A_O);
373+
self.transcript.append_point(b"S", &S);
374374

375375
// 4. Compute blinded vector polynomials l(x) and r(x)
376376

@@ -419,11 +419,11 @@ impl<'a, 'b> ProverCS<'a, 'b> {
419419
let T_5 = self.pc_gens.commit(t_poly.t5, t_5_blinding).compress();
420420
let T_6 = self.pc_gens.commit(t_poly.t6, t_6_blinding).compress();
421421

422-
self.transcript.commit_point(b"T_1", &T_1);
423-
self.transcript.commit_point(b"T_3", &T_3);
424-
self.transcript.commit_point(b"T_4", &T_4);
425-
self.transcript.commit_point(b"T_5", &T_5);
426-
self.transcript.commit_point(b"T_6", &T_6);
422+
self.transcript.append_point(b"T_1", &T_1);
423+
self.transcript.append_point(b"T_3", &T_3);
424+
self.transcript.append_point(b"T_4", &T_4);
425+
self.transcript.append_point(b"T_5", &T_5);
426+
self.transcript.append_point(b"T_6", &T_6);
427427

428428
let x = self.transcript.challenge_scalar(b"x");
429429

@@ -460,10 +460,10 @@ impl<'a, 'b> ProverCS<'a, 'b> {
460460

461461
let e_blinding = x * (i_blinding + x * (o_blinding + x * s_blinding));
462462

463-
self.transcript.commit_scalar(b"t_x", &t_x);
463+
self.transcript.append_scalar(b"t_x", &t_x);
464464
self.transcript
465-
.commit_scalar(b"t_x_blinding", &t_x_blinding);
466-
self.transcript.commit_scalar(b"e_blinding", &e_blinding);
465+
.append_scalar(b"t_x_blinding", &t_x_blinding);
466+
self.transcript.append_scalar(b"e_blinding", &e_blinding);
467467

468468
// Get a challenge value to combine statements for the IPP
469469
let w = self.transcript.challenge_scalar(b"w");

src/r1cs/verifier.rs

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ impl<'a, 'b> Verifier<'a, 'b> {
171171
self.cs.V.push(commitment);
172172

173173
// Add the commitment to the transcript.
174-
self.cs.transcript.commit_point(b"V", &commitment);
174+
self.cs.transcript.append_point(b"V", &commitment);
175175

176176
Variable::Committed(i)
177177
}
@@ -183,7 +183,7 @@ impl<'a, 'b> Verifier<'a, 'b> {
183183
// We cannot do this in advance because user can commit variables one-by-one,
184184
// but this suffix provides safe disambiguation because each variable
185185
// is prefixed with a separate label.
186-
self.cs.transcript.commit_u64(b"m", self.m);
186+
self.cs.transcript.append_u64(b"m", self.m);
187187
self.cs
188188
}
189189
}
@@ -261,26 +261,26 @@ impl<'a, 'b> VerifierCS<'a, 'b> {
261261
// We are performing a single-party circuit proof, so party index is 0.
262262
let gens = self.bp_gens.share(0);
263263

264-
self.transcript.commit_point(b"A_I", &proof.A_I);
265-
self.transcript.commit_point(b"A_O", &proof.A_O);
266-
self.transcript.commit_point(b"S", &proof.S);
264+
self.transcript.append_point(b"A_I", &proof.A_I);
265+
self.transcript.append_point(b"A_O", &proof.A_O);
266+
self.transcript.append_point(b"S", &proof.S);
267267

268268
let y = self.transcript.challenge_scalar(b"y");
269269
let z = self.transcript.challenge_scalar(b"z");
270270

271-
self.transcript.commit_point(b"T_1", &proof.T_1);
272-
self.transcript.commit_point(b"T_3", &proof.T_3);
273-
self.transcript.commit_point(b"T_4", &proof.T_4);
274-
self.transcript.commit_point(b"T_5", &proof.T_5);
275-
self.transcript.commit_point(b"T_6", &proof.T_6);
271+
self.transcript.append_point(b"T_1", &proof.T_1);
272+
self.transcript.append_point(b"T_3", &proof.T_3);
273+
self.transcript.append_point(b"T_4", &proof.T_4);
274+
self.transcript.append_point(b"T_5", &proof.T_5);
275+
self.transcript.append_point(b"T_6", &proof.T_6);
276276

277277
let x = self.transcript.challenge_scalar(b"x");
278278

279-
self.transcript.commit_scalar(b"t_x", &proof.t_x);
279+
self.transcript.append_scalar(b"t_x", &proof.t_x);
280280
self.transcript
281-
.commit_scalar(b"t_x_blinding", &proof.t_x_blinding);
281+
.append_scalar(b"t_x_blinding", &proof.t_x_blinding);
282282
self.transcript
283-
.commit_scalar(b"e_blinding", &proof.e_blinding);
283+
.append_scalar(b"e_blinding", &proof.e_blinding);
284284

285285
let w = self.transcript.challenge_scalar(b"w");
286286

src/range_proof/dealer.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -94,15 +94,15 @@ impl<'a, 'b> DealerAwaitingBitCommitments<'a, 'b> {
9494

9595
// Commit each V_j individually
9696
for vc in bit_commitments.iter() {
97-
self.transcript.commit_point(b"V", &vc.V_j);
97+
self.transcript.append_point(b"V", &vc.V_j);
9898
}
9999

100100
// Commit aggregated A_j, S_j
101101
let A: RistrettoPoint = bit_commitments.iter().map(|vc| vc.A_j).sum();
102-
self.transcript.commit_point(b"A", &A.compress());
102+
self.transcript.append_point(b"A", &A.compress());
103103

104104
let S: RistrettoPoint = bit_commitments.iter().map(|vc| vc.S_j).sum();
105-
self.transcript.commit_point(b"S", &S.compress());
105+
self.transcript.append_point(b"S", &S.compress());
106106

107107
let y = self.transcript.challenge_scalar(b"y");
108108
let z = self.transcript.challenge_scalar(b"z");
@@ -158,8 +158,8 @@ impl<'a, 'b> DealerAwaitingPolyCommitments<'a, 'b> {
158158
let T_1: RistrettoPoint = poly_commitments.iter().map(|pc| pc.T_1_j).sum();
159159
let T_2: RistrettoPoint = poly_commitments.iter().map(|pc| pc.T_2_j).sum();
160160

161-
self.transcript.commit_point(b"T_1", &T_1.compress());
162-
self.transcript.commit_point(b"T_2", &T_2.compress());
161+
self.transcript.append_point(b"T_1", &T_1.compress());
162+
self.transcript.append_point(b"T_2", &T_2.compress());
163163

164164
let x = self.transcript.challenge_scalar(b"x");
165165
let poly_challenge = PolyChallenge { x };
@@ -221,10 +221,10 @@ impl<'a, 'b> DealerAwaitingProofShares<'a, 'b> {
221221
let t_x_blinding: Scalar = proof_shares.iter().map(|ps| ps.t_x_blinding).sum();
222222
let e_blinding: Scalar = proof_shares.iter().map(|ps| ps.e_blinding).sum();
223223

224-
self.transcript.commit_scalar(b"t_x", &t_x);
224+
self.transcript.append_scalar(b"t_x", &t_x);
225225
self.transcript
226-
.commit_scalar(b"t_x_blinding", &t_x_blinding);
227-
self.transcript.commit_scalar(b"e_blinding", &e_blinding);
226+
.append_scalar(b"t_x_blinding", &t_x_blinding);
227+
self.transcript.append_scalar(b"e_blinding", &e_blinding);
228228

229229
// Get a challenge value to combine statements for the IPP
230230
let w = self.transcript.challenge_scalar(b"w");

src/range_proof/mod.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -287,25 +287,25 @@ impl RangeProof {
287287
transcript.rangeproof_domain_sep(n as u64, m as u64);
288288

289289
for V in value_commitments.iter() {
290-
transcript.validate_and_commit_point(b"V", V)?;
290+
transcript.validate_and_append_point(b"V", V)?;
291291
}
292292

293-
transcript.validate_and_commit_point(b"A", &self.A)?;
294-
transcript.validate_and_commit_point(b"S", &self.S)?;
293+
transcript.validate_and_append_point(b"A", &self.A)?;
294+
transcript.validate_and_append_point(b"S", &self.S)?;
295295

296296
let y = transcript.challenge_scalar(b"y");
297297
let z = transcript.challenge_scalar(b"z");
298298
let zz = z * z;
299299
let minus_z = -z;
300300

301-
transcript.validate_and_commit_point(b"T_1", &self.T_1)?;
302-
transcript.validate_and_commit_point(b"T_2", &self.T_2)?;
301+
transcript.validate_and_append_point(b"T_1", &self.T_1)?;
302+
transcript.validate_and_append_point(b"T_2", &self.T_2)?;
303303

304304
let x = transcript.challenge_scalar(b"x");
305305

306-
transcript.commit_scalar(b"t_x", &self.t_x);
307-
transcript.commit_scalar(b"t_x_blinding", &self.t_x_blinding);
308-
transcript.commit_scalar(b"e_blinding", &self.e_blinding);
306+
transcript.append_scalar(b"t_x", &self.t_x);
307+
transcript.append_scalar(b"t_x_blinding", &self.t_x_blinding);
308+
transcript.append_scalar(b"e_blinding", &self.e_blinding);
309309

310310
let w = transcript.challenge_scalar(b"w");
311311

src/transcript.rs

Lines changed: 21 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,30 @@
11
//! Defines a `TranscriptProtocol` trait for using a Merlin transcript.
22
3-
use byteorder::{ByteOrder, LittleEndian};
43
use curve25519_dalek::ristretto::CompressedRistretto;
54
use curve25519_dalek::scalar::Scalar;
65
use merlin::Transcript;
76

87
use errors::ProofError;
98

109
pub trait TranscriptProtocol {
11-
/// Commit a domain separator for an `n`-bit, `m`-party range proof.
10+
/// Append a domain separator for an `n`-bit, `m`-party range proof.
1211
fn rangeproof_domain_sep(&mut self, n: u64, m: u64);
1312

14-
/// Commit a domain separator for a length-`n` inner product proof.
13+
/// Append a domain separator for a length-`n` inner product proof.
1514
fn innerproduct_domain_sep(&mut self, n: u64);
1615

17-
/// Commit a domain separator for a constraint system.
16+
/// Append a domain separator for a constraint system.
1817
fn r1cs_domain_sep(&mut self);
1918

20-
/// Commit a 64-bit integer.
21-
fn commit_u64(&mut self, label: &'static [u8], n: u64);
19+
/// Append a `scalar` with the given `label`.
20+
fn append_scalar(&mut self, label: &'static [u8], scalar: &Scalar);
2221

23-
/// Commit a `scalar` with the given `label`.
24-
fn commit_scalar(&mut self, label: &'static [u8], scalar: &Scalar);
22+
/// Append a `point` with the given `label`.
23+
fn append_point(&mut self, label: &'static [u8], point: &CompressedRistretto);
2524

26-
/// Commit a `point` with the given `label`.
27-
fn commit_point(&mut self, label: &'static [u8], point: &CompressedRistretto);
28-
29-
/// Check that a point is not the identity, then commit it to the
25+
/// Check that a point is not the identity, then append it to the
3026
/// transcript. Otherwise, return an error.
31-
fn validate_and_commit_point(
27+
fn validate_and_append_point(
3228
&mut self,
3329
label: &'static [u8],
3430
point: &CompressedRistretto,
@@ -38,41 +34,31 @@ pub trait TranscriptProtocol {
3834
fn challenge_scalar(&mut self, label: &'static [u8]) -> Scalar;
3935
}
4036

41-
fn le_u64(value: u64) -> [u8; 8] {
42-
let mut value_bytes = [0u8; 8];
43-
LittleEndian::write_u64(&mut value_bytes, value);
44-
value_bytes
45-
}
46-
4737
impl TranscriptProtocol for Transcript {
4838
fn rangeproof_domain_sep(&mut self, n: u64, m: u64) {
49-
self.commit_bytes(b"dom-sep", b"rangeproof v1");
50-
self.commit_bytes(b"n", &le_u64(n));
51-
self.commit_bytes(b"m", &le_u64(m));
39+
self.append_message(b"dom-sep", b"rangeproof v1");
40+
self.append_u64(b"n", n);
41+
self.append_u64(b"m", m);
5242
}
5343

5444
fn innerproduct_domain_sep(&mut self, n: u64) {
55-
self.commit_bytes(b"dom-sep", b"ipp v1");
56-
self.commit_bytes(b"n", &le_u64(n));
45+
self.append_message(b"dom-sep", b"ipp v1");
46+
self.append_u64(b"n", n);
5747
}
5848

5949
fn r1cs_domain_sep(&mut self) {
60-
self.commit_bytes(b"dom-sep", b"r1cs v1");
61-
}
62-
63-
fn commit_u64(&mut self, label: &'static [u8], n: u64) {
64-
self.commit_bytes(label, &le_u64(n));
50+
self.append_message(b"dom-sep", b"r1cs v1");
6551
}
6652

67-
fn commit_scalar(&mut self, label: &'static [u8], scalar: &Scalar) {
68-
self.commit_bytes(label, scalar.as_bytes());
53+
fn append_scalar(&mut self, label: &'static [u8], scalar: &Scalar) {
54+
self.append_message(label, scalar.as_bytes());
6955
}
7056

71-
fn commit_point(&mut self, label: &'static [u8], point: &CompressedRistretto) {
72-
self.commit_bytes(label, point.as_bytes());
57+
fn append_point(&mut self, label: &'static [u8], point: &CompressedRistretto) {
58+
self.append_message(label, point.as_bytes());
7359
}
7460

75-
fn validate_and_commit_point(
61+
fn validate_and_append_point(
7662
&mut self,
7763
label: &'static [u8],
7864
point: &CompressedRistretto,
@@ -82,7 +68,7 @@ impl TranscriptProtocol for Transcript {
8268
if point.is_identity() {
8369
Err(ProofError::VerificationError)
8470
} else {
85-
Ok(self.commit_bytes(label, point.as_bytes()))
71+
Ok(self.append_message(label, point.as_bytes()))
8672
}
8773
}
8874

0 commit comments

Comments
 (0)