Skip to content

Commit

Permalink
Use transcript composition
Browse files Browse the repository at this point in the history
  • Loading branch information
AaronFeickert committed Feb 12, 2024
1 parent da71f78 commit 81d5072
Show file tree
Hide file tree
Showing 5 changed files with 94 additions and 68 deletions.
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_with_rng(
&transcript_labels,
&mut transcripts.clone(),
&statements,
&proofs,
VerifyAction::VerifyOnly,
Expand Down Expand Up @@ -223,7 +230,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 @@ -246,11 +253,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 @@ -260,7 +268,7 @@ fn verify_batched_rangeproofs_helper(bit_length: usize, extension_degree: Extens
match extract_masks {
VerifyAction::VerifyOnly => {
let _masks = RangeProof::verify_batch_with_rng(
&transcript_labels,
&mut transcripts.clone(),
&statements,
&proofs,
VerifyAction::VerifyOnly,
Expand All @@ -270,7 +278,7 @@ fn verify_batched_rangeproofs_helper(bit_length: usize, extension_degree: Extens
},
VerifyAction::RecoverOnly => {
let _masks = RangeProof::verify_batch_with_rng(
&transcript_labels,
&mut transcripts.clone(),
&statements,
&proofs,
VerifyAction::RecoverOnly,
Expand Down
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 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 @@ -34,8 +34,8 @@ pub trait TranscriptProtocol {
}

impl TranscriptProtocol for Transcript {
fn domain_separator(&mut self, label: &'static [u8], message: &[u8]) {
self.append_message(label, message);
fn 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

0 comments on commit 81d5072

Please sign in to comment.