Skip to content

Commit ba4c168

Browse files
authored
Merge pull request #133 from dalek-cryptography/merlin-transcript
Use "Merlin" transcripts
2 parents 9302131 + 2878b41 commit ba4c168

File tree

8 files changed

+134
-389
lines changed

8 files changed

+134
-389
lines changed

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ serde = "1"
2222
serde_derive = "1"
2323
tiny-keccak = "1.4.1"
2424
failure = "0.1"
25+
merlin = "0.3"
2526

2627
[dev-dependencies]
2728
hex = "^0.3"

benches/bulletproofs.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ extern crate curve25519_dalek;
1010
use curve25519_dalek::scalar::Scalar;
1111

1212
extern crate bulletproofs;
13-
use bulletproofs::ProofTranscript;
1413
use bulletproofs::RangeProof;
14+
use bulletproofs::Transcript;
1515
use bulletproofs::{Generators, PedersenGenerators};
1616

1717
static AGGREGATION_SIZES: [usize; 6] = [1, 2, 4, 8, 16, 32];
@@ -31,7 +31,7 @@ fn create_aggregated_rangeproof_helper(n: usize, c: &mut Criterion) {
3131

3232
b.iter(|| {
3333
// Each proof creation requires a clean transcript.
34-
let mut transcript = ProofTranscript::new(b"AggregateRangeProofBenchmark");
34+
let mut transcript = Transcript::new(b"AggregateRangeProofBenchmark");
3535

3636
RangeProof::prove_multiple(
3737
&generators,
@@ -76,7 +76,7 @@ fn verify_aggregated_rangeproof_helper(n: usize, c: &mut Criterion) {
7676
let values: Vec<u64> = (0..m).map(|_| rng.gen_range(min, max)).collect();
7777
let blindings: Vec<Scalar> = (0..m).map(|_| Scalar::random(&mut rng)).collect();
7878

79-
let mut transcript = ProofTranscript::new(b"AggregateRangeProofBenchmark");
79+
let mut transcript = Transcript::new(b"AggregateRangeProofBenchmark");
8080
let proof = RangeProof::prove_multiple(
8181
&generators,
8282
&mut transcript,
@@ -96,7 +96,7 @@ fn verify_aggregated_rangeproof_helper(n: usize, c: &mut Criterion) {
9696

9797
b.iter(|| {
9898
// Each proof creation requires a clean transcript.
99-
let mut transcript = ProofTranscript::new(b"AggregateRangeProofBenchmark");
99+
let mut transcript = Transcript::new(b"AggregateRangeProofBenchmark");
100100

101101
proof.verify(
102102
&value_commitments,

src/inner_product_proof.rs

Lines changed: 22 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
#![allow(non_snake_case)]
2-
32
#![doc(include = "../docs/inner-product-protocol.md")]
43

54
use std::borrow::Borrow;
@@ -8,10 +7,10 @@ use std::iter;
87
use curve25519_dalek::ristretto::{CompressedRistretto, RistrettoPoint};
98
use curve25519_dalek::scalar::Scalar;
109
use curve25519_dalek::traits::VartimeMultiscalarMul;
11-
12-
use proof_transcript::ProofTranscript;
10+
use merlin::Transcript;
1311

1412
use errors::ProofError;
13+
use transcript::TranscriptProtocol;
1514

1615
#[derive(Clone, Debug)]
1716
pub struct InnerProductProof {
@@ -34,7 +33,7 @@ impl InnerProductProof {
3433
/// The lengths of the vectors must all be the same, and must all be
3534
/// either 0 or a power of 2.
3635
pub fn create<I>(
37-
verifier: &mut ProofTranscript,
36+
transcript: &mut Transcript,
3837
Q: &RistrettoPoint,
3938
Hprime_factors: I,
4039
mut G_vec: Vec<RistrettoPoint>,
@@ -65,6 +64,8 @@ impl InnerProductProof {
6564
// All of the input vectors must have a length that is a power of two.
6665
assert!(n.is_power_of_two());
6766

67+
transcript.innerproduct_domain_sep(n as u64);
68+
6869
// XXX save these scalar mults by unrolling them into the
6970
// first iteration of the loop below
7071
for (H_i, h_i) in H.iter_mut().zip(Hprime_factors.into_iter()) {
@@ -88,20 +89,20 @@ impl InnerProductProof {
8889
let L = RistrettoPoint::vartime_multiscalar_mul(
8990
a_L.iter().chain(b_R.iter()).chain(iter::once(&c_L)),
9091
G_R.iter().chain(H_L.iter()).chain(iter::once(Q)),
91-
);
92+
).compress();
9293

9394
let R = RistrettoPoint::vartime_multiscalar_mul(
9495
a_R.iter().chain(b_L.iter()).chain(iter::once(&c_R)),
9596
G_L.iter().chain(H_R.iter()).chain(iter::once(Q)),
96-
);
97+
).compress();
9798

98-
L_vec.push(L.compress());
99-
R_vec.push(R.compress());
99+
L_vec.push(L);
100+
R_vec.push(R);
100101

101-
verifier.commit(L.compress().as_bytes());
102-
verifier.commit(R.compress().as_bytes());
102+
transcript.commit_point(b"L", &L);
103+
transcript.commit_point(b"R", &R);
103104

104-
let u = verifier.challenge_scalar();
105+
let u = transcript.challenge_scalar(b"u");
105106
let u_inv = u.invert();
106107

107108
for i in 0..n {
@@ -129,18 +130,20 @@ impl InnerProductProof {
129130
/// in a parent protocol. See [inner product protocol notes](index.html#verification-equation) for details.
130131
pub(crate) fn verification_scalars(
131132
&self,
132-
transcript: &mut ProofTranscript,
133+
transcript: &mut Transcript,
133134
) -> (Vec<Scalar>, Vec<Scalar>, Vec<Scalar>) {
134135
let lg_n = self.L_vec.len();
135136
let n = 1 << lg_n;
136137

138+
transcript.innerproduct_domain_sep(n as u64);
139+
137140
// 1. Recompute x_k,...,x_1 based on the proof transcript
138141

139142
let mut challenges = Vec::with_capacity(lg_n);
140143
for (L, R) in self.L_vec.iter().zip(self.R_vec.iter()) {
141-
transcript.commit(L.as_bytes());
142-
transcript.commit(R.as_bytes());
143-
challenges.push(transcript.challenge_scalar());
144+
transcript.commit_point(b"L", L);
145+
transcript.commit_point(b"R", R);
146+
challenges.push(transcript.challenge_scalar(b"u"));
144147
}
145148

146149
// 2. Compute 1/(u_k...u_1) and 1/u_k, ..., 1/u_1
@@ -181,7 +184,7 @@ impl InnerProductProof {
181184
#[allow(dead_code)]
182185
pub fn verify<I>(
183186
&self,
184-
transcript: &mut ProofTranscript,
187+
transcript: &mut Transcript,
185188
Hprime_factors: I,
186189
P: &RistrettoPoint,
187190
Q: &RistrettoPoint,
@@ -362,7 +365,7 @@ mod tests {
362365
G.iter().chain(H.iter()).chain(iter::once(&Q)),
363366
);
364367

365-
let mut verifier = ProofTranscript::new(b"innerproducttest");
368+
let mut verifier = Transcript::new(b"innerproducttest");
366369
let proof = InnerProductProof::create(
367370
&mut verifier,
368371
&Q,
@@ -373,15 +376,15 @@ mod tests {
373376
b.clone(),
374377
);
375378

376-
let mut verifier = ProofTranscript::new(b"innerproducttest");
379+
let mut verifier = Transcript::new(b"innerproducttest");
377380
assert!(
378381
proof
379382
.verify(&mut verifier, util::exp_iter(y_inv), &P, &Q, &G, &H)
380383
.is_ok()
381384
);
382385

383386
let proof = InnerProductProof::from_bytes(proof.to_bytes().as_slice()).unwrap();
384-
let mut verifier = ProofTranscript::new(b"innerproducttest");
387+
let mut verifier = Transcript::new(b"innerproducttest");
385388
assert!(
386389
proof
387390
.verify(&mut verifier, util::exp_iter(y_inv), &P, &Q, &G, &H)

src/lib.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ extern crate curve25519_dalek;
1414
extern crate digest;
1515
#[macro_use]
1616
extern crate failure;
17+
extern crate merlin;
1718
extern crate rand;
1819
extern crate sha3;
1920
extern crate subtle;
@@ -34,12 +35,13 @@ mod notes {}
3435
mod errors;
3536
mod generators;
3637
mod inner_product_proof;
37-
mod proof_transcript;
3838
mod range_proof;
39+
mod transcript;
40+
41+
pub use merlin::Transcript;
3942

4043
pub use errors::ProofError;
4144
pub use generators::{Generators, GeneratorsView, PedersenGenerators};
42-
pub use proof_transcript::ProofTranscript;
4345
pub use range_proof::RangeProof;
4446

4547
#[doc(include = "../docs/aggregation-api.md")]

0 commit comments

Comments
 (0)