Let’s chat about (not so) smart contracts. A key theme we’ve analyzed is that the original internet was optimized for communication between machines as opposed to people. Web3 changes that. Smart contracts are part of the “how” that enables this change: they change how we can transact on the internet without the friction of an intermediary.
This is a two-part article. Part one analyzes what a smart contract is and why it matters for enabling the future of the internet. Secondly, the article looks deeper at the early use cases for smart contracts today, ranging from decentralized finance to tokenizing real-world assets.
Part II of this article, to be published later this week, evaluates features of smart contracts, namely immutability, and reports a mechanism to work around editing and amending contracts. Lastly, the article lists some of the most common vulnerabilities of smart contracts across the “deployment stack.” There’s also a fun appendix that outlines the smart contract lifecycle and how it is compiled into the Ethereum running environment.
With that, let’s ride.
What are smart contracts, and why do they matter?
A smart contract is a coded agreement stored and executed on a blockchain. These agreements are the backbone to Web3 enabling a native settlement layer on the internet. To show why this matters, let’s revisit a previous example:
eBay, in the early 2000s, had an incredible marketplace coordination problem. Before Paypal, eBay would pass along coordination of goods exchange to the buyer and seller:
After a successful auction, the buyer had to mail a check to a buyer physically, and the seller would then have to trust that a check would clear. The buyer would then have to trust the seller’s reputation to ship the product described in the listing.
Described succinctly, conducting commerce of any type on the internet incurred friction. Unknown actors had to solve the coordination problem themselves, as Web 1.0 companies could only facilitate the match up to the point.
To create a hack for this coordination problem, Web 2.0 intermediaries presented themselves as trusted third parties to help facilitate transactions and reduce friction. Now, users didn’t have to place trust in the other party, so long as they trusted Visa or PayPal to manage the reputations of their user base. It doesn’t take too much effort to conclude that many of the agreements we reach over the internet can’t be met with an intermediary.
The need for trusted intermediaries paved the way for smart contracts - they address the “how” portion of achieving a settlement layer on the Internet. Smart contracts are used to formalize and execute agreements between unknown participants through code, as opposed to through an intermediary (like PayPal in the previous example). In using code, these smart contracts reduce the cost (and in the future, friction) of enforcing an agreement between two parties.
So, how does a smart contract work? A smart contract is like a coin laundry machine. The rules of what can be done with the laundry machine are pre-programmed in code and executed by the machine. A user selects the wash options offered by the laundry machine, and the machine, in turn, requests payment via coins. Once payment is made by the user, the machine is programmed to run the options selected by the user. If a user does not input enough money, the machine wouldn’t run the selected option, and the user would be able to receive their coins back. Coin laundry provides continuous availability of its service to users without the requirement of an operator or middleman to broker and settle the service.
Using this simple example as a starting point, we can expand smart contracts further.
A smart contract is a self-enforcing agreement formalized as code through a set of conditional if-then statements between two or more parties. The code reflects a set of rules that all parties must agree with to interact with one another. Since smart contracts are public and stored on the blockchain, anyone can view the business logic coded within. When the rules or conditions are met, as in the case of inputting an adequate amount of money in the laundry machine, the agreement is automatically executed. The “state” change (i.e. clothes being washed, and a lower coin balance for the washer) resulting from the smart contract is then recorded on the blockchain.
Smart contracts stored on the blockchain allow for some unique features: they are immutable (changeless), irrevocable, and executable. However, given that smart contracts can’t be changed, there are vulnerabilities from errors or edge cases that smart contract developers may not foresee or hedge. We get into ways around this, as well as some vulnerabilities that smart contracts inherit.
High Level Applications
Smart contracts have far-reaching applications. Use cases range across industries and sectors, which is why input from a broad range of domain experts and participants is required to bring these contracts more mainstream. Some areas of potential application:
• Fine Art
Final Thoughts on Smart Contract Basics
To summarize, a smart contract, executed by two parties, works as follows:
Reach an agreement
Formalize the agreement via code
Enforce the agreement via blockchain
From this breakdown, a smart contract can code legal obligations into an automated process. Returning to our original example, a decentralized eBay would allow both a seller and a buyer to execute the same transaction through a smart contract, placing funds in escrow until there is satisfaction and verification of delivery from the buyer. An intermediary wouldn’t be required to facilitate and ensure adherence to an agreement, thereby reducing the value extraction inherent in such a model.
When programmed with prudence, a smart contract can encode transactions in a manner superior to traditional contract law, allowing for reduced coordination and enforcement.
As we’ve already discussed, smart contracts carry out a set of conditional instructions written in code and executed through a blockchain. What can these instructions facilitate?
Decentralized Autonomous Organizations (DAOs)
One area in which we’ve seen the application of smart contracts is through Decentralized Autonomous Organizations (DAOs), popularized in mainstream media during The Constitution DAO. These organizations wouldn’t exist without the smart contract’s ability to code for business logic. DAOs leverage smart contracts to formalize the governance of an organization through self-enforcing code. DAOs enable multiple individuals across geographies, ages, skill sets, education levels, and otherwise to come together and work towards a common goal or vision for the future – some even anonymously. In pursuing that goal, the ability to standardize operations, voting, and decision-making through smart contracts has created a novel mechanism for human organization and achievement. A deep dive into DAOs will be a topic of a forthcoming post.
Decentralized Finance (DeFi), as a sector, could not have emerged if not for smart contracts. Building upon the ethos of Web3, DeFi embodies the same features, it is trustless, permissionless, and transparent. Anyone can see the transactions made on an open blockchain, and anyone can review and read the smart contracts that individuals in a network interact with.
DeFi largely parallels the traditional finance sector in both function and products offered. Whether relating to lending, borrowing, trading, or investing, smart contracts have provided a mechanism by which all of this can take place in the absence of a centralized intermediary such as a bank. Thanks to smart contracts, DeFi transactions can be achieved with reduced costs, higher latency, near-instant settlement, and constant availability.
While easy for critics to claim that DeFi is just a skeuomorphic representation of its traditional finance counterparts, it ignores the reality of banking in developing countries. Banking services in these regions tend to be reserved for those with education, wealth, or connections. Alternatively, DeFi provides a similar, though not perfect, substitute for anyone, regardless of age, wealth level, education level, gender, or race to access financial markets with merely a Web3 wallet.
One such application of smart contracts in decentralized finance is AAVE. This decentralized application provides for the borrowing and lending of assets in an open-source protocol. Users can borrow collateral for a transparent APR or lend out their assets for a transparent APY. These assets are typically ETH (the token asset of Ethereum) or other blue-chip token assets. While parallel traditional finance services would require a credit score and other safeguards, AAVE simply leverages the ETH a user pledges. If the value of the collateral falls, an AAVE smart contract has pre-conditioned instructions to liquidate any collateral position that falls below the 85% collateral limit. This counterparty risk is buoyed through oracles, which provide a decentralized, trusted mechanism for determining the market price of pledged collateral.
Crypto and Gaming have a storied history. Back when Bitcoin was of limited popularity, players from Magic the Gathering would use the Mt. Gox exchange to transact their cards using Bitcoin as a medium of exchange. It didn’t take long for them to exchange Bitcoin directly through this marketplace.
The extension of smart contracts to Web3 gaming is less difficult to wrap one’s head around - there was already some adoption through various gaming niches. Now, however, it’s not just about players exchanging BTC amongst each other but rather enabling individuals to own and trade digital assets coded for via smart contracts. To understand why this is significant, we must understand the lack of interoperability and asset ownership offered by gaming companies prior to smart contracts.
Traditionally, gaming companies supply their own proprietary marketplaces for digital goods. Whether it be a shield power-up, avatar skin, or unique map unlocked through experience points, those characteristics were always owned by the issuer, never the buyer. Buyers are beholden to the policies surrounding ownership and interoperability set by the developer and, in most cases, are powerless. If they lost access to an account or were banned, there was no recourse given the lack of property rights embedded in those digital goods.
Smart contracts enable digital asset value accrual to be expanded more broadly for both game developers and players. The mechanism that allows this value expansion is driven by non-fungible tokens (NFTs). NFTs deserve their own separate post, but given that they are enabled by smart contracts, we will touch upon them briefly. NFTs are unique, rare, and indivisible (unlike a JPEG that can be copied and pasted, any NFT secures provable scarcity, interoperability, and immutability, thanks to the smart contract that enables them).
Now, as an application to the gaming industry, these smart contracts can allow an individual to purchase or earn in-game digital assets, sell them on any marketplace, or port them over to different games (e.g., a Fornite skin could be used in Call of Duty: Warzone, assuming interoperability was encoded in the NFT). The benefits accrue to the end user, as opposed solely to the developer, creating a more equitable outcome. That is not to say developers would not still have a hand in the marketplace - the smart contracts for the NFTs can include code to allow developers to take a cut of any secondary sales. Some games that broadened the usage of digital assets as smart contracts include Axie Infinity and Splinterlands.
The Tokenization of Real World Assets
Another use case of smart contracts lies in the tokenization of real-world assets. Anything that has some sort of utility can be tokenized. Accordingly, there are two types of tokens, fungible and non-fungible.
Fungible tokens are both interchangeable and divisible. In the case of the U.S. Dollar, one dollar equals one dollar, and separately, 100 pennies equal one dollar. There is versatility in how it is exchanged and valued.
Non-Fungible tokens in the context of asset tokenization have three features: (a) non-interchangeable, (b) non-divisible, and (c) unique. An example could be the fractional ownership of a home tokenized on a distributed ledger: different ownership percentages can be represented by unique fractional NFTs.
Given the abovementioned features, tokenization can range across assets and use cases. As such, they allow for some unique features:
Higher liquidity through fractionalized ownership
Near-zero transaction fees, as middlemen/brokers are replaced with smart contracts
Transparency and provability of ownership through a public blockchain ledger
The main benefits of tokenization range from higher levels of liquidity and reduced coordination costs. An individual could tokenize their home equity value both on-chain (so it can be represented on a distributed ledger) and off-chain (so that the liens to the home are recorded in county offices and other required government institutions) such that they could tap into their home equity while still preserving the asset as their livable space. Soon, such a practice could be more efficient and cost-effective than a traditional bank offering. Given that many of the steps in making this possible can be automated, the need for lawyers, brokers, and bankers to facilitate this transaction wanes, reducing friction and facilitation costs.
Smart contracts will require contributions from everyone, as each domain and industry will have its own use cases and requirements. While Web3 as a whole will make the internet more human-driven as opposed to machine-driven, smart contracts will be one of the first tools to showcase how powerful this paradigm shift will be, allowing exchange between people over the internet absent action rent-seeking intermediaries.
Special thanks to Zoe Enright and Sam Wheeler for their help on this post.
“Aave and Flash Loans.” Gemini, https://www.gemini.com/cryptopedia/aave-flashloans. Accessed 25 Sept. 2022.
Konstantopoulos, Georgios. “How to Secure Your Smart Contracts: 6 Solidity Vulnerabilities and How to Avoid Them (Part 1).” Loom Network, 6 Feb. 2020, https://medium.com/loom-network/how-to-secure-your-smart-contracts-6-solidity-vulnerabilities-and-how-to-avoid-them-part-1-c33048d4d17d.
“Learn Hub.” Ethereum.Org, https://ethereum.org. Accessed 25 Sept. 2022.
Lipton, Alex, and Stuart Levi. “An Introduction to Smart Contracts and Their Potential and Inherent Limitations.” The Harvard Law School Forum on Corporate Governance, 26 May 2018, https://corpgov.law.harvard.edu/2018/05/26/an-introduction-to-smart-contracts-and-their-potential-and-inherent-limitations/.
Monolith. “TKN and Short Address Attack Mitigation:” Monolith, 31 Oct. 2018, https://medium.com/monolith/tkn-and-short-address-attack-mitigation-88cc895734ba.
“Real World Examples of Smart Contracts.” Gemini, https://www.gemini.com/cryptopedia/smart-contract-examples-smart-contract-use-cases. Accessed 25 Sept. 2022.
Smart Contracts 101 - What to Know & Where to Start - Wharton | Wharton - Economics of Blockchain and Digital Assets. https://www.web3.wharton.upenn.edu/blog/smart-contracts-101-what-to-know-where-to-start-wharton. Accessed 25 Sept. 2022.
Valaitis, Alex. “A Deep Dive on Chainlink.” Web3 Pills by Alex Valaitis, 28 July 2022, https://web3pills.substack.com/p/a-deep-dive-on-chainlink.
Voshmgir, Shermin. Token Economy: How Blockchains and Smart Contracts Revolutionize the Economy. 1st edition, 2nd amended printing, BlockchainHub, 2019.
Zhou, Haozhe, et al. “The State of Ethereum Smart Contracts Security: Vulnerabilities, Countermeasures, and Tool Support.” Journal of Cybersecurity and Privacy, vol. 2, no. 2, May 2022, pp. 358–78. DOI.org (Crossref), https://doi.org/10.3390/jcp2020019.