Challenge:
This write-up is for the challenge titled ‘hello’.
This challenge is located in the hello/public/ directory. The source code can be found below:
Hello.sol:
pragma solidity 0.8.0;
contract Hello {
bool public solved = false;
function solve() public {
solved = true;
}
}
Setup.sol:
pragma solidity 0.8.0;
import "./Hello.sol";
contract Setup {
Hello public hello;
constructor() {
hello = new Hello();
}
function isSolved() public view returns (bool) {
return hello.solved();
}
}
The solution for this level can be found below:
Solution:
This challenge is really just about setting up the environment. As the competition is since over, I’ve chosen to simulate the challenges over the HardHat network.
Hardhat Challenge:
const { ethers } = require('hardhat');
const { expect } = require('chai');
describe('[Challenge] hello', function () {
before(async function () {
/** SETUP */
[deployer] = await ethers.getSigners();
const Setup = await ethers.getContractFactory('Setup', deployer);
this.setup = await Setup.deploy();
const Hello = await ethers.getContractFactory('Hello', deployer);
this.hello = await Hello.attach(await this.setup.hello());
});
it('Exploit', async function () {
/** CODE YOUR EXPLOIT HERE */
});
after(async function () {
/** SUCCESS CONDITIONS */
expect(
await this.setup.isSolved()
).to.equal(true);
});
});
HardHat Solution:
it('Exploit', async function () {
/** CODE YOUR EXPLOIT HERE */
await this.hello.solve();
});