Skip to content

Commit

Permalink
fix: reduce vector capacity (#45)
Browse files Browse the repository at this point in the history
When computing the `d` vector, the prover and verify each allocate too
much space for it. This is unnecessary, since the number of scalar
elements in the vector is known.

This PR fixes the over-allocation by correcting the requested capacity.
This can be checked manually by examining the number of elements pushed
to the vector in both the prover and verifier cases.
  • Loading branch information
AaronFeickert committed Jul 21, 2023
1 parent 3e0008e commit 9caa0c9
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/range_proof.rs
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,7 @@ where
}

// Compute d efficiently
let mut d = Vec::with_capacity(bit_length + bit_length * aggregation_factor);
let mut d = Vec::with_capacity(bit_length * aggregation_factor);
d.push(z_square);
let two = Scalar::from(2u8);
for i in 1..bit_length {
Expand Down Expand Up @@ -602,7 +602,7 @@ where
}

// Compute d efficiently
let mut d = Vec::with_capacity(bit_length + bit_length * aggregation_factor);
let mut d = Vec::with_capacity(bit_length * aggregation_factor);
d.push(z_square);
for i in 1..bit_length {
d.push(two * d[i - 1]);
Expand Down

0 comments on commit 9caa0c9

Please sign in to comment.