Skip to content

Commit

Permalink
feat!: remove consensus signatures
Browse files Browse the repository at this point in the history
- This also removes many tests and assumptions that are not relevant any
more.
- NB: There are still tests, and the whole spentbook design, that are
outdated and not reflecting the actual upper layer implementation.
  • Loading branch information
oetyng committed Apr 8, 2023
1 parent 14632ac commit 4e3b38d
Show file tree
Hide file tree
Showing 31 changed files with 625 additions and 4,037 deletions.
41 changes: 16 additions & 25 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,41 +22,32 @@ hex = "0.4.3"
merlin = "3.0.0"
thiserror = "1.0.24"

[dependencies.curve25519-dalek]
package = "curve25519-dalek-ng"
version = "4.1.1"
[dependencies.curve25519-dalek]
package = "curve25519-dalek-ng"
version = "4.1.1"

[dependencies.serde]
version = "1.0.133"
features = [ "derive", "rc" ]
optional = true
[dependencies.serde]
version = "1.0.133"
features = [ "derive", "rc" ]
optional = true

[dependencies.tiny-keccak]
features = [ "sha3" ]
version = "2.0.0"
[dependencies.tiny-keccak]
features = [ "sha3" ]
version = "2.0.0"

[dev-dependencies]
anyhow = "1.0.40"
criterion = "0.4.0"
quickcheck_macros = "1"
quickcheck = "1.0.3"
rustyline = "10.0.0"

[dev-dependencies.sn_dbc]
path = "."
features = [ "serdes", "mock" ]
[dev-dependencies.sn_dbc]
path = "."
features = [ "serdes", "mock" ]

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

[target."cfg(unix)".dev-dependencies.pprof]
version = "0.11.0"
features = [ "flamegraph" ]
[target."cfg(unix)".dev-dependencies.pprof]
version = "0.11.0"
features = [ "flamegraph" ]

[[bench]]
name = "reissue"
harness = false

[[example]]
name = "mint-repl"
path = "examples/mint-repl/mint-repl.rs"
28 changes: 14 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# sn_dbc
Safe Network DBCs
Safe Network Dbcs

|Crate|Documentation|CI|Safe Rust|
|:-:|:-:|:-:|:-:|
Expand All @@ -13,17 +13,17 @@ Safe Network DBCs
This crate provides a library and API for working with Digital Bearer Certificates (DBC)
on the Safe Network.

Safe Network DBCs are envisioned to be a private and fungible digital currency that utilize a distributed (and sharded) spentbook/mint rather than a blockchain.
Safe Network Dbcs are envisioned to be a private and fungible digital currency that utilize a distributed (and sharded) spentbook of spends rather than a blockchain.

Some key properties of these DBCs:
* distributed mint means that it is not necessary to trust in a single mint entity
* sharded mint means that the system scales indefinitely
* transactions are settled immmediately
* privacy by default. all transactions use privacy features.
* utilizes a one-time key for each payment (aka stealth address)
* use BLS cryptography
Some key properties of these Dbcs:
* Distributed spentbook means that it is not necessary to trust in a single entity.
* Sharded spentbook means that the system scales indefinitely.
* Transactions are settled immmediately.
* Privacy by default. all transactions use privacy features.
* Utilizes a one-time key for each payment (aka stealth address).
* Uses BLS cryptography.

At present DBC ownership is single signature only. Multi-sig support is planned.
Multi-sig is a concern of the user of this library.

Some writeups about the technology can be found at:

Expand All @@ -40,14 +40,14 @@ $ cargo build

# Running

## mint-repl example
## spentbook example

A `mint-repl` example is provided which enables interacting with a mock
spentbook/mint and wallet.
A `spentbook` example is provided which enables interacting with a mock
spentbook and wallet.

```
$ cd sn_dbc
$ cargo run --example mint-repl
$ cargo run --example spentbook
```

Additional examples can be found in a separate crate:
Expand Down
78 changes: 35 additions & 43 deletions benches/reissue.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,17 @@ use sn_dbc::{
};

use criterion::{black_box, criterion_group, criterion_main, Criterion};
use std::collections::BTreeMap;
use std::collections::{BTreeMap, BTreeSet};

const N_OUTPUTS: u64 = 100;

fn bench_reissue_1_to_100(c: &mut Criterion) {
let mut rng = rng::from_seed([0u8; 32]);

let (mut spentbook, (starting_dbc, starting_main_key)) =
let (mut spentbook_node, (starting_dbc, starting_main_key)) =
generate_dbc_of_value(Token::from_nano(N_OUTPUTS), &mut rng).unwrap();

let mut dbc_builder = sn_dbc::TransactionBuilder::default()
let dbc_builder = sn_dbc::TransactionBuilder::default()
.add_input_by_secrets(
starting_dbc.derived_key(&starting_main_key).unwrap(),
starting_dbc.revealed_amount(&starting_main_key).unwrap(),
Expand All @@ -37,26 +37,26 @@ fn bench_reissue_1_to_100(c: &mut Criterion) {
MainKey::random_from_rng(&mut rng).random_dbc_id_src(&mut rng),
)
}))
.build(&mut rng)
.build(Hash::default(), &mut rng)
.unwrap();

for (public_key, tx) in dbc_builder.inputs() {
let spent_proof_share = spentbook
.log_spent(public_key, tx, Hash::default())
.unwrap();
dbc_builder = dbc_builder.add_spent_proof_share(spent_proof_share);
for (tx, signed_spend) in dbc_builder.signed_spends() {
spentbook_node.log_spent(tx, signed_spend).unwrap();
}

let spent_proofs = dbc_builder.spent_proofs().unwrap();
let tx = &dbc_builder.transaction;
let tx = &dbc_builder.tx;
let signed_spends: BTreeSet<_> = dbc_builder
.signed_spends()
.iter()
.map(|(_, spend)| (*spend).clone())
.collect();

c.bench_function(&format!("reissue split 1 to {N_OUTPUTS}"), |b| {
#[cfg(unix)]
let guard = pprof::ProfilerGuard::new(100).unwrap();

b.iter(|| {
TransactionVerifier::verify(&spentbook.key_manager, black_box(tx), &spent_proofs)
.unwrap();
TransactionVerifier::verify(black_box(tx), &signed_spends).unwrap();
});

#[cfg(unix)]
Expand All @@ -83,7 +83,7 @@ fn bench_reissue_100_to_1(c: &mut Criterion) {
})
.collect();

let mut dbc_builder = sn_dbc::TransactionBuilder::default()
let dbc_builder = sn_dbc::TransactionBuilder::default()
.add_input_by_secrets(
starting_dbc.derived_key(&starting_main_key).unwrap(),
starting_dbc.revealed_amount(&starting_main_key).unwrap(),
Expand All @@ -101,21 +101,18 @@ fn bench_reissue_100_to_1(c: &mut Criterion) {
)
}),
)
.build(&mut rng)
.build(Hash::default(), &mut rng)
.unwrap();

for (public_key, tx) in dbc_builder.inputs() {
let spent_proof_share = spentbook_node
.log_spent(public_key, tx, Hash::default())
.unwrap();
dbc_builder = dbc_builder.add_spent_proof_share(spent_proof_share);
for (tx, signed_spend) in dbc_builder.signed_spends() {
spentbook_node.log_spent(tx, signed_spend).unwrap();
}
let dbcs = dbc_builder.build(&spentbook_node.key_manager).unwrap();
let dbcs = dbc_builder.build().unwrap();

let main_key = MainKey::random_from_rng(&mut rng);
let derivation_index = random_derivation_index(&mut rng);

let mut merge_dbc_builder = sn_dbc::TransactionBuilder::default()
let merge_dbc_builder = sn_dbc::TransactionBuilder::default()
.add_inputs_by_secrets(
dbcs.into_iter()
.map(|(dbc, revealed_amount)| {
Expand All @@ -131,26 +128,26 @@ fn bench_reissue_100_to_1(c: &mut Criterion) {
derivation_index,
},
)
.build(&mut rng)
.build(Hash::default(), &mut rng)
.unwrap();

for (public_key, tx) in merge_dbc_builder.inputs() {
let spent_proof_share = spentbook_node
.log_spent(public_key, tx, Hash::default())
.unwrap();
merge_dbc_builder = merge_dbc_builder.add_spent_proof_share(spent_proof_share);
for (tx, signed_spend) in merge_dbc_builder.signed_spends() {
spentbook_node.log_spent(tx, signed_spend).unwrap();
}

let spent_proofs = merge_dbc_builder.spent_proofs().unwrap();
let tx = &merge_dbc_builder.transaction;
let tx = &merge_dbc_builder.tx;
let signed_spends: BTreeSet<_> = merge_dbc_builder
.signed_spends()
.iter()
.map(|(_, spend)| (*spend).clone())
.collect();

c.bench_function(&format!("reissue merge {N_OUTPUTS} to 1"), |b| {
#[cfg(unix)]
let guard = pprof::ProfilerGuard::new(100).unwrap();

b.iter(|| {
TransactionVerifier::verify(&spentbook_node.key_manager, black_box(tx), &spent_proofs)
.unwrap();
TransactionVerifier::verify(black_box(tx), &signed_spends).unwrap();
});

#[cfg(unix)]
Expand All @@ -165,7 +162,7 @@ fn bench_reissue_100_to_1(c: &mut Criterion) {
fn generate_dbc_of_value(
amount: Token,
rng: &mut (impl RngCore + CryptoRng),
) -> Result<(mock::SpentBookNode, (Dbc, MainKey))> {
) -> Result<(mock::SpentbookNode, (Dbc, MainKey))> {
let (mut spentbook_node, genesis_dbc, genesis_material, _revealed_amount) =
mock::GenesisBuilder::init_genesis_single(rng)?;

Expand All @@ -176,7 +173,7 @@ fn generate_dbc_of_value(

let main_key = MainKey::random_from_rng(rng);

let mut dbc_builder = sn_dbc::TransactionBuilder::default()
let dbc_builder = sn_dbc::TransactionBuilder::default()
.add_input_by_secrets(
genesis_material.derived_key,
genesis_dbc.revealed_amount(&genesis_material.main_key)?,
Expand All @@ -190,18 +187,13 @@ fn generate_dbc_of_value(
},
)
}))
.build(rng)?;
.build(Hash::default(), rng)?;

for (public_key, tx) in dbc_builder.inputs() {
let spent_proof_share = spentbook_node.log_spent(public_key, tx, Hash::default())?;
dbc_builder = dbc_builder.add_spent_proof_share(spent_proof_share);
for (tx, signed_spend) in dbc_builder.signed_spends() {
spentbook_node.log_spent(tx, signed_spend)?;
}

let (starting_dbc, ..) = dbc_builder
.build(&spentbook_node.key_manager)?
.into_iter()
.next()
.unwrap();
let (starting_dbc, ..) = dbc_builder.build()?.into_iter().next().unwrap();

Ok((spentbook_node, (starting_dbc, main_key)))
}
Expand Down
59 changes: 0 additions & 59 deletions examples/mint-repl/README.md

This file was deleted.

0 comments on commit 4e3b38d

Please sign in to comment.