Skip to content

Commit

Permalink
Update range proof dependency
Browse files Browse the repository at this point in the history
  • Loading branch information
AaronFeickert committed May 7, 2024
1 parent e755b26 commit 3c8b347
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 39 deletions.
15 changes: 6 additions & 9 deletions .github/workflows/clippy-check.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
name: Formatting, lints, and code checks
on: [push, pull_request]

env:
nightly: nightly-2024-02-01

jobs:
clippy_check:
runs-on: ubuntu-latest
Expand All @@ -14,24 +11,24 @@ jobs:
uses: dtolnay/rust-toolchain@master
with:
components: clippy, rustfmt
toolchain: ${{ env.nightly }}
toolchain: nightly
- name: Toolchain thumbv8m.main-none-eabi
uses: dtolnay/rust-toolchain@master
with:
toolchain: ${{ env.nightly }}
toolchain: nightly
targets: thumbv8m.main-none-eabi
- name: Check formatting
run: cargo +${{ env.nightly }} fmt --all -- --check
run: cargo +nightly fmt --all -- --check
- name: Install linter
run: cargo install cargo-lints
- name: Run linter
run: cargo +${{ env.nightly }} lints clippy --all-targets --all-features
run: cargo +nightly lints clippy --all-targets --all-features
- name: Check code
run: cargo +stable check --release --all-targets
- name: Check code (no default features)
run: cargo +stable check --release --no-default-features
# This check here is to ensure that it builds for no-std rust targets
- name: Check code (no-std)
run: cargo +${{ env.nightly }} check --no-default-features --target=thumbv8m.main-none-eabi -Zavoid-dev-deps
run: cargo +nightly check --no-default-features --target=thumbv8m.main-none-eabi -Zavoid-dev-deps
- name: Check benchmarks
run: cargo +${{ env.nightly }} check --benches
run: cargo +nightly check --benches
6 changes: 4 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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", version = "0.4", 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}
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
53 changes: 35 additions & 18 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 @@ -88,7 +89,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 +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() })?,
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,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,
Expand Down Expand Up @@ -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,
Expand All @@ -430,18 +449,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],
&mut [Transcript::new(self.transcript_label.as_bytes())],
&[statement],
&[rp],
VerifyAction::RecoverOnly,
) {
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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();
Expand Down
7 changes: 1 addition & 6 deletions src/ristretto/pedersen/commitment_factory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,18 +90,13 @@ mod test {
use alloc::vec::Vec;
use std::{
collections::hash_map::DefaultHasher,
convert::From,
hash::{Hash, Hasher},
};

use curve25519_dalek::scalar::Scalar;

use super::*;
use crate::{
commitment::HomomorphicCommitmentFactory,
keys::{PublicKey, SecretKey},
ristretto::{pedersen::commitment_factory::PedersenCommitmentFactory, RistrettoSecretKey},
};
use crate::keys::{PublicKey, SecretKey};

#[test]
fn check_default_base() {
Expand Down
6 changes: 2 additions & 4 deletions src/ristretto/ristretto_keys.rs
Original file line number Diff line number Diff line change
Expand Up @@ -625,12 +625,10 @@ impl From<RistrettoPublicKey> for CompressedRistretto {

#[cfg(test)]
mod test {
use blake2::Blake2b;
use digest::consts::{U32, U64};
use tari_utilities::ByteArray;
use digest::consts::U32;

use super::*;
use crate::{keys::PublicKey, ristretto::test_common::get_keypair};
use crate::ristretto::test_common::get_keypair;

fn assert_completely_equal(k1: &RistrettoPublicKey, k2: &RistrettoPublicKey) {
assert_eq!(k1, k2);
Expand Down

0 comments on commit 3c8b347

Please sign in to comment.