ALGORAND SMART-CONTRACTS

Algorand is a fully decentralized, secure, and scalable blockchain that provides a common platform for building products and services for a borderless economy.


The Algorand blockchain provides built-in protection against inadvertently creating or discarding tokens, along with direct support for optionally freezing, clawing back, minting, and burning tokens.

Smart contracts make blockchains programmable. A smart contract establishes a clearly defined procedure for transferring assets. Smart contracts permit trusted transactions and agreements to be carried out among disparate, anonymous parties without the need for a trusted third party.

Algorand’s smart contracts are more scalable and secured.


For example, user A wants to buy tokens issued by user B, so she sends coins to user A’s smart contract. The contract’s code counts the coins, perhaps checks that user A is in the contract’s database of qualified investors, and then transfers the correct number of tokens to user A’s account. The exchange is transparent: user A can inspect the contract’s code, and the code runs without user B’s participation. With this, users can write contracts that may be big, computationally demanding, idiosyncratic, and/or complex without clogging up the blockchain for everyone else.

Algorand’s smart contract architecture includes several kinds of tools because Algorand’s users need to solve several kinds of problems.

Algorand’s smart contract architecture is flexible, and in the future may enable multiple contract execution committees, each with a different service level guarantee, and each with its own contract language and virtual machine.

Smart Contract Two-Tier Architecture


First, Algorand provides (Layer-) on-chain smart contracts, a secure fast-path for common, everyday transactions.


Second, Algorand provides (Layer-2) off-chain smart contracts for the “long tail” of smart contracts that require more customization.

  • Algorand’s Layer-1 (on-chain) Smart Contracts

Algorand Layer-1 smart contracts execute many common, simple transactions directly in the blockchain itself. Algorand Layer-1 smart contracts make atomic swap transaction almost trivial. Layer-1 contracts provide atomic transfers: a built-in mechanism that ensures that multiple transactions authorized by mutually suspicious parties are executed as a single atomic unit: either all succeed, or none do. For example, user A creates an atomic transfer containing both her payment to user B and user B’s payment to her. User A signs their payment, user B signs theirs, and the doubly-signed atomic transfer containing both payments is then sent to the blockchain.

The Algorand smart contract architecture, provides built-in support for user-defined Algorand Standard Assets, at the same level as Algorand’s native Algo currency. Algorand Layer-1 contracts also provide direct support for common kinds of “post-and-sale” transactions, securitized loans, crowdfunding, accredited-only transactions, multi-sig wallets, and other simple, recurring transaction types.

  • Features:

Layer-1 smart contracts are written in TEAL, an assembly-like stack machine language. TEAL provides programmers the expressive power to implement various kinds of common transactions.


Upcoming upgrade to TEAL which will be released later in future will allow programs to store states in Layer-1, and inspect account balances and other blockchain states for even more expressive power. TEAL will also provide enhanced security guarantees for off-chain contracts. Simply put, it provides a powerful base for the off-chain contracts.

  • Algorand’s Layer-2 (off-chain) contracts

Off-chain contract code is written in a high-level language and is executed by a virtual machine (VM). An off-chain contract has its own long-lived state, called contract storage. For privacy, the contract storage itself does not appear on the blockchain. For security, however, each contract call publishes a commitment to the latest contract storage.

Off-chain contracts can read account balances and other on-chain information, and they can issue transactions, such as payments, that modify the blockchain state.

Although there’s a wide range of simple blockchain transactions that are appropriate for the Layer-1 fast path, but there is also a lot of applications that require more specialized tools. Which are:

  • A contract may be too big.

For example, a contract managing a private stock placement may need to consult a database of certified investors who are allowed to participate, perhaps along with a database of blacklisted investors who are not. These databases may be too big to keep on the chain, or too sensitive to make public.

  • A contract may be too computationally demanding.

For example, a contract managing a token that provides a high degree of privacy may require computationally intensive libraries such as ZK-STARKs, ZK-SNARKs, and so on. In the same light, a complex contract that handles valuable assets may make liberal use of assertions checking the integrity of its data structures. Such long computations may obstruct progress by other clients, slowing everyone’s block rate.

  • A contract may be too complex.

TEAL is a powerful and secure tool for programming simple Layer-1 transactions, but more complex applications require a higher-level language. Good software engineering practice often requires splitting an application into multiple contracts, sometimes provided by different parties. Algorand off-chain contracts are flexible, general-purpose programs.

  • Disparities between On-Chain and Off-Chain Contracts

When a user calls an off-chain contract, the call is not directly executed by the consensus committee. Instead, the call is executed and validated by a parallel committee, called the contract execution committee (chosen by Algorand’s secure, randomized, self-selection algorithm, just like the main consensus committee). It should be noted that Algorand’s smart contract architecture isolates off-chain contract execution from the blockchain consensus committee.


Consensus committee validators never execute user-defined contract code, as in an on-chain contract architecture. Instead, consensus committee validators need only check the certificate and the validation conditions before applying the transaction’s effects.


A blockchain that requires on-chain contracts is like a bank that requires all financial transactions to be carried out by cashier’s check. Before spending money, a customer must wait in line, along with all the other customers, at a bank office with only one teller, to escrow the amount of the check.


While a blockchain that uses off-chain contracts is like using a regular checking account: customers write their own checks without queuing at the bank, and funds are transferred later when the check clears

COMPARISON WITH ETHEREUM’S SMART CONTRACTS

  • Programming an atomic swap using Ethereum’s smart contracts requires a hashed timelock contract (or something similar) – a delicate, timed, multi-phase protocol, where any programming error can be disastrous.

By contrast, Algorand Layer-1 smart contracts provide a simple and safe solution to atomic swaps and related problems.

  • In Ethereum smart contract, execution blocks the progress of the blockchain as a whole.

What’s worse is that every miner must re-execute every contract call, and every new miner must re-execute every contract call that ever happened. Ethereum’s architecture is a scalability hazard, severely limiting the rate at which new blocks can be produced.


Algorand’s off-chain contracts are structured more like a supermarket, where customers make their own selections without asking a shopkeeper, and once a customer has decided what to buy, she queues up briefly at the register to pay. An indecisive shopper hesitating between different kinds of commodities will not delay other shoppers, and will not limit the rate at which customers can be serviced.


Ethereum’s smart contracts provide built-in support for its own Ether currency, but clients who wish to create their own currency-like token are left to their own devices.

CONCLUSION

Due to its unique security, scalability, and decentralization, a block in the Algorand protocol is produced in less than 5 seconds, and all transactions are immediately final. These unique features have led many especially those in the community to experiment with the technology in different ways.

The blockchain sure enables all organizations and individuals to transact with efficiency, security, and transparency.

Author: Adesina Oluwasanmi Algorand Ambassador

To know more, visit: Website || Telegram || Medium || Twitter || Facebook || LinkedIn || Reddit