Skip to content

Commit

Permalink
refactor!: rename commitment to blinded amount
Browse files Browse the repository at this point in the history
This makes it much clearer what we in the domain are handling.
The concept "commitment" comes from "Pedersen Commitment", which
is the tech we use to implement blinded amounts.
What we were doing was to try reflect an impl detail, by calling it
"commitment", thus totally missing the aspect of it being a blinded
amount, which was and is the important aspect in our domain.
  • Loading branch information
oetyng authored and davidrusu committed Mar 22, 2023
1 parent 27bb954 commit 59c21f8
Show file tree
Hide file tree
Showing 21 changed files with 623 additions and 681 deletions.
12 changes: 6 additions & 6 deletions benches/reissue.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ fn bench_reissue_1_to_100(c: &mut Criterion) {
.unwrap()
.secret_key()
.unwrap(),
starting_dbc.amount_secrets_bearer().unwrap(),
starting_dbc.revealed_amount_bearer().unwrap(),
)
.add_outputs_by_amount((0..N_OUTPUTS).map(|_| {
let owner_once =
Expand Down Expand Up @@ -80,7 +80,7 @@ fn bench_reissue_100_to_1(c: &mut Criterion) {
.unwrap()
.secret_key()
.unwrap(),
starting_dbc.amount_secrets_bearer().unwrap(),
starting_dbc.revealed_amount_bearer().unwrap(),
)
.add_outputs_by_amount((0..N_OUTPUTS).map(|_| {
let owner_once =
Expand All @@ -104,8 +104,8 @@ fn bench_reissue_100_to_1(c: &mut Criterion) {
let mut merge_dbc_builder = sn_dbc::TransactionBuilder::default()
.add_inputs_by_secrets(
dbcs.into_iter()
.map(|(_dbc, owner_once, amount_secrets)| {
(owner_once.as_owner().secret_key().unwrap(), amount_secrets)
.map(|(_dbc, owner_once, revealed_amount)| {
(owner_once.as_owner().secret_key().unwrap(), revealed_amount)
})
.collect(),
)
Expand Down Expand Up @@ -143,7 +143,7 @@ fn generate_dbc_of_value(
amount: Token,
rng: &mut (impl RngCore + CryptoRng),
) -> Result<(mock::SpentBookNode, Dbc)> {
let (mut spentbook_node, genesis_dbc, _genesis_material, _amount_secrets) =
let (mut spentbook_node, genesis_dbc, _genesis_material, _revealed_amount) =
mock::GenesisBuilder::init_genesis_single(rng)?;

let output_amounts = vec![
Expand All @@ -154,7 +154,7 @@ fn generate_dbc_of_value(
let mut dbc_builder = sn_dbc::TransactionBuilder::default()
.add_input_by_secrets(
genesis_dbc.owner_once_bearer()?.secret_key()?,
genesis_dbc.amount_secrets_bearer()?,
genesis_dbc.revealed_amount_bearer()?,
)
.add_outputs_by_amount(output_amounts.into_iter().map(|amount| {
let owner_once = OwnerOnce::from_owner_base(Owner::from_random_secret_key(rng), rng);
Expand Down
25 changes: 13 additions & 12 deletions examples/mint-repl/mint-repl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ use sn_dbc::{
},
mock,
rand::{seq::IteratorRandom, Rng},
rng, Dbc, DbcBuilder, DbcTransaction, Hash, OutputOwnerMap, Owner, OwnerOnce,
RevealedCommitment, RevealedTransaction, Token, TransactionBuilder,
rng, Dbc, DbcBuilder, DbcTransaction, Hash, OutputOwnerMap, Owner, OwnerOnce, RevealedAmount,
RevealedTransaction, Token, TransactionBuilder,
};

use std::collections::{BTreeMap, HashMap};
Expand Down Expand Up @@ -60,7 +60,7 @@ impl MintInfo {
#[derive(Debug, Clone)]
struct DbcTransactionRevealed {
inner: DbcTransaction,
revealed_commitments: Vec<RevealedCommitment>,
revealed_amounts: Vec<RevealedAmount>,
revealed_tx: RevealedTransaction,
output_owner_map: OutputOwnerMap,
}
Expand Down Expand Up @@ -183,9 +183,10 @@ fn mk_new_mint(sks: SecretKeySet, poly: Poly) -> Result<MintInfo> {

let num_spentbook_nodes = sks.threshold() + 1;

let (spentbook_nodes, genesis_dbc, _genesis, _amount_secrets) = mock::GenesisBuilder::default()
.gen_spentbook_nodes_with_sks(num_spentbook_nodes, &sks)
.build(&mut rng)?;
let (spentbook_nodes, genesis_dbc, _genesis, _revealed_amount) =
mock::GenesisBuilder::default()
.gen_spentbook_nodes_with_sks(num_spentbook_nodes, &sks)
.build(&mut rng)?;

let reissue_auto = ReissueAuto::from(vec![genesis_dbc.clone()]);

Expand Down Expand Up @@ -372,22 +373,22 @@ fn print_dbc_human(dbc: &Dbc, outputs: bool, secret_key_base: Option<SecretKey>)

let result = match secret_key_base {
// use base SecretKey from input param if available.
Some(key_base) => Some((dbc.owner_once(&key_base)?, dbc.amount_secrets(&key_base)?)),
Some(key_base) => Some((dbc.owner_once(&key_base)?, dbc.revealed_amount(&key_base)?)),

// use base SecretKey from dbc if available (bearer)
None if dbc.is_bearer() => Some((dbc.owner_once_bearer()?, dbc.amount_secrets_bearer()?)),
None if dbc.is_bearer() => Some((dbc.owner_once_bearer()?, dbc.revealed_amount_bearer()?)),

// Otherwise, have only the pubkey
_ => None,
};

match result {
Some((ref _owner_once, ref amount_secrets)) => {
Some((ref _owner_once, ref revealed_amount)) => {
println!("*** Secrets (decrypted) ***");
println!(" amount: {}\n", amount_secrets.amount());
println!(" amount: {}\n", revealed_amount.value());
println!(
" blinding_factor: {}\n",
to_be_hex(&amount_secrets.blinding_factor())?
to_be_hex(&revealed_amount.blinding_factor())?
);
}
None => {
Expand Down Expand Up @@ -813,7 +814,7 @@ fn reissue(mintinfo: &mut MintInfo, dbc_builder: DbcBuilder) -> Result<()> {
let output_dbcs = dbc_builder.build(&mintinfo.spentbook_nodes[0].key_manager)?;

// for each output, construct Dbc and display
for (dbc, _owner_once, _amount_secrets) in output_dbcs.iter() {
for (dbc, _owner_once, _revealed_amount) in output_dbcs.iter() {
println!("\n-- Begin DBC --");
print_dbc_human(dbc, false, None)?;
println!("-- End DBC --\n");
Expand Down
24 changes: 12 additions & 12 deletions examples/mint-repl/sample_runs/decode.txt
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ ReissueTransactionUnblinded {
"0000000000000000000000000000000000000000000000000000000000000000",
),
},
amount_secrets_cipher: Ciphertext(
revealed_amount_cipher: Ciphertext(
G1 {
x: Fq(0x130719c576b35a1b371d5382925e7dc2415e286f9f20c615b8b692a18677b1df27cb706072fc282c8390c51d113cebeb),
y: Fq(0x0297a358c296fa9eb03bd7a4c5b2d8c91f5ae62b93c346651cb6387f927b8a01e029a83c7f36ff4120c02432d9cf80b4),
Expand All @@ -101,7 +101,7 @@ ReissueTransactionUnblinded {
},
},
),
commitment: CompressedRistretto: [204, 45, 239, 130, 62, 21, 78, 203, 204, 100, 52, 129, 191, 119, 252, 229, 226, 179, 112, 117, 218, 160, 246, 253, 217, 28, 111, 200, 241, 149, 30, 41],
blinded_amount: CompressedRistretto: [204, 45, 239, 130, 62, 21, 78, 203, 204, 100, 52, 129, 191, 119, 252, 229, 226, 179, 112, 117, 218, 160, 246, 253, 217, 28, 111, 200, 241, 149, 30, 41],
range_proof_bytes: [...],
output_number: 0,
owner: BlindedOwner(
Expand Down Expand Up @@ -139,7 +139,7 @@ ReissueTransactionUnblinded {
"21c5e168173d79fea90489226ed5ce4de64353700f5231e8bf882a0cfb391561",
),
},
amount_secrets_cipher: Ciphertext(
revealed_amount_cipher: Ciphertext(
G1 {
x: Fq(0x07b545ec6fbe47eef82fb2d7524a1a91b4464fc6ed23578a307b73875d7b46cf6683864414e1c437db7e66ad46d16acf),
y: Fq(0x1580abf66f1b988873d330277f96a778b255e441650e31dff591554f26f97481dff75f65de3e7216b94ec88ac086c075),
Expand All @@ -161,7 +161,7 @@ ReissueTransactionUnblinded {
},
},
),
commitment: CompressedRistretto: [92, 249, 1, 19, 34, 185, 36, 228, 200, 31, 127, 166, 227, 52, 94, 147, 89, 105, 121, 86, 177, 185, 251, 236, 150, 210, 244, 167, 33, 121, 239, 65],
blinded_amount: CompressedRistretto: [92, 249, 1, 19, 34, 185, 36, 228, 200, 31, 127, 166, 227, 52, 94, 147, 89, 105, 121, 86, 177, 185, 251, 236, 150, 210, 244, 167, 33, 121, 239, 65],
range_proof_bytes: [...],
output_number: 0,
owner: BlindedOwner(
Expand All @@ -176,7 +176,7 @@ ReissueTransactionUnblinded {
"21c5e168173d79fea90489226ed5ce4de64353700f5231e8bf882a0cfb391561",
),
},
amount_secrets_cipher: Ciphertext(
revealed_amount_cipher: Ciphertext(
G1 {
x: Fq(0x0656e69e25038db6903e3e4d435ab94afbe84f6859b8ecf4745576ce2e18618582535919ae1d791a8434050dfcafd6f7),
y: Fq(0x014d885eb03664fd475558af505d2427a2390c4d73d1fd2a687169b5d326947237fe7b2589fcf91a38a1728f3b7e367b),
Expand All @@ -198,7 +198,7 @@ ReissueTransactionUnblinded {
},
},
),
commitment: CompressedRistretto: [10, 40, 2, 63, 154, 131, 103, 22, 244, 229, 126, 227, 200, 207, 43, 177, 196, 158, 109, 247, 103, 225, 223, 37, 254, 85, 80, 245, 30, 25, 123, 10],
blinded_amount: CompressedRistretto: [10, 40, 2, 63, 154, 131, 103, 22, 244, 229, 126, 227, 200, 207, 43, 177, 196, 158, 109, 247, 103, 225, 223, 37, 254, 85, 80, 245, 30, 25, 123, 10],
range_proof_bytes: [...],
output_number: 1,
owner: BlindedOwner(
Expand Down Expand Up @@ -277,7 +277,7 @@ ReissueRequestUnblinded {
"0000000000000000000000000000000000000000000000000000000000000000",
),
},
amount_secrets_cipher: Ciphertext(
revealed_amount_cipher: Ciphertext(
G1 {
x: Fq(0x130719c576b35a1b371d5382925e7dc2415e286f9f20c615b8b692a18677b1df27cb706072fc282c8390c51d113cebeb),
y: Fq(0x0297a358c296fa9eb03bd7a4c5b2d8c91f5ae62b93c346651cb6387f927b8a01e029a83c7f36ff4120c02432d9cf80b4),
Expand All @@ -299,7 +299,7 @@ ReissueRequestUnblinded {
},
},
),
commitment: CompressedRistretto: [204, 45, 239, 130, 62, 21, 78, 203, 204, 100, 52, 129, 191, 119, 252, 229, 226, 179, 112, 117, 218, 160, 246, 253, 217, 28, 111, 200, 241, 149, 30, 41],
blinded_amount: CompressedRistretto: [204, 45, 239, 130, 62, 21, 78, 203, 204, 100, 52, 129, 191, 119, 252, 229, 226, 179, 112, 117, 218, 160, 246, 253, 217, 28, 111, 200, 241, 149, 30, 41],
range_proof_bytes: [...],
output_number: 0,
owner: BlindedOwner(
Expand Down Expand Up @@ -337,7 +337,7 @@ ReissueRequestUnblinded {
"21c5e168173d79fea90489226ed5ce4de64353700f5231e8bf882a0cfb391561",
),
},
amount_secrets_cipher: Ciphertext(
revealed_amount_cipher: Ciphertext(
G1 {
x: Fq(0x0656e69e25038db6903e3e4d435ab94afbe84f6859b8ecf4745576ce2e18618582535919ae1d791a8434050dfcafd6f7),
y: Fq(0x014d885eb03664fd475558af505d2427a2390c4d73d1fd2a687169b5d326947237fe7b2589fcf91a38a1728f3b7e367b),
Expand All @@ -359,7 +359,7 @@ ReissueRequestUnblinded {
},
},
),
commitment: CompressedRistretto: [10, 40, 2, 63, 154, 131, 103, 22, 244, 229, 126, 227, 200, 207, 43, 177, 196, 158, 109, 247, 103, 225, 223, 37, 254, 85, 80, 245, 30, 25, 123, 10],
blinded_amount: CompressedRistretto: [10, 40, 2, 63, 154, 131, 103, 22, 244, 229, 126, 227, 200, 207, 43, 177, 196, 158, 109, 247, 103, 225, 223, 37, 254, 85, 80, 245, 30, 25, 123, 10],
range_proof_bytes: [...],
output_number: 1,
owner: BlindedOwner(
Expand All @@ -374,7 +374,7 @@ ReissueRequestUnblinded {
"21c5e168173d79fea90489226ed5ce4de64353700f5231e8bf882a0cfb391561",
),
},
amount_secrets_cipher: Ciphertext(
revealed_amount_cipher: Ciphertext(
G1 {
x: Fq(0x07b545ec6fbe47eef82fb2d7524a1a91b4464fc6ed23578a307b73875d7b46cf6683864414e1c437db7e66ad46d16acf),
y: Fq(0x1580abf66f1b988873d330277f96a778b255e441650e31dff591554f26f97481dff75f65de3e7216b94ec88ac086c075),
Expand All @@ -396,7 +396,7 @@ ReissueRequestUnblinded {
},
},
),
commitment: CompressedRistretto: [92, 249, 1, 19, 34, 185, 36, 228, 200, 31, 127, 166, 227, 52, 94, 147, 89, 105, 121, 86, 177, 185, 251, 236, 150, 210, 244, 167, 33, 121, 239, 65],
blinded_amount: CompressedRistretto: [92, 249, 1, 19, 34, 185, 36, 228, 200, 31, 127, 166, 227, 52, 94, 147, 89, 105, 121, 86, 177, 185, 251, 236, 150, 210, 244, 167, 33, 121, 239, 65],
range_proof_bytes: [...],
output_number: 0,
owner: BlindedOwner(
Expand Down
Loading

0 comments on commit 59c21f8

Please sign in to comment.