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.
Submitted by 0x1f8b, also found by Lambda
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
amountdifferent 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
mDaithat constantly change their balance, the established by the_accountantwill be different when the transaction is persisted.
Recommended Mitigation Steps
- Use balance differences instead of the 0 check.
Alex the Entreprenerd (judge) commented:
The warden has shown how, anyone, via a simple transfer of
underlyingcan deny the functionality ofdoTransferOut.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.
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.