Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat!: use transcript composition #115

Merged
Merged
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
28 changes: 18 additions & 10 deletions benches/range_proof.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ extern crate criterion;

use criterion::{Criterion, SamplingMode};
use curve25519_dalek::scalar::Scalar;
use merlin::Transcript;
use rand_chacha::ChaCha12Rng;
use rand_core::{CryptoRngCore, SeedableRng};
use tari_bulletproofs_plus::{
Expand Down Expand Up @@ -92,7 +93,12 @@ fn create_aggregated_rangeproof_helper(bit_length: usize, extension_degree: Exte
// Benchmark this code
b.iter(|| {
// 4. Create the aggregated proof
let _proof = RistrettoRangeProof::prove_with_rng(transcript_label, &statement, &witness, &mut rng);
let _proof = RistrettoRangeProof::prove_with_rng(
&mut Transcript::new(transcript_label.as_bytes()),
&statement,
&witness,
&mut rng,
);
})
});
}
Expand Down Expand Up @@ -131,7 +137,7 @@ fn verify_aggregated_rangeproof_helper(bit_length: usize, extension_degree: Exte
// 0. Batch data
let mut statements = vec![];
let mut proofs = vec![];
let mut transcript_labels = vec![];
let mut transcripts = vec![];

// 1. Generators
let generators = RangeParameters::init(bit_length, aggregation_factor, pederson_gens.clone()).unwrap();
Expand Down Expand Up @@ -163,17 +169,18 @@ fn verify_aggregated_rangeproof_helper(bit_length: usize, extension_degree: Exte
let statement =
RangeStatement::init(generators, commitments.clone(), minimum_values.clone(), seed_nonce).unwrap();
statements.push(statement.clone());
transcript_labels.push(transcript_label);
let mut transcript = Transcript::new(transcript_label.as_bytes());
transcripts.push(transcript.clone());

// 4. Create the proof
let proof = RistrettoRangeProof::prove_with_rng(transcript_label, &statement, &witness, &mut rng).unwrap();
let proof = RistrettoRangeProof::prove_with_rng(&mut transcript, &statement, &witness, &mut rng).unwrap();
proofs.push(proof);

// Benchmark this code
b.iter(|| {
// 5. Verify the aggregated proof
let _masks =
RangeProof::verify_batch(&transcript_labels, &statements, &proofs, VerifyAction::VerifyOnly)
RangeProof::verify_batch(&mut transcripts.clone(), &statements, &proofs, VerifyAction::VerifyOnly)
.unwrap();
});
});
Expand Down Expand Up @@ -218,7 +225,7 @@ fn verify_batched_rangeproofs_helper(bit_length: usize, extension_degree: Extens
// Batch data
let mut statements = vec![];
let mut proofs = vec![];
let mut transcript_labels = vec![];
let mut transcripts = vec![];

for _ in 0..number_of_range_proofs {
// Witness data
Expand All @@ -241,11 +248,12 @@ fn verify_batched_rangeproofs_helper(bit_length: usize, extension_degree: Extens
)
.unwrap();
statements.push(statement.clone());
transcript_labels.push(transcript_label);
let mut transcript = Transcript::new(transcript_label.as_bytes());
transcripts.push(transcript.clone());

// Proof
let proof =
RistrettoRangeProof::prove_with_rng(transcript_label, &statement, &witness, &mut rng).unwrap();
RistrettoRangeProof::prove_with_rng(&mut transcript, &statement, &witness, &mut rng).unwrap();
proofs.push(proof);
}

Expand All @@ -255,7 +263,7 @@ fn verify_batched_rangeproofs_helper(bit_length: usize, extension_degree: Extens
match extract_masks {
VerifyAction::VerifyOnly => {
let _masks = RangeProof::verify_batch(
&transcript_labels,
&mut transcripts.clone(),
&statements,
&proofs,
VerifyAction::VerifyOnly,
Expand All @@ -264,7 +272,7 @@ fn verify_batched_rangeproofs_helper(bit_length: usize, extension_degree: Extens
},
VerifyAction::RecoverOnly => {
let _masks = RangeProof::verify_batch(
&transcript_labels,
&mut transcripts.clone(),
&statements,
&proofs,
VerifyAction::RecoverOnly,
Expand Down
2 changes: 2 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,5 +34,7 @@ mod utils;
pub use generators::bulletproof_gens::BulletproofGens;
/// Bulletproofs+ generators and base points needed for a batch of range proofs
pub use generators::pedersen_gens::PedersenGens;
/// Merlin transcripts
pub use merlin::Transcript;

pub mod ristretto;
8 changes: 4 additions & 4 deletions src/protocols/transcript_protocol.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ use crate::{errors::ProofError, traits::FixedBytesRepr};

/// Defines a `TranscriptProtocol` trait for using a Merlin transcript.
pub trait TranscriptProtocol {
/// Append a domain separator for the range proof with the given `label` and `message`.
fn domain_separator(&mut self, label: &'static [u8], message: &[u8]);
/// Append a domain separator for the range proof.
fn append_domain_separator(&mut self);

/// Append a `point` with the given `label`.
fn append_point<P: FixedBytesRepr>(&mut self, label: &'static [u8], point: &P);
Expand All @@ -37,8 +37,8 @@ pub trait TranscriptProtocol {
}

impl TranscriptProtocol for Transcript {
fn domain_separator(&mut self, label: &'static [u8], message: &[u8]) {
self.append_message(label, message);
fn append_domain_separator(&mut self) {
self.append_message(b"dom-sep", b"Bulletproofs+ Range Proof");
}

fn append_point<P: FixedBytesRepr>(&mut self, label: &'static [u8], point: &P) {
Expand Down
Loading