Introduction and Summary
As a start, we will delve into the workings of a conceptual ‘Bitcoin-like’ blockchain to gain an understanding of the fundamental concepts. We will then be able to expand the concept to other blockchains. The specific topics are covered in the links below:
The diagram below is a good, but simplified starting point to illustrate the basic blockchain structure.
Blocks are cryptographically chained together
Each block above contains the minimum number of elements to demonstrate the basic structure of the blockchain. These include the index, timestamp, data (for example a group of payment transactions) and hashes. The hashes could be outputs of an SHA-256 cryptographic function. An SHA-256 hash function is executed using the content of the block (the index, timestamp, data and the hash of the previous block). SHA-256 stands for Secure Hash Algorithm – 256 bit, and is a type of mathematical function that turns data into a unique, fixed-size 256 bit (32-byte) number or fingerprint of that data called a hash. If any data item within a block is changed, the hash generated for that block will change.
This is demonstrated in the diagram below. If the data in block 44 is changed from “DESERT” to “STREET”, all hashes of the consecutive blocks must be changed to preserve the blockchain’s integrity. This is because the hash of each block depends on the value of the hash for the previous block.
Only valid blocks are added to the chain
At any given time nodes must be able to validate if a block or a chain of blocks is valid. As new payment transactions are created by the participants in the network, the nodes must decide whether to accept the payments as valid or not. Only valid payments will be added to a block. And for a block to be valid the following conditions must apply:
- The index of the block must be one number larger than the previous
- The previousHash of the block matches the hash of the previous block
- The hash of the block itself must be valid
Therefore, if any record in one of the blocks is tampered with, the nodes will detect the discrepancy when they run their block validation functions. Modifying one block will require all subsequent blocks to be recalculated in order for the chain to preserve integrity and to be confirmed as valid by the nodes. The ‘Genesis block’ is the first block in the blockchain. It is the only block that has no previousHash value.
A more realistic but simplified illustration of the blockchain is represented below:
A more realistic structure of a blockchain
Generaly, each block contains a header and a collection of transactions and other data. A group of one or more new transactions is collected into the transaction data part of a block and not the header. Instead, transactions (their ID’s to be more specific) are paired/concatenated and each pair is hashed. The resulting hashes are then paired, hashed, paired again, and hashed again until a single hash remains. This single hash is called the Merkle root of a Merkle tree. This Merkle root, and not the collection of transactions is what is stored in the block header. Each block header also stores the hash of the previous block’s header, thus cryptographically chaining the blocks together.
Thus far, we have only discussed a basic structure of a blockchain and how to cryptographically link the blocks in the chain. We have not yet gone through the process by which the blocks are generated, validated by all the nodes, agreed to by all the nodes, and finally written to the blockchain.
Although not necessary, it is quite interesting to divert to a seemingly unrelated but fascinating subject before delving further into the blockchain. This subject is the Byzantine General’s Problem.