Skip to content

Commit

Permalink
feat: confidential transactions. pedersen commitments + bulletproofs …
Browse files Browse the repository at this point in the history
…(range proofs)
  • Loading branch information
dan-da committed Aug 13, 2021
1 parent 95670e6 commit ee2623e
Show file tree
Hide file tree
Showing 14 changed files with 1,140 additions and 458 deletions.
20 changes: 15 additions & 5 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,15 @@ thiserror = "1.0.24"
quickcheck = "1"
quickcheck_macros = "1"
rand = "0.7.1"
blsttc = "1.0.1"
rand8 = { package = "rand", version = "0.8.0" }
bulletproofs = "4.0.0"
curve25519-dalek-ng = "4.0.1"
merlin = "3.0.0"
blsttc = "2.3.0"
hex = "0.4.3"

[dependencies.bls_dkg]
version = "~0.4"
version = "~0.5"
optional = true

[dependencies.tiny-keccak]
Expand All @@ -33,15 +37,21 @@ hex = "0.4.3"
version = "1.0.111"
features = [ "derive", "rc" ]

[patch.crates-io]
# Use this branch until it is merged into bls_dkg master.
bls_dkg = { git = "https://github.com/maidsafe/bls_dkg", branch="blsttc_2_3_0_pr" }

[dev-dependencies]
criterion = "0.3"
anyhow = "1.0.40"
rustyline = "8.0.0"
serde = "1.0.126"
rand = "0.7.1"
bincode = "1.3.3"
xor_name = "1.2.0"
hex = "0.4.3"
rustyline = "8.0.0"
bincode = "1.3.3"

[target.'cfg(unix)'.dev-dependencies]
termios = "0.3.3"

[dev-dependencies.sn_dbc]
path = "."
Expand Down
68 changes: 55 additions & 13 deletions benches/reissue.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,27 @@
#![allow(clippy::from_iter_instead_of_collect)]

use bls_dkg::SecretKeyShare;
use std::collections::{BTreeMap, BTreeSet, HashMap, HashSet};
use std::iter::FromIterator;

use curve25519_dalek_ng::scalar::Scalar;
use sn_dbc::{
bls_dkg_id, Dbc, DbcContent, Mint, ReissueRequest, ReissueTransaction, SimpleKeyManager,
SimpleSigner, SimpleSpendBook,
bls_dkg_id, AmountSecrets, Dbc, DbcContent, Error, Mint, ReissueRequest, ReissueTransaction,
SimpleKeyManager, SimpleSigner, SimpleSpendBook,
};

use criterion::{black_box, criterion_group, criterion_main, Criterion};

fn decrypt_amount_secrets(
owner: &bls_dkg::outcome::Outcome,
dbcc: &DbcContent,
) -> Result<AmountSecrets, Error> {
let mut shares: BTreeMap<usize, SecretKeyShare> = Default::default();
shares.insert(0, owner.secret_key_share.clone());

dbcc.amount_secrets_by_secret_key_shares(&owner.public_key_set, &shares)
}

fn genesis(
amount: u64,
) -> (
Expand Down Expand Up @@ -58,12 +70,24 @@ fn bench_reissue_1_to_100(c: &mut Criterion) {
let inputs = HashSet::from_iter(vec![genesis_dbc.clone()]);
let input_hashes = BTreeSet::from_iter(inputs.iter().map(|in_dbc| in_dbc.name()));

let genesis_secrets = decrypt_amount_secrets(&genesis_owner, &genesis_dbc.content).unwrap();

let output_owner = bls_dkg_id();
let owner_pub_key = output_owner.public_key_set.public_key();
let mut outputs_bf_sum: Scalar = Default::default();
let outputs = (0..n_outputs)
.into_iter()
.map(|i| DbcContent::new(input_hashes.clone(), 1, i, owner_pub_key))
.collect();
.map(|i| {
let blinding_factor = DbcContent::calc_blinding_factor(
i == n_outputs - 1,
genesis_secrets.blinding_factor,
outputs_bf_sum,
);
outputs_bf_sum += blinding_factor;
DbcContent::new(input_hashes.clone(), 1, i, owner_pub_key, blinding_factor)
})
.collect::<Result<_, _>>()
.unwrap();

let transaction = ReissueTransaction { inputs, outputs };

Expand Down Expand Up @@ -102,15 +126,31 @@ fn bench_reissue_100_to_1(c: &mut Criterion) {
let inputs = HashSet::from_iter(vec![genesis_dbc.clone()]);
let input_hashes = BTreeSet::from_iter(inputs.iter().map(|in_dbc| in_dbc.name()));

let genesis_secrets = decrypt_amount_secrets(&genesis_owner, &genesis_dbc.content).unwrap();
let mut outputs_bf_sum: Scalar = Default::default();

let owners: Vec<_> = (0..n_outputs).into_iter().map(|_| bls_dkg_id()).collect();
let outputs = Vec::from_iter((0..n_outputs).into_iter().map(|i| {
DbcContent::new(
input_hashes.clone(),
1,
i,
owners[i as usize].public_key_set.public_key(),
)
}));
let outputs = Vec::from_iter(
(0..n_outputs)
.into_iter()
.map(|i| {
let blinding_factor = DbcContent::calc_blinding_factor(
i == n_outputs - 1,
genesis_secrets.blinding_factor,
outputs_bf_sum,
);
outputs_bf_sum += blinding_factor;
DbcContent::new(
input_hashes.clone(),
1,
i,
owners[i as usize].public_key_set.public_key(),
blinding_factor,
)
})
.collect::<Result<Vec<_>, _>>()
.unwrap(),
);

let transaction = ReissueTransaction {
inputs,
Expand Down Expand Up @@ -157,7 +197,9 @@ fn bench_reissue_100_to_1(c: &mut Criterion) {
n_outputs as u64,
0,
bls_dkg_id().public_key_set.public_key(),
);
outputs_bf_sum,
)
.unwrap();

let merge_transaction = ReissueTransaction {
inputs: HashSet::from_iter(dbcs.clone()),
Expand Down

0 comments on commit ee2623e

Please sign in to comment.