What is a timelock in smart contracts?

A timelock is a contract that makes privileged actions wait: an action is queued, a minimum delay passes, and only then can it be executed. Placed between the admin of a protocol and its contracts, it gives users and monitors time to read an upgrade or a parameter change and to exit before it takes effect (Chainlink).

Last updated . 2 minute read. By the QuillAudits Team.

How does a timelock work?

The OpenZeppelin TimelockController splits the job into roles: proposers schedule operations, executors run them once the delay has passed, and cancellers can remove them in between. Its minimum delay can only be changed by an operation that goes through the timelock itself, and set as the owner of an Ownable contract it puts every onlyOwner function behind the delay (OpenZeppelin).

A minimal timelock with schedule and execute (illustrative, not audited code) TinyTimelock.sol

// SPDX-License-Identifier: MIT
pragma solidity 0.8.28;

contract TinyTimelock {
    address public immutable admin;
    uint256 public constant DELAY = 2 days; // illustrative: longer than users need to exit
    mapping(bytes32 => uint256) public readyAt;

    constructor(address admin_) {
        admin = admin_;
    }

    function schedule(address target, bytes calldata data) external returns (bytes32 id) {
        require(msg.sender == admin, "not admin");
        id = keccak256(abi.encode(target, data));
        require(readyAt[id] == 0, "already queued");
        readyAt[id] = block.timestamp + DELAY; // visible on chain from now
    }

    function execute(address target, bytes calldata data) external {
        bytes32 id = keccak256(abi.encode(target, data));
        require(readyAt[id] != 0 && block.timestamp >= readyAt[id], "not ready");
        delete readyAt[id];
        (bool ok, ) = target.call(data);
        require(ok, "call failed");
    }
}

Each operation moves through fixed states: unset, pending once it is scheduled, ready when the delay has passed, and done after it runs. A predecessor can make one operation wait for another, and a batch executes its calls atomically (OpenZeppelin).

What should you check on a timelock?

  • Every privileged path goes through it: upgrades, role grants, oracle and fee changes. One admin function outside it makes the delay decorative.
  • Emergency powers, such as pausing, sit outside the delay but can only make the protocol safer, never move funds.
  • The delay is longer than it takes users to notice a queued change and withdraw.
  • Shortening the delay has to wait out the current delay.
  • Executors and cancellers are the accounts you expect, ideally a multisig.

Two settings decide who holds the power. Granting the executor role to the zero address lets anyone run a ready operation, and the optional admin set at deployment should renounce its role once setup is tested, so every later change goes through the delay (OpenZeppelin).

QuillShield is building the security layer between AI and money, so you can keep shipping between audits.

Sign-up is free, and new accounts get $50 in credit, good for up to half of an order.

  1. 1Sign up and import a repo
  2. 2See the exact price before anything is charged
  3. 3Approve it, and the audit starts