Hey everyone, welcome back to the course.
So now we have discussed about the overview of the blockchain and we have also gone through blockchain
fundamentals.
Now let's see how the core of blockchain performs the core functions with the help of an example.
We will go through the working of blockchain through an example.
Let's imagine that there are ten people inside a room and they decide to create their currency for any
exchange between them.
Apart from transacting, they also need to have a transparency for all the transactions taking place.
They need to be aware about the flow of funds between them so that disputes regarding the same can be
resolved in the future.
This is why they decide to appoint one person to keep the list of all the transactions which are taking
place between the members of the group.
Let's call this person Dave.
You can see in the image that Dave kept a record of all transactions happening in the room in a notebook.
All the transactions from the beginning were noted down.
For example, Alice gave three coins to Carol.
Carol gave five coins to Chuck.
Chuck gave three coins to Eve, and finally Eve transferred one coin to Bob were recorded down in a
notebook.
This notebook acts as a source of transparency and verification for the group.
Now out of the group of ten people, there is one person, let's call him Chuck, who decided to steal
money from the group.
To accomplish that, he changed the entries present in the Notebook.
One night he got hold of the notebook and modified his entry to somebody else.
For example, he turned the entry number three in the notebook from Chuck, gave three coins to Eve
to Carol, gave three coins to Eve, thus making sure his account is not deducted for the transaction.
Dave notices that someone has messed with the notebook and he decided to protect the entries.
He created a program called a Hash function.
How does a hash function work?
A hash function converts a variable length of data to an alphanumeric string of a fixed length.
A hash function always generates the same size of data for any input size.
For example, Sha 256 is a known hash function which is being used in Bitcoin and Ethereum, be it one
kilobyte of input data or one gigabyte of input data.
Sha256 hash function will always generate 256 bits of output hash.
We can see the example of hash function in action as shown in the table.
Examples like attack can't attack and can attack have a fixed length hash through the Sha256 hash function.
Even a single bit of change in data will lead to a different hash result.
In other words, we can say that the hash acts like a digital signature for the data.
If the data change, the hash will also change.
Dave added the records of hash inside the notebook in such a way that after each transaction he has
a hash of the transaction.
The new notebook entries look like as shown in the image.
You can see now when Alice gave ten coins to Carol, a hash of the same is recorded below the transaction.
The same happens for the rest of the transactions or any other future transactions.
If Chuck tries to again change the entries inside the notebook, then the hash for those entries will
be different and Dave would be able to verify the modified entries.
Although the hash function has been put into effect, Chuck somehow learned about the hash function
and decided to manipulate the entries again.
He took the notebook one night and changed the transactions as well as the hash of the transactions.
For example, you can see in the image he changed the transaction.
Carol gave five coins to Chuck, two, Carol gave eight coins to Chuck so that his account has more
coins.
He also recalculated the hash of the other transactions and modified those in the notebook as well.
By changing the hash.
He made sure that if somebody tries to verify the transactions by using the hash function, then the
transactions get validated.
Dave noticed again that somebody has fiddled with the notebook.
Frustrated with the attacker, he decided to complicate the records in such a way that each hash is
generated by combining it with the previous hash.
So each transaction record is added with the last hash transaction and pass through the hash function.
The resultant hash is the current transaction hash and it will be used to generate the hash for the
next transaction in the notebook.
Each entry in the journal depends upon the previous entry.
If the attacker tries to change any record in the notebook, then he needs to replace all the entries
inside the notebook.
Now the notebook looked like as shown in the image, so you can see that we have the input.
Alice gave ten coins to Carol and corresponding to that there is a hash recorded for the same.
The second input Carol gave five coins to Chuck cumulated with the previous hash and passed through
the hash function.
The resultant hash is recorded against Carol's transaction.
Similarly, the next input Carol gave three coins to Eve is again linked to the previous hash and then
passed through the hash function to generate the current transaction hash.
This is repeated for all the records in the notebook, making sure all the records are linked to each
other, thus forming a chain of records.
But Chuck is a persistent attacker.
Chuck wanted more money and he spends the whole night counting all the hashes.
Finally, he came to know about the linked hashes and somehow managed to change the hash and the entries.
He replaced all the entries as per his advantage and also replaced all the hashes with the corresponding
cheat hashes to gain money from the group.
Dave was also getting frustrated with the attacker, but he didn't want to give up.
Dave decided to add some more complications with the entries in the notebook.
He decided to add a random number after each transaction record, which will be called as the Nouns,
and it should be chosen in such a way that the hash of each transaction record ends in two zeros.
For example, the notebook entries looked as shown in the image.
The first entry Alice gave ten coins to Carol is suffixed with the nouns whose value is 247.
This 247 helps to generate a resultant hash which is ending with two zeros.
As you can see in the image.
Similarly, the second entry Carol gave five coins to Chuck has the nonce value 511 added to it, which
results in a hash value ending with two zeros.
Dave added nouns for each transaction in the notebook, thus creating more complexity for the records.
They've created all the transactions and trees with the nouns.
Now, to force the transaction, Chuck needs to spend hours to find out the value of nouns, which will
lead to the corresponding hash.
More importantly, it would be tough for even the computers to guess the nouns quickly.
After some time, Dave realizes that there are too many transactions in the notebook and it's tough
for him to manage all the records.
So he decided to get all the transactions verified by Karel and then distribute them globally so that
every computer which is working on this network has the copy of all the transaction records.
This is the core principle of blockchain, too.
Transactions are stored inside the blocks which are linked to the next block through a hash value.
Hashes are generated in a way, as we discussed in the example, a value of nouns is added with the
block to create its hash.
The number of leading zeros, which are to be present in the hash, is calculated through a formula
which makes sure that the block generation time does not deviate from the specified interval.
For example, in the case of Bitcoin, leading zeros and nouns are calculated in such a way that a period
of ten minutes is maintained for each block.
In our example, every time a new transaction occurs, it has to be validated by a node and then only
it will be confirmed over the blockchain.
Once every node receives the transaction, it performs the consensus on the transaction and checks whether
the transaction is valid or fraud.
In the real world scenario, this consensus occurs on the block, which has all the transactions coming
in for the certain period.
For example, a Bitcoin block has all the transactions for the period of ten minutes and then a new
block opens up to receive other transactions.
Now our attacker is facing an uphill battle because he not only needs to change the entries within the
notebook or computer held by Dave, but to cheat the system he needs to replace all the entries present
at different nodes which are located globally.
This spreadsheet created by Dave is an example of a block present in the blockchain and the whole chain
of blocks which are interconnected to each other is called blockchain.
Once a block reaches a certain number of approvals from the nodes, then it is added to the chain and
a new block is opened up for the transactions.
There is an entry of nouns with the block, which is a random number chosen in such a way that it leads
to some leading zeros for the hash of the block.
Different formulas for different platforms define the number of leading zeros.
The primary purpose of the miners is to guess this nouns and validate all the transactions.
Miners run algorithms on their computer or nodes to calculate the nouns and take the hash of the block.
Once the hash of the block is in the range of the accepted hash, miners can confirm the block and put
it over the blockchain.
Moreover, the spreadsheet in our example or the blockchain is available globally at different locations.
If somebody tries to change any data in the blockchain, then everyone who is part of the network can
verify that this data was not present originally.
Participants can catch hold of the culprit and reject the change.
That's why it's almost impossible to hack the blockchain.
So that was about how blockchain works with the help of an example.
This is just a generalized overview for the working of blockchain.
Now we have seen that blockchain provides some key characteristics and fundamentals which can be appointed
to different kinds of problem statements.
But is blockchain a solution for everything?
In the next session we are going to talk about is blockchain a silver bullet?
And also we are going to see the different kinds of factors which will affect your blockchain solution
appointment.
If you have any queries, feel free to contact us at info at the rate v2 blocks.com.