Skip to content

Commit d31eecf

Browse files
committed
halo2_proofs: Fix oversized initialization of commitment_data.evals
If `commitment_data.point_indices` contains duplicate indices, then `point_index_set` will be shorter. The old code initialized `commitment_data.evals` to be the same size as `point_indices`, which then left entries near the end without evaluations. Before the bugfix to reject two queries with the same point and commitment but different evaluations, this would have resulted in `commitment_data.evals` being returned with invalid "default" entries at the end. Fortunately this was not an observable bug as the code using `commitment_data.evals` does not index it using `commitment_data.point_indices`. After the bugfix (which changed the default `commitment_data.evals` entries to `None` internally), this would have resulted in a panic at the end of `construct_intermediate_sets` (which expects all evaluations to be provided). We now directly initialize `commitment_data.evals` to the correct length.
1 parent dfe9fc1 commit d31eecf

File tree

1 file changed

+3
-5
lines changed

1 file changed

+3
-5
lines changed

halo2_proofs/src/poly/multiopen.rs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -190,23 +190,21 @@ where
190190
// Also construct mapping from commitment to point_idx_set
191191
let mut commitment_set_map = IndexMap::new();
192192

193-
for (commitment, commitment_data) in commitment_map.iter() {
193+
for (commitment, commitment_data) in commitment_map.iter_mut() {
194194
let mut point_index_set = BTreeSet::new();
195195
// Note that point_index_set is ordered, unlike point_indices
196196
for &point_index in commitment_data.point_indices.iter() {
197197
point_index_set.insert(point_index);
198198
}
199+
let len = point_index_set.len();
199200

200201
// Push point_index_set to CommitmentData for the relevant commitment
201202
commitment_set_map.insert(*commitment, point_index_set.clone());
202203

203204
let num_sets = point_idx_sets.len();
204205
point_idx_sets.entry(point_index_set).or_insert(num_sets);
205-
}
206206

207-
// Initialise empty evals vec for each unique commitment
208-
for commitment_data in commitment_map.values_mut() {
209-
let len = commitment_data.point_indices.len();
207+
// Initialise empty evals vec for each unique commitment
210208
commitment_data.evals = vec![None; len];
211209
}
212210

0 commit comments

Comments
 (0)