I have an upgradable contract that uses OpenZeppelin version 4.9.0. This contract is deployed on Ethereum. OpenZeppelin version 5.0.0 has been released. My questions: Next time I upgrade the smart contract
- Could I use new v5 contracts ?
- Could I replace the v4 contracts with v5 contracts ?
- Will the OpenZeppelin upgrade plugin identify errors/conflicts if they exists?
The following code to reproduce is only an example (would probably not cause a problem because it is simple). But my question is more general about upgrades between different breaking changes versions of OpenZeppelin and the recommendation of the developers ?
Thank you
Code to reproduce
The code of the deployed upgradable contract
// SPDX-License-Identifier: MIT
pragma solidity 0.8.19;
import "https://github.com/OpenZeppelin/openzeppelin-contracts/blob/v4.9.0/contracts/token/ERC20/IERC20.sol";
import "https://github.com/OpenZeppelin/openzeppelin-contracts/blob/v4.9.0/contracts/token/ERC20/utils/SafeERC20.sol";
import "https://github.com/OpenZeppelin/openzeppelin-contracts-upgradeable/blob/v4.9.0/contracts/proxy/utils/Initializable.sol";
import "https://github.com/OpenZeppelin/openzeppelin-contracts-upgradeable/blob/v4.9.0/contracts/proxy/utils/UUPSUpgradeable.sol";
import "https://github.com/OpenZeppelin/openzeppelin-contracts-upgradeable/blob/v4.9.0/contracts/access/AccessControlUpgradeable.sol";
contract ExampleV1 is Initializable, UUPSUpgradeable, AccessControlUpgradeable {
using SafeERC20 for IERC20;
uint256 counter;
constructor() {
_disableInitializers();
}
function initialize(
address admin
) public initializer {
__UUPSUpgradeable_init();
__AccessControl_init();
_grantRole(DEFAULT_ADMIN_ROLE, admin);
}
function _authorizeUpgrade(
address newContractAddress
) internal view override onlyRole(DEFAULT_ADMIN_ROLE) { }
function doSomething() external {
counter++;
}
function getVersion() public pure returns (string memory) {
return "Example Version 1";
}
}
The new implementation contract that I would deploy and then set the proxy to:
// SPDX-License-Identifier: MIT
pragma solidity 0.8.20;
import "https://github.com/OpenZeppelin/openzeppelin-contracts/blob/v5.0.0/contracts/token/ERC20/IERC20.sol";
import "https://github.com/OpenZeppelin/openzeppelin-contracts/blob/v5.0.0/contracts/token/ERC20/utils/SafeERC20.sol";
import "https://github.com/OpenZeppelin/openzeppelin-contracts-upgradeable/blob/v5.0.0/contracts/proxy/utils/Initializable.sol";
import "https://github.com/OpenZeppelin/openzeppelin-contracts-upgradeable/blob/v5.0.0/contracts/proxy/utils/UUPSUpgradeable.sol";
import "https://github.com/OpenZeppelin/openzeppelin-contracts-upgradeable/blob/v5.0.0/contracts/access/AccessControlUpgradeable.sol";
contract ExampleV2 is UUPSUpgradeable, AccessControlUpgradeable {
using SafeERC20 for IERC20;
uint256 public counter;
function _authorizeUpgrade(
address newContractAddress
) internal view override onlyRole(DEFAULT_ADMIN_ROLE) { }
function doSomething() external {
counter = counter + 2;
}
function getVersion() public pure returns (string memory) {
return "Example Version 2";
}
}
Environment
Hardhat / Remix