Skip to content
Business logic Audit finding Intermediate

CompoundHandler#topUp() Using the wrong function selector makes native token topUp() always revert

The CompoundHandler's topUp() function calls mint with a uint256 argument on a native cToken (CEther), but CEther's mint takes no arguments, so the function selector is wrong and the call always reverts. This prevents native token top-ups from ever succeeding.

WatchPug Follow

Originally disclosed on Code4rena

Submitted by WatchPug

compound-finance/CEther.sol#L44-L47

function mint() external payable {
    (uint err,) = mintInternal(msg.value);
    requireNoError(err, "mint failed");
}

mint() for native cToken (CEther) does not have any parameters, as the Function Selector is based on the function name with the parenthesised list of parameter types, when you add a nonexisting parameter, the Function Selector will be incorrect.

CTokenInterfaces.sol#L316

function mint(uint256 mintAmount) external payable virtual returns (uint256);

The current implementation uses the same CToken interface for both CEther and CErc20 in topUp(), and function mint(uint256 mintAmount) is a nonexisting function for CEther.

As a result, the native token topUp() always revert.

CompoundHandler.sol#L57-L70

CToken ctoken = cTokenRegistry.fetchCToken(underlying);
uint256 initialTokens = ctoken.balanceOf(address(this));

address addr = account.addr();

if (repayDebt) {
    amount -= _repayAnyDebt(addr, underlying, amount, ctoken);
    if (amount == 0) return true;
}

uint256 err;
if (underlying == address(0)) {
    err = ctoken.mint{value: amount}(amount);
}

See also:

samwerner (Backd) confirmed and resolved


The original report as published on Code4rena, by WatchPug. 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 code uses the same interface for both native and ERC20 cTokens, calling a mint function with a uint256 argument that does not exist on the native cToken.

What the attacker needed

Native token topUp() call

The fix

The code should use the correct mint function signature for native cTokens (no arguments) when the underlying asset is the native token.

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 function selector is a short code that tells a smart contract which function to run, and it depends on the function's name and the types of its inputs. Here, the code used the selector for a function that takes a number, but the native token contract only has a function with no inputs, so the call fails every time.

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 WatchPug

View all

197 more disclosed reports, best first.

More from Backd Tokenomics contest

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.