I’m trying to use the latest UUPSProxy to replace the transparent proxy for some of our old contracts, which is written in Solidity 0.5.
Wondering if anyone has done that, or have any recommendations? I’m thinking to just port over the UUPSProxy related contracts. Any suggestions?
Hi @maxweng . Are you using the Upgrades Plugins? You can switch to UUPS proxies by just changing the options when you depoy the proxy.
You will need to port the UUPSUpgradeable
contract to 0.5, but it should be small changes.
UUPS Proxies: A Tutorial
In this tutorial we will deploy an upgradeable contract using the UUPS proxy pattern. We assume some familiarity with Ethereum upgradeable proxies.
Introduction to UUPS
The original proxies included in OpenZeppelin followed the Transparent Proxy Pattern . While this pattern is still provided, our recommendation is now shifting towards UUPS proxies, which are both lightweight and versatile. The name UUPS comes from EIP1822 , which first documented the pattern.
While bot…
Yes, I’m using the upgrade plugin. And seems like there’s one issue when trying to port over UUPSUpgradeable
.
If I understand it correctly, the new proxy uses a storage layout called Diamond Storage. It takes advantage of a new Solidity feature supported from v0.6.4, that allows creating pointers to structs in arbitrary places in contract storage. Here’s the actual code I’m talking about: https://github.com/OpenZeppelin/openzeppelin-contracts-upgradeable/blob/aeb86bf4f438e0fedb5eecc3dd334fd6544ab1f6/contracts/utils/StorageSlotUpgradeable.sol#L53
So, wondering if I change the implementation mentioned above, will it destroy UUPSProxy, or it doesn’t matter as it’s just a utility thing.
This pattern is not called Diamond Storage.
It’s true that this feature is only available since Solidity 0.6.4. It would be fine to replace the use of this feature with a getter and setter like we used to do:
function _setImplementation(address newImplementation) private {
require(Address.isContract(newImplementation), "ERC1967Proxy: new implementation is not a contract");
bytes32 slot = _IMPLEMENTATION_SLOT;
// solhint-disable-next-line no-inline-assembly
assembly {
sstore(slot, newImplementation)
}
}
1 Like