Damn vulnerable defi challenge3 truster
overview
More and more lending pools are offering flash loans. In this case, a new pool has launched that is offering flash loans of DVT tokens for free.
The pool holds 1 million DVT tokens. You have nothing.
how to get it started
- git clone github repo
- yarn install
- fill your code in *.challenge.js
- run your script via hardhat tools
code bug
1 | function flashLoan(uint256 amount, address borrower, address target, bytes calldata data) |
Target here means address of the DVT token that we deployed before.Thus we can use this call to approve amount to attacker address.Let's jump into code:
1 | function attack(TrusterLenderPool pool,DamnValuableToken _token) external { |
Firstly, we need an abi string about the approve function.
Secondly,make a flash loan via pool address.
Finally,transfer all amount of pool DVT token to msg.sender(palyer).
hardhat test script
1 | //deploy the attack contract |
- 1.deploy the attack contract
- 2.invoke attack contract via player address.