What is a smart contract?

In 1997, Nick Szabo published a blog about the idea of smart contracts to embed contractual clauses in software. He envisioned a future where all sorts of valuable property will be controlled by digital means:

"Smart contracts reference that property in a dynamic, proactively enforced form, and provide much better observation and verification where proactive measures must fall short. And where the vending machine, like electronic mail, implements an asynchronous protocol between the vending company and the customer, some smart contracts entail multiple synchronous steps between two or more parties." - Nick Szabo

The name “smart contract” led to a narrative that “lawyers should learn to code”, “smart contracts will end lawyers” and “lawyers will need to work with coders”.

While some lawyers like Dan Robinson did learn to code and contributed greatly to the field of cryptocurrencies, many of us do not believe it is the ideal mental model for understanding what is a smart contracts and why it is useful.

Mental model for smart contracts

A smart contract is a trusted third party with public state
A smart contract is a trusted third party with public state

In the eyes of a protocol designer. A smart contract represents a trusted third party with public state and it is a solution to the co-ordination problem. It is a public bulletin board and it will only store user-generated messages if the message satisfies a set of defined conditions. For example, a vote message is processed and stored by the smart contract if it was authorised by an eligible voter and submitted to the smart contract before the voting period’s deadline.

Put another way, a smart contract allows a set of parties (on a global scale) to interact with each other with the guarantee that all pre-agreed rules of engagement are enforced (protocol). Unlike the legacy system, there is no need to find or hire a third party to run the protocol and there is no longer a need to blindly trust this party to enforce the rules. As a result, smart contracts are essential pipework for replacing human trust with computer programs and empowering parties to “trust”, but verify.

Technical level. A smart contract is a computer program that has exclusive access to a section of the database. It allows a developer to implement programmatic write access to this section of the database. Anyone can read the code, the database state, and pay to invoke the program to update the database. All smart contracts have a unique identifier (address) and it can hold assets. It will only send assets if a set of conditions (implemented by the developer in the code) are satisfied. For example, the assets can only be transferred out of the smart contract if Alice, Bob and Caroline agree.

The execution environment for a smart contract is a finite state machine. The next state of the program is based on its current state, inputs, and the invoked function. All execution must be atomic such that the entire transaction’s execution completes, otherwise it will revert any changes if it stops mid-execution. Users are charged a fee regardless if it is successful or reverts. There is no background execution as smart contracts are event-driven programs and users must pay a fee for it to perform any execution.

Cryptocurrencies are just globally replicated databases, but the value is its credibly neutrality and composability.
Cryptocurrencies are just globally replicated databases, but the value is its credibly neutrality and composability.

Composability and Decentralization. The cornerstone of a smart contract is its autonomous* nature such that no single party can interfere or prevent its eventual execution.

We call this “code is law” as the smart contract code cannot be changed in the future and its execution is only dependent on the code/database. Developers can read the code, check its functionality, and make an informed decision to build a system on top of it (service or smart contract). It is a seamless process as smart contracts can interact and compose with each other.

Unlike the legacy system, developers are not tied to a proprietary stack. Many smart contracts rely on open-standards advocated by the community, there is reduced risk the underlying code will change, and deployed smart contracts can thrive long into the future even if the development company disappears.

The right for anyone to execute a smart contract and “code is law” is protected by the layer-1 platform. This empowerment relies upon decentralization of the network and the platform’s credible neutrality which should be sustained by the financial interests of all involved parties. Ultimately, we all work together to protect the integrity of the system and the independence of smart contracts.

*A smart contract be designed to be upgradable and have built-in admin features.

Potential applications

Tokenisation is the process of representing an asset as a token and assigning ownership to it. There are several type of tokens (and assets) to consider:

  • Commodity. A resource like art, a fungible token, or a sock.
  • Utility. Holder obtains special features in the application.
  • Governance. Holders to vote on the future progression of a project.
  • Security. Buyer can bet on the success of a venture (or team) with expected upside in the future.

Smart contracts simplify the process of representing an asset and creating a secondary market for it. The global nature allows anyone to speculate on the asset’s value by buying or selling it. As a result, many smart contracts represent basic pipework of a financial system including the ability to:

  • Swap assets. A user can swap an asset to another asset.
  • Manage loans. A user can borrow an asset from a smart contract and pay it back later with interest.
  • Fundraise. A user can advertise their venture and anyone can fund it.
  • Gamble in a publicly fair manner. Users out compete each other to win the game and the rules are fixed/known in advance.
  • Define access control. Allowing an owner (or multiple owners) to establish and enforce rules before an asset can be transferred by a smart contract.

The pipework forms the basis for building financial applications on top and many applications from the traditional world of finance can be re-implemented as a smart contract. A good example is PoolTogether. It is a risk-free lottery as users lock up assets, the assets are invested for yield, and every week some lucky folks will win the earned yield. This is just a Premium Bond and it was invented by the UK Government in the 1950s.

At the same time, new financial applications that were unimaginable or possible are starting to emerge. Automated Market Makers are the pinnacle example. It allows a user to exchange assets without an order book and to passively facilitate market making by locking up their assets.

The pace of rapid innovation and usage is only possible because of the platform’s credible neutrality. The participant’s identity or geographical location does not matter. As long as they can pay a fee to execute transactions, then they are welcome to use and help build the DeFi eco-system.

To conclude potential applications, there are also non-financial use-cases to consider and this is a great read for exploring them.

Are smart contracts prominent?

Yes.

We will simply consider the assets held by smart contracts and the network fees paid by users on Ethereum.

A fun research project is to measure the rise of smart contracts for all networks and how it has evolved over the years.

DeFi Market capitalisation. Let’s consider the value in dollar terms on Ethereum’s DeFi eco-system at the start of 2022.

  • Over $110 billion dollars locked in DeFI applications.
  • Over $80 billion dollars issued for stable coins like USDT and USDC.
  • Over $5 billion dollars locked on rollups.

At one point in time, the market capitalisation of assets held on Ethereum alone was greater than the the GDP of sovereign countries including Luxembourg ($73bn), Qatar ($146bn) and Greece ($189bn).

I, alongside others, expect this trend to continue into the future.

Operators have an incentive to leverage smart contracts as basic pipework for their infrastructure. This is because the operator can provide the same service without taking on the risk of holding and protecting their’s users assets. Especially if the value of all held assets grows to exceed billions of dollars.

In this way, DeFi will continue to grow as custody of assets is becoming an unnecessary liability for many operators.

Figure 1: Total fees on Ethereum over 2021.
Figure 1: Total fees on Ethereum over 2021.

Fees paid by users. All user-generated transactions that interact with smart contracts are required to pay a fee for its execution.

Throughout 2021-2022, users paid tens of millions of dollars, every day, to use Ethereum. The data is reliable as it is financially expensive to fake this metric as fees are burnt by the protocol and users are forced to pay it. There is no way to retrieve the fee back after it is burnt thanks to EIP-1559.

This has led to a joke that Ethereum has become a whale chain, but it demonstrates that users are willing to pay extortionate fees to use smart contracts. It has led to the rise of significantly cheaper layer-1 and layer-2 networks which we have explored in another blog post.

Regardless, the fees paid by users to interact with smart contracts highlights real demand for its usage and growing prominence.

How can I get started?

The Cryptocurrency Class focuses on the mental models that you will need to develop in a smart contract environment or build services on top of it. It does not focus on helping you learn how to implement the smart contracts in a specific language.

There are plenty of online resources that do a much better job including:

  • Remix. An online IDE for implementing smart contracts.
  • Crypto zombies. Interactive tutorial for writing smart contracts.
  • Eth-Scaffold. An environment for rapid interaction on smart contracts and front-end development.
  • Foundry. A new Ethereum development toolbox.
  • Nader Debit. Youtube series on Web3 development.

Good luck frens.

Subscribe to Patrick McCorry
Receive the latest updates directly to your inbox.
Verification
This entry has been permanently stored onchain and signed by its creator.