Skip to content

Commit

Permalink
fix: dynamic dory gpu implementation should handle empty sub commits
Browse files Browse the repository at this point in the history
* tests are added to check when there are no sub commits
  • Loading branch information
jacobtrombetta committed Oct 14, 2024
1 parent 7c2ecd7 commit 922fb26
Show file tree
Hide file tree
Showing 3 changed files with 80 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -328,6 +328,36 @@ fn we_can_compute_an_empty_dory_commitment() {
assert_eq!(res[0].0, GT::zero());
let res = compute_dory_commitments(&[CommittableColumn::BigInt(&[0; 0])], 20, &setup);
assert_eq!(res[0].0, GT::zero());
let res = compute_dory_commitments(
&[
CommittableColumn::BigInt(&[0; 0]),
CommittableColumn::BigInt(&[0; 0]),
],
0,
&setup,
);
assert_eq!(res[0].0, GT::zero());
assert_eq!(res[1].0, GT::zero());
let res = compute_dory_commitments(
&[
CommittableColumn::BigInt(&[0; 0]),
CommittableColumn::BigInt(&[0; 0]),
],
5,
&setup,
);
assert_eq!(res[0].0, GT::zero());
assert_eq!(res[1].0, GT::zero());
let res = compute_dory_commitments(
&[
CommittableColumn::BigInt(&[0; 0]),
CommittableColumn::BigInt(&[0; 0]),
],
20,
&setup,
);
assert_eq!(res[0].0, GT::zero());
assert_eq!(res[1].0, GT::zero());
}

#[test]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -291,15 +291,26 @@ pub(super) fn compute_dynamic_dory_commitments(

// Calculate the dynamic Dory commitments.
let span = span!(Level::INFO, "multi_pairing").entered();
let ddc: Vec<DynamicDoryCommitment> = (0..committable_columns.len())
.map(|i| {
let sub_slice = signed_sub_commits[i..]
.iter()
.step_by(committable_columns.len())
.take(num_commits);
DynamicDoryCommitment(pairings::multi_pairing(sub_slice, &Gamma_2[..num_commits]))
})
.collect();
let ddc: Vec<DynamicDoryCommitment> = signed_sub_commits
.is_empty()
.then_some(vec![
DynamicDoryCommitment::default();
committable_columns.len()
])
.unwrap_or_else(|| {
(0..committable_columns.len())
.map(|i| {
let sub_slice = signed_sub_commits[i..]
.iter()
.step_by(committable_columns.len())
.take(num_commits);
DynamicDoryCommitment(pairings::multi_pairing(
sub_slice,
&Gamma_2[..num_commits],
))
})
.collect()
});
span.exit();

ddc
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,36 @@ fn we_can_compute_an_empty_dynamic_dory_commitment() {
assert_eq!(res[0].0, GT::zero());
let res = compute_dynamic_dory_commitments(&[CommittableColumn::BigInt(&[0; 0])], 20, &setup);
assert_eq!(res[0].0, GT::zero());
let res = compute_dynamic_dory_commitments(
&[
CommittableColumn::BigInt(&[0; 0]),
CommittableColumn::BigInt(&[0; 0]),
],
0,
&setup,
);
assert_eq!(res[0].0, GT::zero());
assert_eq!(res[1].0, GT::zero());
let res = compute_dynamic_dory_commitments(
&[
CommittableColumn::BigInt(&[0; 0]),
CommittableColumn::BigInt(&[0; 0]),
],
5,
&setup,
);
assert_eq!(res[0].0, GT::zero());
assert_eq!(res[1].0, GT::zero());
let res = compute_dynamic_dory_commitments(
&[
CommittableColumn::BigInt(&[0; 0]),
CommittableColumn::BigInt(&[0; 0]),
],
20,
&setup,
);
assert_eq!(res[0].0, GT::zero());
assert_eq!(res[1].0, GT::zero());
}

#[test]
Expand Down

0 comments on commit 922fb26

Please sign in to comment.