The One Question bounty closes Thursday 10 December.

Join in
We Them Media logo We Them Media Support us

Web3bridge Students (Cohort XI) Share What They’ve Learned: Upgradeable Smart Contract

The picture loads from YouTube. The player loads only when you press Play. Turn on captions in the player if you need them.

Cohort 11 students explain upgradeable smart contracts. Normally deployed code cannot change, so a bug means a new address. They describe the proxy and implementation pattern, where storage stays in the proxy and logic is reached by delegate call, compare transparent and universal proxies, and mention the Diamond pattern used by some projects.

Not by We Them Media Channel: Web3Bridge. Published Wednesday 1 January 2025.

Titles are the owner’s. It plays from their channel.

Transcript

This transcript may contain errors. This video belongs to Web3Bridge. Letters mark each change of speaker.

These are the speakers’ own words. We have not checked their claims.

0:00 A: This video is proudly brought to you by VirtuBridge with LIX, our official sponsors for Cohort 11.

0:08 B: I know you must have heard that smart contracts are immutable and they cannot be changed, but why are we talking about upgradable smart contracts? Now, what if there was a bug in your smart contract? How do you remediate that? Or say you want to add additional functionalities to the smart contract, how do you modify, how do you remediate that? That is your upgradeable smart contract that comes into play.

0:38 C: Firstly, what is the need for upgradeable smart contracts? So as we know it, smart contracts are fixed. When you deploy a particular smart contract as we know it, you cannot make changes to the code. And if you make changes to the code, you have to redeploy. And redeploying it means you are redeploying the smart contract code to a different address on the blockchain. But now, this is what upgradeable smart contract does. It gives you the ability to write a smart contract and then keep on upgrading the contract code using that same address. Now, how does this work, right? For upgrading smart contracts, it works using the principle of proxy and implementation. So there's usually a proxy which we'll call the mother contract, and then the implementations we will call the children contracts. So in the mother contract, we always have storage. So storage is not in the children contracts, or like I called it, the implementation contract. It is just in the mother contract. But then this implementation contract just imports the storage in the mother contract and then make changes to that storage using what we call delegate call. So now what is delegate call? In very, very brief form, delegate call is simply making, um, a call to another contract to make changes to your own storage. So like the concept I used of mother and child, when the mother makes a delegate call to the child, she's simply saying the child should run some particular function that changes her own storage or her own state. Upgradeable smart contracts make use of the proxy and implementation, the proxy implementation design And then under the hood, it makes use of delegate call to achieve this.

2:43 B: So one thing to note is that when we talk about upgradeable smart contracts, you are not modifying the state or the address of the contract. You're just adding functionality or trying to remediate a bug. So the contract that is deployed, the address is maintained, the balances, all the transactions that have been performed on that contract are still maintained. Or just adding functionalities to it. Now, this upgradable smart contract makes use of something known as the proxy pattern, just like my colleague has said, which consists of, um, the proxy, um, contracts and then the execution contracts, or some also known as the facets, such that the proxy contract holds the address to the execution contract and uses the logic in the execution contract to update its own state. Now, there are types of, um, upgradable smart contracts. We have the, um, transparent proxy, which is also known as the simple proxy, which uses delegate call to call the facets or the execution contracts. And that's why that is preferred. It has its own drawback. And also, there is another type known as the universal proxy. Um, universal proxy which is another type of upgradable smart contracts. One thing to note is that in this case, the proxy is the one calling- the user calls the proxy, which calls the facet or the execution logic, which holds the logic that is to be used to either make upgrades, make changes to the contracts, or even remediate a bug.

4:20 C: Companies like Aavegotchi, companies like Composable Finance use Diamond smart contracts to enhance their applications, right? They have this- they use-

4:31 D: they make use of Diamond smart contracts to make their contracts upgradable, right, and modular, to save gas costs, to always update their contracts, to add or to replace or to remove facets, right? That is implementation contract.

More from this hub

Something wrong, or a video you want off this page? Write to wethem.xyz@gmail.com and it is fixed or taken down within 48 hours.