Upgradeable Smart Contract

Kritsada Dechawattana
Valix Consulting
Published in
4 min readOct 31, 2023

When a smart contract is immutable why could be upgradeable?

Back to the traditional program, most programs or software are never final products, they need to update new features in order to outpace their competitors, or they need to update to fix the surprising bugs that may emerge even after rigorous testing.

In the modern software development process, upgrading the program is easy, almost editing the code and then only pushing the code to GitHub and waiting for the CI/CD to serve the new version to users.

We can upgrade traditional program any time when we want

Smart Contract

When we are new to the Ethereum or EVM-compatible chains, It is known that smart contracts are trustworthy. Every functionality is represented with the smart contract code, no one can lie to us except the code. Most importantly, smart contracts are, in theory, “Immutable”, once they are deployed, they become a permanent ledger and cannot be changed. This immutability enhances the security and dependability of smart contracts.

However, why do we keep hearing about many decentralized applications getting updates to fix bugs or even add new interesting features?

The answer is in practice, currently, we can change smart contract behaviors in two solutions:

  1. Proxy Pattern: The developer can upgrade contract logic post-deployment without changing the deployed contract code
  2. Metamorphosis Smart Contracts: Using SELFDESTRUCT along with the CREATE2 opcodes to destroy the deployed contract and re-deploy the new contract code

Therefore, we are able to change the contract behavior, and the smart contract that can be changed behavior is called an “Upgradeable Smart Contract”.

Important Note: In the future, the second solution may not work, the SELFDESTRUC is deprecated and the compiler will warn about its use, both in Solidity and in Yul, including inline assembly.

The question is when the smart contract can be upgraded, it still be trustworthy?

Being placing assets in any decentralized application, we accept the contract’s rules. If there are any changes. It means that we accept the new contract’s rules implicitly.

The upgradeable smart contract has an advantage and disadvantages, It may cause users to be unsure of the contract, developer could upgrade the code to update the rule making it unfair to the users. On the other side, it provides flexibility that allows for continuous improvement, bug fixes, improving gas efficiency, and the addition of new features.

To enhance the upgrade process further, we have the opportunity to incorporate Timelock and Decentralized Autonomous Organization (DAO) mechanisms. These mechanisms introduce an adjusting delay and reviewing step before accepting the new contract code. This innovative approach empowers the community to collectively determine whether the new contract code should be adopted or rejected in a decentralized manner.

Finally, we can design an upgradeable contract that can remove upgradability, which allows us can continuously improve, bug fixes, and add new features until satisfied, then make it become a final contract code that can no longer be changed.

Actually, smart contract is a program. Just every functionality is represented with the public code. Not even the upgradeable code. We can know contract we are interested in is an “Upgradeable Smart Contract” or not.

Security

The upgradeable smart contract is more complex than the general contract. Both in terms of code and the upgrade process. This complexity may lead to various vulnerabilities and risks such as:

  • Storage Collision Between Version
  • Risk Of Uninitializing Contract

and many more risks we will talk about in the next chapter.

Summary

In this article, we talk about upgradeable smart contracts that leverage blockchain technology by providing flexibility. They allow for continuous improvement, bug fixes, improving gas efficiency, and the addition of new features while maintaining security. This opens up endless possibilities for developers and users, shaping the future of decentralized applications.

In the next chapter, we will talk about the “Proxy pattern” that is popular use in the Smart Contract Upgradeable.

Author Details

Kritsada Dechawattana, Senior Blockchain Security Auditor and Consultant.

About Valix Consulting

Valix Consulting is a blockchain and smart contract security firm offering a wide range of cybersecurity consulting services. Our specialists, combined with technical expertise with industry knowledge, and support staff, strive to deliver consistently superior quality services.

For any business inquiries, please get in touch with us via Twitter, Facebook, or info@valix.io.

--

--