Skip to content

Commit

Permalink
Range proof API updates
Browse files Browse the repository at this point in the history
  • Loading branch information
AaronFeickert committed Mar 8, 2024
1 parent 09b6eb3 commit b9a42af
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 15 deletions.
2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ bulletproofs_plus = { package = "tari_bulletproofs_plus", git = "https://github.
curve25519-dalek = { package = "tari-curve25519-dalek", version = "4.0.3", default-features = false, features = [ "alloc", "rand_core", "precomputed-tables", "zeroize"] }
digest = { version = "0.10", default-features = false }
log = { version = "0.4" , default-features = false}
merlin = { version = "3", default-features = false }
once_cell = { version = "1.8", default-features = false, features = ["critical-section"] }
rand_chacha = { version = "0.3", default-features = false }
rand_core = { version = "0.6" , default-features = false}
Expand All @@ -43,6 +44,7 @@ std = [
"borsh?/std",
"digest/std",
"log/std",
"merlin/std",
"once_cell/std",
"rand_chacha/std",
"rand_core/std",
Expand Down
43 changes: 28 additions & 15 deletions src/ristretto/bulletproofs_plus.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ use bulletproofs_plus::{
};
use curve25519_dalek::{ristretto::RistrettoPoint, scalar::Scalar};
use log::*;
use merlin::Transcript;

use crate::{
alloc::string::ToString,
Expand Down Expand Up @@ -223,8 +224,12 @@ impl RangeProofService for BulletproofsPlusService {
let statement = RangeStatement::init(self.generators.clone(), vec![commitment], vec![None], None)
.map_err(|e| RangeProofError::ProofConstructionError { reason: e.to_string() })?;

let proof = RistrettoRangeProof::prove(self.transcript_label, &statement, &witness)
.map_err(|e| RangeProofError::ProofConstructionError { reason: e.to_string() })?;
let proof = RistrettoRangeProof::prove(
&mut Transcript::new(self.transcript_label.as_bytes()),
&statement,
&witness,
)
.map_err(|e| RangeProofError::ProofConstructionError { reason: e.to_string() })?;

Ok(proof.to_bytes())
}
Expand All @@ -242,7 +247,7 @@ impl RangeProofService for BulletproofsPlusService {
seed_nonce: None,
};
match RistrettoRangeProof::verify_batch(
&[self.transcript_label],
&mut [Transcript::new(self.transcript_label.as_bytes())],
&[statement],
&[rp.clone()],
VerifyAction::VerifyOnly,
Expand Down Expand Up @@ -306,8 +311,12 @@ impl ExtendedRangeProofService for BulletproofsPlusService {
)
.map_err(|e| RangeProofError::ProofConstructionError { reason: e.to_string() })?;

let proof = RistrettoRangeProof::prove(self.transcript_label, &statement, &witness)
.map_err(|e| RangeProofError::ProofConstructionError { reason: e.to_string() })?;
let proof = RistrettoRangeProof::prove(
&mut Transcript::new(self.transcript_label.as_bytes()),
&statement,
&witness,
)
.map_err(|e| RangeProofError::ProofConstructionError { reason: e.to_string() })?;

Ok(proof.to_bytes())
}
Expand Down Expand Up @@ -345,8 +354,12 @@ impl ExtendedRangeProofService for BulletproofsPlusService {
)
.map_err(|e| RangeProofError::ProofConstructionError { reason: e.to_string() })?;

let proof = RistrettoRangeProof::prove(self.transcript_label, &statement, &witness)
.map_err(|e| RangeProofError::ProofConstructionError { reason: e.to_string() })?;
let proof = RistrettoRangeProof::prove(
&mut Transcript::new(self.transcript_label.as_bytes()),
&statement,
&witness,
)
.map_err(|e| RangeProofError::ProofConstructionError { reason: e.to_string() })?;

Ok(proof.to_bytes())
}
Expand All @@ -362,13 +375,13 @@ impl ExtendedRangeProofService for BulletproofsPlusService {
// Deserialize the range proofs
let range_proofs = self.deserialize_range_proofs(&proofs)?;

// Set up a common transcript label
let transcript_labels = vec![self.transcript_label; range_statements.len()];
// Set up transcripts
let mut transcripts = vec![Transcript::new(self.transcript_label.as_bytes()); range_statements.len()];

// Verify and recover
let mut recovered_extended_masks = Vec::new();
match RistrettoRangeProof::verify_batch(
&transcript_labels,
&mut transcripts,
&range_statements,
&range_proofs,
VerifyAction::RecoverAndVerify,
Expand Down Expand Up @@ -409,12 +422,12 @@ impl ExtendedRangeProofService for BulletproofsPlusService {
// Deserialize the range proofs
let range_proofs = self.deserialize_range_proofs(&proofs)?;

// Set up a common transcript label
let transcript_labels = vec![self.transcript_label; range_statements.len()];
// Set up transcripts
let mut transcripts = vec![Transcript::new(self.transcript_label.as_bytes()); range_statements.len()];

// Verify
match RistrettoRangeProof::verify_batch(
&transcript_labels,
&mut transcripts,
&range_statements,
&range_proofs,
VerifyAction::VerifyOnly,
Expand Down Expand Up @@ -446,7 +459,7 @@ impl ExtendedRangeProofService for BulletproofsPlusService {
};

match RistrettoRangeProof::verify_batch(
&[self.transcript_label],
&mut [Transcript::new(self.transcript_label.as_bytes())],
&[statement],
&[rp],
VerifyAction::RecoverOnly,
Expand Down Expand Up @@ -491,7 +504,7 @@ impl ExtendedRangeProofService for BulletproofsPlusService {
let range_statements = self.prepare_private_range_statements(vec![statement]);

match RistrettoRangeProof::verify_batch(
&[self.transcript_label],
&mut [Transcript::new(self.transcript_label.as_bytes())],
&range_statements,
&[rp],
VerifyAction::RecoverOnly,
Expand Down

0 comments on commit b9a42af

Please sign in to comment.