Skip to content

Commit

Permalink
feat: implement metadata comsig on txn output (#3057)
Browse files Browse the repository at this point in the history
  • Loading branch information
stringhandler committed Jul 6, 2021
2 parents 868a064 + 4a3d7cc commit 8ecbb1f
Show file tree
Hide file tree
Showing 61 changed files with 5,164 additions and 4,518 deletions.
4 changes: 2 additions & 2 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.8", path = "../../base_layer/common_types"}
tari_core = { path = "../../base_layer/core"}
tari_wallet = { path = "../../base_layer/wallet"}
tari_crypto = { git = "ssh://git@github.com/tari-project/tari-crypto.git", branch = "main" } #switch back to official after merge
tari_crypto = { git = "https://github.com/tari-project/tari-crypto.git", rev = "ecd77ec2b" } #switch back to official after merge
tari_comms = { path = "../../comms"}

chrono = "0.4.6"
Expand Down
13 changes: 7 additions & 6 deletions applications/tari_app_grpc/proto/types.proto
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ message TransactionInput {
// A signature with k_s, signing the script, input data, and mined height
ComSignature script_signature = 7;
// The offset public key, K_O
bytes script_offset_public_key = 8;
bytes sender_offset_public_key = 8;
}

// Output for a transaction, defining the new ownership of coins that are being transferred. The commitment is a
Expand All @@ -186,9 +186,10 @@ message TransactionOutput {
// Tari script serialised script
bytes script = 5;
// Tari script offset public key, K_O
bytes script_offset_public_key = 6;
// UTXO signature with the script offset private key, k_O
Signature sender_metadata_signature = 7;
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;
}

// Options for UTXO's
Expand Down Expand Up @@ -318,7 +319,7 @@ message UnblindedOutput {
// Tari script private key
bytes script_private_key = 7;
// Tari script offset pubkey, K_O
bytes script_offset_public_key = 8;
bytes sender_offset_public_key = 8;
// UTXO signature with the script offset private key, k_O
Signature sender_metadata_signature = 9;
ComSignature metadata_signature = 9;
}
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@ impl TryFrom<grpc::TransactionInput> for TransactionInput {
.try_into()
.map_err(|_| "script_signature could not be converted".to_string())?;

let script_offset_public_key =
PublicKey::from_bytes(input.script_offset_public_key.as_bytes()).map_err(|err| format!("{:?}", err))?;
let sender_offset_public_key =
PublicKey::from_bytes(input.sender_offset_public_key.as_bytes()).map_err(|err| format!("{:?}", err))?;
let script = TariScript::from_bytes(input.script.as_slice()).map_err(|err| format!("{:?}", err))?;
let input_data = ExecutionStack::from_bytes(input.input_data.as_slice()).map_err(|err| format!("{:?}", err))?;

Expand All @@ -60,7 +60,7 @@ impl TryFrom<grpc::TransactionInput> for TransactionInput {
script,
input_data,
script_signature,
script_offset_public_key,
sender_offset_public_key,
})
}
}
Expand All @@ -82,7 +82,7 @@ impl From<TransactionInput> for grpc::TransactionInput {
signature_u: Vec::from(input.script_signature.u().as_bytes()),
signature_v: Vec::from(input.script_signature.v().as_bytes()),
}),
script_offset_public_key: input.script_offset_public_key.as_bytes().to_vec(),
sender_offset_public_key: input.sender_offset_public_key.as_bytes().to_vec(),
}
}
}
25 changes: 13 additions & 12 deletions applications/tari_app_grpc/src/conversions/transaction_output.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,25 +43,25 @@ impl TryFrom<grpc::TransactionOutput> for TransactionOutput {

let commitment = Commitment::from_bytes(&output.commitment)
.map_err(|err| format!("Invalid output commitment: {}", err.to_string()))?;
let script_offset_public_key = PublicKey::from_bytes(output.script_offset_public_key.as_bytes())
.map_err(|err| format!("Invalid script_offset_public_key {:?}", err))?;
let sender_offset_public_key = PublicKey::from_bytes(output.sender_offset_public_key.as_bytes())
.map_err(|err| format!("Invalid sender_offset_public_key {:?}", err))?;

let script = TariScript::from_bytes(output.script.as_slice())
.map_err(|err| format!("Script deserialization: {:?}", err))?;

let sender_metadata_signature = output
.sender_metadata_signature
.ok_or_else(|| "Sender signature not provided".to_string())?
let metadata_signature = output
.metadata_signature
.ok_or_else(|| "Metadata signature not provided".to_string())?
.try_into()
.map_err(|_| "Sender signature could not be converted".to_string())?;
.map_err(|_| "Metadata signature could not be converted".to_string())?;

Ok(Self {
features,
commitment,
proof: BulletRangeProof(output.range_proof),
script,
script_offset_public_key,
sender_metadata_signature,
sender_offset_public_key,
metadata_signature,
})
}
}
Expand All @@ -78,10 +78,11 @@ impl From<TransactionOutput> for grpc::TransactionOutput {
commitment: Vec::from(output.commitment.as_bytes()),
range_proof: Vec::from(output.proof.as_bytes()),
script: output.script.as_bytes(),
script_offset_public_key: output.script_offset_public_key.as_bytes().to_vec(),
sender_metadata_signature: Some(grpc::Signature {
public_nonce: Vec::from(output.sender_metadata_signature.get_public_nonce().as_bytes()),
signature: Vec::from(output.sender_metadata_signature.get_signature().as_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()),
}),
}
}
Expand Down
25 changes: 13 additions & 12 deletions applications/tari_app_grpc/src/conversions/unblinded_output.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,11 @@ impl From<UnblindedOutput> for grpc::UnblindedOutput {
script: output.script.as_bytes(),
input_data: output.input_data.as_bytes(),
script_private_key: output.script_private_key.as_bytes().to_vec(),
script_offset_public_key: output.script_offset_public_key.as_bytes().to_vec(),
sender_metadata_signature: Some(grpc::Signature {
public_nonce: Vec::from(output.sender_metadata_signature.get_public_nonce().as_bytes()),
signature: Vec::from(output.sender_metadata_signature.get_signature().as_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()),
}),
}
}
Expand All @@ -73,14 +74,14 @@ impl TryFrom<grpc::UnblindedOutput> for UnblindedOutput {
let script_private_key = PrivateKey::from_bytes(output.script_private_key.as_bytes())
.map_err(|e| format!("script_private_key: {:?}", e))?;

let script_offset_public_key = PublicKey::from_bytes(output.script_offset_public_key.as_bytes())
.map_err(|err| format!("script_offset_public_key {:?}", err))?;
let sender_offset_public_key = PublicKey::from_bytes(output.sender_offset_public_key.as_bytes())
.map_err(|err| format!("sender_offset_public_key {:?}", err))?;

let sender_metadata_signature = output
.sender_metadata_signature
.ok_or_else(|| "Sender signature not provided".to_string())?
let metadata_signature = output
.metadata_signature
.ok_or_else(|| "Metadata signature not provided".to_string())?
.try_into()
.map_err(|_| "Sender signature could not be converted".to_string())?;
.map_err(|_| "Metadata signature could not be converted".to_string())?;

Ok(Self {
value: MicroTari::from(output.value),
Expand All @@ -89,8 +90,8 @@ impl TryFrom<grpc::UnblindedOutput> for UnblindedOutput {
script,
input_data,
script_private_key,
script_offset_public_key,
sender_metadata_signature,
sender_offset_public_key,
metadata_signature,
})
}
}
2 changes: 1 addition & 1 deletion applications/tari_app_utilities/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ edition = "2018"

[dependencies]
tari_comms = { path = "../../comms"}
tari_crypto = { git = "ssh://git@github.com/tari-project/tari-crypto.git", branch = "main" }
tari_crypto = { git = "https://github.com/tari-project/tari-crypto.git", rev = "ecd77ec2b" }
tari_common = { path = "../../common" }
tari_p2p = { path = "../../base_layer/p2p", features = ["auto-update"] }
tari_wallet = { path = "../../base_layer/wallet" }
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 @@ -14,7 +14,7 @@ tari_common = { path = "../../common" }
tari_comms = { path = "../../comms", features = ["rpc"]}
tari_comms_dht = { path = "../../comms/dht"}
tari_core = { path = "../../base_layer/core", default-features = false, features = ["transactions"]}
tari_crypto = { git = "ssh://git@github.com/tari-project/tari-crypto.git", branch = "main" }
tari_crypto = { git = "https://github.com/tari-project/tari-crypto.git", rev = "ecd77ec2b" }
tari_mmr = { path = "../../base_layer/mmr" }
tari_p2p = { path = "../../base_layer/p2p", features = ["auto-update"] }
tari_service_framework = { path = "../../base_layer/service_framework"}
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 @@ -6,7 +6,7 @@ edition = "2018"

[dependencies]
tari_wallet = { path = "../../base_layer/wallet" }
tari_crypto = { git = "ssh://git@github.com/tari-project/tari-crypto.git", branch = "main" }
tari_crypto = { git = "https://github.com/tari-project/tari-crypto.git", rev = "ecd77ec2b" }
tari_common = { path = "../../common" }
tari_app_utilities = { path = "../tari_app_utilities"}
tari_comms = { path = "../../comms"}
Expand Down
11 changes: 6 additions & 5 deletions applications/tari_console_wallet/src/automation/commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -645,13 +645,13 @@ fn write_utxos_to_csv_file(utxos: Vec<UnblindedOutput>, file_path: String) -> Re
let mut csv_file = LineWriter::new(file);
writeln!(
csv_file,
r##""index","value","spending_key","commitment","flags","maturity","script","input_data","script_private_key","script_offset_public_key","signature","public_nonce""##
r##""index","value","spending_key","commitment","flags","maturity","script","input_data","script_private_key","sender_offset_public_key","public_nonce","signature_u","signature_v""##
)
.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 @@ -661,9 +661,10 @@ fn write_utxos_to_csv_file(utxos: Vec<UnblindedOutput>, file_path: String) -> Re
utxo.script.to_hex(),
utxo.input_data.to_hex(),
utxo.script_private_key.to_hex(),
utxo.script_offset_public_key.to_hex(),
utxo.sender_metadata_signature.get_signature().to_hex(),
utxo.sender_metadata_signature.get_public_nonce().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(),
)
.map_err(|e| CommandError::CSVFile(e.to_string()))?;
}
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 @@ -16,7 +16,7 @@ tari_app_grpc = { path = "../tari_app_grpc" }
tari_common = { path = "../../common" }
tari_core = { path = "../../base_layer/core", default-features = false, features = ["transactions"]}
tari_app_utilities = { path = "../tari_app_utilities"}
tari_crypto = { git = "ssh://git@github.com/tari-project/tari-crypto.git", branch = "main" }
tari_crypto = { git = "https://github.com/tari-project/tari-crypto.git", rev = "ecd77ec2b" }
tari_utilities = "^0.3"

anyhow = "1.0.40"
Expand Down
2 changes: 1 addition & 1 deletion applications/tari_mining_node/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,6 @@ thiserror = "1.0"


[dev-dependencies]
tari_crypto = { git = "ssh://git@github.com/tari-project/tari-crypto.git", branch = "main" }
tari_crypto = { git = "https://github.com/tari-project/tari-crypto.git", rev = "ecd77ec2b" }
prost-types = "0.6.1"
chrono = "0.4"
2 changes: 1 addition & 1 deletion applications/test_faucet/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ tari_utilities = "^0.3"
serde = { version = "1.0.97", features = ["derive"] }
serde_json = "1.0"
rand = "0.7.2"
tari_crypto = { git = "ssh://git@github.com/tari-project/tari-crypto.git", branch = "main" }
tari_crypto = { git = "https://github.com/tari-project/tari-crypto.git", rev = "ecd77ec2b" }

[dependencies.tari_core]
version = "^0.8"
Expand Down
2 changes: 1 addition & 1 deletion base_layer/common_types/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@ edition = "2018"
[dependencies]
futures = {version = "^0.3.1", features = ["async-await"] }
rand = "0.7.2"
tari_crypto = { git = "ssh://git@github.com/tari-project/tari-crypto.git", branch = "main" }
tari_crypto = { git = "https://github.com/tari-project/tari-crypto.git", rev = "ecd77ec2b" }
serde = { version = "1.0.106", features = ["derive"] }
tokio = { version="^0.2", features = ["blocking", "time", "sync"] }
2 changes: 1 addition & 1 deletion base_layer/core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ tari_common_types = { version = "^0.8", path = "../../base_layer/common_types"}
tari_comms = { version = "^0.8", path = "../../comms"}
tari_comms_dht = { version = "^0.8", path = "../../comms/dht"}
tari_comms_rpc_macros = { version = "^0.8", path = "../../comms/rpc_macros"}
tari_crypto = { git = "ssh://git@github.com/tari-project/tari-crypto.git", branch = "main" }
tari_crypto = { git = "https://github.com/tari-project/tari-crypto.git", rev = "ecd77ec2b" }
tari_mmr = { version = "^0.8", path = "../../base_layer/mmr", optional = true }
tari_p2p = { version = "^0.8", path = "../../base_layer/p2p" }
tari_service_framework = { version = "^0.8", path = "../service_framework"}
Expand Down
Loading

0 comments on commit 8ecbb1f

Please sign in to comment.