1 - Unstoppable

Problem with similar topic

Solution

chevron-rightKey to solve this problem πŸ”‘hashtag
  • reentrancy is not the only way to break contracts

  • always check require and assert conditions carefully

We will break the assert statement.

function flashLoan(uint256 borrowAmount) external nonReentrant {
    require(borrowAmount > 0, "Must borrow at least one token");

    uint256 balanceBefore = damnValuableToken.balanceOf(address(this));
    require(balanceBefore >= borrowAmount, "Not enough tokens in pool");

    // Ensured by the protocol via the `depositTokens` function
    assert(poolBalance == balanceBefore); // <- we will break here!

    damnValuableToken.transfer(msg.sender, borrowAmount);

    IReceiver(msg.sender).receiveTokens(address(damnValuableToken), borrowAmount);

    uint256 balanceAfter = damnValuableToken.balanceOf(address(this));
    require(balanceAfter >= balanceBefore, "Flash loan hasn't been paid back");
}

depositTokens function updates poolBalance if you deposited tokens by calling it.

But we can simply transfer tokens to UnstoppableLender contract by using ERC20 transfer function without using depositTokens.

Done! 😎

Last updated