Very few projects have been able to release updates as per the planned timeline, given the immense complexity involved with blockchain technology. But since its inception, Algorand keeps upgrading its capabilities like clockwork. With every upgrade, Algorand is revealing its determination to dominate the DeFi space.
On August 19, 2020, Algorand founder Silvio Micali announced the launch of stateful smart contract technology that is geared towards developing powerful DeFi solutions and other DApps.
What’s this smart contract upgrade all about?
In its quest to achieve speed, scalability, and security, Algorand has taken the route of adding its key features to layer-1 i.e., the consensus layer, presenting the Algorand Smart Contract (ASC-1), Algorand Standard Assets (ASA), and Atomic Swap.
Algorand smart contracts utilize both layer-1 and layer-2 functionality. But by design Algorand’s layer-1 smart contract has two components – stateless smart contract and stateful smart contract. ASC-1 is the stateless version Algorand introduced earlier. Let’s check this out before understanding what the stateful version is all about.
Algorand Smart Contract
Stateless Smart Contract
This is where instructions or conditions to execute a transaction are supplied within the transaction itself. Besides being highly customizable, stateless smart contracts are efficient because instruction is just 1KB long with basic tasks like comparing or verifying digital signatures. A transaction gets approved when all such conditions are met; if a single condition is not met, it gets rejected. Complex independent payments, Atomic swap, collateralized loans, or escrow systems are some use cases for this type.
Stateful Smart Contract
Instead of attaching with a transaction, these conditions/instructions are supplied from outside in a stateful smart contract. A transaction is approved through checking a sequence of interactive conditions saved somewhere else.
Therefore, by nature stateful is not as efficient as stateless but offers high flexibility. Algorand’s objective was simple – extract as much efficiency as possible from its stateless implementation without compromising on speed, scalability, and low fee Algorand boasts about.
Trying Different Approaches
So the question is where to store the state information. There were two clear options –
- Method 1: Storing on the blockchain – Since a long-running application’s blocks are widely spread, recovering them for every transaction will bog down the block generation speed. Additionally, updating state data means continuous overwriting that needs to be simulated due to block finality. This takes a toll on efficiency.
- Method 2: Storing on off-chain – While trying to workaround the first, this method doesn’t offer concurrency for multiple state changes for transactions at all. Also, it lowers speed to a few TPS.
Third Method – The Algorand Approach
The Algorand team decided to store an application’s state information on its creator’s account and its users’ accounts. While the former saves the application’s global state, its local state is stored in the latter collectively. Algorand adopted this method because its architecture allows users to generate and consult accounts very efficiently and still manage to keep costs low.
Advantages
- Concurrency – This enables multiple transactions to concurrently change an application’s internal state data without blocking one another. This sharding an application’s state information presents great concurrency and therefore scalability.
- Efficiency – Though local state data for an account is small, it increases linearly as the more users sign in an application. This allows it to handle complex applications efficiently.
-
- Maintaining speed – To avoid a slow block generation rate, Algorand has restricted the respective state size of creator and sign-in accounts. This way stateful smart contracts can maintain 1,000 TPS at layer-1 amid growing opt-ins.
- Low cost – Instead of paying fees, a participant account should maintain a meager balance (0.05 ALGOs per variable-value pair of local state) to save its local state share. This is refunded through on-chain transactions once users opt-out.
Extending the PyTEAL Functionality
Algorand smart contract is written in a special language called TEAL granting Algorand developers the power to develop complex solutions. To offer the ease and flexibility of a known language, Algorand brought PyTEAL – where developers can develop solutions in Python code and Algorand will compile that in TEAL.
After stateless, developers writing stateful smart contracts will now get the PyTEAL support.
DeFi Use Case Advantages
The upgrade coupled with Algorand’s other layer-1 features offers unique opportunities to DeFi space.
- Advanced security token – The ASA feature allows users to tokenize different fungible and non-fungible assets in an unrestricted or restricted way. A security token is a restricted fungible token use case. With stateful TEAL technology, users can develop security tokens with customizable trade restrictions in place. While the global state dictates the token’s general conditions, each account holds its assigned authorization group state.
- Crowdsourcing – Building a fundraiser with a stateful smart contract will save the fund goals in a global state while local states will store donor conditions. The total fund is saved in a stateless contract. The creator can access funds only if the goal is met, otherwise it will be returned to donors.
- Next-gen trade – Thanks to the atomic swap feature, users can trade directly with another given it meets full criteria i.e. trade item, price, and know identities of buyers/sellers. Stateful contracts act as an order book to facilitate direct trade with zero prior knowledge. A user’s buy/sell order is stored in the local storage of the order book application’s account and executes it only when the condition matches a seller’s conditions.
- Transparent banking – Algorand banking application brings the opportunity to earn extra from stored ALGOs. Once lent, the stateful contract allows it to keep every contribution in the user’s local storage (keeping reserve fund in global account) and pay interests. With proper restrictions, users can freely extract their funds.
Conclusion
Ethereum’s stateful smart contract is a prime reason behind attracting so many different projects. Algorand, without having this feature already bagged multiple top-ranking projects including top-two stablecoins – Tether and USDC, Marshall Islands’ CBDC, IDEX, IBMR.io’s macroeconomic infrastructure, and Republic investing. This brings in an advanced version bound to attract more DeFi projects.
Ethereum is bogging down with so many projects and the Ethereum 2.0 launch continues to get delayed. This creates a unique opportunity for Algorand to divert DeFi projects with its superior speed, scalability, and enterprise-grade features and realizing its DeFi dream.