BitBoxSwiss / bitbox02-firmware

Firmware code of the BitBox02 hardware wallet
https://bitbox.swiss/bitbox02
Apache License 2.0
217 stars 81 forks source link

bitcoin/signtx: cache xpubs #1035

Closed benma closed 1 year ago

benma commented 1 year ago

When loading a transaction, every input and change address requires the public key in order to compute the pkScript, which is used in the sighash that is signed.

For single-sig, these public keys are currently always at keypaths:

where coin and account are the same for all inputs/changes in the transaction.

Instead of deriving the xpub at these keypaths repeatedly, we cache the xpubs at the account level and the receive/change level. The xpub then only has to be derived once once for the account level and once for change/receive per script type.

Benefits: