What do you think of when you hear the word ‘Database’?
Most people envision a huge warehouse filled with massive servers controlled by a powerful company, because traditionally, only those types of entities that have enough money to build and maintain servers would be able to store data on a massive scale.
What if this doesn’t have to be the case? What if there was a way for an individual to contribute the storage and computing capacity of their personal device to a whole network of databases in exchange for compensation?
Welcome to the world of Decentralization.
Decentralization is a key principle of blockchain technology. Instead of storing data at one central location where it can be controlled by an individual person or company, data can instead be dispersed across a whole network where no one person can control it.
This means that with blockchain, no one has the power to stop you from owning or accessing your data because no entity can manipulate the database.
Think about how someone would interact with a traditional database. If they want to push information to a database or receive information from it, that person would create a transaction that would complete the task, and then that transaction would be logged in the database.
While this is simple and straightforward, it raises a concern: unless the user has direct access to the database, there is no way to prove that the transaction did or did not occur because no one but the database owner can access that list of transactions. This creates room for fraud, where an owner of the database (or a malicious actor such as a hacker) can go in and edit a transaction without anyone knowing.
Blockchain as a Tamper-Proof Network
Blockchain works in a very unique way compared to traditional databases. Instead of storing data on one machine, a blockchain database operates across a whole network. Each node (a contributing computer) creates its own copy of the database and compares it to the results of the other nodes within the network. The correct state of the network is then reached once all the nodes agree on one version of the database.
While traditional centralized databases only hold one copy of all the data on them (not including backed up copies stored on the cloud), blockchain creates a system where each node on the network receives a copy of the data. For example, if there are 100 nodes operating a network, then there are 100 copies of the data, with each node receiving a copy. All of the nodes then have to come to an agreement on what is the correct version of the database by seeing which version is supported by the most nodes, where if 95 nodes have a matching version of the data while the other 5 have a slightly different version, the version backed by the majority of nodes becomes the accepted state of the blockchain.
The point of this process is to create a tamper-proof system that doesn’t let a database operator get away with making unsolicited changes to the network. In centralized databases, if a transaction is altered by the owner of that database or any other malicious entity, there would be no way to prove that the change wasn’t there before. On a blockchain network that contains copies of the database, if one node changes the database or gets hacked, all of the other nodes still have the unadulterated copy of the data and can prove that the affected dataset was manipulated.
Imagine you ordered a shipment of automobile parts. The company you ordered the parts from has a traditional centralized database where it tracks all orders. You need these parts delivered on the 20th to fix a vehicle, and you pay extra to receive priority shipping. There is a delay in the shipment, and instead of telling the company, the shipper changes the expected delivery date from the 20th to the 25th without informing them. You get angry at the company because the shipment was supposed to come on the 20th, but they check their centralized database and it shows the 25th, making it seem as if you are in the wrong.
If that company used a decentralized database, the fraudulent change would be noticed right away. The shipper would edit the transaction, which would be reflected on one of the nodes. However, when compared to the other nodes, it becomes evident that the manipulated node no longer matches, and the change would be detected.
In the case of Bitcoin, these nodes are the miners. When a miner is mining Bitcoin, they are actually a node contributing to the network by validating transactions and making their own copy of the database. They then get rewarded for their effort by receiving Bitcoin, which incentivizes them to keep mining and therefore operating the network.
While the nodes get paid to operate the network, regular users pay fees to create transactions. These fees are generally referred to as gas. Gas is paid for by the native currency of the given network, so in the case of the Bitcoin network, transactions are paid for using Bitcoin. The amount of gas required depends on the amount of congestion on the network; the more people using the network at a given time, the more transactions a miner has to process, the higher the gas.
Let’s break down the process of adding a new transaction to the Bitcoin network:
- You decide to send your friend some Bitcoin. You enter their wallet address, add an amount, and sign off on the transaction.
- Your transaction gets broadcast to the Bitcoin network and is received by the nodes operating the network. Once received by a node, the validity of the transaction is confirmed to be legitimate, and your transaction gets added into a list of transactions that need to be confirmed. This list is called a mempool.
- The node then selects the transactions listed in the mempool to include in the next batch of transactions. Each batch is called a block and all the blocks are all connected to one another, hence the name blockchain (a chain of blocks).
- The node then goes on to solve a complex cryptographic puzzle to get a number known as the nonce. The nonce, when combined with the data from the block, produces a unique identifier called a hash. This hash is very important because it serves as a fingerprint for each transaction that occurs on the network.
- Once the nonce is found, the new block that contains your transaction, among others, is created. The new block is then broadcasted to all of the nodes in the network, who confirm that it is valid and add it to their own copy of the blockchain.
- Once the new block is officially added to the network, your transaction receives a confirmation and the transaction is fully settled, and your friend use the Bitcoin you sent them.
Source: STEX
Advantages of a Decentralized Internet
In a decentralized Internet model, everyone has equal access to the database and can prove the validity of any transaction that has occurred.
Just like with a traditional database, whenever a new transaction is sent to the blockchain, it is published onto the network (regardless what that transaction contains). The difference is that due to the decentralized properties of blockchain, neither you nor anyone else can go back and alter or delete that transaction because no one person owns and controls the database. In order to successfully alter or falsify a transaction on the blockchain, you’d need to have control of at least 51% of the nodes that operate that network. On large networks that contain thousands of nodes, this is something nearly impossible to do.
The blockchain system has two key aspects that differentiate it from traditional databases:
- All transactions are broadcasted publicly onto the blockchain network.
- Anyone can go into the blockchain database and view their transactions. This means that you don’t have to take anyone’s word that the transaction was successful, but rather you can literally see it for yourself. This would be like having direct access to Google’s servers where you can directly see your search went through as expected and nobody messed with it.
- The larger and more decentralized the network gets, the more secure it becomes.
- If there was only one node responsible for operating the database, that node can edit the transactions however they want and no one would know because there is only one copy of the database - just like in a traditional database. However if there are ten nodes and one of them decides to edit a transaction, the other nine will realize that the one node doesn’t match, and the issue will be called out. This makes blockchain much more fraud proof because a node can’t get away with falsifying transactions.
Once a transaction is complete and the block that it was listed on is published, it becomes immutable, meaning no one can go onto the blockchain and edit it. It will exist in that state, on the network, visible to everyone, forever.
In the case of the Bitcoin you buy, this means that there is concrete proof that cannot be disputed in any way that ties the amount of Bitcoin you bought directly to you. No one can go and say that the money you have does not belong to you because the blockchain network contains all the evidence you need, and that evidence is supported by the entire network that has confirmed the transaction to be legitimate. All of this data is navigated through the use of hashes that allow users to identify any transaction in a unique way.
The Mechanics of Blockchain Hashes
Think of a ledger book, where each page contains a set amount of items, and all the pages are in order because they are connected by the book binding. This is exactly how a blockchain database functions, with each block containing a certain number of transactions, and each block bound to one another in numerical order.
Each transaction in the block contains several key pieces of data including:
- Where the transaction is originating from as well as its destination
- The value of the transaction and its gas fee (cost to send it)
- The type of transaction
- The transaction hash
All transactions and blocks are identified through hashes, which are the unique fingerprints for each transaction that never repeat.
This image (to the right) contains a full list of actual transactions visible on-chain. Anyone can go and search for a transaction hash to identify any existing transaction that occurred using this system.
Hashes work very well as identifiers because they have a property that makes them completely tamper-proof, which is that the output of a hash is directly based on the input it receives. The hash that is generated for any transaction is entirely based on the data that transaction contains; if any of the data changes, the hash changes as well.
Source: Etherscan
To demonstrate how effective hashing is, let’s look at SHA-256, which is the encryption method that Bitcoin uses to create its hashes. If you take the string ‘pretend this is a Bitcoin transaction ’ and run it through a hash generator, it will return the following hash:
dafab953202ffc169d818e5cba59076848369712613357819fdb30f5b7ddac79
However, if you take that same exact string and add an exclamation point at the end and turn it into ‘pretend this is a Bitcoin transaction! ’, then the hash completely changes:
22d2db82e032157335c9d359d31ba11e11eff5d0019eed49d193abe08010c47f
If you remove the exclamation point, the hash returns to the original version.
Check out a hash simulator here to try this for yourself.
This type of data encryption makes your transactions tamper-proof. When a transaction is published onto the network and given a hash, that transaction can’t be altered, because then the hash would change and the data would no longer match.
This principle is also applied to the blocks themselves, which have their own hashes. Each block contains its own hash that is generated by all of the transactions on it, as well as the hash of the previous block. This effectively creates the block chain, where each block is linked to the block before it to create an ordered system. This method also makes the blocks tamper-proof because a bad actor can’t edit a block without changing the hash. If they go to a previously published block and attempt to change its contents, the hash of the block will change, and the following blocks will become invalid because the hash that the next block has doesn’t match the new hash created.
When two blocks are mined and then the first one is edited, its hash changes and the second block becomes invalid because the hash that it has for the first block no longer matches the actual hash of the previous block
Check out this website for an interactive demonstration of how this system works.
Creating a Blockchain Transaction
Because blockchain is a trustless database solution, it does not have any middlemen when it comes to creating or processing transactions. All transactions are meant to be directly peer-to-peer and without any middlemen. For simple networks such as Bitcoin, the transaction model is straightforward: a user enters the wallet address of another user and sends them Bitcoin directly. There are no intermediaries, solely two wallets exchanging a given amount of currency.
For a basic networks, this is the only way to execute transactions. However, more advanced networks such as Ethereum can execute far more complex transactions on top of peer-to-peer money transfers. This includes actions such as:
- Storing data on-chain
- Communication and messaging
- Borrowing and lending
…and much more. They can do this through special programs known as smart contracts.
Smart contracts are self-executing programs saved directly on the blockchain network that allow a user to create custom transactions. They have the terms of an agreement written directly into the code, which lets these contracts execute as soon as the terms are met and without any third party. These terms can range from a service to data storage to communication.
The opportunity for smart contracts is only limited by their complexity, as more compute-heavy contracts will cost more to execute.
Anyone can create and deploy their own smart contract onto a blockchain network. All a developer would have to do is write up a smart contract using a language such as Solidity, and they would be able to directly deploy it onto the network for a small deployment fee. It is then stored directly on the blockchain and can be viewed by anyone. Many popular blockchain networks also contain testnets, or mock networks that operate exactly the same way as the real network does, but without real money. Developers can utilize these testnets to test out their contracts to ensure they are working correctly before deployment onto the real network.
Contract #1 is a simple escrow contract, where all that it does is take in money from a payer, store it until the the listed conditions of the contract are met, and then releases the money to the payee.
Contract #2 is designed in a way where the payer deposits money into it, but then multiple parties get to vote on a proposal of who gets the money, and then whichever party wins will be the payee.
The second contract will require much more computing power to process than the first one because it has an additional layer of complexity built into it. Because of the increased computing power required to execute it, the contract will have a higher deployment cost onto the network.
Once a smart contract is deployed, users can interact with it either directly by referencing the hash that identifies the contract, or through a user interface such as a website. Most developers prefer the latter, where they are able to build out good looking and functional websites and applications that directly integrate the smart contract.
Smart contracts allow blockchain networks to operate like no other centralized network can because of the built in automation:
- With no middlemen to take a percentage of each transaction processed, using blockchain to settle payments becomes much cheaper than using other monetary transfer systems, making it an ideal system
- With no controlling authority owning smart contracts, all data is secured and encrypted in a way that only those with explicit permission given in the terms of the contract can access it
- With no workers required to process transactions, settlement time goes down from days to seconds and occurs 24/7
As smart contract development continues to progress and become cheaper, new use cases are arising every day. A huge use case that arose from this system is Decentralized Finance. Decentralized finance, or DeFi, is a completely open financial market that can be accessed by anyone, anywhere. Learn more about DeFi later on in the course.
Works Consulted for this page:
Brownworth, A. (n.d.). Blockchain Demo. Anders Brownworth. Retrieved from https://andersbrownworth.com/blockchain/blockchain
Brownworth, A. (n.d.). Hash Function - Blockchain Demo. Anders Brownworth. Retrieved from https://andersbrownworth.com/blockchain/hash