-
Notifications
You must be signed in to change notification settings - Fork 0
ops(script): rehearse the timelock before governance moves to it #306
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,107 @@ | ||
| // SPDX-License-Identifier: LicenseRef-DCL-1.0 | ||
| // SPDX-FileCopyrightText: Copyright (c) 2020 Rain Open Source Software Ltd | ||
| pragma solidity =0.8.25; | ||
|
|
||
| import {Script} from "forge-std-1.16.1/src/Script.sol"; | ||
| import {console2} from "forge-std-1.16.1/src/console2.sol"; | ||
| import {IAccessControl} from "@openzeppelin-contracts-5.6.1/access/IAccessControl.sol"; | ||
| import {TimelockController} from "@openzeppelin-contracts-5.6.1/governance/TimelockController.sol"; | ||
|
|
||
| import {LibSafeInvariants} from "../src/lib/LibSafeInvariants.sol"; | ||
| import {LibTimelockInvariants} from "../src/lib/LibTimelockInvariants.sol"; | ||
| import {LibTimelockRehearsal} from "../src/lib/LibTimelockRehearsal.sol"; | ||
|
|
||
| /// @notice The active chain's governance-timelock pin is unhydrated. | ||
| /// @param chainId The active chain id. | ||
| error ExecuteTimelockNotPinned(uint256 chainId); | ||
|
|
||
| /// @notice The operation is not in a state this script can execute: it is | ||
| /// unknown, already done, or still waiting out its delay. | ||
| /// @param id The operation id. | ||
| /// @param pending Whether the timelock reports it pending. | ||
| /// @param ready Whether the timelock reports it ready. | ||
| /// @param done Whether the timelock reports it done. | ||
| error OperationNotExecutable(bytes32 id, bool pending, bool ready, bool done); | ||
|
|
||
| /// @notice Execution is not open on this timelock, so the CI deploy key — | ||
| /// which holds no roles — cannot execute. Surfaced by name because the whole | ||
| /// point of this script is that it needs no privilege. | ||
| /// @param timelock The timelock inspected. | ||
| error ExecutionNotPermissionless(address timelock); | ||
|
|
||
| /// @title ExecuteTimelockOperations | ||
| /// @notice **PENDING.** Executes a matured timelock operation from the CI | ||
| /// deploy key. | ||
| /// | ||
| /// This is deliberately NOT a Safe-routed script. The timelock grants | ||
| /// `EXECUTOR_ROLE` to `address(0)`, so once an operation's delay has run | ||
| /// ANYONE may execute it. Driving execution from the CI deploy key — a key | ||
| /// that holds no role on the timelock, the authoriser or any vault — is the | ||
| /// most direct demonstration that the property is real: if this succeeds, | ||
| /// execution is genuinely permissionless and the operator cannot censor a | ||
| /// matured operation. | ||
| /// | ||
| /// Dispatch via `Actions → manual-broadcast` with | ||
| /// `script = 20260813-execute-timelock-operations` and the target `network`. | ||
| /// | ||
| /// ## Which operation | ||
| /// | ||
| /// OZ's `TimelockController` stores only a timestamp per operation id; it | ||
| /// keeps no enumerable list, so "every outstanding proposal" cannot be read | ||
| /// from contract state alone — recovering it would mean indexing | ||
| /// `CallScheduled` logs. Rather than pretend otherwise, this script executes | ||
| /// operations it can RECONSTRUCT, and asserts their state before acting. | ||
| /// Today that is the rehearsal no-op defined in `LibTimelockRehearsal`, | ||
| /// whose parameters are fixed and shared with the scripts that schedule and | ||
| /// cancel it, so the three cannot drift onto different ids. A future | ||
| /// operation is added by appending its reconstruction here, which also keeps | ||
| /// the executor honest: it can only ever run something whose full calldata is | ||
| /// committed in this repo and therefore reviewable. | ||
| /// | ||
| /// @dev Pre-flight asserts the timelock's pinned configuration AND that | ||
| /// execution is open, so a timelock whose executor role had been closed | ||
| /// fails by name rather than as an opaque `AccessControl` revert. | ||
| contract ExecuteTimelockOperations is Script { | ||
| /// @notice Execute the rehearsal operation on the active chain if it has | ||
| /// matured. Broadcasts from the CI deploy key, which holds no roles. | ||
| function run() external { | ||
| address safe = LibSafeInvariants.assertActiveChainTokenOwnerSafe(block.chainid); | ||
| address timelock = LibTimelockInvariants.timelockForChainId(block.chainid); | ||
| if (timelock == address(0)) revert ExecuteTimelockNotPinned(block.chainid); | ||
| LibTimelockInvariants.assertTimelockState(timelock, safe); | ||
|
|
||
| // The property this script depends on, asserted rather than assumed. | ||
| if (!IAccessControl(timelock).hasRole(LibTimelockInvariants.TIMELOCK_EXECUTOR_ROLE, address(0))) { | ||
| revert ExecutionNotPermissionless(timelock); | ||
| } | ||
|
|
||
| TimelockController controller = TimelockController(payable(timelock)); | ||
| bytes memory payload = LibTimelockRehearsal.payload(); | ||
| bytes32 id = LibTimelockRehearsal.operationId(timelock); | ||
|
|
||
| bool pending = controller.isOperationPending(id); | ||
| bool ready = controller.isOperationReady(id); | ||
| bool done = controller.isOperationDone(id); | ||
| if (!ready) revert OperationNotExecutable(id, pending, ready, done); | ||
|
|
||
| console2.log("Executing matured operation:", vm.toString(id)); | ||
| console2.log("Timelock:", vm.toString(timelock)); | ||
| console2.log("Chain:", block.chainid); | ||
|
|
||
| vm.startBroadcast(); | ||
| address executor = msg.sender; | ||
| controller.execute(timelock, 0, payload, bytes32(0), LibTimelockRehearsal.REHEARSAL_SALT); | ||
| vm.stopBroadcast(); | ||
|
|
||
| require(controller.isOperationDone(id), "ExecuteTimelockOperations: operation did not complete"); | ||
|
|
||
| // The executing key holds no role — that is the point. | ||
| require( | ||
| !IAccessControl(timelock).hasRole(LibTimelockInvariants.TIMELOCK_EXECUTOR_ROLE, executor), | ||
| "ExecuteTimelockOperations: executor unexpectedly holds EXECUTOR_ROLE" | ||
| ); | ||
|
Comment on lines
+96
to
+102
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 📐 Maintainability & Code Quality | 🟡 Minor | ⚡ Quick win Check the executor's roles before broadcasting. The require at Lines 109-112 runs after 🤖 Prompt for AI Agents |
||
|
|
||
| console2.log("Executed by:", vm.toString(executor)); | ||
| console2.log("That address holds no EXECUTOR_ROLE - execution is permissionless"); | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,84 @@ | ||
| // SPDX-License-Identifier: LicenseRef-DCL-1.0 | ||
| // SPDX-FileCopyrightText: Copyright (c) 2020 Rain Open Source Software Ltd | ||
| pragma solidity =0.8.25; | ||
|
|
||
| import {Script} from "forge-std-1.16.1/src/Script.sol"; | ||
| import {console2} from "forge-std-1.16.1/src/console2.sol"; | ||
| import {TimelockController} from "@openzeppelin-contracts-5.6.1/governance/TimelockController.sol"; | ||
|
|
||
| import {IGnosisSafe} from "../src/interface/IGnosisSafe.sol"; | ||
| import {LibSafeInvariants} from "../src/lib/LibSafeInvariants.sol"; | ||
| import {LibSafeOps, SafeTx} from "../src/lib/LibSafeOps.sol"; | ||
| import {LibTimelockInvariants} from "../src/lib/LibTimelockInvariants.sol"; | ||
| import {LibTimelockRehearsal} from "../src/lib/LibTimelockRehearsal.sol"; | ||
|
|
||
| /// @notice The active chain's governance-timelock pin is unhydrated, so | ||
| /// there is nothing to rehearse against. | ||
| /// @param chainId The active chain id. | ||
| error CancelTimelockNotPinned(uint256 chainId); | ||
|
|
||
| /// @notice The rehearsal operation is not pending, so there is nothing to | ||
| /// cancel and the bundle would revert inside the Safe. | ||
| /// @param id The operation id that is not pending. | ||
| error RehearsalNotScheduled(bytes32 id); | ||
|
|
||
| /// @title TimelockRehearsalCancel | ||
| /// @notice **PENDING.** Authors the Safe bundle that CANCELS the scheduled | ||
| /// timelock rehearsal — see `LibTimelockRehearsal` for the operation. | ||
| /// | ||
| /// This is the stage that demonstrates the veto: a scheduled operation can be | ||
| /// stopped inside its window, and OZ's `cancel` has no open-role path, so | ||
| /// vetoing stays privileged even though execution is permissionless. After it | ||
| /// lands, the identical operation becomes schedulable again — re-dispatch | ||
| /// `20260813-timelock-rehearsal-schedule` for the re-propose stage. | ||
| /// | ||
| /// Dispatch via `Actions → run-script` with | ||
| /// `script = 20260813-timelock-rehearsal-cancel` and the target `network`. | ||
| /// | ||
| /// @dev Refuses unless the operation is actually pending, so cancelling | ||
| /// nothing fails at authoring time rather than in the Safe. Post-state | ||
| /// asserts the operation is fully deregistered, which is what makes the | ||
| /// re-propose stage possible. | ||
| contract TimelockRehearsalCancel is Script { | ||
| /// @notice Author the cancel bundle for the active chain. | ||
| function run() external { | ||
| IGnosisSafe safe = IGnosisSafe(LibSafeInvariants.assertActiveChainTokenOwnerSafe(block.chainid)); | ||
| address timelock = LibTimelockInvariants.timelockForChainId(block.chainid); | ||
| if (timelock == address(0)) revert CancelTimelockNotPinned(block.chainid); | ||
| LibTimelockInvariants.assertTimelockState(timelock, address(safe)); | ||
|
|
||
| TimelockController controller = TimelockController(payable(timelock)); | ||
| bytes32 id = LibTimelockRehearsal.operationId(timelock); | ||
| if (!controller.isOperationPending(id)) revert RehearsalNotScheduled(id); | ||
|
|
||
| SafeTx[] memory txs = new SafeTx[](1); | ||
| txs[0] = SafeTx({to: timelock, value: 0, data: LibTimelockRehearsal.cancelCalldata(timelock), operation: 0}); | ||
|
|
||
| uint256 nonce = safe.nonce(); | ||
| bytes32 safeTxHash = LibSafeOps.computeSafeTxHashViaSafe(safe, txs[0], nonce); | ||
|
|
||
| LibSafeOps.simulateExternalCall(safe, txs[0].to, txs[0].data); | ||
|
|
||
| // Fully deregistered: not pending, and not known to the timelock at | ||
| // all — which is what lets the same operation be scheduled again. | ||
| require(!controller.isOperationPending(id), "TimelockRehearsalCancel: still pending after cancel"); | ||
| require(!controller.isOperation(id), "TimelockRehearsalCancel: still registered after cancel"); | ||
|
|
||
| string memory artifactPath = | ||
| string.concat("out/20260813-timelock-rehearsal-cancel-", vm.toString(block.chainid), ".json"); | ||
| string memory json = LibSafeOps.emitTxBuilderJson( | ||
| address(safe), block.chainid, "ST0x timelock rehearsal: cancel the no-op", txs | ||
| ); | ||
| vm.writeFile(artifactPath, json); | ||
|
|
||
| console2.log("==== TX BUILDER JSON BEGIN ===="); | ||
| console2.log(json); | ||
| console2.log("==== TX BUILDER JSON END ===="); | ||
| console2.log("Artifact:", artifactPath); | ||
| console2.log("SafeTxHash:", vm.toString(safeTxHash)); | ||
| console2.log("Nonce:", nonce); | ||
| console2.log("Operation id:", vm.toString(id)); | ||
| console2.log("Chain:", block.chainid); | ||
| console2.log("Cancelled: the same operation is schedulable again - re-dispatch the schedule script"); | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,107 @@ | ||
| // SPDX-License-Identifier: LicenseRef-DCL-1.0 | ||
| // SPDX-FileCopyrightText: Copyright (c) 2020 Rain Open Source Software Ltd | ||
| pragma solidity =0.8.25; | ||
|
|
||
| import {Script} from "forge-std-1.16.1/src/Script.sol"; | ||
| import {console2} from "forge-std-1.16.1/src/console2.sol"; | ||
| import {TimelockController} from "@openzeppelin-contracts-5.6.1/governance/TimelockController.sol"; | ||
|
|
||
| import {IGnosisSafe} from "../src/interface/IGnosisSafe.sol"; | ||
| import {LibSafeInvariants} from "../src/lib/LibSafeInvariants.sol"; | ||
| import {LibSafeOps, SafeTx} from "../src/lib/LibSafeOps.sol"; | ||
| import {LibTimelockInvariants} from "../src/lib/LibTimelockInvariants.sol"; | ||
| import {LibTimelockRehearsal} from "../src/lib/LibTimelockRehearsal.sol"; | ||
|
|
||
| /// @notice The active chain's governance-timelock pin is unhydrated, so | ||
| /// there is nothing to rehearse against. | ||
| /// @param chainId The active chain id. | ||
| error RehearsalTimelockNotPinned(uint256 chainId); | ||
|
|
||
| /// @notice The rehearsal operation is already registered on the timelock, so | ||
| /// scheduling it again would revert inside the Safe transaction. Cancel it | ||
| /// (or execute it) first. | ||
| /// @param id The operation id already registered. | ||
| error RehearsalAlreadyScheduled(bytes32 id); | ||
|
|
||
| /// @notice Executing the scheduled rehearsal changed the timelock's minimum | ||
| /// delay. The rehearsal is a no-op by construction, so a change means the | ||
| /// operation is not the one this script believes it is. | ||
| /// @param expected The delay before execution. | ||
| /// @param actual The delay after. | ||
| error RehearsalChangedMinDelay(uint256 expected, uint256 actual); | ||
|
|
||
| /// @title TimelockRehearsalSchedule | ||
| /// @notice **PENDING.** Authors the Safe bundle that SCHEDULES the timelock | ||
| /// rehearsal no-op — see `LibTimelockRehearsal` for what the operation is and | ||
| /// why it was chosen. | ||
| /// | ||
| /// Dispatch via `Actions → run-script` with | ||
| /// `script = 20260813-timelock-rehearsal-schedule` and the target `network`. | ||
| /// | ||
| /// Re-dispatch this same script for the "re-propose" stage: `cancel` clears | ||
| /// the timestamp, so the identical operation becomes schedulable again, and | ||
| /// that recovery is itself the property worth rehearsing. No separate | ||
| /// re-schedule script exists because there is no separate operation. | ||
| /// | ||
| /// Execution is NOT a Safe action: the timelock grants `EXECUTOR_ROLE` to | ||
| /// `address(0)`, so anyone may execute once the delay has run. | ||
| /// `20260813-execute-timelock-operations` does that from the CI deploy key. | ||
| /// | ||
| /// @dev Pre-flight asserts the Safe's pinned policy and the timelock's pinned | ||
| /// configuration, and refuses if the operation is already registered — so a | ||
| /// stage dispatched out of order fails here rather than in the Safe. The run | ||
| /// then proves the whole loop on the fork: warp past the delay, execute as an | ||
| /// address holding no roles, and confirm the delay is unchanged. | ||
| contract TimelockRehearsalSchedule is Script { | ||
| /// @notice Author the schedule bundle for the active chain. | ||
| function run() external { | ||
| IGnosisSafe safe = IGnosisSafe(LibSafeInvariants.assertActiveChainTokenOwnerSafe(block.chainid)); | ||
| address timelock = LibTimelockInvariants.timelockForChainId(block.chainid); | ||
| if (timelock == address(0)) revert RehearsalTimelockNotPinned(block.chainid); | ||
| LibTimelockInvariants.assertTimelockState(timelock, address(safe)); | ||
|
|
||
| TimelockController controller = TimelockController(payable(timelock)); | ||
| bytes32 id = LibTimelockRehearsal.operationId(timelock); | ||
| if (controller.isOperation(id)) revert RehearsalAlreadyScheduled(id); | ||
|
|
||
| SafeTx[] memory txs = new SafeTx[](1); | ||
| txs[0] = SafeTx({to: timelock, value: 0, data: LibTimelockRehearsal.scheduleCalldata(timelock), operation: 0}); | ||
|
|
||
| uint256 nonce = safe.nonce(); | ||
| bytes32 safeTxHash = LibSafeOps.computeSafeTxHashViaSafe(safe, txs[0], nonce); | ||
|
|
||
| uint256 delayBefore = controller.getMinDelay(); | ||
| LibSafeOps.simulateExternalCall(safe, txs[0].to, txs[0].data); | ||
|
|
||
| // Pending, and NOT executable until the delay has run. | ||
| require(controller.isOperationPending(id), "TimelockRehearsalSchedule: operation not registered"); | ||
| require(!controller.isOperationReady(id), "TimelockRehearsalSchedule: ready before the delay elapsed"); | ||
|
|
||
| // Prove the loop on the fork, executing as an address with no roles — | ||
| // which is what permissionless execution means. | ||
| vm.warp(block.timestamp + LibTimelockInvariants.TIMELOCK_MIN_DELAY); | ||
| require(controller.isOperationReady(id), "TimelockRehearsalSchedule: not ready after the delay"); | ||
| vm.prank(address(uint160(uint256(keccak256("st0x.rehearsal.roleless-executor"))))); | ||
| controller.execute(timelock, 0, LibTimelockRehearsal.payload(), bytes32(0), LibTimelockRehearsal.REHEARSAL_SALT); | ||
| require(controller.isOperationDone(id), "TimelockRehearsalSchedule: execution did not complete"); | ||
| uint256 delayAfter = controller.getMinDelay(); | ||
| if (delayAfter != delayBefore) revert RehearsalChangedMinDelay(delayBefore, delayAfter); | ||
|
|
||
| string memory artifactPath = | ||
| string.concat("out/20260813-timelock-rehearsal-schedule-", vm.toString(block.chainid), ".json"); | ||
| string memory json = LibSafeOps.emitTxBuilderJson( | ||
| address(safe), block.chainid, "ST0x timelock rehearsal: schedule the no-op", txs | ||
| ); | ||
| vm.writeFile(artifactPath, json); | ||
|
|
||
| console2.log("==== TX BUILDER JSON BEGIN ===="); | ||
| console2.log(json); | ||
| console2.log("==== TX BUILDER JSON END ===="); | ||
| console2.log("Artifact:", artifactPath); | ||
| console2.log("SafeTxHash:", vm.toString(safeTxHash)); | ||
| console2.log("Nonce:", nonce); | ||
| console2.log("Operation id:", vm.toString(id)); | ||
| console2.log("Chain:", block.chainid); | ||
| console2.log("Loop proven on fork: schedule -> 48h -> execute BY A ROLELESS ADDRESS -> delay unchanged"); | ||
| } | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
📐 Maintainability & Code Quality | 🟠 Major | ⚡ Quick win
The
ExecutionNotPermissionlessguard is unreachable.LibTimelockInvariants.assertTimelockStatealready asserts the open executor role.src/lib/LibTimelockInvariants.solLines 297-298 call_assertHasRole(acl, timelock, TIMELOCK_EXECUTOR_ROLE, address(0)). That call reverts at Line 81 before Line 84 runs, soExecutionNotPermissionlesscan never be raised and the error declaration at Line 29 is dead.Either drop the duplicate check and the error, or reorder so the named check runs before
assertTimelockState.♻️ Proposed reorder that makes the named error reachable
📝 Committable suggestion
🤖 Prompt for AI Agents