When calling vote_for_gauge_weights
in GaugeController
the changes_sum
are not applied to the next points_sum
#75
Labels
3 (High Risk)
Assets can be stolen/lost/compromised directly
bug
Something isn't working
unsatisfactory
does not satisfy C4 submission criteria; not eligible for awards
Lines of code
https://github.com/code-423n4/2023-08-verwa/blob/a693b4db05b9e202816346a6f9cada94f28a2698/src/GaugeController.sol#L263-L278
https://github.com/code-423n4/2023-08-verwa/blob/a693b4db05b9e202816346a6f9cada94f28a2698/src/GaugeController.sol#L66-L85
Vulnerability details
Impact
Since the reduced
changes_sum
will never be applied to the nextpoints_sum
for the sum of the gaugs, the slope of the sum will always be to flat. This will lead to less rewards distributed to the gauges since when calculating the sum ofbias
it will be higher than it should be resulting in the sum being higher than the total of thebias
of all gauges.Proof of Concept
The variable
changes_sum
is a mapping of time (t) =>"amount that should be deducted from the slope of the sum at time(t)". This deduction from the slope of the sum is necessary because at time t the locks of uses that have voted for gauges are getting unlocked and therefore their voting power is 0. This means the slope their vote added to the sum`s slope needs to be deducted to ensure the right slope for the sum. If this would not happen, the slope of the sum would be to steep resulting in the bias of the sum decreasing to fast.When calling
vote_for_gauge_weights
inGaugeController
, at the end of the function thechanges_sum
for the sum is reduced if the user already had voted for the gauge before.The
chages_sum
values are applied to the corresponding point when calling_get_sum
, deducting them from the slope of the sum. If theold_slope.end
falls at the firstpoints_sum
after the time the functionvote_for_gauge_weights
is called, the decrease of the slope of the sum resulting fromold_slope
was already applied and will not be added to the gaugs slope again. This is because_get_sum
was already called in the function setting thetime_sum
(the time the sum was updated last) to the firstpoints_sum
after the time the functionvote_for_gauge_weights
is called. And only points aftertime_sum
are updated with the correspondingchages_sum
. This will result in a slope for the sum that is more flat than it should be. This makes the bias of the sum bigger than it should be and therefor will lead to less rewards being distributed than the governance has approved.Example:
The next
points_sum
of the gauge after the function is called will be referred to “next point of sum” =NPS
.Alice calls
vote_for_gauge_weights
for a gauge that she has voted before. This means that there is anold slope
that will be applied. Theold_slope
looks like this:In the beginning of
vote_for_gauge_weights
the function_get_sum
is called, updating allpoints_sum
since they were last updated ending in updating the point forNPS
. When updating the point forNPS
, the slope of the sum is reduced by10
sinceold_slope.end
isNPS
andtime_sum
(the last time the sum points were updated) is set toNPS
.The new voting weight Alice is wanting is applied and since
old_slope.end > block.timestamp
thechanges_sum[NPS]
is reduced by 10 to account for the change. But this change will never be applied since even if anyone calls_get_sum
(the only function wherechange_sum
is used) the point atNPS
will not be adjusted sincetime_sum
was set toNPS
and only points aftertime_sum
are adjusted when calling_get_sum
.Tools Used
Manual review
Recommended Mitigation Steps
Check if
old_slope.end
equals the time of the nextpoints_sum
after the function call. If so explicitly adjust the slope of this point by adding theold_slope.slope
to the sum slope to compensate the reduction of the slope before.Assessed type
Other
The text was updated successfully, but these errors were encountered: