Treasury will run out of liquidated funds to give to withdrawing users causing withdrawals to fail
The treasury contract caches the amount of liquidated collateral available but never decreases this cached value when funds are withdrawn. As a result, the system believes it has more funds than it actually does, causing withdrawals to fail when the treasury cannot cover the requested amount.
John44 Follow with Ruhum, almurhasan and 1 other
Originally disclosed on Sherlock
Source: https://github.com/sherlock-audit/2024-11-autonomint-judging/issues/799
Found by
John44, Ruhum, almurhasan, pashap9990
Summary
The cached liquidated asset amount is never decreased causing the treasury to believe that it has more funds than it actual does.
Root Cause
In CDSLib.sol:687, it calls getLiquidatedCollateralToGive() with the available liquidated assets set as liquidatedCollateralAmountInWei(x):
// call getLiquidatedCollateralToGive in cds library to get in which assests to give liquidated collateral
(
totalWithdrawCollateralAmountInETH,
params.ethAmount,
weETHAmount,
rsETHAmount,
collateralToGetFromOtherChain
) = getLiquidatedCollateralToGive(
CDSInterface.GetLiquidatedCollateralToGiveParam(
params.ethAmount,
weETHAmount,
rsETHAmount,
interfaces.treasury.liquidatedCollateralAmountInWei(IBorrowing.AssetName.ETH),
interfaces.treasury.liquidatedCollateralAmountInWei(IBorrowing.AssetName.WeETH),
interfaces.treasury.liquidatedCollateralAmountInWei(IBorrowing.AssetName.WrsETH),
interfaces.treasury.totalVolumeOfBorrowersAmountLiquidatedInWei(),
params.weETH_ExchangeRate,
params.rsETH_ExchangeRate
)
);
If the liquidatedCollateralAmountInWei for a token is bigger than the amount of tokens the contract needs, it will simply transfer the whole amount in that single token, see CDSLib.sol:324
function getLiquidatedCollateralToGive(
CDSInterface.GetLiquidatedCollateralToGiveParam memory param
) public pure returns (uint128, uint128, uint128, uint128, uint128) {
// calculate the amount needed in eth value
uint256 totalAmountNeededInETH = param.ethAmountNeeded + (param.weETHAmountNeeded * param.weETHExRate) / 1 ether + (param.rsETHAmountNeeded * param.rsETHExRate) / 1 ether;
// calculate amount needed in weeth value
uint256 totalAmountNeededInWeETH = (totalAmountNeededInETH * 1 ether) / param.weETHExRate;
// calculate amount needed in rseth value
uint256 totalAmountNeededInRsETH = (totalAmountNeededInETH * 1 ether) / param.rsETHExRate;
uint256 liquidatedCollateralToGiveInETH;
uint256 liquidatedCollateralToGiveInWeETH;
uint256 liquidatedCollateralToGiveInRsETH;
uint256 liquidatedCollateralToGetFromOtherChainInETHValue;
// If this chain has sufficient amount
if (param.totalCollateralAvailableInETHValue >= totalAmountNeededInETH) {
// If total amount is avaialble in eth itself
if (param.ethAvailable >= totalAmountNeededInETH) {
liquidatedCollateralToGiveInETH = totalAmountNeededInETH;
// If total amount is avaialble in weeth itself
} else if (param.weETHAvailable >= totalAmountNeededInWeETH) {
// ...
} else if (param.rsETHAvailable >= totalAmountNeededInRsETH) {
// ...
} else {
// ...
}
} else {
// ...
}
return (
uint128(totalAmountNeededInETH),
uint128(liquidatedCollateralToGiveInETH),
uint128(liquidatedCollateralToGiveInWeETH),
uint128(liquidatedCollateralToGiveInRsETH),
uint128(liquidatedCollateralToGetFromOtherChainInETHValue)
);
}
The given amount is then transferred from the treasury, see CDSLib.sol:825:
if (params.ethAmount != 0) {
params.omniChainData.collateralProfitsOfLiquidators -= totalWithdrawCollateralAmountInETH;
// Call transferEthToCdsLiquidators to tranfer eth
interfaces.treasury.transferEthToCdsLiquidators(
msg.sender,
params.ethAmount
);
}
The same thing applies to weETH and wrsETH as well.
The issue is that after a user has withdrawn their funds, the cached available asset amount isn't decreased. In the treasury contract, liquidatedCollateralAmountInWei is only updated in the updateDepositedCollateralAmountInWei() function where the value is increased:
function updateDepositedCollateralAmountInWei(
IBorrowing.AssetName asset,
uint256 amount
) external onlyCoreContracts {
depositedCollateralAmountInWei[asset] -= amount;
liquidatedCollateralAmountInWei[asset] += amount;
}
So even after a user has withdrawn and the actual collateral asset balance has decreased, liquidatedCollateralAmountInWei() will return the same value. That will cause the CDSLib contract to again try to send the full amount in that given token ignoring the fact that the treasury doesn't hold enough funds. When the transfer is executed it will revert, causing the tx to revert and the user's funds to be stuck.
Internal pre-conditions
none
External pre-conditions
none
Attack Path
none
Impact
CDS users who have opted into liquidation won't be able to withdraw their funds.
PoC
No response
Mitigation
The value should be decreased in withdrawUser().
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 cached liquidated collateral amount is not decreased after withdrawals, so the treasury overestimates its available funds.
Impact
CDS users who have opted into liquidation won't be able to withdraw their funds.
What the attacker needed
None
The fix
The value should be decreased in withdrawUser().
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.
In a blockchain system, a smart contract keeps track of how much money it has. Here, the contract's record of available funds is not updated when money is taken out, so it thinks it has more than it really does. When users try to withdraw, the contract attempts to send more than it holds, and the transaction fails, locking user funds.
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.