Skip to content

Commit 9302131

Browse files
authored
Merge pull request #134 from dalek-cryptography/rework-gens
Check generator lengths in range proof
2 parents 58c2f3e + 386bfda commit 9302131

File tree

2 files changed

+17
-2
lines changed

2 files changed

+17
-2
lines changed

src/errors.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,15 @@ pub enum ProofError {
1515
WrongNumBlindingFactors,
1616
/// This error occurs when attempting to create a proof with
1717
/// bitsize other than \\(8\\), \\(16\\), \\(32\\), or \\(64\\).
18-
#[fail(display = "Invalid bitsize, must have n = 8,16,32,64")]
18+
#[fail(display = "Invalid bitsize, must have n = 8,16,32,64.")]
1919
InvalidBitsize,
2020
/// This error occurs when attempting to create an aggregated
2121
/// proof with non-power-of-two aggregation size.
22-
#[fail(display = "Invalid aggregation size, m must be a power of 2")]
22+
#[fail(display = "Invalid aggregation size, m must be a power of 2.")]
2323
InvalidAggregation,
24+
/// This error occurs when the generators are of the wrong length.
25+
#[fail(display = "Invalid generators length, must be equal to n.")]
26+
InvalidGeneratorsLength,
2427
/// This error results from an internal error during proving.
2528
///
2629
/// The single-party prover is implemented by performing

src/range_proof/mod.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,12 @@ impl RangeProof {
7878
if values.len() != blindings.len() {
7979
return Err(ProofError::WrongNumBlindingFactors);
8080
}
81+
if generators.n != n {
82+
return Err(ProofError::InvalidGeneratorsLength);
83+
}
84+
if !(n == 8 || n == 16 || n == 32 || n == 64) {
85+
return Err(ProofError::InvalidBitsize);
86+
}
8187

8288
let dealer = Dealer::new(generators, n, values.len(), transcript)?;
8389

@@ -145,6 +151,12 @@ impl RangeProof {
145151
) -> Result<(), ProofError> {
146152
// First, replay the "interactive" protocol using the proof
147153
// data to recompute all challenges.
154+
if gens.n != n {
155+
return Err(ProofError::InvalidGeneratorsLength);
156+
}
157+
if !(n == 8 || n == 16 || n == 32 || n == 64) {
158+
return Err(ProofError::InvalidBitsize);
159+
}
148160

149161
let m = value_commitments.len();
150162

0 commit comments

Comments
 (0)