# What is a timelock in smart contracts?

URL: https://shield.quillaudits.com/learn/glossary/timelock/

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](https://chain.link/article/timelock-smart-contract)).

Last updated 3 December 2026. 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](https://docs.openzeppelin.com/contracts/4.x/api/governance)).

**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](https://docs.openzeppelin.com/contracts/4.x/api/governance)).

## 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](https://shield.quillaudits.com/learn/glossary/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](https://docs.openzeppelin.com/contracts/4.x/api/governance)).

## Sources

- [Understanding the timelock smart contract, Chainlink](https://chain.link/article/timelock-smart-contract) · checked 3 December 2026
- [Governance API: TimelockController, OpenZeppelin docs](https://docs.openzeppelin.com/contracts/4.x/api/governance) · checked 3 December 2026
