- Bitcoin Addresses, Private Keys, and Public Keys
- Bitcoin Transactions: Sending Funds and Scripts
- UTXOs: Unspent Transaction Outputs
- Multi-signature Addresses
This chapter is a bit special since it will not be directly dedicated to Lightning, but to Bitcoin. Indeed, the Lightning Network is a layer on top of Bitcoin. It is therefore essential to understand certain fundamental concepts of Bitcoin to properly grasp the functioning of Lightning in the subsequent chapters. In this chapter, we will review the basics of Bitcoin receiving addresses, UTXOs, as well as the functioning of Bitcoin transactions.
Bitcoin Addresses, Private Keys, and Public Keys
A Bitcoin address is a series of characters derived from a public key, which is itself calculated from a private key. As you surely know, it is used to lock bitcoins, which is equivalent to receiving them in our wallet.
The private key is a secret element that should never be shared, while the public key and the address can be shared without security risk (their disclosure only represents a risk to your privacy). Here is a common representation that we will adopt throughout this training:
- The private keys will be represented vertically.
- The public keys will be represented horizontally.
- Their color indicates who possesses them (Alice in orange and Bob in black...).
Bitcoin Transactions: Sending Funds and Scripts
On Bitcoin, a transaction involves sending funds from one address to another. Let's take the example of Alice sending 0.002 Bitcoin to Bob. Alice uses the private key associated with her address to sign the transaction, thereby proving that she is indeed able to spend these funds. But what exactly happens behind this transaction? The funds on a Bitcoin address are locked by a script, a type of mini-program that imposes specific conditions for spending the funds.
The most common script requires a signature with the private key associated with the address. When Alice signs a transaction with her private key, she unlocks the script that blocks the funds, and they can then be transferred. The transfer of funds involves adding a new script to these funds, stipulating that to spend them this time, Bob's private key signature will be required.
UTXOs: Unspent Transaction Outputs
On Bitcoin, what we actually exchange are not directly bitcoins, but UTXOs (Unspent Transaction Outputs), meaning "unspent transaction outputs".
A UTXO is a piece of bitcoin that can be of any value, for example, 2,000 bitcoins, 8 bitcoins, or even 8,000 sats. Each UTXO is locked by a script, and to spend it, one must satisfy the script's conditions, often a signature with the private key corresponding to a given receiving address.
UTXOs cannot be divided. Each time they are used to spend the amount of bitcoins they represent, it must be done in their entirety. It's a bit like a banknote: if you have a €10 bill and you owe the baker €5, you can't just cut the bill in half. You have to give him the €10 bill, and he will give you €5 in change. This is exactly the same principle for UTXOs on Bitcoin! For example, when Alice unlocks a script with her private key, she unlocks the entire UTXO. If she wishes to send only a part of the funds represented by this UTXO to Bob, she can "fragment" it into several smaller ones. She will then send 0.0015 BTC to Bob and send the remainder, 0.0005 BTC, to a change address.
Here is an example of a transaction with 2 outputs:
- A UTXO of 0.0015 BTC for Bob, locked by a script requiring Bob's private key signature.
- A UTXO of 0.0005 BTC for Alice, locked by a script requiring her own signature.
Multi-signature Addresses
In addition to simple addresses generated from a single public key, it is possible to create multi-signature addresses from multiple public keys. A particularly interesting case for the Lightning Network is the 2/2 multi-signature address, generated from two public keys:
To spend the funds locked with this 2/2 multi-signature address, it is necessary to sign with the two private keys associated with the public keys.
This type of address precisely represents the payment channels on the Bitcoin blockchain, specifically those on the Lightning Network.
What should you take away from this chapter?
- A Bitcoin address is derived from a public key, which is itself derived from a private key.
- Funds on Bitcoin are locked by scripts, and to spend these funds, one must satisfy the script, which generally involves providing a signature with the corresponding private key.
- UTXOs are pieces of bitcoins locked by scripts, and each transaction on Bitcoin consists of unlocking a UTXO and then creating one or more new ones in return.
- 2/2 multi-signature addresses require the signature of two private keys to spend the funds. These specific addresses are used in the context of Lightning to create payment channels.
This chapter on Bitcoin has allowed us to review some essential notions for what follows. In the next chapter, we will specifically discover how the opening of channels on the Lightning Network works.
Quiz
Quiz1/5
lnp2012.2
Why are UTXOs often compared to banknotes?