Author

Topic: I'm trying to understand the exact mechanism of a UTXO spend (Read 118 times)

legendary
Activity: 2618
Merit: 6452
Self-proclaimed Genius
Clearly I don't grasp the entire structure of a BTC transaction as indicated by the fact that I put several "IDK"s in the diagram. Can someone fill in the gaps in my knowledge?
Read this technical article: https://learnmeabitcoin.com/technical/transaction-data
It breaks-down every part of a non-SegWit transaction, with clickable links to explanation to that specific part and even has a diagram for you to understand how it works,
like the scriptPubKey: https://learnmeabitcoin.com/technical/scriptPubKey (hover-over to display the "IDK what goes here" part)

For the "signature of IDK" part, refer to this for p2pkh: https://learnmeabitcoin.com/technical/ecdsa#signing-a-transaction
For SegWit, the message that needs to be signed is different, read BIP143.
The rest, you already figured out.
legendary
Activity: 3472
Merit: 10611
Each transaction creates at least one output that contains two things: (1) amount field which indicates how much bitcoin is being locked up and (2) the script which is the lock indicating how these coins can be unlocked or spent.
These outputs don't have an explicit field for their index, the index is the order inside the transaction output array itself.

Each UTXO (that's not a null value UTXO like an OP_RETURN), has a value, scriptPubKey (hereafter referred to as a "locking script"), and index (hereafter referred to as "n").  
This means all outputs have the two fields (value and scriptpub) including OP_RETURN outputs.


Each input of a transaction spending a UTXO has to address them by providing the (1) transaction ID of the tx containing the output being spent (2) index of the output being spent (3) the unlocking script which can be scriptsig or witness depending on the UTXO type and (4) a 4 byte sequence.

Quote
In order to spend a UTXO, you have have to supply an unlocking script which contains a signature from the address possessing the UTXO (this proves that the spender actually has the private key for the address), and the UTXO owner's public key so the signature can be verified.  
This means what you provide when spending UTXOs, what you provide depends on their type. It can contain one signature and one public key, it can contain multiple signatures and public keys, it can contain more complex scripts like a locktime or execution branches, etc.

Quote
I made this diagram to show what I believe a bitcoin transaction spend to look like:  
https://imgur.com/a/titAohe

Clearly I don't grasp the entire structure of a BTC transaction as indicated by the fact that I put several "IDK"s in the diagram. Can someone fill in the gaps in my knowledge?
This is one of the oldest and simplest scripts known as P2PKH or pay to pubkey hash.
In the outputs the first value that is being pushed to the stack after the OP_HASH160 is the hash160 digest of the public key.

In the inputs (scriptsig) there is no value field anymore since it is already present in the output that is being addressed and the signature (last value pushed to the stack or the first inside the script) is the ECDSA signature created using the private key that created the address.

The new outputs this new transaction creates is the same as before.

This page can be helpful to see more scripts and the standard one you used here:
https://en.bitcoin.it/wiki/Script#Script_examples
newbie
Activity: 19
Merit: 25
My understanding of a bitcoin transaction is as follows. Each UTXO (that's not a null value UTXO like an OP_RETURN), has a value, scriptPubKey (hereafter referred to as a "locking script"), and index (hereafter referred to as "n"). 

In order to spend a UTXO, you have have to supply an unlocking script which contains a signature from the address possessing the UTXO (this proves that the spender actually has the private key for the address), and the UTXO owner's public key so the signature can be verified. 

I made this diagram to show what I believe a bitcoin transaction spend to look like:  
https://imgur.com/a/titAohe

Clearly I don't grasp the entire structure of a BTC transaction as indicated by the fact that I put several "IDK"s in the diagram. Can someone fill in the gaps in my knowledge?
Jump to: