3

When spending a P2PKH output, the "data" we hash only includes the output script from previous transaction but when spending a P2WPKH (the new serialization) we also include the amount field from previous transaction (#6 in BIP-143 specification). Why?

3

It's not particularly required and may be considered redundant as that information is generally implied from the transaction outpoints referenced in the input. However, this form of transaction serialization allows wallet softwares to explicitly commit to the fees involved in the transaction. This is particularly useful if say you are using a hardware wallet where you have your private keys and at the same time you use a watch-only online wallet. Since the online wallets knows all the UTXOs that your private keys control, it can effectively create a transaction consuming some inputs.

To know how much fee you are committing to the transaction, the hardware wallet would have to query the input referenced, grab all the outputs of that transactions (which may be very large) and then only it will know what the fee is for this particular transaction. Otherwise, if it doesn't, the software that created the transaction could lie, and in fact convert a giant portion of the bitcoins consumed into fee without you knowing it. However, keeping the input amount as part of the message that signature commits to means the hardware wallet software knows the amount explicitly and hence can provide the user with an accurate measurement of the fees.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.