-
Notifications
You must be signed in to change notification settings - Fork 85
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
modify upgrade scripts for non-multisig, non-openzeppelin-defender de…
…ployments (#1705) * use the same LC file for LCV2 since a separate file has not been used for further deployments * changes to script for upgradge deployment alongside readme updates * add support for mnenomic offset * modified scripts required for upgrading the LC without OPZ defender
- Loading branch information
1 parent
3fe0e95
commit cd9ae47
Showing
14 changed files
with
854 additions
and
26 deletions.
There are no files selected for viewing
153 changes: 153 additions & 0 deletions
153
contracts/broadcast/LightClient.s.sol/11155111/run-1720726496.json
Large diffs are not rendered by default.
Oops, something went wrong.
153 changes: 153 additions & 0 deletions
153
contracts/broadcast/LightClient.s.sol/11155111/run-latest.json
Large diffs are not rendered by default.
Oops, something went wrong.
56 changes: 56 additions & 0 deletions
56
contracts/broadcast/UpgradeLightClient.s.sol/11155111/run-1720727659.json
Large diffs are not rendered by default.
Oops, something went wrong.
131 changes: 131 additions & 0 deletions
131
contracts/broadcast/UpgradeLightClient.s.sol/11155111/run-1720727923.json
Large diffs are not rendered by default.
Oops, something went wrong.
131 changes: 131 additions & 0 deletions
131
contracts/broadcast/UpgradeLightClient.s.sol/11155111/run-latest.json
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity ^0.8.19; | ||
|
||
import { Script } from "forge-std/Script.sol"; | ||
|
||
import { LightClient as LCV2 } from "../src/LightClient.sol"; | ||
import { LightClient as LC } from "../src/LightClient.sol"; | ||
|
||
contract UpgradeLightClientScript is Script { | ||
/// @notice runs the upgrade | ||
/// @param mostRecentlyDeployedProxy address of deployed proxy | ||
/// @return address of the proxy | ||
/// TODO get the most recent deployment from the devops tooling | ||
function run(uint32 seedPhraseOffset, address mostRecentlyDeployedProxy) | ||
external | ||
returns (address) | ||
{ | ||
string memory seedPhrase = vm.envString("MNEMONIC"); | ||
(address admin,) = deriveRememberKey(seedPhrase, seedPhraseOffset); | ||
vm.startBroadcast(admin); | ||
address proxy = upgradeLightClient(mostRecentlyDeployedProxy, address(new LCV2())); | ||
return proxy; | ||
} | ||
|
||
/// @notice upgrades the light client contract by calling the upgrade function the | ||
/// implementation contract via | ||
/// the proxy | ||
/// @param proxyAddress address of proxy | ||
/// @param newLightClient address of new implementation | ||
/// @return address of the proxy | ||
function upgradeLightClient(address proxyAddress, address newLightClient) | ||
public | ||
returns (address) | ||
{ | ||
LC proxy = LC(proxyAddress); //make the function call on the previous implementation | ||
proxy.upgradeToAndCall(newLightClient, ""); //proxy address now points to the new | ||
// implementation | ||
vm.stopBroadcast(); | ||
return address(proxy); | ||
} | ||
} |
8 changes: 8 additions & 0 deletions
8
contracts/script/output/defenderDeployments/LightClient.sol/11155111/13.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
{ | ||
"multisig": "0xc56fA6505d10bF322e01327e22479DE78C3Bf1cE", | ||
"newContractName": "LightClient.sol", | ||
"proposalId": "8d347333-7e10-417e-96fd-a2b785115c58", | ||
"proxyAddress": "0xbC781a2BCcdac8F65EF10EA85D765CA240D1789b", | ||
"responseUrl": "https://app.safe.global/transactions/tx?safe=sep:0xc56fA6505d10bF322e01327e22479DE78C3Bf1cE&id=0xad6fe9ec8b6275b81e3a894fb87408fb77e9ad0020e40506aa189024fe28fae8", | ||
"salt": 13 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
// SPDX-License-Identifier: UNLICENSED | ||
pragma solidity ^0.8.0; | ||
pragma experimental ABIEncoderV2; | ||
|
||
import { Test } /*, console2*/ from "forge-std/Test.sol"; | ||
import { LightClient as LCV1 } from "../src/LightClient.sol"; | ||
import { LightClient as LCV2 } from "../src/LightClient.sol"; | ||
import { DeployLightClientContractScript } from "../script/LightClient.s.sol"; | ||
import { UpgradeLightClientScript } from "../script/UpgradeSameLightClient.s.sol"; | ||
|
||
contract LightClientUpgradeSameContractTest is Test { | ||
LCV1 public lcV1Proxy; | ||
LCV2 public lcV2Proxy; | ||
|
||
DeployLightClientContractScript public deployer = new DeployLightClientContractScript(); | ||
UpgradeLightClientScript public upgrader = new UpgradeLightClientScript(); | ||
|
||
LCV1.LightClientState public stateV1; | ||
|
||
address public admin; | ||
address public proxy; | ||
|
||
// deploy the first implementation with its proxy | ||
function setUp() public { | ||
(proxy, admin, stateV1) = deployer.run(10, 5); | ||
lcV1Proxy = LCV1(proxy); | ||
} | ||
|
||
function testCorrectInitialization() public view { | ||
assert(lcV1Proxy.blocksPerEpoch() == 10); | ||
assert(lcV1Proxy.currentEpoch() == 0); | ||
|
||
assertEq(abi.encode(lcV1Proxy.getGenesisState()), abi.encode(stateV1)); | ||
|
||
assertEq(abi.encode(lcV1Proxy.getFinalizedState()), abi.encode(stateV1)); | ||
|
||
bytes32 stakeTableComm = lcV1Proxy.computeStakeTableComm(stateV1); | ||
assertEq(lcV1Proxy.votingStakeTableCommitment(), stakeTableComm); | ||
assertEq(lcV1Proxy.frozenStakeTableCommitment(), stakeTableComm); | ||
assertEq(lcV1Proxy.votingThreshold(), stateV1.threshold); | ||
assertEq(lcV1Proxy.frozenThreshold(), stateV1.threshold); | ||
} | ||
|
||
// that the data remains the same after upgrading the implementation | ||
function testUpgradeSameData() public { | ||
// Upgrade LightClient and check that the genesis state is not changed and that the new | ||
// field | ||
// of the upgraded contract is set to 0 | ||
lcV2Proxy = LCV2(upgrader.run(0, proxy)); | ||
|
||
assertEq(lcV2Proxy.blocksPerEpoch(), 10); | ||
assertEq(lcV2Proxy.currentEpoch(), 0); | ||
|
||
LCV2.LightClientState memory expectedLightClientState = LCV2.LightClientState( | ||
stateV1.viewNum, | ||
stateV1.blockHeight, | ||
stateV1.blockCommRoot, | ||
stateV1.feeLedgerComm, | ||
stateV1.stakeTableBlsKeyComm, | ||
stateV1.stakeTableSchnorrKeyComm, | ||
stateV1.stakeTableAmountComm, | ||
stateV1.threshold | ||
); | ||
|
||
assertEq(abi.encode(lcV2Proxy.getFinalizedState()), abi.encode(expectedLightClientState)); | ||
} | ||
|
||
// check that the proxy address remains the same | ||
function testUpgradesSameProxyAddress() public { | ||
(uint8 major, uint8 minor, uint8 patch) = lcV1Proxy.getVersion(); | ||
assertEq(major, 1); | ||
assertEq(minor, 0); | ||
assertEq(patch, 0); | ||
|
||
//upgrade box | ||
lcV2Proxy = LCV2(upgrader.run(0, proxy)); | ||
assertEq(address(lcV2Proxy), address(lcV1Proxy)); | ||
} | ||
|
||
function testMaliciousUpgradeFails() public { | ||
address attacker = makeAddr("attacker"); | ||
|
||
//attempted upgrade as attacker will revert | ||
vm.prank(attacker); | ||
vm.expectRevert(); | ||
lcV2Proxy = LCV2(upgrader.run(0, address(proxy))); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters