DEV Community

Cover image for Blockchain: Understanding basics - part 2
Vishnu Prasaath
Vishnu Prasaath

Posted on • Originally published at blog.vishnuprasaath.dev on

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 cant 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: Lets 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. Lets call them 81a, 81b, 81c.

three_blocks

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. Lets say you see 81a first. You can start building the next block on that, trying to create 82a:

mine_on_first

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:

mine_on_longest

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:

  1. Refusal to relay valid transactions: A dishonest miner can choose not to pass valid transactions to other nodes within the network.

  2. Manipulating block contents: They can attempt to create blocks that selectively include or exclude specific transactions according to their preferences.

  3. 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:

  1. 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.

  2. Stealing bitcoins from your account: The security measures in place prevent a dishonest miner from pilfering bitcoins from a user's account.

  3. 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:

  1. Creating dual payments: Initiate two payments with the same bitcoinsone to an online retailer and the other to another address under your control.

  2. Broadcasting the retailer payment: Only share the payment intended for the retailer with the network.

  3. Retailer payment confirmation: As the payment is included in an honest block, the retailer dispatches the ordered goods.

  4. 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.

  5. 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.

  6. 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.

double_spend

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 arent 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.

Top comments (1)

Collapse
 
parth51199 profile image
parth51199

I thought this was a great article that provides a comprehensive overview of blockchain technology. I would definitely recommend it to anyone who is interested in learning more about this fascinating technology.