Skip to content
Smart contracts Audit finding Advanced

Replace old_sum_bias by old_bias

A one-line arithmetic mistake in the gauge controller used the wrong variable as the floor in an underflow-protection calculation for the total bias. In edge cases where total voting power was near zero, this could cause an underflow that prevented a user from voting, though the error would generally recover over time.

Franfran Follow

Originally disclosed on Code4rena

Submitted by Franfran

Note: This audit was preceded by a Code4rena Test Coverage competition. While auditing was not the purpose of the testing phase, relevant and valuable findings reported during that phase were eligible to be judged. This finding [M-03] was discovered during that period and is being included here for completeness.

diff --git a/src/GaugeController.sol b/src/GaugeController.sol
index 68b832a..1794639 100644
--- a/src/GaugeController.sol
+++ b/src/GaugeController.sol
@@ -250,7 +250,7 @@ contract GaugeController {
         uint256 old_sum_slope = points_sum[next_time].slope;

         points_weight[_gauge_addr][next_time].bias = Math.max(old_weight_bias + new_bias, old_bias) - old_bias;
-        points_sum[next_time].bias = Math.max(old_sum_bias + new_bias, old_sum_bias) - old_bias;
+        points_sum[next_time].bias = Math.max(old_sum_bias + new_bias, old_bias) - old_bias;
         if (old_slope.end > next_time) {
             points_weight[_gauge_addr][next_time].slope =
                 Math.max(old_weight_slope + new_slope.slope, old_slope.slope) -

OpenCoreCH (veRWA) confirmed and commented:

This was discovered during the testing contest and fixed before the auditing contest.

alcueca (Judge) commented:

@OpenCoreCH, since the warden didn’t really submit a report, would you be so kind as to explain the impact of this bug?

OpenCoreCH (veRWA) commented:

The Math.max there is an underflow protection for points_sum[next_time]. This wrong implementation would have lead to an underflow in some edge cases (points_sum is near 0 / low, i.e. there is not a lot of voting power in the system), preventing votes for the user. Because old_bias decreases over time (and eventually reaches 0), the error would generally have been recoverable, but it could have taken some time.


The original report as published on Code4rena, by Franfran. Images and videos are our own copies; raw HTML is shown as text. View it on Code4rena.

Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.

How it worked

Root cause

Likely a copy-paste error: the total-bias line reused the per-gauge variable `old_bias` instead of the total variable `old_sum_bias` inside the underflow-protection expression.

Impact

In edge cases with very low total voting power, an underflow could occur and prevent the user from voting; the error would generally have been recoverable as the bias decayed, but it could have taken some time.

What the attacker needed

Total voting power near zero

The fix

The line was changed to use `old_sum_bias` as the floor, and the project says it was fixed before the auditing contest.

Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.

Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.

The contract tracks voting power with numbers that must never go below zero. A safety check was meant to stop that happening, but it compared against the wrong value, so in rare situations the number could wrap around to a huge value instead. That would block a user's vote until the value naturally decayed back down.

What is Smart contracts?

Flaws in on-chain code that let an attacker drain funds, freeze them or break the protocol's accounting.

More by Franfran

View all

14 more disclosed reports, best first.

More from veRWA

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Smart contract vulnerabilities

The lesson behind this report.

Flaws in on-chain code that let an attacker drain funds, freeze them or break the protocol's accounting.