Skip to content

contracts: Governor vote weight is read from a live mutable mapping, not snapshotted — weight can increase during an active vote #847

Closed

Description

@alpergundogdu

Severity: Medium

Summary

OpenZeppelin Governor calls _getVotes(account, proposalSnapshot, …) with a fixed past timepoint and relies on the returned weight being immutable after the snapshot. DecdnGovernor instead computes weight from FeeRouter's live per-epoch byte mappings, which keep accumulating after the snapshot. This breaks the snapshot invariant: an operator can raise its own already-counted weight mid-vote, and two voters casting at different times can see different totals.

Where

  • DecdnGovernor._cappedServed / _getVotes (contracts/src/DecdnGovernor.sol:207-217, :173-189) compute endEpoch = timepoint / epochLength (fixed at the snapshot) but read feeRouter.bytesInWindow(account, endEpoch, n).
  • FeeRouter.bytesInWindow (contracts/src/FeeRouter.sol:252-262) sums the live _bytesPerEpoch[op][e] mapping. FeeRouter checkpoints only windowEpochs (_windowEpochsHistory), not per-operator byte tallies.
  • slashedAtEpoch and firstBondedAt (_slashedInWindow, _ageRampScaled) are likewise read live.

Mechanism

The snapshot epoch's bucket (_bytesPerEpoch[op][endEpoch]) continues to accumulate after the proposal snapshot. Voting period is 7 days and an epoch is 7 days, so the snapshot epoch can still be "current" for part of the voting window. An operator who settles more bytes during that window — while still inside the snapshot's endEpoch — raises its own counted weight. Different voters see different total/served.

Impact

Vote weight and quorum are not deterministic at the snapshot, violating the core Governor assumption. Independent of the served-byte decoupling issue, but that issue makes this cheap to exploit (inflate bytes during the live vote for ~zero cost).

Suggested fix

Checkpoint per-operator and total byte tallies in FeeRouter (e.g. Trace208 keyed by epoch, read via upperLookupRecent at the snapshot), or have the Governor count only fully-elapsed epochs strictly before the snapshot timepoint.

Notes

Found during a full-repo audit; verified against the contract source.

Activity

  1. added
    kind:bug
    kind:security
    design:economics
    prio:medium
    on Jun 9, 2026
  2. github-actions commented on Jun 9, 2026

    @github-actions

    🎯 Triage report

    DecdnGovernor._getVotes reads vote weight from FeeRouter's live _bytesPerEpoch mapping rather than a checkpointed snapshot value. Because the snapshot epoch's bucket can still be "current" during part of the 7-day voting window (epoch length = 7 days), an operator can keep settling bytes while a vote is live and raise its own already-counted weight. Two voters casting at different times will see different totals, and quorum is non-deterministic — a core violation of the OZ Governor invariant. Found during a full-repo audit with exact line references provided.

    📊 Assessment

    Dimension Value Reasoning
    Type Bug Contract implementation defect — live mutable mapping used where an immutable snapshot is contractually required by OZ Governor
    Labels bug, security, high Security-relevant governance manipulation; vote weight and quorum can be gamed mid-vote; operator-exploitable on-chain
    Coding agent Suitable Exact file/line references, root cause, and a concrete fix strategy (OZ Trace208 checkpoints in FeeRouter) are all provided; scope is self-contained within FeeRouter + DecdnGovernor

    🔗 Similar issues

    💡 Notes and suggestions

    Root cause summary

    FeeRouter checkpoints windowEpochs via _windowEpochsHistory (an OZ Checkpoints trace), but does not checkpoint per-operator byte tallies (_bytesPerEpoch[op][e]). DecdnGovernor._cappedServed calls feeRouter.bytesInWindow(account, endEpoch, n), which sums the live mapping. Since endEpoch = timepoint / epochLength can still equal the active epoch when a vote begins, bytes settled during the voting window are counted.

    Affected state (all read live, not checkpointed)

    • _bytesPerEpoch[op][e] — per-operator byte tally per epoch
    • slashedAtEpoch — used in _slashedInWindow
    • firstBondedAt — used in _ageRampScaled

    Two viable fix paths

    1. Checkpoint per-operator tallies in FeeRouter (suggested in the issue):

      • Add mapping(address => Checkpoints.Trace208) private _bytesCheckpoints keyed by operator.
      • On each _recordBytes(op, epoch, bytes) call, write _bytesCheckpoints[op].push(clock(), currentTotal).
      • Expose a bytesInWindowAt(address op, uint48 timepoint, uint48 endEpoch, uint8 n) that reads the checkpointed value via upperLookupRecent.
      • DecdnGovernor._getVotes calls the new At variant.
    2. Governor-side epoch guard (simpler, may miss edge cases):

      • In _cappedServed, compute safeEndEpoch = (timepoint / epochLength) - 1 (only count fully-elapsed epochs). No FeeRouter changes required, but loses up to one epoch of weight history and doesn't fix the slashedAtEpoch/firstBondedAt liveness issue.

    Recommendation: Path 1 is the correct fix; path 2 is a short-term mitigation. Both slashedAtEpoch and firstBondedAt should also be checkpointed or treated conservatively at the snapshot timepoint.

    Connection to #846: Fix #846 first (or concurrently) to eliminate the cheap byte-inflation vector that makes this bug inexpensive to exploit.

    ADR 036 touch: The fix to FeeRouter.bytesInWindow → bytesInWindowAt changes the interface described in ADR 036 §FeeRouter.bytesPerEpoch. The ADR should be updated to reflect the checkpointed API.

    Sub-task checklist

    • Add per-operator Checkpoints.Trace208 to FeeRouter; update _recordBytes to push on write
    • Expose bytesInWindowAt(address, uint48 timepoint, uint48 endEpoch, uint8 n) in FeeRouter
    • Checkpoint slashedAtEpoch (or derive at snapshot via events) and firstBondedAt
    • Update DecdnGovernor._cappedServed / _getVotes to use the snapshotted API
    • Add governance test: cast two votes at different block times and assert identical weights
    • Update ADR 036 to reflect new FeeRouter interface
    • Address contracts: served-bytes are decoupled from USDC paid — near-free governance vote-weight inflation & quorum griefing (ADR 036) #846 (served-bytes / USDC coupling) to eliminate the low-cost exploit amplifier

    Generated by Agentic Triage for issue #847 · sonnet46 585.8K · ◷

    Add this agentic workflows to your repo

    To install this agentic workflow, run

    gh aw add githubnext/agentics/workflows/issue-triage.md@94ec5db57374c5b04a4b8eef8b4413f9af44d63f
    
  3. self-assigned this
    on Jun 13, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

design:economicskind:bugkind:securityprio:highprio:medium

Type

No type

Fields

Priority

None yet

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions