From e5e13083d441dda11f99aa8956eb9d0cc9736963 Mon Sep 17 00:00:00 2001 From: "dustin.ray" Date: Mon, 21 Oct 2024 21:45:21 -0700 Subject: [PATCH 1/2] feat: proversetup fileio --- Cargo.toml | 2 +- .../proof_primitive/dory/public_parameters.rs | 1 + .../src/proof_primitive/dory/setup.rs | 35 +++++++++++++++++++ 3 files changed, 37 insertions(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index c1f8ad763..a0d8f7216 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -25,7 +25,7 @@ arrow-csv = { version = "51.0" } bit-iter = { version = "1.1.1" } bigdecimal = { version = "0.4.5", default-features = false, features = ["serde"] } blake3 = { version = "1.3.3", default-features = false } -blitzar = { version = "3.3.0" } +blitzar = { version = "3.4.0" } bumpalo = { version = "3.11.0" } bytemuck = {version = "1.16.3", features = ["derive"]} byte-slice-cast = { version = "1.2.1", default-features = false } 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 43c1e02d3..ae91923a9 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 @@ -18,6 +18,7 @@ use std::{ /// Note: even though `H_1` and `H_2` are marked as blue, they are still needed. /// /// Note: `Gamma_1_fin` is unused, so we leave it out. +#[derive(Clone)] pub struct PublicParameters { /// This is the vector of G1 elements that are used in the Dory protocol. That is, `Γ_1,0` in the Dory paper. pub(super) Gamma_1: Vec, diff --git a/crates/proof-of-sql/src/proof_primitive/dory/setup.rs b/crates/proof-of-sql/src/proof_primitive/dory/setup.rs index 4283fa7d5..ed394b094 100644 --- a/crates/proof-of-sql/src/proof_primitive/dory/setup.rs +++ b/crates/proof-of-sql/src/proof_primitive/dory/setup.rs @@ -66,6 +66,41 @@ impl<'a> ProverSetup<'a> { } } + /// Create a new `ProverSetup` from the public parameters and blitzar handle + /// # Panics + /// Panics if the length of `Gamma_1` or `Gamma_2` is not equal to `2^max_nu`. + #[must_use] + #[cfg(feature = "blitzar")] + pub fn from_public_parameters_and_blitzar_handle( + public_parameters: &'a PublicParameters, + blitzar_handle: blitzar::compute::MsmHandle< + blitzar::compute::ElementP2, + >, + ) -> Self { + let Gamma_1: &'a [G1Affine] = &public_parameters.Gamma_1; + let Gamma_2: &'a [G2Affine] = &public_parameters.Gamma_2; + let H_1 = public_parameters.H_1; + let H_2 = public_parameters.H_2; + let Gamma_2_fin = public_parameters.Gamma_2_fin; + let max_nu = public_parameters.max_nu; + assert_eq!(Gamma_1.len(), 1 << max_nu); + assert_eq!(Gamma_2.len(), 1 << max_nu); + + let (Gamma_1, Gamma_2): (Vec<_>, Vec<_>) = (0..=max_nu) + .map(|k| (&Gamma_1[..1 << k], &Gamma_2[..1 << k])) + .unzip(); + ProverSetup { + Gamma_1, + Gamma_2, + H_1, + H_2, + Gamma_2_fin, + max_nu, + #[cfg(feature = "blitzar")] + blitzar_handle, + } + } + #[cfg(feature = "blitzar")] #[tracing::instrument(name = "ProverSetup::blitzar_msm", level = "debug", skip_all)] pub(super) fn blitzar_msm( From df3d41589b32f8465ca732a755da8962ff9d1ac0 Mon Sep 17 00:00:00 2001 From: Dustin Ray <40841027+Dustin-Ray@users.noreply.github.com> Date: Tue, 22 Oct 2024 09:08:16 -0700 Subject: [PATCH 2/2] Update public_parameters.rs --- .../proof-of-sql/src/proof_primitive/dory/public_parameters.rs | 1 - 1 file changed, 1 deletion(-) 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 ae91923a9..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 @@ -18,7 +18,6 @@ use std::{ /// Note: even though `H_1` and `H_2` are marked as blue, they are still needed. /// /// Note: `Gamma_1_fin` is unused, so we leave it out. -#[derive(Clone)] pub struct PublicParameters { /// This is the vector of G1 elements that are used in the Dory protocol. That is, `Γ_1,0` in the Dory paper. pub(super) Gamma_1: Vec,