Wrong state update in `liquidationType1` call
In the liquidationType1 function, the code updates the abondUSDaPool state instead of the usdaGainedFromLiquidation state. As a result, the usdaGainedFromLiquidation value always remains zero, so yield calculations in redeemYields that depend on it always produce zero.
Source: https://github.com/sherlock-audit/2024-11-autonomint-judging/issues/1021
Found by
0x37, CL001, Cybrid, Laksmana, LordAlive, OrangeSantra, ParthMandale, almurhasan, elolpuer, futureHack, nuthan2x, santiellena, valuevalk, wellbyt3
Summary
Not updating usdaGainedFromLiquidation state on liquidationType1 instead abondUSDaPool is being updated.
This will make abond usda ratio from liquidation always == 0. And yields will never be increased/decreased.
Instead, yield from liquidation is sent to abondUSDaPool
Root Cause
updateAbondUSDaPool call instead of updateUSDaGainedFromLiquidation(usdaToTransfer, true) on liquidationType1
Internal pre-conditions
No response
External pre-conditions
No response
Attack Path
The usdaToAbondRatioLiq accounting in redeemYields will always be 0, because treasury.usdaGainedFromLiquidation() will always return 0. Because in liquidationType1, treasury.updateAbondUSDaPool is called instead of treasury.updateUSDaGainedFromLiquidation(usdaToTransfer, true)
borrowLiquidation.liquidationType1 BorrowLib.redeemYields Treasury.updateAbondUSDaPool Treasury.updateUSDaGainedFromLiquidation
function liquidationType1(
address user,
uint64 index,
uint64 currentEthPrice,
uint256 lastCumulativeRate
) internal returns (CDSInterface.LiquidationInfo memory liquidationInfo) {
//////////////////////////////////////
/////////////////////////////////////
// Calculate borrower's debt
uint256 borrowerDebt = ((depositDetail.normalizedAmount * lastCumulativeRate) / BorrowLib.RATE_PRECISION);
uint128 returnToTreasury = uint128(borrowerDebt);
// 20% to abond usda pool
uint128 returnToAbond = BorrowLib.calculateReturnToAbond(depositDetail.depositedAmountInETH, depositDetail.ethPriceAtDeposit, returnToTreasury);
@> treasury.updateAbondUSDaPool(returnToAbond, true);
//////////////////////////////////////
/////////////////////////////////////
}
function redeemYields(
address user,
uint128 aBondAmount,
address usdaAddress,
address abondAddress,
address treasuryAddress,
address borrow
) public returns (uint256) {
// check abond amount is non zewro
if (aBondAmount == 0) revert IBorrowing.Borrow_NeedsMoreThanZero();
IABONDToken abond = IABONDToken(abondAddress);
// get user abond state
State memory userState = abond.userStates(user);
// check user have enough abond
if (aBondAmount > userState.aBondBalance) revert IBorrowing.Borrow_InsufficientBalance();
ITreasury treasury = ITreasury(treasuryAddress);
// calculate abond usda ratio
uint128 usdaToAbondRatio = uint128((treasury.abondUSDaPool() * RATE_PRECISION) / abond.totalSupply());
uint256 usdaToBurn = (usdaToAbondRatio * aBondAmount) / RATE_PRECISION;
// update abondUsdaPool in treasury
treasury.updateAbondUSDaPool(usdaToBurn, false);
// calculate abond usda ratio from liquidation
@> uint128 usdaToAbondRatioLiq = uint128((treasury.usdaGainedFromLiquidation() * RATE_PRECISION) /abond.totalSupply());
@> uint256 usdaToTransfer = (usdaToAbondRatioLiq * aBondAmount) / RATE_PRECISION;
//update usdaGainedFromLiquidation in treasury
treasury.updateUSDaGainedFromLiquidation(usdaToTransfer, false);
//////////////////////////////////////
/////////////////////////////////////
}
function updateAbondUSDaPool( uint256 amount, bool operation) external onlyCoreContracts {
require(amount != 0, "Treasury:Amount should not be zero");
if (operation) {
abondUSDaPool += amount;
} else {
abondUSDaPool -= amount;
}
}
function updateUSDaGainedFromLiquidation( uint256 amount, bool operation) external onlyCoreContracts {
if (operation) {
usdaGainedFromLiquidation += amount;
} else {
usdaGainedFromLiquidation -= amount;
}
}
Impact
updateUSDaGainedFromLiquidation(usdaToTransfer, true) is not done, so the yeild gained from liquidation is updated to abondUSDaPool. Broken core contains the wrong functionality. Yield from liquidation will always be == 0
PoC
No response
Mitigation
call updateUSDaGainedFromLiquidation(usdaToTransfer, true) instead of updateAbondUSDaPool call on borrowLiquidation.liquidationType1
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 the developer called updateAbondUSDaPool instead of updateUSDaGainedFromLiquidation in liquidationType1, so the liquidation yield is credited to the wrong accounting variable.
Impact
The yield gained from liquidation is always zero, so users cannot redeem any liquidation yield, and the core functionality is broken.
What the attacker needed
None
The fix
The code should call updateUSDaGainedFromLiquidation(usdaToTransfer, true) instead of updateAbondUSDaPool in liquidationType1.
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.
A smart contract keeps track of two separate pools of money: one for regular yield and one for yield gained from liquidations. When a liquidation happens, the code mistakenly adds the liquidation yield to the regular pool instead of the liquidation pool. Later, when users try to redeem their liquidation yield, the contract sees the liquidation pool as empty and gives them nothing.
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.