|
| 1 | +// SPDX-License-Identifier: BUSL-1.1 |
| 2 | +pragma solidity ^0.8.12; |
| 3 | + |
| 4 | +import {EOADeployer} from "zeus-templates/templates/EOADeployer.sol"; |
| 5 | +import "../Env.sol"; |
| 6 | + |
| 7 | +/** |
| 8 | + * @title DeployRewardsCoordinatorImpl |
| 9 | + * @notice Deploy new RewardsCoordinator implementation with Rewards v2.2 support. |
| 10 | + * This adds support for: |
| 11 | + * - Unique stake rewards submissions (rewards linear to allocated unique stake) |
| 12 | + * - Total stake rewards submissions (rewards linear to total stake) |
| 13 | + */ |
| 14 | +contract DeployRewardsCoordinatorImpl is EOADeployer { |
| 15 | + using Env for *; |
| 16 | + |
| 17 | + /// forgefmt: disable-next-item |
| 18 | + function _runAsEOA() internal override { |
| 19 | + // Only execute on source chains with version 1.9.0 |
| 20 | + if (!(Env.isSourceChain() && Env._strEq(Env.envVersion(), "1.9.0"))) { |
| 21 | + return; |
| 22 | + } |
| 23 | + |
| 24 | + vm.startBroadcast(); |
| 25 | + |
| 26 | + // Deploy RewardsCoordinator implementation with the new MAX_FUTURE_LENGTH |
| 27 | + deployImpl({ |
| 28 | + name: type(RewardsCoordinator).name, |
| 29 | + deployedTo: address( |
| 30 | + new RewardsCoordinator( |
| 31 | + IRewardsCoordinatorTypes.RewardsCoordinatorConstructorParams({ |
| 32 | + delegationManager: Env.proxy.delegationManager(), |
| 33 | + strategyManager: Env.proxy.strategyManager(), |
| 34 | + allocationManager: Env.proxy.allocationManager(), |
| 35 | + pauserRegistry: Env.impl.pauserRegistry(), |
| 36 | + permissionController: Env.proxy.permissionController(), |
| 37 | + CALCULATION_INTERVAL_SECONDS: Env.CALCULATION_INTERVAL_SECONDS(), |
| 38 | + MAX_REWARDS_DURATION: Env.MAX_REWARDS_DURATION(), |
| 39 | + MAX_RETROACTIVE_LENGTH: Env.MAX_RETROACTIVE_LENGTH(), |
| 40 | + MAX_FUTURE_LENGTH: 63072000, // 730 days (2 years) |
| 41 | + GENESIS_REWARDS_TIMESTAMP: Env.GENESIS_REWARDS_TIMESTAMP(), |
| 42 | + version: Env.deployVersion() |
| 43 | + }) |
| 44 | + ) |
| 45 | + ) |
| 46 | + }); |
| 47 | + |
| 48 | + // Update the MAX_FUTURE_LENGTH environment variable |
| 49 | + zUpdateUint32("REWARDS_COORDINATOR_MAX_FUTURE_LENGTH", 63072000); |
| 50 | + |
| 51 | + vm.stopBroadcast(); |
| 52 | + } |
| 53 | + |
| 54 | + function testScript() public virtual { |
| 55 | + if (!(Env.isSourceChain() && Env._strEq(Env.envVersion(), "1.9.0"))) { |
| 56 | + return; |
| 57 | + } |
| 58 | + |
| 59 | + // Deploy the new RewardsCoordinator implementation |
| 60 | + runAsEOA(); |
| 61 | + |
| 62 | + _validateNewImplAddress(); |
| 63 | + _validateProxyAdmin(); |
| 64 | + _validateImplConstructor(); |
| 65 | + _validateImplInitialized(); |
| 66 | + _validateVersion(); |
| 67 | + _validateNewFunctionality(); |
| 68 | + _validateStorageLayout(); |
| 69 | + } |
| 70 | + |
| 71 | + /// @dev Validate that the new RewardsCoordinator impl address is distinct from the current one |
| 72 | + function _validateNewImplAddress() internal view { |
| 73 | + address currentImpl = Env._getProxyImpl(address(Env.proxy.rewardsCoordinator())); |
| 74 | + address newImpl = address(Env.impl.rewardsCoordinator()); |
| 75 | + |
| 76 | + assertFalse(currentImpl == newImpl, "RewardsCoordinator impl should be different from current implementation"); |
| 77 | + } |
| 78 | + |
| 79 | + /// @dev Validate that the RewardsCoordinator proxy is still owned by the correct ProxyAdmin |
| 80 | + function _validateProxyAdmin() internal view { |
| 81 | + address pa = Env.proxyAdmin(); |
| 82 | + |
| 83 | + assertTrue( |
| 84 | + Env._getProxyAdmin(address(Env.proxy.rewardsCoordinator())) == pa, "RewardsCoordinator proxyAdmin incorrect" |
| 85 | + ); |
| 86 | + } |
| 87 | + |
| 88 | + /// @dev Validate the immutables set in the new RewardsCoordinator implementation constructor |
| 89 | + function _validateImplConstructor() internal view { |
| 90 | + RewardsCoordinator rewardsCoordinatorImpl = Env.impl.rewardsCoordinator(); |
| 91 | + |
| 92 | + // Validate version |
| 93 | + assertEq( |
| 94 | + keccak256(bytes(rewardsCoordinatorImpl.version())), |
| 95 | + keccak256(bytes(Env.deployVersion())), |
| 96 | + "RewardsCoordinator impl version mismatch" |
| 97 | + ); |
| 98 | + |
| 99 | + // Validate core dependencies |
| 100 | + assertTrue( |
| 101 | + address(rewardsCoordinatorImpl.delegationManager()) == address(Env.proxy.delegationManager()), |
| 102 | + "RewardsCoordinator delegationManager mismatch" |
| 103 | + ); |
| 104 | + assertTrue( |
| 105 | + address(rewardsCoordinatorImpl.strategyManager()) == address(Env.proxy.strategyManager()), |
| 106 | + "RewardsCoordinator strategyManager mismatch" |
| 107 | + ); |
| 108 | + assertTrue( |
| 109 | + address(rewardsCoordinatorImpl.allocationManager()) == address(Env.proxy.allocationManager()), |
| 110 | + "RewardsCoordinator allocationManager mismatch" |
| 111 | + ); |
| 112 | + |
| 113 | + // Validate reward parameters |
| 114 | + assertEq( |
| 115 | + rewardsCoordinatorImpl.CALCULATION_INTERVAL_SECONDS(), |
| 116 | + Env.CALCULATION_INTERVAL_SECONDS(), |
| 117 | + "CALCULATION_INTERVAL_SECONDS mismatch" |
| 118 | + ); |
| 119 | + assertEq( |
| 120 | + rewardsCoordinatorImpl.MAX_REWARDS_DURATION(), Env.MAX_REWARDS_DURATION(), "MAX_REWARDS_DURATION mismatch" |
| 121 | + ); |
| 122 | + assertEq( |
| 123 | + rewardsCoordinatorImpl.MAX_RETROACTIVE_LENGTH(), |
| 124 | + Env.MAX_RETROACTIVE_LENGTH(), |
| 125 | + "MAX_RETROACTIVE_LENGTH mismatch" |
| 126 | + ); |
| 127 | + assertEq( |
| 128 | + rewardsCoordinatorImpl.MAX_FUTURE_LENGTH(), |
| 129 | + 63_072_000, |
| 130 | + "MAX_FUTURE_LENGTH should be 730 days (63072000 seconds)" |
| 131 | + ); |
| 132 | + assertEq( |
| 133 | + rewardsCoordinatorImpl.GENESIS_REWARDS_TIMESTAMP(), |
| 134 | + Env.GENESIS_REWARDS_TIMESTAMP(), |
| 135 | + "GENESIS_REWARDS_TIMESTAMP mismatch" |
| 136 | + ); |
| 137 | + } |
| 138 | + |
| 139 | + /// @dev Validate that the new implementation cannot be initialized (should revert) |
| 140 | + function _validateImplInitialized() internal { |
| 141 | + bytes memory errInit = "Initializable: contract is already initialized"; |
| 142 | + |
| 143 | + RewardsCoordinator rewardsCoordinatorImpl = Env.impl.rewardsCoordinator(); |
| 144 | + |
| 145 | + vm.expectRevert(errInit); |
| 146 | + rewardsCoordinatorImpl.initialize( |
| 147 | + address(0), // initialOwner |
| 148 | + 0, // initialPausedStatus |
| 149 | + address(0), // rewardsUpdater |
| 150 | + 0, // activationDelay |
| 151 | + 0 // defaultSplitBips |
| 152 | + ); |
| 153 | + } |
| 154 | + |
| 155 | + /// @dev Validate the version is correctly set |
| 156 | + function _validateVersion() internal view { |
| 157 | + assertEq( |
| 158 | + keccak256(bytes(Env.impl.rewardsCoordinator().version())), |
| 159 | + keccak256(bytes(Env.deployVersion())), |
| 160 | + "RewardsCoordinator version should match deploy version" |
| 161 | + ); |
| 162 | + } |
| 163 | + |
| 164 | + /// @dev Validate new Rewards v2.2 functionality |
| 165 | + function _validateNewFunctionality() internal view { |
| 166 | + RewardsCoordinator rewardsCoordinatorImpl = Env.impl.rewardsCoordinator(); |
| 167 | + |
| 168 | + // The new functions exist (this will fail to compile if they don't exist) |
| 169 | + // Just checking that the contract has the expected interface |
| 170 | + bytes4 createUniqueStakeSelector = rewardsCoordinatorImpl.createUniqueStakeRewardsSubmission.selector; |
| 171 | + bytes4 createTotalStakeSelector = rewardsCoordinatorImpl.createTotalStakeRewardsSubmission.selector; |
| 172 | + |
| 173 | + // Verify the selectors are non-zero (functions exist) |
| 174 | + assertTrue(createUniqueStakeSelector != bytes4(0), "createUniqueStakeRewardsSubmission function should exist"); |
| 175 | + assertTrue(createTotalStakeSelector != bytes4(0), "createTotalStakeRewardsSubmission function should exist"); |
| 176 | + |
| 177 | + // Check new pause constants are defined |
| 178 | + // These are internal constants, so we can't directly access them, but we can verify |
| 179 | + // the contract compiles with them and that the pause functionality would work |
| 180 | + } |
| 181 | + |
| 182 | + /// @dev Validate storage layout changes |
| 183 | + function _validateStorageLayout() internal view { |
| 184 | + // The storage gap was reduced from 35 to 33 slots to accommodate the new mappings: |
| 185 | + // - isUniqueStakeRewardsSubmissionHash (1 slot) |
| 186 | + // - isTotalStakeRewardsSubmissionHash (1 slot) |
| 187 | + // This validation ensures the contract is compiled with the expected storage layout |
| 188 | + |
| 189 | + // We can't directly access the storage gap, but we can ensure the contract |
| 190 | + // compiles and deploys successfully, which validates the storage layout is correct |
| 191 | + RewardsCoordinator rewardsCoordinatorImpl = Env.impl.rewardsCoordinator(); |
| 192 | + |
| 193 | + // Verify we can access the existing public mappings |
| 194 | + // This validates that storage layout hasn't been corrupted |
| 195 | + |
| 196 | + // Check that we can call view functions that access storage |
| 197 | + address testAvs = address(0x1234); |
| 198 | + bytes32 testHash = keccak256("test"); |
| 199 | + |
| 200 | + // These calls should not revert, validating storage is accessible |
| 201 | + bool isRewardsSubmission = rewardsCoordinatorImpl.isAVSRewardsSubmissionHash(testAvs, testHash); |
| 202 | + bool isOperatorDirected = rewardsCoordinatorImpl.isOperatorDirectedAVSRewardsSubmissionHash(testAvs, testHash); |
| 203 | + bool isOperatorSet = |
| 204 | + rewardsCoordinatorImpl.isOperatorDirectedOperatorSetRewardsSubmissionHash(testAvs, testHash); |
| 205 | + bool isUniqueStake = rewardsCoordinatorImpl.isUniqueStakeRewardsSubmissionHash(testAvs, testHash); |
| 206 | + bool isTotalStake = rewardsCoordinatorImpl.isTotalStakeRewardsSubmissionHash(testAvs, testHash); |
| 207 | + |
| 208 | + // All should be false for a random hash |
| 209 | + assertFalse(isRewardsSubmission, "Random hash should not be a rewards submission"); |
| 210 | + assertFalse(isOperatorDirected, "Random hash should not be operator directed"); |
| 211 | + assertFalse(isOperatorSet, "Random hash should not be operator set"); |
| 212 | + assertFalse(isUniqueStake, "Random hash should not be unique stake"); |
| 213 | + assertFalse(isTotalStake, "Random hash should not be total stake"); |
| 214 | + } |
| 215 | +} |
0 commit comments