Skip to content
DoS Audit finding Intermediate

Deny of service in CNote.doTransferOut

The CNote contract's doTransferOut function requires the contract's token balance to be exactly zero after a transfer, so any extra token sent by an attacker causes the transaction to revert. An attacker can front-run a legitimate transfer with a small token amount to block withdrawals.

0x1f8b Follow

Originally disclosed on Code4rena

Submitted by 0x1f8b, also found by Lambda

https://github.dev/Plex-Engineer/lending-market-v2/blob/2646a7676b721db8a7754bf5503dcd712eab2f8a/contracts/CNote.sol#L148

The CNote.doTransferOut method is susceptible to denial of service.

Proof of Concept

The logic of the doTransferOut method in CNote is as follows:

    function doTransferOut(address payable to, uint amount) virtual override internal {
        require(address(_accountant) != address(0));
        EIP20Interface token = EIP20Interface(underlying);
        if (to != address(_accountant)) {
            uint err = _accountant.supplyMarket(amount);
            if (err != 0) { revert AccountantRedeemError(amount); }
        }
        token.transfer(to, amount);
        bool success;
        assembly {
            switch returndatasize()
                case 0 { success := not(0) }
                case 32 {
                    returndatacopy(0, 0, 32)
                    success := mload(0)
                }
                default { revert(0, 0) }
        }
        require(success, "TOKEN_TRANSFER_OUT_FAILED");
        require(token.balanceOf(address(this)) == 0, "cNote::doTransferOut: TransferOut Failed"); // <-- ERROR
    }

The doTransferOut method receives an amount which is transferred to to, after it the balance of the contract token is checked to be equal to zero or the transaction will be reverted.

In the following cases a denial of service will occur:

  • In the case that is used an amount different than the balance, the transaction will be reverted.
  • In the case that an attacker front-runs the transaction and sends one token more than the established by the _accountant.
  • In case of increasing balance tokens like mDai that constantly change their balance, the established by the _accountant will be different when the transaction is persisted.

Recommended Mitigation Steps

  • Use balance differences instead of the 0 check.

nivasan1 (Canto) confirmed

Alex the Entreprenerd (judge) commented:

The warden has shown how, anyone, via a simple transfer of underlying can deny the functionality of doTransferOut.

Because the function is used in multiple functions inherited from CToken, and the griefing can be easily run by anyone, I believe High Severity to be appropriate.


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

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 checks that its token balance is exactly zero after a transfer, rather than checking the change in balance, so any extra tokens cause a revert.

Impact

Anyone can block the doTransferOut functionality, which is used in multiple functions inherited from CToken, by sending a small amount of the underlying token.

What the attacker needed

Ability to send tokens to the contract; ability to front-run transactions

The fix

The check should use balance differences instead of requiring the balance to be zero.

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 that holds tokens and lets users withdraw them. The withdrawal code checks that the contract's token balance is exactly zero after sending the tokens out. If someone else sends even one token to the contract first, that check fails and the withdrawal is blocked. An attacker can do this on purpose to stop withdrawals.

What is DoS?

A request that exhausts resources or crashes a component. Many programs forbid testing it; reports usually show it from code, not by attacking.

More by 0x1f8b

View all

21 more disclosed reports, best first.

More from Canto v2 contest

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Denial of service

The lesson behind this report.

A request that exhausts resources or crashes a component. Many programs forbid testing it; reports usually show it from code, not by attacking.