Blockchain introduction
A blockchain is made up of a series of blocks, where each block contains a set of transactions that have been validated and confirmed by the network. Each block in the chain has a unique cryptographic hash, which identifies it and links it to the previous block in the chain. This creates an immutable record of all the transactions that have taken place on the network.
The header of each block in the chain contains a number of fields, including:
By including the previous block hash in each block header, the blockchain creates a linked list of blocks that cannot be modified without invalidating the entire chain. This makes the blockchain a secure and reliable ledger for recording transactions.
A blockchain is created through a process called mining, which involves a distributed network of nodes competing to solve a complex mathematical puzzle. The first node to solve the puzzle is rewarded with a block of newly created cryptocurrency and the right to add a new block of transactions to the blockchain.
The process of creating a new block involves taking a group of pending transactions, verifying them for accuracy and consistency, and then adding them to the block. The block also includes a reference to the previous block in the chain, forming a chronological record of all transactions on the blockchain.
Once the block is created, it is broadcast to the network for validation and added to each node’s copy of the blockchain. Each node independently verifies the block’s contents and the proof of work that was required to create it, ensuring that the block is legitimate and that the miner has expended the necessary computational resources to create it.
As new blocks are added to the chain, the blockchain grows longer, creating an immutable and transparent ledger of all transactions that have ever occurred on the network.
Let me talk little about the how the 1st block(genesis block) in the blockchain is created . The genesis block is the first block in a blockchain, and it is created differently for each blockchain.
In most cases, the genesis block is created by the developers of the blockchain. They typically define the initial parameters of the blockchain, such as the initial distribution of tokens and the mining rewards. They also specify the initial transactions and other information that will be included in the genesis block.
Once the initial parameters and transactions are defined, the developers will generate the genesis block using a special software tool. This block is then added to the blockchain as the first block, and all subsequent blocks are added on top of it.
The creation of the genesis block is a critical step in the creation of a new blockchain, as it sets the foundation for the entire blockchain. Any errors or mistakes made in the creation of the genesis block can have significant consequences for the blockchain's security and stability.
The Genesis block contains a hardcoded Merkle root that is used to validate the block. Once the Genesis block is created, its Merkle root cannot be changed. It is only used to establish the initial state of the blockchain and does not change as new blocks are added.
In Ethereum, the genesis block is created through a JSON file called genesis.json. This file contains various parameters that are used to create the genesis block, such as the initial state of the Ethereum network, the timestamp, the difficulty, and the gas limit. Once the genesis.json file is created, it can be used to initialize the Ethereum network by running a command such as:
geth init path/to/genesis.json
This command initializes the genesis block and creates the initial state of the Ethereum network based on the parameters defined in the genesis.json file.
Example genesis.json :
{
"config": {
"chainId": 1234,
"homesteadBlock": 0,
"eip155Block": 0,
"eip158Block": 0
},
"difficulty": "0x400",
"gasLimit": "0x21000",
"alloc": {
"0x0000000000000000000000000000000000000001": {"balance": "1000000000000000000000000000"},
"0x0000000000000000000000000000000000000002": {"balance": "2000000000000000000000000000"}
},
"coinbase": "0x0000000000000000000000000000000000000000",
"timestamp": "0x00",
"parentHash": "0x0000000000000000000000000000000000000000000000000000000000000000",
"extraData": "",
"mixHash": "0x0000000000000000000000000000000000000000000000000000000000000000",
"nonce": "0x0000000000000042"
}
In Bitcoin, the genesis block was hardcoded into the original Bitcoin client software by its creator, Satoshi Nakamoto. The genesis block is defined in the source code of the Bitcoin client and cannot be changed without a hard fork of the network. The genesis block contains a special message from Nakamoto, which reads "The Times 03/Jan/2009 Chancellor on brink of second bailout for banks." This message is widely interpreted as a commentary on the flaws of the traditional banking system and the need for a decentralized alternative like Bitcoin.
A Merkle tree is used in blockchain to provide efficient and secure verification of large data structures. Every block in a blockchain contains a Merkle root, which is calculated by hashing all the transactions in the block using a tree structure. In a blockchain, each block contains a set of transactions. Instead of including the entire transaction data in the block header, which would make the header unnecessarily large, a Merkle root is included.
The Merkle root is the hash of all the transaction hashes in the block. To verify that a transaction is included in the block, a node in the network only needs to have the block header and the Merkle proof of the transaction. The Merkle proof consists of a path of hashes in the Merkle tree, starting from the transaction hash and leading up to the Merkle root in the block header.
By using a Merkle tree, the block header can be made small while still allowing efficient and secure verification of the transaction data. Additionally, it provides a way to easily detect any tampering with the transaction data, as any change in a transaction will cause a different hash for that transaction and all the hashes in the path up to the Merkle root.
In the above fig copied from wikipedia :
Each leaf node represents a block of data that needs to be hashed. The hashes of the leaf nodes, denoted L1, L2, L3, and L4, are calculated independently. The parent node of L1 and L2 is computed as the hash of the concatenation of L1 and L2 hashes, denoted as Hash 0 (H00). Similarly, the parent node of L3 and L4 is computed as the hash of the concatenation of L3 and L4 hashes, denoted as Hash 1 (H10). Finally, the top hash, denoted as Top hash (H01), is computed as the hash of the concatenation of Hash 0 and Hash 1.
Top hash (H01)
/ \
Hash 0 (H00) Hash 1 (H10)
/ \ / \
L1 (0-0) L2 (0-1) L3 (1-0) L4 (1-1))
The binary hash tree can be visualized as a tree as above, with the leaf nodes at the bottom and the root node at the top. Each node is labeled with its hash value, and the arrows indicate the direction of the hashing process.
To verify the integrity of the data, a user can verify the top hash value against a trusted value. If the top hash matches the trusted value, then the data has not been tampered with.
To verify the integrity of any block in the binary hash tree, we start from the leaf nodes (L1, L2, L3, L4) and move up the tree towards the root node (Top Hash).
Let's say we want to verify the integrity of hash 1-0, which is the hash value of data block L3.
In summary, to verify the integrity of any block in a binary hash tree, we need to compute the hash values of its sibling nodes and the parent nodes all the way up to the root node, and compare the resulting Top Hash value with the known Top Hash value. If they match, we can be sure that the block is authentic and has not been tampered with.
What is Merkle Tree?
A Merkle Tree is a type of data structure used in cryptography and computer science for efficiently verifying the integrity and authenticity of large sets of data. It is named after its inventor, Ralph Merkle.
A Merkle Tree is a binary tree where each leaf node represents a piece of data, such as a transaction or a file, and each non-leaf node represents a hash of its child nodes. The hash function used to generate the hash value must be a one-way function that is collision-resistant, such as SHA-256.
The Merkle Tree allows for efficient and secure verification of large sets of data. Instead of having to download and verify every piece of data individually, a user can download only the root hash of the Merkle Tree and then verify the authenticity of a specific piece of data by following a path of hashes from the leaf node up to the root. If the hash value of each node along the path matches the hash value of its parent node, then the data is authentic and has not been tampered with.
How does transaction get it to block-chain ?
To get into a block, a transaction needs to go through several stages of verification and validation before it can be added to the blockchain:
Map b/w components and benefit:
How is Authentication and Authorization of transactions done?
The original blockchain was designed to operate without a central authority (i.e. with no bank or regulator controlling who transacts), but transactions still have to be authenticated.
In blockchain, authentication and authorization of transactions are achieved through the use of digital signatures and cryptographic verification.
This is done using cryptographic keys, a string of data (like a password) that identifies a user and gives access to their “account” or “wallet” of value on the system(Ex: Metamask).
Once the transaction is agreed b/w the users, it will be approved, or authorised, before it is added to a block in the chain.
Each user has their own private key and a public key that everyone can see. Using them both creates a secure digital identity to authenticate the user via digital signatures and to ‘unlock’ the transaction they want to perform.
Each transaction in a blockchain network is initiated by a specific user or entity, who creates a digital signature using their private key. This digital signature serves as proof that the transaction was initiated by the user and has not been tampered with during transmission. The digital signature is then verified by the network using the user's public key, which ensures that the transaction is authentic and authorized by the user.
Once the transaction is verified, it is then added to a block by a miner. For a public blockchain, the decision to add a transaction to the chain is made by consensus. This means that the majority of “nodes” (or computers in the network) must agree that the transaction is valid(Blockchain consensus typically means at least 51% of nodes are in agreement over the current global state of the network). Before adding the block to the blockchain, the miner must first solve a complex mathematical problem, known as a proof-of-work, which ensures the integrity of the blockchain network. Once the proof-of-work is solved, the block is added to the blockchain, and the transaction is recorded as a permanent and immutable part of the ledger. The people who own the computers in the network commonly called miners are incentivized to verify transactions through rewards. This process is known as ‘proof of work’.
Why solving the puzzle is required in order to add the block to blockchain?
Proof of Work (PoW): Many cryptocurrencies, including Bitcoin, use proof of work as the basis for their mining mechanism. Here’s how it works:
Security and Trust:
Recommended by LinkedIn
Solving the Puzzle (Proof of Work):
Adding the Block to the Blockchain:
Validation by Other Nodes:
Miner’s Incentive:
In summary, miners play a crucial role in securing the blockchain by solving puzzles, validating transactions, and ensuring the integrity of the system. Other nodes verify their work, maintaining the trustworthiness of the entire network. 😊
There are several consensus mechanisms used in blockchain, some of the most popular ones are listed below :
Strengths:
Weaknesses:
2. Proof of Stake (PoS): This consensus mechanism is used by Ethereum and several other cryptocurrencies. In PoS, validators stake their own cryptocurrency to participate in the consensus process. Validators are chosen to validate transactions based on the amount of cryptocurrency they have staked.
Strengths:
Weaknesses:
3. Delegated Proof of Stake (DPoS): This consensus mechanism is used by several blockchains, including EOS and BitShares. In DPoS, stakeholders vote for a set of delegates who are responsible for validating transactions and adding new blocks to the blockchain.
Strengths:
Weaknesses:
4. Byzantine Fault Tolerance (BFT): This consensus mechanism is used by several blockchains, including Hyperledger Fabric. In BFT, a set of validators must agree on the next block to be added to the blockchain, even if some of the validators are malicious or faulty.
Strengths:
Weaknesses:
5. Proof of Authority (PoA): This consensus mechanism is used by several private blockchains. In PoA, a set of validators are pre-approved to validate transactions and add new blocks to the blockchain. Validators are chosen based on their reputation and authority in the network.
Strengths:
Weaknesses:
6. Proof of Elapsed Time (PoET): This consensus mechanism is used by the Hyperledger Sawtooth blockchain. In PoET, validators compete to be chosen to validate transactions and add new blocks to the blockchain. The validator with the shortest "wait time" is chosen to validate the next block.
Strengths:
Weaknesses:
Overall, authentication and authorization in blockchain ensure that only authorized users can initiate transactions and that each transaction is secure and tamper-proof.
Both Bitcoin and Ethereum use Elliptic Curve Digital Signature Algorithm (ECDSA) as the public key cryptography algorithm for signing and verifying transactions.
In Bitcoin, the ECDSA algorithm is used with the secp256k1 curve, while in Ethereum, it is used with the secp256k1 curve or the alternative BN128 curve for some specific operations.
How the transactions are verified , signed and validated with the help of Public Key Cryptography ?
Below are the steps for Public Key Cryptography with ECDSA
1. Hashing Messages
In order to create a digital signature, the message that needs to be signed is first hashed using a secure hash function such as SHA-256. This produces a fixed-length message digest.
2. Signing the Hash
Once the message digest is created, the private key holder uses ECDSA to sign the message. This involves a mathematical process that generates a unique signature based on the private key and the message digest. The signature is a pair of numbers that can be verified using the public key.
3. Recover the Public Key
This step involves recovering the public key from the signature and the message digest. This is done using a mathematical process that involves solving an equation using the signature and the message digest. The result of this process is a pair of possible public keys.
4. Convert Public Key to Address
The final step is to convert the public key to an address. This involves hashing the public key using a secure hash function such as SHA-256 and RIPEMD-160. The result is a unique address that can be used to receive cryptocurrency.
Overall summary:
ECDSA is used in Bitcoin and Ethereum to create digital signatures for transactions. The process involves hashing the message, signing the hash with the private key, recovering the public key from the signature, and converting the public key to an address.
Please see this article on usage of public key cryptography: Brief about Ethereum accounts | LinkedIn
Some of the important terms in block chain technology:
Thanks for reading till end, If you have any questions or suggestions, please leave a comment.