From e3068d12b890fed66b3df01ecef87bd5d70e6ebb Mon Sep 17 00:00:00 2001 From: Hansie Odendaal Date: Wed, 10 Jul 2024 05:16:43 +0200 Subject: [PATCH] review comments --- .../src/automation/commands.rs | 148 ++++++++++-------- .../minotari_console_wallet/src/cli.rs | 40 ++--- .../src/wallet_modes.rs | 73 +++++---- .../src/output_manager_service/handle.rs | 17 +- .../src/output_manager_service/service.rs | 17 +- .../wallet/src/transaction_service/handle.rs | 14 +- .../wallet/src/transaction_service/service.rs | 7 +- 7 files changed, 184 insertions(+), 132 deletions(-) diff --git a/applications/minotari_console_wallet/src/automation/commands.rs b/applications/minotari_console_wallet/src/automation/commands.rs index e140a2f993..207e399e61 100644 --- a/applications/minotari_console_wallet/src/automation/commands.rs +++ b/applications/minotari_console_wallet/src/automation/commands.rs @@ -83,7 +83,7 @@ use tari_core::{ }, }, }; -use tari_crypto::ristretto::RistrettoSecretKey; +use tari_crypto::ristretto::{pedersen::PedersenCommitment, RistrettoSecretKey}; use tari_key_manager::key_manager_service::KeyManagerInterface; use tari_script::{script, ExecutionStack, TariScript}; use tari_utilities::{hex::Hex, ByteArray}; @@ -167,6 +167,7 @@ async fn encumber_aggregate_utxo( mut wallet_transaction_service: TransactionServiceHandle, fee_per_gram: MicroMinotari, output_hash: String, + expected_commitment: PedersenCommitment, script_input_shares: Vec, script_public_key_shares: Vec, script_signature_public_nonces: Vec, @@ -179,6 +180,7 @@ async fn encumber_aggregate_utxo( .encumber_aggregate_utxo( fee_per_gram, output_hash, + expected_commitment, script_input_shares, script_public_key_shares, script_signature_public_nonces, @@ -734,19 +736,19 @@ pub async fn command_runner( Err(e) => eprintln!("BurnMinotari error! {}", e), } }, - CreateKeyPair(args) => match key_manager_service.create_key_pair(args.key_branch).await { + FaucetCreateKeyPair(args) => match key_manager_service.create_key_pair(args.key_branch).await { Ok((key_id, pk)) => { println!( "New key pair: - 1. key id : {}, - 2. public key: {}", + 1. key id : {}, + 2. public key: {}", key_id, pk.to_hex() ) }, Err(e) => eprintln!("CreateKeyPair error! {}", e), }, - CreateAggregateSignatureUtxo(args) => match create_aggregate_signature_utxo( + FaucetCreateAggregateSignatureUtxo(args) => match create_aggregate_signature_utxo( transaction_service.clone(), args.amount, args.fee_per_gram, @@ -763,7 +765,7 @@ pub async fn command_runner( { Ok((tx_id, output_hash)) => { println!( - "Created an utxo with n-of-m aggregate public key, with: + "Created a UTXO with n-of-m aggregate public key, with: 1. n = {}, 2. m = {}, 3. tx id = {}, @@ -773,7 +775,7 @@ pub async fn command_runner( }, Err(e) => eprintln!("CreateAggregateSignatureUtxo error! {}", e), }, - SignMessage(args) => { + FaucetSignMessage(args) => { match key_manager_service .sign_script_message(&args.private_key_id, args.challenge.as_bytes()) .await @@ -781,9 +783,9 @@ pub async fn command_runner( // 1. What is the message/challenge? => commitment Ok(sgn) => { println!( - "Sign message: - 1. signature: {}, - 2. public nonce: {}", + "Signed message: + 1. signature: {}, + 2. public nonce: {}", sgn.get_signature().to_hex(), sgn.get_public_nonce().to_hex(), ) @@ -792,63 +794,69 @@ pub async fn command_runner( } }, FaucetCreatePartyDetails(args) => { - let spend_key = wallet.get_wallet_id().await?.wallet_node_key_id.clone(); - let public_spend_key = key_manager_service.get_public_key_at_key_id(&spend_key).await?; - let (script_nonce, public_script_nonce) = key_manager_service.get_random_key().await?; + let wallet_spend_key_id = wallet.get_wallet_id().await?.wallet_node_key_id.clone(); + let wallet_public_spend_key = key_manager_service + .get_public_key_at_key_id(&wallet_spend_key_id) + .await?; + let (script_nonce_key_id, public_script_nonce) = key_manager_service.get_random_key().await?; - let (sender_offset_key, public_sender_offset_key) = key_manager_service + let (sender_offset_key_id, public_sender_offset_key) = key_manager_service .get_next_key(TransactionKeyManagerBranch::SenderOffset.get_branch_key()) .await?; - let (sender_offset_nonce, public_sender_offset_nonce) = key_manager_service.get_random_key().await?; + let (sender_offset_nonce_key_id, public_sender_offset_nonce) = + key_manager_service.get_random_key().await?; let commitment = Commitment::from_hex(&args.commitment)?; - let com_hash: [u8; 32] = + let commitment_hash: [u8; 32] = DomainSeparatedConsensusHasher::>::new("com_hash") .chain(&commitment) .finalize() .into(); let shared_secret = key_manager_service .get_diffie_hellman_shared_secret( - &sender_offset_key, - args.destination + &sender_offset_key_id, + args.recipient_address .public_view_key() .ok_or(CommandError::InvalidArgument("Missing public view key".to_string()))?, ) .await?; - let shared_secret_key = PublicKey::from_canonical_bytes(shared_secret.as_bytes())?; + let shared_secret_public_key = PublicKey::from_canonical_bytes(shared_secret.as_bytes())?; - let signature = key_manager_service.sign_script_message(&spend_key, &com_hash).await?; + let script_input_signature = key_manager_service + .sign_script_message(&wallet_spend_key_id, &commitment_hash) + .await?; println!( - "Sign message: - 1. signature: ({},{}), - 2. public spend key: {}, - 2. public spend key_id: {}, - 4. spend nonce key: {}, - 5. public spend nonce key: {}, - 6. sender offset key: {}, - 7. public sender offset key: {}, - 8. sender offset nonce key: {}, - 9. public sender offset nonce key: {}, - 10. shared secret: {}", - signature.get_signature().to_hex(), - signature.get_public_nonce().to_hex(), - public_spend_key, - spend_key, - script_nonce, + "Party details created with: + 1. script input signature: ({},{}), + 2. wallet public spend key: {}, + 3. wallet public spend key_id: {}, + 4. spend nonce key_id: {}, + 5. public spend nonce key: {}, + 6. sender offset key_id: {}, + 7. public sender offset key: {}, + 8. sender offset nonce key_id: {}, + 9. public sender offset nonce key: {}, + 10. public shared secret: {}", + script_input_signature.get_signature().to_hex(), + script_input_signature.get_public_nonce().to_hex(), + wallet_public_spend_key, + wallet_spend_key_id, + script_nonce_key_id, public_script_nonce, - sender_offset_key, + sender_offset_key_id, public_sender_offset_key, - sender_offset_nonce, + sender_offset_nonce_key_id, public_sender_offset_nonce, - shared_secret_key + shared_secret_public_key ); }, - EncumberAggregateUtxo(args) => { + FaucetEncumberAggregateUtxo(args) => { match encumber_aggregate_utxo( transaction_service.clone(), args.fee_per_gram, args.output_hash, + Commitment::from_hex(&args.commitment)?, args.script_input_shares .iter() .map(|v| v.clone().into()) @@ -885,22 +893,22 @@ pub async fn command_runner( total_script_nonce, )) => { println!( - "Encumber aggregate utxo: - 1. Tx_id: {} - 2. input_commitment: {}, - 3. input_stack: {}, - 4. input_script: {}, - 5. total_script_key: {}, - 6. script_signature_ephemeral_commitment: {}, - 7. script_signature_ephemeral_pubkey: {}, - 8. output_commitment: {}, - 9. output_hash: {}, - 10. sender_offset_pubkey: {}, - 11. meta_signature_ephemeral_commitment: {}, - 12. meta_signature_ephemeral_pubkey: {}, - 13. total_public_offset: {}, - 14. encrypted_data: {}, - 15. output_features: {}", + "Encumbered aggregate UTXO: + 1. tx_id: {}, + 2. input_commitment: {}, + 3. input_stack: {}, + 4. input_script: {}, + 5. total_script_key: {}, + 6. script_signature_ephemeral_commitment: {}, + 7. script_signature_ephemeral_pubkey: {}, + 8. output_commitment: {}, + 9. output_hash: {}, + 10. sender_offset_pubkey: {}, + 11. meta_signature_ephemeral_commitment: {}, + 12. meta_signature_ephemeral_pubkey: {}, + 13. total_public_offset: {}, + 14. encrypted_data: {}, + 15. output_features: {}", tx_id, transaction.body.inputs()[0].commitment().unwrap().to_hex(), transaction.body.inputs()[0].input_data.to_hex(), @@ -928,7 +936,7 @@ pub async fn command_runner( Err(e) => println!("Encumber aggregate transaction error! {}", e), } }, - SpendAggregateUtxo(args) => { + FaucetSpendAggregateUtxo(args) => { let mut offset = PrivateKey::default(); for key in args.script_offset_keys { let secret_key = @@ -955,7 +963,7 @@ pub async fn command_runner( Err(e) => println!("Error completing transaction! {}", e), } }, - CreateScriptSig(args) => { + FaucetCreateScriptSig(args) => { let script = TariScript::from_hex(&args.input_script) .map_err(|e| CommandError::InvalidArgument(e.to_string()))?; let input_data = ExecutionStack::from_hex(&args.input_stack) @@ -976,12 +984,12 @@ pub async fn command_runner( ); match key_manager_service - .sign_with_nonce_and_message(&args.private_key_id, &args.secret_nonce, &challenge) + .sign_with_nonce_and_message(&args.private_key_id, &args.secret_nonce_key_id, &challenge) .await { Ok(signature) => { println!( - "Sign script sig: + "Script signature created: 1. signature: ({},{})", signature.get_signature().to_hex(), signature.get_public_nonce().to_hex(), @@ -990,10 +998,10 @@ pub async fn command_runner( Err(e) => eprintln!("SignMessage error! {}", e), } }, - CreateMetaSig(args) => { + FaucetCreateMetaSig(args) => { let offset = key_manager_service - .get_script_offset(&vec![args.secret_script_key], &vec![args - .secret_sender_offset_key + .get_script_offset(&vec![args.secret_script_key_id], &vec![args + .secret_sender_offset_key_id .clone()]) .await?; let script = script!(PushPubKey(Box::new(args.recipient_address.public_spend_key().clone()))); @@ -1036,16 +1044,20 @@ pub async fn command_runner( &encrypted_data, minimum_value_promise, ); - trace!(target: LOG_TARGET, "meta challange: {:?}", challenge); + trace!(target: LOG_TARGET, "meta challenge: {:?}", challenge); match key_manager_service - .sign_with_nonce_and_message(&args.secret_sender_offset_key, &args.secret_nonce, &challenge) + .sign_with_nonce_and_message( + &args.secret_sender_offset_key_id, + &args.secret_nonce_key_id, + &challenge, + ) .await { Ok(signature) => { println!( - "1. Meta sig: - signature: ({},{}), - 2. Script offset: {}", + "Metadata signature created: + 1. signature: ({},{}), + 2. script offset: {}", signature.get_signature().to_hex(), signature.get_public_nonce().to_hex(), offset.to_hex(), diff --git a/applications/minotari_console_wallet/src/cli.rs b/applications/minotari_console_wallet/src/cli.rs index 10a570a48a..b088efaf83 100644 --- a/applications/minotari_console_wallet/src/cli.rs +++ b/applications/minotari_console_wallet/src/cli.rs @@ -119,14 +119,14 @@ pub enum CliCommands { GetBalance, SendMinotari(SendMinotariArgs), BurnMinotari(BurnMinotariArgs), - CreateKeyPair(CreateKeyPairArgs), - CreateAggregateSignatureUtxo(CreateAggregateSignatureUtxoArgs), - EncumberAggregateUtxo(EncumberAggregateUtxoArgs), - SpendAggregateUtxo(SpendAggregateUtxoArgs), - SignMessage(SignMessageArgs), + FaucetCreateKeyPair(FaucetCreateKeyPairArgs), + FaucetCreateAggregateSignatureUtxo(FaucetCreateAggregateSignatureUtxoArgs), + FaucetEncumberAggregateUtxo(FaucetEncumberAggregateUtxoArgs), + FaucetSpendAggregateUtxo(FaucetSpendAggregateUtxoArgs), + FaucetSignMessage(FaucetSignMessageArgs), FaucetCreatePartyDetails(FaucetCreatePartyDetailsArgs), - CreateScriptSig(CreateScriptSigArgs), - CreateMetaSig(CreateMetaSigArgs), + FaucetCreateScriptSig(FaucetCreateScriptSigArgs), + FaucetCreateMetaSig(FaucetCreateMetaSigArgs), SendOneSidedToStealthAddress(SendMinotariArgs), MakeItRain(MakeItRainArgs), CoinSplit(CoinSplitArgs), @@ -169,13 +169,13 @@ pub struct BurnMinotariArgs { } #[derive(Debug, Args, Clone)] -pub struct CreateKeyPairArgs { +pub struct FaucetCreateKeyPairArgs { #[clap(long)] pub key_branch: String, } #[derive(Debug, Args, Clone)] -pub struct CreateAggregateSignatureUtxoArgs { +pub struct FaucetCreateAggregateSignatureUtxoArgs { #[clap(long)] pub amount: MicroMinotari, #[clap(long)] @@ -197,11 +197,11 @@ pub struct FaucetCreatePartyDetailsArgs { #[clap(long)] pub commitment: String, #[clap(long)] - pub destination: TariAddress, + pub recipient_address: TariAddress, } #[derive(Debug, Args, Clone)] -pub struct SignMessageArgs { +pub struct FaucetSignMessageArgs { #[clap(long)] pub private_key_id: TariKeyId, #[clap(long)] @@ -209,10 +209,12 @@ pub struct SignMessageArgs { } #[derive(Debug, Args, Clone)] -pub struct EncumberAggregateUtxoArgs { +pub struct FaucetEncumberAggregateUtxoArgs { #[clap(long)] pub fee_per_gram: MicroMinotari, #[clap(long)] + pub commitment: String, + #[clap(long)] pub output_hash: String, #[clap(long)] pub script_input_shares: Vec, @@ -231,7 +233,7 @@ pub struct EncumberAggregateUtxoArgs { } #[derive(Debug, Args, Clone)] -pub struct SpendAggregateUtxoArgs { +pub struct FaucetSpendAggregateUtxoArgs { #[clap(long)] pub tx_id: u64, #[clap(long)] @@ -243,11 +245,11 @@ pub struct SpendAggregateUtxoArgs { } #[derive(Debug, Args, Clone)] -pub struct CreateScriptSigArgs { +pub struct FaucetCreateScriptSigArgs { #[clap(long)] pub private_key_id: TariKeyId, #[clap(long)] - pub secret_nonce: TariKeyId, + pub secret_nonce_key_id: TariKeyId, #[clap(long)] pub input_script: String, #[clap(long)] @@ -263,13 +265,13 @@ pub struct CreateScriptSigArgs { } #[derive(Debug, Args, Clone)] -pub struct CreateMetaSigArgs { +pub struct FaucetCreateMetaSigArgs { #[clap(long)] - pub secret_script_key: TariKeyId, + pub secret_script_key_id: TariKeyId, #[clap(long)] - pub secret_sender_offset_key: TariKeyId, + pub secret_sender_offset_key_id: TariKeyId, #[clap(long)] - pub secret_nonce: TariKeyId, + pub secret_nonce_key_id: TariKeyId, #[clap(long)] pub ephemeral_commitment: String, #[clap(long)] diff --git a/applications/minotari_console_wallet/src/wallet_modes.rs b/applications/minotari_console_wallet/src/wallet_modes.rs index 8bd9e03f14..85063a058e 100644 --- a/applications/minotari_console_wallet/src/wallet_modes.rs +++ b/applications/minotari_console_wallet/src/wallet_modes.rs @@ -496,9 +496,9 @@ mod test { burn-minotari --message Ups_these_funds_will_be_burned! 100T - create-key-pair --key-branch pie + faucet-create-key-pair --key-branch pie - create-aggregate-signature-utxo \ + faucet-create-aggregate-signature-utxo \ --amount 125T \ --fee-per-gram 1 \ --n 3 \ @@ -508,13 +508,14 @@ mod test { --public-keys=5c4f2a4b3f3f84e047333218a84fd24f581a9d7e4f23b78e3714e9d174427d61 \ --public-keys=f6b2ca781342a3ebe30ee1643655c96f1d7c14f4d49f077695395de98ae73665 - sign-message \ + faucet-sign-message \ --private-key-id imported.96159b07298a453c9f514f5307f70659c7561dd6d9ed376854c5cb573cb2e311 \ --challenge f6b2ca781342a3ebe30ee1643655c96f1d7c14f4d49f077695395de98ae73665 - encumber-aggregate-utxo \ + faucet-encumber-aggregate-utxo \ --fee-per-gram 1 \ --output-hash f6b2ca781342a3ebe30ee1643655c96f1d7c14f4d49f077695395de98ae73665 \ + --commitment f6b2ca781342a3ebe30ee1643655c96f1d7c14f4d49f077695395de98ae73665 \ --script-input-shares=3ddde10d0775c20fb25015546c6a8068812044e7ca4ee1057e84ec9ab6705d03,8a55d1cb503be36875d38f2dc6abac7b23445bbd7253684a1506f5ee1855cd58 \ --script-input-shares=3edf1ed103b0ac0bbad6a6de8369808d14dfdaaf294fe660646875d749a1f908,50a26c646db951720c919f59cd7a34600a7fc3ee978c64fbcce0ad184c46844c \ --script-public-key-shares=5c4f2a4b3f3f84e047333218a84fd24f581a9d7e4f23b78e3714e9d174427d61 \ @@ -529,7 +530,7 @@ mod test { --dh-shared-secret-shares=f6b2ca781342a3ebe30ee1643655c96f1d7c14f4d49f077695395de98ae73665 \ --recipient-address f4LR9f6WwwcPiKJjK5ciTkU1ocNhANa3FPw1wkyVUwbuKpgiihawCXy6PFszunUWQ4Te8KVFnyWVHHwsk9x5Cg7ZQiA - spend-aggregate-utxo \ + faucet-spend-aggregate-utxo \ --tx-id 12345678 \ --meta-signatures=3ddde10d0775c20fb25015546c6a8068812044e7ca4ee1057e84ec9ab6705d03,8a55d1cb503be36875d38f2dc6abac7b23445bbd7253684a1506f5ee1855cd58 \ --meta-signatures=3edf1ed103b0ac0bbad6a6de8369808d14dfdaaf294fe660646875d749a1f908,50a26c646db951720c919f59cd7a34600a7fc3ee978c64fbcce0ad184c46844c \ @@ -538,9 +539,13 @@ mod test { --script-offset-keys=5c4f2a4b3f3f84e047333218a84fd24f581a9d7e4f23b78e3714e9d174427d61 \ --script-offset-keys=f6b2ca781342a3ebe30ee1643655c96f1d7c14f4d49f077695395de98ae73665 - create-script-sig \ + faucet-create-party-details \ + --commitment f6b2ca781342a3ebe30ee1643655c96f1d7c14f4d49f077695395de98ae73665 \ + --recipient-address f4LR9f6WwwcPiKJjK5ciTkU1ocNhANa3FPw1wkyVUwbuKpgiihawCXy6PFszunUWQ4Te8KVFnyWVHHwsk9x5Cg7ZQiA + + faucet-create-script-sig \ --private-key-id imported.96159b07298a453c9f514f5307f70659c7561dd6d9ed376854c5cb573cb2e311 \ - --secret-nonce imported.96159b07298a453c9f514f5307f70659c7561dd6d9ed376854c5cb573cb2e311 \ + --secret-nonce-key-id imported.96159b07298a453c9f514f5307f70659c7561dd6d9ed376854c5cb573cb2e311 \ --input-script ae010268593ed2d36a2d95f0ffe0f41649b97cc36fc4ef0c8ecd6bd28f9d56c76b793b08691435a5c813578f8a7f4973166dc1c6c15f37aec2a7d65b1583c8b2129364c916d5986a0c1b3dac7d6efb94bed688ba52fa8b962cf27c0446e2fea6d66a04 \ --input-stack 050857c14f72cf885aac9f08c9484cb7cb06b6cc20eab68c9bee1e8d5a85649b0a6d31c5cc49afc1e03ebbcf55c82f47e8cbc796c33e96c17a31eab027ee821f00 \ --ephemeral-commitment f6b2ca781342a3ebe30ee1643655c96f1d7c14f4d49f077695395de98ae73665 \ @@ -548,10 +553,10 @@ mod test { --total-script-key 5c4f2a4b3f3f84e047333218a84fd24f581a9d7e4f23b78e3714e9d174427d61 \ --commitment 94966b4f1b5dc050df1109cf07a516ae85912c82503b1a8c1625986a569fae67 - create-meta-sig \ - --secret-script-key imported.96159b07298a453c9f514f5307f70659c7561dd6d9ed376854c5cb573cb2e311 \ - --secret-sender-offset-key imported.96159b07298a453c9f514f5307f70659c7561dd6d9ed376854c5cb573cb2e311 \ - --secret-nonce imported.96159b07298a453c9f514f5307f70659c7561dd6d9ed376854c5cb573cb2e311 \ + faucet-create-meta-sig \ + --secret-script-key-id imported.96159b07298a453c9f514f5307f70659c7561dd6d9ed376854c5cb573cb2e311 \ + --secret-sender-offset-key-id imported.96159b07298a453c9f514f5307f70659c7561dd6d9ed376854c5cb573cb2e311 \ + --secret-nonce-key-id imported.96159b07298a453c9f514f5307f70659c7561dd6d9ed376854c5cb573cb2e311 \ --ephemeral-commitment f6b2ca781342a3ebe30ee1643655c96f1d7c14f4d49f077695395de98ae73665 \ --ephemeral-pubkey 8a55d1cb503be36875d38f2dc6abac7b23445bbd7253684a1506f5ee1855cd58 \ --total-meta-key 5c4f2a4b3f3f84e047333218a84fd24f581a9d7e4f23b78e3714e9d174427d61 \ @@ -579,13 +584,14 @@ mod test { let mut get_balance = false; let mut send_tari = false; let mut burn_tari = false; - let mut create_key_pair = false; - let mut create_aggregate_signature_utxo = false; - let mut encumber_aggregate_utxo = false; - let mut spend_aggregate_utxo = false; - let mut sign_message = false; - let mut create_script_sig = false; - let mut create_meta_sig = false; + let mut faucet_create_key_pair = false; + let mut faucet_create_aggregate_signature_utxo = false; + let mut faucet_encumber_aggregate_utxo = false; + let mut faucet_spend_aggregate_utxo = false; + let mut faucet_sign_message = false; + let mut faucet_create_party_details = false; + let mut faucet_create_script_sig = false; + let mut faucet_create_meta_sig = false; let mut make_it_rain = false; let mut coin_split = false; let mut discover_peer = false; @@ -597,13 +603,14 @@ mod test { CliCommands::GetBalance => get_balance = true, CliCommands::SendMinotari(_) => send_tari = true, CliCommands::BurnMinotari(_) => burn_tari = true, - CliCommands::CreateKeyPair(_) => create_key_pair = true, - CliCommands::CreateAggregateSignatureUtxo(_) => create_aggregate_signature_utxo = true, - CliCommands::EncumberAggregateUtxo(_) => encumber_aggregate_utxo = true, - CliCommands::SpendAggregateUtxo(_) => spend_aggregate_utxo = true, - CliCommands::SignMessage(_) => sign_message = true, - CliCommands::CreateScriptSig(_) => create_script_sig = true, - CliCommands::CreateMetaSig(_) => create_meta_sig = true, + CliCommands::FaucetCreateKeyPair(_) => faucet_create_key_pair = true, + CliCommands::FaucetCreateAggregateSignatureUtxo(_) => faucet_create_aggregate_signature_utxo = true, + CliCommands::FaucetEncumberAggregateUtxo(_) => faucet_encumber_aggregate_utxo = true, + CliCommands::FaucetSpendAggregateUtxo(_) => faucet_spend_aggregate_utxo = true, + CliCommands::FaucetSignMessage(_) => faucet_sign_message = true, + CliCommands::FaucetCreatePartyDetails(_) => faucet_create_party_details = true, + CliCommands::FaucetCreateScriptSig(_) => faucet_create_script_sig = true, + CliCommands::FaucetCreateMetaSig(_) => faucet_create_meta_sig = true, CliCommands::SendOneSidedToStealthAddress(_) => {}, CliCommands::MakeItRain(_) => make_it_rain = true, CliCommands::CoinSplit(_) => coin_split = true, @@ -631,20 +638,20 @@ mod test { CliCommands::RevalidateWalletDb => {}, CliCommands::RegisterValidatorNode(_) => {}, CliCommands::CreateTlsCerts => {}, - CliCommands::FaucetCreatePartyDetails(_) => {}, } } assert!( get_balance && send_tari && burn_tari && - create_key_pair && - create_aggregate_signature_utxo && - encumber_aggregate_utxo && - spend_aggregate_utxo && - sign_message && - create_script_sig && - create_meta_sig && + faucet_create_key_pair && + faucet_create_aggregate_signature_utxo && + faucet_encumber_aggregate_utxo && + faucet_spend_aggregate_utxo && + faucet_sign_message && + faucet_create_party_details && + faucet_create_script_sig && + faucet_create_meta_sig && make_it_rain && coin_split && discover_peer && diff --git a/base_layer/wallet/src/output_manager_service/handle.rs b/base_layer/wallet/src/output_manager_service/handle.rs index d28acd054f..c99400061c 100644 --- a/base_layer/wallet/src/output_manager_service/handle.rs +++ b/base_layer/wallet/src/output_manager_service/handle.rs @@ -37,6 +37,7 @@ use tari_core::{ SenderTransactionProtocol, }, }; +use tari_crypto::ristretto::pedersen::PedersenCommitment; use tari_script::TariScript; use tari_service_framework::reply_channel::SenderService; use tari_utilities::hex::Hex; @@ -64,6 +65,7 @@ pub enum OutputManagerRequest { tx_id: TxId, fee_per_gram: MicroMinotari, output_hash: String, + expected_commitment: PedersenCommitment, script_input_shares: Vec, script_public_key_shares: Vec, script_signature_public_nonces: Vec, @@ -154,10 +156,17 @@ impl fmt::Display for OutputManagerRequest { v.metadata_signature.u_y().to_hex(), v.metadata_signature.u_a().to_hex(), ), - EncumberAggregateUtxo { tx_id, output_hash, .. } => write!( + EncumberAggregateUtxo { + tx_id, + output_hash, + expected_commitment, + .. + } => write!( f, - "Encumber aggregate utxo with tx_id: {} and output_hash: {}", - tx_id, output_hash + "Encumber aggregate utxo with tx_id: {} and output: ({},{})", + tx_id, + expected_commitment.to_hex(), + output_hash ), GetRecipientTransaction(_) => write!(f, "GetRecipientTransaction"), ConfirmPendingTransaction(v) => write!(f, "ConfirmPendingTransaction ({})", v), @@ -755,6 +764,7 @@ impl OutputManagerHandle { tx_id: TxId, fee_per_gram: MicroMinotari, output_hash: String, + expected_commitment: PedersenCommitment, script_input_shares: Vec, script_public_key_shares: Vec, script_signature_public_nonces: Vec, @@ -779,6 +789,7 @@ impl OutputManagerHandle { tx_id, fee_per_gram, output_hash, + expected_commitment, script_input_shares, script_public_key_shares, script_signature_public_nonces, diff --git a/base_layer/wallet/src/output_manager_service/service.rs b/base_layer/wallet/src/output_manager_service/service.rs index 25e7c23dca..1582dfb72b 100644 --- a/base_layer/wallet/src/output_manager_service/service.rs +++ b/base_layer/wallet/src/output_manager_service/service.rs @@ -70,7 +70,7 @@ use tari_core::{ SenderTransactionProtocol, }, }; -use tari_crypto::keys::SecretKey; +use tari_crypto::{keys::SecretKey, ristretto::pedersen::PedersenCommitment}; use tari_script::{ inputs, push_pubkey_script, @@ -251,6 +251,7 @@ where tx_id, fee_per_gram, output_hash, + expected_commitment, script_input_shares, script_public_key_shares, script_signature_public_nonces, @@ -263,6 +264,7 @@ where tx_id, fee_per_gram, output_hash, + expected_commitment, script_input_shares, script_public_key_shares, script_signature_public_nonces, @@ -500,7 +502,7 @@ where fee_per_gram: MicroMinotari, ) -> Result { let output = self - .fetch_outputs_from_node(vec![output_hash]) + .fetch_unspent_outputs_from_node(vec![output_hash]) .await? .pop() .ok_or_else(|| OutputManagerError::ServiceError("Output not found".to_string()))?; @@ -1180,6 +1182,7 @@ where tx_id: TxId, fee_per_gram: MicroMinotari, output_hash: String, + expected_commitment: PedersenCommitment, script_input_shares: Vec, script_public_key_shares: Vec, script_signature_public_nonces: Vec, @@ -1206,10 +1209,16 @@ where let output_hash = FixedHash::from_hex(&output_hash).map_err(|e| OutputManagerError::ConversionError(e.to_string()))?; let output = self - .fetch_outputs_from_node(vec![output_hash]) + .fetch_unspent_outputs_from_node(vec![output_hash]) .await? .pop() .ok_or_else(|| OutputManagerError::ServiceError(format!("Output not found (TxId: {})", tx_id)))?; + if output.commitment != expected_commitment { + return Err(OutputManagerError::ServiceError(format!( + "Output commitment does not match expected commitment (TxId: {})", + tx_id + ))); + } // Retrieve the list of n public keys from the script let public_keys = if let [Opcode::CheckMultiSigVerifyAggregatePubKey(_n, _m, keys, _msg)] = output.script.as_slice() { @@ -2425,7 +2434,7 @@ where Ok((tx_id, stp.into_transaction()?, accumulated_amount + fee)) } - async fn fetch_outputs_from_node( + async fn fetch_unspent_outputs_from_node( &mut self, hashes: Vec, ) -> Result, OutputManagerError> { diff --git a/base_layer/wallet/src/transaction_service/handle.rs b/base_layer/wallet/src/transaction_service/handle.rs index 2b2135b532..b865c4feae 100644 --- a/base_layer/wallet/src/transaction_service/handle.rs +++ b/base_layer/wallet/src/transaction_service/handle.rs @@ -52,6 +52,7 @@ use tari_core::{ }, }, }; +use tari_crypto::ristretto::pedersen::PedersenCommitment; use tari_service_framework::reply_channel::SenderService; use tari_utilities::hex::Hex; use tokio::sync::broadcast; @@ -112,6 +113,7 @@ pub enum TransactionServiceRequest { EncumberAggregateUtxo { fee_per_gram: MicroMinotari, output_hash: String, + expected_commitment: PedersenCommitment, script_input_shares: Vec, script_public_key_shares: Vec, script_signature_public_nonces: Vec, @@ -229,6 +231,7 @@ impl fmt::Display for TransactionServiceRequest { Self::EncumberAggregateUtxo { fee_per_gram, output_hash, + expected_commitment, script_input_shares, script_public_key_shares, script_signature_public_nonces, @@ -238,12 +241,13 @@ impl fmt::Display for TransactionServiceRequest { recipient_address, .. } => f.write_str(&format!( - "Creating encumber n-of-m utxo with: fee_per_gram = {}, output_hash = {}, script_input_shares = {:?}, \ - script_public_key_shares = {:?}, script_signature_shares = {:?}, sender_offset_public_key_shares = \ - {:?}, metadata_ephemeral_public_key_shares = {:?}, dh_shared_secret_shares = {:?}, recipient_address \ - = {}", + "Creating encumber n-of-m utxo with: fee_per_gram = {}, output_hash = {}, commitment = {}, \ + script_input_shares = {:?}, script_public_key_shares = {:?}, script_signature_shares = {:?}, \ + sender_offset_public_key_shares = {:?}, metadata_ephemeral_public_key_shares = {:?}, \ + dh_shared_secret_shares = {:?}, recipient_address = {}", fee_per_gram, output_hash, + expected_commitment.to_hex(), script_input_shares .iter() .map(|v| format!( @@ -731,6 +735,7 @@ impl TransactionServiceHandle { &mut self, fee_per_gram: MicroMinotari, output_hash: String, + expected_commitment: PedersenCommitment, script_input_shares: Vec, script_public_key_shares: Vec, script_signature_public_nonces: Vec, @@ -744,6 +749,7 @@ impl TransactionServiceHandle { .call(TransactionServiceRequest::EncumberAggregateUtxo { fee_per_gram, output_hash, + expected_commitment, script_input_shares, script_public_key_shares, script_signature_public_nonces, diff --git a/base_layer/wallet/src/transaction_service/service.rs b/base_layer/wallet/src/transaction_service/service.rs index f2d10f4c94..e0f727a51e 100644 --- a/base_layer/wallet/src/transaction_service/service.rs +++ b/base_layer/wallet/src/transaction_service/service.rs @@ -78,6 +78,7 @@ use tari_core::{ }; use tari_crypto::{ keys::{PublicKey as PKtrait, SecretKey}, + ristretto::pedersen::PedersenCommitment, tari_utilities::ByteArray, }; use tari_key_manager::key_manager_service::KeyId; @@ -712,6 +713,7 @@ where TransactionServiceRequest::EncumberAggregateUtxo { fee_per_gram, output_hash, + expected_commitment, script_input_shares, script_public_key_shares, script_signature_public_nonces, @@ -723,6 +725,7 @@ where .encumber_aggregate_tx( fee_per_gram, output_hash, + expected_commitment, script_input_shares, script_public_key_shares, script_signature_public_nonces, @@ -1376,6 +1379,7 @@ where &mut self, fee_per_gram: MicroMinotari, output_hash: String, + expected_commitment: PedersenCommitment, script_input_shares: Vec, script_public_key_shares: Vec, script_signature_public_nonces: Vec, @@ -1393,6 +1397,7 @@ where tx_id, fee_per_gram, output_hash, + expected_commitment, script_input_shares, script_public_key_shares, script_signature_public_nonces, @@ -1436,7 +1441,7 @@ where total_script_nonce, )) }, - Err(_) => Err(TransactionServiceError::UnexpectedApiResponse), + Err(e) => Err(e.into()), } }