|
| 1 | +// SPDX-License-Identifier: BUSL-1.1 |
| 2 | +pragma solidity ^0.8.12; |
| 3 | + |
| 4 | +import "../Env.sol"; |
| 5 | +import {QueueTaskMailboxUpgrade} from "./2-queueTaskMailboxUpgrade.s.sol"; |
| 6 | +import {Encode} from "zeus-templates/utils/Encode.sol"; |
| 7 | + |
| 8 | +/** |
| 9 | + * @title ExecuteTaskMailboxUpgrade |
| 10 | + * @notice Execute the queued TaskMailbox upgrade after the timelock delay. |
| 11 | + * This completes the upgrade to fix the task replay vulnerability where certificates |
| 12 | + * could be replayed across different tasks directed at the same operator set. |
| 13 | + */ |
| 14 | +contract ExecuteTaskMailboxUpgrade is QueueTaskMailboxUpgrade { |
| 15 | + using Env for *; |
| 16 | + using Encode for *; |
| 17 | + |
| 18 | + function _runAsMultisig() internal override prank(Env.protocolCouncilMultisig()) { |
| 19 | + if (!(Env.isDestinationChain() && Env._strEq(Env.envVersion(), "1.8.0"))) { |
| 20 | + return; |
| 21 | + } |
| 22 | + |
| 23 | + bytes memory calldata_to_executor = _getCalldataToExecutor(); |
| 24 | + TimelockController timelock = Env.timelockController(); |
| 25 | + |
| 26 | + timelock.execute({ |
| 27 | + target: Env.executorMultisig(), |
| 28 | + value: 0, |
| 29 | + payload: calldata_to_executor, |
| 30 | + predecessor: 0, |
| 31 | + salt: 0 |
| 32 | + }); |
| 33 | + } |
| 34 | + |
| 35 | + function testScript() public virtual override { |
| 36 | + if (!(Env.isDestinationChain() && Env._strEq(Env.envVersion(), "1.8.0"))) { |
| 37 | + return; |
| 38 | + } |
| 39 | + |
| 40 | + // 1 - Deploy. The new TaskMailbox implementation has been deployed |
| 41 | + runAsEOA(); |
| 42 | + |
| 43 | + TimelockController timelock = Env.timelockController(); |
| 44 | + bytes memory calldata_to_executor = _getCalldataToExecutor(); |
| 45 | + bytes32 txHash = timelock.hashOperation({ |
| 46 | + target: Env.executorMultisig(), |
| 47 | + value: 0, |
| 48 | + data: calldata_to_executor, |
| 49 | + predecessor: 0, |
| 50 | + salt: 0 |
| 51 | + }); |
| 52 | + |
| 53 | + // 2 - Queue. Check that the operation IS ready |
| 54 | + QueueTaskMailboxUpgrade._runAsMultisig(); |
| 55 | + _unsafeResetHasPranked(); // reset hasPranked so we can use it again |
| 56 | + |
| 57 | + assertTrue(timelock.isOperationPending(txHash), "Transaction should be queued"); |
| 58 | + assertFalse(timelock.isOperationReady(txHash), "Transaction should NOT be ready immediately"); |
| 59 | + assertFalse(timelock.isOperationDone(txHash), "Transaction should NOT be complete"); |
| 60 | + |
| 61 | + // 3 - Warp past the timelock delay |
| 62 | + vm.warp(block.timestamp + timelock.getMinDelay()); |
| 63 | + assertTrue(timelock.isOperationReady(txHash), "Transaction should be ready for execution"); |
| 64 | + |
| 65 | + // 4 - Execute the upgrade |
| 66 | + execute(); |
| 67 | + assertTrue(timelock.isOperationDone(txHash), "v1.8.1 TaskMailbox upgrade should be complete"); |
| 68 | + |
| 69 | + // 5 - Validate the upgrade was successful |
| 70 | + _validateUpgradeComplete(); |
| 71 | + _validateProxyAdmin(); |
| 72 | + _validateProxyConstructor(); |
| 73 | + _validateProxyInitialized(); |
| 74 | + _validateGetMessageHash(); |
| 75 | + } |
| 76 | + |
| 77 | + /// @dev Validate that the TaskMailbox proxy now points to the new implementation |
| 78 | + function _validateUpgradeComplete() internal view { |
| 79 | + address currentImpl = Env._getProxyImpl(address(Env.proxy.taskMailbox())); |
| 80 | + address expectedImpl = address(Env.impl.taskMailbox()); |
| 81 | + |
| 82 | + assertTrue(currentImpl == expectedImpl, "TaskMailbox proxy should point to new implementation"); |
| 83 | + } |
| 84 | + |
| 85 | + /// @dev Validate the proxy's constructor values through the proxy |
| 86 | + function _validateProxyConstructor() internal view { |
| 87 | + TaskMailbox taskMailbox = Env.proxy.taskMailbox(); |
| 88 | + |
| 89 | + // Validate version |
| 90 | + assertEq( |
| 91 | + keccak256(bytes(taskMailbox.version())), |
| 92 | + keccak256(bytes(Env.deployVersion())), |
| 93 | + "TaskMailbox version mismatch" |
| 94 | + ); |
| 95 | + |
| 96 | + // Validate certificate verifiers |
| 97 | + assertTrue( |
| 98 | + taskMailbox.BN254_CERTIFICATE_VERIFIER() == address(Env.proxy.bn254CertificateVerifier()), |
| 99 | + "TaskMailbox BN254_CERTIFICATE_VERIFIER mismatch" |
| 100 | + ); |
| 101 | + assertTrue( |
| 102 | + taskMailbox.ECDSA_CERTIFICATE_VERIFIER() == address(Env.proxy.ecdsaCertificateVerifier()), |
| 103 | + "TaskMailbox ECDSA_CERTIFICATE_VERIFIER mismatch" |
| 104 | + ); |
| 105 | + |
| 106 | + // Validate MAX_TASK_SLA |
| 107 | + assertEq(taskMailbox.MAX_TASK_SLA(), Env.MAX_TASK_SLA(), "TaskMailbox MAX_TASK_SLA mismatch"); |
| 108 | + } |
| 109 | + |
| 110 | + /// @dev Validate that the proxy cannot be re-initialized |
| 111 | + function _validateProxyInitialized() internal { |
| 112 | + bytes memory errInit = "Initializable: contract is already initialized"; |
| 113 | + |
| 114 | + TaskMailbox taskMailbox = Env.proxy.taskMailbox(); |
| 115 | + |
| 116 | + vm.expectRevert(errInit); |
| 117 | + taskMailbox.initialize( |
| 118 | + address(0), // owner |
| 119 | + 0, // feeSplit |
| 120 | + address(0) // feeSplitCollector |
| 121 | + ); |
| 122 | + } |
| 123 | + |
| 124 | + /// @dev Validate that the new getMessageHash function works correctly |
| 125 | + function _validateGetMessageHash() internal view { |
| 126 | + TaskMailbox taskMailbox = Env.proxy.taskMailbox(); |
| 127 | + |
| 128 | + // Test the new getMessageHash function with sample data |
| 129 | + bytes32 taskHash = keccak256("test_task"); |
| 130 | + bytes memory result = abi.encode("test_result"); |
| 131 | + |
| 132 | + // The new implementation should compute messageHash as keccak256(abi.encode(taskHash, result)) |
| 133 | + bytes32 expectedMessageHash = keccak256(abi.encode(taskHash, result)); |
| 134 | + bytes32 actualMessageHash = taskMailbox.getMessageHash(taskHash, result); |
| 135 | + |
| 136 | + assertTrue( |
| 137 | + expectedMessageHash == actualMessageHash, |
| 138 | + "getMessageHash should compute correct message hash with taskHash included" |
| 139 | + ); |
| 140 | + |
| 141 | + // Verify that different tasks with same result produce different message hashes |
| 142 | + bytes32 differentTaskHash = keccak256("different_task"); |
| 143 | + bytes32 differentMessageHash = taskMailbox.getMessageHash(differentTaskHash, result); |
| 144 | + |
| 145 | + assertFalse( |
| 146 | + actualMessageHash == differentMessageHash, |
| 147 | + "Different tasks with same result should produce different message hashes" |
| 148 | + ); |
| 149 | + } |
| 150 | +} |
0 commit comments