Vite Tech Series: Understanding the UTXO Transaction Model of Bitcoin (Part 1)

Khun Sir
Sep 14, 2018 · 8 min read

If you’ve followed cryptocurrencies for awhile, you may have stumbled upon the phrase: “There is actually no Bitcoin, only UTXO” — so what exactly are people referring to? In essence, tokens are just a unit of measure — a symbol of value. What really drives the growth of blockchain is its trading model.

All available outputs can be used in a Bitcoin node called Unspent Transaction Outputs, or UTXO. If a wallet shows the balance of 10,000 Satoshi (1 Bitcoin), it essentially means that 10,000 Satoshi exists in one or more UTXOs waiting to be used. The unspent balance of an account is the premise for the payment of a new transaction.

A transaction consumes UTXO and also generates a new UTXO. The inquiry of UTXOs not only occurs when creating a transaction, but it is also a necessary step for data verification when broadcasting in a P2P network. Moreover, it is a function of displaying balance in a wallet application. It can be said that UTXO plays an important part in the entire Bitcoin transaction, and that each transaction affects the UTXO set.

Before understanding the transaction model, we need to first understand some of the more confusing concepts in Bitcoin: public keys, addresses, accounts, and wallets.

A public key is not an address, but they are used to generate an address. In a typical Bitcoin transaction, the address is the result of a one-way hash transformation of the public key. The address is not an account and does not exist on the Bitcoin chain. Accounts are channels for the wallet application to manage addresses. The wallet controls user access, manages keys and addresses, tracks balances, and creates and signs transactions.

Transaction

UTXO is a Bitcoin-specific trading model. To understand its role in a transaction, we need to first understand what information is carried by the transaction.

There are two types of transactions, a General and a Coinbase Transaction. The first transaction in each block is often a Coinbase transaction, which is a special transaction that is paid as a mining reward. There is no transaction input in the Coinbase transaction.

The UTXO generated by the Coinbase transaction cannot be used within at least the next 100 blocks (referenced by the transaction input), in case the blockchain is forked and the Coinbase transaction is destroyed. A General transaction can contain multiple inputs and outputs, which are structured as follows:

Transaction: {

Vin, # Transaction input

Vout, # Transaction output

ID, # Transaction ID, the hash of the transaction after serialization

witness_hash, # Segwit witness hash

}

Bitcoin transactions can be divided into the status of transaction and the witness of transaction by transaction content. The status of transaction refers to the input and output of the remaining value, and the witness refers to the signing of the legality of the transaction. Here we only study the status of transaction. Each input of the transaction is the output of the previous transaction, and each output stays as a UTXO until it is used by the input of a new transaction. The transactions are linked as shown below.

Transaction output

Each transaction can create multiple transaction outputs (Output), similar to sending to multiple addresses. Each output has an implicit index number (vout) based on the position in the transaction.

The index of the first output is zero, and each output can only be referenced once by the input in the subsequent new transaction. Whether the position of an output in the transaction is referenced determines the state of the output (unspent or not), so UTXOs are a subset of outputs. The specific structure of output is as follows:

Output{

value, # Spent amount, the unit is Satoshi

locking script, # Locking script, an encryption puzzle to be solved to spend this output

}

Value (the value of transaction output) is a discrete and indivisible value unit of Satoshi. It can only be consumed as a whole in subsequent transactions. Multiple sub-transaction outputs can be created by sharing the value.

The locking script indicates the payment conditions. Most transactions processed via the Bitcoin network are in the form of P2PKH (Pay-to-Public-Key-Hash). In short, the address in the lock condition is the hash of public key, which we can refer to as the payee address. In addition, in a complex transaction such as P2SH (Pay-to-Script-Hash), the address is obtained by a script hash, indicating the value is paid to the script address.

Transaction input

Each transaction can have multiple transaction inputs (Input), the basic data structure of Vin. The specific structure of Input is as follows:

Input{

OutPoint, # Output point, referring to the output of the previous transaction, can be used by the signature script

unlocking script, # Unlocking script

sequence, # Sequence number

}

Outpoint (output point). Since the input of the transaction does not directly contain the amount of the transaction and the lock script of the expenditure condition, Outpoint is actually a pointer to the transaction address of UTXO, consisting of the hash value (txid) and sequence number (vout) of the transaction in the blockchain. Double-spending is prohibited from OutPoint.

The unlocking script provides the payment condition parameters set by the locking script in UTXO to be spent, usually including the digital signature and public key used to prove ownership. SigScript is sometimes used to refer to it, but not all unlocking scripts contain signatures. Whether or not a UTXO can be correctly retrieved depends on if the execution result of the unlocking script satisfies the condition set by the locking script referenced and the batch execution result is True. Otherwise, the UTXO can not be used.

Sequence (sequence number) often matches with the lock time (locktime) of a block. Locktime defines the earliest transaction timestamp that can be added to the blockchain. Before the lock time of a transaction expires, the transaction is replaceable if the sequence number of the transaction input does not meet the maximum value (UINT_MAX).

General transactions will be executed immediately and never updated if statement sequence=UINT_MAX && locktime=0 is satisfied. Sequence is also used in RBF (replace-by-fee) scenario where a transaction can be updated by paying a higher fee before confirmation.

In summary, we can simply describe the ledger structure and transaction delivery process of Bitcoin, as shown below:

In above chart, the input in Transaction Block 003 comes from the unspent transaction output with sequence number 0 in Transaction Block 002. In addition, the transaction input contains an unlocking script, which unlocks the Outputs of the UTXOs being spent. As result, a part of output amount is sent to Lily’s address, and rest goes to Bob’s address.

UTXO

Based on above logic, we can see that UTXO is not represented as a data structure in the main chain, but the complete information it refers to is permanently stored in the block.

UTXO consumption does not modify the information it refers to. However, it’s quite inefficient to search the whole chain to obtain UTXO information for an account, so Bitcoin introduces the unspent transaction output set (UTXO set), which is stored in a separate database apart from the blockchain storage.

When the state of a transaction changes, the UTXO set changes accordingly. The Output of the new transaction of this node will be added to the UTXO set because it is not “spent”, and the Output that can be correctly retrieved by the new transaction, which will be deleted from the UTXO set. The Bitcoin code sample below shows what information UTXO carries by creating a new transaction:

When a new transaction is created, UTXO actually passes the transaction hash value (txid) required by the Outpoint, the sequence number (vout) of the transaction output and transfer value(value) to the new transaction. They construct the data structure of UTXO.

UTXO{

txid # transaction hash value

vout # output sequence number

value # output value

}

Change

In real life, we can collect various small denominations of currency to pay for large expenses, or pay a small amount of money by looking for change with one single large bill — Bitcoin is similar to this.

Multiple Outputs can be merged and then used as an input for a new transaction. The large amount of Output can also return the remaining as change to meet the demand for small expenses. In Bitcoin transactions, the agreed value in the Outputs referenced by UTXOs that are used is sent to a new Bitcoin address, which usually includes the payee address, the change address, and the address of the miner who charges the transaction fees.

The change address has been required to be a “new” address since the initial design, in other words, the payer’s Bitcoin address will change. Although later Bitcoin versions also supports the ability to choose the address designated by the locking script in UTXO (P2PKH pubkey hash or P2SH script hash), it is often preferred to generate new addresses (also recommended by most major users) because this helps to maximize account security and privacy.

The reason for this is because since addresses are all one-way irreversible hash values, the unlocking script of the transaction Input often contains the public key of the payer address in order to unlock the private key.

When the payment is complete, the transaction is broadcasted and written into the chain, meaning that the account public key has been exposed, and all transaction information, payment habits, account information are traceable. This violates Bitcoin’s initial purpose for privacy, and increases the possibility of being attacked once the private key is rebuilt. This is also one of the reasons why Bitcoin uses public key hashes as Bitcoin addresses in general transactions, rather than public keys directly.

Advantages of UTXO

  • Strong privacy; no account concept; each output refers to a new address.
  • UTXO data is independent between each other, so parallel transaction processing is supported.

(In the next part, we will discuss how Vite leverage UTXO model in transaction design. To be continued)

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Official: https://www.vite.org/

Telegram:

Twitter:https://twitter.com/vitelabs

Discord:https://discordapp.com/invite/CsVY76q

Vite Labs

Official blog for Vite, a new-generation public blockchain

Khun Sir

Written by

Khun Sir

Crypto enthusiast. Experienced in investment, business development, marketing, and community management.

Vite Labs

Vite Labs

Official blog for Vite, a new-generation public blockchain