Submitted by bart1e, also found by 0xDetermination
https://github.com/code-423n4/2023-08-verwa/blob/a693b4db05b9e202816346a6f9cada94f28a2698/src/GaugeController.sol#L91-L114 
https://github.com/code-423n4/2023-08-verwa/blob/a693b4db05b9e202816346a6f9cada94f28a2698/src/GaugeController.sol#L142 
https://github.com/code-423n4/2023-08-verwa/blob/a693b4db05b9e202816346a6f9cada94f28a2698/src/GaugeController.sol#L180 
https://github.com/code-423n4/2023-08-verwa/blob/a693b4db05b9e202816346a6f9cada94f28a2698/src/GaugeController.sol#L189 
https://github.com/code-423n4/2023-08-verwa/blob/a693b4db05b9e202816346a6f9cada94f28a2698/src/GaugeController.sol#L247
_get_weight function is used in order to return the total gauges weight and it also updates past values of the points_weight mapping, if time_weight[_gauge_addr] is less or equal to the block.timestamp. It contains the following loop:
There are two possible scenarios:
The first scenario will always happen naturally, since pt.bias will be the total voting power allocated for some point and since slope is a sum of all users slopes and slopes are calculated in such a way that <SLOPE> * <TIME_TO_END_OF_STAKING_PERIOD> = <INITIAL_BIAS>.
However, it is possible to artificially change points_weight[_gauge_addr][t].bias by calling change_gauge_weight (which can be only called by the governance). It important to notice here, that change_gauge_weight doesnt modify points_weight[_gauge_addr][t].slope
change_gauge_weight does permit to change the weight to a smaller number than its current value, so its both perfectly legal and possible that governance does this at some point (it could be changing the weight to 0 or any other value smaller than the current one).
Then, at some point when _get_weight is called, we will enter the else block because pt.bias will be less than the sum of all users biases (since originally these values were equal, but pt.bias was lowered by the governance). It will set pt.bias and pt.slope to 0.
After some time, the governance may realise that the gauges weight is 0, but should be bigger and may change it to some bigger value.
We will have the situation where points_weight[_gauge_addr][t].slope = 0 and points_weight[_gauge_addr][t].bias > 0.
If this happens and there is any nonzero changes_weight[_gauge_addr] not yet taken into account (for instance in the week after the governance update), then all the functions related to the gauge at _gauge_addr will not work.
Its because, the following functions:
call _get_weight at some point.
Lets see what will happen in _get_weight when its called:
We will enter the if statement, because pt.bias will be > 0 and pt.slope will be 0 (or some small value, if users give their voting power to gauge in the meantime), since it was previously set to 0 in the else statement and wasnt touched when gauges weight was changed by the governance. We will:
However, there could be a user (or users) whose voting power allocation finishes at t for some t not yet handled. It means that changes_weight[_gauge_addr][t] > 0 (and if pt.slope is not 0, then changes_weight[_gauge_addr][t] still may be greater than it).
If this happens, then the integer underflow will happen in pt.slope -= d_slope;. It will now happen in every call to _get_weight and it wont be possible to recover, because:
as they call _get_weight internally. So, it wont be possible to modify pt.slope and pt.bias for any point in time, so the revert will always happen for that gauge. It wont even be possible to remove that gauge.
So, in short, the scenario is as follows:
Note that it is also possible to frontrun the call to change_gauge_weight when the weight is set to a lower value - user with a lot of capital can watch the mempool and if weight is lowered to some value x, he can give a voting power of x to that gauge. Then, right after weight is changed by the governance, he can withdraw his voting power, leaving the gauge with weight = 0. Then, governance will manually increase the weight to recover and DoS will happen as described. So it is only needed that governance decreases gauges weight at some point.
As stated, above the impact is that the entire gauge is useless, voting powers are permanently locked there and its weight is impossible to change, so the impact is high.
In order for this situation to succeed, governance has to decrease weight of some gauge, but I think its very likely, because:
So, it is predicted that gauges weight may be lowered and the protocol does its best to handle it properly, but as I showed, it fails to do so. Hence, I believe that this finding is of High severity, because although it requires governance to perform some action (decrease weight of some gauge), I believe that its likely that governance decides to decrease weight, especially that it is anticipated in the code and edge cases are handled there (and they wouldnt be if we assumed that governance would never allowed them to happen).
Please run the test below. The test shows slightly simplified situation where governance just sets weight to 0 for gauge1, but as Ive described above, it suffices that its just changed to a smaller value and it may drop to 0 naturally as users withdraw their voting power. The following import will also have to be added: import {Test, stdError} from "forge-std/Test.sol";.
VS Code
Perform pt.slope -= d_slope in _get_weight only when pt.slope >= d.slope and otherwise zero it out.
__141345__ (Lookout) commented:
OpenCoreCH (veRWA) confirmed
alcueca (Judge) commented:
