Blockchain 101 for dummies – Part 2
Have you ever wondered what is inside a blockchain looks like?
This part will present more visualisation on the mechanism of how blockchain works with Hash function, private/public key and wallet.
A blockchain is just like a series of spreadsheets linked together by Hash codes (See diagram below), inside each block is just a record of all the transactions of all the different owners. Eg from Emily's 10 tokens to Jackson on block 4 and Jackson's 2 tokens to Alexandra on block 5.
It is like a bank account with credit as deposit and debit as withdraw to create a new balance. It is like a spreadsheet of accounting ledger, that is why it is also called distributed ledger.
When each spreadsheet is filled with transactions (approx 2,000 transactions per MB for bitcoin, Solana has a block size of 170+ MB and it can fill it up with 100,000 transactions), these transactions are verified, a hash code - cryptographic code of 64 characters is generated, this hash code is linked to the next new block of transactions to form a blockchain.
This hash code is like a lock that fixed the content of the ledger, it is not allow to change any more. If a transaction of a block is changed, the hash code would change immediately and the blockchain is broken and it cannot be verified and validated by other computers in the network, and the said transaction is viewed as error/fraudulent and ignored.
You can see the fundamental mechanism of how all blockchains function lies on the Hash Function as the center. A hash function is like mathematical operation on a excel spreadsheet, you can think of it as a Sum function on your excel which does the summation of all the numbers in the cells above, anyone change the cells, the Sum function will spill out a different number. Similarly a Hash function would take any content in a spreadsheet as input to calculate a 64 characters output called the Hash code. Any change on the content the hash code is completely different. That is how a blockchain function, once the transactions are verified it is locked by the hash code and linked to the new block and prevent any one to change it, making it a trustworthy information block for the whole network.
This is exactly what a block looks like
In a block, all owners are identified by the wallet addresses, each transaction has a signature attached, a block basically records a wallet address’s balance and its tokens from buy/sell/transfer instruction with signature to prove the authenticity (see below)
Similar to a bank account operation when you deposit/withdraw money you need a signature. Instead of using hand written signature, blockchain use a private key to sign a transaction, so that it can be automated with super security. Under each transaction a signature must be attached for validator to verify two things:
That it is the true signer and transaction not altered during transmission.
When a block (or ledger) is filled with these transactions and verified, then a new hash code is generated based on the content of the ledger so this hash code is always unique and will never exist before, and it will be linked to the new block as a previous hash code.
This is the magic of blockchain lies on the Hash code generator (called the Hash function). It is like a magic box with mathematical calculations when the input is the same it always output the same 64 digits of alphanumeric code (hash code), even a millionth of a part change it will output a totally different code and trigger a system alert.
The input can be a list of transactions with signatures or another hash code it always output a hash code. That is the core concept of blockchain technology that facilitates a distributed ledger with accurate and secured information with collaboration of the whole network.
Solana blockchain network has 3000 computers to participate in the validation of new transactions on the blockchain, every day these computers collaborate together to verify new transactions, generate a new hash code to close the ledger/block and then link it to the new block. That’s why they are called validators. When validator generated a new block that computer node is rewarded a gas fee, in the bitcoin blockchain the reward is 6.25 bitcoins! That’s why people are crazy about mining Bitcoin.
Proof of work Vs Proof of Stake
When people do mining of bitcoin they are basically guessing a new hash code that never
exist before and met the protocol’s criteria so they can establish a new block and claim 6.25 bitcoins as reward.
The guessing and verification of transactions work together they do is called Proof of work, it is a long guessing process of wasting energy of running hundreds of thousands if not millions of computers at once. The guessing process involve generating a random hash code that match bitcoin protocol’s hash code requirements (eg current Bitcoin hash code must start with 18 zeros in its 64 characters code) and at the same time they need to verify all the new Bitcoin transactions added.
A hash function output changes drastically with a tiny change on the input, so it is a tedious guessing game that only a computer can do it. With all these computers guessing frantically around the world, someone would get it right eventually with time. That time it takes for a new bitcoin block to generate is every 10 minutes.
Ethereum blockchain adopted a new innovation that validate new transactions based on Proof of Stake. This consensus mechanism required only 51% of the validators to vote and confirm the verification of new transactions, then generate a new block, these validators’ computer node each has a stake of Ethereum coins locked up in the protocol and if any one cheat in the transactions, then that stake is burned, that is sending their stake coins to an unknown wallet address. This new block generation time is reduced to 15 seconds because they don’t need to do any guessing game, and just generate a hash code based on the filled block to close it off. This save a lot of energy with running about 8600 computer nodes, that is much less than the bitcoin network.
Solana’s Proof of History
The Solana blockchain further reduced the new block generation time to only 0.4 second with an innovation that timestamp each transaction, it is basically stamping the transactions with serial numbers that increase in order of 1 increment with a clock counter as 0001, 0002, 0003….00026000. Because the 26,000 transactions are all timestamp, these can be validated in parallel by many validators working at the same time that result a validation speed of 65,000 transactions per second. They can validate as fast as the blocks can be filled by lining up the 3000 validators in advance with selection based on their stake size as proof of stake.
How does computer nodes validate the new transactions?
Each transaction is signed by a wallet address owner with a private key to generate a signature code, this is basically encrypted the transaction instruction with a private key.
See diagram below, if a person is trying to change the transaction from $2 to $25 the signature codes will turn red and the hash code for that block will also turn red and this blockchain link is broken, and alert other computer node that this transaction is cheating or has error which to be ignored in the verification.
When a user send coins to someone this is the process of how the transaction is verified by validator computer node on a blockchain:
Your wallet app do the following steps:
coverts Transaction data >>> Hash function >>> Hash code
Hash code + Private key >>> Hash function >>> Signature code
These codes and the transaction data are send over the internet to the blockchain network sytem.
Validator do the following to verify your transaction:
Convert your Transaction data >>> Hash function >>> Hash code
Use your public key to verify your Signature:
Signature code + your public key >>> Hash function >>> Hash code
If both hash codes is a match then that means the transaction data is not altered during transmission and the signature was signed by a private key that match that public key.
The validator would have verified this transaction and can be added in the block.
Private and Public key pair
When you open a wallet account via a provider like Phantom, it generates a private key with a 12 word secret phrase like Bravo Tango Alpha Beta …… by putting it through a Hash function as follows:
12 word secret phrase >>> Hash function >>> Private key code
Then Private key code >>> Hash function >>> Public key code
Then Public key >>> Hash function >>> Wallet address code
When you created an account on Phantom you basically put your wallet address on the Solana blockchain with zero balance, and the network has your public key that match your wallet address. Each wallet address has a unique pair of private key and public key. So, don’t share your private key with anyone because they can sign your transactions and drain your wallet.
And remember your 12 word secret phrase, it is needed to recover your wallet when you change device.
Hope you have learned all. If you have any questions feel free to drop a comment below.
This link is Part 1 which describes the basic overview of Blockchain