What is DeFi and why we need it
As the name suggests, Decentralized Finance is a movement that aims to recreate traditional financial and banking services without centralized technologies. It is a natural continuation of Bitcoin’s success. Blockchain, in general, is a trust machine that is able to act the role of a trusted third party. In the traditional world, we trust many third parties like banks that are represented by people. The whole cryptocurrency space strives for handing over trust to distributed machines. To be more precise, to the source codes of distributed protocols and infrastructures, that are maintained by plenty of independent people. The power and influence of individuals are weakened by establishing a collective of validators that automatically execute all valid user operations.
DeFi needs more functionalities than just sending transactions between two addresses. Smart contracts enable us to define a set of rules and conditions and automatically execute them based on real development of expected events. Alice will be willing to send a value to Bob only in case she knows him or is able to force him to fulfill the terms of conditions. If Alice did not know Bob at all and vice versa then it would be difficult to swap one token for another between them. Why? DeFi is naturally a global service without KYC. Both parties might stay in anonymity if they want. Either Alice or Bob would have to send the token as the first one from the pair. It is risky since the second from the pair might not send the token to the counterparty and can keep both of them. A pure transactional decentralized system is not able to establish trust within such a simple scenario.
Only smart contracts can help here. It must be possible to configure conditions in the beginning and then let the network play the role of the third party to which both parties trust. Both parties can independently check the conditions in the beginning before sending tokens. The smart contract will take care of a short-term custody service. If Alice sends the token first, the smart contract will lock it and it will wait for Bob’s token. If Bob sends his token in time then the smart contract will swap tokens and send them to Alice and Bob at the same time. If Bob does not send his token, the smart contract will send the token back to Alice. As you can see, Alice and Bob need a trusted third party since they do not trust each other.
There is a catch, though. Most users will never be capable of checking the source code of smart contracts. Is it a problem? People are not capable of verifying the source code of transactional protocols and their consensus mechanisms. Despite that, they slowly begin to build trust in it. People will similarly trust decentralized applications and services in the near future. It is a question of time.
What decentralized services can we build? Well, if you have a closer look at the example with Alice and Bob then you realize that the smart contract realized a similar service that is expected from a decentralized exchange (DEX). Decentralized exchanges will have more functionalities but they will basically connect supply with demand. The wheel of the economy stands on transactions and the exchange of values. Crypto space definitely needs such services. Without them, we will have to rely on the traditional centralized exchanges. The real business also needs loans and the ability to operate with debt. We could repeat ourselves by saying that building such services is possible only with smart contracts. Parties need to define terms, conditions, and penalties. DeFi often works with collateralized loans. Collateralization is a situation when a borrower pledges an asset as a means for the lender to compensate their capital in the case that the borrower fails to pay off the loan. When the borrower continuously misses payments on the debt over an extended period of time then the ownership of the proportional part of the collateral will be passed to the lender. In traditional finance, the most common types of collateral used to secure a loan include real estate, automobiles, art, jewelry, and securities.
It would be difficult or maybe even impossible to work with debt if we had to rely on volatile assets. Both lenders and borrowers need to carefully evaluate conditions of agreements and have to carefully calculate how much they are able to regularly pay off. The volatility of crypto-assets cannot be an enemy. Thus, it is necessary to work with some form of stability that we can find in the traditional world of finance. It is possible to use special services called Oracles, that are able to provide smart contracts with information from the real world. Thanks to the Oracles, smart contracts are able to work with the real price of fiat currencies and create many forms of stable coins. We covered just the most important parts of DeFi and there are more services and ideas that wait for realization.
Some people often forget why blockchain technology is such a big invention. It is mainly about the ability to intermediate trust between two parties that do not trust each other. The more cases and services we will be able to cover, the more value we will bring to the world. Smart contracts are the natural continuation of the effort and it seems that it is a bigger challenge than we expected. Let’s have a look at what is wrong with DeFi and what we have to improve.
Platform developers and DeFi developers are two separated groups
DeFi services are implemented through smart contracts that are written by DeFi developers. Users usually access DeFi services through decentralized applications (dApps). DeFi developers utilize blockchain networks and their execution engines that represent the basic stones of every smart contract platform. If we have a look at it from the point of trust and reliability then we can simplify it and say that users have to trust DeFi developers and DeFi developers need to rely on a platform. If a platform fails then dApps will be affected and thus also users will hurt. So users basically trust both platforms that are created by platform developers and smart contracts that are created by DeFi developers. Why do we make the distinction between platforms and dApps? Well, the platform can be reliable, stable, and well-prepared for writing good dApps but the quality of dApps always depends on the ability of DeFi developers. In other words, platform developers are responsible only for the quality of the platform. So they are responsible for blockchain, consensus mechanism, and building smart contract languages, necessary tooling, and infrastructure that DeFi developers can use for writing their dApps. The platform team cannot directly influence the quality of dApps that are created by DeFi developers. If DeFi developers write a dApp incorrectly, make a bug, or do not test the contract properly then it is only their failure.
The majority of the current DeFi services are built on Ethereum and we can see two major issues. Firstly, we have seen a lot of smart contract failures that resulted in financial losses. The mistakes have been made mostly by DeFi developers. It should be noted, however, that DeFi developers can make a lot of mistakes due to the inherent issues in a smart contract language. You will see an example below.
Secondly, transaction fees are too high for ordinary users. It is the issue that should be solved by platform developers and DeFi developers cannot do much with that.
How Cardano can improve the writing of smart contracts
Let’s first debate the first issue. Smart contracts written in Solidity are full of security vulnerabilities that have been exploited in many highly publicized attacks. The reason why Solidity is considered unfriendly for writing smart contracts is the fact that the language has been influenced by JavaScript and C++. Unexperienced developers that come from the web or the traditional development of applications are led to draw parallels between Solidity and these languages even where they do not exist. To be able to write secure smart contracts in Solidity, it is essential to have a sound understanding of the underlying Ethereum system and its various subtleties. Let’s have a look at a few problems with Solidity.
One of many Solidity issues is a reentrancy one. Reentrancy occurs when external contract calls are allowed to make new calls to the calling contract before the initial execution is complete. It means that the contract state may change in the middle of its execution as a result of a call to an untrusted contract or the use of a low-level function with an external address. This opens the contract to a number of risks and in some cases, the entire token balance could be drained as happened when the DAO was hacked and 3,6M of ETH has been lost. Integer overflows and underflows are not a new class of vulnerability in the traditional programming world, but they are especially dangerous in smart contracts. This vulnerability allowed attackers to steal huge amounts of ETH. Researchers discovered that at least a dozen ERC-20 tokens were susceptible to the same attack.
It showed up that it is needed to create a language that is significantly easier and more suitable for writing smart contracts. A good language for writing smart contracts should prevent developers from intentionally writing misleading or malicious code and also protects developers from unintendedly leaving vulnerabilities in their contract code. Cardano can bring a new level of quality regarding writing smart contracts. The team has invented the smart contract language Plutus, which has been inspired by the functional language Haskell.
In general, there are two major families of programming languages. These are imperative and functional. Solidity, but also C++ or Java, are examples of imperative programming languages. When a developer wants to write a simple program or smart contract, it is necessary to put down all the steps that the computer needs to take in order to reach an expected goal. This kind of programming approach is also called algorithmic programming. If a developer wants to add two numbers then multiple steps are necessary to achieve the goal. Every step constantly changes the state of the program. Steps are processed individually in the order that the developer determined during the development phase. Let’s have a look at an example:
int numberA = 100;
int numberB = 200;
int result;
result = numberA + numberB;
The developer had to declare 3 variables, assign value to two of them, and have the third variable for storing the result, and make the addition.
Functional programming languages, like Haskell and Plutus, have been created to build a functional approach to solving problems. This kind of programming approach is also called declarative programming. It is a programming paradigm that expresses the logic of a computation (what to do) without a need of describing its control flow (how to do it). Declarative programming tries to blur the distinction between a program as a set of instructions and a program as an assertion about the desired answer.
Computation is treated as the evaluation of mathematical functions and avoids state and mutable data. It emphasizes the application of functions, in contrast to the imperative programming style, which emphasizes changes in state. In a purely functional language, such as Haskell and Plutus, all functions are without side effects, and state changes are only represented as functions that transform the state.
Let’s assume that there is a function f(x) that a developer wants to use to calculate a function g(x). Then he wants to use that to work with a function h(x). Instead of solving all of those in a sequence, it is possible to join all functions together in a single function like this:
h(g(f(x)))
This approach allows developers to consider problems in a mathematical way. Functional programs are supposed to be a more secure approach to smart contract creation. This also aids in simpler Formal Verification which pretty much means that it is easier to mathematically prove what a program does and how it will behave under all possible conditions. This gives Cardano its High Assurance Code property. It is true for the Cardano network and it will be the same for applications that will be written in Plutus.
Solidity was the first language for writing smart contracts and issues could be expected. On the other hand, we can say that the team underestimated the complexity and abilities of developers to use the language in a secure way. Even experienced developers claim that they still have a lot of respect when they write a smart contract in Solidity. It will definitely take some time to learn Plutus but the effort will be rewarded. DeFi needs secure and reliable smart contracts without unexpected side effects or vulnerabilities that can be easily exploited. It is not possible to deploy a smart contract that can be hacked literally within a few days. We have seen such issues and it will not definitely attract more people into the DeFi space. We do not need projects that offer a high-reward for taking a high risk. We need projects that will have sustainable economical or incentive models and mainly, that will be reliable, stable, fast, and user friendly.
How Cardano can improve user experience
High fees are definitely a very unfriendly feature. Moreover, if you paid a little fee when you started to use some DeFi service and then you have to pay a significantly higher fee when you want to move assets elsewhere. At the time of writing the article, a common fee is a few dollars per transaction in the Ethereum network. Some people claimed that they needed to pay a $50 fee to close a position. The fee can be higher than the profit that users have made. Some people are not willing to pay such a high fee and rather let the position open even if they wished to close it. It is not economically smart to pay such high fees in many cases.
Ethereum still runs on PoW and it is not a good consensus mechanism regarding scalability. Every blockchain network has a limit regarding the number of transactions that are able to process in a given time. When the limit is surpassed then some transactions have to wait longer to be processed. Miners select transactions by the size of transaction fees and they prefer higher fees. Users can set transaction fees themselves. When a network is clogged then users have to set a higher fee and hope that their transactions will be processed faster. Older transactions with lower fees can wait in mem-pool for a very long time since newer transactions with higher fees jump over them.
At the time of writing, the average Ethereum block time was 13 seconds and the network was able to process approximately 13 transactions per second. There were more than 150,000 pending transactions in the mem-pool. I have seen transactions waiting for more than 12 days since they have set a low fee. Newer transactions had approximately 80x higher fees. User experience is not good when conditions change so dramatically within a short period of time. When a network processes a transaction cheaply within a few seconds and suddenly it takes days and you need to pay a significantly higher fee then users will be probably very unsatisfied.
It is definitely a good thing that people are interested in cryptocurrencies and DeFi space. High transaction fees and the long time needed to process transactions cannot be an obstacle for newcomers to play with decentralized services. Newcomers will never build trust in decentralized services if user experience will be actually worse than traditional services can offer. Banks used to be and often still are rigid, slow and people have to pay quite big fees. Cryptocurrencies are here not only to provide decentralized services but also to be faster and cheaper.
To overcome these obstacles blockchain networks must resolve the scalability problem. A decentralized network without offering a good user experience, reliability, stability, and security will not make a revolution. People actually do not care much about decentralization and it is not going to change much till decentralized services will be able to offer really competitive financial services. Cardano has the potential to bring these qualities and attract people to decentralized services that will not suffer problems of the first and the second generations of blockchain. The Cardano network is configured to randomly select a slot leader approximately every 20 seconds. It can be faster or it can take more time. When a selected slot leader does not produce a block then the slot might stay empty. It means that transactions can be processed in the next slot. Regarding scalability, Cardano is roughly 20x more scalable than Ethereum. It is an outstanding technological improvement and it will be sufficient for the first years. The issue with high fees will hopefully become part of history. Hydra is the second layer solution for Cardano and once it will be deployed users will love it. Block time could be roughly a second. In contrast to other second-layer solutions, Hydra will be able to process smart contracts and work directly with UTxO of the first layer (actually with the extended version EUTxO). EUTxO will be handed over from the first layer to the second layer during opening channels and then back from the second layer to the first layer during closing channels. It will very probably ensure a high level of security for decentralized services. dApps will be very fast since the execution of smart contracts will also be processed in Hydra. The user experience will be very satisfactory.
Conclusion
The quality of dApps will always depend on the quality of underlying blockchain technology and infrastructure for smart contracts. Network consensus of the first layer directly influences the user experience of smart contract users. Users basically want to use a secure and reliable service without bothering with technical details. Users just want to download applications to their cell phones and use them. They will consider usability, added value, and benefits that applications can offer. Nothing more. Only services that will be reliably and smoothly working a few years can be adopted by masses. The IOG team will deliver an ERC-20 converter that allows redeployment of existing Ethereum ERC-20 tokens on the Cardano network. We will see how many teams will consider the option. It would be beneficial to users and DeFi space.
Source: Cardano can bring stability and reliability to the World of DeFi