Skip to content
Business logic Audit finding Intermediate

`totalCdsDepositedAmountWithOptionFees` is incorrectly reduced in `CDSLib::withdrawUser()`, leading to stuck option fees

The CDSLib::withdrawUser() function incorrectly reduces totalCdsDepositedAmountWithOptionFees by using optionsFeesToGetFromOtherChain instead of the correct option fee amount, causing option fees to become stuck or miscalculated. An attacker could exploit this to cause underflows in getOptionsFeesProportions(), leading to incorrect fee distribution.

0x73696d616f Follow with 0xe4669da, John44 and 1 other

Originally disclosed on Sherlock

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

Found by

0x73696d616f, 0xe4669da, John44, almurhasan

Summary

totalCdsDepositedAmountWithOptionFees in CDSLib::withdrawUser() is reduced by:

Solidity
totalCdsDepositedAmountWithOptionFees -= (params.cdsDepositDetails.depositedAmount - params.cdsDepositDetails.liquidationAmount + params.optionsFeesToGetFromOtherChain);

This is incorrect as the correct amount to reduce in option fees is params.optionFees - params.optionsFeesToGetFromOtherChain, not optionsFeesToGetFromOtherChain in this chain. As such, depending on the cds amounts of each chain, it will lead to too many/little option fees registered in the local chain, which will lead to stuck option fees.###

Root Cause

In CDSLib.sol:731, totalCdsDepositedAmountWithOptionFees is reduced by the incorrect amount.

Internal pre-conditions

None.

External pre-conditions

None.

Attack Path

  1. Cds depositor withdraws, having option fees, in which params.optionsFeesToGetFromOtherChain is null. Suppose a liquidation happened of 500, deposited amount is 1000 and options fees are 50, the resulting totalCdsDepositedAmountWithOptionFees is :
Solidity
totalCdsDepositedAmountWithOptionFees -= (params.cdsDepositDetails.depositedAmount - params.cdsDepositDetails.liquidationAmount + params.optionsFeesToGetFromOtherChain); = 550 - (1000 - 500 + 0) = 50

Note: for simplicity, it was assumed that the liquidation that happened reduced totalCdsDepositedAmountWithOptionFees by 500, which is not precise but it's an okay approximation for this example. The user withdraws the option fees, but the CDS contract still has the 50 option fees stored in totalCdsDepositedAmountWithOptionFees, even though it is not actually backed.

Impact

As totalCdsDepositedAmountWithOptionFees is 50, but the global totalCdsDepositedAmountWithOptionFees is null (it was correctly decreased), it will lead to incorrect calculations when getting the option fees proportions. For example, if someone deposits 1000 cds and another user deposits borrows (suppose it pays more 50 USD), it will add option fees on deposit. Then, when the borrower withdraws and the cds depositor withdraws, getOptionsFeesProportions() will calculate totalOptionFeesInOtherChain as 1050 - 1100, which underflows.

PoC

See above.

Mitigation

The correct code is:

Solidity
totalCdsDepositedAmountWithOptionFees -= (params.cdsDepositDetails.depositedAmount - params.cdsDepositDetails.liquidationAmount + (params.optionFees - params.optionsFeesToGetFromOtherChain));

The original report as published on Sherlock, by 0x73696d616f. 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 subtracts the wrong variable (optionsFeesToGetFromOtherChain) instead of the correct option fee amount (optionFees - optionsFeesToGetFromOtherChain) when updating totalCdsDepositedAmountWithOptionFees.

Impact

This could lead to stuck option fees and incorrect fee proportion calculations, potentially causing underflows that disrupt the protocol.

What the attacker needed

None

How it was found

  1. A CDS depositor with option fees withdraws, and optionsFeesToGetFromOtherChain is zero.
  2. The withdrawal reduces totalCdsDepositedAmountWithOptionFees by an incorrect amount, leaving extra option fees recorded.
  3. Later, getOptionsFeesProportions() calculates totalOptionFeesInOtherChain using the inflated total, which can underflow.

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.

This is a smart contract bug where a total sum tracking deposited amounts and option fees is updated wrongly when a user withdraws. The wrong update leaves extra fees recorded, which can later cause calculations to fail or funds to be stuck.

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 0x73696d616f

View all

172 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.