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

Conversation

SWvheerden
Copy link
Collaborator

@SWvheerden SWvheerden commented Nov 23, 2022

Description

Replaces PR #4733
This updates CommitmentSignature to CommitmentAndPublicKeySignature for transaction authorization.
Includes a new Gen block

Motivation and Context

See issue: #4734

How Has This Been Tested?

Unit tests

BREAKING CHANGE: Commitment signature proof has changed

WIP

WIP: size typo

wip

Auto stash before checking out "origin/development"

wip

wip
@SWvheerden SWvheerden added the W-consensus_breaking Warn - A change requiring a hard fork to be activated label Nov 23, 2022
@stringhandler stringhandler merged commit 00e98f9 into tari-project:development Nov 23, 2022
@SWvheerden SWvheerden deleted the sw_comsig branch November 24, 2022 12:24
@@ -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.

@@ -170,7 +172,8 @@ impl TransactionInput {
match version {
TransactionInputVersion::V0 | TransactionInputVersion::V1 => {
DomainSeparatedConsensusHasher::<TransactionHashDomain>::new("script_challenge")
Copy link
Collaborator

Choose a reason for hiding this comment

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

May want to use the reverse-domain standard for this label, in order to be more consistent with other uses of the hashing API elsewhere in the codebase.

/// Convenience function that calculates the challenge for the metadata commitment signature
pub fn build_metadata_signature_challenge(
version: TransactionOutputVersion,
script: &TariScript,
features: &OutputFeatures,
sender_offset_public_key: &PublicKey,
public_commitment_nonce: &Commitment,
ephemeral_commitment: &Commitment,
ephemeral_pubkey: &PublicKey,
commitment: &Commitment,
covenant: &Covenant,
encrypted_value: &EncryptedValue,
minimum_value_promise: MicroTari,
) -> [u8; 32] {
let common = DomainSeparatedConsensusHasher::<TransactionHashDomain>::new("metadata_signature")
Copy link
Collaborator

Choose a reason for hiding this comment

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

May want to use the reverse-domain standard for this label, in order to be more consistent with other uses of the hashing API elsewhere in the codebase.

let aggregated_metadata_signature = ComSignature::new(r_pub_aggregated, u_aggregated, v.clone());

let sender_offset_public_key = PublicKey::from_secret_key(sender_offset_private_key);
let aggregated_metadata_signature = &sender_signature + &output.metadata_signature;
Copy link
Collaborator

Choose a reason for hiding this comment

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

It's possible that the recipient maliciously provided its own values for ephemeral_pubkey or u_y before returning it to the sender. Provided the output's sender offset public key cannot be overwritten by the recipient in a way that forces the sender to include it in the challenge, this will be caught by the verification check below, but could also be short-circuited by asserting that the recipient's partial metadata signature has ephemeral_pubkey == u_y == 0.

Copy link
Collaborator

Choose a reason for hiding this comment

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

It may also be a good idea to include this check anyway for defense in depth.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

When doing m-of-n this will need to be bypassed. I prefer a one fit for all check.

But yeah if the recipient changes ephemeral_pubkey or u_y the check below will fail and the signature will not pass.

The recipient can at all times replace sender offset public key and create a new signature at will, but this will break the script_offset of the transaction.

@AaronFeickert
Copy link
Collaborator

An even safer approach to partial metadata signatures would be not to add them at all (which is where you could get recipient shenanigans), but instead to build a fresh metadata signature from the appropriate constituent parts provided by the sender and recipient. This would eliminate the possibility of unexpected values included in partial signatures.

@SWvheerden
Copy link
Collaborator Author

One thing to keep in mind with these signatures, is that the main thing that stop any recipient shenanigans is script_offset
Nothing stops the recipient or anybody who knows the blinding factor of the commitment being created to put a new sender_offset_public_key on the utxo and create a new fake signature that verifies. This is not stoppable on the utxo.
The only thing that stops this is the script_offset

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
W-consensus_breaking Warn - A change requiring a hard fork to be activated
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants