Skip to content

Commit

Permalink
Merge branch 'main' into c-p-fix-8
Browse files Browse the repository at this point in the history
  • Loading branch information
JayWhite2357 authored Oct 7, 2024
2 parents ef87bb4 + a32364a commit 6aaf148
Show file tree
Hide file tree
Showing 26 changed files with 63 additions and 50 deletions.
2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -81,3 +81,5 @@ cloned_instead_of_copied = "deny"
from_iter_instead_of_collect = "deny"
cast_lossless = "deny"
redundant_closure_for_method_calls = "deny"
inconsistent_struct_constructor = "deny"
default_trait_access = "deny"
3 changes: 2 additions & 1 deletion crates/proof-of-sql/examples/posql_db/commit_accessor.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use core::error::Error;
use indexmap::IndexMap;
use proof_of_sql::base::{
commitment::{Commitment, QueryCommitments, TableCommitment},
database::{CommitmentAccessor, MetadataAccessor, SchemaAccessor, TableRef},
Expand All @@ -13,7 +14,7 @@ impl<C: Commitment + Serialize + for<'a> Deserialize<'a>> CommitAccessor<C> {
pub fn new(base_path: PathBuf) -> Self {
Self {
base_path,
inner: Default::default(),
inner: IndexMap::default(),
}
}
pub fn write_commit(
Expand Down
2 changes: 1 addition & 1 deletion crates/proof-of-sql/examples/posql_db/csv_accessor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ impl CsvDataAccessor {
pub fn new(base_path: PathBuf) -> Self {
Self {
base_path,
inner: Default::default(),
inner: RecordBatchAccessor::default(),
}
}
pub fn load_table(
Expand Down
4 changes: 2 additions & 2 deletions crates/proof-of-sql/src/base/commitment/column_commitments.rs
Original file line number Diff line number Diff line change
Expand Up @@ -272,8 +272,8 @@ impl<C: Commitment> ColumnCommitments<C> {
.expect("we've already checked that self and other have equal column counts");

Ok(ColumnCommitments {
column_metadata,
commitments,
column_metadata,
})
}

Expand All @@ -293,8 +293,8 @@ impl<C: Commitment> ColumnCommitments<C> {
.expect("we've already checked that self and other have equal column counts");

Ok(ColumnCommitments {
column_metadata,
commitments,
column_metadata,
})
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ impl CommitmentEvaluationProof for InnerProductProof {
_setup: &Self::ProverPublicSetup<'_>,
) -> Self {
assert!(!a.is_empty());
let b = &mut vec![Default::default(); a.len()];
let b = &mut vec![MontScalar::default(); a.len()];
if b_point.is_empty() {
assert_eq!(b.len(), 1);
b[0] = Self::Scalar::ONE;
Expand Down Expand Up @@ -124,7 +124,7 @@ impl CommitmentEvaluationProof for InnerProductProof {
_setup: &Self::VerifierPublicSetup<'_>,
) -> Result<(), Self::Error> {
assert!(table_length > 0);
let b = &mut vec![Default::default(); table_length];
let b = &mut vec![MontScalar::default(); table_length];
if b_point.is_empty() {
assert_eq!(b.len(), 1);
b[0] = Self::Scalar::ONE;
Expand All @@ -140,7 +140,7 @@ impl CommitmentEvaluationProof for InnerProductProof {
.iter()
.zip(batching_factors.iter())
.map(|(c, m)| *m * c)
.fold(Default::default(), |mut a, c| {
.fold(RistrettoPoint::default(), |mut a, c| {
a += c;
a
}),
Expand Down
5 changes: 4 additions & 1 deletion crates/proof-of-sql/src/base/commitment/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,11 @@ impl Commitment for RistrettoPoint {
offset: usize,
_setup: &Self::PublicSetup<'_>,
) -> Vec<Self> {
use curve25519_dalek::ristretto::CompressedRistretto;

let sequences: Vec<_> = committable_columns.iter().map(Into::into).collect();
let mut compressed_commitments = vec![Default::default(); committable_columns.len()];
let mut compressed_commitments =
vec![CompressedRistretto::default(); committable_columns.len()];
blitzar::compute::compute_curve25519_commitments(
&mut compressed_commitments,
&sequences,
Expand Down
2 changes: 1 addition & 1 deletion crates/proof-of-sql/src/base/database/column.rs
Original file line number Diff line number Diff line change
Expand Up @@ -515,8 +515,8 @@ impl ColumnRef {
pub fn new(table_ref: TableRef, column_id: Identifier, column_type: ColumnType) -> Self {
Self {
column_id,
column_type,
table_ref,
column_type,
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ pub struct OwnedTableTestAccessor<'a, CP: CommitmentEvaluationProof> {
impl<CP: CommitmentEvaluationProof> Default for OwnedTableTestAccessor<'_, CP> {
fn default() -> Self {
Self {
tables: Default::default(),
tables: IndexMap::default(),
alloc: Bump::new(),
setup: None,
}
Expand All @@ -43,7 +43,7 @@ impl<CP: CommitmentEvaluationProof> TestAccessor<CP::Commitment>
type Table = OwnedTable<CP::Scalar>;

fn new_empty() -> Self {
Default::default()
OwnedTableTestAccessor::default()
}

fn add_table(&mut self, table_ref: TableRef, data: Self::Table, table_offset: usize) {
Expand Down
2 changes: 1 addition & 1 deletion crates/proof-of-sql/src/base/database/test_accessor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ impl TestAccessor<RistrettoPoint> for UnimplementedTestAccessor {
type Table = ();

fn new_empty() -> Self {
Default::default()
UnimplementedTestAccessor
}

fn add_table(&mut self, _table_ref: TableRef, _data: (), _table_offset: usize) {
Expand Down
2 changes: 1 addition & 1 deletion crates/proof-of-sql/src/base/scalar/mont_scalar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ impl<T: MontConfig<4>> PartialEq for MontScalar<T> {
}
impl<T: MontConfig<4>> Default for MontScalar<T> {
fn default() -> Self {
Self(Default::default())
Self(Fp::default())
}
}
impl<T: MontConfig<4>> Debug for MontScalar<T> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,12 @@ pub(super) fn build_vmv_prover_state(
VMVProverState {
v_vec,
T_vec_prime,
L_vec,
R_vec,
#[cfg(test)]
l_tensor,
#[cfg(test)]
r_tensor,
L_vec,
R_vec,
nu,
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,19 +44,19 @@ impl CommitmentEvaluationProof for DoryEvaluationProof {
if generators_offset != 0 {
// TODO: support offsets other than 0.
// Note: this will always result in a verification error.
return Default::default();
return DoryMessages::default();
}
let a: &[F] = bytemuck::TransparentWrapper::peel_slice(a);
let b_point: &[F] = bytemuck::TransparentWrapper::peel_slice(b_point);
let prover_setup = setup.prover_setup();
let nu = compute_nu(b_point.len(), setup.sigma());
if nu > prover_setup.max_nu {
return Default::default(); // Note: this will always result in a verification error.
return DoryMessages::default(); // Note: this will always result in a verification error.
}
let T_vec_prime = compute_T_vec_prime(a, setup.sigma(), nu, prover_setup);
let state = build_vmv_prover_state(a, b_point, T_vec_prime, setup.sigma(), nu);

let mut messages = Default::default();
let mut messages = DoryMessages::default();
let extended_state = eval_vmv_re_prove(&mut messages, transcript, state, prover_setup);
extended_dory_inner_product_prove(&mut messages, transcript, extended_state, prover_setup);
messages
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,7 @@ pub(super) fn compute_l_r_tensors(b_point: &[F], sigma: usize, nu: usize) -> (Ve
#[cfg(test)]
mod tests {
use super::*;
use ark_ff::Fp;
use ark_std::UniformRand;
use core::iter::repeat_with;

Expand All @@ -163,7 +164,7 @@ mod tests {
}
/// This is the naive inner product. It is used to check the correctness of the `compute_LMR` method.
fn compute_ab_inner_product(a: &[F], b_point: &[F]) -> F {
let mut b = vec![Default::default(); a.len()];
let mut b = vec![Fp::default(); a.len()];
compute_evaluation_vector(&mut b, b_point);
a.iter().zip(b.iter()).map(|(a, b)| a * b).sum()
}
Expand All @@ -177,8 +178,8 @@ mod tests {
assert_eq!(LMR, ab);
}
fn check_L_R_vecs_with_l_r_tensors(L: &[F], R: &[F], l: &[F], r: &[F]) {
let mut l_vec = vec![Default::default(); 1 << l.len()];
let mut r_vec = vec![Default::default(); 1 << r.len()];
let mut l_vec = vec![Fp::default(); 1 << l.len()];
let mut r_vec = vec![Fp::default(); 1 << r.len()];
compute_evaluation_vector(&mut l_vec, l);
compute_evaluation_vector(&mut r_vec, r);
assert_eq!(l_vec, L);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,18 +46,18 @@ impl CommitmentEvaluationProof for DynamicDoryEvaluationProof {
if generators_offset != 0 {
// TODO: support offsets other than 0.
// Note: this will always result in a verification error.
return Default::default();
return DynamicDoryEvaluationProof::default();
}
let a: &[F] = bytemuck::TransparentWrapper::peel_slice(a);
let b_point: &[F] = bytemuck::TransparentWrapper::peel_slice(b_point);
let nu = compute_dynamic_nu(b_point.len());
if nu > setup.max_nu {
return Default::default(); // Note: this will always result in a verification error.
return DynamicDoryEvaluationProof::default(); // Note: this will always result in a verification error.
}
let T_vec_prime = compute_dynamic_T_vec_prime(a, nu, setup);
let state = build_dynamic_vmv_prover_state(a, b_point, T_vec_prime, nu);

let mut messages = Default::default();
let mut messages = DoryMessages::default();
let extended_state = eval_vmv_re_prove(&mut messages, transcript, state, setup);
extended_dory_inner_product_prove(&mut messages, transcript, extended_state, setup);
Self(messages)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ mod tests {
D_2: DeferredMSM::new([], []),
nu,
},
s2_tensor: Default::default(),
s2_tensor: Vec::default(),
};
let (lo_fold, hi_fold) = fold_dynamic_tensors(&state);

Expand Down
13 changes: 7 additions & 6 deletions crates/proof-of-sql/src/proof_primitive/dory/extended_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ use super::{G1Affine, G1Projective, G2Projective, ProverSetup};
use alloc::{vec, vec::Vec};
#[cfg(test)]
use ark_ec::VariableBaseMSM;
use ark_ff::Fp;

/// The state of the prover during the Dory proof generation with the extended algorithm.
/// `base_state` is the state of the prover during the Dory proof generation with the original algorithm.
Expand Down Expand Up @@ -53,8 +54,8 @@ impl ExtendedProverState {
use crate::base::polynomial::compute_evaluation_vector;
assert_eq!(s1_tensor.len(), nu);
assert_eq!(s2_tensor.len(), nu);
let mut s1 = vec![Default::default(); 1 << nu];
let mut s2 = vec![Default::default(); 1 << nu];
let mut s1 = vec![Fp::default(); 1 << nu];
let mut s2 = vec![Fp::default(); 1 << nu];
compute_evaluation_vector(&mut s1, &s1_tensor);
compute_evaluation_vector(&mut s2, &s2_tensor);
ExtendedProverState {
Expand All @@ -80,8 +81,8 @@ impl ExtendedProverState {
E_2: E_2.into(),
s1_tensor: self.s1_tensor.clone(),
s2_tensor: self.s2_tensor.clone(),
alphas: vec![Default::default(); self.base_state.nu],
alpha_invs: vec![Default::default(); self.base_state.nu],
alphas: vec![Fp::default(); self.base_state.nu],
alpha_invs: vec![Fp::default(); self.base_state.nu],
}
}
}
Expand Down Expand Up @@ -127,8 +128,8 @@ impl ExtendedVerifierState {
E_2,
s1_tensor,
s2_tensor,
alphas: vec![Default::default(); nu],
alpha_invs: vec![Default::default(); nu],
alphas: vec![Fp::default(); nu],
alpha_invs: vec![Fp::default(); nu],
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use super::{
};
use crate::base::polynomial::compute_evaluation_vector;
use ark_ec::{pairing::Pairing, VariableBaseMSM};
use ark_ff::Fp;

#[test]
pub fn we_can_create_an_extended_verifier_state_from_an_extended_prover_state() {
Expand All @@ -14,8 +15,8 @@ pub fn we_can_create_an_extended_verifier_state_from_an_extended_prover_state()
for nu in 0..max_nu {
let (v1, v2) = rand_G_vecs(nu, &mut rng);
let (s1_tensor, s2_tensor) = rand_F_tensors(nu, &mut rng);
let mut s1 = vec![Default::default(); 1 << nu];
let mut s2 = vec![Default::default(); 1 << nu];
let mut s1 = vec![Fp::default(); 1 << nu];
let mut s2 = vec![Fp::default(); 1 << nu];
compute_evaluation_vector(&mut s1, &s1_tensor);
compute_evaluation_vector(&mut s2, &s2_tensor);
let extended_prover_state = ExtendedProverState::new_from_tensors(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,10 @@ impl PublicParameters {
Self {
Gamma_1,
Gamma_2,
max_nu,
H_1,
H_2,
Gamma_2_fin,
max_nu,
}
}
}
9 changes: 5 additions & 4 deletions crates/proof-of-sql/src/proof_primitive/dory/vmv_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,17 +92,18 @@ impl VMV {
nu: usize,
) -> Self {
use crate::base::polynomial::compute_evaluation_vector;
use ark_ff::Fp;

let mut L = vec![Default::default(); 1 << l_tensor.len()];
let mut R = vec![Default::default(); 1 << r_tensor.len()];
let mut L = vec![Fp::default(); 1 << l_tensor.len()];
let mut R = vec![Fp::default(); 1 << r_tensor.len()];
compute_evaluation_vector(&mut L, &l_tensor);
compute_evaluation_vector(&mut R, &r_tensor);
Self {
M,
L,
R,
l_tensor,
r_tensor,
L,
R,
nu,
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use super::test_cases::sumcheck_test_cases;
use crate::base::{
polynomial::{CompositePolynomial, CompositePolynomialInfo},
proof::Transcript as _,
scalar::{test_scalar::TestScalar, Curve25519Scalar, Scalar},
scalar::{test_scalar::TestScalar, Curve25519Scalar, MontScalar, Scalar},
};
/*
* Adopted from arkworks
Expand Down Expand Up @@ -168,7 +168,7 @@ fn we_can_verify_many_random_test_cases() {

for test_case in sumcheck_test_cases::<TestScalar>(&mut rng) {
let mut transcript = Transcript::new(b"sumchecktest");
let mut evaluation_point = vec![Default::default(); test_case.num_vars];
let mut evaluation_point = vec![MontScalar::default(); test_case.num_vars];
let proof = SumcheckProof::create(
&mut transcript,
&mut evaluation_point,
Expand Down
2 changes: 1 addition & 1 deletion crates/proof-of-sql/src/sql/proof/count_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ impl<'a> CountBuilder<'a> {
pub fn new(bit_distributions: &'a [BitDistribution]) -> Self {
Self {
bit_distributions,
counts: Default::default(),
counts: ProofCounts::default(),
}
}

Expand Down
2 changes: 1 addition & 1 deletion crates/proof-of-sql/src/sql/proof/indexes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ pub enum Indexes {

impl Default for Indexes {
fn default() -> Self {
Self::Sparse(Default::default())
Self::Sparse(Vec::default())
}
}

Expand Down
7 changes: 5 additions & 2 deletions crates/proof-of-sql/src/sql/proof/indexes_test.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
use super::Indexes;
use crate::base::{polynomial::compute_evaluation_vector, scalar::Curve25519Scalar};
use crate::base::{
polynomial::compute_evaluation_vector,
scalar::{Curve25519Scalar, MontScalar},
};
use num_traits::Zero;

#[test]
Expand Down Expand Up @@ -169,7 +172,7 @@ fn we_can_evaluate_indexes_at_an_evaluation_point() {
Curve25519Scalar::from(5u64),
Curve25519Scalar::from(7u64),
];
let mut evaluation_vector = vec![Default::default(); 8];
let mut evaluation_vector = vec![MontScalar::default(); 8];
compute_evaluation_vector(&mut evaluation_vector, &evaluation_point);

let ix = Indexes::Sparse(vec![0, 1, 1]);
Expand Down
Loading

0 comments on commit 6aaf148

Please sign in to comment.