Crypto Basics: Building on top of Bitcoin

Bitcoin, Layer 2 & the Lightning Network

Learn Crypto tries as much as possible to explain concepts in simple language, but reading the headline of this article, you might feel that we’re failing in our mission.

If you’ve followed this section on the Basics of Crypto sequentially you’ll know that Bitcoin is a new form of internet money which is digitally scarce. That scarcity makes it an excellent store of value. So far so good,

But for it to become a widely used form of money -  used for everyday purchases - it also needs to be as fast and convenient as the contactless options we are used to.

Unfortunately, Bitcoin out of the box cannot do this, because of something called the Bitcoin trilemma, which has been already introduced

The trilemma highlights the difficulty of accommodating the three ideal aspects of a blockchain-based money system -

  1. Security
  2. Scalability
  3. Decentralisation. 

Fiat currencies have traditionally sacrificed decentralisation to provide security and scalability in a highly centralised manner; which creates problems of accountability and trust (see the 2008 Financial Crisis).

Bitcoin can provide security and decentralisation but at the cost of scalability. The bitcoin blockchain can currently only process around five transactions per second, when Visa processes thousands of transactions per second. 

The term Layer 2 simply refers to the idea of building functionality on top of Bitcoin’s blockchain, to solve the scalability part of the trilemma; the Lighting Network is a specific Layer 2 solution, focused on speeding up payments and competing with the likes of Visa.

Let's zoom in to understand exactly how you can build on top of Bitcoin - via Layer 2 - and explore the fundamentals of the Lightning Network.

Separating the Layers

The idea of Layer 2 is to build protocols or secondary infrastructure (e.g. the Lightning Network) that can interact with a fundamental base blockchain (Layer 1 e.g Bitcoin) but not be restricted by its scale limitations. This is where we make a clear distinction between on-chain (Layer 1) and off-chain (Layer 2). 

Transactions described as being on-chain are processed entirely through the relevant blockchain's consensus mechanism and recorded publicly onto the chain. 

Bitcoin requires Proof of Work, which takes roughly 10 minutes to confirm a transaction, with six recommended for finality, so you can see why on-chain transactions cannot compete with the speed of Visa..

Transactions described as being off-chain are processed outside of the given blockchain network and its consensus mechanism, but at a later date are batched together and the aggregate activity is recorded as an on-chain transaction.

The beauty of layer 2 solutions is that the main chain doesn't need to go through any structural change, or sacrifice either security or decentralisation in order to increase scalability.

For Bitcoin, the relevant Layer 2 application that can do this is called the Lighting Network. 

The Lightning Network: Channels & Invoices

The Lightning Network is an example of Layer 2 bitcoin service. It is an off-chain approach first formally proposed in a paper by Joseph Poon and Thaddeus Dryja in 2015.

The technology uses micropayment channels to scale the bitcoin blockchain’s capability by processing transactions more efficiently. 

Micropayment channels are opened between two parties looking to conduct a transaction. This channel is opened off-chain and without the overhead of the consensus mechanism, can process transactions much more efficiently than those that occur on-chain.

Transactions are added to the chain once both parties have closed the channel, i.e. agreed to the transaction's validity. 

Think of it like having credit at your local convenience store, agreed up to a fixed point, say €50. Once that limit is reached, you get an invoice and settle up.

On the Lightning Network, payment channels are opened between two parties through multi-signature addresses. These act as mutual vaults that both parties can deposit funds into; multi-signature means that more than one signature is needed to release funds, a fail-safe ensuring one side cannot walk away with the funds within the channel.

When funds are deposited, a channel is opened, creating a balance sheet between the two parties; this is then added to the main chain. 

Transactions between the two parties are recorded by updating this balance sheet to include the new balance between the two parties. These updates come in the form of Invoices

An invoice is a request for payment via the Lightning Network. Just like a traditional Invoice, say from your builder, includes instructions of where to remit the payment for services rendered, a Lightning Invoice is a structured set of instructions.

  • The payment amount
  • Which blockchain the invoice applies to 
  • An expiry date
  • Payee pubkey

Rather than using Bitcoin-style addresses Lightning Invoices are generally generated as QR codes, to ease the user experience, though they can be presented as alphanumeric strings. 

Illustrating Lighting By Example

We can illustrate the Lightning Network through a simple example. Bob wants to buy a coffee from a cafe. Bob opens a payment channel with the Cafe and deposits some BTC to create a balance sheet between them. 

When Bob buys a coffee the Cafe issues an Invoice via QR code which Bob pay through this Lightning Wallet on his phone.

The balance sheet between Bob/The Cafe gets updated; with every coffee Bob buys the relevant amount of BTC gets subtracted from Bob's balance, added to the coffee shop's balance. 

Both parties sign each updated balance sheet with their unique signature key. All this happens instantly, solving the issue of slow on-chain confirmations.

To close the payment channel and release the funds, either party can broadcast the latest agreed balance sheet to the Bitcoin main-chain network and get the transactions verified by Bitcoin's consensus mechanism. 

  • The Cafe will then receive the proceeds of Bob's coffee purchases
  • Bob will retain any unspent balance

Thus we can see how the Lightning Network significantly reduces the transactional load on the bitcoin blockchain. Thousands of transactions can occur within the micropayment channels between two parties. 

Only two transactions have to be processed by the blockchain - the micropayment channel's (balance sheet) opening and closing. 

The Lightning Network structure is designed to connect individual users through micropayment channels in the most efficient way possible. Therefore, it isn’t unnecessary to open a payment channel with every individual actor you want to use. 

A may only know B, but if B knows C, then A can connect to C via B acting as a kind of router or hub.

All of this not only means faster transactions - some estimates put the upper limits of lightning network capability at nearly 1 million transactions per second - it also means lower transaction costs. The fewer transactions that have to be processed by bitcoin's consensus mechanisms, the fewer fees have to be paid. 

The hope is that as the Lightning Network expands and the UX of wallets improves, you’ll be able to use just a few taps to buy a coffee by opening a channel with a coffee shop and scanning a QR code.

The Lightning Network - Bitcoin's killer Application? 

By enabling the transaction to occur through payment channels rather than on-chain, the lightning network offers a potential way for bitcoin to address its scalability problem. People have likened this to what fiat currency did for gold, arguing that the lightning network could be bitcoin's 'killer application'. 

The analogy works when you think about it, fiat currency was a way of scaling gold, just like the lightning network is a way of scaling bitcoin. In a sense, Fiat 'killed' gold as a currency and turned it into a value store. It remains to be seen if the lightning network can do this for Bitcoin. 

What then, are the potential drawbacks of the lightning network and how do other attempts to scale blockchains differ? 

Lightning is still handling only a tiny fraction of on-chain transactions. Nodes are growing along with the number of wallets that support Lightning, but there is a long way to go to simplify the User Experience of creating/managing channels and invoices.

Another, perhaps more significant, problem, is the risk of powerful hubs developing on the network. 

Hubs are big pools of capital that could facilitate a large proportion of the transactions in the network. This would risk the network's security, and of course, risk re-introducing centralisation to the system. 

The other main prominent attempt to scale blockchain technology is occurring on Ethereum. These upgrades are known as ETH 2.0 and include changes to consensus mechanism and a technology known as sharding. These are covered in more detail in the knowledge base article on Ethereum. 

The Lightning Network is a work in progress but should it be successful, may finally provide the solution to Bitcoin's trilemma, enabling it to scale transactions without compromising its core features. At that point it becomes more than a Store of Value, and can compete with fiat currencies as an effective Medium of Exchange.. 

Next step: What is Ethereum

Go to next step