diff --git a/crates/proof-of-sql/benches/README.md b/crates/proof-of-sql/benches/README.md index 4419dce19..8d7b58fcb 100644 --- a/crates/proof-of-sql/benches/README.md +++ b/crates/proof-of-sql/benches/README.md @@ -11,7 +11,8 @@ To run benchmarks with Jaeger, you need to do the following 2. Run a benchmark. ```bash cargo bench -p proof-of-sql --bench jaeger_benches InnerProductProof - cargo bench -p proof-of-sql --bench jaeger_benches Dory --features="test" + cargo bench -p proof-of-sql --bench jaeger_benches Dory + cargo bench -p proof-of-sql --bench jaeger_benches DynamicDory ``` 3. Navigate to http://localhost:16686/ to see the results. 4. To end the Jaeger service, run diff --git a/crates/proof-of-sql/benches/jaeger_benches.rs b/crates/proof-of-sql/benches/jaeger_benches.rs index f6e20bba7..77ac08288 100644 --- a/crates/proof-of-sql/benches/jaeger_benches.rs +++ b/crates/proof-of-sql/benches/jaeger_benches.rs @@ -3,17 +3,16 @@ //! ```bash //! docker run --rm -d --name jaeger -p 6831:6831/udp -p 16686:16686 jaegertracing/all-in-one:latest //! cargo bench -p proof-of-sql --bench jaeger_benches InnerProductProof -//! cargo bench -p proof-of-sql --bench jaeger_benches Dory --features="test" +//! cargo bench -p proof-of-sql --bench jaeger_benches Dory +//! cargo bench -p proof-of-sql --bench jaeger_benches DynamicDory //! ``` //! Then, navigate to to view the traces. -#[cfg(feature = "test")] use ark_std::test_rng; use blitzar::{compute::init_backend, proof::InnerProductProof}; -#[cfg(feature = "test")] use proof_of_sql::proof_primitive::dory::{ - DoryEvaluationProof, DoryProverPublicSetup, DoryVerifierPublicSetup, ProverSetup, - PublicParameters, VerifierSetup, + DoryEvaluationProof, DoryProverPublicSetup, DoryVerifierPublicSetup, + DynamicDoryEvaluationProof, ProverSetup, PublicParameters, VerifierSetup, }; mod scaffold; use crate::scaffold::querys::QUERIES; @@ -51,7 +50,6 @@ fn main() { } } } - #[cfg(feature = "test")] "Dory" => { // Run 3 times to ensure that warm-up of the GPU has occurred. let pp = PublicParameters::test_rand(10, &mut test_rng()); @@ -73,6 +71,25 @@ fn main() { } } } + "DynamicDory" => { + // Run 3 times to ensure that warm-up of the GPU has occurred. + let public_parameters = PublicParameters::test_rand(11, &mut test_rng()); + let prover_setup = ProverSetup::from(&public_parameters); + let verifier_setup = VerifierSetup::from(&public_parameters); + + for _ in 0..3 { + for (title, query, columns) in QUERIES { + jaeger_scaffold::( + title, + query, + columns, + SIZE, + &&prover_setup, + &&verifier_setup, + ); + } + } + } _ => panic!("Invalid benchmark type specified."), } diff --git a/crates/proof-of-sql/src/proof_primitive/dory/blitzar_metadata_table.rs b/crates/proof-of-sql/src/proof_primitive/dory/blitzar_metadata_table.rs index c4a0138cc..72e2ca8cb 100644 --- a/crates/proof-of-sql/src/proof_primitive/dory/blitzar_metadata_table.rs +++ b/crates/proof-of-sql/src/proof_primitive/dory/blitzar_metadata_table.rs @@ -1,5 +1,7 @@ use super::{ - dynamic_dory_structure::{full_width_of_row, index_from_row_and_column, matrix_size}, + dynamic_dory_structure::{ + full_width_of_row, index_from_row_and_column, matrix_size, row_and_column_from_index, + }, G1Affine, F, }; use crate::{ @@ -153,6 +155,10 @@ pub fn create_blitzar_metadata_tables( (0, 0) }; + // We will ignore the rows that are zero from the offsets. + let (offset_row, _) = row_and_column_from_index(offset); + let offset_height = max_height - offset_row; + // Find the single packed byte size of all committable columns. let num_of_bytes_in_committable_columns: usize = committable_columns .iter() @@ -171,7 +177,7 @@ pub fn create_blitzar_metadata_tables( .iter() .copied() .cycle() - .take(single_entry_in_blitzar_output_bit_table.len() * max_height) + .take(single_entry_in_blitzar_output_bit_table.len() * offset_height) .collect(); // Create the full length vector to be used by Blitzar's vlen_msm algorithm. @@ -179,7 +185,7 @@ pub fn create_blitzar_metadata_tables( / single_entry_in_blitzar_output_bit_table.len()) .flat_map(|i| { itertools::repeat_n( - full_width_of_row(i) as u32, + full_width_of_row(i + offset_row) as u32, single_entry_in_blitzar_output_bit_table.len(), ) }) @@ -196,7 +202,7 @@ pub fn create_blitzar_metadata_tables( // Create scalars array. Note, scalars need to be stored in a column-major order. let num_scalar_rows = max_width; let num_scalar_columns = - (num_of_bytes_in_committable_columns + ones_columns_lengths.len()) * max_height; + (num_of_bytes_in_committable_columns + ones_columns_lengths.len()) * offset_height; let mut blitzar_scalars = vec![0u8; num_scalar_rows * num_scalar_columns]; // Populate the scalars array. @@ -207,12 +213,14 @@ pub fn create_blitzar_metadata_tables( .enumerate() .for_each(|(scalar_row, scalar_row_slice)| { // Iterate over the columns and populate the scalars array. - for scalar_col in 0..max_height { + for scalar_col in 0..offset_height { // Find index in the committable columns. Note, the scalar is in // column major order, that is why the (row, col) arguments are flipped. - if let Some(index) = index_from_row_and_column(scalar_col, scalar_row).and_then( - |committable_column_idx| committable_column_idx.checked_sub(offset), - ) { + if let Some(index) = + index_from_row_and_column(scalar_col + offset_row, scalar_row).and_then( + |committable_column_idx| committable_column_idx.checked_sub(offset), + ) + { for (i, committable_column) in committable_columns .iter() .enumerate() @@ -264,60 +272,330 @@ mod tests { use crate::base::math::decimal::Precision; use proof_of_sql_parser::posql_time::{PoSQLTimeUnit, PoSQLTimeZone}; - #[test] - fn we_can_populate_blitzar_metadata_tables_with_empty_columns() { - let committable_columns = [CommittableColumn::BigInt(&[0; 0])]; - let offset = 0; + fn assert_blitzar_metadata( + committable_columns: &[CommittableColumn], + offset: usize, + expected_bit_table: &[u32], + expected_length_table: &[u32], + expected_scalars: &[u8], + ) { let (bit_table, length_table, scalars) = - create_blitzar_metadata_tables(&committable_columns, offset); + create_blitzar_metadata_tables(committable_columns, offset); - assert!(bit_table.is_empty()); - assert!(length_table.is_empty()); - assert!(scalars.is_empty()); + assert_eq!( + bit_table, expected_bit_table, + "Bit table mismatch for offset {offset}" + ); + assert_eq!( + length_table, expected_length_table, + "Length table mismatch for offset {offset}" + ); + assert_eq!( + scalars, expected_scalars, + "Scalars mismatch for offset {offset}" + ); } #[test] - fn we_can_populate_blitzar_metadata_tables_with_empty_columns_and_an_offset() { + fn we_can_populate_blitzar_metadata_tables_with_empty_columns_and_offset_that_fills_row() { let committable_columns = [CommittableColumn::BigInt(&[0; 0])]; - let offset = 1; - let (bit_table, length_table, scalars) = - create_blitzar_metadata_tables(&committable_columns, offset); + let offsets = vec![ + 0, 1, 2, 4, 8, 12, 16, 24, 32, 40, 48, 56, 64, 80, 96, 112, 128, + ]; + for &offset in &offsets { + assert_blitzar_metadata(&committable_columns, offset, &[], &[], &[]); + } + } - assert_eq!(bit_table, vec![64, 8]); - assert_eq!(length_table, vec![1, 1]); - assert_eq!(scalars, vec![0, 0, 0, 0, 0, 0, 0, 0, 0]); + #[test] + fn we_can_populate_blitzar_metadata_tables_with_empty_columns_and_offset_that_does_not_fill_row( + ) { + let committable_columns = [CommittableColumn::BigInt(&[0; 0])]; + + let offset = 3; + assert_blitzar_metadata( + &committable_columns, + offset, + &[64, 8], + &[2, 2], + &[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], + ); + + let offset = 5; + assert_blitzar_metadata( + &committable_columns, + offset, + &[64, 8], + &[4, 4], + &[ + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, + ], + ); + + let offset = 17; + assert_blitzar_metadata( + &committable_columns, + offset, + &[64, 8], + &[8, 8], + &[ + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + ], + ); + + let offset = 65; + assert_blitzar_metadata( + &committable_columns, + offset, + &[64, 8], + &[16, 16], + &[ + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, + ], + ); } #[test] fn we_can_populate_blitzar_metadata_tables_with_simple_column() { let committable_columns = [CommittableColumn::BigInt(&[1])]; - let offset = 0; - let (bit_table, length_table, scalars) = - create_blitzar_metadata_tables(&committable_columns, offset); - assert_eq!(bit_table, vec![64, 8]); - assert_eq!(length_table, vec![1, 1]); - assert_eq!(scalars, vec![1, 0, 0, 0, 0, 0, 0, 128, 1]); + let offset = 0; + assert_blitzar_metadata( + &committable_columns, + offset, + &[64, 8], + &[1, 1], + &[1, 0, 0, 0, 0, 0, 0, 128, 1], + ); } #[test] fn we_can_populate_blitzar_metadata_tables_with_simple_column_and_offset() { let committable_columns = [CommittableColumn::BigInt(&[1])]; + let offset = 1; - let (bit_table, length_table, scalars) = - create_blitzar_metadata_tables(&committable_columns, offset); + assert_blitzar_metadata( + &committable_columns, + offset, + &[64, 8], + &[2, 2], + &[0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 128, 1], + ); + } - assert_eq!(bit_table, vec![64, 8, 64, 8]); - assert_eq!(length_table, vec![1, 1, 2, 2]); - assert_eq!( - scalars, - vec![ - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, - 0, 0, 0, 0, 0, 0, 128, 1 - ] + #[test] + fn we_can_populate_blitzar_metadata_tables_with_simple_column_and_non_trivial_offsets() { + let committable_columns = [CommittableColumn::TinyInt(&[1])]; + + let expected_bit_table = vec![8, 8]; + + let offset = 0; + assert_blitzar_metadata( + &committable_columns, + offset, + &expected_bit_table, + &[1, 1], + &[129, 1], + ); + + let offset = 1; + assert_blitzar_metadata( + &committable_columns, + offset, + &expected_bit_table, + &[2, 2], + &[0, 0, 129, 1], + ); + + let offset = 2; + assert_blitzar_metadata( + &committable_columns, + offset, + &expected_bit_table, + &[2, 2], + &[129, 1, 0, 0], + ); + + let offset = 3; + assert_blitzar_metadata( + &committable_columns, + offset, + &expected_bit_table, + &[2, 2], + &[0, 0, 129, 1], ); } + #[test] + fn we_can_populate_blitzar_metadata_tables_with_simple_column_and_offsets_with_4_columns() { + let committable_columns = [CommittableColumn::TinyInt(&[1])]; + + let expected_bit_table = vec![8, 8]; + let expected_length_table = vec![4, 4]; + + let offsets = vec![4, 8, 12]; + for &offset in &offsets { + assert_blitzar_metadata( + &committable_columns, + offset, + &expected_bit_table, + &expected_length_table, + &[129, 1, 0, 0, 0, 0, 0, 0], + ); + + assert_blitzar_metadata( + &committable_columns, + offset + 1, + &expected_bit_table, + &expected_length_table, + &[0, 0, 129, 1, 0, 0, 0, 0], + ); + + assert_blitzar_metadata( + &committable_columns, + offset + 2, + &expected_bit_table, + &expected_length_table, + &[0, 0, 0, 0, 129, 1, 0, 0], + ); + + assert_blitzar_metadata( + &committable_columns, + offset + 3, + &expected_bit_table, + &expected_length_table, + &[0, 0, 0, 0, 0, 0, 129, 1], + ); + } + } + + #[test] + fn we_can_populate_blitzar_metadata_tables_with_simple_column_and_offsets_with_8_columns() { + let committable_columns = [CommittableColumn::TinyInt(&[1])]; + + let expected_bit_table = vec![8, 8]; + let expected_length_table = vec![8, 8]; + + let offsets = vec![16, 24, 32, 40, 48, 56]; + for &offset in &offsets { + assert_blitzar_metadata( + &committable_columns, + offset, + &expected_bit_table, + &expected_length_table, + &[129, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], + ); + + assert_blitzar_metadata( + &committable_columns, + offset + 1, + &expected_bit_table, + &expected_length_table, + &[0, 0, 129, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], + ); + + assert_blitzar_metadata( + &committable_columns, + offset + 2, + &expected_bit_table, + &expected_length_table, + &[0, 0, 0, 0, 129, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], + ); + + assert_blitzar_metadata( + &committable_columns, + offset + 3, + &expected_bit_table, + &expected_length_table, + &[0, 0, 0, 0, 0, 0, 129, 1, 0, 0, 0, 0, 0, 0, 0, 0], + ); + + assert_blitzar_metadata( + &committable_columns, + offset + 4, + &expected_bit_table, + &expected_length_table, + &[0, 0, 0, 0, 0, 0, 0, 0, 129, 1, 0, 0, 0, 0, 0, 0], + ); + + assert_blitzar_metadata( + &committable_columns, + offset + 5, + &expected_bit_table, + &expected_length_table, + &[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 129, 1, 0, 0, 0, 0], + ); + + assert_blitzar_metadata( + &committable_columns, + offset + 6, + &expected_bit_table, + &expected_length_table, + &[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 129, 1, 0, 0], + ); + + assert_blitzar_metadata( + &committable_columns, + offset + 7, + &expected_bit_table, + &expected_length_table, + &[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 129, 1], + ); + } + } + + #[test] + fn we_can_populate_blitzar_metadata_tables_with_simple_column_and_offsets_with_16_columns() { + let committable_columns = [CommittableColumn::TinyInt(&[1])]; + + let expected_bit_table = vec![8, 8]; + let expected_length_table = vec![16, 16]; + + let offsets = vec![64, 80, 96, 112]; + for &offset in &offsets { + assert_blitzar_metadata( + &committable_columns, + offset, + &expected_bit_table, + &expected_length_table, + &[ + 129, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + ], + ); + + assert_blitzar_metadata( + &committable_columns, + offset + 8, + &expected_bit_table, + &expected_length_table, + &[ + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 129, 1, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + ], + ); + + assert_blitzar_metadata( + &committable_columns, + offset + 15, + &expected_bit_table, + &expected_length_table, + &[ + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 129, 1, + ], + ); + } + } + #[test] fn we_can_populate_blitzar_metadata_tables_with_mixed_columns() { let committable_columns = [ @@ -334,27 +612,102 @@ mod tests { ]; let offset = 0; - let (bit_table, length_table, scalars) = - create_blitzar_metadata_tables(&committable_columns, offset); - assert_eq!( - bit_table, - vec![8, 16, 32, 64, 128, 256, 256, 256, 64, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8] + assert_blitzar_metadata( + &committable_columns, + offset, + &[ + 8, 16, 32, 64, 128, 256, 256, 256, 64, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, + ], + &[1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1], + &[ + 129, 2, 128, 3, 0, 0, 128, 4, 0, 0, 0, 0, 0, 0, 128, 5, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 128, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 7, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 8, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 9, 0, 0, 0, 0, 0, 0, 128, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + ], ); + } - assert_eq!( - length_table, - vec![1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1] - ); - assert_eq!( - scalars, - vec![ + #[test] + fn we_can_populate_blitzar_metadata_tables_with_mixed_columns_and_partial_column_offset() { + let committable_columns = [ + CommittableColumn::TinyInt(&[1]), + CommittableColumn::SmallInt(&[2]), + CommittableColumn::Int(&[3]), + CommittableColumn::BigInt(&[4]), + CommittableColumn::Int128(&[5]), + CommittableColumn::Decimal75(Precision::new(1).unwrap(), 0, vec![[6, 0, 0, 0]]), + CommittableColumn::Scalar(vec![[7, 0, 0, 0]]), + CommittableColumn::VarChar(vec![[8, 0, 0, 0]]), + CommittableColumn::TimestampTZ(PoSQLTimeUnit::Second, PoSQLTimeZone::Utc, &[9]), + CommittableColumn::Boolean(&[true]), + ]; + + let offsets = vec![1, 3]; + for &offset in &offsets { + assert_blitzar_metadata( + &committable_columns, + offset, + &[ + 8, 16, 32, 64, 128, 256, 256, 256, 64, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, + ], + &[2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2], + &[ + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 129, 2, 128, 3, 0, 0, 128, 4, + 0, 0, 0, 0, 0, 0, 128, 5, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 128, 6, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 7, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 8, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 9, 0, 0, 0, 0, 0, 0, 128, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, + ], + ); + } + } + + #[test] + fn we_can_populate_blitzar_metadata_tables_with_mixed_columns_and_full_column_offset() { + let committable_columns = [ + CommittableColumn::TinyInt(&[1]), + CommittableColumn::SmallInt(&[2]), + CommittableColumn::Int(&[3]), + CommittableColumn::BigInt(&[4]), + CommittableColumn::Int128(&[5]), + CommittableColumn::Decimal75(Precision::new(1).unwrap(), 0, vec![[6, 0, 0, 0]]), + CommittableColumn::Scalar(vec![[7, 0, 0, 0]]), + CommittableColumn::VarChar(vec![[8, 0, 0, 0]]), + CommittableColumn::TimestampTZ(PoSQLTimeUnit::Second, PoSQLTimeZone::Utc, &[9]), + CommittableColumn::Boolean(&[true]), + ]; + + let offset = 2; + assert_blitzar_metadata( + &committable_columns, + offset, + &[ + 8, 16, 32, 64, 128, 256, 256, 256, 64, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, + ], + &[2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2], + &[ 129, 2, 128, 3, 0, 0, 128, 4, 0, 0, 0, 0, 0, 0, 128, 5, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 128, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 7, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 8, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 9, 0, 0, 0, 0, 0, 0, 128, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 - ] + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + ], ); } } 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 4a1f10b86..7a5c8c022 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 @@ -1,5 +1,6 @@ use super::{ blitzar_metadata_table::{create_blitzar_metadata_tables, signed_commits}, + dynamic_dory_structure::row_and_column_from_index, pairings, DynamicDoryCommitment, G1Affine, ProverSetup, }; use crate::base::{commitment::CommittableColumn, slice_ops::slice_cast}; @@ -32,6 +33,7 @@ pub(super) fn compute_dynamic_dory_commitments( setup: &ProverSetup, ) -> Vec { let Gamma_2 = setup.Gamma_2.last().unwrap(); + let (gamma_2_offset, _) = row_and_column_from_index(offset); // Get metadata tables for Blitzar's vlen_msm algorithm. let (blitzar_output_bit_table, blitzar_output_length_table, blitzar_scalars) = @@ -75,7 +77,7 @@ pub(super) fn compute_dynamic_dory_commitments( .take(num_commits); DynamicDoryCommitment(pairings::multi_pairing( sub_slice, - &Gamma_2[..num_commits], + &Gamma_2[gamma_2_offset..gamma_2_offset + num_commits], )) }) .collect() diff --git a/crates/proof-of-sql/src/proof_primitive/dory/public_parameters.rs b/crates/proof-of-sql/src/proof_primitive/dory/public_parameters.rs index 032dee470..43c1e02d3 100644 --- a/crates/proof-of-sql/src/proof_primitive/dory/public_parameters.rs +++ b/crates/proof-of-sql/src/proof_primitive/dory/public_parameters.rs @@ -38,17 +38,16 @@ impl PublicParameters { pub fn rand(max_nu: usize, rng: &mut R) -> Self { Self::rand_impl(max_nu, rng) } - #[cfg(any(test, feature = "test"))] /// Generate random public parameters for testing. pub fn test_rand(max_nu: usize, rng: &mut R) -> Self { Self::rand_impl(max_nu, rng) } fn rand_impl(max_nu: usize, rng: &mut R) -> Self { + let (H_1, H_2) = (G1Affine::rand(rng), G2Affine::rand(rng)); + let Gamma_2_fin = G2Affine::rand(rng); let (Gamma_1, Gamma_2) = iter::repeat_with(|| (G1Affine::rand(rng), G2Affine::rand(rng))) .take(1 << max_nu) .unzip(); - let (H_1, H_2) = (G1Affine::rand(rng), G2Affine::rand(rng)); - let Gamma_2_fin = G2Affine::rand(rng); Self { Gamma_1,