Timelock Verification
Make sure that a timelock has been correctly triggered for governance actions
Use Case
Timelocks are a governance mechanism in DeFi protocols that enforce a delay between when a governance action is proposed and when it can be executed. This delay allows the community to review and react to potentially harmful changes.
This assertion prevents:
- Bypassing the timelock mechanism
- Setting timelock delays that are too short
- Changing the timelock admin without proper authorization
- Executing governance actions before the timelock period has expired
This is important because:
- Timelocks provide a buffer against malicious governance actions
- Without proper enforcement, changes could be executed immediately
- Effective timelock periods need to be of appropriate duration
Applicable Protocols
- DeFi lending protocols that use timelocks for parameter updates
- DEX protocols that require timelocked governance for pool parameter changes
- Yield aggregators that use timelocks for strategy updates
- Cross-chain bridges that implement timelocks for security parameters
- DAOs that use timelocks for treasury management and protocol upgrades
Each of these protocol types relies on timelocks to:
- Prevent flash loan attacks through parameter manipulation
- Allow community review of significant protocol changes
- Protect against governance attacks
- Ensure proper security review periods for critical updates
Explanation
The assertion verifies timelock integrity by:
-
Pre-state Verification
- Captures the initial timelock state before any changes
- Records whether the timelock is currently active
-
Post-state Analysis
- Compares the final timelock state after changes
- Verifies that any changes maintain security parameters
-
Parameter Validation
- Ensures timelock delay is within acceptable bounds (1 day to 2 weeks)
- Confirms timelock activation follows proper procedures
The assertion uses these cheatcodes:
forkPreState()
: Captures the initial timelock stateforkPostState()
: Analyzes the final timelock stateregisterStorageChangeTrigger()
: Monitors changes to the timelock storage slot
The implementation performs checks on:
- The timelock’s active status before and after the transaction
- The timelock delay parameters when the timelock is activated
This ensures that:
- Timelock activations use appropriate delay periods
- Security parameters are maintained during governance changes
- Protocol changes follow proper governance procedures
For more information about cheatcodes, see the Cheatcodes Documentation.
Code Example
Note: This code example is maintained in the Phylax Assertion Examples Repository. For a full examples with mock protocol code and tests please refer to the repository.
Testing
To test this assertion:
- Deploy a mock governance contract with timelock functionality
- Create test cases for:
- Valid timelock activation with proper parameters
- Invalid timelock activation with too short delay
- Attempts to bypass timelock entirely
- Verify the assertion correctly identifies valid and invalid states
Assertion Best Practices
- Combine this assertion with Owner Change for comprehensive governance security
- Use appropriate delay bounds based on your protocol’s risk profile