I updated openzeppelin from v4 to v5 and have tried to deploy the contract using ReentrancyGuard as ReentrancyGuardUpgradeable has been deprecated.
The error I receive trying to deploy bellow:
Error: script failed: Upgrade safety validation failed:
ā src/ExampleContract.sol:ExampleContract
lib/openzeppelin-contracts-upgradeable/lib/openzeppelin-contracts/contracts/utils/ReentrancyGuard.sol:58: Contract `ReentrancyGuard` has a constructor
Define an initializer instead
https://zpl.in/upgrades/error-001
Any example of a working deployment is very much appreciated ![]()
Code to reproduce
Here is the example contract I am trying deploy
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.28;
import {
Initializable
} from "@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol";
import {
UUPSUpgradeable
} from "@openzeppelin/contracts/proxy/utils/UUPSUpgradeable.sol";
import {
ReentrancyGuard
} from "@openzeppelin/contracts/utils/ReentrancyGuard.sol";
import {StorageSlot} from "@openzeppelin/contracts/utils/StorageSlot.sol";
contract ExampleContract is Initializable, UUPSUpgradeable, ReentrancyGuard {
uint256 value;
function initialize() public initializer {
StorageSlot
.getUint256Slot(
0x9b779b17422d0df92223018b32b4d1fa46e071723d6817e2486d003becc55f00
)
.value = 1; // NOT_ENTERED
}
function setValue(uint256 _value) public nonReentrant {
value = _value;
}
function _authorizeUpgrade(address newImplementation) internal override {}
}
The script responsible for deployment
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.28;
import {Upgrades} from "openzeppelin-foundry-upgrades/Upgrades.sol";
import {Script} from "forge-std/Script.sol";
import {ExampleContract} from "../src/ExampleContract.sol";
import {console} from "forge-std/console.sol";
contract DeployExampleContract is Script {
function run() public {
uint256 deployerPrivateKey = vm.envUint("PRIVATE_KEY");
vm.startBroadcast(deployerPrivateKey);
address proxy = Upgrades.deployUUPSProxy(
"ExampleContract.sol",
abi.encodeCall(ExampleContract.initialize, ())
);
ExampleContract exampleContract = ExampleContract(proxy);
exampleContract.setValue(1);
console.log("ExampleContract deployed at:", proxy);
vm.stopBroadcast();
}
}
The only way I made it deployed was using UnsafeUpgrades which I really dont want to push for production in our project.
Environment
I am using this current setup
Development ENV: Foundry
forge-std: 1.12.0
forge Version: 1.4.4-nightly - (in case is relavent)
openzeppelin-contracts-upgradeable: 5.5.0
openzeppelin-foundry-upgrades: 0.4.0