Hey Guyz! I am starting a series on Blockchain, where I will be writing about blockchain, Ethereum, solidity, smart contract audit, and their security implications, etc. In this part, I will be starting from blockchain fundamentals, so lets’ begin.
What is Blockchain
Have you ever seen the ledger in your house, I bet you already have seen it? A ledger in the local language is a diary where anyone maintains their financial transaction so that at the end of the month, he/she can track all of his expenses. Now think of every page in that diary as a block, and every block is connected to the previous block. Now that ledger you can call it a blockchain.
Blockchain is basically a distributed ledger that helps in the transfer of data in a business network. Data/information is stored in blocks, and every block is connected to its previous block, that’s why it is called a blockchain (chain of blocks). That data could be anything like property, contract, etc, Now, let’s see what is the design principle of blockchain.
Design Principles of Blockchain
The first design principle in the blockchain network is distribution. In the blockchain, a node is basically a device that volunteers in that network use for mining purposes. In a peer-to-peer network, if store our data in the central node, and if somehow the central node gets failed, then no nodes would be able to retrieve the data. So, that’s why in the blockchain every node has a copy of data, so in case any node gets failed, others will still have the access to latest data. Now, if every node has access to the data, it will create a problem with respect to privacy, now everyone can see who owns how much. For tackling this issue, blockchain has a concept of pseudonymity, where users hide behind an address so that other users can see that this particular address owns this much, but they can not see who is behind this address.
The second Design principle in blockchain architecture is Decentralization. Now, think, if every node in a network has a copy of data, who should hold the power of modifying the data, or adding the next block? If data modification power resides in the central node, then if any attack happens on the central node, then it would be impossible for updating the data in the nodes. So, that’s why every node in the blockchain network holds the power of updating data. But, if every node has the power, then there will be a problem of inconsistency, so for solving this problem consensus algorithm comes into play.
In the blockchain, as we know, every node has the power to modify the data, so every other node has to give their validation, if the data modified by the other node is correct or not. There are various consensus algorithms, currently, blockchain architecture is using a proof-of-work algorithm. We will learn about every other algorithm in upcoming blogs. For a basic understanding, this is more than enough.
source: Making sense of bitcoin and blockchain technology: PwC
The above picture will give you a holistic idea of how blockchain implementation works. First, a transaction( will cover in-depth the transaction) request has happened from the user’s end, now that request is broadcasted by nodes present in that particular peer-to-peer network. The node will tell which block will get added to the ledger. The node which will first find the block gets validated by other nodes, and the miner will get the reward(some bitcoin).
Transactions
Let’s Explore the life cycle of transactions happening in the blockchain. When I refer to the transaction, it could be anything like property, contract, etc. Here we will be referring to bitcoin transactions.
For example, Alice wants to transfer 1 bitcoin, so the following things will happen. Refer to the above picture.
- Alice will make a request for a transaction for 1 bitcoin through his wallet, and his transaction will be signed by his private keys.
- Then the transaction request will be broadcasted to the peer-to-peer network of the blockchain.
- The nodes in the network will verify the request using Alice’s public key if it is legit or not.
- Transaction will be allocated to the memory pool of the network, where the transaction is in a pending state.
- Now the miners will calculate the next block in the blockchain using the consensus algorithm, and all the other nodes will validate the block.
- If block validation is done, then the transaction would be completed and Bob will get 1 bitcoin. For more info on transactions, you can refer here.
Structure of Blocks
Now we will see, what information blocks contain in the blockchain network.
A block in the blockchain contains the following things:
- Block Size: Size of the block, 4-byte field.
- Block Height: The sequence number of blocks in the blockchain
- Tx Count: Number of Transactions contained in the block.
- Block Header: 80 bytes field containing the following things:
a. Time: Time when the block is mined
b. Version: Version Number of protocol
c. Previous Block hash
d. Nonce: 32-bit number, that miners try to find so that the block hash gets lower than the difficulty hash (for a block to be valid, block hash < difficulty hash)
e. Merkle Root: It’s constructed hierarchically combining hashes of the individual transactions in a block.
There are several implementations of blockchain, like bitcoin, Ethereum, Ripple, etc. We will be focusing more on Ethereum because it is currently widely accepted by the community. (refer to the below screenshot). So, In the next part, we will see some basics about Ethereum and move forward to solidity programming concepts.
References:
Structure of a Block in Blockchain – Naukri Learning
Proof-of-Work (PoW) in Blockchain – Naukri Learning
What Is a Block in the Blockchain? Block Structure | Gemini
How does a blockchain transaction work? | Ledger