Lab: free tools · size first · stock scanner · crypto scanner · journal
Timelock in Smart Contracts Explained
A timelock is a smart contract mechanism that enforces a mandatory waiting period between when a governance action is proposed and when it can be executed. Timelocks give users time to review and react to protocol changes, including exiting their positions if they disagree, before the change takes effect. Timelocks are a critical governance security feature for all DeFi protocols with upgradeable contracts.
A timelock is a smart contract that delays execution of certain actions, such as upgrades or treasury transfers, for a set period after they are queued. The delay gives users time to see a change coming and exit if they disagree. Timelocks are a common safeguard in DeFi governance. A timelock that can be bypassed by an admin key offers much less protection than it appears.
How a timelock works
OpenZeppelin's TimelockController is the common version. Accounts with the proposer role schedule an operation, which is a call to some contract with set data. The operation waits for at least the minimum delay, then anyone with the executor role can run it. Accounts allowed to cancel can kill it while it's waiting. Each operation is identified by a hash of its contents, so what gets executed is exactly what was announced. The timelock usually sits as the owner of the protocol's contracts, so every admin change has to go through it. By default the timelock also administers itself, so even shortening its own delay has to wait out the current one.
How long is long enough
In DeFi governance the delay after a vote is often between 24 and 72 hours. That's enough time for watchers to spot a bad upgrade and for users to pull funds out. A delay of a few hours is close to useless for ordinary users. Check the actual number in the contract, since docs and announcements can lag behind it.
What can undercut it
Watch for an emergency role that can upgrade or move funds without waiting, a guardian that can pause and change settings at once, or proposer and executor roles held by one person's key. A pause button that only freezes things is a fair exception, since it can stop an exploit without changing anyone's balance. When we look at a protocol, we want to see who holds each role and whether the timelock really owns the contracts that hold the money.