Skip to content

Commit

Permalink
fix: use updated range proof API (#160)
Browse files Browse the repository at this point in the history
Uses a new [range proof API](tari-project/bulletproofs-plus#22).
  • Loading branch information
AaronFeickert committed Jan 4, 2023
1 parent 91ef70a commit be0a491
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 10 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Expand Up @@ -17,7 +17,7 @@ base64 = "0.10.1"
blake2 = "0.9.1"
borsh = { version = "0.9.3", optional = true }
bulletproofs = { package = "tari_bulletproofs", git = "https://github.com/tari-project/bulletproofs", tag = "v4.4.0" }
bulletproofs_plus = { package = "tari_bulletproofs_plus", git = "https://github.com/tari-project/bulletproofs-plus", tag = "v0.1.1" }
bulletproofs_plus = { package = "tari_bulletproofs_plus", git = "https://github.com/tari-project/bulletproofs-plus", tag = "v0.2.1" }
curve25519-dalek = {git = "https://github.com/tari-project/curve25519-dalek", tag = "v4.0.1", default-features = false, features = ["serde", "alloc"] }
digest = "0.9.0"
getrandom = { version = "0.2.3", default-features = false, optional = true }
Expand Down
40 changes: 31 additions & 9 deletions src/ristretto/bulletproofs_plus.rs
Expand Up @@ -11,7 +11,7 @@ use bulletproofs_plus::{
extended_mask::ExtendedMask as BulletproofsExtendedMask,
generators::pedersen_gens::ExtensionDegree as BulletproofsExtensionDegree,
range_parameters::RangeParameters,
range_proof::RangeProof,
range_proof::{RangeProof, VerifyAction},
range_statement::RangeStatement,
range_witness::RangeWitness,
PedersenGens,
Expand Down Expand Up @@ -237,9 +237,12 @@ impl RangeProofService for BulletproofsPlusService {
minimum_value_promises: vec![None],
seed_nonce: None,
};
match RistrettoRangeProof::verify_do_not_recover_masks(self.transcript_label, &[statement], &[
rp.clone()
]) {
match RistrettoRangeProof::verify_batch(
self.transcript_label,
&[statement],
&[rp.clone()],
VerifyAction::VerifyOnly,
) {
Ok(_) => true,
Err(e) => {
if self.generators.extension_degree() != rp.extension_degree() {
Expand Down Expand Up @@ -357,7 +360,12 @@ impl ExtendedRangeProofService for BulletproofsPlusService {

// Verify and recover
let mut recovered_extended_masks = Vec::new();
match RistrettoRangeProof::verify_and_recover_masks(self.transcript_label, &range_statements, &range_proofs) {
match RistrettoRangeProof::verify_batch(
self.transcript_label,
&range_statements,
&range_proofs,
VerifyAction::RecoverAndVerify,
) {
Ok(recovered_masks) => {
if recovered_masks.is_empty() {
// A mask vector should always be returned so this is a valid error condition
Expand Down Expand Up @@ -396,8 +404,12 @@ impl ExtendedRangeProofService for BulletproofsPlusService {
let range_proofs = self.deserialize_range_proofs(&proofs)?;

// Verify
match RistrettoRangeProof::verify_do_not_recover_masks(self.transcript_label, &range_statements, &range_proofs)
{
match RistrettoRangeProof::verify_batch(
self.transcript_label,
&range_statements,
&range_proofs,
VerifyAction::VerifyOnly,
) {
Ok(_) => Ok(()),
Err(e) => Err(RangeProofError::InvalidRangeProof(format!(
"Internal range proof(s) error ({})",
Expand All @@ -423,7 +435,12 @@ impl ExtendedRangeProofService for BulletproofsPlusService {
};
// Prepare the range statement

match RistrettoRangeProof::recover_masks_ony(self.transcript_label, &vec![statement], &[rp]) {
match RistrettoRangeProof::verify_batch(
self.transcript_label,
&vec![statement],
&[rp],
VerifyAction::RecoverOnly,
) {
Ok(recovered_mask) => {
if recovered_mask.is_empty() {
Err(RangeProofError::InvalidRewind(
Expand Down Expand Up @@ -463,7 +480,12 @@ impl ExtendedRangeProofService for BulletproofsPlusService {
// Prepare the range statement
let range_statements = self.prepare_private_range_statements(vec![statement]);

match RistrettoRangeProof::recover_masks_ony(self.transcript_label, &range_statements, &[rp]) {
match RistrettoRangeProof::verify_batch(
self.transcript_label,
&range_statements,
&[rp],
VerifyAction::RecoverOnly,
) {
Ok(recovered_mask) => {
if recovered_mask.is_empty() {
Ok(None)
Expand Down

0 comments on commit be0a491

Please sign in to comment.