Hash-Preimage Construction for a two p2pkh Input transaction?

When verifying a transaction, a Bitcoin node rebuilds the hash-preimage used to create each signature.

After serializing the hash-preimage for each input, the next step is to double-hash it and verify the signature for each input using the corresponding public key.

My question is: what is the exact serialized hash-preimage for each input? I haven't found clear guidance on how this should be constructed.

For example, take this transaction: https://mempool.space/es/tx/592ea2010ec259252959b6047e227ceac6ffd0dbbe20bad71248960c18a5d890

This transaction uses the SIGHASH_ALL flag, meaning that each signature signs all inputs and outputs.

Should the hash-preimage include the scriptPubKey of every input, or only the scriptPubKey of the input being signed, leaving the other inputs with an empty script (0x00)?

Example of My Attempt: Here is my attempt to construct the hash-preimage for signing both inputs:

01000000 - Version
02 - Number of inputs
19f4d40cb4204ad8429ec3d98d240661593edcfcfb8efcb3b684141ceb0df2e4 - First UTXO txid
00000000 - First UTXO output index
1976a914d52c9ce97c8dea0b71df687659a847a62c37732c88ac - scriptPubKey of first UTXO
ffffffff - Sequence for first input
22d07db06b68e4c15154db0ce0dd9c9dcd683a60a5117490451e0b52743492ca - Second UTXO txid
00000000 - Second UTXO output index
1976a91497ccdcca4f494b1bd652ad8f9d816b4bbb1108ac88ac - scriptPubKey of second UTXO
ffffffff - Sequence for second input
01 - Number of outputs
c047bfe54d000000 - Amount in satoshis
1976a91492512166101806dd6a695cbe56f883c3bea2a7e488ac - Output's scriptPubKey
00000000 - Locktime
01000000 - SIGHASH_ALL flag

When I try to construct the preimage for just one input (with the second input's scriptSig set to 0x00):

01000000 - Version
02 - Number of inputs
19f4d40cb4204ad8429ec3d98d240661593edcfcfb8efcb3b684141ceb0df2e4 - First UTXO txid
00000000 - First UTXO output index
1976a914d52c9ce97c8dea0b71df687659a847a62c37732c88ac - scriptPubKey of first UTXO
ffffffff - Sequence for first input
00 - Empty scriptSig for second input (set to 0x00)
ffffffff - Sequence for second input
01 - Number of outputs
c047bfe54d000000 - Amount in satoshis
1976a91492512166101806dd6a695cbe56f883c3bea2a7e488ac - Output's scriptPubKey
00000000 - Locktime
01000000 - SIGHASH_ALL flag

Am I correctly understanding how to set the scriptPubKey for non-signed inputs in the hash-preimage? Should I be clearing the scriptSig of other inputs as 0x00?

Thanks for any guidance!



from Recent Questions - Bitcoin Stack Exchange https://ift.tt/ELVCBw1
via IFTTT

Popular posts from this blog

Do Kwon’s Detention Prolonged Until 2024 As Montenegro Responds To Extradition Requests

Sam Bankman-Fried Trial Begins Tomorrow: 3 Reasons Ex-SEC Official Foresees Conviction

April’s Crypto Game-Changers: 7 Events Set To Drastically Impact The Course Of Digital Currencies