Credit:Khaled Ziad/AFP
Compound inflation attack like most donation attacks requires the attacker both being the first to deposit and also owning all the shares in the concerned vault.
Since the exchange rate of the vault is measured using the cash available in the contract by a call of balance(address(this))
[CErc20 CEther], it means any donation directly to the vault balance would increase the exchange Rate.
As seen in the code, there are two exchange rates, the first initialExchangeRateMantissa
is a fixed value used only at initial deposit into the protocol and is assigned at initialization defined at CToken interface.
Ex. Initial Deposit
$$ (a) ~~~~ CTokenAmount = \frac{UnderlyningAmount}{InitialExchangeRate} $$
After initial deposit the exchange rate takes effect, which is measured by the sum total deposit into the vault in respect to the total supply.
$$ (b) ~~~~ CTokenAmount = \frac{UnderlyningAmount}{(\frac{TotalCash + TotalBorrow - Reserve}{TotalSupply})} $$