Skip to content
Business logic Audit finding Intermediate

excess funds will not always be refunded to borrower when they are withdrawing

When a borrower withdraws and the downside protection is covered by existing CDS funds on the same chain, the ETH sent for cross-chain fees is not refunded. This leads to a loss of funds for the borrower, with no way to recover them from the contract.

0x23r0 Follow with 0x37, 0xAristos and 11 others

Originally disclosed on Sherlock

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

Found by

0x23r0, 0x37, 0xAristos, Audinarey, DenTonylifer, John44, itcruiser00, maxim371, newspacexyz, santiellena, t.aksoy, theweb3mechanic, valuevalk, volodya

Summary

No response

Root Cause

When a borrower calls _withdraw() the funds sent with the call to cover any crosschain transactions is only returned when there the position does not need to be protected on the downside

Solidity
File: borrowing.sol
687:         {if (result.downsideProtected > 0) {
688:             _getDownsideFromCDS(result.downsideProtected, msg.value - fee.nativeFee);
689:         } else {
690:             // Send the remaining ETH to Borrower
691:      @>     (bool sent, ) = payable(toAddress).call{value: msg.value - fee.nativeFee}("");
692:             if (!sent) revert Borrow_TransferFailed();
693:         }

The developer wrongly assumes that provided the result.downsideProtected > 0 then there must be a cross chain call to request funds to cover the downside.

This is not true considering the implementaion of the _getDownsideFromCDS() function as shown below

Solidity
File: borrowing.sol
721:     function _getDownsideFromCDS(
722:         uint128 downsideProtected,
723:         uint256 feeForOFT
724:     ) internal {
725:         if (cds.getTotalCdsDepositedAmount() < downsideProtected) {
726:             // Call the oftOrCollateralReceiveFromOtherChains function in global variables
727:             globalVariables.oftOrCollateralReceiveFromOtherChains{value: feeForOFT}(
728:                 IGlobalVariables.FunctionToDo(3),
729:                 IGlobalVariables.USDaOftTransferData(address(treasury),downsideProtected - cds.getTotalCdsDepositedAmount()),
730:                 // Since we don't need ETH, we have passed zero params
731:                 IGlobalVariables.CollateralTokenTransferData(address(0),0,0,0), 
732:                 IGlobalVariables.CallingFunction.BORROW_WITHDRAW,
733:                 msg.sender
734:             );
735:         } else {
736:             // updating downside protected from this chain in CDS
737:             cds.updateDownsideProtected(downsideProtected);
738:         }
739:         // Burn the borrow amount
740:         treasury.approveTokens(IBorrowing.AssetName.USDa, address(this), downsideProtected);
741:         bool success = usda.contractBurnFrom(address(treasury), downsideProtected);
742:         if (!success) revert Borrow_BurnFailed();
743:     }

Notice that the cross-chain request is invoke only when the current TotalCdsDepositedAmount is not enough to cover the accrued downsideProtected.

Hence in a situation where the funds in the current chain are enough to cover the downside, the funds sent for fees are not refunded

Internal pre-conditions

No response

External pre-conditions

No response

Attack Path

No response

Impact

Funds sent to cover fees are not refunded even when they are not used leadng to loss of funds and there is not way to sweep them out of the `borrowing contract.

PoC

No response

Mitigation

Consider reimplementing the logic for the fee reversal during withdrawal

The original report as published on Sherlock, by 0x23r0. 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

The contract only refunds the fee when downsideProtected is zero, but fails to refund when downsideProtected is positive and covered locally, because the cross-chain call is skipped.

Impact

Borrowers lose the ETH they sent for fees when their position's downside is fully covered by local CDS funds, and these funds become stuck in the contract.

What the attacker needed

Borrower withdraws with ETH for fees; downsideProtected > 0; local CDS funds sufficient

The fix

The logic for fee refund during withdrawal should be reimplemented to return unused fees even when downsideProtected is positive and covered locally.

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.

When you withdraw from a borrowing contract, you send some extra cryptocurrency to pay for potential cross-chain transactions. The contract only returns this extra money if it needs to request funds from another chain. If the local funds are enough, it keeps your extra money, and you cannot get it back.

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

View all

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