generated from foundry-rs/forge-template
-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #248 from PufferFinance/feature/arbitrary-reop-call
Custom external call from the ReOp
- Loading branch information
Showing
17 changed files
with
361 additions
and
8 deletions.
There are no files selected for viewing
Submodule pufETH
updated
4 files
+40 −13 | README.md | |
+ − | audits/Immunefi_Boost_pufETH_v1.pdf | |
+3 −0 | script/Roles.sol | |
+2 −0 | src/PufferVaultV2.sol |
67 changes: 67 additions & 0 deletions
67
script/AccessManagerMigrations/GenerateAccessManagerCalldata1.s.sol
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,67 @@ | ||
// SPDX-License-Identifier: GPL-3.0 | ||
pragma solidity >=0.8.0 <0.9.0; | ||
|
||
import { Script } from "forge-std/Script.sol"; | ||
import { AccessManager } from "openzeppelin/access/manager/AccessManager.sol"; | ||
import { Multicall } from "openzeppelin/utils/Multicall.sol"; | ||
import { console } from "forge-std/console.sol"; | ||
import { AVSContractsRegistry } from "../../src/AVSContractsRegistry.sol"; | ||
import { ROLE_ID_AVS_COORDINATOR_ALLOWLISTER, ROLE_ID_DAO } from "pufETHScript/Roles.sol"; | ||
import { PufferModuleManager } from "puffer/PufferModuleManager.sol"; | ||
|
||
/** | ||
* @title GenerateAccessManagerCalldata1 | ||
* @author Puffer Finance | ||
* @notice Generates the AccessManager call data to setup the public access | ||
* The returned calldata is queued and executed by the Operations Multisig | ||
* 1. timelock.queueTransaction(address(accessManager), encodedMulticall, 1) | ||
* 2. ... 7 days later ... | ||
* 3. timelock.executeTransaction(address(accessManager), encodedMulticall, 1) | ||
*/ | ||
contract GenerateAccessManagerCalldata1 is Script { | ||
function run(address moduleManager, address avsContractsRegistry, address whitelister) | ||
public | ||
pure | ||
returns (bytes memory) | ||
{ | ||
bytes[] memory calldatas = new bytes[](4); | ||
|
||
bytes4[] memory whitelisterSelectors = new bytes4[](1); | ||
whitelisterSelectors[0] = AVSContractsRegistry.setAvsRegistryCoordinator.selector; | ||
|
||
calldatas[0] = abi.encodeWithSelector( | ||
AccessManager.setTargetFunctionRole.selector, | ||
avsContractsRegistry, | ||
whitelisterSelectors, | ||
ROLE_ID_AVS_COORDINATOR_ALLOWLISTER | ||
); | ||
|
||
// Whitelister has 1 day timelock to add new coordinators | ||
calldatas[1] = abi.encodeWithSelector( | ||
AccessManager.grantRole.selector, | ||
ROLE_ID_AVS_COORDINATOR_ALLOWLISTER, | ||
whitelister, | ||
1 days // 1 day timelock | ||
); | ||
|
||
// The role guardian can cancel | ||
calldatas[2] = abi.encodeWithSelector( | ||
AccessManager.setRoleGuardian.selector, ROLE_ID_AVS_COORDINATOR_ALLOWLISTER, ROLE_ID_DAO | ||
); | ||
|
||
bytes4[] memory pufferModuleManagerSelectors = new bytes4[](1); | ||
|
||
pufferModuleManagerSelectors[0] = PufferModuleManager.customExternalCall.selector; | ||
|
||
calldatas[3] = abi.encodeWithSelector( | ||
AccessManager.setTargetFunctionRole.selector, moduleManager, pufferModuleManagerSelectors, ROLE_ID_DAO | ||
); | ||
|
||
bytes memory encodedMulticall = abi.encodeCall(Multicall.multicall, (calldatas)); | ||
|
||
// console.log("GenerateAccessManagerCallData:"); | ||
// console.logBytes(encodedMulticall); | ||
|
||
return encodedMulticall; | ||
} | ||
} |
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
68 changes: 68 additions & 0 deletions
68
script/MainnetContractMigrations/UpgradeRestakingOperator.s.sol
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,68 @@ | ||
// SPDX-License-Identifier: GPL-3.0 | ||
pragma solidity >=0.8.0 <0.9.0; | ||
|
||
import "forge-std/Script.sol"; | ||
import { BaseScript } from "script/BaseScript.s.sol"; | ||
import { PufferProtocol } from "puffer/PufferProtocol.sol"; | ||
import { AccessManager } from "openzeppelin/access/manager/AccessManager.sol"; | ||
import { BaseScript } from "script/BaseScript.s.sol"; | ||
import { stdJson } from "forge-std/StdJson.sol"; | ||
import { PufferModuleManager } from "puffer/PufferModuleManager.sol"; | ||
import { AVSContractsRegistry } from "puffer/AVSContractsRegistry.sol"; | ||
import { UUPSUpgradeable } from "@openzeppelin-contracts-upgradeable/proxy/utils/UUPSUpgradeable.sol"; | ||
import { UpgradeableBeacon } from "openzeppelin/proxy/beacon/UpgradeableBeacon.sol"; | ||
import { RestakingOperator } from "puffer/RestakingOperator.sol"; | ||
import { IDelegationManager } from "eigenlayer/interfaces/IDelegationManager.sol"; | ||
import { ISlasher } from "eigenlayer/interfaces/ISlasher.sol"; | ||
import { GenerateAccessManagerCalldata1 } from "script/AccessManagerMigrations/GenerateAccessManagerCalldata1.s.sol"; | ||
|
||
/** | ||
* forge script script/UpgradeRestakingOperator.s.sol:UpgradeRestakingOperator --rpc-url=$RPC_URL --private-key $PK | ||
*/ | ||
contract UpgradeRestakingOperator is Script { | ||
address DELEGATION_MANAGER = 0x39053D51B77DC0d36036Fc1fCc8Cb819df8Ef37A; | ||
address EIGEN_SLASHER = 0xD92145c07f8Ed1D392c1B88017934E301CC1c3Cd; | ||
address MODULE_MANAGER_PROXY = 0x9E1E4fCb49931df5743e659ad910d331735C3860; | ||
address MODULE_BEACON = 0xdd38A5a7789C74fc7F64556fc772343658EEBb04; | ||
address RESTAKING_OPERATOR_BEACON = 0x6756B856Dd3843C84249a6A31850cB56dB824c4B; | ||
address PUFFER_PROTOCOL = 0xf7b6B32492c2e13799D921E84202450131bd238B; | ||
address DAO = 0xC0896ab1A8cae8c2C1d27d011eb955Cca955580d; | ||
address ACCESS_MANAGER = 0x8c1686069474410E6243425f4a10177a94EBEE11; | ||
|
||
function run() public { | ||
require(block.chainid == 1, "This script is only for Puffer Mainnet"); | ||
vm.startBroadcast(); | ||
|
||
AVSContractsRegistry avsRegistry = new AVSContractsRegistry(address(ACCESS_MANAGER)); | ||
|
||
PufferModuleManager pufferModuleManagerImpl = new PufferModuleManager({ | ||
pufferModuleBeacon: MODULE_BEACON, | ||
restakingOperatorBeacon: RESTAKING_OPERATOR_BEACON, | ||
pufferProtocol: PUFFER_PROTOCOL, | ||
avsContractsRegistry: avsRegistry | ||
}); | ||
|
||
RestakingOperator restakingOperatorImpl = new RestakingOperator({ | ||
delegationManager: IDelegationManager(DELEGATION_MANAGER), | ||
slasher: ISlasher(EIGEN_SLASHER), | ||
moduleManager: PufferModuleManager(MODULE_MANAGER_PROXY) | ||
}); | ||
|
||
bytes memory accessCd = | ||
new GenerateAccessManagerCalldata1().run(MODULE_MANAGER_PROXY, address(avsRegistry), DAO); | ||
|
||
bytes memory cd1 = abi.encodeCall(UUPSUpgradeable.upgradeToAndCall, (address(pufferModuleManagerImpl), "")); | ||
bytes memory cd2 = abi.encodeCall(UpgradeableBeacon.upgradeTo, address(restakingOperatorImpl)); | ||
bytes memory cd3 = abi.encodeCall(AccessManager.execute, (MODULE_MANAGER_PROXY, cd1)); | ||
bytes memory cd4 = abi.encodeCall(AccessManager.execute, (RESTAKING_OPERATOR_BEACON, cd2)); | ||
|
||
// calldata to execute using the timelock contract. setting the target as the Access Manager | ||
console.logBytes(cd3); | ||
console.logBytes(cd4); | ||
console.logBytes(accessCd); | ||
|
||
// AccessManager is the owner of upgradeable beacon for restaking operator & module manager | ||
// AccessManager(ACCESS_MANAGER).execute(MODULE_MANAGER_PROXY, cd1); | ||
// AccessManager(ACCESS_MANAGER).execute(RESTAKING_OPERATOR_BEACON, cd2); | ||
} | ||
} |
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,46 @@ | ||
// SPDX-License-Identifier: GPL-3.0 | ||
pragma solidity >=0.8.0 <0.9.0; | ||
|
||
import { AccessManaged } from "openzeppelin/access/manager/AccessManaged.sol"; | ||
|
||
/** | ||
* @title AVSContractsRegistry | ||
* @author Puffer Finance | ||
* @custom:security-contact [email protected] | ||
*/ | ||
contract AVSContractsRegistry is AccessManaged { | ||
event AvsRegistryCoordinatorSet(address indexed avsRegistryCoordinator, bytes4 selector, bool isAllowed); | ||
|
||
mapping(address avsRegistryCoordinator => mapping(bytes4 selector => bool allowed)) internal | ||
_avsRegistryCoordinators; | ||
|
||
constructor(address authority) AccessManaged(authority) { } | ||
|
||
/** | ||
* @notice Sets the boolean for the AVS registry coordinator contract | ||
* @param avsRegistryCoordinator is the address of the registry coordinator of the AVS | ||
* @param selector is the signature of the function | ||
* @param isAllowed is the boolean value to set if coordinator contract and signature are allowed or not | ||
*/ | ||
function setAvsRegistryCoordinator(address avsRegistryCoordinator, bytes4 selector, bool isAllowed) | ||
external | ||
restricted | ||
{ | ||
_avsRegistryCoordinators[avsRegistryCoordinator][selector] = isAllowed; | ||
emit AvsRegistryCoordinatorSet(avsRegistryCoordinator, selector, isAllowed); | ||
} | ||
|
||
/** | ||
* @notice Returns `true` if the `avsRegistryCoordinator` contract is allowed | ||
*/ | ||
function isAllowedRegistryCoordinator(address avsRegistryCoordinator, bytes calldata customCalldata) | ||
external | ||
view | ||
returns (bool) | ||
{ | ||
// Extract the function selector (first 4 bytes of customCalldata) | ||
bytes4 selector = bytes4(customCalldata[:4]); | ||
|
||
return _avsRegistryCoordinators[avsRegistryCoordinator][selector]; | ||
} | ||
} |
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
Oops, something went wrong.