You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
contracts: Governor vote weight is read from a live mutable mapping, not snapshotted — weight can increase during an active vote #847
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.
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
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
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.
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
Activity
github-actions commentedon Jun 9, 2026
🎯 Triage report
DecdnGovernor._getVotesreads vote weight fromFeeRouter's live_bytesPerEpochmapping 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
bug,security,highTrace208checkpoints inFeeRouter) are all provided; scope is self-contained withinFeeRouter+DecdnGovernor🔗 Similar issues
💡 Notes and suggestions
Root cause summary
FeeRoutercheckpointswindowEpochsvia_windowEpochsHistory(an OZCheckpointstrace), but does not checkpoint per-operator byte tallies (_bytesPerEpoch[op][e]).DecdnGovernor._cappedServedcallsfeeRouter.bytesInWindow(account, endEpoch, n), which sums the live mapping. SinceendEpoch = timepoint / epochLengthcan 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 epochslashedAtEpoch— used in_slashedInWindowfirstBondedAt— used in_ageRampScaledTwo viable fix paths
Checkpoint per-operator tallies in
FeeRouter(suggested in the issue):mapping(address => Checkpoints.Trace208) private _bytesCheckpointskeyed by operator._recordBytes(op, epoch, bytes)call, write_bytesCheckpoints[op].push(clock(), currentTotal).bytesInWindowAt(address op, uint48 timepoint, uint48 endEpoch, uint8 n)that reads the checkpointed value viaupperLookupRecent.DecdnGovernor._getVotescalls the newAtvariant.Governor-side epoch guard (simpler, may miss edge cases):
_cappedServed, computesafeEndEpoch = (timepoint / epochLength) - 1(only count fully-elapsed epochs). NoFeeRouterchanges required, but loses up to one epoch of weight history and doesn't fix theslashedAtEpoch/firstBondedAtliveness issue.Recommendation: Path 1 is the correct fix; path 2 is a short-term mitigation. Both
slashedAtEpochandfirstBondedAtshould 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→bytesInWindowAtchanges the interface described in ADR 036 §FeeRouter.bytesPerEpoch. The ADR should be updated to reflect the checkpointed API.Sub-task checklist
Checkpoints.Trace208toFeeRouter; update_recordBytesto push on writebytesInWindowAt(address, uint48 timepoint, uint48 endEpoch, uint8 n)inFeeRouterslashedAtEpoch(or derive at snapshot via events) andfirstBondedAtDecdnGovernor._cappedServed/_getVotesto use the snapshotted APIFeeRouterinterfaceAdd this agentic workflows to your repo
To install this agentic workflow, run
fix(contracts): snapshot Governor vote weight to fully-elapsed epochs (…
fix(contracts): enforce per-byte price floor at settlement (#846) (#891)
docs(adr-036): fold amendment into canonical body (#1649)