Skip to content

Commit 0f2fed9

Browse files
committed
Add a transcript protocol function that checks for identity points.
1 parent 707ee84 commit 0f2fed9

File tree

4 files changed

+39
-8
lines changed

4 files changed

+39
-8
lines changed

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ keywords = ["cryptography", "ristretto", "zero-knowledge", "bulletproofs"]
1212
description = "A pure-Rust implementation of Bulletproofs using Ristretto"
1313

1414
[dependencies]
15-
curve25519-dalek = { version = "1", features = ["serde"] }
15+
curve25519-dalek = { version = "1.0.3", features = ["serde"] }
1616
subtle = "2"
1717
sha3 = "0.8"
1818
digest = "0.8"

src/inner_product_proof.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -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.commit_point(b"L", L);
209-
transcript.commit_point(b"R", R);
208+
transcript.validate_and_commit_point(b"L", L)?;
209+
transcript.validate_and_commit_point(b"R", R)?;
210210
challenges.push(transcript.challenge_scalar(b"u"));
211211
}
212212

src/range_proof/mod.rs

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

289289
for V in value_commitments.iter() {
290-
transcript.commit_point(b"V", V);
290+
transcript.validate_and_commit_point(b"V", V)?;
291291
}
292-
transcript.commit_point(b"A", &self.A);
293-
transcript.commit_point(b"S", &self.S);
292+
293+
transcript.validate_and_commit_point(b"A", &self.A)?;
294+
transcript.validate_and_commit_point(b"S", &self.S)?;
294295

295296
let y = transcript.challenge_scalar(b"y");
296297
let z = transcript.challenge_scalar(b"z");
297298
let zz = z * z;
298299
let minus_z = -z;
299300

300-
transcript.commit_point(b"T_1", &self.T_1);
301-
transcript.commit_point(b"T_2", &self.T_2);
301+
transcript.validate_and_commit_point(b"T_1", &self.T_1)?;
302+
transcript.validate_and_commit_point(b"T_2", &self.T_2)?;
302303

303304
let x = transcript.challenge_scalar(b"x");
304305

src/transcript.rs

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,19 +5,35 @@ use curve25519_dalek::ristretto::CompressedRistretto;
55
use curve25519_dalek::scalar::Scalar;
66
use merlin::Transcript;
77

8+
use errors::ProofError;
9+
810
pub trait TranscriptProtocol {
911
/// Commit a domain separator for an `n`-bit, `m`-party range proof.
1012
fn rangeproof_domain_sep(&mut self, n: u64, m: u64);
13+
1114
/// Commit a domain separator for a length-`n` inner product proof.
1215
fn innerproduct_domain_sep(&mut self, n: u64);
16+
1317
/// Commit a domain separator for a constraint system.
1418
fn r1cs_domain_sep(&mut self);
19+
1520
/// Commit a 64-bit integer.
1621
fn commit_u64(&mut self, label: &'static [u8], n: u64);
22+
1723
/// Commit a `scalar` with the given `label`.
1824
fn commit_scalar(&mut self, label: &'static [u8], scalar: &Scalar);
25+
1926
/// Commit a `point` with the given `label`.
2027
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
30+
/// transcript. Otherwise, return an error.
31+
fn validate_and_commit_point(
32+
&mut self,
33+
label: &'static [u8],
34+
point: &CompressedRistretto,
35+
) -> Result<(), ProofError>;
36+
2137
/// Compute a `label`ed challenge variable.
2238
fn challenge_scalar(&mut self, label: &'static [u8]) -> Scalar;
2339
}
@@ -56,6 +72,20 @@ impl TranscriptProtocol for Transcript {
5672
self.commit_bytes(label, point.as_bytes());
5773
}
5874

75+
fn validate_and_commit_point(
76+
&mut self,
77+
label: &'static [u8],
78+
point: &CompressedRistretto,
79+
) -> Result<(), ProofError> {
80+
use curve25519_dalek::traits::IsIdentity;
81+
82+
if point.is_identity() {
83+
Err(ProofError::VerificationError)
84+
} else {
85+
Ok(self.commit_bytes(label, point.as_bytes()))
86+
}
87+
}
88+
5989
fn challenge_scalar(&mut self, label: &'static [u8]) -> Scalar {
6090
let mut buf = [0u8; 64];
6191
self.challenge_bytes(label, &mut buf);

0 commit comments

Comments
 (0)