Skip to content

Fix: Enforce a Minimum Timelock for Contract Upgrades #699

Description

@jahrulezfrancis

Problem

The contract admin can set the upgrade timelock to zero and execute a new
WASM implementation immediately, defeating the purpose of the timelock
safeguard entirely.

Severity: High
Location: contracts/batch-vesting/src/lib.rs:774-782,1243-1277

Description

set_config writes any supplied Config, including upgrade_timelock,
directly to storage via set_config_internal with no minimum-value check.
propose_upgrade computes execute_at = timestamp() + config.upgrade_timelock,
and execute_upgrade only rejects execution if timestamp() < execute_at.
With upgrade_timelock == 0, execute_at equals the proposal timestamp, so
that check never triggers — the same admin can propose and execute a new
WASM hash in immediate succession, with no window for anyone to react to a
compromised or malicious admin.

Steps to Reproduce

  1. As the current admin, call set_config with upgrade_timelock: 0.
  2. Call propose_upgrade with an arbitrary replacement WASM hash.
  3. Call execute_upgrade — it succeeds immediately since
    timestamp() < execute_at is false when they're equal.

Expected Behavior

Every upgrade should retain a non-bypassable minimum review delay,
regardless of what the admin sets in configuration.

Suggested Fix Approach

Enforce a hard-coded minimum upgrade_timelock in set_config (reject
values below it), or make timelock reductions themselves subject to the
existing timelock delay before taking effect.

Acceptance Criteria

  • set_config rejects (or the contract otherwise prevents) an
    effective upgrade delay below a defined minimum
  • Test confirms execute_upgrade cannot succeed in the same or an
    insufficient interval after propose_upgrade regardless of
    upgrade_timelock value supplied
  • Existing upgrade-flow tests still pass

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions