Bitcoin Forum
April 28, 2024, 06:01:46 PM *
News: Latest Bitcoin Core release: 27.0 [Torrent]
 
   Home   Help Search Login Register More  
Pages: [1]
  Print  
Author Topic: I'm trying to understand the exact mechanism of a UTXO spend  (Read 92 times)
warpanomaly (OP)
Newbie
*
Offline Offline

Activity: 16
Merit: 25


View Profile
January 07, 2024, 12:12:06 AM
Merited by o_e_l_e_o (4), pooya87 (2), hosseinimr93 (1)
 #1

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?
1714327306
Hero Member
*
Offline Offline

Posts: 1714327306

View Profile Personal Message (Offline)

Ignore
1714327306
Reply with quote  #2

1714327306
Report to moderator
Bitcoin addresses contain a checksum, so it is very unlikely that mistyping an address will cause you to lose money.
Advertised sites are not endorsed by the Bitcoin Forum. They may be unsafe, untrustworthy, or illegal in your jurisdiction.
1714327306
Hero Member
*
Offline Offline

Posts: 1714327306

View Profile Personal Message (Offline)

Ignore
1714327306
Reply with quote  #2

1714327306
Report to moderator
pooya87
Legendary
*
Offline Offline

Activity: 3430
Merit: 10505



View Profile
January 07, 2024, 07:12:04 AM
Merited by hosseinimr93 (4), o_e_l_e_o (4), Charles-Tim (1), warpanomaly (1)
 #2

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

.
.BLACKJACK ♠ FUN.
█████████
██████████████
████████████
█████████████████
████████████████▄▄
░█████████████▀░▀▀
██████████████████
░██████████████
████████████████
░██████████████
████████████
███████████████░██
██████████
CRYPTO CASINO &
SPORTS BETTING
▄▄███████▄▄
▄███████████████▄
███████████████████
█████████████████████
███████████████████████
█████████████████████████
█████████████████████████
█████████████████████████
███████████████████████
█████████████████████
███████████████████
▀███████████████▀
█████████
.
nc50lc
Legendary
*
Offline Offline

Activity: 2394
Merit: 5543


Self-proclaimed Genius


View Profile
January 07, 2024, 07:46:33 AM
Merited by o_e_l_e_o (4), pooya87 (2), hosseinimr93 (2), warpanomaly (1)
 #3

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.

.
.HUGE.
▄██████████▄▄
▄█████████████████▄
▄█████████████████████▄
▄███████████████████████▄
▄█████████████████████████▄
███████▌██▌▐██▐██▐████▄███
████▐██▐████▌██▌██▌██▌██
█████▀███▀███▀▐██▐██▐█████

▀█████████████████████████▀

▀███████████████████████▀

▀█████████████████████▀

▀█████████████████▀

▀██████████▀▀
█▀▀▀▀











█▄▄▄▄
▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀
.
CASINSPORTSBOOK
▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄
▀▀▀▀█











▄▄▄▄█
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.19 | SMF © 2006-2009, Simple Machines Valid XHTML 1.0! Valid CSS!