Skip to content
Business logic Audit finding Intermediate

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.

0x37 Follow

Originally disclosed on Sherlock

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:

  1. Alice deposits 1000 USDT/USDA into cds.
  2. Bob borrows some USDA using 1 Ether.
  3. 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.
  4. 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.
Solidity
    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);
}
Solidity
    function withdrawUserWhoNotOptedForLiq(
        CDSInterface.WithdrawUserParams memory params,
        CDSInterface.Interfaces memory interfaces,
        uint256 totalCdsDepositedAmount,
        uint256 totalCdsDepositedAmountWithOptionFees
    ) public returns (CDSInterface.WithdrawResult memory) {
        totalCdsDepositedAmount -= params.cdsDepositDetails.depositedAmount;
}
Solidity
        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

  1. Alice deposits 1000 USDT/USDA into cds.
  2. Bob borrows some USDA using 1 Ether.
  3. 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.
  4. 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.

The original report as published on Sherlock, by 0x37. Images and videos are our own copies; raw HTML is shown as text. View it on Sherlock.

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

  1. Alice deposits 1000 USDT/USDA into CDS.
  2. Bob borrows some USDA using 1 Ether as collateral.
  3. Ether price increases and Bob repays his debt, leaving some remaining Ether (e.g. 0.01 Ether).
  4. The remaining Ether is swapped to USDT, but the total CDS deposit amount is not updated.
  5. Alice tries to withdraw her position, expecting her deposit plus cumulative gain and option fee.
  6. 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.

More by 0x37

View all

79 more disclosed reports, best first.

More from Autonomint Colored Dollar V1

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Business logic flaws

The lesson behind this report.

The application works as coded but not as intended: a negative price, a skipped payment step, a limit that can be crossed.