Introduction to Smart Contracts
When a contract is written in computer code, as opposed to traditional legal language, it is deemed a smart contract. This programmed contract is set up to execute and carry itself out automatically under specified conditions. When a smart contract is on the blockchain, both parties can check its programming before agreeing to it, and then let it do its thing, confident that it cannot be tampered with or changed. It lets two parties agree to complex terms without needing to trust each other, and without needing to involve any third parties.
For example, you can write a smart contract about paying $450 for rent every 30th of the month, transferring the assets once the predetermined payment is received, vote on the day of elections with the records being untampered, etc. One of the most important qualities of the smart contracts is that since the contracts are stored in a blockchain, they cannot be changed once written.
Read our guide on smart contracts to know how smart contracts work and their pros and cons. This guide has been written as an extension to the guide on smart contracts to discuss smart contracts on different platforms.
Ethereum’s Smart Contracts
Ethereum is a public, open-source, blockchain-based peer to peer networking software with a built-in programming language that allows developers to build and deploy decentralized applications (Dapps) using smart contracts. It provides a decentralized virtual machine, the Ethereum Virtual Machine (EVM), that executes contracts used to transfer money and develop and run various kinds of Dapps which are accessible anywhere in the world.
It was Vitalik Buterin, the co-founder of Ethereum, who introduced the world to the new concept of smart contracts. He wanted a future where developers could create new applications on decentralized platforms. Ethereum’s network is a decentralized supercomputer that rents out its resources i.e. its computing power to developers in return for gas.
Ethereum currently uses the Proof of Work (PoW) consensus mechanism but is soon planning to move to Proof of Stake (PoS). One of the biggest reasons why blockchain platforms are moving from PoW to PoS consensus is that the PoW algorithm consumes a lot of computational resources which is harmful for the environment. It is very difficult to scale a blockchain that has a PoW consensus mechanism. It is also only beneficial for the miners. PoS on the other hand is beneficial for the token holders as it allows them to participate in the block production process. The new consensus protocol that Ethereum plans to use is called Casper Friendly Finality Gadget (FFG).
Casper has been designed in such a manner that it can punish all malicious elements in the network. The validators on Ethereum’s network stake their ETH on the network. The blocks are produced and added to the chain as done in a PoS consensus mechanism. Whoever appends the chain with the block gets rewarded for doing so. But there is a case of “nothing at stake” where validators try to fool the system in order to get rewarded. In that case their stake will get slashed. Casper therefore helps in building a trustless system that is more Byzantine Fault Tolerant.
Having their stake slashed means that their chances of getting rewarded decreases. Casper has also been designed in a manner that guarantees network security by punishing all the validators who go offline be it intentionally or not. Therefore, all validators have to stay alert as long as they are a part of the network.
While Casper consists of both Casper Friendly Finality Gadget (FFG) and Casper Correct by Construction (CBC), Ethereum is currently focusing on Casper FFG for Ethereum 2.0’s rollout. Casper FFG is a hybrid of PoW/PoS consensus mechanism which has been designed to make the transition between Ethereum from PoW to PoS smooth.
Smart Contracts on Ethereum
Smart contracts on Ethereum use a resource meter to keep a check on such spams. This resource meter is called gas fees. It refers to the fee for the computational resources needed by the nodes to successfully conduct a transaction or execute a contract on the Ethereum blockchain platform. The main purpose of gas is to mitigate spam and allocate resources on the network. Gas is priced in Gwei where 1 Ether = 1,000,000,000 Gwei. This gas is used to allocate resources of the EVM so that decentralized applications such as smart contracts can self-execute in a secured fashion. You need to pay for gas before the execution begins. This ensures that the network is not spammed.
Governance and Ethereum’s Smart Contracts
Governance refers to the mechanisms through which a system makes decisions. Ethereum’s protocol allows for only some on-chain governance. Most of the governance is off-chain and is managed through Ethereum Improvement Proposals (EIPs). An Ethereum Improvement Proposal is the document used to provide information to the Ethereum community regarding requests for enhancements or proposed upgrades to the Ethereum protocol
Ethereum’s guidelines suggest that these proposals must be backed by technical knowledge and specifications, must be accepted by the community and most importantly all the views regarding the EIP must be viewed and heard before reaching a conclusion. These EIPs can also originate from Ethereum Request for Comments (ERCs). It is through this ERC that ERC-20 tokens and other tokens came into existence. Once the ERC is able to garner support from the community will it later be changed into an EIP.
Thus, developers of Ethereum have a lot of discussions around the EIPs on Github before any implementations are made. New codes are implemented only if they believe that it will improve the functionality of the network. It is very difficult to get something implemented through the EIPs especially to avoid failures like the Ethereum hard fork.
EOS’s Smart Contracts
The EOS Blockchain is a decentralized operating system that has been developed to support industrial-scale Dapps. This platform was developed after scalability issues were witnessed on Ethereum’s blockchain. While Dapps can be developed on the Ethereum blockchain too, they cannot be used for large scale purposes. This is because the number of transactions per second that Ethereum offers is far less than what the centralized institutions can offer in the industry. Adding to that, the fact that users have to pay a transaction fee while executing smart contracts on Ethereum acts as a disincentive for people who could switch from centralized apps to Dapps.
The EOS protocol was developed by the private blockchain firm Block.one, which is based in the Cayman Islands. Brendon Blumer, the CEO, has been involved in blockchain since 2014. He was previously involved in companies that dealt with currency exchanges in MMORPGs and in real estate. It’s Chief Technology Officer is Daniel Larimer who launched both the first decentralized exchange, Bitshares and the blockchain-based social media platform, Steemit. He has also helped in the development of the Delegated Proof of Stake consensus mechanism (DPoS) that was adopted by EOS.
In order to increase the number of transactions per second so that EOS can support industrial-scale Dapps, EOS delegates the validation of the blockchain to 21 members in the network. This is done under the Delegated Proof of Stake (DPoS) consensus mechanism that has been adopted by the software.
For new blocks to be produced, the 21 block producers who are also referred to as “supernodes” are chosen from the network. These supernodes have the responsibility of validating transactions, signing them, and adding them to the blockchain. Only they have the right to do these tasks on the network. The top 20 producers are automatically chosen while the 21st person is chosen based on the number of his votes as compared to the other candidates. To ensure that regular block production is maintained at the rate of 3 seconds per block, producers are punished for not participating by getting removed from the group of 21 producers. To be taken into consideration, a producer has to produce at least one block every 24 hours. Since only 21 people are involved in this consensus mechanism, this network is faster than most of the other networks that we are aware of. But giving the power to only 21 people also poses a risk of centralization in the network.
But we have seen that other decentralized networks have a large number of stakeholders who are responsible for validating transactions. The reason why Daniel Larimer, the founder of EOS, chose to appoint 21 delegates in EOS is because any more, according to him, would be detrimental to the stakeholder’s attention which would cause voters to make poor decisions.
Anyone who holds the EOS cryptocurrency can vote for the block producers for the network. The weightage of the votes is based on their respective holdings. Also, anyone can participate in the block producer election and they will be given an opportunity to produce blocks proportional to the total votes they receive relative to all other producers.
The DPoS consensus mechanism and the Byzantine Fault Tolerance system represent EOS’s consensus mechanism. To vote on the network, the EOS token holders have to stake their tokens on the network which gets locked for three days. Each staked EOS token can be used to vote for up to 30 block producer candidates and the top 21 candidates are elected as the supernodes. Thus, EOS uses token voting to achieve decentralization. But this also poses a risk of centralization as there is a potential risk as whales can upvote specific individuals and create cartels or not share rewards with the ecosystem.
As of August 23, 2020, 595 million EOS tokens were staked for voting which is approximately 58% of the total supply of EOS tokens. You can get more information about voting details on this website.
Smart Contracts on EOS
Developers who have worked on other platforms to develop Dapps might have found working on the EOS platform more preferable especially because no user has to pay any transaction fee unlike many other blockchain platforms. Moreover, developers can develop Dapps using WebAssembly languages like C++, Java and Python.
Additionally, developers do not have to spend as per the pay per transaction model. Instead they use the resources of the network in proportion to their stake in it. This means that any developer who owns a 10% stake in the network can use 10% of the entire network resources.
The EOS blockchain contains three types of resources. The first one is the network bandwidth that is needed for relaying information across the network. The network also needs some processing power to run the Dapps. The higher is the computing power, the better it will be for the users and the developers. Both of these resources are measured as the average usage in the past 3 days. Lastly, for all the tasks that are performed on the network, users and developers need to store their data on the blockchain. This storage is provided by the RAM. Users use it to add information in their accounts and developers use it to store their current state information on the blockchain.
It might happen that some people may try to misuse the resources and constrain the network by unnecessarily occupying the resources. This is exactly why they need to stake EOS tokens before using the resources. It might happen that someone has extra RAM and they may not need it. The RAM can be traded with other developers and the best part about using EOS is that the trading of RAM is independent of the price of EOS token.
For people who wish to start using EOS’s platform, they need to purchase RAM from the network. This will allow them to create an account and then start using Dapps. Once an account is created and you start doing more and more transactions, the CPU available for your use keeps decreasing if you do not stake more tokens on the network. The CPU can take up to 24 hours to regenerate depending on EOS network congestion.
While users do not have to pay any transaction fees, the network is not completely free for users and developers. The net bandwidth and the CPU can be used by staking EOS tokens but RAM can only be used by purchasing it directly from the marketplace. Thus, the blockchain platform is of no use to people who do not own EOS. Also, users do not pay any transaction fee but that does not mean that there is no computing power involved during transactions. All transaction fees are simply borne by the Dapp developers who own the resources in the network.
All the resources available for the users and developers are scarce and it is not possible that one person unnecessarily blocks them. The software for EOS has been designed in such a manner that the account of EOS members who don’t use their tokens for three years gets terminated. Thus, developers can own the resources needed to develop Dapps and launch them on the EOS blockchain.
Governance and EOS’s Smart Contracts
The DPoS consensus mechanism on EOS ensures that the token holders decide which nodes represent the supernodes. Anyone who owns an EOS token can operate the network and decide who the supernode will be, depending on the tokens staked by them with respect to others’ stake. Voters can also use this power to oust corrupt block producers and make changes to the software’s rules.
The supernodes who have the right to validate and include the transactions on the blocks have a lot of advantage on the platform. They even have the capacity to freeze accounts of users. This can be done by simply proposing a change on the network and getting it approved by a minimum of ⅔ of the supernodes. Once that is approved, it must be maintained for the next 30 days. Full nodes are given a week to adapt to the new changes. Nodes that do not follow the new protocol are automatically shut down.
This method brings a lot of criticism to the existing consensus mechanism of EOS. Due to the delegation of power to a small number of nodes, it is possible that the group of supernodes becomes centralized.
Cardano’s Smart Contracts
The idea of Cardano emerged in 2014 when Charles Hoskinson, one of the co-founders of Ethereum, started working on finding a middle ground between the need for regulation and the decentralization principle of blockchain technology. While Ethereum did a commendable job of running as an open-source platform for the development and running of decentralized applications (Dapps), Hoskinson believed that there was a need for a more standardized and scalable blockchain. Hoskinson along with his former co-worker, Jeremy Wood, began their journey into developing the smart contract platform of Cardano.
There are many reasons behind the development of Cardano. Some of the principles that have directly been taken from Cardano’s website are –
- Separation of accounting and computation into different layers
- Implementation of core components in highly modular functional code
- Small groups of academics and developers competing with peer reviewed research
- Heavy use of interdisciplinary teams including early use of InfoSec experts
- Fast iteration between white papers, implementation and new research required to correct issues discovered during review
- Building in the ability to upgrade post-deployed systems without destroying the network
- Development of a decentralized funding mechanism for future work
- A long-term view on improving the design of cryptocurrencies so they can work on mobile devices with a reasonable and secure user experience
- Bringing stakeholders closer to the operations and maintenance of their cryptocurrency
- Acknowledging the need to account for multiple assets in the same ledger
- Abstracting transactions to include optional metadata in order to better conform to the needs of legacy systems
- Learning from the nearly 1,000 altcoins by embracing features that make sense
- Adopt a standards-driven process inspired by the Internet Engineering Task Force using a dedicated foundation to lock down the final protocol design
- Explore the social elements of commerce
- Find a healthy middle ground for regulators to interact with commerce without compromising some core principles inherited from Bitcoin.
Ouroboros is the first peer-reviewed secure blockchain protocol used by computers running the Cardano software to keep the network secure, validate transactions and get new ADA while guaranteeing everything at a fraction of the energy consumed in the Proof of Work (PoW) mechanism. The consensus algorithm uses cryptography, game theory and combinatorics combined with behavioral psychology and economic philosophy to ensure the integrity of the protocol.
One of the most significant features of this mechanism is the security that it offers. The protocol is supposed to be secured as long as 51% of ADAs are held by honest participants of the network. Moreover, the protocol keeps evolving with new iterations and rigorous security analysis.
As in the case of any other network, Ouroboros too incentivises network participants to remain a part of the network by allowing them to either operate a stake pool or delegate a stake in an ADA pool. All the stakeholders in the network are rewarded for their participation in the network.
Ouroboros processes transaction blocks in the network by dividing physical time into epochs which are further divided into time slots. There is a slot every 20 seconds and each epoch contains 21600 slots. But there are multiple epochs that can run parallely on Cardano’s blockchain. As the number of epochs increase, so does the number of transactions per second. This helps in the scalability issue of Cardano.
Continuing with time slots, each slot gets its own slot leader who is randomly assigned by the protocol. Once the slot leader has been assigned, the protocol acts similar to how a PoW protocol works i.e. the slot leader can now choose the block and earn rewards. If the slot leader misses their chance of choosing the block, they will have to wait again till the protocol randomly chooses them later. While it is okay for some slots to remain empty, i.e. no blocks chosen, at least 50 percent or more blocks must be produced within a given epoch.
The slot leaders themselves are elected among the Cardano (ADA) stakeholders by the ones who were picked previously. But how does this ensure randomness? Each stakeholder in Cardano’s network performs an action named ”a coin tossing” through a protocol and they consequently share their results with the group of electors. The stakeholder getting a certain number, which has been predefined, is named the slot leader. This election is also divided into three phases namely the commitment phase, the reveal phase and the recovery phase.
The commitment phase involves an elector generating a random value to form a commitment which contains the proof of secret and the encrypted shares. The commitment is kept secret and signed using the elector’s private key and labeled by attaching the epoch number and the elector’s public key. Using the public key helps to identify who has made the commitment and attaching the epoch number helps to check which epoch the commitment belongs to. The electors then send their commitments to other electors. Eventually, each elector collects the other elector’s commitments that get put into the block that becomes a part of the blockchain.
As the commitments still hold a secret value, a reveal phase then consists in using a key-like value called an opening to unlock them. Each elector adds their opening to the chain. This is followed by a recovery phase, which happens once the electors have both the commitments and the openings in their hands. In the event of an elector releasing their commitment without a corresponding opening, the secret value it holds will be reconstructed by the honest electors. This is possible because of Ouroboros’ Byzantine Fault Tolerance protocol that allows the honest electors to post all the encrypted shares and construct the secrets from them. By revealing the secret values the commitments hold, the electors then generate a seed which is a byte string. All the electors now possess this seed. This seed constitutes the random element for the selection of the next epoch’s slot leaders.
Slot leaders are now elected using Follow the Satoshi (FTS) algorithm. This algorithm selects a random coin from the stake and the owner of that coin becomes the slot leader. This is why owning a greater stake in the pool increases your chances of winning the lottery and the reward. The slot leaders not only choose the blocks in the main blockchain but also in other blockchains inside the Cardano ecosystem as well. Once the epoch has ended, the previous slot leaders elect the slot leaders of the next epoch.
Smart Contracts on Cardano
The division of Cardano’s network into two layers has been done to increase the efficiency, scalability and flexibility of the network. The Cardano Settlement Layer (CSL) acts as the ledger of account or balance ledger. This is an idea created as an improvement of Bitcoin blockchain. It uses a PoS consensus algorithm to generate new blocks and confirm transactions.
The Cardano Computational Layer (CCL) on the other hand contains the smart contract logic that developers can leverage to programmatically move funds. This layer comprises the Plutus, the Marlowe and the Marlowe playground that help users of the CCL to create customized rules when evaluating transactions.
The Plutus is a purpose-built smart contract development language and execution platform that is based on Haskell. Marlowe allows finance and business experts to create smart contracts without having any technical knowledge. Marlowe is a high-level, domain-specific language (DSL) for financial contracts which is built on Plutus. Lastly, Marlowe Playground is an application building platform that people from non technical backgrounds can use along with Marlowe to create financial smart contracts.
While C++, Java and even Solidity are imperative programming languages, meaning all the steps need to be written to explain the computer about the flow of order, using functional languages like Haskell to code the ecosystem and Plutus for the smart contracts helps in building high assurance codes on the network. Using functional programming languages in place of imperative programming languages is therefore a better option and that has helped in the development of this third generation blockchain.
Token holders on Cardano’s network are entitled to vote on proposals to develop or upgrade the blockchain and ecosystem. Voting for Funding Proposals or FP are submitted by members of the community through a dedicated voting app. Once these proposals are submitted, ADA holders then vote for them. Each vote requires a temporary deposit of ADA, to ensure the votes made are considered. The most successful proposals will receive funds from the treasury, in accordance with the amount specified within the proposal. Cardano Improvement Proposals or CIPs are structured proposals that are publicly visible and voting for them is done through the CIP GitHub repository.
Other Smart Contract Platforms
While Ethereum, EOS and Cardano are one of the most popular smart contract platforms, there are many other platforms that provide smart contracts development features. Given below is a brief description of some of them –
Hyperledger is not a software but a framework that is administered by the Linux Foundation and which began in December 2015. It is co-developed by IBM and is a private or permissioned blockchain infrastructure that facilitates the execution of smart contracts or chain nodes. It is open source and free-to-use that supports the development of blockchain based distributed ledgers.
Permissioned blockchains require authentication and permission to participate unlike other blockchain platforms like Ethereum or Cardano where anyone can join and become a part of the community. Hyperledger Fabric is usually used by companies to maintain confidentiality between parties. They do not believe in global transparency as such.
Stellar is a payment network that was developed by Jed McCaleb who also founded Ripple and Mt. Gox. It was founded in 2014 when it forked from the Ripple protocol, which makes it the oldest smart contract platform. The goal of Stellar is to create an open source, decentralized protocol for digital currency to fiat currency in any country. It aims to be recognised as a platform that connects banks and payments systems to people.
Unlike Ethereum, Stellar Smart Contracts (SSC) are not Turing complete. This means that its platform can only be used to make simple smart contracts and for basic applications only. It is not meant for more sophisticated contracts. As hailed by many investors and blockchain enthusiasts, Stellar is one of the most cost effective, time saving and simple solutions for anyone who wishes to participate in the payment process. IBM announced World Wire, a global payment system that is built on the Stellar network. Stellar therefore outperforms other smart contract platforms when it comes to the execution of simple smart contracts.
Formerly known as Antshares and often recognised as the “Ethereum of China”, Neo offers opportunities to build decentralized applications and smart contracts while also allowing the hosting of tokens for ICOs.
It has two tokens called NEO, which is the main token on the platform, and GAS, an automatic creation that comes about when NEO is held in a wallet which is officially approved.
Nem was launched on March 31, 2015 and is favoured by many developers because it is written in Java. Since it has been written in Java, programmers do not have to learn any other language like Solidity to develop smart contracts. Java is also superior to Solidity in terms of security issues. It has lesser security vulnerabilities than the newer platform specific languages like Solidity. Another amazing feature of Nem is its scalability and excellence in performance.
Where Ethereum can manage around 15-20 transactions per second (TPS), Nem is able to manage hundreds of transactions. It is for this reason that developers are increasingly jumping ship from other platforms like Ethereum.
Some of the major disadvantages of this platform is that the development community of Nem is very small as compared to other blockchain platforms used for development of smart contracts. Nem also gives access to lesser tools and uses code off the blockchain which makes it more decentralized.
Lastly, we have Qtum which uses a UTXO based model with more than one virtual machine to develop and execute smart contracts on its platform. Read our step by step guide on QTUM to learn everything about it.
0 commentsWrite a comment