Blockchain Security

Blockchain Structure

September 29, 2020 by Howard Poston

Introduction

The blockchain gets its name from its underlying structure. The blockchain is organized as a series of “blocks” that are “chained” together.

Understanding blockchain security requires understanding how the blockchain is put together. This requires knowing what the blocks and chains of blockchain are and why they are designed the way that they are.

Inside the blockchain block

The blockchain block is the data storage component of the blockchain’s distributed ledger. Each block in the blockchain contains a number of different transactions that it adds to the shared state of the blockchain network.

The image above shows a simple representation of several different blocks within a blockchain. The blocks are divided into two parts: the header (across the top of the image) and the body (represented by the tree dangling from block 11 in the image).

Inside the blockchain header

When discussing the structure of the blockchain, it is often described as a series of blocks that are linked together in a way that protects them against modification. However, it is only the headers of the blocks that are actually linked together in this way.

The header of a block in a blockchain can have a number of different fields, depending on the details of the particular blockchain implementation. However, the four fields shown in the image above are fairly common and each is significant to the operation of the blockchain:

  • Previous block hash: This value implements the “chains” in blockchain. More on it in a later section
  • Timestamp: This indicates roughly when a block was created. It is used by smart contracts that depend on timestamps and to determine how well the current average rate of block creation matches the target value
  • Transaction root: This value summarizes the contents of the block’s body. It helps to ensure that the transactions that the block contains benefit from the same integrity protections as the block header
  • Nonce: This is a random value controlled by the block creator. It is used in the Proof of Work consensus algorithm to change the hash of the block header. In Proof of Work, only a block with a header value less than a certain threshold is considered valid

Despite only containing four values, the header of a blockchain block achieves a number of different purposes. The transaction root and previous block hash contribute to preserving the integrity of the distributed ledger, and the timestamp and nonce make the original blockchain consensus algorithm (Proof of Work) possible and ensure that it is functioning correctly.

Blockchain bodies and Merkle trees

The image above provides a slightly misleading view of the body of a blockchain block. In reality, the body of the block can be structured as a simple list of the transactions that the block is intended to contain.

The image above shows the transactions organized into a Merkle tree. The reason for this is that a Merkle tree is used to protect the integrity of the transactions contained within a block.

The image shows a more detailed representation of a Merkle tree. A Merkle tree is structured as follows:

  • The bottom nodes contain the data to be stored within the Merkle tree
  • Interior nodes contain the hash of their child(ren)’s values

This structure takes advantage of the collision resistance of hash functions. A hash function is considered collision resistant if it is difficult to find two inputs that produce the same hash output.

This property of collision resistance means that it is infeasible to find two different Merkle trees that contain the same transaction root since doing so would require finding at least one hash collision. As long as the root of the Merkle tree is protected against modification, the data that it contains can be stored simply as an ordered list.

With this list, anyone can regenerate the tree and compare the calculated root hash to the stored one. If they match, then the data has not been modified. If they do not match, then the data has been tampered with.

The blocks’ “chains”

The “chains” in blockchain are designed to protect the integrity of the Merkle tree’s root hash (and the other values contained within a blockchain block). They do so by making it difficult for an attacker to create a valid, competing version of a blockchain that the network would accept over the legitimate one.

The blockchain’s chains are implemented using the previous hash value in the block header. Since each block in the chain contains the hash of the previous block header, modifying one block changes every block after it. To replace a single block in the blockchain, an attacker needs to create a valid version of every following block as well.

Creating a single valid block in the blockchain is relatively easy. It has to be for the blockchain to function. Blockchain consensus algorithms are designed to select the creator of the next block in the chain, and, if they create a valid block, the rest of the network should accept it.

It’s certainly possible to create a chain of valid blocks that competes with the original version of the blockchain, but consensus algorithms are designed to make this difficult. Additionally, getting other nodes to accept a divergent chain requires it to be longer than the original blockchain (under the longest chain rule). This means that an attacker not only needs to create a chain of valid blocks but also needs to do so more rapidly than the rest of the network combined, which is hopefully infeasible.

Conclusion

Blockchain’s blocks and chains are carefully designed. A blockchain block enables an entire list of transactions to be summarized within a fixed-size header. This header is structured to protect the integrity of the data it contains. These headers are protected in turn by the blockchain’s “chains” that link the entirety of the ledger together and make it resistant to modification and attack.

Sources

  1. What is a Merkle Tree? Beginner’s Guide to this Blockchain Component, Blockonomi
  2. Collision resistance, Crypto Wiki
Posted: September 29, 2020
Articles Author
Howard Poston
View Profile

Howard Poston is a cybersecurity researcher with a background in cryptography and malware analysis. He has a Master’s degree in Cyber Operations from the Air Force Institute of Technology and two years of experience in cybersecurity R&D at Sandia National Labs. He currently provides consulting and technical content writing for cybersecurity, cryptocurrency, and blockchain.