Progress pill
Definitions and key concepts

The structure of Bitcoin transactions

Privacy on Bitcoin

The structure of Bitcoin transactions

  • Transaction inputs and outputs
  • Exchange and merging in a Bitcoin transaction
  • Transaction fees
  • Creating UTXOs on Bitcoin
  • The implications of the UTXO model

Transaction inputs and outputs

A Bitcoin transaction is an operation recorded on the blockchain that transfers ownership of Bitcoin from one person to another. More precisely, since we're on a UTXO model and there are no accounts, the transaction satisfies the spending conditions that secured one or more UTXOs, consumes them, and, equivalently, creates new UTXOs with new spending conditions. In short, a transaction moves bitcoins from a satisfied script to a new script designed to secure them.
Each Bitcoin transaction, therefore, consists of one or more inputs and one or more outputs. Inputs are UTXOs consumed by the transaction to generate outputs. Outputs are new UTXOs that can be used as inputs for future transactions.
Did you know? Theoretically, a bitcoin transaction could have an infinite number of inputs and outputs. The only limit is the maximum block size.
Each input in a Bitcoin transaction refers to a previous unspent UTXO. To use a UTXO as an input, its holder must demonstrate that he/she is the rightful owner by validating the associated script, i.e., by satisfying the spending condition imposed. Generally speaking, this means providing a digital signature produced with the private key corresponding to the public key that initially secured this UTXO. The script, therefore, consists of verifying that the signature corresponds to the public key used when the funds were received.
Each output, in turn, specifies the amount of bitcoins to be transferred, as well as the recipient. The latter is defined by a new script, which usually blocks the newly created UTXO with a receiving address or a new public key.
For a transaction to be considered valid according to the consensus rules, total outputs must be less than or equal to total inputs. In other words, the sum of new UTXOs generated by the transaction must not exceed the sum of UTXOs consumed as inputs. This principle is logical: if you only have 500,000 SATS, you can't make a purchase of 700,000 SATS.

Exchange and merging in a Bitcoin transaction

The action of a Bitcoin transaction on UTXO can thus be compared to recasting a gold coin. Indeed, a UTXO is not divisible, but only fusible. This means that a user cannot simply divide a UTXO representing a certain amount of Bitcoin into several smaller UTXOs. He must consume it entirely in a transaction to create one or more new UTXOs of arbitrary values in outputs, which must be less than or equal to the initial value.
This mechanism is similar to that of a gold coin. Let's say you own a 2-ounce coin and want to make a payment of 1 ounce, assuming the seller can't give you change. You would have to melt your coin and cast two new ones, each weighing 1 ounce.
Bitcoin works in a similar way. Let's imagine that Alice has a UTXO of 10,000 SATS and wishes to buy bread costing 4,000 SATS. Alice will make a transaction with 1 UTXO of 10,000 SATS as input, which she will consume in full, and 2 UTXOs of 4,000 SATS and 6,000 SATS as output. The UTXO of 4,000 SATS will be sent to the baker in payment for the baguette, while the UTXO of 6,000 SATS will return to Alice in the form of change. This UTXO, which returns to the original issuer of the transaction, is referred to as an "exchange" in Bitcoin jargon.
Now let's imagine that Alice doesn't have a single UTXO of 10,000 SATS, but rather two UTXOs of 3,000 SATS each. In this situation, neither of the UTXOs individually is sufficient to set the wand's 4,000 SATS. Alice must therefore simultaneously use the 2 UTXOs of 3,000 SATS as inputs to her transaction. In this way, the total amount of inputs will reach 6,000 SATS, enabling her to satisfy the 4,000 SATS payment to the baker. This method, in which several UTXOs are grouped together as inputs to a transaction, is often referred to as "merging".

Transaction fees

Intuitively, one might think that transaction costs also represent the output of a transaction. But in reality, this is not the case. Transaction costs represent the difference between total inputs and total outputs. This means that, after using part of the value of the inputs to cover the desired outputs in a transaction, a certain sum of the inputs remains unused. This residual sum constitutes the transaction costs.
Transaction fees = total inputs - total outputs
Let's take the example of Alice, who has a UTXO of 10,000 SATS and wants to buy bread at 4,000 SATS. Alice creates a transaction with her UTXO of 10,000 SATS as input. She then generates an output of 4,000 SATS for the baker to pay for the baguette. To encourage miners to integrate her transaction into a block, Alice allocates 200 SATS in fees. She then creates a second output, the change, which will be returned to her, amounting to 5,800 SATS.
Applying the fee formula, we see that there are indeed 200 SATS left for minors:
Transaction fees = total inputs - total outputs Transaction fees = 10 000 - (4 000 + 5 800) Transaction fees = 10 000 - 9 800 Transaction fees = 200
When a miner successfully validates a block, they are authorized to collect fees for all the transactions included in their block, via the so-called "coinbase" transaction.

Creating UTXOs on Bitcoin

If you've followed the previous paragraphs carefully, you'll now know that UTXOs can only be created by consuming other existing UTXOs. In this way, Bitcoin coins form a continuous chain. However, you may wonder how the first parts in this chain originated. This raises a problem similar to that of the chicken and the egg: where did these original UTXOs come from?
The answer is in the transaction coinbase.
The coinbase is a specific type of Bitcoin transaction, unique to each block and always the first of its kind. It allows the miner who has found a valid proof of work to receive their block reward. This reward consists of two elements: block grant and transaction fee, as discussed in the previous section.
The coinbase transaction is unique in that it is the only one capable of creating bitcoins ex nihilo, without the need to consume inputs to generate outputs. These newly created bitcoins are what we might refer to as "original UTXOs."
Block-subsidized bitcoins are new BTC created from scratch, according to a pre-established issuance schedule in the consensus rules. The block grant is halved every 210,000 blocks, approximately every four years, in a process known as "halving." Originally, 50 bitcoins were created with each subsidy; however, this amount has gradually decreased, and currently, it is 3.125 bitcoins per block.
As for transaction fees, although they also represent newly created BTC, they must not exceed the difference between the total inputs and outputs of all transactions in a block. We saw earlier that these fees represent the portion of inputs that is not used in transaction outputs. This portion is technically "lost" during the transaction, and the miner has the right to recreate this value in the form of one or more new UTXOs. This is a transfer of value between the transaction issuer and the miner who adds it to the blockchain.
Did you know? Bitcoins generated by a coinbase transaction are subject to a maturity period of 100 blocks, during which they cannot be spent by the miner. This rule is designed to avoid complications associated with the use of newly created bitcoins on a chain that could later become obsolete.

The implications of the UTXO model

Firstly, the UTXO model directly impacts Bitcoin's transaction fees. Since the capacity of each block is limited, miners favor transactions that offer the best fees in relation to the space they occupy in the block. Indeed, the more UTXOs a transaction includes in its inputs and outputs, the heavier it is, and therefore, it requires higher fees. This is one of the reasons why we often attempt to reduce the number of UTXOs in our wallet, which can also impact confidentiality —a subject we'll address in detail in the third part of this course.
Secondly, as mentioned in the previous sections, Bitcoin coins are essentially a chain of UTXOs. Each transaction thus creates a link between a past UTXO and a future UTXO. UTXOs, therefore, make it possible to explicitly follow the path of Bitcoins from their creation to their current expenditure. This transparency can be viewed positively, as it enables each user to ascertain the authenticity of the bitcoins received. However, it is also on this principle of traceability and auditability that blockchain analysis is based, a practice that compromises your confidentiality. We'll be taking an in-depth look at this practice in the second part of the course.
Quiz
Quiz1/5
If a transaction has 2 UTXOs of 5,000 sats as inputs and 3 UTXOs of 3,000 sats as outputs, what are the transaction fees?