Chapter 1: Blockchain and Bitcoin
Episode 3(part 1): In this post, we are going to read about how blockchain technology works and how Bitcoin uses it to process its network.
Note: I wrote this article in summary note style
Blockchain Technology: Part 1
Ledger
A ledger in a blockchain network is a record-keeping system for decentralized information storage.
The information can be anything that is important to the network for example in Bitcoin's case is transactions.
This public ledger secures the identities of users mostly anonymously, maintains their balances of crypto assets, and records all the transactions among network participants.
In the crypto ecosystem, the blockchain is essentially the digital ledger and public record of transactions that is replicated and distributed across the participating network of computers.
An example:
If you make a transfer through a bank, the details of the transaction will be entered into the bank’s records. The bank’s accounting system ensures the record of balances on both sides of the transfer. The bank’s records, however, are accessible to bank officials as well as authorities like the government or tax officials. By contrast, on a cryptocurrency ledger, the blockchain — which contains details of the transaction — cannot be accessed by a central authority. The information on the transaction is held not with one institution such as a bank but with a network of computers working in a synchronized manner
Note: Transaction data of an account contains
1. Input
2. Output
3. Volume
Distributed ledger
A distributed ledger is a database that is consensually shared and synchronized across multiple sites, institutions, or geographies, accessible by multiple people.
It allows transactions to have public “witnesses.”
The participant at each node of the network can access the recordings shared across that network and can own an identical copy of it.
Any changes or additions made to the ledger are reflected and copied to all participants in a matter of seconds or minutes.
Benefits:
A centralized ledger is more prone to cyber-attacks and fraud, as it has a single point of failure.
Distributed ledgers reduce operational inefficiencies, speed up the amount of time a transaction takes to complete, and are automated, and therefore function 24/7, all of which reduce overall costs for the entities that use them.
Distributed ledgers provide for an easy flow of information, which makes an audit trail easy to follow for accountants when they conduct reviews of financial statements. This helps remove the possibility of fraud occurring on the financial books of a company. (The reduction in the use of paper is also a benefit to the environment)
The basis of distributed ledgers is the same technology that is used by blockchain, which is the technology that is used by Bitcoin. (Blockchain is a type of distributed ledger used by bitcoin)
The bitcoin network
As a new user, you can get started with Bitcoin without understanding the technical details. Once you’ve installed a Bitcoin wallet(more on future posts) on your computer or mobile phone, it will generate your first Bitcoin address and you can create more whenever you need one. You can disclose your addresses to your friends so that they can pay you or vice versa. (This is pretty similar to how email works)
The blockchain
The blockchain is a shared public ledger on which the entire Bitcoin network relies. All confirmed transactions are included in the blockchain. It allows Bitcoin wallets to calculate their spendable balance so that new transactions can be verified thereby ensuring they’re actually owned by the spender. The integrity and the chronological order of the blockchain are enforced with cryptography.
Transaction
A transaction is a transfer of value between Bitcoin wallets that gets included in the blockchain. Bitcoin wallets keep a secret piece of data called a private key(More on private key subtopic) or seed, which is used to sign transactions, providing mathematical proof that they have come from the owner of the wallet. The signature also prevents the transaction from being altered by anybody once it has been issued. All transactions are broadcast to the network and usually begin to be confirmed within 10–20 minutes, through a process called mining(More on mining subtopic).
Bitcoin network node types:
In bitcoin networks, there are different types of computers that are connected together (each is called a node) and each type of node plays a specific role in the network.
- A node is a computer connected to other computers which follows rules and share information
- A ‘full node’ is a computer in Bitcoin’s peer-to-peer network which hosts and synchronizes a copy of the entire Bitcoin blockchain
- Nodes are essential for keeping a cryptocurrency network running
Mining nodes
Commonly referred to as minders, these nodes solve complex cryptographic puzzles in a process referred to as “mining”. Each miner aims to be the first node to create a new block(More on block subtopic) in the blockchain and to prove that it is the one that has performed the required work (Proof of Work). Once the entire network verifies a transaction, a new block is added to the existing blockchain and the miner receives a reward.
Note:
In the Bitcoin whitepaper, Satoshi used the word “node” as a synonym for “miner” but over the years these two definitions branched out somewhat. While technically “nodes”, “miners” use specialized ASIC hardware to add blocks to the Bitcoin blockchain and receive rewards for doing so. (The letters ASIC stand for “application-specific integrated circuits” which have been designed for a particular use, such as Bitcoin mining.)
What is defined as a ‘full node’?
According to Bitcoin Core documentation, “a full node is a program that fully validates transactions and blocks. Almost all full nodes also support the network by accepting transactions and blocks from other full nodes, validating those transactions and blocks, and then relaying them to further full nodes.”
Type of full nodes
- pruned full node → Download the block from the beginning to the certain limit and then deletes the oldest block.
- Archival full node
What is a ‘light node’?
There are also “light nodes” or “lightweight nodes” that depend on full nodes for functioning. They require significantly less download and storage capacities than full nodes since they only download block headers(More on block subtopic) from the Bitcoin blockchain and thus do not store the entire blockchain. Their only task is to verify transactions in the blockchain using simplified payment verification (SPV).
How full nodes can make money?
By downloading all transactions, a full node will always have the latest and greatest information relating to information on bitcoin’s blockchain.
Simply they sell data like:
Glassnode — On-chain market intelligence
P2P networks VS Server-based networks
P2P Network is an infrastructure or technology in which two or more computers are connected in order to share resources.
An independent network system that does not require a system administrator for managing the network. This type of network is based on Peer-to-Peer architecture.
In comparison to P2P networks, server-based networks run on a central machine that holds and updates the network data, and devices within a server-based network can communicate to each other through the server process.
Distributed VS Decentralized
Decentralized
Decentralized means that a decision is made across various nodes. Each node decides its behavior, which ultimately affects the system’s behavior. This ensures that no single node has complete system information.
A decentralized system has access to a massive amount of computing power due to various machines on the network. The computing power of each node is combined to operate the network.
The best example of a decentralized system is Bitcoin and Ethereum. Bitcoin has a decentralized network, where no government or entity has control over it. Ethereum(More on future posts) offers a decentralized blockchain where anyone can publish dapps(More on future posts) that connect users and providers directly.
Note: Centralized networks can be distributed too(for example they can have multiple servers throughout the world)
Advantages
- The decisions made are decentralized, i.e., made across various nodes.
- Provides more control to users.
- No single entity has control over the entire network.
- It improves the speed and flexibility of the system.
- Increased computation power.
Disadvantages
There aren’t many disadvantages to a decentralized system. The main contention is the level of resources. Due to the demanding nature, maintenance is something that is regularly required to avoid any issues.
In blockchain:
Cryptocurrencies make use of decentralized and distributed systems to operate. As we already know, decentralized systems are a subset of distributed systems. So if a blockchain is distributed, it can be decentralized.
In other means, we want decentralized distributed systems.
Gossip protocol
It is the protocol that Bitcoin uses to spread the data through its network. Let’s have an example to better understand it.
Step 1: Let’s say, N1 (node) receives new information. N1 randomly choose a peer (say, node N2) and share that information.
Step 2: N1 and N2 then pick a peer each (say, node N3 and N4) randomly and share the same information. The process continues in this fashion unless the information is passed on to all the connected nodes.
Generally, nodes store the time of information exchange. In the example above, in the first exchange between N1 and N2, N2 would store the details of N1, the information, and the time at which N2 got to know about that information.
Rules can be built on these nodes for determining the truthfulness of the information. Let’s say if a network following gossip protocol holds a rule that when 2/3 of the nodes return the same information, then that information will be taken as the truth.
In this process, all the nodes are treated with the same equality. It makes no difference if a node is more powerful than its peers. The only thing that makes a difference here is network bandwidth.
In the bitcoin blockchain, each node spread the information to 6 other random nodes.
6 –> 36 –> 216 –> 7776 —> …
You can play with gossip protocol simulation here
Consensus method:
Each decision and change will take place by the consensus of more than 51 percent of the network users. So decisions and changes are powered by the community and it is needed to keep all the nodes honest and trustworthy.
There are different kinds of consensus mechanism algorithms, each of which works on different principles.
- Proof of Work(PoW)
- Proof of Stake(PoS)
- Proof of Capacity(PoC)
- Proof of Activity(PoA)
- Proof of Burn(PoB)
- Proof of Elapsed Time(PoET)
- Proof of Participation(PoP)
You can check the link below for more:
Cryptography
Cryptography is the study of secure communications techniques that allow only the sender and intended recipient of a message to view its contents. The term is derived from the Greek word kryptos, which means hidden. It is closely associated with encryption, which is the act of scrambling ordinary text into what’s known as ciphertext and then back again upon arrival. I
Hash algorithm
A hashing algorithm is a one-way mathematical function that garbles data and makes it unreadable, so the text can’t be unscrambled and decoded by anyone else. And that’s the point. Hashing protects data at rest, so even if someone gains access to your server, the items stored there remain unreadable.
Hashing can also help you prove that data isn’t adjusted or altered after the author is finished with it. And some people use hashing to help them make sense of reams of data. (With the smallest changes to the input the hash function output will be completely changed)
There are different hash functions and the one which bitcoin blockchain uses is: SHA256
An example:
Input = 1234 — > Output = 03AC674216F3E15C761EE1A5E255F067953623C8B388B4459E13F978D7C846F4
Input = 1 234 -> Output = F50B28FF6BB08E493DB02EF3037854FE4CDA82AFB1351357A174310634116A99
You can see that even with adding a space between the digit 1 and 2 the hash output will be completely different.
Note that the output of a hash function is a number, it is a hexadecimal number. And normally you can hash any digital document with hash functions including movies, songs, pieces of text and….
You can play with SHA256 function here
Blocks and transaction(the use of hash algorithm)
Block
A block is a container that contains a load of network data.
Each transaction report will be hashed before being saved in the block and each block contains data from different sources(which each data set is hashed) and then when the block is filled completely the block itself going to have a hash value which this hash is going to be a data set for the next block. And in this way, these blocks create the blockchain.
The action of adding previous blocks hash makes the chain protected against any small changes in the existing history of the network because even a minor change can lead to a completely different string and it is easily recognizable. And if a block was labeled as distorted its following blocks are all invalid.
When you request a bitcoin transaction, it isn’t added to the blockchain straight away. Instead, it is held in a transaction pool (or memory pool).
If you are a miner, your job is to gather transactions from the transaction pool into a “candidate block”, and to try and add this candidate block to the blockchain.
Miner also gives each candidate block a block header, which is basically a bunch of metadata about the block.
Version → Describes the structure of the data inside the block. This is used so that computers can read the contents of each block correctly.
Last block (hash of the previous block)->An identification number for the previous block. We are trying to get one of these for the current candidate block
Merkle root(More on its subtopic)→ All of the transactions inside the block hashed together to form a single line of text. All of the fields are unique, but it would be fair to think of this as the most significant part of the block header.
Time -> time stamp
Target → A value that miners work with to try and add candidate block to the blockchain. It is set by the bitcoin network(More on part 2).
Merkle root
A Merkle root is created by hashing together pairs of TXIDs(Transaction IDs), which gives you a short yet unique fingerprint for all the transactions in a block.
This Merkle root is then used as a field in a block header, which means that every block header will have a short representation of every transaction inside the block.
Chapter 1 episodes
Previous episode