Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat!: update commitment signature #4943

Merged
merged 3 commits into from
Nov 23, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
178 changes: 93 additions & 85 deletions Cargo.lock

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions applications/tari_app_grpc/proto/transaction.proto
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ message TransactionInput {
// The script input data, if any
bytes input_data = 5;
// A signature with k_s, signing the script, input data, and mined height
ComSignature script_signature = 7;
ComAndPubSignature script_signature = 7;
// The offset public key, K_O
bytes sender_offset_public_key = 8;
// The hash of the output this input is spending
Expand Down Expand Up @@ -102,7 +102,7 @@ message TransactionOutput {
bytes sender_offset_public_key = 6;
// Metadata signature with the homomorphic commitment private values (amount and blinding factor) and the sender
// offset private key
ComSignature metadata_signature = 7;
ComAndPubSignature metadata_signature = 7;
// Covenant
bytes covenant = 8;
// Version
Expand Down Expand Up @@ -162,7 +162,7 @@ message UnblindedOutput {
// Tari script offset pubkey, K_O
bytes sender_offset_public_key = 8;
// UTXO signature with the script offset private key, k_O
ComSignature metadata_signature = 9;
ComAndPubSignature metadata_signature = 9;
// The minimum height the script allows this output to be spent
uint64 script_lock_height = 10;
// Covenant
Expand Down
12 changes: 7 additions & 5 deletions applications/tari_app_grpc/proto/types.proto
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,14 @@ message Signature {
bytes signature = 2;
}

// Define the explicit ComSignature implementation for the Tari base layer. A different signature scheme can be
// Define the explicit ComAndPubSignature implementation for the Tari base layer. A different signature scheme can be
// employed by redefining this type.
message ComSignature {
bytes public_nonce_commitment = 1;
bytes signature_u = 2;
bytes signature_v = 3;
message ComAndPubSignature {
bytes ephemeral_commitment = 1;
bytes ephemeral_pubkey = 2;
bytes u_a = 3;
bytes u_x = 4;
bytes u_y = 5;
}

/// PoW Algorithm constants
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,22 +22,23 @@

use std::convert::TryFrom;

use tari_common_types::types::{ComSignature, Commitment, PrivateKey};
use tari_common_types::types::{ComAndPubSignature, Commitment, PrivateKey, PublicKey};
use tari_utilities::ByteArray;

use crate::tari_rpc as grpc;

impl TryFrom<grpc::ComSignature> for ComSignature {
impl TryFrom<grpc::ComAndPubSignature> for ComAndPubSignature {
type Error = String;

fn try_from(sig: grpc::ComSignature) -> Result<Self, Self::Error> {
let public_nonce = Commitment::from_bytes(&sig.public_nonce_commitment)
.map_err(|_| "Could not get public nonce commitment".to_string())?;
let signature_u =
PrivateKey::from_bytes(&sig.signature_u).map_err(|_| "Could not get partial signature u".to_string())?;
let signature_v =
PrivateKey::from_bytes(&sig.signature_v).map_err(|_| "Could not get partial signature v".to_string())?;
fn try_from(sig: grpc::ComAndPubSignature) -> Result<Self, Self::Error> {
let ephemeral_commitment = Commitment::from_bytes(&sig.ephemeral_commitment)
.map_err(|_| "Could not get ephemeral commitment".to_string())?;
let ephemeral_pubkey = PublicKey::from_bytes(&sig.ephemeral_pubkey)
.map_err(|_| "Could not get ephemeral public key".to_string())?;
let u_a = PrivateKey::from_bytes(&sig.u_a).map_err(|_| "Could not get partial signature u_a".to_string())?;
let u_x = PrivateKey::from_bytes(&sig.u_x).map_err(|_| "Could not get partial signature u_x".to_string())?;
let u_y = PrivateKey::from_bytes(&sig.u_y).map_err(|_| "Could not get partial signature u_y".to_string())?;

Ok(Self::new(public_nonce, signature_u, signature_v))
Ok(Self::new(ephemeral_commitment, ephemeral_pubkey, u_a, u_x, u_y))
}
}
4 changes: 2 additions & 2 deletions applications/tari_app_grpc/src/conversions/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ mod base_node_state;
mod block;
mod block_header;
mod chain_metadata;
mod com_signature;
mod com_and_pub_signature;
mod consensus_constants;
mod historical_block;
mod new_block_template;
Expand All @@ -52,7 +52,7 @@ pub use self::{
block::*,
block_header::*,
chain_metadata::*,
com_signature::*,
com_and_pub_signature::*,
consensus_constants::*,
historical_block::*,
new_block_template::*,
Expand Down
10 changes: 6 additions & 4 deletions applications/tari_app_grpc/src/conversions/transaction_input.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,10 +91,12 @@ impl TryFrom<TransactionInput> for grpc::TransactionInput {
type Error = String;

fn try_from(input: TransactionInput) -> Result<Self, Self::Error> {
let script_signature = Some(grpc::ComSignature {
public_nonce_commitment: Vec::from(input.script_signature.public_nonce().as_bytes()),
signature_u: Vec::from(input.script_signature.u().as_bytes()),
signature_v: Vec::from(input.script_signature.v().as_bytes()),
let script_signature = Some(grpc::ComAndPubSignature {
ephemeral_commitment: Vec::from(input.script_signature.ephemeral_commitment().as_bytes()),
ephemeral_pubkey: Vec::from(input.script_signature.ephemeral_pubkey().as_bytes()),
u_a: Vec::from(input.script_signature.u_a().as_bytes()),
u_x: Vec::from(input.script_signature.u_x().as_bytes()),
u_y: Vec::from(input.script_signature.u_y().as_bytes()),
});
if input.is_compact() {
let output_hash = input.output_hash().to_vec();
Expand Down
10 changes: 6 additions & 4 deletions applications/tari_app_grpc/src/conversions/transaction_output.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,10 +87,12 @@ impl From<TransactionOutput> for grpc::TransactionOutput {
range_proof: Vec::from(output.proof.as_bytes()),
script: output.script.to_bytes(),
sender_offset_public_key: output.sender_offset_public_key.as_bytes().to_vec(),
metadata_signature: Some(grpc::ComSignature {
public_nonce_commitment: Vec::from(output.metadata_signature.public_nonce().as_bytes()),
signature_u: Vec::from(output.metadata_signature.u().as_bytes()),
signature_v: Vec::from(output.metadata_signature.v().as_bytes()),
metadata_signature: Some(grpc::ComAndPubSignature {
ephemeral_commitment: Vec::from(output.metadata_signature.ephemeral_commitment().as_bytes()),
ephemeral_pubkey: Vec::from(output.metadata_signature.ephemeral_pubkey().as_bytes()),
u_a: Vec::from(output.metadata_signature.u_a().as_bytes()),
u_x: Vec::from(output.metadata_signature.u_x().as_bytes()),
u_y: Vec::from(output.metadata_signature.u_y().as_bytes()),
}),
covenant: output.covenant.to_bytes(),
version: output.version as u32,
Expand Down
10 changes: 6 additions & 4 deletions applications/tari_app_grpc/src/conversions/unblinded_output.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,12 @@ impl From<UnblindedOutput> for grpc::UnblindedOutput {
input_data: output.input_data.to_bytes(),
script_private_key: output.script_private_key.as_bytes().to_vec(),
sender_offset_public_key: output.sender_offset_public_key.as_bytes().to_vec(),
metadata_signature: Some(grpc::ComSignature {
public_nonce_commitment: Vec::from(output.metadata_signature.public_nonce().as_bytes()),
signature_u: Vec::from(output.metadata_signature.u().as_bytes()),
signature_v: Vec::from(output.metadata_signature.v().as_bytes()),
metadata_signature: Some(grpc::ComAndPubSignature {
ephemeral_commitment: Vec::from(output.metadata_signature.ephemeral_commitment().as_bytes()),
ephemeral_pubkey: Vec::from(output.metadata_signature.ephemeral_pubkey().as_bytes()),
u_a: Vec::from(output.metadata_signature.u_a().as_bytes()),
u_x: Vec::from(output.metadata_signature.u_x().as_bytes()),
u_y: Vec::from(output.metadata_signature.u_y().as_bytes()),
}),
script_lock_height: output.script_lock_height,
covenant: output.covenant.to_bytes(),
Expand Down
12 changes: 7 additions & 5 deletions applications/tari_console_wallet/src/automation/commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1032,13 +1032,13 @@ fn write_utxos_to_csv_file(utxos: Vec<UnblindedOutput>, file_path: PathBuf) -> R
let mut csv_file = LineWriter::new(file);
writeln!(
csv_file,
r##""index","value","spending_key","commitment","flags","maturity","script","input_data","script_private_key","sender_offset_public_key","public_nonce","signature_u","signature_v""##
r##""index","value","spending_key","commitment","flags","maturity","script","input_data","script_private_key","sender_offset_public_key","emperical_commitment","emperical_nonce","signature_u_x","signature_u_a","signature_u_y""##
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Misspelling... should be ephemeral_commitment and ephemeral_nonce.

)
.map_err(|e| CommandError::CSVFile(e.to_string()))?;
for (i, utxo) in utxos.iter().enumerate() {
writeln!(
csv_file,
r##""{}","{}","{}","{}","{:?}","{}","{}","{}","{}","{}","{}","{}","{}""##,
r##""{}","{}","{}","{}","{:?}","{}","{}","{}","{}","{}","{}","{},"{}","{}","{}""##,
i + 1,
utxo.value.0,
utxo.spending_key.to_hex(),
Expand All @@ -1052,9 +1052,11 @@ fn write_utxos_to_csv_file(utxos: Vec<UnblindedOutput>, file_path: PathBuf) -> R
utxo.input_data.to_hex(),
utxo.script_private_key.to_hex(),
utxo.sender_offset_public_key.to_hex(),
utxo.metadata_signature.public_nonce().to_hex(),
utxo.metadata_signature.u().to_hex(),
utxo.metadata_signature.v().to_hex(),
utxo.metadata_signature.ephemeral_commitment().to_hex(),
utxo.metadata_signature.ephemeral_pubkey().to_hex(),
utxo.metadata_signature.u_x().to_hex(),
utxo.metadata_signature.u_a().to_hex(),
utxo.metadata_signature.u_y().to_hex(),
)
.map_err(|e| CommandError::CSVFile(e.to_string()))?;
}
Expand Down
4 changes: 2 additions & 2 deletions base_layer/common_types/src/types/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ use tari_crypto::{
ristretto::{
bulletproofs_plus::BulletproofsPlusService,
pedersen::{extended_commitment_factory::ExtendedPedersenCommitmentFactory, PedersenCommitment},
RistrettoComSig,
RistrettoComAndPubSig,
RistrettoPublicKey,
RistrettoSchnorr,
RistrettoSecretKey,
Expand All @@ -44,7 +44,7 @@ pub use fixed_hash::{FixedHash, FixedHashSizeError};
/// employed by redefining this type.
pub type Signature = RistrettoSchnorr;
/// Define the explicit Commitment Signature implementation for the Tari base layer.
pub type ComSignature = RistrettoComSig;
pub type ComAndPubSignature = RistrettoComAndPubSig;

/// Define the explicit Commitment implementation for the Tari base layer.
pub type Commitment = PedersenCommitment;
Expand Down
Loading