Skip to content
Business logic Audit finding Intermediate

veCVXStrategy.manualRebalance has wrong logic

The manualRebalance function in veCVXStrategy compares two values that represent different things: a percentage and a token amount. This broken comparison causes the rebalancing logic to lock nearly all tokens when the total balance is high.

cmichel Follow

Originally disclosed on Code4rena

Submitted by cmichel, also found by tabish

The veCVXStrategy.manualRebalance function computes two ratios currentLockRatio and newLockRatio and compares them.

However, these ratios compute different things and are not comparable:

  • currentLockRatio = balanceInLock.mul(10**18).div(totalCVXBalance) is a percentage value with 18 decimals (i.e. 1e18 = 100%). Its max value can at most be 1e18.
  • newLockRatio = totalCVXBalance.mul(toLock).div(MAX_BPS) is a CVX token amount. It’s unbounded and just depends on the totalCVXBalance amount.

The comparison that follows does not make sense:

if (newLockRatio <= currentLockRatio) {
  // ...
}

Impact

The rebalancing is broken and does not correctly rebalance. It usually leads to locking nearly everything if totalCVXBalance is high.

Recommended Mitigation Steps

Judging from the cvxToLock = newLockRatio.sub(currentLockRatio) it seems the desired computation is that the “ratios” should actually be in CVX amounts and not in percentages. Therefore, currentLockRatio should just be balanceInLock. (The variables should be renamed as they aren’t really ratios but absolute CVX balance amounts.)

GalloDaSballo (BadgerDAO) acknowledged:

Agree with the finding, the math is wrong

GalloDaSballo (BadgerDAO) confirmed:

We will mitigate by deleting the function and using manualRebalance and manualSendbCVXToVault as way to manually rebalance

GalloDaSballo (BadgerDAO) patched:

We mitigated by rewriting the code for manualRebalance

The original report as published on Code4rena, by cmichel. 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

The code compares a percentage value (scaled to 18 decimals) with an absolute token amount, which are not comparable.

Impact

The rebalancing is broken and usually locks nearly all tokens when the total balance is high.

What the attacker needed

None

The fix

The function was rewritten to fix the logic, as confirmed by the developer.

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.

This smart contract has a function that is supposed to adjust how many tokens are locked. It calculates two numbers to compare, but one is a percentage and the other is a raw token amount, so the comparison is meaningless. As a result, the function often locks almost all tokens instead of balancing them.

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.

More by cmichel

View all

196 more disclosed reports, best first.

More from bveCVX by BadgerDAO contest

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Business logic flaws

The lesson behind this report.

The application works as coded but not as intended: a negative price, a skipped payment step, a limit that can be crossed.