Skip to content

Commit

Permalink
feat: swap dalek bulletproofs for bulletproofs-plus (#4213)
Browse files Browse the repository at this point in the history
Description
---
Swapped out Dalek Bulletproofs for Tari Bulletproofs+ using the most basic range proof creation and verification

Motivation and Context
---

How Has This Been Tested?
---
  • Loading branch information
hansieodendaal authored Jun 24, 2022
1 parent 641844a commit 46f9bb8
Show file tree
Hide file tree
Showing 53 changed files with 5,051 additions and 8,945 deletions.
12 changes: 6 additions & 6 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion applications/tari_app_grpc/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ edition = "2018"
tari_common_types = { version = "^0.32", path = "../../base_layer/common_types"}
tari_comms = { path = "../../comms/core"}
tari_core = { path = "../../base_layer/core"}
tari_crypto = { git = "https://github.com/tari-project/tari-crypto.git", rev = "a564ba8f15ea37f0e26f9e13d3ad7ed8e397d312" }
tari_crypto = { git = "https://github.com/tari-project/tari-crypto.git", tag = "v0.14.0" }
tari_script = { path = "../../infrastructure/tari_script" }
tari_utilities = { git = "https://github.com/tari-project/tari_utilities.git", tag = "v0.4.4" }

Expand Down
2 changes: 1 addition & 1 deletion applications/tari_app_utilities/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ license = "BSD-3-Clause"

[dependencies]
tari_comms = { path = "../../comms/core" }
tari_crypto = { git = "https://github.com/tari-project/tari-crypto.git", rev = "a564ba8f15ea37f0e26f9e13d3ad7ed8e397d312" }
tari_crypto = { git = "https://github.com/tari-project/tari-crypto.git", tag = "v0.14.0" }
tari_common = { path = "../../common" }
tari_common_types = { path = "../../base_layer/common_types" }
tari_p2p = { path = "../../base_layer/p2p", features = ["auto-update"] }
Expand Down
2 changes: 1 addition & 1 deletion applications/tari_base_node/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ tari_comms = { path = "../../comms/core", features = ["rpc"] }
tari_common_types = { path = "../../base_layer/common_types" }
tari_comms_dht = { path = "../../comms/dht" }
tari_core = { path = "../../base_layer/core", default-features = false, features = ["transactions"] }
tari_crypto = { git = "https://github.com/tari-project/tari-crypto.git", rev = "a564ba8f15ea37f0e26f9e13d3ad7ed8e397d312" }
tari_crypto = { git = "https://github.com/tari-project/tari-crypto.git", tag = "v0.14.0" }
tari_libtor = { path = "../../infrastructure/libtor" }
tari_mmr = { path = "../../base_layer/mmr", features = ["native_bitmap"] }
tari_p2p = { path = "../../base_layer/p2p", features = ["auto-update"] }
Expand Down
2 changes: 1 addition & 1 deletion applications/tari_collectibles/src-tauri/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ tari_app_grpc = { path = "../../tari_app_grpc" }
tari_app_utilities = { path = "../../tari_app_utilities" }
tari_common = { path = "../../../common" }
tari_common_types = { path = "../../../base_layer/common_types" }
tari_crypto = { git = "https://github.com/tari-project/tari-crypto.git", rev = "a564ba8f15ea37f0e26f9e13d3ad7ed8e397d312" }
tari_crypto = { git = "https://github.com/tari-project/tari-crypto.git", tag = "v0.14.0" }
tari_key_manager = { path = "../../../base_layer/key_manager" }
tari_mmr = { path = "../../../base_layer/mmr" }
tari_utilities = { git = "https://github.com/tari-project/tari_utilities.git", tag = "v0.4.4" }
Expand Down
2 changes: 1 addition & 1 deletion applications/tari_console_wallet/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ license = "BSD-3-Clause"

[dependencies]
tari_wallet = { path = "../../base_layer/wallet", features = ["bundled_sqlite"] }
tari_crypto = { git = "https://github.com/tari-project/tari-crypto.git", rev = "a564ba8f15ea37f0e26f9e13d3ad7ed8e397d312" }
tari_crypto = { git = "https://github.com/tari-project/tari-crypto.git", tag = "v0.14.0" }
tari_common = { path = "../../common" }
tari_app_utilities = { path = "../tari_app_utilities" }
tari_comms = { path = "../../comms/core" }
Expand Down
2 changes: 1 addition & 1 deletion applications/tari_merge_mining_proxy/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ tari_common = { path = "../../common" }
tari_comms = { path = "../../comms/core" }
tari_core = { path = "../../base_layer/core", default-features = false, features = ["transactions"] }
tari_app_utilities = { path = "../tari_app_utilities" }
tari_crypto = { git = "https://github.com/tari-project/tari-crypto.git", rev = "a564ba8f15ea37f0e26f9e13d3ad7ed8e397d312" }
tari_crypto = { git = "https://github.com/tari-project/tari-crypto.git", tag = "v0.14.0" }
tari_utilities = { git = "https://github.com/tari-project/tari_utilities.git", tag = "v0.4.4" }

anyhow = "1.0.53"
Expand Down
2 changes: 1 addition & 1 deletion applications/tari_miner/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ tari_common = { path = "../../common" }
tari_comms = { path = "../../comms/core" }
tari_app_utilities = { path = "../tari_app_utilities"}
tari_app_grpc = { path = "../tari_app_grpc" }
tari_crypto = { git = "https://github.com/tari-project/tari-crypto.git", rev = "a564ba8f15ea37f0e26f9e13d3ad7ed8e397d312" }
tari_crypto = { git = "https://github.com/tari-project/tari-crypto.git", tag = "v0.14.0" }
tari_utilities = { git = "https://github.com/tari-project/tari_utilities.git", tag = "v0.4.4" }

crossterm = { version = "0.17" }
Expand Down
2 changes: 1 addition & 1 deletion applications/tari_validator_node/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ tari_common = { path = "../../common" }
tari_comms = { path = "../../comms/core" }
tari_comms_dht = { path = "../../comms/dht" }
tari_comms_rpc_macros = { path = "../../comms/rpc_macros" }
tari_crypto = { git = "https://github.com/tari-project/tari-crypto.git", rev = "a564ba8f15ea37f0e26f9e13d3ad7ed8e397d312" }
tari_crypto = { git = "https://github.com/tari-project/tari-crypto.git", tag = "v0.14.0" }
tari_mmr = { path = "../../base_layer/mmr" }
tari_p2p = { path = "../../base_layer/p2p" }
tari_service_framework = { path = "../../base_layer/service_framework" }
Expand Down
2 changes: 1 addition & 1 deletion applications/test_faucet/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ simd = ["tari_crypto/simd"]
avx2 = ["simd"]

[dependencies]
tari_crypto = { git = "https://github.com/tari-project/tari-crypto.git", rev = "a564ba8f15ea37f0e26f9e13d3ad7ed8e397d312" }
tari_crypto = { git = "https://github.com/tari-project/tari-crypto.git", tag = "v0.14.0" }
tari_utilities = { git = "https://github.com/tari-project/tari_utilities.git", tag = "v0.4.4" }
tari_common_types = { path = "../../base_layer/common_types" }
tari_script = { path = "../../infrastructure/tari_script" }
Expand Down
47 changes: 44 additions & 3 deletions applications/test_faucet/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,12 @@

use std::{
fs::File,
io::{stdout, Write},
io,
io::{stdout, BufRead, Write},
};

use serde::Serialize;
use tari_common_types::types::{Commitment, PrivateKey};
use tari_common_types::types::{Commitment, PrivateKey, RangeProof};
use tari_core::{
covenants::Covenant,
transactions::{
Expand All @@ -27,6 +28,7 @@ use tari_core::{
};
use tari_crypto::{commitment::HomomorphicCommitmentFactory, range_proof::RangeProofService, tari_utilities::hex::Hex};
use tari_script::{script, TariScript};
use tari_utilities::ByteArray;
use tokio::{sync::mpsc, task};

const NUM_KEYS: usize = 4000;
Expand Down Expand Up @@ -125,6 +127,40 @@ async fn write_keys(mut rx: mpsc::Receiver<(TransactionOutput, PrivateKey, Micro
let kernel = serde_json::to_string(&kernel).unwrap();
let _result = utxo_file.write_all(format!("{}\n", kernel).as_bytes());

// Test the UTXO file
println!("\n\nTesting the UTXO file...\n\n");
drop(utxo_file);
let file = File::open("utxos.json").unwrap();
let mut counter = 1;
for line in io::BufReader::new(file).lines() {
if counter < 4001 {
let utxo: TransactionOutput = serde_json::from_str(&*line.unwrap()).unwrap();
match utxo.verify_range_proof(&CryptoFactories::default().range_proof) {
Ok(_) => {},
Err(e) => {
println!("proof error! {}: {}", counter, e);
},
}
match utxo.verify_metadata_signature() {
Ok(_) => {},
Err(e) => {
println!("metadata_signature error! {}: {}", counter, e);
},
}
} else {
let kernel: TransactionKernel = serde_json::from_str(&*line.unwrap()).unwrap();
match kernel.verify_signature() {
Ok(_) => {},
Err(e) => {
println!("kernel_signature error! {}: {}", counter, e);
},
}
println!();
break;
}
counter += 1;
}

println!("Done.");
}

Expand Down Expand Up @@ -161,6 +197,9 @@ fn create_utxo(
let offset_keys = generate_keys();
let commitment = factories.commitment.commit_value(&keys.k, value.into());
let proof = factories.range_proof.construct_proof(&keys.k, value.into()).unwrap();
if !factories.range_proof.verify(&proof, &commitment) {
panic!("Range proof does not verify");
};
let encrypted_value = EncryptedValue::todo_encrypt_from(value);
let metadata_sig = TransactionOutput::create_final_metadata_signature(
TransactionOutputVersion::get_current_version(),
Expand All @@ -177,12 +216,14 @@ fn create_utxo(
let utxo = TransactionOutput::new_current_version(
features,
commitment,
proof.into(),
RangeProof::from_bytes(&proof).unwrap(),
script,
offset_keys.pk,
metadata_sig,
covenant,
encrypted_value,
);
utxo.verify_range_proof(&CryptoFactories::default().range_proof)
.unwrap();
(utxo, keys.k, offset_keys.k)
}
2 changes: 1 addition & 1 deletion base_layer/common_types/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ version = "0.32.5"
edition = "2018"

[dependencies]
tari_crypto = { git = "https://github.com/tari-project/tari-crypto.git", rev = "a564ba8f15ea37f0e26f9e13d3ad7ed8e397d312" }
tari_crypto = { git = "https://github.com/tari-project/tari-crypto.git", tag = "v0.14.0" }
tari_utilities = { git = "https://github.com/tari-project/tari_utilities.git", tag = "v0.4.4" }

digest = "0.9.0"
Expand Down
8 changes: 4 additions & 4 deletions base_layer/common_types/src/types/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ pub use bullet_rangeproofs::BulletRangeProof;
use tari_crypto::{
common::Blake256,
ristretto::{
dalek_range_proof::DalekRangeProofService,
bulletproofs_plus::BulletproofsPlusService,
pedersen::{extended_commitment_factory::ExtendedPedersenCommitmentFactory, PedersenCommitment},
RistrettoComSig,
RistrettoPublicKey,
Expand Down Expand Up @@ -73,11 +73,11 @@ pub type MessageHash = Vec<u8>;
/// Define the data type that is used to store results of `HashDigest`
pub type HashOutput = Vec<u8>;

pub const MAX_RANGE_PROOF_RANGE: usize = 64; // 2^64
pub const RANGE_PROOF_BIT_LENGTH: usize = 64; // 2^64
pub const RANGE_PROOF_AGGREGATION_FACTOR: usize = 1;

/// Specify the range proof type
// TODO: Replace `DalekRangeProofService` with `BulletproofsPlusService` when 'bulletproofs_plus'
pub type RangeProofService = DalekRangeProofService;
pub type RangeProofService = BulletproofsPlusService;

/// Specify the range proof
pub type RangeProof = BulletRangeProof;
2 changes: 1 addition & 1 deletion base_layer/core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ tari_common_types = { version = "^0.32", path = "../../base_layer/common_types"
tari_comms = { version = "^0.32", path = "../../comms/core" }
tari_comms_dht = { version = "^0.32", path = "../../comms/dht" }
tari_comms_rpc_macros = { version = "^0.32", path = "../../comms/rpc_macros" }
tari_crypto = { git = "https://github.com/tari-project/tari-crypto.git", rev = "a564ba8f15ea37f0e26f9e13d3ad7ed8e397d312" }
tari_crypto = { git = "https://github.com/tari-project/tari-crypto.git", tag = "v0.14.0" }
tari_metrics = { path = "../../infrastructure/metrics" }
tari_mmr = { version = "^0.32", path = "../../base_layer/mmr", optional = true, features = ["native_bitmap"] }
tari_p2p = { version = "^0.32", path = "../../base_layer/p2p" }
Expand Down
Loading

0 comments on commit 46f9bb8

Please sign in to comment.