Skip to content

Instantly share code, notes, and snippets.

@zaryab2000
Last active January 16, 2021 13:27
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 zaryab2000/f108f216b835168e2463784353d2e426 to your computer and use it in GitHub Desktop.
Save zaryab2000/f108f216b835168e2463784353d2e426 to your computer and use it in GitHub Desktop.
const { ether, balance } = require('@openzeppelin/test-helpers');
const { accounts, contract, web3 } = require('@openzeppelin/test-environment');
const LenderPool = contract.fromArtifact('NaiveReceiverLenderPool');
const FlashLoanReceiver = contract.fromArtifact('FlashLoanReceiver');
const myAttackContract = contract.fromArtifact('AttackContract');
const { expect } = require('chai');
describe('[Challenge] Naive receiver', function () {
const [deployer, user, attacker, ...otherAccounts] = accounts;
// Pool has 1000 ETH in balance
const ETHER_IN_POOL = ether('1000');
// Receiver has 10 ETH in balance
const ETHER_IN_RECEIVER = ether('10');
before(async function () {
/** SETUP - NO NEED TO CHANGE ANYTHING HERE */
this.pool = await LenderPool.new({ from: deployer });
await web3.eth.sendTransaction({ from: deployer, to: this.pool.address, value: ETHER_IN_POOL });
expect(await balance.current(this.pool.address)).to.be.bignumber.equal(ETHER_IN_POOL);
expect(await this.pool.fixedFee({ from: deployer })).to.be.bignumber.equal(ether('1'));
this.receiver = await FlashLoanReceiver.new(this.pool.address, { from: user });
await web3.eth.sendTransaction({ from: user, to: this.receiver.address, value: ETHER_IN_RECEIVER });
expect(await balance.current(this.receiver.address)).to.be.bignumber.equal(ETHER_IN_RECEIVER);
});
it('Exploit', async function () {
/** YOUR EXPLOIT GOES HERE */
});
after(async function () {
/** SUCCESS CONDITIONS */
// All ETH has been drained from the receiver
expect(
await balance.current(this.receiver.address)
).to.be.bignumber.equal('0');
expect(
await balance.current(this.pool.address)
).to.be.bignumber.equal(ETHER_IN_POOL.add(ETHER_IN_RECEIVER));
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment