Skip to content

Commit d58d6cf

Browse files
committed
sign_tx: compute taproot signature hashes once all inputs are verified
1 parent c5bf1c7 commit d58d6cf

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

main/process/sign_tx.c

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -498,6 +498,7 @@ void sign_tx_process(void* process_ptr)
498498
uint32_t num_to_sign = 0; // Total number of inputs to sign
499499
uint32_t num_p2tr_to_sign = 0; // Total number of p2tr inputs to sign
500500

501+
// Loop to fetch data for and validate all inputs
501502
for (size_t index = 0; index < num_inputs; ++index) {
502503
jade_process_load_in_message(process, true);
503504
if (!IS_CURRENT_MESSAGE(process, "tx_input")) {
@@ -691,6 +692,22 @@ void sign_tx_process(void* process_ptr)
691692
}
692693
}
693694

695+
// Loop to process any taproot inputs now that we have all input
696+
// values and scriptpubkeys
697+
for (size_t index = 0; num_p2tr_to_sign != 0 && index < num_inputs; ++index) {
698+
signing_data_t* const sig_data = all_signing_data + index;
699+
if (sig_data->segwit_ver != SEGWIT_V1 || !sig_data->path_len) {
700+
// Not signing this input
701+
continue;
702+
}
703+
if (!wallet_get_tx_input_hash(tx, index, sig_data, NULL, 0, input_amounts, tx->num_inputs, scriptpubkeys)) {
704+
// We are using ae-signatures, so we need to load the message to send the error back on
705+
jade_process_load_in_message(process, true);
706+
jade_process_reject_message(process, CBOR_RPC_INTERNAL_ERROR, "Failed to make taproot tx input hash", NULL);
707+
goto cleanup;
708+
}
709+
}
710+
694711
// Sanity check amounts
695712
uint64_t output_amount;
696713
JADE_WALLY_VERIFY(wally_tx_get_total_output_satoshi(tx, &output_amount));

0 commit comments

Comments
 (0)