Skip to content

Instantly share code, notes, and snippets.

@zaryab2000
Created January 16, 2021 13:50
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/1287ed3ab8dd1046d3e0581190cea7d5 to your computer and use it in GitHub Desktop.
Save zaryab2000/1287ed3ab8dd1046d3e0581190cea7d5 to your computer and use it in GitHub Desktop.
const { ether, balance } = require('@openzeppelin/test-helpers');
const { accounts, contract } = require('@openzeppelin/test-environment');
const SideEntranceLenderPool = contract.fromArtifact('SideEntranceLenderPool');
const SideEntranceAttacker = contract.fromArtifact('SideEntranceAttacker');
const { expect } = require('chai');
describe('[Challenge] Side entrance', function () {
const [deployer, attacker, ...otherAccounts] = accounts;
const ETHER_IN_POOL = ether('1000');
before(async function () {
/** SETUP SCENARIO */
this.pool = await SideEntranceLenderPool.new({ from: deployer });
await this.pool.deposit({ from: deployer, value: ETHER_IN_POOL });
this.attackerInitialEthBalance = await balance.current(attacker);
expect(
await balance.current(this.pool.address)
).to.be.bignumber.equal(ETHER_IN_POOL);
});
it('Exploit', async function () {
/** YOUR EXPLOIT GOES HERE */
});
after(async function () {
/** SUCCESS CONDITIONS */
expect(
await balance.current(this.pool.address)
).to.be.bignumber.equal('0');
// Not checking exactly how much is the final balance of the attacker,
// because it'll depend on how much gas the attacker spends in the attack
// If there were no gas costs, it would be balance before attack + ETHER_IN_POOL
expect(
await balance.current(attacker)
).to.be.bignumber.gt(this.attackerInitialEthBalance);
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment