Credit:Khaled Ziad/AFP

Credit:Khaled Ziad/AFP

Preamble

Assumptions about the reader

  1. General Understanding of money markets
  2. DEFI pricing
  3. Solidity

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.

Exchange rate

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.

Initial 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} $$

Exchange rate

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})} $$