-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathChallenge4.t.sol
46 lines (34 loc) · 1.64 KB
/
Challenge4.t.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
42
43
44
45
46
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.13;
import "@openzeppelin/contracts/utils/cryptography/MessageHashUtils.sol";
import {console} from "forge-std/Test.sol";
import {BaseTest} from "../BaseTest.sol";
import {Challenge4} from "../../src/Challenge4.sol";
import {NFTFlags} from "../../src/NFTFlags.sol";
contract Challenge4Test is BaseTest {
using MessageHashUtils for bytes32;
Challenge4 challenge4;
address MINTER = 0xFABB0ac9d68B0B445fB7357272Ff202C5651694a; // address used in actual challenge
uint256 MINTER_PRIVATE_KEY = 0xa267530f49f8280200edf313ee7af6b827f2a8bce2897751d06a843f644967b1;
function setUp() public {
setUpChallenges();
vm.prank(ADMIN);
challenge4 = new Challenge4(address(nftFlags));
vm.prank(ADMIN);
nftFlags.addAllowedMinter(address(challenge4));
vm.prank(ADMIN);
challenge4.addMinter(MINTER);
}
function test_challenge4() public {
vm.startPrank(PLAYER, PLAYER);
// Step 1: reconstruct the same message as the challenge contract
bytes32 message = keccak256(abi.encode("BG CTF Challenge 4", PLAYER));
bytes32 hash = message.toEthSignedMessageHash();
// Step 2: sign this contract with the known private key (this is known because it is one of the hardhat accounts)
(uint8 v, bytes32 r, bytes32 s) = vm.sign(MINTER_PRIVATE_KEY, hash);
// Step 3: call the mintFlag function with the signature
challenge4.mintFlag(MINTER, abi.encodePacked(r, s, v));
// DONE: You should have obtained the flag for challenge #4
assertTrue(nftFlags.hasMinted(PLAYER, 4));
}
}