Last active
November 13, 2020 23:25
-
-
Save iphelix/327fe3b0d3e40c51b23e6ba68d6a98d6 to your computer and use it in GitHub Desktop.
Damn Vulnerable DeFi - Unstoppable
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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