banner

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!

banner

Converter

Source: CurrencyRate
Top Selling Multipurpose WP Theme

Newsletter

Subscribe my Newsletter for new blog posts, tips & new photos. Let's stay updated!

banner

Leave a Comment

Layer 1
Your Crypto & Blockchain Beacon

CryptoInsightful

Welcome to CryptoInsightful.com, your trusted source for in-depth analysis, news, and insights into the world of cryptocurrencies, blockchain technology, NFTs (Non-Fungible Tokens), and cybersecurity. Our mission is to empower you with the knowledge and understanding you need to navigate the rapidly evolving landscape of digital assets and emerging technologies.