Skip to content

Commit a4b7774

Browse files
committed
Ensure all iterators have exact lengths
1 parent 97c54d5 commit a4b7774

File tree

2 files changed

+9
-4
lines changed

2 files changed

+9
-4
lines changed

src/range_proof/mod.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -187,14 +187,15 @@ impl RangeProof {
187187
// Construct concat_z_and_2, an iterator of the values of
188188
// z^0 * \vec(2)^n || z^1 * \vec(2)^n || ... || z^(m-1) * \vec(2)^n
189189
let powers_of_2: Vec<Scalar> = util::exp_iter(Scalar::from(2u64)).take(n).collect();
190-
let powers_of_z = util::exp_iter(z).take(m);
191-
let concat_z_and_2 =
192-
powers_of_z.flat_map(|exp_z| powers_of_2.iter().map(move |exp_2| exp_2 * exp_z));
190+
let concat_z_and_2: Vec<Scalar> = util::exp_iter(z)
191+
.take(m)
192+
.flat_map(|exp_z| powers_of_2.iter().map(move |exp_2| exp_2 * exp_z))
193+
.collect();
193194

194195
let g = s.iter().map(|s_i| minus_z - a * s_i);
195196
let h = s_inv
196197
.zip(util::exp_iter(y.invert()))
197-
.zip(concat_z_and_2)
198+
.zip(concat_z_and_2.iter())
198199
.map(|((s_i_inv, exp_y_inv), z_and_2)| z + exp_y_inv * (zz * z_and_2 - b * s_i_inv));
199200

200201
let value_commitment_scalars = util::exp_iter(z).take(m).map(|z_exp| c * zz * z_exp);

src/util.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,10 @@ impl Iterator for ScalarExp {
2626
self.next_exp_x *= self.x;
2727
Some(exp_x)
2828
}
29+
30+
fn size_hint(&self) -> (usize, Option<usize>) {
31+
(usize::max_value(), None)
32+
}
2933
}
3034

3135
/// Return an iterator of the powers of `x`.

0 commit comments

Comments
 (0)