What Is Smart Contract in Blockchain?

SMART CONTRACT IN BLOCKCHAIN

In the blockchain architecture, The term was coined by Nick Szabo, a computer scientist, and cryptographer, in 1996.

Szabo claimed that smart contracts can be realized with the help of a public ledger.

Blockchain architecture can be a pioneering technology to realize smart contracts.

 The smart contract term was first coined by Nick Szabo who was a computer scientist and cryptographer.

  In 1996;  he had first coined this term.

 Szabo claimed that this smart contracts that whenever you are establishing some kind of contracts between multiple parties that can be realized with the help of a public Ledger.

  That was his idea and because it can be realized by a public ledger. The same concept can also be realized using a blockchain. So, blockchain can be a pioneering technology to realize smart contracts.

CONTRACTS IN A CENTRALIZED PLATFORM-CROWDFUNDING

this concept of contracts in a centralized platform with an example of crowdfunding.  there is some kind of crowdfunding companies like Kickstarter.

  Kickstarter works in this principle like you want to execute some kind of interesting project, but you do not have sufficient money and this can be an individual or a group of people who want to execute some projects, but they do not have sufficient money. 

they submit this project to Kickstarter and mean the Kickstarter type crowdfunding company. 

And now there are multiple supporters who can support with some small funds to that particular project.

 Now, the project can be executed by one or individuals who have submitted the project proposal to Kickstarter.

 And on the other hand, you can have multiple supporters; so, these multiple supporters they can support a small fund and the total fund that you are getting with that help of that fund you can support that project or you can execute that project.

Now, the task of this Kickstarter platform is to ensure that when you are completing some milestones of the project, you are getting that fund. 

So,  Kickstarter is ensuring that whenever some supporters are providing with the fund; the fund is going to the intended project and as and when the project completes some milestones.

 So, the project executors are getting the fund and if the project is not completed successfully or in between the project gets scrap then the fund is sent back to the supporters.

THE CROWDFUNDING PLATFORM IN BLOCKCHAIN ARCHITECTURE

  • Both the product team and the supporters need to trust the crowdfunding platform
  • The product team expects the money to be get paid based on the project progress
  • The supporters expect the money to go to the project
  • However, the crowdfunding platform the middleman takes significant charge to manage the entire process

Now, in this kind of architecture, you need to have a kind of trust relationship; that means, the product team they expect that their money to get paid based on Project Progress.

 So, whenever there is some milestone that has been reached. So, they will be getting paid by Kickstarter; the supporter expects that their money is going to the right project and if the project gets scrapped in between then they will get back their money.

Now, this crowdfunding platform; which means, the Kickstarter who is working here as a middleman they take a significant amount of charges both from the supporters as well as from the product team.

 So, that way huge money is taken by the middleman and that is indeed the kind of problem with the centralized platform; that first of all you need to trust the platform, and second that you have to provide a significant amount of charge to this to this middlemen because they are actually handling the risk factor.

 you can understand for that for this kind of project there is a risk factor which is associated to it and because they are this kind of Kickstarter of the middlemen, they are handling this kind of risk factor that the project might not get completed or in between the supporters may claim that I do not want to support it further.

So, this kind of risk is associated with it. So, the middleman like kickstarted; they are taking significant charge to handle this kind of risk.

CROWDFUNDING PLATFORM USING SMART CONTRACTS

  • The contract is written in a code which is available to all the stakeholders-the supporters and product team

  This kind of crowdfunding platform can be realized with the help of a smart contract. So, the above image you have a set of supporters; so, this is your list of supporters and on the other hand you have the product team.

Now, this contract between the supporters and the product team is written in a code that is available to all the stakeholders like that particular code. So, this code contains the contract; so, this is your contract, and the contract is made available to the supporters, as well as to the product team.

Now everyone can verify that contract and in this particular case, you can see that if we put that contract inside the blockchain; then everyone will be able to verify that contract, but no one will be able to tamper with that contract.

So, this gives an interesting idea that well such kind of smart contract platform can be realized with the help of a blockchain.  so, whenever this contract gets executed.

 the contract has like after 10 days if this particular project milestone has reached then you transfer the money from the supporter to the product team.

  • If certain goals of the project are reached then the code automatically transfers the money from supporters to the production team.

 if this condition gets satisfied then the money is transferred from the supporter to the product team. 

that is automatically based on whatever is written inside the contract. 

  • If the project goals(contract) fail, then the code can transfer the money back to the supporters.

Now, whenever the project gets scrap if it is like that after some 50 days the product team says that well we are not able to make sufficient progress in the product.

So, we want to scrap the project then the money goes back from the product team to the supporters.

So, the contract the code which is written there inside the smart contract; it automatically transfers the money from the product team to the supporter.

 So, that way in this particular application inside the blockchain rather than putting some transactions or putting some data, we are putting a code which will be automatically verified by every stakeholder, they will not be able to tamper the code, they will not be able to deny the code in between, but as an when the code runs by verifying that whatever actions or whatever events have been executed the contract can get executed over time and fulfill the initial agreements that have been made.

SMART CONTRACTS-THE ADVANTAGE

  • Immutable: no party will be able to change the contract once it is fixed and written to the public ledger(the blockchain)
  • Distributed: all the steps of the contract can be validated by every participating party-no one can claim later that the contract was not validated
  • Why blockchain?
  • The blocks are immutable
  • The information is open-everyone can check and validate

So, the advantage of this kind of smart contract is first of all they are immutable; that means, no party will be able to change the contract once it is fixed and return to the public ledger like blockchain.

 Next, it is distributed you do not need a middleman like this to say Kickstarter who is handling all the risk.

  your code will be automatically get executed and if you are not fulfilling your promise then automatically the code will execute some steps based on the contracts.

 And why the blockchain? Why blockchain is a suitable platform for the executable smart contract? Because first based on the blockchain architecture, the blocks are immutable and the second the information is open, everyone can check and validate the information inside a blockchain.

SMART CONTRACT PLATFORM

 So, there are multiple smart contract platforms like Ethereum, hyper ledger, rootstock, ripple. So, we look into the hyper ledger in detail;

THE BLOCKCHAIN IN A BLOCKCHAIN-SECURING DATA CRYPTOGRAPHICALLY

Digitally signed and encrypted transaction verified by the peers

Cryptographic security-ensures that participants can only view information on the ledger that they are authorized to see

.

we will look into what is there inside the block of a blockchain. So, we so to put some data in the blockchain; we want to secure that data and how a block is securing the data by utilizing the concept of cryptography. 

So, we will take the example of bitcoin, in this case, to explain to you that what is there inside the block and how individual blocks are getting connected.

 So, these blocks they are kind of they are containing the digital is signed and encrypted transactions which are already verified by the peers.

So, inside the block, you can have multiple transactions. So, these are the transactions which are verified by the peers

and  these transactions are there in an encrypted format or it is basically signed digitally;

these are digitally signed  transactions which ensures that the participants they can

only view the information on the ledger that they are authorized to see .

STRUCTURE OF BLOCK

  • A block is a container data structure that contains a series of transaction
  • In bitcoin: a block may contain more than 500 transactions on average, the average size of a block is around 1 MB (an upper bound proposed by Satoshi Nakamoto in 2010)
  • May grow up to 8 MB or sometimes higher (as of March 2018)
  • Larger blocks can help in processing a large number of transactions in one go.

 the structure of a block. a block is a container data structure that contains a series of transactions.

 So, in the case of bitcoin, a block may contain more than 500 transactions on average. So, the average size of a block is around 1 MB; so, in the original white paper by Satoshi Nakamoto and bitcoin, he has me he had mentioned that the upper bound of a block can be around 1 megabyte, but in nowadays we are expanding the block size. So, a block may grow up to 8 megabytes or sometimes even higher than that.

that was the information as of March 2018; the recent information and the larger blocks it can help in processing a large number of transactions in one go.

So, if you remember the mining procedure in bitcoin that the miners collect all the transactions together put them in a single block.

if you can put more transactions in a single block then you can process it in one go. So, that is the advantage of having a larger block, but there are multiple disadvantages. 

STRUCTURE OF A BLOCK(REFERENCE: BITCOIN)

Two components;

  • Block header
  • List of transaction

BLOCK NO #500312

 let us look into the structure of a block; so, a structure of a block in the context of bitcoin they have 2 component the block header and the list of transaction.

whatever block is there in the bitcoin network you can see all the block blocks by going to this blockchain dot info website. So, this is the information of a particular block with ah block number 500312.

there is 2 part of the block the first part is the block header; so this is the block header and then there a list of transaction size of just shown one transaction, but there is the list of transactions which are there inside that block.

BLOCK HEADER

  • Metadata about a block
  1. Previous block hash
  2. Mining statistics used to construct a block
  3. Merkle tree root
  • Previous block hash: every block inherits from the previous block-we use previous blocks hash to create the new blocks hash-make the blockchain tamper-proof.

Now, in the block header; so this blockchain as you know as I have mentioned that this blockchain is a  sequence of blocks that are connected by the hash of the previous block.

So, H 1 is connected with the hash of the previous H 0, H 2 is connected with the hash of H 1 then ah this H 2 is used to connect H 3.

that way the hash function constructs the chain kind of structure. So, inside a block header, you have this previous block hash which is utilized to construct the current block hash.

So, here this is the previous block hash which is used to construct the current block hash; then the mining statistics in the case of bitcoin that some statistics about mining.

And something called the Merkle tree root which constructs, which stores the information or a or a hash value of all the transactions which are there.

Now, this previous block hash; that means, in the case of blockchain as we have mentioned earlier that every block inherits the from the previous block; that means, we use the previous block hash to create the new blocks it makes the blockchain tamper-proof; that means if you want to make some changes saying in this block; that means, this particular hash value will get changed and you have to change all the subsequent hash values.

So, that way you can think of that in a distributed network some people are trying to tamper the block if that person is trying to tamper the block; he has to make a change in all the blocks which are thereafter that.

And we want to make this problem as complicated such that by the time some person will tamper with few blocks, new blocks will get added and people will be he will never be able to reach up to the last block changing the hash value for the last block.

that way we make it tamper-proofs.

BLOCK HEADER(REFERENCE: BITCOIN)

  • Mining- the mechanism to generate the hash

-the mechanism needs to be complicated enough, to make the blockchain tamper-proof

-bitcoin mining: Hk = Hash(Hk-1||T||Nonce)

-find the nonce such that Hk has certain predefined complexity (numbers of zeros at the prefix)

  • The header contains mining statistics-timestamp, nonce, and difficulty

the second field which is there in The block header is the mining statistics.

the mine is to mechanism the generated hash. So, in the case of bitcoin, the hash function looks something like this. So, you have the previous hash along with the set of transactions.

this is the previous hash the hash of block k minus 1; the set of transactions and the random nonce value.

the task of the miner is to find out this nonce value such that they can ensure certain difficulty with this generated hash value.

for example, the complexity in bitcoin is something like that whenever you are generating this hash value; you have to find out this nonce such that whatever be the value of H k it will have some 20 number of 0s in its prefix or first 20 bits will be 0s.

So, that is the level of complexity.

Now, by the property of the hash function if H k is known you will not be able to find out this message, but if this message is known then only will be able to find out H k.

That means, what the miner has to do? They have to change this nonce, they will have to try with different values of the nonce to find out that when that objective is met the objective is that the generated hash value will have some certain number of 0s at the beginning So, that particular thing that how many numbers of 0s you want at the prefix or at the beginning that is called the complexity of the mining Algorithm.

the complexity of the mining algorithm will tell you that you want this many numbers of 0s at the beginning and as you increase the complexity of the algorithm you will require more time to find out this nonce value.

Now, this header ah blockchain header contains These parameters, it contains the timestamp when that mining has been done the nonce value which is providing the corresponding hash value and difficulty or the com complexity of the algorithm.

The difficulty actually determines that ah how difficult it was to find out ah that particular nonce to meet the criteria of the complexity of having certain number of 0s at the ah prefix of your hash value.

BLOCK HEADER(REFERENCE: BITCOIN)

  • Merkle tree root: the transactions are organized in a Merkle Tree structure.

The root of the Merkle Tree is a verification of all the transactions.

 the next of the block header it contains Other parameters called Merkle tree root;

 So, all the Transactions in an in a block we arrange them in the form of a Merkle tree. So, it is like that at the root of the Merkle tree you have this hash of the transactions.

every leaf node at the Merkle tree contains the hash of the transactions and the intermediate nodes; it contains the hash of the combined hash values.

Now, the root contains again the combined hash values of its left tree and the right tree. Now interestingly if you want to make any change in the transaction say if you want to make a change in transaction T 2, then this hash will get change, this hash will get change and at the same time, the root hash will get change.

that means if someone is changing one transaction; the root hash will change and once the root hash will change all the subsequent hash of all the blocks will get the change because they are linked with each other.

that is the beauty of The entire design of a blockchain which makes it a tamper-proof data structure.

So, this is a typical block header the different parameters in the block header;

see that in that particular block the number of transactions which were there in the block the total amount of bitcoin that have have been transferred the transaction fees that have been taken by the bitcoin network, the height of the block; that means, this is the height of the current main chain.

  the chain that was there the block was at hash this number. So, the first block is number 0 the second block is number 1 that way this block is of number 500312 the timestamp values who have generated these blocks.

this B T C dot TOP he is one of the minors who has validated the block. The difficulty level based on the hash finding algorithm, the mining algorithm that was there, how many bits ah was there in that block, the entire size of the block.

You can see that it is little more than 1 megabyte then some parameter called weight which actually balances among the size of different blocks.

The nonce which is used to generate the hash value; so, with this nonce the intended hash value has been found by this miner. And the block reward; that means, by generating this block

  1.  Block identifier- the hash of the current block header (hash algorithm: double SHA256)
  2. Previous block hash is used to compute the current block hash

 the block header also contains a certain number of hashes. So, these are the hashes; so, this is the hash value of the current block(1 row) now this is the hash value of the previous block(row2) and if there are some next block; it also contains the shows the hash value of the next blocks although this is not contained in the header and this is the value of the Merkle root.

now if you are making any change in one of the transactions the Merkle root gets change; if the Merkle root gets change then the corresponding hash value will get change if this hash value will get change the next block hash value will get change.

The way everything will get change and ah attacker have to actually change the entire blockchain. And initially, the current blockchain size is around 259; 250 GB. So,

 you have to make a change of that 250 GB of the blockchain of size. So, the hash algorithm which is used to compute that hash is a double SHA 256, 

  • The transaction is organized as a Merkle tree. The Merkle root is used to construct the block hash
  • If you change a transaction, you need to change all the subsequent block hash
  • The difficulty of the mining algorithm determines the toughness of tampering with a block in a blockchain

Now, the transactions in a block are organized as a Merkle tree and the Merkle root is used to construct the block hash.

if you change a transaction you need to change all the subsequent block hash. So, the difficulty of the mining algorithm determines the toughness of tampering with a block Now, you can see that if an attacker once to tamper with a block, he needs to change the values of all the subsequent hashes. 

the difficulties not very high then it may happen that by the time a miner will accept a new block, an attacker can change the hash of all the blocks that way the attacker maybe successful.

in this particular case, you need to ensure that finding out that particular The hash value is hash of hash ah the mine the attacker will not be able to change all the hash values in the ah complete blockchain. 

So, these are the transactions ah information inside the block. So, you can see that these are the users.

here it is not a transaction rather this particular user got some amount of bitcoin by mining; so, that transaction is here.

this is a valid transaction where this user has made a transaction to this user of ah around 2.96 bitcoin; so, that is the transaction in that block.

you cannot individually identify who is this user or who is this user, but you can determine that this is a kind of unique ID or unique address of a user ah who is making a transaction.

by looking into the value of this transaction you can validate the transactions, and at the same time at the top, you can see a hash value, this hash value is the hash value corresponds to this transaction.

Now all these hash values are combined in a Merkle tree and finally, Merkle root is added as a part of the block header.

THE BLOCK IN A BLOCKCHAIN -SUMMARY             

  • The block contains two parts- the header and the data(the transactions)
  • The header of a block connects the transactions-any change in any transaction will result in a change at the block header

The headers of subsequent blocks are connected in a chain-the entire blockchain needs to be updated if you want to make my change anywhere

in summary that the block ah in a blockchain; it contains 2 parts the header and the data the data contain the transaction the header of the block it connects the transaction. any change in any transaction will result in a change in the block header and the headers of the subsequent blocks, they are connected in a chain that way if you want to make any change in any of the blocks; you need to update the entire chain.

THE BLOCKCHAIN REPLICAS

  • Every peer in a blockchain network maintains a local copy of the blockchain.
  • Requirements
  • All the replicas need to be updated with the last mined block
  • All the replicas need to be consistent -the copies of the blockchain at different peers need to be exactly similar

  the replica the idea of this blockchain is that multiple nodes in the network are interconnected and every node, they contained a replica of the ah blockchain. every one of these nodes is maintaining a replica of the global blockchain.

the requirements are first all the replicas that are there at individual users they need to be updated with the last mined block. And all the replicas need to be consistent; that means, the copies of the blockchain at different peers need to be exactly similar.

THE NOTION OF DISTRIBUTED CONSENSUS

  • Ensure that different nodes in the network see the same data at nearly the same point in time.
  • All nodes in the network need to agree or consent regularly, that data stored by them is the same.
  • No single point of failure-the data is decentralized
  • The system can provide service even in the presence of failures

here the notion of consensus come into practice and a notion of distributed consensus

where explode in the literature from the early 1990s, where people have ensured that different nodes in the network, they see the same data at nearly the same point of time.

And in other words all the nodes in the network they need to agree or consent on a regular basis that the date of which is stored by them; they are similar they are exactly similar.

that particular algorithm we call it as a consensus algorithm and the consensus algorithm ensures that there is no single point of failure because your entire data is decentralized.

if one node fails you have still had the data into multiple other nodes and so, the system can provide you service even in the presence of failures until and unless the network gets disconnected.

THE NOTION OF DISTRIBUTED CONSENSUS

  • Starting from the early ’90s a large number of works have been devoted to the development of consensus algorithms over a network
  • The basic philosophy is based on message passing-inform your current state to others so that everyone can match their current state with others in the network
  • However, this philosophy requires that the participants in the consensus algorithm know each other.

 Now,   I have mentioned that starting from the early 90s a large number of works have been devoted on the development of consensus algorithms over a network.

And a basic philosophy is based on message passing like you inform your current data to other nodes and everyone that way gets the data from all other nodes and validates their local data.

And that way you can see whether the data that you have whether it is the most recent data or whether that need data matches the data of your peer.

Now, this philosophy requires that the participant in the consensus algorithm; know each other because you need to check or you need to find out with which node you can validate your data.

  • Can we achieve consensus even when the network is arbitrarily large, and no participant in the network really knew all other participants?
  • An open network scenario-the permission-less protocol-you do not record your identity while participating in the consensus system
  • A challenge-response based system-the network would pose a challenge and each node in the network would attempt to solve the challenge.

  the question that comes in the blockchain network; if you remember the objective of the bitcoin network that bitcoin network was a kind of permissionless network.

Permissionless network in the sense that anyone can join the network anytime without reviling their authority; so, or reviling their identity.

in that sense, the traditional distributed system algorithm based on message passing is not applicable here because you do not know that with which nodes you will validate your data. 

the question that we have here that can we achieve consensus even when the network is arbitrarily large; that means, no participant in the network really knew who are all other participants? So, we call it a kind of open network scenario or a permissionless protocol.

you do not record your identity while participating in the consensus algorithm, but still, you will be able to reach in the consensus.

to explore this kind of idea people have found out that well a kind of challenge-response based system can work good in this architecture where a network would pose a challenge to the participants, every participant to will solve that challenge individually and each node will ah in the network would attempt to solve that particular challenge.

CHALLANGE-RESPONSE TO PERMISSION-LESS CONSENSUS

  • The challenge-response protocol: the nodes in the network tries to solve the challenge posed by the network

-The nodes or the participants do not need to reveal their identity

  • The node that is able to solve the challenge first would get to dictate what the next set of data or state elements to be added should be
  • This will continue iteratively at different rounds

  a kind of challenge-response protocol where the nodes in the network they try to solve the challenge which is posed by the network.

in that case the nodes do not need to reveal their identity. So, the network is giving them the challenge they have to solve the challenge and once they have to solve a challenge; they will announce that way I have able to solve the challenge first.

I was able to validate the data you can add this data to the existing system; so, this will continue iteratively at different round 

  • Design of a good challenge- ensures that different nodes will win the challenge at different runs.
  • This ensures that no node would be able to control the network
  • The bitcoin proof of work (pow) algorithm-ensures consensus over a permission-less setting based on challenge-response

if you can design a good challenge which will be posted at different rounds. So, you can ensure that that different rounds of different nodes will win the challenge.

that way you are ensuring that no node will be able to control the network single-handedly. So, at one round one, a note will node will able to solve the challenge.

that node will be able to say that way I am able to solve this a particular challenge; so, this block is the valid block please add this block in the ah current blockchain.

that was the idea which came into practice and this idea is known as proof of work algorithm in the context of bitcoin, which ensures that you are ah you are having a consensus over a permissionless setting based on this kind of challenge-response principle.

  this challenge-response kind of thing is the basic principle behind proof of work algorithm.

THE ECONOMICS BEHIND BLOCKCHAIN CONSENSUS

  • The challenge-response requires that every node spend a large amount of computational power to solve a mathematical challenge in each iteration of consensus.
  • What is the incentive for nodes? Only one (or sometimes a very few of them) will win in each round

 Now, there is another factor; so, the participate they are solving the challenge; that means, they are incorporating or they are spending a significant amount of resources like computation power than time to solve that particular challenge and what is the benefit to them? What is the incentive for the nodes? Why they will participate in this challenge-response algorithm?  Because only one will win in each round, but others are also spending their resources what would be the incentive for them.

  • The digital money
  • Ensures operational efficiency
  • More levels of controlling monetary policy
  • 1998: Wei Dai published “b-money” – an anonymous distributed cash system
  • cryptocurrency – a currency beyond the control of banks and governments

 the concept of digital money ensures operational efficiency and it provides more level of controlling monetary policy.

Now in 1998 Wei Dai; published a concept call b money which is a kind of anonymous distributed cash system which is we can say it is the mother of this concept of bitcoin or cryptocurrency.

cryptocurrencies something like it is a cryptographic currency there is no such physical currency. So, no one has to give the physical currency to a person rather than the network will generate that currency; so, those currencies beyond the control of the banks and the governments.

  • The mining ensures that no node has the power to sabotage the network and gain control 

          -no one can hold the control of the cryptocurrency

  • The computational effort expended by the nodes in achieving consensus would be paid for by the cryptocurrency generated and managed by the network
  • Blockchain ensures that the currency is secure and tamper-proof

  That whenever the participants are there in the mining procedure, the mining ensures that no node has the power to sabotage the network and gain the control that is the good part of this cryptocurrency algorithm that no one will be able to hold a control of the entire cryptocurrency.

that was the basic philosophy like there should not be one centralized node like a bank or a government will control the entire monetary policy; at every round, different people will able to add data to the blockchain.

And the computational effort expended by the nodes in achieving the consensus algorithm will be paid with certain cryptocurrency which is generated by the network and managed by the network.

that way there is a kind of monetary benefit to the miners that if they participate in the mining procedure and if they devote their computational resources and time in the mining procedure; they will get a certain amount of money in return.

that is the economic thing behind ah this kind of ah bitcoin mining concept. So, the blockchain is ensuring this currency is secure and tamper-proof.

In summary

  • The technology behind blockchain
  • The data structure-distributed ledger
  • Cryptography and digital signature– ensure security and tamper-proof architecture
  • The consensus over a permission-less environment
  • The economy of the revenue model-encourage participants to join in the mining procedure

 In summary, there are multiple technologies behind blockchain and we have a data structure that minutes the distributed ledger.

 which is forming the backbone of the blockchain.

We have the cryptography and the digital signature algorithms which is ensuring the security and tamper-proof architecture of this entire blockchain data structure. 

We have the consensus algorithm over a permissionless environment based on the challenge-response scenario where you do not require to reveal your identity. 

But still, you can ensure that whatever data which is there at individual nodes they are correct data and then the economy or the revenue model behind this architecture that it encourages the participant to join in the mining procedure and to validate that a block is a correct block.

READ MORE ARTICLE: R3 CORDA

follow us on facebook

Leave a Comment