I have been struggling to grasp what exactly is included in the input of a Transaction that allows the intended recipient to then redeem/unlock that UTXO when they are ready to do so.

I understand that a transaction contains a Digital Signature created by the Senders Private Key on the message.

I become confused when trying to understand what data the sender includes in the Transaction that allows the recipient to unlock that UTXO and turn it into a subsequent input when they choose to do so. Is the Sender including the Recipients Public Key in the Transaction allowing them to use a scriptSig to unlock that UTXO?

1 Answer
1

The transaction output has a property called the scriptPubkey that is executed with the scriptSig when the output is spent in a transaction. An understanding of Bitcoin script would help.

Bitcoin Script

Bitcoin uses it's own stack-based scripting language with a set of op-codes. This scripting language is used to determine whether an unspent transaction output (utxo) can be spent. When you send Bitcoin, you are really just assigning a Bitcoin value to a script, which can be spent only if the script executes successfully and results in a single true value on the stack. The script that is assigned to the Bitcoin transaction output is called the scriptPubKey. To satisfy the script, you must provide the correct scriptSig, which is also a script, which is prepended to the scriptSig and executed to test if the spending succeeded. Let's look at an example:

OP_DUP: Duplicate the top item on the stack (place a copy of it on the stack)

OP_HASH160: Pop the top item off the stack, calculate it's HASH160, i.e. the RIPEMD160(SHA256()), and place that on the stack

OP_EQUALVERIFY: Pop the top 2 items off the stack, and if they are not equal, it will exit immediately and fail, otherwise nothing

OP_CHECKSIG: Pop the top 2 items off the stack, and use the top as the public key, the second as the signature, and verify the transaction signature

In order to spend this output, we must provide a valid signature and public key. We'll just provide 00 for the signature for this example, and not worry about the final checksig op.

Example

Let's visualize this example with a scriptSig. Let's use kallewoof's btcdeb Script visualization tool. After the first command, you can type step once, and then just press enter each time after that to step through each operation: