Skip to content

Commit

Permalink
WIP: update range proof dependency
Browse files Browse the repository at this point in the history
  • Loading branch information
AaronFeickert committed Mar 8, 2024
1 parent e755b26 commit 09b6eb3
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 13 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Expand Up @@ -14,7 +14,7 @@ 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 }
bulletproofs_plus = { package = "tari_bulletproofs_plus", git = "https://github.com/tari-project/bulletproofs-plus", optional = true }
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}
Expand Down
28 changes: 16 additions & 12 deletions src/ristretto/bulletproofs_plus.rs
Expand Up @@ -88,7 +88,7 @@ impl TryFrom<&RistrettoExtendedMask> for BulletproofsExtendedMask {
type Error = RangeProofError;

fn try_from(extended_mask: &RistrettoExtendedMask) -> Result<Self, Self::Error> {
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() })
Expand All @@ -109,7 +109,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() })?,
Expand Down Expand Up @@ -242,7 +242,7 @@ impl RangeProofService for BulletproofsPlusService {
seed_nonce: None,
};
match RistrettoRangeProof::verify_batch(
self.transcript_label,
&[self.transcript_label],
&[statement],
&[rp.clone()],
VerifyAction::VerifyOnly,
Expand Down Expand Up @@ -362,10 +362,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()];

// Verify and recover
let mut recovered_extended_masks = Vec::new();
match RistrettoRangeProof::verify_batch(
self.transcript_label,
&transcript_labels,
&range_statements,
&range_proofs,
VerifyAction::RecoverAndVerify,
Expand Down Expand Up @@ -406,9 +409,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()];

// Verify
match RistrettoRangeProof::verify_batch(
self.transcript_label,
&transcript_labels,
&range_statements,
&range_proofs,
VerifyAction::VerifyOnly,
Expand All @@ -430,18 +436,18 @@ 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()],
commitments_compressed: vec![*commitment.0.compressed()],
minimum_value_promises: vec![None],
seed_nonce: Some(seed_nonce.0),
};
// Prepare the range statement

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

match RistrettoRangeProof::verify_batch(
self.transcript_label,
&[self.transcript_label],
&range_statements,
&[rp],
VerifyAction::RecoverOnly,
Expand Down Expand Up @@ -626,9 +632,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();
Expand Down

0 comments on commit 09b6eb3

Please sign in to comment.