Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ members = [
"proof-of-sql/on-chain-table",
"proof-of-sql/commitment-sql",
"proof-of-sql/static-setups",
"proof-of-sql/unchecked-deserialize",
"proof-of-sql/unversioned",
"native",
"native-api",
Expand Down Expand Up @@ -96,6 +97,7 @@ proof-of-sql-commitment-map = { path = "./proof-of-sql/commitment-map/", default
commitment-column-mapping = { path = "./proof-of-sql/commitment-column-mapping/", default-features = false }
proof-of-sql-static-setups = { path = "./proof-of-sql/static-setups/", default-features = false }
proof-of-sql-unversioned = { path = "./proof-of-sql/unversioned/", default-features = false }
proof-of-sql-unchecked-deserialize = { path = "./proof-of-sql/unchecked-deserialize/", default-features = false }
rand = { version = "0.8.5", default-features = false }
rand_chacha = { version = "0.3.1", default-features = false }
rayon = { version = "1.10.0" }
Expand Down Expand Up @@ -235,6 +237,7 @@ prometheus = "0.14.0"
proptest = { version = "1.7.0", default-features = false }
proptest-derive = { version = "0.6.0", default-features = false }
blake3 = { version = "1.6.1", default-features = false }
derive_more = { version = "0.99" }

[workspace.lints]
rust.missing_docs = "warn"
Expand Down
1 change: 1 addition & 0 deletions pallets/commitments/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ on-chain-table.workspace = true
proof-of-sql.workspace = true
proof-of-sql-commitment-map = { workspace = true, features = ["substrate"] }
proof-of-sql-static-setups = { workspace = true, features = ["baked"] }
proof-of-sql-unchecked-deserialize.workspace = true
sp-core.workspace = true
sp-api.workspace = true
sqlparser.workspace = true
Expand Down
23 changes: 21 additions & 2 deletions pallets/commitments/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -347,9 +347,28 @@ pub mod pallet {

let commitments_bytes = commitments_bytes.data;

let commitments = commitments_bytes
.try_into()
let PerCommitmentScheme {
hyper_kzg: maybe_hyper_kzg_commitment_bytes,
dynamic_dory: maybe_dynamic_dory_commitment_bytes,
} = commitments_bytes;
let maybe_hyper_kzg_commitment = maybe_hyper_kzg_commitment_bytes
.map(|hyper_kzg_commitment_bytes| (&hyper_kzg_commitment_bytes).try_into())
.transpose()
.map_err(|_| Error::DeserializeCommitment)?;
let maybe_dynamic_dory_commitment = maybe_dynamic_dory_commitment_bytes
.map(|dynamic_dory_commitment_bytes| (&dynamic_dory_commitment_bytes).try_into())
.transpose()
.map_err(|_| Error::DeserializeCommitment)?
.map(|unchecked_dynamic_dory_commitment| {
proof_of_sql_unchecked_deserialize::map_table_commitment(
&unchecked_dynamic_dory_commitment,
Into::into,
)
});
let commitments = PerCommitmentScheme {
hyper_kzg: maybe_hyper_kzg_commitment,
dynamic_dory: maybe_dynamic_dory_commitment,
};

let insert_with_meta_columns = insert_with_meta_columns_bytes
.try_into()
Expand Down
20 changes: 20 additions & 0 deletions proof-of-sql/unchecked-deserialize/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
[package]
name = "proof-of-sql-unchecked-deserialize"
version = "0.1.0"
license.workspace = true
authors.workspace = true
homepage.workspace = true
repository.workspace = true
edition.workspace = true

[dependencies]
proof-of-sql.workspace = true
ark-serialize.workspace = true
derive_more.workspace = true
serde.workspace = true

[lints]
workspace = true



2 changes: 2 additions & 0 deletions proof-of-sql/unchecked-deserialize/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# `proof-of-sql-unchecked-deserialize`
Utility for proof-of-sql that enables efficient deserialization (using no validation).
6 changes: 6 additions & 0 deletions proof-of-sql/unchecked-deserialize/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
//! This crate enables unchecked deserialization for certain types, in particular `TableCommitment<DynamicDoryCommitment>``.

mod unchecked_dynamic_dory_commitment;
pub use crate::unchecked_dynamic_dory_commitment::UncheckedDynamicDoryCommitment;
mod table_commitment_util;
pub use crate::table_commitment_util::map_table_commitment;
19 changes: 19 additions & 0 deletions proof-of-sql/unchecked-deserialize/src/table_commitment_util.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
//! Module containing utility functions `TableCommitment`s.

use proof_of_sql::base::commitment::{Commitment, TableCommitment};

/// Map a `TableCommitment<A>` to a `TableCommitment<B>` by applying `f` to each column commitment.
pub fn map_table_commitment<'a, A: Commitment, B: Commitment, F: Fn(&'a A) -> B>(
table_commitment: &'a TableCommitment<A>,
f: F,
) -> TableCommitment<B> {
TableCommitment::try_new(
table_commitment
.column_commitments()
.iter()
.map(|(i, m, c)| (i.clone(), *m, f(c)))
.collect(),
table_commitment.range().clone(),
)
.expect("range was cloned from existing commitment, so valid")
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
//! This module provides `UncheckedDynamicDoryCommitment`, a wrapper around `DynamicDoryCommitment` that allows for unchecked deserialization.

use core::ops::Mul;

use ark_serialize::{CanonicalDeserialize, CanonicalSerialize};
use derive_more::{AddAssign, Neg, Sub, SubAssign};
use proof_of_sql::base::commitment::{Commitment, CommittableColumn};
use proof_of_sql::proof_primitive::dory::{DoryScalar, DynamicDoryCommitment};

#[derive(
Debug,
Sub,
Eq,
PartialEq,
Neg,
Copy,
Clone,
AddAssign,
SubAssign,
CanonicalSerialize,
CanonicalDeserialize,
Default,
)]

/// A wrapper around `DynamicDoryCommitment` with unchecked deserialization.
/// Note: while it implements the `Commitment` trait, it does not actually implement its methods.
/// This should `only` be used for unchecked deserialization, and then converted to `DynamicDoryCommitment`.
pub struct UncheckedDynamicDoryCommitment(DynamicDoryCommitment);

impl From<UncheckedDynamicDoryCommitment> for DynamicDoryCommitment {
fn from(value: UncheckedDynamicDoryCommitment) -> Self {
value.0
}
}
impl From<&UncheckedDynamicDoryCommitment> for DynamicDoryCommitment {
fn from(value: &UncheckedDynamicDoryCommitment) -> Self {
value.0
}
}

impl serde::Serialize for UncheckedDynamicDoryCommitment {
fn serialize<S: serde::Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error> {
let mut bytes = Vec::with_capacity(CanonicalSerialize::compressed_size(self));
CanonicalSerialize::serialize_compressed(self, &mut bytes)
.map_err(serde::ser::Error::custom)?;
bytes.serialize(serializer)
}
}
impl<'de> serde::Deserialize<'de> for UncheckedDynamicDoryCommitment {
fn deserialize<D: serde::Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
CanonicalDeserialize::deserialize_compressed_unchecked(
Vec::deserialize(deserializer)?.as_slice(),
)
.map_err(serde::de::Error::custom)
}
}
impl Mul<UncheckedDynamicDoryCommitment> for DoryScalar {
type Output = UncheckedDynamicDoryCommitment;
fn mul(self, _rhs: UncheckedDynamicDoryCommitment) -> Self::Output {
unimplemented!()
}
}
impl Mul<&UncheckedDynamicDoryCommitment> for DoryScalar {
type Output = UncheckedDynamicDoryCommitment;
fn mul(self, _rhs: &UncheckedDynamicDoryCommitment) -> Self::Output {
unimplemented!()
}
}
impl Commitment for UncheckedDynamicDoryCommitment {
type Scalar = DoryScalar;
type PublicSetup<'a> = ();
fn compute_commitments(
_committable_columns: &[CommittableColumn],
_offset: usize,
_setup: &Self::PublicSetup<'_>,
) -> Vec<Self> {
unimplemented!()
}

fn to_transcript_bytes(&self) -> Vec<u8> {
unimplemented!()
}
}
Loading