Skip to content

Commit 5c80d44

Browse files
committed
Add generator length check and n-is-power-of-two checks
1 parent b0360e1 commit 5c80d44

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed

src/errors.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@ pub enum ProofError {
2121
/// proof with non-power-of-two aggregation size.
2222
#[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)