Skip to content

Instantly share code, notes, and snippets.

@iphelix
Last active November 13, 2020 23:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save iphelix/327fe3b0d3e40c51b23e6ba68d6a98d6 to your computer and use it in GitHub Desktop.
Save iphelix/327fe3b0d3e40c51b23e6ba68d6a98d6 to your computer and use it in GitHub Desktop.
Damn Vulnerable DeFi - Unstoppable
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);
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");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment