Hi, Habr! I present to your attention the translation of the article "
A Deeper Look at Different Smart Contract Platforms ".
We live in the era of smart contracts. While Bitcoin showed us that a payment system can exist in a decentralized peer-to-peer network, Ethereum opened the second generation blockchain Pandora's box, and people finally saw the true potential of distributed applications (Dapps) and smart contracts.
In this article we will look at one of the new Cardano smart contract platforms and see what makes it different.
Before we do this, let's ask ourselves the question.
What are smart contracts?
Smart contracts are automated contracts. They are self-executed with specific instructions written in a programming language that are executed when certain conditions are met.
What properties of smart contracts will satisfy the conditions of use in distributed registries?
Everything that works on the blockchain should be constant and be able to work on several nodes without compromising the integrity of the system state. As a result, the functionality of a smart contract should be three things:
- Determinacy
- Ability to complete on time
- IsolationFunction # 1: Determinacy
A program is deterministic if it gives the same output to a given input each time. For example If 3 + 1 = 4, then 3 + 1 will always be 4. Therefore, when the program outputs the same set of input data on different computers, the program is called deterministic.
There are various moments when a program can act in a non-deterministic manner:
- call nondeterministic function
- use of non-deterministic data
- dynamic call, since the called function or program is determined only at run time, the call itself is non-deterministic.
Function # 2: Ability to complete on time
In mathematical logic, we have an error called the “problem of stopping”. She argues that there is no way to know if a given program can perform its function for a period of time. In 1936, Alan Turing proved, using Cantor's Diagonal Problem, that there is no way to know if a given program can finish its work on time or not ...
This is obviously a problem with smart contracts, because contracts by definition must be capable of being completed within a given time frame. There are several ways to provide a way to terminate a contract from the outside and to avoid entering into an endless cycle that drains resources:
- Turing incomplete : limited functionality will not allow jumps and / or cycles. Therefore, the smart contract will not be able to enter an infinite loop.
- Step and cost meter : the program can simply track the number of commands executed, and then complete the work after performing a certain count of steps. The other method is the counter. Here contracts are executed with an advance payment. Each instruction requires a certain amount. If the paid fee exceeds the prepaid fee, the contract is terminated.
- Timer : if the execution of the contract does not fit into a certain period, then it is terminated forcibly.
Function # 3: Isolation
In the blockchain, each participant can download a smart contract. However, contracts can, consciously and unconsciously, contain viruses and errors.
If the contract is not isolated, it can disrupt the entire system. Therefore, it is very important that the contract is isolated in order to save the entire ecosystem from any negative consequences. Smart contracts are usually executed using one of two systems:
- Virtual Machines : (Ethereum and Neo)
- Docker : (Fabric)
Let's compare these two and determine what creates the best ecosystem. For simplicity, we are going to compare Ethereum (virtual machine) with Fabric (Docker).
Virtual machines | Docker |
---|
The contracts contain non-deterministic functions and the data is limited to the information contained in the blockchain. At the same time, dynamic calls can be non-deterministic in nature. Available data is deterministic | Because of the design features of Docker, the system depends on the users who create deterministic contracts. Not the best solution |
Ethereum uses a “cost meter” to complete a contract. Each step of the contract is "gas" and as soon as the execution cost exceeds the prepaid amount, the execution is terminated. | Fabric uses a timer. Since takimers from different nodes can be different due to different computing powers, there is a risk of a disruption of the consensus process. |
Good isolation properties | Isolation is determined by the docker-ecosystem (insufficient insulation) |
Thus, virtual machines provide better determinism, completeness and isolation of the environment for smart contracts.
We considered some features of the implementation of smart contracts.
It must be said that smart contracts are becoming an integral part and a necessary component of modern distributed applications.
Here are some blockchain platforms providing smart contracting opportunities:
- Ethereum
- EOS
- Stellar
- Cardano
- Neo
- Hyperledger fabric
- Ripple
- Waves
- Ergo platform
In the following articles we will take a closer look at the mechanisms of smart contracts for some of these platforms.