Skip to content

Commit

Permalink
feat!: put merlin behind feature (#180)
Browse files Browse the repository at this point in the history
# Rationale for this change

See #161 for rationale.

# What changes are included in this PR?

NOTE: the individual commits may be good to review individually

* `DoryMessages` accepts `impl Transcript` instead of
`merlin::Transcript`. This is a breaking change, making the proofs
non-backward compatible. The API deos not change.
* Changed `CommitmentEvaluationProof` to accept `impl Transcript` rather
than `merlin::Transcript`.
* Replaced `merlin::Transcript` with `Keccak256Transcript` within
`QueryProof`. Although the proof could be made generic, there is no real
use-case for `merlin`. In the future, we can easily support other
transcripts, but I think it is best to keep it concrete for now.
* Dropped dead code and renamed the old `merlin` module.
* Put `merlin` behind the `blitzar` feature flag since it is still
required for the `blitzar::InnerProductProof`.

* The tests are _NOT_ refactored to remove `merlin`. This can be done in
a separate PR.

# Are these changes tested?

Yes. Existing tests cover the changes.
  • Loading branch information
JayWhite2357 authored Sep 26, 2024
2 parents 3193fa0 + d59ec73 commit 057edde
Show file tree
Hide file tree
Showing 19 changed files with 145 additions and 435 deletions.
4 changes: 3 additions & 1 deletion crates/proof-of-sql/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ derive_more = { workspace = true }
indexmap = { workspace = true, features = ["serde"] }
itertools = { workspace = true }
lazy_static = { workspace = true }
merlin = { workspace = true }
merlin = { workspace = true, optional = true }
num-traits = { workspace = true }
num-bigint = { workspace = true, default-features = false }
postcard = { workspace = true, features = ["alloc"] }
Expand All @@ -58,6 +58,7 @@ blitzar = { workspace = true }
clap = { workspace = true, features = ["derive"] }
criterion = { workspace = true, features = ["html_reports"] }
# forge-script = { workspace = true }
merlin = { workspace = true }
opentelemetry = { workspace = true }
opentelemetry-jaeger = { workspace = true }
rand = { workspace = true, default-features = false }
Expand All @@ -75,6 +76,7 @@ development = ["arrow-csv"]
[features]
default = ["arrow", "blitzar", "rayon"]
arrow = ["dep:arrow"]
blitzar = ["dep:blitzar", "dep:merlin"]
test = ["dep:rand"]

[lints]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
use super::Commitment;
use crate::base::{proof::Transcript as _, scalar::Scalar};
use crate::base::{proof::Transcript, scalar::Scalar};
#[cfg(feature = "blitzar")]
use crate::base::{scalar::MontScalar, slice_ops};
#[cfg(feature = "blitzar")]
use blitzar::proof::{InnerProductProof, ProofError};
#[cfg(feature = "blitzar")]
use curve25519_dalek::RistrettoPoint;
use merlin::Transcript;
use serde::{Deserialize, Serialize};

/// A trait for using commitment schemes generically. Specifically, this trait is for the evaluation proof of a commitment scheme.
Expand All @@ -31,7 +30,7 @@ pub trait CommitmentEvaluationProof {
/// `b_point` are the values for the variables that are being evaluated.
/// The resulting evaluation is the the inner product of `a` and `b`, where `b` is the expanded vector form of `b_point`.
fn new(
transcript: &mut Transcript,
transcript: &mut impl Transcript,
a: &[Self::Scalar],
b_point: &[Self::Scalar],
generators_offset: u64,
Expand All @@ -45,7 +44,7 @@ pub trait CommitmentEvaluationProof {
#[allow(clippy::too_many_arguments)]
fn verify_proof(
&self,
transcript: &mut Transcript,
transcript: &mut impl Transcript,
a_commit: &Self::Commitment,
product: &Self::Scalar,
b_point: &[Self::Scalar],
Expand All @@ -68,7 +67,7 @@ pub trait CommitmentEvaluationProof {
#[allow(clippy::too_many_arguments)]
fn verify_batched_proof(
&self,
transcript: &mut Transcript,
transcript: &mut impl Transcript,
commit_batch: &[Self::Commitment],
batching_factors: &[Self::Scalar],
product: &Self::Scalar,
Expand All @@ -87,7 +86,7 @@ impl CommitmentEvaluationProof for InnerProductProof {
type ProverPublicSetup<'a> = ();
type VerifierPublicSetup<'a> = ();
fn new(
transcript: &mut Transcript,
transcript: &mut impl Transcript,
a: &[Self::Scalar],
b_point: &[Self::Scalar],
generators_offset: u64,
Expand Down Expand Up @@ -115,7 +114,7 @@ impl CommitmentEvaluationProof for InnerProductProof {

fn verify_batched_proof(
&self,
transcript: &mut Transcript,
transcript: &mut impl Transcript,
commit_batch: &[Self::Commitment],
batching_factors: &[Self::Scalar],
product: &Self::Scalar,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use super::{naive_commitment::NaiveCommitment, CommitmentEvaluationProof};
use crate::base::scalar::test_scalar::TestScalar;
use crate::base::{proof::Transcript, scalar::test_scalar::TestScalar};

/// This should only be used for the purpose of unit testing.
pub struct TestEvaluationProof {}
Expand All @@ -21,7 +21,7 @@ impl CommitmentEvaluationProof for TestEvaluationProof {
type VerifierPublicSetup<'a> = ();

fn new(
_transcript: &mut merlin::Transcript,
_transcript: &mut impl Transcript,
_a: &[Self::Scalar],
_b_point: &[Self::Scalar],
_generators_offset: u64,
Expand All @@ -32,7 +32,7 @@ impl CommitmentEvaluationProof for TestEvaluationProof {

fn verify_batched_proof(
&self,
_transcript: &mut merlin::Transcript,
_transcript: &mut impl Transcript,
_commit_batch: &[Self::Commitment],
_batching_factors: &[Self::Scalar],
_product: &Self::Scalar,
Expand Down
30 changes: 30 additions & 0 deletions crates/proof-of-sql/src/base/proof/merlin_transcript_core.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
impl super::transcript_core::TranscriptCore for merlin::Transcript {
fn new() -> Self {
merlin::Transcript::new(b"TranscriptCore::new")
}
fn raw_append(&mut self, message: &[u8]) {
self.append_message(b"TranscriptCore::raw_append", message)
}
fn raw_challenge(&mut self) -> [u8; 32] {
let mut result = [0u8; 32];
self.challenge_bytes(b"TranscriptCore::raw_challenge", &mut result);
result
}
}

#[cfg(test)]
mod tests {
use super::super::transcript_core::test_util::*;
#[test]
fn we_get_equivalent_challenges_with_equivalent_merlin_transcripts() {
we_get_equivalent_challenges_with_equivalent_transcripts::<merlin::Transcript>()
}
#[test]
fn we_get_different_challenges_with_different_keccak256_transcripts() {
we_get_different_challenges_with_different_transcripts::<merlin::Transcript>()
}
#[test]
fn we_get_different_nontrivial_consecutive_challenges_from_keccak256_transcript() {
we_get_different_nontrivial_consecutive_challenges_from_transcript::<merlin::Transcript>()
}
}
6 changes: 2 additions & 4 deletions crates/proof-of-sql/src/base/proof/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,8 @@ mod error;
pub use error::ProofError;

/// Contains an extension trait for `merlin::Transcript`, which is used to construct a proof.
mod transcript_protocol;
#[cfg(test)]
mod transcript_protocol_test;
pub use transcript_protocol::{MessageLabel, TranscriptProtocol};
#[cfg(any(test, feature = "blitzar"))]
mod merlin_transcript_core;

mod transcript;
pub use transcript::Transcript;
Expand Down
215 changes: 0 additions & 215 deletions crates/proof-of-sql/src/base/proof/transcript_protocol.rs

This file was deleted.

Loading

0 comments on commit 057edde

Please sign in to comment.