Storing transactions
Popularized by Bitcoin, a blockchain is exactly what it sounds like. A chain of blocks. It can’t be that simple, can it?
At a high level, it is that simple. But under the hood, there are various moving parts working together to create a blockchain network. Blockchains can be public or private and have different consensus mechanisms. Before exploring these differences, we need to understand the basics.
Since Bitcoin introduced us to blockchain, a good first step is to understand the characteristics of a blockchain through the context of Bitcoin.
A blockchain stores data contained within “blocks”. In theory, a block can contain anything. In the Bitcoin network, blocks contain transactions. Bitcoin maintains a history of transactions through blocks.
That doesn’t sound like anything revolutionary. We’re already capable of tracking transactions. Why does Bitcoin store transactions in a blockchain?
What is a block?
We’ve established that the Bitcoin network exists to facilitate transactions and this network maintains a blockchain.
I’m sending you one bitcoin. The first step in the process is the memory pool (mempool).
When I send you bitcoin, it’s broadcast to the Bitcoin network and gets placed in the Bitcoin mempool. The mempool is the staging area for a block. Not all blockchains use mempools, but it’s a fundamental component of Bitcoin and many other blockchains such as Ethereum. Unconfirmed transactions congregate inside the mempool.
From the mempool, the transaction that I sent you moves to the next block.
When a new block is created, it pulls unconfirmed transactions from the mempool. The confirmation process adds this new block to the existing chain of blocks that came before it.
Along with transactions, a block contains more information. Among this information is a pointer to the previous block. As every block points to the block before it, the chain of blocks create a path back to the first (genesis) block. So Bitcoin is a blockchain that keeps a historical record of all the transactions that have occurred on its network.
Blocks have further complexities. Bitcoin limits the size of its blocks. Other blockchains limit their blocks in other ways. The limits are often in place to prevent spam transactions.
That’s interesting, now we know what a block is, but that doesn’t explain why we need to store our transaction history on a blockchain.
Nodes and Miners
Okay, we’ll get to the burning question of why we’re even storing our transactions on a blockchain. But first we need to understand a few more details.
Nodes
Without nodes the Bitcoin blockchain would not be possible.
We just learned about the mempool. When a transaction enters the mempool, we’re relying on nodes to legitimize the transaction. Most importantly, Bitcoin aims to solve the problem of double spending. A currency system can’t work if users can send coins to another user while also spending those same coins elsewhere. So the role of the node is to maintain the honesty of the network. Nodes keep a history of the blockchain, and they share this history with each other.
A global distribution of nodes is one aspect that makes Bitcoin decentralized.
Miners
When transactions are deemed legitimate, miners play the essential role of creating a new block.
If the incentives are right, miners take transactions from the mempool and add it to the next potential block. In the Bitcoin network, users choose a tip to include with their transaction. This fee goes to the miner, so transactions with higher fees are more enticing for miners to confirm. Less favorable transactions remain in the mempool. Miners are also rewarded some Bitcoin for creating a new block, and a new block is created roughly every 10 minutes.
So I sent you some Bitcoin. My transfer request was broadcast to the Bitcoin network. The transaction got placed in the mempool. The multitude of nodes that maintain the history of the Bitcoin network independently verify that my transaction conforms to the rules of the network. From there, a miner is satisfied with the tip I’ve attached to the transaction, and the miner adds the transaction to the next block.
A global distribution of miners is another feature that makes Bitcoin decentralized.
Can we answer the question? We’re already capable of storing data and record keeping, so why do we need a blockchain (which sounds unnecessarily complex) to store transactions?
Consensus
We’re going to answer our question soon, but we need to understand another fundamental concept.
What does the miner do after choosing transactions for the next block?
As we learned earlier, blockchains can be categorized based on their “consensus mechanisms”. Bitcoin uses “Proof of Work” consensus. In proof of work, the miners compete with each other to solve a complex equation. This is an energy intensive battle, and the energy is a major component of the “proof”. Solving the equation is the “work”. The first miner that solves the equation is rewarded with a fixed amount of bitcoin along with all of the fees from the transactions included in the block. The block reward is cut in half every few years.
We also learned that blocks are limited in their size. So not every transaction in the mempool is going to make it into the next block. Transactions are going to vary in size, so a block can only fit so many transactions. Currently, a Bitcoin block contains about 2000 transactions.
The transactions with the most generous tips will be chosen first. If you leave a laughable, disrespectful tip it may stay in the mempool forever. The amount you’ll have to tip will vary based on how congested the network is. The busier and more congested the network, the higher your tip will have to be to be in order to be included in the next block.
Once a miner has successfully solved the equation, it broadcasts the block to the nodes for verification. Once the block is independently verified by the nodes, they reach a consensus and the block is confirmed. This is the first confirmation. Each subsequent block added afterwards counts as another confirmation. Different blockchains will have their own parameters for finalization of a block. For Bitcoin, a transaction is usually considered finalized after 6 confirmations. That means, after our transaction is added to the block, 5 subsequent blocks would deem our transaction “finalized”.
A globally distributed group of nodes and miners reached a consensus, and you now have a claim to spend the amount of bitcoin I sent you.
We can use websites like mempool.space to check network statistics such as the current transaction fee recommendation and blocks to be confirmed.
Well, now we have to answer another question before we get to our original question of “Why do we need a blockchain?”: What is this equation that miners need to solve?
Cryptography
We haven’t yet mentioned the star of the show, cryptography. It’s a mathematical method to secure communication and information, and it serves as the backbone of blockchains. We can take any piece of information of arbitrary length and return a fixed sized output. The output is a “hash”. This process fleshes out some key aspects of the Bitcoin network.
SHA-256
Specifically, the Bitcoin network utilizes the SHA-256 cryptographic hash function. It contributes to an important aspect of the Bitcoin network: wallets. Wallets are derived using cryptographic functions. We input a seed phrase in the SHA-256 function and the output hash serves as our “wallet address”. Wallets are our portal to the blockchain.
Another fundamental concept in the Bitcoin network is the signature. Bitcoin uses the Elliptic Curve Digital Signature Algorithm (ECDSA) to create signatures. Wallets exist as a private and public key pairs. The private key (something you never want to share) is used to create a signature with ECDSA. The public key (which is derived from the private key using yet another hashing function: RACE Integrity Primitives Evaluation Message Digest) is used to verify signatures. We share our public keys in order to receive Bitcoin.
Solving the problem
We spoke earlier about how blocks contain more information than just transactions. Another piece of information included in a block is the nonce. The nonce serves as a counter that indicates how many attempts it took for a miner to solve the problem. The nonce plays a key role in creating the block hash.
Here is an example of a block. The nonce is stored as a hexadecimal value: 0x90d9cd6a (2,430,193,002 in decimal).
Difficulty
So what exactly is the miner “solving” and what role does the nonce play?
The miners take the contents of the block (the transactions hash, the previous block hash, the nonce, and the rest of the information included in the block) and throw it into the SHA-256 function. The miners increment the nonce (while the rest of the contents of the block remain the same) until they arrive at the “solution”.
If we look back at the same block from earlier, we see the block hash is:
0000000000000000000341a3c14bd99a9d2cfbe880b3233be965daae91c3a296
That’s 19 leading zeros. This hash is the “solution”, and it is a value that is lower than the current target number.
The target number is based on the current difficulty set by the network.
The miners compete to arrive at a solution (a hash value) that is smaller than the target number (a number which is chosen based on the current difficulty).
Hashrate
Bitcoin and other proof of work blockchains have a hashrate metric. This measures the combined computational ability of all the miners in the network.
In order to maintain a “1 block per 10 minutes” standard, the network adjusts the difficulty every 2016 blocks based on network hashrate and other factors.
As the hashrate of the network increases, the difficulty also increases. The higher the difficulty, the lower the target number. The lower the target number, the more leading zeros required by the block hash (remember the block from earlier had 19 leading zeros).
As more miners join the network, the hashrate increases.
Recap
To recap, the Bitcoin blockchain utilizes the SHA-256 cryptographic hashing function as the foundation of its network. SHA-256 plays a role in producing wallets and signatures which are essential in creating transactions. SHA-256 is also a key component of the competition in the proof of work dynamic. The competition involves finding the correct hash that is a value lower than the current target. The target is based on the current difficulty. And the difficulty is adjusted every 2016 blocks to ensure that a block is produced every 10 minutes.
So now we understand why Bitcoin is a “cryptocurrency” (because of the cryptography involved).
Surely, we know enough now to answer our question. Why do we need a blockchain to store our transactions?
The transaction process
That was a lot of information to absorb, and we have enough information to answer our question. But we’re going to perform a segue to touch on a Bitcoin specific topic. Everything we’ve discussed so far, while in the context of Bitcoin, was information to help answer the question, “Why do we need to store our transactions on a blockchain?”
Since we’re talking about Bitcoin, we might as well talk about UTXOs and Script (information that isn’t important to answer our question but important to understand Bitcoin).
UTXO
When I sent you 1 bitcoin, technically, I didn’t send you bitcoin. You received an unspent transaction output (UTXO). Bitcoin transactions have inputs and outputs, and the UTXO you received is your claim to 1 bitcoin. When I sent you the UTXO, I “spent” a UTXO of my own and used it as the input for the transaction that I initiated. When you choose to send your bitcoin, you’ll use your UTXO as an input for your transaction and the receiving party will gain a UTXO.
Each UTXO is unique. When we pay with dollars, we’re using a fungible item. That means the dollars in your wallet are interchangeable with the dollars in my wallet. UTXOs are non-fungible. When you received a UTXO through our transaction, it wasn’t the same UTXO I owned. So wallets contain non-fungible UTXOs which are claims of varying amounts to the Bitcoin network.
Script
Different programming languages will be utilized based on the blockchain. Ethereum uses languages such as Solidity and Vyper to interact with the low level opcodes that govern the Ethereum Virtual Machine. Bitcoin uses a simple programming language called Script. Script is intentionally limited in it’s capabilities (not Turing complete) and plays an important role in managing transactions.
UTXOs and Script are defining features of Bitcoin. Not all blockchains will use the UTXO model, and not all blockchains use a limited language such as Script. But all blockchains will have some model to govern transactions, and they will be mediated by programming languages.
Public
Blockchains can be public or private. Bitcoin is a public blockchain.
Transparent
Public blockchains provide transparency. We can view every transaction that occurs on the network. We also learned The Bitcoin network is decentralized because of the distributed nature of nodes and miners. There are about 55,000 nodes maintaining the integrity of the network. The combination of transparency and decentralization creates a trustless environment.
Since we’re viewing blockchains through the lens of Bitcoin, we are making financial arguments. Perhaps, institutions would prefer the tradition of maintaining centralized control. But from the perspective of the user, a public blockchain is an improvement over traditional finance.
Keeping track of transactions in a public, proof of work blockchain removes the need to trust centralized institutions. Contrast this with our traditional financial system. We trust that when it’s time to withdraw, our banks will allow us to do so. We trust our banks to have the money that they say they have. We can’t verify their claims in the same way we can use a block explorer to view the activity occurring on the Bitcoin network.
Security
Security is also an improvement offered by blockchains (whether they’re public or private). Security is inherent in blockchains because of the role cryptography plays. Cryptography guides every action on the blockchain. In contrast to traditional finance where sensitive information is constantly hacked.
It’s not all roses. While highly unlikely to occur on the Bitcoin network because of the resources it would require, a blockchain can suffer a 51% attack.
Why is it unlikely to occur in the Bitcoin network? Malicious actors would need more than 50% of the computing power. Depending on how they want to attack the system (denial of service, sybil attack, double spend, etc.), it would require a massive amount of resources to successfully attack the network. The network hashrate and the distribution of nodes are factors that influence the ease of carrying out the attack. Bitcoin is robust in those areas.
However, on a network that isn’t as distributed or with a much lower network hashrate, attackers can feasibly execute a 51% attack. The Ethereum Classic public, proof of work blockchain has been victimized by the attack on more than one occasion.
Private
Of course, we can also have private blockchains. Potentially, they would be less transparent (if at all) or centralized. Without transparency or decentralization, a blockchain would still be different from our current method of storing data. Private blockchains have the potential to have a positive impact on many sectors.
The goal of these blockchains would be to securely share sensitive information. Access would be limited to the parties involved using the public/private key dynamic mentioned earlier. These blockchains could also remove constraints on mining and eliminate the concept of fees all together. The goal would be to create a private, distributed database.
Private blockchains could be implemented by governments to enhance transparency related to public services, identity management, property ownership, and more.
Supply chains could be improved offering enhanced transparency and traceability between businesses and consumers.
Educational institutions could be connected by a private blockchain sharing credentials, certificates, and licenses.
Healthcare facilities could securely share sensitive information
The key idea to understand is that public blockchains do not require permission while private blockchains are permissioned.
Why use a blockchain?
Warren Buffet says Bitcoin is rat poison. If Bitcoin could speak, it would say the banks are the rats. Our financial system argues that we need centralized control to prevent a chaotic market. Bitcoin argues that a distributed, decentralized system of consensus governed by cryptography will bring chaos to heel.
Regardless of which side we align with, Bitcoin has popularized an interesting technology.
While Bitcoin is public blockchain that uses proof of work, blockchains can take other forms. Bitcoin’s proof of work consensus method is energy intensive. Other consensus mechanisms, such as proof of stake, don’t rely on energy but still maintain the foundation of cryptography.
We can already use centralized databases with encryption to keep information secure. So why are we lauding the cryptography in a blockchain as some new discovery?
Transparency.
While the security offered by cryptography is appealing, the true value in blockchain lies in transparency. Blockchains, whether public or private, provide a “fraud-proof” foundation.
Blockchains can be applied to much more than finance.
The real goal of blockchain is to eliminate trust. When we remove trust from financial, medical, or government settings, we are able to operate with new found confidence. We don’t have to trust that our banks have our funds. We don’t have to worry about manipulation of medical records after the fact. We are confident the results of an election haven’t been manipulated as each vote is verifiable on the blockchain with a cryptographic proof. The implementation of blockchain provides more confidence in our institutions.
The system doesn’t have to be one where miners compete for a reward. For Bitcoin, that system makes sense. But for other fields such as healthcare, the rules can be adjusted. What blockchain brings is a level of transparency that removes doubt.
If trust is an issue, and a need for transparency is apparent, blockchain could be the solution.