Blockchain: Understanding basics - part 2
With peer-to-peer models, even if all peers are ‘trusted’, there is a potential problem of agreement or consensus – let's assume that each peer is updating at a different speed and end up holding different states, how to determine the “real” or “true” state of the data?
In the case of an ‘untrusted’ peer-to-peer network, we can’t necessarily trust any of the peers, how to ensure that the bad peers won't corrupt the system?
CONSENSUS: How to resolve conflicts?
A very basic conflict is when multiple miners create blocks at the same time. As the blocks take time to be shared across the network, which one should be considered a legit block?
Example: Let’s consider that all the nodes on the network have synchronised their blockchains, and they are all on block number 80.
If three different miners create ‘Block 81’ at roughly the same time, which ‘Block 81’ should be considered valid? Remember that each ‘Block 81’ will look slightly different: They will certainly contain a different payment address for the 25 BTC block reward, and they may contain a different set of transactions. Let’s call them 81a, 81b, 81c.
Which block will be considered the legit one?
How to resolve this?
Longest chain rule. In Bitcoin, this conflict is resolved by a rule called the “longest chain rule”.
In the example above, you would assume that the first ‘Block 81’ you see is valid. Let’s say you see 81a first. You can start building the next block on that, trying to create 82a:
Treat the first block you see as legitimate.
However, in a few seconds, you may see 81b. If you see this, you keep an eye on it. If later you see 82b, the “longest chain rule” says that you should regard the longer ‘b’ chain as the valid one (…80, 81b, 82b) and ignore the shorter chain (…80, 81a). So you stop trying to make 82a and instead, start trying to make 83b:
Longest chain rule: If there are multiple blocks, treat the longest chain as legitimate.
The “longest chain rule” is the rule that the Bitcoin blockchain ecosystem uses to resolve these conflicts which are common in distributed networks.
However, with a more centralised or trusted blockchain network, we can make decisions by using a trusted, or senior validator to arbitrate in these cases.
DEFENCE: How do you make it hard for baddies?
The most common issue with permissionless, or open networks is that they can be attacked easily. So we need to make sure the network as a whole needs to be trustworthy, even if few nodes aren't.
Understanding the Miscreant's Capabilities
A dishonest miner, despite causing concern, is confined in terms of the harm they can inflict. Here are some actions a dishonest miner can take:
Refusal to relay valid transactions: A dishonest miner can choose not to pass valid transactions to other nodes within the network.
Manipulating block contents: They can attempt to create blocks that selectively include or exclude specific transactions according to their preferences.
Attempting to construct a longer chain: By creating a sequence of blocks that surpasses the existing main chain, a dishonest miner can render previously accepted blocks as "orphans," thereby excluding them from the primary chain.
However, a dishonest miner is unable to execute the following actions:
Generating bitcoins out of thin air: While theoretically possible, creating bitcoins out of nothing remains unfeasible. If such transactions are attempted, other nodes will reject them, emphasizing the importance of confirming transactions across multiple nodes.
Stealing bitcoins from your account: The security measures in place prevent a dishonest miner from pilfering bitcoins from a user's account.
Impersonation or unauthorized payments: A dishonest miner cannot conduct payments on behalf of others or pretend to be someone else within the network.
Transaction Security
The impact of a dishonest miner's actions on transactions is limited, primarily due to the presence of honest nodes in the network. If the majority of nodes are honest, they will reject any invalid transactions introduced by the miscreant. Moreover, these honest nodes will propagate valid transactions to ensure their inclusion in subsequent blocks, even if the dishonest miner refuses to relay them.
Block Security
In the context of blocks, the influence of a miscreant with significant block creation power becomes more pronounced. They can delay a specific transaction by omitting it from their blocks. However, other honest nodes will recognize this transaction as an "unconfirmed transaction" and incorporate it into their blocks.
A more significant concern arises when a dishonest miner manages to construct a longer chain of blocks compared to the rest of the network. By invoking the "longest chain rule," the miscreant can effectively undermine a transaction. Here's an overview of this strategy:
Creating dual payments: Initiate two payments with the same bitcoins—one to an online retailer and the other to another address under your control.
Broadcasting the retailer payment: Only share the payment intended for the retailer with the network.
Retailer payment confirmation: As the payment is included in an honest block, the retailer dispatches the ordered goods.
Secretly constructing a longer chain: Covertly generates a longer chain of blocks that excludes the payment to the retailer but includes the payment to yourself.
Publishing the longer chain: When the longer chain is published, nodes following the "longest chain rule" ignore the honest block containing the retailer payment. Instead, they continue building on the longer chain, effectively orphaning the honest block.
Invalidating the retailer payment: Due to the existence of the longer chain, honest nodes deem the original payment to the retailer invalid, as the bitcoins associated with it have already been spent according to your longer chain.
The “double spend” attack.
This is called a “double spend” because the same bitcoins were spent twice – but the second one was the one that became part of the eventual blockchain, and the first one eventually gets rejected.
How to make it hard for dishonest miners to create blocks?
Remember, this is only a problem for ledgers where block-makers aren’t trusted.
Essentially you want to make it hard, or expensive for baddies to add blocks. In Bitcoin, this is done by making it computationally expensive to add blocks. Computationally expensive means “takes a lot of computer processing power” and translates to financially expensive (as computers need to be bought then run and maintained).
The computation itself is a guessing game where block-makers need to guess a number, which when crunched with the rest of the block data contents, results in a hash/fingerprint that is smaller than a certain number. That number is related to the ‘difficulty’ of mining which is related to the total network processing power. The more computers join in to process blocks, the harder it gets, in a self-regulating cycle.
Every 2,016 blocks (roughly every 2 weeks), the Bitcoin network adjusts the difficulty of the guessing game based on the speed in which the blocks have been created.
This guessing game is called “Proof of work”. By publishing the block with a fingerprint that is smaller than the target number, you are proving that you did enough guesswork to satisfy the network at that point in time.
Subscribe to my newsletter
Read articles from Vishnu Prasaath directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by
Vishnu Prasaath
Vishnu Prasaath
A Full Stack Developer and an open source enthusiast. Curious tech junkie. Breaking keyboards to build software from 'Hello World' 🌍 to 'cloud' 🚀! Perpetually caffeinated 🍼. I write code by day, and laugh at it by night.