Missing cds deposit amount in swapCollateralForUSDT
The swapCollateralForUSDT function converts leftover collateral to USDT and credits it to the CDS cumulative value but fails to update the total CDS deposit amount. This causes the total deposit amount to be lower than the sum of individual CDS positions, so when a CDS owner tries to withdraw, the subtraction underflows and the transaction reverts.
Source: https://github.com/sherlock-audit/2024-11-autonomint-judging/issues/719
Found by
0x37
Summary
swapCollateralForUSDT() will help to convert the remaining Ether to USDT. This part of upside collateral will be taken as the cds owner's profit. But we miss update the cds deposit amount. This will cause that cds owners fail to withdraw.
Root Cause
In Treasury.sol:804, when ether price increases and borrowers withdraw their collateral, there will be some remaining collateral because of the upside collateral. These remaining collateral will be taken as one part of the cds owner's profit and swapped to USDT.
This part of profit has already updated into the cds cumulative value(profit/loss), but we don't update the total cds deposit amount. This will cause that the total cds deposit amount will be less than cds owners should withdraw.
For example:
- Alice deposits 1000 USDT/USDA into cds.
- Bob borrows some USDA using 1 Ether.
- Ether price increases, Bob repays his debt. There will be some remaining Ether(e.g. 0.01 Ether). We will swap 0.01 Ether to USDT. But the total cds deposit amount is 1000.
- Alice withdraw her position, her expected return amount should be (1000 + 30(cumulative gain) + 50(option fee)). When we try to deduct from totalCdsDepositedAmount, (1000 - (1000 + 30)), this transaction will be reverted.
function swapCollateralForUSDT(
IBorrowing.AssetName asset, // input token
uint256 swapAmount, // input token amt
bytes memory odosAssembledData
) external onlyCoreContracts returns (uint256) {
(bool success, bytes memory result) = odosRouterV2.call{value: asset == IBorrowing.AssetName.ETH ? swapAmount : 0}(odosAssembledData);
}
function withdrawUserWhoNotOptedForLiq(
CDSInterface.WithdrawUserParams memory params,
CDSInterface.Interfaces memory interfaces,
uint256 totalCdsDepositedAmount,
uint256 totalCdsDepositedAmountWithOptionFees
) public returns (CDSInterface.WithdrawResult memory) {
totalCdsDepositedAmount -= params.cdsDepositDetails.depositedAmount;
}
uint256 currentValue = cdsAmountToReturn(
msg.sender,
index,
omniChainData.cumulativeValue,
omniChainData.cumulativeValueSign,
excessProfitCumulativeValue
) - 1; //? subtracted extra 1 wei
// here we change the depositedAmount.
cdsDepositDetails.depositedAmount = currentValue;
uint256 returnAmount = cdsDepositDetails.depositedAmount + optionFees;
Internal pre-conditions
N/A
External pre-conditions
N/A
Attack Path
- Alice deposits 1000 USDT/USDA into cds.
- Bob borrows some USDA using 1 Ether.
- Ether price increases, Bob repays his debt. There will be some remaining Ether(e.g. 0.01 Ether). We will swap 0.01 Ether to USDT. But the total cds deposit amount is 1000.
- Alice withdraw her position, her expected return amount should be (1000 + 30(cumulative gain) + 50(option fee)). When we try to deduct from totalCdsDepositedAmount, (1000 - (1000 + 30)), this transaction will be reverted.
Impact
We miss updating the total cds deposit amount when there is some upside collateral. This may cause cds owners fail to withdraw their positions.
PoC
N/A
Mitigation
After we swap collateral to USDT, we should mint the related USDA and add these to total cds deposit amount.
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 swapCollateralForUSDT function updates the cumulative value for CDS owners but does not increase the totalCdsDepositedAmount, creating a mismatch between the aggregate total and the sum of individual deposit amounts.
Impact
CDS owners may be unable to withdraw their positions because the withdrawal transaction reverts due to the underflow.
What the attacker needed
CDS owner has a deposit; Borrower has a loan with ETH collateral; ETH price increases; Borrower repays debt
The fix
After swapping collateral to USDT, the contract should mint the related USDA and add it to the total CDS deposit amount.
How it was found
- Alice deposits 1000 USDT/USDA into CDS.
- Bob borrows some USDA using 1 Ether as collateral.
- Ether price increases and Bob repays his debt, leaving some remaining Ether (e.g. 0.01 Ether).
- The remaining Ether is swapped to USDT, but the total CDS deposit amount is not updated.
- Alice tries to withdraw her position, expecting her deposit plus cumulative gain and option fee.
- The withdrawal transaction reverts because the contract tries to subtract a larger amount from totalCdsDepositedAmount than it contains.
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 smart contract, a shared total (total CDS deposit amount) is supposed to equal the sum of all individual deposits. Here, when extra profit is added to individual positions, the shared total is not increased by the same amount. Later, when someone withdraws, the contract tries to subtract a larger number from the shared total than it actually holds, which makes the transaction fail.
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.