An Introduction to Smart Contracts
Smart contracts defined
One of the blockchain key tool is smart contract, first coined by cryptographer and legal philosopher Nick Szabo in 1994. He wrote:
“A smart contract is a set of promises, specified in digital form, including protocols within which the parties perform on these promises.”
The classic example of a smart contract offered by Szabo is a vending machine. Once a purchaser has satisfied the conditions of the “contract” (i.e., inserting money into the machine) the machine automatically honors the terms of the unwritten agreement and delivers the snack. He also pointed out that:
“The basic idea of smart contracts is that many kinds of contractual clauses (such as liens, bonding, delineation of property rights, etc.) can be embedded in the hardware and software we deal with, in such a way as to make breach of contract expensive (if desired, sometimes prohibitively so) for the breacher.”
The smart contract idea fits perfectly with the properties of blockchain technology, where contract clauses written in cryptographic building blocks are stored and automatically executed in a distributed ledger when predefined conditions are met, without the intervention of a trusted third party.
What is a Smart Contract?
Using the word of Szabo:
“A smart contract is a computerized transaction protocol that executes the terms of a contract. The general objectives of smart-contract design are to satisfy common contractual conditions (such as payment terms, liens, confidentiality, and even enforcement), minimise exceptions both malicious and accidental, and minimise the need for trusted intermediaries. Related economic goals include lowering fraud loss, arbitration and enforcement costs, and other transaction costs.”
In few words, smart contracts are lines of computer code built upon blockchain technology, digitally mimic all the characteristics of a traditional contract.
Many smart contracts will originate as documents written in natural language that require subsequent translation into executable code. The approved contractual clauses are converted into computer code, recorded as an immutable transaction stored in the blockchain and executed automatically upon the occurrence of certain conditions established prior to the signing of the contract by the parties to the agreement. Therefore, the evaluation of the requirements, the respect of the positions and the status of the contract are not regulated by third parties since this role is covered by the network consensus.
Once a smart contract is deployed on a blockchain, it self self-execute and cannot be modified or aemended due to the immutability of block-chains: any emendation requires the creation of a new contract.
How do smart contracts work?
To clarify the functioning of smart contracts, it is necessary to distinguish all the phases that characterize their birth:
- Agreement - The first step is the signing of the contract and the signing of the clauses that bind the counterparties. Several involved parties first negotiate on the obligations, rights and prohibitions on contracts.
- Development – Software engineers then convert this agreement written in natural languages into a smart contract written in computer languages, including declarative languages and logic-based rule languages.
- Transfer –Once a smart contract has been developed, it can be transferred to an already running blockchain, such as Ethereum, to be recorded and stored in the blockchain. At this point, the contract (identified by a hash code) becomes part of a block that guarantees its maintenance, accessibility and correct updating.
- Verification – The verification and validation of data and information takes place through the Proof of Work (PoW) or Proof of Stake (PoS) blockchain consensus protocols.
- Time-Stamping - After being validated, the block is added to the chain and marked with a time-stamp (or an alphanumeric string called a hash) that chronologically enforce each transaction and prove its existence. Each node, therefore, adds the block to the chain, makes it non-counterfeit. The contract is now public and visible within the platform.
- Execution – Once the contractual conditions reach, the contractual procedures (or functions) will be automatically executed and, consequently, a transaction is executed and validated by miners in the blockchains. Responsibility for verifying the contractual clauses is entrusted to a third party agent, the oracle, data feeds or APIs that connect blockchains to external systems, thereby enabling smart contracts to execute based upon inputs and outputs from the real world.
Main platforms for smart contracts development
Not all blockchains support distinctive features for writing and developing smart contracts (including high-level programming languages, contract code execution, and security levels). Over the years, several platforms that aim to solve different problems through the use of smart contracts have developed:
- Ethereum – It’s the the first and most popular blockchain platform for developing smart contracts and considered the best choice by most of the users. It is a public and non-specialized blockchain that can be used to design various kinds of decentralized applications (DApps) in several domains, is easily programmable and suitable for multiple scenarios. It currently uses a PoW consensus protocol, despite planning a migration to the PoS protocol. It supports advanced and customized smart contracts with the help of a Turing-complete virtual machine, called the Ethereum virtual machine (EVM). EVM is the runtime environment for smart contracts, and every node in the Ethereum network runs an EVM implementation and executes the same instructions. Solidity, as a high-level programming language, is used to write smart contracts, and the contract code is compiled down to EVM bytecode and deployed on the blockchain for execution.
- EOS - This platform is designed to enable the scalability of decentralized applications. Instead of using one type of consensus algorithms only, EOS combines Byzantine Fault Tolerance (BFT) and Delegated Proof of Stake (DPOS), thereby obtaining the advantages of both consensus algorithms. At each round, delegates (i.e., block producers) will be selected by stake holders to produce a new block and BFT will proceed among those selected delegates to make the block irreversible. Similar to Bitcoin, EOS is also account-based but it also allows all accounts to be referenced by human readable names. Instead of customizing a virtual machine for code execution like Ethereum, EOS chooses to use WebAssembly (Wasm) so that it is possible to write a smart contract in various languages as long as it can be compiled into Wasm (e.g., EOS supports C++).
Smart contract applications
Smart contracts are boosting a broad spectrum of applications developed in several implementation domains such as:
- Internet of Things – IoT is one of the most promising technologies can support numerous applications including supply chain management, inventory control systems, retailers, access control, libraries, health care systems, etc.
- Finance – Smart contracts can potentially reduce financial risks, cut down administration and service costs and improve the efficiency of financial services. They can be used to enforcing rules and policies in banking, for example the mortgage service, or to streamline clearing and settlement activities.
- Insurance – Applying smart contracts may decrease overhead claim processing and save time and costs in the insurance sector, especially claim handling. They can also perform error checking, routing, approve workflows, and calculate payouts based on the type of claim and the underlying policy.
- Sharing economy – The sharing economy brings many benefits such as reducing consumer costs by borrowing and recycling items, improving resource usage, enhancing quality of service, lowering the environment impacts. Smart contracts can potentially reshape sharing economy by decentralizing sharing economy platforms.
- Public sector – Smart contracts can be used to prevent data fraudulence and provide the transparency of public information, establish personal digital identity and reputation, automate the bidding process, introduce e-voting systems.
- Supply-Chain – Smart contracts can make supply chains more transparent to smooth out the transfer of goods, monitor ownership rights as products pass through the supply chain at any given moment. They can also automate contractual rights and obligations during the payment and the delivery of goods while all the parties in the whole process are trustful.
- Nick Szabo, Smart Contracts: Building Blocks for Digital Markets, (1996).
- Stuart D. Levi and Alex B. Lipton, An Introduction To Smart Contracts And Their Potential And Inherent Limitations (Harvard Law School Forum on Corporate Governance, 26 May 2018)
- A. Pasdar, Z. Dong, and Y. C. Lee, Blockchain Oracle Design Patterns. Available: https://arxiv.org/pdf/2106.09349.pdf
- AA.VV, What Is a Blockchain Oracle?, Chainlink. Available: https://chain.link/education/blockchain-oracles
- D. Macrinici, C. Cartofeanu, and S. Gao, Smart contractapplications within blockchain technology: a systematicmapping study, Telematics and Informatics, 2018
- Sharma, Pratima, Jindal, Rajni, Borah, Malaya Dutta, A review of smart contract-based platforms, applications, and challenges, Cluster Computing (IF1.809), Pub Date 2022-01-15.
- Shafaq Naheed Khan, Faiza Loukil, Chirine Ghedira-Guegan, Elhadj Benkhelifa & Anoud Bani-Hani, Blockchain smart contracts: Applications, challenges, and future trends, 2021, Available: https://link.springer.com/article/10.1007/s12083-021-01127-0
- Zibin Zheng,Shaoan Xie, Hong-Ning Dai, Weili Chen, Xiangping Chen, Jian Weng, Muhammad Imran, An Overview on Smart Contracts: Challenges, Advances and Platforms, 2019, Available: https://www.henrylab.net/wp-content/uploads/2019/12/SmartContractFGCS__arXiv_.pdf