Interactive Playground — CToken Share Inflation Vulnerability
mintTokens can be 0 when actualMintAmount < exchangeRate.
The function proceeds to transfer the user's tokens in (line 424) but mints 0 cTokens.
There is no require(mintTokens > 0) check anywhere.
getCashPrior() reads underlying.balanceOf(address(this)), which includes
tokens sent via direct ERC20.transfer(). An attacker can inflate the exchange rate
by donating tokens without going through mint(). With totalSupply = 1, the exchange rate
becomes arbitrarily large.
require(mintTokens > 0) in mintFresh()Pre-loaded test results from forge test --match-path test/poc/FirstDepositorAttack.t.sol -vvv