Skip to content
Business logic Audit finding Advanced

Incorrect deducted cds deposit amount in withdrawUser

The withdrawUser function deducts the wrong amount from the global total of CDS deposits when a CDS owner who took part in liquidations withdraws. This makes the tracked total incorrect, which the report says affects related calculations and the value returned to CDS owners.

0x37 Follow with valuevalk

Originally disclosed on Sherlock

Source: https://github.com/sherlock-audit/2024-11-autonomint-judging/issues/563

Found by

0x37, valuevalk

Summary

The calculation for totalCdsDepositedAmount in withdrawUser() is incorrect when the cds owners opt in liquidations. This will impact all calculations which are related with omniChainData.totalCdsDepositedAmount.

Root Cause

When cds owners want to withdraw positions, we will try to deduct this position's cds deposit from the omniChainData.totalCdsDepositedAmount. If this cds deposit position is opt in the liquidation, one part of cds deposit has already been used in the liquidation process. So when cds owners want to withdraw, we should [deduct the left deposited amount](https://github.com/sherlock-audit/2024-11-autonomint/blob/main/Blockchain/Blockchian/contracts/lib/CDSLib.sol#L728-L729 from omniChainData.totalCdsDepositedAmount.

The problem is that when we update totalCdsDepositedAmount, we calculate via params.cdsDepositDetails.depositedAmount - params.cdsDepositDetails.liquidationAmount. We should notice that params.cdsDepositDetails.liquidationAmount is not the used liquidation amount from the cds owner. It stands for left liquidation amount for this position.

We should deduct the left deposit amount: depositedAmount - (initialLiquidationAmount - liquidationAmount)

Solidity
    function withdrawUser(
        CDSInterface.WithdrawUserParams memory params,
        CDSInterface.Interfaces memory interfaces,
        uint256 totalCdsDepositedAmount,
        uint256 totalCdsDepositedAmountWithOptionFees,
        mapping(uint128 liquidationIndex => CDSInterface.LiquidationInfo)
            storage omniChainCDSLiqIndexToInfo
    ) public returns (CDSInterface.WithdrawResult memory) {
          CDSInterface.LiquidationInfo memory liquidationData = omniChainCDSLiqIndexToInfo[i];
          uint128 share = (liquidationAmount * 1e10) / uint128(liquidationData.availableLiquidationAmount);
          params.cdsDepositDetails.liquidationAmount -= getUserShare(liquidationData.liquidationAmount, share);
}
Solidity
      totalCdsDepositedAmount -= (params.cdsDepositDetails.depositedAmount - params.cdsDepositDetails.liquidationAmount);
      params.omniChainData.totalCdsDepositedAmount -= (params.cdsDepositDetails.depositedAmount - params.cdsDepositDetails.liquidationAmount);

Internal pre-conditions

N/A

External pre-conditions

N/A

Attack Path

N/A

Impact

omniChainData.totalCdsDepositedAmount will be updated incorrectly. This will cause incorrect cds cumulative value's calculation. Cds owners may get the incorrect return value.

PoC

N/A

Mitigation

Solidity
totalCdsDepositedAmount -= depositedAmount - (initialLiquidationAmount - liquidationAmount);

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 code treats liquidationAmount as the amount already used in liquidations, when it actually represents the amount still remaining, so the subtraction uses the wrong figure.

Impact

The global CDS deposit total is updated incorrectly, which the report says causes wrong cumulative value calculations and may give CDS owners an incorrect return value.

What the attacker needed

CDS owner opted into liquidations; CDS owner withdraws position

The fix

The deduction should subtract the remaining deposit, that is the deposited amount minus the difference between the initial and current liquidation amounts.

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 a running total of how much money all users have deposited. When someone takes their money out, the contract should subtract exactly what that person still has left. Here it subtracts the wrong figure, so the running total drifts away from reality and later maths based on it goes wrong.

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.