-
Notifications
You must be signed in to change notification settings - Fork 85
Expand file tree
/
Copy pathReverExploit.t.sol
More file actions
46 lines (37 loc) · 1.37 KB
/
ReverExploit.t.sol
File metadata and controls
46 lines (37 loc) · 1.37 KB
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: Unlicense
pragma solidity ^0.8.15;
import "foundry-huff/HuffDeployer.sol";
import "forge-std/Test.sol";
import "./challenge/Setup.sol";
contract ReverExploitTest is Test {
address playerAddress = makeAddr("player");
function testExploit() public {
Setup setup = new Setup();
bytes memory bytecode = compilePalindromeChecker();
vm.startPrank(playerAddress, playerAddress);
bytecode = bytes.concat(bytecode, flip(bytecode));
setup.challenge().deploy(bytecode);
vm.stopPrank();
assertEq(setup.test(""), true);
assertEq(setup.test("a"), true);
assertEq(setup.test("ab"), false);
assertEq(setup.test("aba"), true);
assertEq(setup.test("paradigm"), false);
assertEq(setup.test("tattarrattat"), true);
}
function compilePalindromeChecker() public returns (bytes memory) {
string[] memory cmds = new string[](3);
cmds[0] = "huffc";
cmds[1] = "src/ParadigmCTF2021/Rever/PalindromeChecker.huff";
cmds[2] = "-r";
bytes memory bytecode = vm.ffi(cmds);
return bytecode;
}
function flip(bytes memory a) private pure returns (bytes memory) {
bytes memory b = new bytes(a.length);
for (uint256 i = 0; i < a.length; i++) {
b[b.length - i - 1] = a[i];
}
return b;
}
}