Skip to content

Commit fc0f40e

Browse files
jgriffithsJamie C. Driver
authored andcommitted
psbt: avoid iterating private keys for input detection
We only need the pubkeys for the initial iteration where we identify inputs belonging to the wallet. Avoid deriving private keys until we actually sign.
1 parent 308f072 commit fc0f40e

File tree

3 files changed

+10
-2
lines changed

3 files changed

+10
-2
lines changed

main/process/sign_psbt.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -636,7 +636,7 @@ int sign_psbt(const char* network, struct wally_psbt* psbt, const char** errmsg)
636636
}
637637
JADE_ASSERT(tx->num_inputs == psbt->num_inputs && tx->num_outputs == psbt->num_outputs);
638638

639-
key_iter iter; // Holds any private key in use
639+
key_iter iter; // Holds any public/private key in use
640640
SENSITIVE_PUSH(&iter, sizeof(iter));
641641
int retval = 0;
642642

@@ -669,7 +669,7 @@ int sign_psbt(const char* network, struct wally_psbt* psbt, const char** errmsg)
669669
input_amount += utxo->satoshi;
670670

671671
// If we are signing this input, look at the script type, sighash, multisigs etc.
672-
if (key_iter_input_begin(psbt, index, &iter)) {
672+
if (key_iter_input_begin_public(psbt, index, &iter)) {
673673
// Found our key - we are signing this input
674674
JADE_LOGD("Key %u belongs to this signer, so we will need to sign input %u", iter.key_index, index);
675675
signing_inputs[index] = true;

main/utils/psbt.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,11 @@ bool key_iter_input_begin(const struct wally_psbt* psbt, const size_t index, key
5959
return key_iter_init(psbt, index, /* is_input */ true, /* is_private */ true, iter);
6060
}
6161

62+
bool key_iter_input_begin_public(const struct wally_psbt* psbt, const size_t index, key_iter* iter)
63+
{
64+
return key_iter_init(psbt, index, /* is_input */ true, /* is_private */ false, iter);
65+
}
66+
6267
bool key_iter_output_begin_public(const struct wally_psbt* psbt, const size_t index, key_iter* iter)
6368
{
6469
return key_iter_init(psbt, index, /* is_input */ false, /* is_private */ false, iter);

main/utils/psbt.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,9 @@ typedef struct key_iter_t {
2727
// Initialize a key iterator for the `index`th PSBT input
2828
bool key_iter_input_begin(const struct wally_psbt* psbt, size_t index, key_iter* iter);
2929

30+
// Initialize a public key iterator for the `index`th PSBT input
31+
bool key_iter_input_begin_public(const struct wally_psbt* psbt, size_t index, key_iter* iter);
32+
3033
// Initialize a public key iterator for the `index`th PSBT output
3134
bool key_iter_output_begin_public(const struct wally_psbt* psbt, size_t index, key_iter* iter);
3235

0 commit comments

Comments
 (0)