Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add zeus upgrade #1044

Open
wants to merge 1 commit into
base: slashing-magnitudes-fixes
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
96 changes: 96 additions & 0 deletions script/releases/v1.0.4-slashing-sm/1-eoa.s.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
// SPDX-License-Identifier: BUSL-1.1
pragma solidity ^0.8.12;

import {EOADeployer} from "zeus-templates/templates/EOADeployer.sol";
import "../Env.sol";

import "@openzeppelin/contracts/proxy/transparent/TransparentUpgradeableProxy.sol";
import "@openzeppelin/contracts/proxy/transparent/ProxyAdmin.sol";
import "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import "@openzeppelin/contracts/token/ERC20/extensions/IERC20Metadata.sol";

// Just upgrade StrategyManager
contract Deploy is EOADeployer {
using Env for *;

function _runAsEOA() internal override {
vm.startBroadcast();

// Deploy SM
deployImpl({
name: type(StrategyManager).name,
deployedTo: address(new StrategyManager({
_delegation: Env.proxy.delegationManager(),
_pauserRegistry: Env.impl.pauserRegistry()
}))
});

vm.stopBroadcast();
}

function testDeploy() public virtual {
_runAsEOA();
_validateDomainSeparatorNonZero();
_validateNewImplAddresses(false);
_validateImplConstructors();
_validateImplsInitialized();
}

function _validateDomainSeparatorNonZero() internal view {
bytes32 zeroDomainSeparator = bytes32(0);

assertFalse(Env.impl.strategyManager().domainSeparator() == zeroDomainSeparator, "rc.domainSeparator is zero");
}


/// @dev Validate that the `Env.impl` addresses are updated to be distinct from what the proxy
/// admin reports as the current implementation address.
///
/// Note: The upgrade script can call this with `areMatching == true` to check that these impl
/// addresses _are_ matches.
function _validateNewImplAddresses(bool areMatching) internal view {
function (address, address, string memory) internal pure assertion =
areMatching ? _assertMatch : _assertNotMatch;


assertion(
_getProxyImpl(address(Env.proxy.strategyManager())),
address(Env.impl.strategyManager()),
"strategyManager impl failed"
);
}

/// @dev Validate the immutables set in the new implementation constructors
function _validateImplConstructors() internal view {
StrategyManager strategyManager = Env.impl.strategyManager();
assertTrue(strategyManager.delegation() == Env.proxy.delegationManager(), "sm.dm invalid");
assertTrue(strategyManager.pauserRegistry() == Env.impl.pauserRegistry(), "sm.pR invalid");
}

/// @dev Call initialize on all deployed implementations to ensure initializers are disabled
function _validateImplsInitialized() internal {
bytes memory errInit = "Initializable: contract is already initialized";

StrategyManager strategyManager = Env.impl.strategyManager();
vm.expectRevert(errInit);
strategyManager.initialize(address(0), address(0), 0);
}

/// @dev Query and return `proxyAdmin.getProxyImplementation(proxy)`
function _getProxyImpl(address proxy) internal view returns (address) {
return ProxyAdmin(Env.proxyAdmin()).getProxyImplementation(ITransparentUpgradeableProxy(proxy));
}

/// @dev Query and return `proxyAdmin.getProxyAdmin(proxy)`
function _getProxyAdmin(address proxy) internal view returns (address) {
return ProxyAdmin(Env.proxyAdmin()).getProxyAdmin(ITransparentUpgradeableProxy(proxy));
}

function _assertMatch(address a, address b, string memory err) private pure {
assertEq(a, b, err);
}

function _assertNotMatch(address a, address b, string memory err) private pure {
assertNotEq(a, b, err);
}
}
72 changes: 72 additions & 0 deletions script/releases/v1.0.4-slashing-sm/2-multisig.s.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
// SPDX-License-Identifier: BUSL-1.1
pragma solidity ^0.8.12;

import {Deploy} from "./1-eoa.s.sol";
import "../Env.sol";

import {MultisigBuilder} from "zeus-templates/templates/MultisigBuilder.sol";
import "zeus-templates/utils/Encode.sol";

import {TimelockController} from "@openzeppelin/contracts/governance/TimelockController.sol";

contract Queue is MultisigBuilder, Deploy {
using Env for *;
using Encode for *;

function _runAsMultisig() prank(Env.opsMultisig()) internal virtual override {
bytes memory calldata_to_executor = _getCalldataToExecutor();

TimelockController timelock = Env.timelockController();
timelock.schedule({
target: Env.executorMultisig(),
value: 0,
data: calldata_to_executor,
predecessor: 0,
salt: 0,
delay: timelock.getMinDelay()
});
}

/// @dev Get the calldata to be sent from the timelock to the executor
function _getCalldataToExecutor() internal returns (bytes memory) {
MultisigCall[] storage executorCalls = Encode.newMultisigCalls()
/// core/
.append({
to: Env.proxyAdmin(),
data: Encode.proxyAdmin.upgrade({
proxy: address(Env.proxy.strategyManager()),
impl: address(Env.impl.strategyManager())
})
});


return Encode.gnosisSafe.execTransaction({
from: address(Env.timelockController()),
to: address(Env.multiSendCallOnly()),
op: Encode.Operation.DelegateCall,
data: Encode.multiSend(executorCalls)
});
}

function testScript() public virtual {
runAsEOA();

TimelockController timelock = Env.timelockController();
bytes memory calldata_to_executor = _getCalldataToExecutor();
bytes32 txHash = timelock.hashOperation({
target: Env.executorMultisig(),
value: 0,
data: calldata_to_executor,
predecessor: 0,
salt: 0
});

// Check that the upgrade does not exist in the timelock
assertFalse(timelock.isOperationPending(txHash), "Transaction should NOT be queued.");

execute();

// Check that the upgrade has been added to the timelock
assertTrue(timelock.isOperationPending(txHash), "Transaction should be queued.");
}
}
71 changes: 71 additions & 0 deletions script/releases/v1.0.4-slashing-sm/3-execute.s.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
// SPDX-License-Identifier: BUSL-1.1
pragma solidity ^0.8.12;

import "../Env.sol";
import {Queue} from "./2-multisig.s.sol";

import "@openzeppelin/contracts/proxy/transparent/TransparentUpgradeableProxy.sol";
import "@openzeppelin/contracts/proxy/transparent/ProxyAdmin.sol";

contract Execute is Queue {
using Env for *;

function _runAsMultisig() prank(Env.protocolCouncilMultisig()) internal override(Queue) {
bytes memory calldata_to_executor = _getCalldataToExecutor();

TimelockController timelock = Env.timelockController();
timelock.execute({
target: Env.executorMultisig(),
value: 0,
payload: calldata_to_executor,
predecessor: 0,
salt: 0
});
}

function testScript() public virtual override(Queue){
// 0. Deploy Impls
runAsEOA();

TimelockController timelock = Env.timelockController();
bytes memory calldata_to_executor = _getCalldataToExecutor();
bytes32 txHash = timelock.hashOperation({
target: Env.executorMultisig(),
value: 0,
data: calldata_to_executor,
predecessor: 0,
salt: 0
});
assertFalse(timelock.isOperationPending(txHash), "Transaction should NOT be queued.");

// 1. Queue Upgrade
Queue._runAsMultisig();
_unsafeResetHasPranked(); // reset hasPranked so we can use it again

// 2. Warp past delay
vm.warp(block.timestamp + timelock.getMinDelay()); // 1 tick after ETA
assertEq(timelock.isOperationReady(txHash), true, "Transaction should be executable.");

// 3- execute
execute();

assertTrue(timelock.isOperationDone(txHash), "Transaction should be complete.");

// 4. Validate
_validateNewImplAddresses(true);
_validateProxyConstructors();
_validateProxyDomainSeparators();
}

function _validateProxyDomainSeparators() internal view {
bytes32 zeroDomainSeparator = bytes32(0);

assertFalse(Env.proxy.strategyManager().domainSeparator() == zeroDomainSeparator, "rc.domainSeparator is zero");
}

function _validateProxyConstructors() internal view {
StrategyManager strategyManager = Env.proxy.strategyManager();
assertTrue(strategyManager.delegation() == Env.proxy.delegationManager(), "sm.dm invalid");
assertTrue(strategyManager.pauserRegistry() == Env.impl.pauserRegistry(), "sm.pR invalid");
}
}
19 changes: 19 additions & 0 deletions script/releases/v1.0.4-slashing-sm/upgrade.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"name": "slashing-sm",
"from": "1.0.3",
"to": "1.0.4",
"phases": [
{
"type": "eoa",
"filename": "1-eoa.s.sol"
},
{
"type": "multisig",
"filename": "2-multisig.s.sol"
},
{
"type": "multisig",
"filename": "3-execute.s.sol"
}
]
}
Loading