UUPS Example
EIP-1822
Proxy
UUPS proxy is fairly minimal compared to the transparent proxy setup.
Using OZ's implementation library, you don't need to do anything else other than simply deploying the
ERC1967Proxy.sol
contract and linking your implementation.
Implementation
We will need to have our implementation contract inherit UUPSUpgradeable
, which defines the upgradeability mechanism to be included in the implementation contract.
Inheriting from UUPSUpgradeable
(and overriding the _authorizeUpgrade
function with the relevant access control mechanism) will turn your contract into a UUPS compliant implementation.
Disable Initializer
_disableInitializer()
is called inside the constructor; prevents any further initialization. This is done so that in the context of the logic contract the initializer is locked.
Therefore an attacker will not able to call the initalizer()
function in the state of the logic contract and perform any malicious activity (like self-destruct)
Note that the proxy contract state will still be able to call this function, this is because the constructor does not effect the state of the proxy contract.
When you upgrade your contract you need to follow the convention of inheriting the previous version and then adding any modifications.
It is not expected that you will need to initialize something every time. So, if you shouldn’t confuse this as preventing any upgrades.
Upgradeable smart contracts can have constructors
Upgradeable smart contracts cannot have any constructors which initialize any variable data.
Can have a constructor that initializes an immutable (constants are initialized inline).
Need to use reinitializer()
in subsequent upgrades for the initializer function
Last updated