Post-proposal vote quorum/threshold checks use a stale total supply value
Source: https://github.com/sherlock-audit/2024-01-olympus-on-chain-governance-judging/issues/102
Found by
IllIllI, hals
Summary
The pessimistic vote casting approach stores its cutoffs based on the total supply during proposal creation, rather than looking up the current value for each check.
Vulnerability Detail
gOHM token holders can delegate their voting rights either to themselves or to an address of their choice. Due to the elasticity in the gOHM supply, and unlike the original implementation of Governor Bravo, the Olympus governance system relies on dynamic thresholds based on the total gOHM supply. This mechanism sets specific thresholds for each proposal, based on the current supply at that time, ensuring that the requirements (in absolute gOHM terms) for proposing and executing proposals scale with the token supply.
https://github.com/sherlock-audit/2024-01-olympus-on-chain-governance/tree/main/bophades/audit/2024-01_governance#olympus-governor-bravo-implementation
The above means that over time, due to dynamic minting and burning, the total supply will be different at different times, whereas the thresholds/quorums checked against are solely the ones set during proposal creation.
Impact
DoS of the voting system, preventing proposals from ever passing, under certain circumstances
Consider the case of a bug where there is some sort of runaway death spiral bug or attack in the dymamic burning of gOHM (e.g. opposite of Terra/Luna), and the only fix is to pass a proposal to disable the module(s) causing a problem where everyone is periodically having their tokens burn()-from-ed. At proposal creation there are sufficient votes to pass the threshold, but after the minimum 3-day waiting period, the total supply has been halved, and the original proposer no longer has a sufficient quorum to execute the proposal (or some malicious user decides to cancel it, and there is no user for which isWhitelisted() returns true). No proposal can fix the issue, since no proposal will have enough votes to pass, by the time it's time to vote. Finally, once the total supply reaches low wei amounts, the treasury can be stolen by any remaining holders, due to loss of precision:
getProposalThresholdVotes(): min threshold is 1_000, so if supply is <100, don't need any votes to pass anythinggetQuorumVotes(): quorum percent is hard-coded to 20_000 (20%), so if supply drops below 5, quorum is zerogetHighRiskQuorumVotes(): high percent is hard-coded to 30_000 (30%), so if supply drops below 4, quorum is zero for high risk
Code Snippet
The quorum comes from the total supply...
// File: src/external/governance/GovernorBravoDelegate.sol : GovernorBravoDelegate.getHighRiskQuorumVotes() #1
698 function getQuorumVotes() public view returns (uint256) {
699 return (gohm.totalSupply() * quorumPct) / 100_000;
700 }
...
706 function getHighRiskQuorumVotes() public view returns (uint256) {
707 return (gohm.totalSupply() * highRiskQuorum) / 100_000;
708: }
...and is set during propose(), and checked as-is against the eventual vote:
// File: src/external/governance/GovernorBravoDelegate.sol : GovernorBravoDelegate.getVoteOutcome() #2
804 } else if (
805 (proposal.forVotes * 100_000) / (proposal.forVotes + proposal.againstVotes) <
806 @> approvalThresholdPct ||
807 @> proposal.forVotes < proposal.quorumVotes
808 ) {
809 return false;
810: }
Tool used
Manual Review
Recommendation
Always calculate the quorum and thresholds based on the current gohm.totalSupply() as is done in the OZ implementation, and consider making votes based on the fraction of total supply held, rather than a raw amount, since vote tallies are affected too
Discussion
0xLienid
If votes are locked in at a maximum of the value a voter had at the time the proposal started I don't think it makes sense to use the current totalSupply at proposal queueing to determine success/meeting quorum. you want it to be a comparable value to the votes values, hence lock it in at proposal creation
IllIllI000
Since the votes are locked in at the proposal start, then shouldn't the quorum be based on the total supply at that starting block, in order to have a comparable value? Right now the code is consistent with the proposal time only, which may have a vastly different total supply. Shouldn't the code always be consistent with total supply of whichever block is being checked? The votes would still be at the time of the start of voting, but when determining whether a proposal should be queueable/executable/cancelable, if everyone's token counts and the total supply has be halved, there has been no change in who logically would be best positioned to vote, but since the code compares against a stored raw value rather than a ratio, the proposal can fail through no fault of the proposer. They would be able to propose a new vote but be unable to use their old proposal, even though the ownership percentage is the same as before.
nevillehuang
@0xLienid I think @IllIllI000 highlights a valid scenario where this can cause a significant issue, and makes a good point as to why OZ implements quorums and thresholds computation that way.
However, I can also see how this is speculating on emergency situations etc.., but I think in the context of a governance, it is reasonable given it is where sensitive actions are performed. @Czar102 What do you think of this?
0xLienid
I just don't agree that you want the quorum to be subject to deviations in supply during the voting period. It allows user manipulation of the ease/difficulty required to pass a proposal.
shouldn't the quorum be based on the total supply at that starting block, in order to have a comparable value?
yes, but that's impossible with gOHM
Frankly, I feel like if there is a critical bug in the core voting token then it's pretty expected that the governance system is also broken.
The only tenable option I guess is getting rid of the pessimistic voting.
0xLienid
@nevillehuang @IllIllI000 Do you guys have additional thoughts on this? I'm trying to think about how severe it actually is, and if there's any path to fixing it other than using the live total supply which feels more or less similar to using votes not pinned to a block which is bad.
IllIllI000
@0xLienid When you say it's impossible with gOHM, I believe you mean that once the starting block has passed, that there's no way to get the total supply from that prior block. If that's what you meant, in order to get the total supply at the starting block, you could require that the proposal creator actually trigger the start of voting (within some grace period) with another transaction at some point after the projected start block based on the delay, and have that operation update the stored quorums and start block at that point, assuming that the old quorums are still valid. In reality, the proposer controls the block during which the start occurs anyway, since the proposal block is under their control, and the delay is known.
As for the remainder of the issue, I'm not familiar with all that is planned, but I don't think it would have to be a bug in the core voting token itself - it could be a kernel module that has a role that allows it to mint/burn gOHM, given some algorithm with a time delay. Once things are decentralized, it's difficult to be able to predict that that won't happen. You could create a new gOHM that checkpoints the prior total supply, and migrate the old token, but yeah, that would be a big change, and would likely require larger changes than can be done for this contest.
nevillehuang
Actually @IllIllI000 will there even ever be a situation where gOHM would be burned to literal 100, 5 and 4 given gOHM holds 18 decimals? I think on second look this is low severity, given the protocol can easily just implement a sanity check where they block any proposals creation/execution/queue and allow cancellation once totalSupply reaches this extreme small values.
I'm guessing your issue also points to the possible decrease in absolute quorums not just solely small amounts, but I think that example is not realistic and representative enough. Or am I missing a possible scenario where gOHM supply can reach literal small weis of value?
@0xLienid maybe a possible fix would be to make quorum percentages adjustable? This could open to front-running attacks though so I'll have to think through it more.
IllIllI000
@nevillehuang the 100/5/4 scenario is the end point after which everything can get stolen. Prior to that, this bug outlines that they can't stop an ongoing attack because creating a proposal to do so would never pass quorums due to the bug. This bug essentially was an elaboration of the issue described in the duplicate #74, to show that it's an issue with the underlying mechanics, rather than a one-time total supply discrepancy
nevillehuang
@IllIllI000 Yup that is my initial thoughts as well, sorry that I got confused by that scenario. I will likely maintain this issue as medium severity, and facilitate discussions between us and sponsor for a potential fix, since it seems to be non trivial.
0xLienid
Ok @IllIllI000 @nevillehuang just talked with the other devs for a bit and here's what we came up with.
- Separate out proposal activation to another function so we can snapshot total supply more accurately
- Set a minimum total supply such that proposing/queuing/executing ends up in the hands of an admin (and block the standard behavior for end users) if we fall below that. If you think about a burn bug of this magnitude it's a critical implosion of the protocol and so it makes sense to not rely on full on chain governance
Thoughts?
IllIllI000
By activation, you mean the triggering of the start of voting like I described above, or do you mean something else? The docs mention a veto guardian that will eventually be set to the zero address. If there is a new admin for this case, it won't be able to do the same sort of relinquishment without having the end result of the attack being a locked treasury (assuming there's no governance bypass to access funds some other way). If that's acceptable, I believe your two changes will solve the issue.
0xLienid
Yep, triggering of the start of voting.
0xrusowsky
@IllIllI000 ready for review
RealLTDingZhen
I thought about this issue while the contest was going on and didn't submit it, because I thought it's a design choice——Due to the highly variable totalsupply of gOHM, the proposer may need far more tokens than its initial amount to ensure that the proposal is not canceled, and opponents can use fewer votes to reject the proposal by mint more gOHM. By the way, the solution given by LSR is flawed——Attackers can manipulate totalsupply to cancel the proposer's proposal through flashloan.
IllIllI000
The PR implements part of the discussed changes. There is a new gOHM total supply threshold, under which only emergency votes are allowed. The level is correctly many orders of magnitude above the levels at which quorums have loss of precision. Calls to propose() are prevented when the total supply falls below the cutoff. A new emergencyPropose() is added, which can only be called during emergencies, by the veto guardian. It does not have any threshold requirements, or any limit to the number of outstanding proposals (both good), and does not update latestProposalIds (ok). Besides those differences, the code looks like propose(). For propose() the end block and quorum are no longer initially set, and require the user to call activate() to set them instead. The activate() function requires a non-emergency, pending state, for the start block to have been passed, and to not have been activated before. The proposal can be reentrantly re-activated in the same way #62, but there aren't any negative effects outside of extra events. There is no cut-off of when a proposal can be activated, which may allow proposals to stay dormant for years, until they're finally activated. activate() cannot be called during emergencies, so proposals created before an emergency will expire if things don't get resolved. This also means emergencyPropose() does not require activation or any actual votes - just that delays have been respected (seems to be intended behavior). The execute() function does not require any specific state during emergencies for the veto admin, but timelock.executeTransaction() prevents calling it multiple times. The state() function has a new state for Emergency, which applies to any proposal created by the veto admin via emergencyPropose().
Bug Med: the proposal.proposalThreshold isn't updated during activate(), which can be many years after the initial proposal.
Bug Low: extra events if reentrantly called
Bug Low: emergency proposals (more than one is allowed) created during one emergency, can be executed during a later emergency
0xLienid
Refix: https://github.com/OlympusDAO/bophades/pull/334
We added a activation grace period (which is checked in the state call) so that proposals cannot sit unactivated for months or years. We believe this sufficiently reduces the proposalThreshold concern. We chose not to update the proposalThreshold at the time of activation with this added check because it feels backwards from a governance perspective to brick someone's proposal after proposing if their balance has not changed.
We also shifted certain components of the proposal struct modification above the _isHighRiskProposalCheck to prevent reentrancy.
IllIllI000
The PR correctly addresses the Medium and one of the Lows from item 7 of 9 of the prior review, while leaving the remaining Low about emergency proposals being able to be used across emergencies.
The extra events issue is fixed by moving up the state variable assignments to above the high risk proposal checks.
The Medium is addressed by introducing a new state variable to GovernorBravoDelegateStorageV1, rather than to GovernorBravoDelegateStorageV2, for a grace period. There is no setter for the variable, so it must be set during the call to initialize() as the penultimate argument, which is properly done, or by creating a new implementation with a setter function. The initialize() call bounds the value within reasonable limits.
The min amount is set to 17280, which is 2.4 days, and the max is set to 50400, which is exactly 7 days.
The state() function is properly changed to convert Pending to Expired, after the activation grace period. The code reverts with GovernorBravo_Vote_Closed() when activation is attempted after the grace period.
The PR adds tests for the grace period and for the reentrancy issue
With the death spiral issue and the activation grace period issue resolved, the issue of the total supply changing has been mitigated to low.
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
What is known
A medium-severity business logic bug in Olympus On-Chain Governance. Sherlock made it public on 31 January 2024. Found in the 155 audit contest (finding M-3), also found by 1 other warden.
About Business logic
The application works as coded but not as intended: a negative price, a skipped payment step, a limit that can be crossed.
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
What is Business logic?
The application works as coded but not as intended: a negative price, a skipped payment step, a limit that can be crossed.