welcome back to my lectures on blockchain technology
In this video i'm going to talk about cryptography hash function
one of the key technology used to secure the blockchain network
okay let's start
before explain more about cryptograph
cryptography hash function let's see
why we need cryptography hash function?
okay let's look at this figure you see..
this show a blockchain network
we have a lot of nodes in here
and each node store the blockchain ledger
let's say each block in the blockchain ledger
will have maximum up to one megabytes data size
And there is one block will be created every 10 minutes in average
let's say the blockchain system already operate for 10 years
It means that there are 262,800 blocks have been created
or the total size of the blockchain ledger would be 256 GB
This is a huge ledger, and...
all the nodes here, they must store this huge amount of huge ledger
256 gigabyte data
so how it can detect.. whether is there any modification?
any other unexpected change of the data in blockchain or not yet?
so that's a big problem
how to detect the unexpected change in blockchain ledger quickly?
of course it cannot compare one by one the data because the data is very huge
a lot of data... cannot compare such things like that
so is there any method to detect the
modification quickly?
That is where we should use
cryptography hash functions!
What it is? (hash functions)
In this figure, you see this is a hash function, crypto hash function
It receives an input data
and it will calculate the hash of the data
and the calculation is just one way calculation
from the hash of data cannot cannot get back the original data
currently there are several algorithms for the hash functions
For example: md5, sha 1, sha-2,  sha-3, and so on..
For example in SHA-2 family, there are many algorithms such as SHA-256,
SHA-512, and so on
and these functions are commonly used nowaday
For example, if we input an input message "hello words"
if we calculate the hash value
each hash function will generate the different hash value
md5 generates the hash value like this
sha-1 is like this... sha-256 is like this
And this is the hash value of the sha-512
okay
what are the patterns of the hash functions?
so we have independent hashing, repeated,
combined, sequential, or hierarchy hashing
for example this is the independent hash
we have the hello world message
we can calculate the hash of each word independently
or this is the repeated hash
we can firstly compute the hash of the hello world
and then compute the hash of the hash
of the "hello world"
repeat the hash
or combined.. we combine the "hello" and
"world"
independent words into one word
and then calculate the hash of the combined word
or the sequential hash
we can compute the hash of the "hello"
and then combine this hash with the "world"
and then calculate the hash of the final one
or hierarchy.. we calculate the hash of the "hello" and "world" independently
and then, we combine these two hashes
and calculate the hash for this combined hashes
okay! properties of the hash function
properties of the hash function is very
important,
because..
it shows that whether the hash function is enough secure
for using or not
these are the important properties for a hash function
firstly, it transforms any kind of data into a fixed length output
for example,  if we say about sha-256
regardless of the size of the input data
it always generates 256 bit hashed output,
always 256 bit
okay and the next property is calculation quickly
It means that..
the hash function should be able to
calculate the hash of the data very quickly
therefore when construct a hash function
we should use the simple operation like..
logic operators such as and, or, xor, not
sometimes we use the adder
but the complicated one like multiplier or divider should not be used
okay?
the next property is deterministic
It means that for a data there is only one hash value will be generated
there's no case that 2 hashes for one input data
okay the next is very important.. pseudorandom
It means that the output hash value is somehow random
for two input data that are similarly for example
similarly
they even different only one or two bits
but their output hash values should be completely different
because the outputs are random
it seems that there is no relationship
between the output hash and the input data
That are the properties of the hash function that we should achieve
the next is one way usage
It means that's..
the hash function can calculate the hash of the input data
but from the hash output we cannot estimate any information
of the original data of the input data
cannot! because it's one-way usage only
the next is collision resistance
It means that it is very hard to find
two input data having the same hash value
to avoid the collision may cause during the operation
the question here is:
how to detect the change of blockchain ledger quickly by using the hash function?
okay
remember that:
blockchain is a chain of blocks connected via the hash values
here we have block 1 that stores the data set 1
to create a new block
we must firstly compute the hash of the data in the block 1
and then, this hash will be combined with the data set 2 in block 2
to form a new information
and then to create new block we need to compute the hash R2
of the data set 2 and the R1 here
and similarly, from here R2 combined with the data set 3
to make a new block and then we compute the next hash R3
for the new block
and doing so on
by doing like this you see that
a little change of data can cause the change of the final hash value R3 in here
for example, let's say if there's some modification in the dataset 1
it will result to the change of the R1
and R1 change, it means that R2 will change
R2 change means that R3 will be changed
right?
so finally we only check the final hash R3
if R3 is changed, it means that there is already some modification
inside the blockchain ledger
we don't know where it has been modified
we don't care and we don't know
but we just know that, we can ensure that
the blockchain ledger has been modified if the R3 here is changed, right?
so finally we will check R3 only
merkle Tree!
let's see the situation like this:
if there are many messages be stored in one block
how to compute the hash value of that block?
let's say we have four messages
message one two three and four
the calculation of the hash will follow the Merkle tree
this calculates like this
firstly the hash of this message will be calculated independently
r1, r2, r3, and r4 okay
and then it combined the hash of two messages into one new message
and compute the hash of the new combined hash here
for example:
here we calculate the hash R12 of the combined hash R1 and R2
or R34 for the combined hash R3 and R4
and finally we combine these two hashes R12 and R34 into a new message
and calculate the final hash
finally, the final hash is called the Merkle tree root hash
that will be stored in the block header
by doing like this if there are several thousands of messages inside one block
the Merkle tree hash function,
the calculation will become complicated and time-consuming
what are the steps to create a new block?
basically it follows three steps:
now we have block one
we want to create a new block, block two
and block 2 should store the msg3 and msg4
In first step, it generates the Merkle tree hash for msg3 and msg4
to finally get the Merkle tree root hash R34
the second step is to form the block header
by combining the Merkle tree hash R34
with the previous hash B1 and some other
information
that I will show you later
but it generate the header for block 2
In step three, it finds the new block hash B2 for this header
here is the structure of a blockchain ledger in more detail
Lets say, we have a blockchain ledger that has several blocks like this
block 51, block 52, 53, 54, block N,
and so on
and in each block there are transaction data
sometimes we can also call it as the message data
transaction A, B, C, D...
from these data we calculate the Merkle tree root
the Merkle root hash is combined with the header information
to form a new header
from this header, we calculate the block hash
in each block, you see that there are the transaction data
that we want to store in this block
and the hash of the previous block
and the hash of current block
there are two hash values will be stored in each block
okay
that is all for our lecture today
if you have questions or comments
please send me emails
or comment in the below of this video
thank you so much for your attention
Lets SUBSCRIBE our channel for more video
