From 922fb26f5b0c9959737901db3eb36ac796320661 Mon Sep 17 00:00:00 2001 From: Jacob Trombetta Date: Mon, 14 Oct 2024 10:21:08 -0400 Subject: [PATCH] fix: dynamic dory gpu implementation should handle empty sub commits * tests are added to check when there are no sub commits --- .../dory/dory_compute_commitments_test.rs | 30 +++++++++++++++++++ .../dynamic_dory_commitment_helper_gpu.rs | 29 ++++++++++++------ .../dynamic_dory_compute_commitments_test.rs | 30 +++++++++++++++++++ 3 files changed, 80 insertions(+), 9 deletions(-) diff --git a/crates/proof-of-sql/src/proof_primitive/dory/dory_compute_commitments_test.rs b/crates/proof-of-sql/src/proof_primitive/dory/dory_compute_commitments_test.rs index d2b09559b..b5f7a66e2 100644 --- a/crates/proof-of-sql/src/proof_primitive/dory/dory_compute_commitments_test.rs +++ b/crates/proof-of-sql/src/proof_primitive/dory/dory_compute_commitments_test.rs @@ -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] diff --git a/crates/proof-of-sql/src/proof_primitive/dory/dynamic_dory_commitment_helper_gpu.rs b/crates/proof-of-sql/src/proof_primitive/dory/dynamic_dory_commitment_helper_gpu.rs index b0aa4d0df..f6aa6fba2 100644 --- a/crates/proof-of-sql/src/proof_primitive/dory/dynamic_dory_commitment_helper_gpu.rs +++ b/crates/proof-of-sql/src/proof_primitive/dory/dynamic_dory_commitment_helper_gpu.rs @@ -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 = (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 = 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 diff --git a/crates/proof-of-sql/src/proof_primitive/dory/dynamic_dory_compute_commitments_test.rs b/crates/proof-of-sql/src/proof_primitive/dory/dynamic_dory_compute_commitments_test.rs index b6426efba..20519a74c 100644 --- a/crates/proof-of-sql/src/proof_primitive/dory/dynamic_dory_compute_commitments_test.rs +++ b/crates/proof-of-sql/src/proof_primitive/dory/dynamic_dory_compute_commitments_test.rs @@ -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]