From e463ba8889722aec305dc2a1d954f6b0d98eb8da Mon Sep 17 00:00:00 2001 From: Aaron Feickert <66188213+AaronFeickert@users.noreply.github.com> Date: Mon, 15 Jan 2024 10:34:42 -0600 Subject: [PATCH] Update range proof dependency --- Cargo.toml | 6 ++-- src/ristretto/bulletproofs_plus.rs | 53 ++++++++++++++++++++---------- 2 files changed, 39 insertions(+), 20 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 0f16442e..541d1a18 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -14,10 +14,11 @@ edition = "2018" tari_utilities = { version = "0.7", default-features = false, features = ["zero"] } blake2 = { version = "0.10", default-features = false } borsh = { version = "1.2" , optional = true , default-features = false, features = ["derive"]} -bulletproofs_plus = { package = "tari_bulletproofs_plus", version = "0.3", optional = true } -curve25519-dalek = { package = "tari-curve25519-dalek", version = "4.0.3", default-features = false, features = [ "alloc", "rand_core", "precomputed-tables", "zeroize"] } +bulletproofs_plus = { package = "tari_bulletproofs_plus", git = "https://github.com/AaronFeickert/bulletproofs-plus", branch = "no-more-partial-preomp", optional = true } +curve25519-dalek = { version = "4", 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} @@ -43,6 +44,7 @@ std = [ "borsh?/std", "digest/std", "log/std", + "merlin/std", "once_cell/std", "rand_chacha/std", "rand_core/std", diff --git a/src/ristretto/bulletproofs_plus.rs b/src/ristretto/bulletproofs_plus.rs index fe302ff1..236149f7 100644 --- a/src/ristretto/bulletproofs_plus.rs +++ b/src/ristretto/bulletproofs_plus.rs @@ -19,6 +19,7 @@ use bulletproofs_plus::{ }; use curve25519_dalek::{ristretto::RistrettoPoint, scalar::Scalar}; use log::*; +use merlin::Transcript; use crate::{ alloc::string::ToString, @@ -88,7 +89,7 @@ impl TryFrom<&RistrettoExtendedMask> for BulletproofsExtendedMask { type Error = RangeProofError; fn try_from(extended_mask: &RistrettoExtendedMask) -> Result { - let extension_degree = BulletproofsExtensionDegree::try_from_size(extended_mask.secrets().len()) + let extension_degree = BulletproofsExtensionDegree::try_from(extended_mask.secrets().len()) .map_err(|e| RangeProofError::RPExtensionDegree { reason: e.to_string() })?; BulletproofsExtendedMask::assign(extension_degree, Vec::try_from(extended_mask)?) .map_err(|e| RangeProofError::RPExtensionDegree { reason: e.to_string() }) @@ -109,7 +110,7 @@ impl BulletproofsPlusService { h_base_compressed: factory.h_base_compressed, g_base_vec: factory.g_base_vec, g_base_compressed_vec: factory.g_base_compressed_vec, - extension_degree: BulletproofsExtensionDegree::try_from_size(factory.extension_degree as usize) + extension_degree: BulletproofsExtensionDegree::try_from(factory.extension_degree as usize) .map_err(|e| RangeProofError::InitializationError { reason: e.to_string() })?, }) .map_err(|e| RangeProofError::InitializationError { reason: e.to_string() })?, @@ -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()) } @@ -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, @@ -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()) } @@ -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()) } @@ -362,10 +375,13 @@ impl ExtendedRangeProofService for BulletproofsPlusService { // Deserialize the range proofs let range_proofs = self.deserialize_range_proofs(&proofs)?; + // 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( - self.transcript_label, + &mut transcripts, &range_statements, &range_proofs, VerifyAction::RecoverAndVerify, @@ -406,9 +422,12 @@ impl ExtendedRangeProofService for BulletproofsPlusService { // Deserialize the range proofs let range_proofs = self.deserialize_range_proofs(&proofs)?; + // Set up transcripts + let mut transcripts = vec![Transcript::new(self.transcript_label.as_bytes()); range_statements.len()]; + // Verify match RistrettoRangeProof::verify_batch( - self.transcript_label, + &mut transcripts, &range_statements, &range_proofs, VerifyAction::VerifyOnly, @@ -430,6 +449,7 @@ impl ExtendedRangeProofService for BulletproofsPlusService { .map_err(|e| RangeProofError::InvalidRangeProof { reason: e.to_string() }) { Ok(rp) => { + // Prepare the range statement let statement = RangeStatement { generators: self.generators.clone(), commitments: vec![commitment.0.point()], @@ -437,11 +457,10 @@ impl ExtendedRangeProofService for BulletproofsPlusService { minimum_value_promises: vec![None], seed_nonce: Some(seed_nonce.0), }; - // Prepare the range statement match RistrettoRangeProof::verify_batch( - self.transcript_label, - &vec![statement], + &mut [Transcript::new(self.transcript_label.as_bytes())], + &[statement], &[rp], VerifyAction::RecoverOnly, ) { @@ -485,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, @@ -626,9 +645,7 @@ mod test { let key = RistrettoSecretKey(Scalar::random_not_zero(&mut rng)); let proof = bulletproofs_plus_service.construct_proof(&key, value); // This should only succeed with trivial aggregation and extension and a valid value - if extension_degree == CommitmentExtensionDegree::DefaultPedersen && - aggregation_factor == 1 && - value >> (BIT_LENGTH - 1) <= 1 + if extension_degree == CommitmentExtensionDegree::DefaultPedersen && value >> (BIT_LENGTH - 1) <= 1 { // The proof should succeed let proof = proof.unwrap();