BITCOIN BASIC III
So, in the last discussion, we have discussed that whenever a new node comes to join for a bitcoin network so that a new A node can join in an existing bitcoin network and then get updated to the most recent copy of the blockchain. Now, in this particular discussion, BITCOIN BASIC III we will look into how the node can start initiating the transaction and how the transaction gets committed in the current blockchain that a network has.
BITCOIN TRANSACTION NETWORK
- Alice joins the Bitcoin network by opening her applet
- Alice makes a transaction to Bob: A->B: BTC 10
- Alice includes the scripts with the transactions
- Alice broadcasts this transaction in the bitcoin network
The transaction in a bitcoin network happens in this particular way. So, after Alice joins the bitcoin network after that joining by opening her applet
Alice can initiate a transaction with Bob. So, this is a sample transaction that Alice Initiates. So, this a sample transaction that Alice initiates. Once Alice constructed this transaction with Bob with certain bitcoin say 10 bitcoin.
Alice includes the inputs scripts and outputs scripts with this transaction to validate the authority of this particular transaction. And once these transaction messages get constructed then Alice broadcasts this transaction information in the bitcoin network.
TRANSACTION FLOODING IN A BITCOIN NETWORK
Let us look into the way these things are getting broadcasted.
So, when Alice joins the network after joining the initial step is to get the A most recent copy of the blockchain from the peer neighbors, after getting the most recent copy of the blockchain from the peer neighbors Alice can start initiating the transactions. once Alice initiates a transaction. see basically broadcast this transaction to her peers. the transaction gets broadcasted in the peer network.
Once we are making a broadcast of the transaction in the peer network every node in the peer network, they can receive this transaction and they can validate whether the transaction is a valid transaction or not by looking into the scripts by executing the scripts.
So, the nodes individually validate the transaction that is their First task, through validating the transaction that you can do. So, there are multiple algorithms to validate a transaction.
To validate a transaction you can Basically, first, run the input script and output script which is associated with your bitcoin transactions, by executing that script you can find out whether Alice is actually initiated by the transactions or not.
Well, in that particular transaction a transaction looks like from Alice to Bob in this transaction say if this node is not Bob says this node is something like C, Charlie.
Charlie will be able to validate this particular transaction, but because of the destination, The address is Bob’s address. Charlie will not be able to accept These transactions or include this bitcoin in his wallet.
Only only Bob will be able to include this bitcoin in his wallet and will be able to use that bitcoin for further transactions.
But any intermediate node they can run the scripts, they can look into the scripts, and by looking into the scripts by executing the scripts they can validate whether this particular transaction is actually originated from Alice or not.
Now, after doing this validation every node they again flood the transactions in the network.
That way every transaction is actually getting propagated in the entire bitcoin network and everyone in the entire bitcoin network will be able to see all the transactions if they are online during that time and they will be able to validate the transactions.
So, that is the interesting concept behind bitcoin mining that the miners will also be able to receive all the transactions which are getting propagated in the bitcoin network and they will be able to construct a block with the help of those transactions.
So, let us look into that particular mining procedure in further detail.
So whenever you are flooding the transactions during that time it may happen that this particular node has already seen the transactions.
If the node has already seen the transaction they need, it does not consider these transactions any further; it simply drops that transaction or it does not do a rebroadcast of that transaction. So, for this particular node initially, it had already received the transactions directly from Alice.
During that time it had already observed These transactions, so every node may also maintain a list of a first transaction that the node has observed and flooded.
If it receives any such kind of duplicate transactions do not flood the transactions for a second time. it avoids having kind of the entire bitcoin network getting clogged with this kind of flooding message.
We basically limit the amount of flooding in the bitcoin network, that you are not unnecessary doing any flooding of the transactions.
WHICH TRANSACTION SHOULD YOU RELAY?
- The transaction is valid with the current blockchain
- No conflict
- No double spending
- The script with a pre-given set of whitelist script – avoid unusual script, avoid infinite loops
- Does not conflict with other transactions that I have relayed after getting the blockchain updated – avoid double-spending
Now, the question comes that which transaction
Should I relay?
So, first of all, you need to check that the transaction is valid with the current blockchain. In the blockchain, you already have a list of transactions.
you already have a blockchain that has a list of transactions and whenever you are getting new transactions of some bitcoin thirty from Alice you check with the existing transactions in the blockchain that whether Alice is allowed to spend that much bitcoin or not.
It may happen in the transactions you can find out that initially, Alice had some say 50 bitcoin with her, and Alice already made a transaction of say 40 bitcoin.
If you can see from the existing blockchain that this particular two transaction has happened already that means, from here you can compute that currently, Alice has only some 10 bitcoin with her.
This particular transaction which she is going to do right. Now, this is not a valid transaction. So, that way by looking into the existing history of the transactions you can determine whether a particular transaction is valid or not.
That is the first task that every node needs to do that after doing the script validation they need to validate that there is no such conflict with the existing transactions, and there is no such double-spending. Double spending in the sense that you are looking into there are two transactions from Alice says that initially, Alice had some 10 bitcoin with him.
Now, say, Alice is making one transaction of bitcoin 10 to Bob, and Alice is making another transaction of saying bitcoin 10 to Charlie.
If Alice is making two such transactions that mean this is an example of double-spending and Alice is not allowed to make this transaction. while doing this validation you have to check that with the existing blockchain there is no such conflict and at the same time, there is no such double-spending.
So, after doing this check then you check the script that matches a pre-given set of whitelist script. So, in a bitcoin network, there are already a certain set of scripts that are normal or which are usual scripts.
you check whether the script belongs to that set of whitelist script or not, and In general, if you are a normal bitcoin User, you avoid unusual scripts.
Say for example, if a script somehow implemented a kind of indefinite loop inside the code, if that is the case then that is not a general feature of a bitcoin script. So, you discard that particular transaction.
And then the point that I have mentioned is that although double spending can be a part of the existing blockchain like Alice has already made a transaction which has been recorded in the existing blockchain.
And then Alice is making the transaction of the same bitcoin again which is an example of double-spending. Another example of double spending is that Alice is sending two transactions one after another and in both the transactions, She is trying to spend that same bitcoins.
That means Alice has made a transaction to Bob with some 10 bitcoins and immediately Alice has initiated another transaction to say Charlie with a similar 10 bitcoin.
So, if that is the case that can be one example.
The second example would be like Alice has a transferred Bob of 10 bitcoins and after a few seconds Alice has initiated another transaction that may be an intention on the transaction or that sometimes becomes an unintentional transaction; that means, you have kept the same button twice in your wallet if you tap the same button twice in your wallet that will generate two different transactions.
That will generate two different transactions from Alice to Bob. If you are generous, two different such transactions. So, you do not include both the transactions in the same blockchain.
If you have already seen this transaction when you do not relay these transactions any further. this also avoids this kind of double-spending where unintentionally Alice has tapped the same button twice. That way you can validate whether the transactions that you have received from one of the peer nodes should relay the transactions further or not.
Now, if you agree to relay the transactions further then you broadcast the transactions again among your peer nodes.
TRANSACTION FLOODING IN A BITCOIN NETWORK
Now, whenever you are flooding the transactions in the network, there are certainly interesting scenarios. It may happen that different nodes have different views of the transactions or they have different transaction pools.
So, for example, in this particular scenario this A to B transaction that gets propagated in this direction, there is another transaction C to D which is getting propagated.
Now, right side nodes have only seen the C to D transactions; this set of nodes has only seen the A to B transaction. Left side set of nodes they have only seen the C to D transactions and this set of nodes(middle) have observed both the transactions.
So, ideally what happens that this can always happen in a network, and if this happens then you accept the first set of transactions that you have heard and use those set of transactions to construct a new block.
But whenever you are constructing a new block it is always like that different miner in the network, they can start working with A different set of transactions, and they try to push the transaction in an existing block.
And in general what we do in the case of a bitcoin A network you wait for around 10 minutes of time for taking all the transactions which you are observing and then construct a block of the maximum block size.
Now, if you are waiting for 10 minutes of time to collect all the transactions, later on, will see that it is guaranteed that by that time you will also receive the most updated block.
So, once you received the most updated block you can see that which are the transaction that you have adopted whether they have already included in the existing block or not if they are not included in the existing block and you are a miner then you can construct a new block with the remaining transactions and you can try to mine the corresponding Hash function to find out the nonce and connect this block try to connect this block with the existing blockchain.
well, that was the idea that you always accept the first setup transactions that you have heard.
MINING IN A BITCOIN NETWORK
Now, once you have constructed the blocks with the set of transactions that you have heard there are certain nodes in the bitcoin The network works as a miner.
Now, remember that it is not necessary that every participant in the bitcoin network need to be a miner. There can be a certain special node who has some good computation power and they can invest time to participate in the mining process and a mining procedure that we have discussed briefly, the broad idea is to solve that hash A puzzle where your task is to find out nonce.
So, that the resultant hash value becomes a hash the condition like you have a certain A number of zeros at the prefix. So, if that particular condition its imposed and based on that condition you are trying to mine the new blocks you are trying to find out the new blocks that are a computationally difficult task and you need to support the power of your machine and the computation time.
That is why, so it is not necessary that all the nodes in the network work as a miner you can have a certain number of nodes in the network which is ready to dedicate their resource for the mining purpose and they can participate in the mining procedure.
And remember that as we discussed earlier like in this scenario the incentive for the miner is that if they are successfully able to mine a new block they will be able to get a reward from the network which is the kind of incentive that they get.
Now, the miners they collect all the transactions from the network after collecting all the transaction from the network which has been flooded within the last 10-minute duration that I have mentioned, they construct the new block if the transactions are not already included in the most updated blockchain and they can start mining.
BLOCK GENERATION PUZZLE
Now, in the mining part as we have mentioned that in a blockchain architecture you have this hash value of this block is included in the hash value of the next block.
So, every block header contains the previous hash value and along with that the task of the miner is to find out this nonce. So, the task of the miners is to find out this nonce such that the hash value the block The hash value that it is generating that particular block hash value has a certain fixed number of zeros at the prefix.
a block has looked like this where you have a certain number of zeros at the prefix.
that is the difficulty of the problem that is imposed from the bitcoin network, and it works like a challenge to the miner and the task of the minor is to accept this challenge and try to solve this particular puzzle.
Their task is to find out this nonce value such that they can find out the block hash by including this Merkle root and the previous hash so that this hash cash this property it has a certain number of fix zeros at the prefix.
Now, if that is the case based on that the blockchain architecture you can understand That more than one miners can actually find out the non simultaneously.
So, we will discuss how we actually handle this kind of problem in a blockchain or in a bitcoin network.
So, in general in an ideal case one Miner, the miner will be able to correctly find out the nonce value by solving that puzzle.
Once the miner is able to find out the nonce value by solving that puzzle he or she is able to generate the new hash which connects the blockchain with the which connects the block with the previous blockchain and that way by connecting the new block with the previous blockchain the entire blockchain gets updated.
And after updating the blockchain you actually update you actually broadcast this updated blockchain to your peer neighbors. So, that way the blocks, the updated blocks they are basically getting flooded again in the network.
So, we have to floodings here one is the flooding of the transactions and the second is the flooding of the blocks from the miners. Now, as I have mentioned earlier that it is certainly possible that more than one miners have generated the blocks.
Now, if more than one miners have generated the block there are multiple cases that may arise, it may happen that both the miners Have to mine the same block or it may happen that both the miners have mine different blocks because they have a different view of the transactions.
So, what may happen that if they generate new blocks simultaneously or at least in a near-identical type that the blockchain can have more than one block connected to a particular block?
BLOCK PROPAGATION – ACCEPT THE LONGEST CHAIN
So, in this example that we had seen earlier during or initial discussion that a particular block can have more than one trades through which the blocks are getting added.
It is like that in this particular example that at that time duration one miner say M 1, that miner was able to find out The cryptographic hash for this block which connect block 3 with block 1, at the same time miner 2 this also able to connect this block to block 1.
Now, in a typical bitcoin network what will happen that let me go to the previous
An example is whenever two miners are able To construct the block simultaneously.
So, upper side miners will start sending the blocks and right side miners will also start sending the updated blocks. So, these nodes consider this node in between.
Now, this(in center green circle) node is getting the blocks from 3 different links, this node (in center green circle)will get the blocks to his right side link to his upper side link as well as to his left side link. Now, whenever that particular node is getting more than one copy of the blockchain.
So, this node accepts the copy which has been transferred by the maximum number of peers. if this copy(left side) of the blockchain from this node, if it goes to say let us use a different color.
So, if it goes from here and then if it comes in this particular link; that means this block has been received by this node from two peers.
So, add I this blue block has been received from one peer. So, this node then will accept this brown block and it will broadcast this brown block Further. So, this particular rule we call the 51 percent rule.
It says that the copy of the block that you are getting from more than 50 percent of the neighbors, you accept that particular block and broadcasted further in the network and the other block you can discard.
So, that way different copies of the blockchain can propagate in the network, and whenever different copies of the blockchains have propagated in the network then you can select the blocks based on this principle.
Otherwise, if you are getting two copies of the blockchain where the maximum chain plaint is different if the maximum chain lengths differ between the two receive copies of the blockchain then you accept the copy which has the longest chain length that we discussed earlier.
So, that way, whenever you have such multiple leaks multiple parts you always accept either the longest chain which is there and all the new mine blocks will be added to the longest chain.
And these other parts which are there which can eventually construct and after some time they will not be used by any of the nodes in the blockchain and they will get discarded this particular block we call as the orphaned blocks.
These are termed as the orphaned blocks, and this procedure when where you can have a different part other than the longest chain this particular part is known as a fork. So, this is the longest chain and these are the fork. So, you always accept the longest chain and you ignore the forks.
Now, as I have mentioned that sometimes it may happen that you have two different chains of the same length if there are two different chains of the same length then you accept the chain which has been broadcasted by a more number of peers,
WHICH BLOCK RELAY
- Block contains the correct hash based on the existing blockchain
- All the transaction inside the block are valid
- Check the scripts
- Validate with the existing blockchain
- The block is included in the current longest chain
- Do not relay the forks
So, the question comes that whenever you are getting a block with a block to relay.
first, you check the validity of the block like the block contains the correct hash based on the existing blockchain. So, the hash value is already included there.
As we have mentioned during the discussion of the hash function, finding out the reverse of a hash means that if the message The digest is given, finding out the original message is difficult but given a message you can easily construct the digest. Now, whenever a new blockchain is getting propagated in the network say for example,
In this case, whenever this blockchain is getting propagated in the network and you are getting this information say you this is the latest block that you have received, So, whenever you have received the blocks.
in the block header, you already have the block hash and you know that this block hash is generated by doing a hash over the previous hash, the nonce, and the Merkle root. you take these 3 parameters to apply to play the hash function and you check whether you are able to get the block hash or not.
If you are able to get the block hash that means, you are able to successfully validate the authenticity of this particular block at this block can get added in the network. So, that was the first point. The second point was that you need to change the check that all transactions inside the block are valid.
So, you can do that again by checking the scripts or validating it with the existing blockchain that you already had and the third point that a block is included in the longest chain.
So, you should not relay the fork.
That means, in a blockchain if it is a case like that say this is the longest chain and a new block is an included here if this is a new block then you should not accept this new block because this new block is included as a fork and not a not as a part of the longest The chain that you have.
BLOCK PROPAGATION LATENCY
An interesting fact about this block propagation is the block propagation latency. So, this is one particular example that was taken from this paper by Christian Decker and Wattenhofer Roger.
They have done a lot of statistical study over this bitcoin network and they have found out a distribution of the block propagation duration.
So, in this curve, you can see that the x-axis is the time for this block propagation that once The block has been created and after that you have a received update what is the time difference between the two, that is the time since first An observation which is in second and in the y-axis you have the probability density function of that. And you can see that most of the blocks most of the time you can, actually, see the blocks with some twenty second duration.
So, the meantime for this block observation is 12.6 seconds; that means, on average within 12.6 seconds every node in the bitcoin network will get the most updated Blockchain. And 95 percent of the nodes can see the block within 40 seconds.
if you can wait up to 60 seconds or 1 minute within 1 minute if a new block is created it is sure that we need 1 minute you will be able to see the new block. Now, you are waiting for 10 minutes to construct the next block.
If that is the case then the interesting factories that by the time you will construct a new block you have already seen the most updated block.
So, because you have seen the most updated block you can see only find out which are the transactions that you should include in the new block and try to add that new block with the existing blockchain if you are a miner and then you can start the mining procedure with an expectation that you will be able to solve the hash puzzle and you will be able to include that block in the blockchain.
So, that is all about these particular discussions.
So, we have broadly looked into how the transactions are generated in a bitcoin network and how these concepts of script checking are used to validate a particular transaction in a bitcoin network and finally, how the blocks are constructed and gradually included in a bitcoin network.
In the next set of discussions, we will look into the details of the consensus distributed consensus algorithm which is a part of a blockchain. So, will start with the consensus as an algorithm that is used in a general bitcoin network like the proof of our consensus such that is widely accepted as a consensus algorithm for the bitcoin network, which was originally proposed for the bitcoin network.
And then gradually we will look into that details about other variants of consensus The algorithm which people have proposed for bitcoin kind of network or in general any kind of permissionless blockchain that is there in our current system.
So, with this, we have covered the basic part of the basic understanding of the cryptographic primitives for blockchain and with bitcoin, we have seen an example about how you can apply these concepts of blockchain in a practical example of bitcoin to create a digital currency.
So, with this as a starting point, we will move further with the details of a different blockchain consensus algorithm and the blockchain security algorithm in the subsequent discussion.
READ MORE ARTICLE: R3 CORDA
follow us on facebook