Closed code423n4 closed 2 years ago
Agree with the finding, the math is wrong
We will mitigate by deleting the function and usingmanualSendbCVXToVault
as way to manually rebalance
We mitigated by rewriting manualRebalance
following the advice of the warden
duplicat of #47
Handle
tabish
Vulnerability details
manualRebalance
function : a ratio (currentLockRatio
) has been compared to balance (newLockRatio
) https://github.com/code-423n4/2021-09-bvecvx/blob/1d64bd58c7a4224cc330cef283561e90ae6a3cf5/veCVX/contracts/veCVXStrategy.sol#L477 and at another point in the same function subtracted https://github.com/code-423n4/2021-09-bvecvx/blob/1d64bd58c7a4224cc330cef283561e90ae6a3cf5/veCVX/contracts/veCVXStrategy.sol#L488 .1> Expanding on the first one - checking
newLockRatio < = currentLockRatio
is incorrect asnewLockRatio
is the new total amount of CVX to lock in the locker and we are comparing it with a the ratio of (cvx in (locker * 10 **18)/totalCVXBalance). https://github.com/code-423n4/2021-09-bvecvx/blob/1d64bd58c7a4224cc330cef283561e90ae6a3cf5/veCVX/contracts/veCVXStrategy.sol#L477Solution: Instead the
if
should be likeif (newLockRatio <= balanceInLock) {
2> Expanding on the second one - Calculation mistake in calculating cvxToLock in manualRebalance function. https://github.com/code-423n4/2021-09-bvecvx/blob/1d64bd58c7a4224cc330cef283561e90ae6a3cf5/veCVX/contracts/veCVXStrategy.sol#L488
so lets say the total
balanceInLock
= 100 * 1018 weitotalCVXBalance
= 200 * 10*18 weitoLock
= 7_000 thencurrentLockRatio
= 5 1017 andnewLockRatio
= 140 * 10**18 weito calculate the
cvxToLock
in the function on line #488 we do thisuint256 cvxToLock = newLockRatio.sub(currentLockRatio);
which gives an incorrect answer asnewLockRatio
is the total funds to lock into the CVX Locker according to the new ratio.Solution: Therefore cvxToLock should be calculated as
uint256 cvxToLock = newLockRatio.sub(balanceInLock);
Also the variable newLockRatio should be named newLockAmount and currentLockRatio definition and references should be removed from the
manualRebalance
function