Well, here we are again with another edition of ‘The Blockchain with OnChain’. Ironically, in this edition we are going to be talking about the blockchain (I swear this is all a coincidence. Wink face ;) ).
Once we have published all the articles in this series, we shall be holding a quiz in discord to test your knowledge…
Ahhhh just kidding!
No seriously, WE ARE…
Ok ok, really we’re not. However, there is some great content here, so if you’re looking to brush up on your knowledge or maybe we have peaked your interest, we thank you for taking the time out to read these. So without further adieu let's begin.
Over the last decade and a half, blockchains have gained prominence in the tech world. They have been used to build different applications to accomplish various tasks. The first known use case for a blockchain was the Bitcoin project. But what exactly is a blockchain, and what makes it so important?
This article will cover the building blocks of blockchains and their key attributes.
Blockchains, From the Ground Up
A blockchain is a distributed ledger that contains data that is organized in blocks and linked together in a chain. To better understand what that means and how it works, we’ll discuss the following terms in detail:
Block, Hashing, and Mining/Validation.
Block
In a blockchain, a block is a collection of some data. Using the Bitcoin and Ethereum blockchains as examples, a Bitcoin block will contain a list of Bitcoin transactions, while an Ethereum block will contain a list of Ethereum transactions. Every transaction that happens is added to the block. On the Bitcoin blockchain, the amount of data a block stores is called the “Block Size.” Many blockchains have a block size limit. Bitcoin’s block size limit is 1MB, which gives room to store between 1500 to 2000 transactions per block. Although all blockchains follow the same fundamental principles, they agree on key details differently. For instance, Ethereum and some other blockchains do not have a fixed block size limit like Bitcoin but are rather limited by gas. On Ethereum, gas is the term for the fees required to conduct a transaction. The block size limit (or gas limit) for Ethereum is 30 million gas, meaning that the total gas fees of all the transactions on an Ethereum block must not exceed 30 million. Starknet, the blockchain StarkDeFi builds on, leverages Ethereum and has the same gas limit as Ethereum.
Apart from transaction data, all blocks on a blockchain also contain the previous block’s hash. But what is a hash?
Hashing
Imagine a black box that gives you some output for whatever input you give it without following an identifiable pattern. In blockchains, this black box is a complicated function called a “hashing function.” Hashing functions take in the block data and some metadata and return a “cryptographic hash.”
This cryptographic hash helps create the chain of blocks that form blockchains. It is done by including the hash obtained from a block to the next block of transactions, forming a link between every adjacent block.
One may ask: “But what about the first block in the blockchain? What hash is included since there’s no previous block?” The first block in a blockchain is called the “Genesis Block.” Different blockchains choose what hash to assign to a Genesis Block. Some use 0 or the hash of something important to the development team, or no hash at all. It all depends on what the team wants to do.
There are several secure hashing functions already in use in the industry. Most blockchains use already existing ones, and some create their own. Bitcoin, for instance, uses the Secure Hash Algorithm 256-bit (SHA-256).
For a hashing function to be considered fit for purpose, it must:
a) be deterministic i.e., an input should ALWAYS produce the same output.
b) compute hashes in a reasonable time.
c) be difficult to compute an inverse i.e., the input should not be derived from the output easily without doing computationally intensive calculations.
d) be resistant to “hash collisions” i.e., it must always have a unique hash for every input. No two inputs should result in the same hash.
e) not have identifiable patterns. A small change in the input should result in a completely different hash.
Mining/Validation
Remember that we said the blockchain was a distributed ledger. That means that it comprises nodes (computers) in a network that seek to achieve a common goal of maintaining the blockchain and keeping all data valid by following a protocol (set of rules). Like block size limits, blockchains achieve this through different means. The two popular methods are Proof-of-Work and Proof-of-Stake.
For Proof-of-Work blockchains like Bitcoin, once a block reaches its limit, the nodes(called miners in this case) start calculating a value that can be combined with the block data and the previous block’s hash to produce the current block’s hash set by the protocol. This value can only be found by guessing in a process called “mining” since good hashing functions are technically irreversible. All the nodes in the network race to be the first to find the value. The protocol increases the difficulty by increasing the number of guesses required based on the number of miners on the network. This is why you could mine Bitcoins with a laptop in the early days when it wasn’t popular but you need large mining rigs now.
The moment a node finds a value that meets the set criteria, it broadcasts the solution to all the other nodes in the network. If the hash and all the transactions in the block are valid, then the other nodes accept this as the next block and add it to theirs. The node that found the value is also rewarded with the transaction fees of that block and the newly minted bitcoin associated with that block.
In Proof-of-Stake blockchains, however, miners are swapped for validators. Validators do the same work as miners but are nominated by the network to verify transactions in a block, as against a “free for all” competitive approach, in order to make the process more equitable.
Key Blockchain Attributes
Up until this point, we have discussed the key basics of blockchains. One may ask: “Why should you go through all this hassle when we could just keep a good old database of transactions.” Well, blockchains have some features that make them unique and important. These include decentralization, immutability, security, and transparency.
Decentralization
Decentralization is the core tenet of blockchain technology. Unlike traditional systems that keep data in the hands of a single entity, blockchain data is distributed across the network of nodes. Each node keeps and updates a copy of this data to ensure no central point of failure since no single entity can manipulate or control the data.
Immutability
When we say data is Immutable, it cannot be edited or changed once it’s added to a block. Blockchain immutability ensures that the data stored in it is highly secure and trustworthy, making it ideal for applications such as financial transactions and voting systems.
Security
Systems leveraging blockchains offer high security. Cryptographic techniques like hashing ensure that the data stored on blockchains is highly resistant to security breaches and makes the blockchain ideal for security-centered applications as well.
Transparency
Finally, blockchains offer transparency and accountability to all stakeholders of a system. All transactions on a blockchain are visible to any person who is interested, which makes them very easy to audit. This makes blockchains perfect for applications where transparency and accountability are important, such as government records and identity management systems.
Blockchain Forking
As discussed in the previous sections, blockchains are distributed systems with many managing nodes. Therefore, what happens when errors require fixing or there are disputes within the project community is very important. That is where forking is useful.
Blockchain forking refers to the act of creating a new version of a blockchain. There are two types of forking: Soft Forks and Hard Forks.
Soft Forks
Soft Forks occur when the rules of the blockchain are changed in a way that is backward-compatible with the existing blockchain. This means that nodes that do not upgrade to the new version of the software can still participate in the network but may not be able to take advantage of the new features introduced in the fork. Soft forking is done more frequently in the blockchain community without many divided opinions.
Hard Forks
Hard Forks are more popular events in the blockchain community and are anticipated more ceremoniously. Hard Forks occur when the blockchain is split into two chains that are no longer compatible. This happens when the rules of the blockchain are changed in such a way that nodes that do not upgrade to the new version are no longer able to participate in the network. This can result in a permanent divergence of the blockchain, with different communities and users supporting different versions. This typically happens in cases where the blockchain community has strongly divergent views on the blockchain’s future developments. For Example, Bitcoin Cash and Bitcoin are the results of a hard fork where the nodes on the side of Bitcoin Cash wanted the community to increase the block size limit. Ethereum and Ethereum Classic are other examples. They resulted from a hard fork where the nodes on the side of Ethereum wanted to undo an error that resulted in an attacker exploiting the network and seizing some cryptocurrencies worth millions of dollars.
The Blockchain Trilemma
Across the blockchain industry, there is a widely held belief that blockchains face three main challenges: Decentralization, Security, and Scalability (number of transactions per second). Most blockchains are only able to achieve two out of three. Blockchain communities typically choose the two to focus on which often affects the third negatively. Any blockchain that can be great at all three would have built the ultimate blockchain. This problem is called the “Blockchain Trilemma”.
For instance, Ethereum is very decentralized and secure but not very scalable. Starknet, StarkDeFi’s blockchain, is on a mission to improve this scalability problem by offering a solution known as “ZK-Rollup,” where they improve the scalability significantly on Starknet and bundle a lot of transactions onto Ethereum as a single transaction. In the blockchain industry, Ethereum is a Layer 1(L1) blockchain, and Starknet will be considered a Layer 2(L2) blockchain.
Conclusion
Blockchain technology has emerged as a powerful tool for secure and transparent transactions. Its decentralized nature has the potential to revolutionize the way we think about data, trust, and transactions. The blockchain applications of cryptography have enabled them to provide a level of security and transparency previously impossible with traditional systems. However, blockchain technology is still in its early stages, and many challenges must be addressed to reach global adoption. StarkDeFi is contributing towards this goal. As more businesses and industries explore the possibilities of blockchains, we can expect to see exciting new developments and innovations in the years to come.
Follow StarkDeFi here and on Twitter, LinkedIn, and GitHub for more awesome posts and other announcements. Also, join our Telegram channel and Discord server for the best DeFi experience.
Thank you…