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.
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 be1e18.newLockRatio = totalCVXBalance.mul(toLock).div(MAX_BPS)is a CVX token amount. It’s unbounded and just depends on thetotalCVXBalanceamount.
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
manualRebalanceandmanualSendbCVXToVaultas way to manually rebalance
GalloDaSballo (BadgerDAO) patched:
We mitigated by rewriting the code for
manualRebalance
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.