Skip to content

Commit

Permalink
Upgrade safety validation (#68)
Browse files Browse the repository at this point in the history
* forge install: forge-std

v1.9.1

* forge install: openzeppelin-foundry-upgrades

v0.3.1

* forge install: openzeppelin-contracts-upgradeable

v5.0.2

* chore: adding instructions for validating upgrade safety between versions

* chore: updating the configuration according to instructions here https://docs.openzeppelin.com/upgrades-plugins/1.x/foundry-upgrades

* chore: adding v1.0.0 implementation and validation script

* chore: adding upgrade script for completion

* fix: clarifying file ref

* chore: formatting script ref

* fix: typos and clarity

* fix: typo

* fix: clarity and formatting

* fix: explicit imports

* fix: explicit imports

* chore: making upgrade script accept the address of the proxy to upgrade

* fix: fixing command

* fix: wrapping path in backquotes
  • Loading branch information
RonTuretzky authored Jul 25, 2024
1 parent 459e7be commit d9e912e
Show file tree
Hide file tree
Showing 10 changed files with 428 additions and 2 deletions.
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,6 @@
[submodule "lib/bread-token-v2"]
path = lib/bread-token-v2
url = [email protected]:BreadchainCoop/bread-token-v2.git
[submodule "lib/openzeppelin-foundry-upgrades"]
path = lib/openzeppelin-foundry-upgrades
url = https://github.com/OpenZeppelin/openzeppelin-foundry-upgrades
14 changes: 14 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,3 +69,17 @@ $ forge --help
$ anvil --help
$ cast --help
```

## Validate Upgrade Safety
1. Checkout to the deployed implementation commit
2. Copy "YieldDistributor.sol" to `test/upgrades/<version>/YieldDistributor.sol`
3. Checkout to upgrade candidate version (A version that is strictly higher than the version in the previous step)
4. Update the version in the options object of the `script/upgrades/ValidateUpgrade.s.sol` script
5. Run `forge clean && forge build && forge script script/upgrades/ValidateUpgrade.s.sol`
6. If script is runs successfully, proceed, otherwise address errors produced by the script until no errors are produced.

## Test Upgrade with Calldata Locally
1. Amend the `data` variable in `script/upgrades/UpgradeYieldDistributor.s.sol` to match desired data
2. run `forge clean && forge build && forge script script/upgrades/UpgradeYieldDistributor.s.sol --sig "run(address)" <proxy_address> --rpc-url $RPC_URL --sender <proxy_admin>`

The proxy admin address is configured to be the Breadchain multisig at address `0x918dEf5d593F46735f74F9E2B280Fe51AF3A99ad` and the Yield Distributor proxy address is `0xeE95A62b749d8a2520E0128D9b3aCa241269024b`
2 changes: 2 additions & 0 deletions foundry.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ libs = ["lib"]
fs_permissions = [{ access = "read-write", path = "./" }]
solc_version = "0.8.25"
build_info = true
ffi = true
ast = true
extra_output = ["storageLayout"]
[rpc_endpoints]
sepolia = "QUICKNODE_ENDPOINT_URL"
Expand Down
1 change: 1 addition & 0 deletions lib/openzeppelin-foundry-upgrades
2 changes: 2 additions & 0 deletions remappings.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,5 @@ openzeppelin-contracts/=lib/openzeppelin-contracts/
lib/openzeppelin-contracts:@openzeppelin/contracts/=lib/openzeppelin-contracts/contracts/
lib/openzeppelin-contracts-upgradeable:@openzeppelin/contracts-upgradeable/=lib/openzeppelin-contracts-upgradeable/contracts/
lib/openzeppelin-contracts-upgradeable:@openzeppelin/contracts/=lib/openzeppelin-contracts-upgradeable/lib/openzeppelin-contracts/contracts/
@openzeppelin/contracts/=lib/openzeppelin-contracts-upgradeable/lib/openzeppelin-contracts/contracts/
@openzeppelin/contracts-upgradeable/=lib/openzeppelin-contracts-upgradeable/contracts/
16 changes: 16 additions & 0 deletions script/upgrades/UpgradeYieldDistributor.s.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
pragma solidity ^0.8.20;

import {Script} from "forge-std/Script.sol";
import {Options} from "openzeppelin-foundry-upgrades/Options.sol";
import {Upgrades} from "openzeppelin-foundry-upgrades/Upgrades.sol";

contract DeployYieldDistributor is Script {
function run(address proxyAddress) external {
vm.startBroadcast();
bytes memory data;
Options memory opts;
opts.referenceContract = "v1.0.0/YieldDistributor.sol:YieldDistributor";
Upgrades.upgradeProxy(proxyAddress, "YieldDistributor.sol:YieldDistributor", data, opts);
vm.stopBroadcast();
}
}
16 changes: 16 additions & 0 deletions script/upgrades/ValidateUpgrade.s.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
pragma solidity ^0.8.20;

import {Script} from "forge-std/Script.sol";
import {Options} from "openzeppelin-foundry-upgrades/Options.sol";
import {Upgrades} from "openzeppelin-foundry-upgrades/Upgrades.sol";
import {YieldDistributor} from "../../src/YieldDistributor.sol";

contract DeployYieldDistributor is Script {
function run() external {
vm.startBroadcast();
Options memory opts;
opts.referenceContract = "v1.0.0/YieldDistributor.sol:YieldDistributor";
Upgrades.validateUpgrade("YieldDistributor.sol:YieldDistributor", opts);
vm.stopBroadcast();
}
}
Loading

0 comments on commit d9e912e

Please sign in to comment.