Skip to content

Commit 3d77a4f

Browse files
committed
fix FuzzyIdentity
1 parent fde96ca commit 3d77a4f

File tree

4 files changed

+34
-5
lines changed

4 files changed

+34
-5
lines changed

foundry.lock

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
{
2+
"lib/forge-std": {
3+
"tag": {
4+
"name": "v1.9.7",
5+
"rev": "77041d2ce690e692d6e03cc812b57d1ddaa4d505"
6+
}
7+
},
8+
"lib/openzeppelin-contracts": {
9+
"rev": "cae60c595b37b1e7ed7dd50ad0257387ec07c0cf"
10+
},
11+
"lib/solady": {
12+
"rev": "7175c21f95255dc7711ce84cc32080a41864abd6"
13+
},
14+
"lib/v2-core": {
15+
"rev": "ee547b17853e71ed4e0101ccfd52e70d5acded58"
16+
},
17+
"lib/foundry-huff": {
18+
"rev": "7648faf3990cc4561d52b71af03282fad3a803d8"
19+
},
20+
"lib/prb-math": {
21+
"rev": "77fa88eda4a4a91b3f3e9431df291292c26b6c71"
22+
},
23+
"lib/solmate": {
24+
"rev": "bfc9c25865a274a7827fea5abf6e4fb64fc64e6c"
25+
}
26+
}

src/CaptureTheEther/FuzzyIdentity/Exploit.t.sol

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,17 @@ contract ExploitTest is Test {
2020

2121
Create2Deployer deployer = new Create2Deployer();
2222
assert(address(deployer) == deployerAddr);
23-
bytes32 salt = bytes32(uint256(787669)); // found by _testSearchSalt
23+
bytes32 salt = bytes32(uint256(3289423)); // found by _testSearchSalt
2424
address exploitAddr = deployer.deploy(vm.getCode("Exploit.t.sol:FuzzyIdentityExploit"), salt);
2525
FuzzyIdentityExploit(exploitAddr).exploit(address(challenge));
2626

2727
vm.stopPrank();
2828
assertTrue(challenge.isComplete(), "Challenge is not complete");
2929
}
3030

31+
// this function is used to find the salt, but it uses a lot of gas, so it should be called only once.
32+
// usually, the function name changes to `_testSearchSalt` after the salt is found.
33+
// use the following command: forge test -vv
3134
function _testSearchSalt() public view {
3235
bytes memory creationCode = vm.getCode("Exploit.t.sol:FuzzyIdentityExploit");
3336
for (uint256 salt = 0; salt < (1 << 32); salt++) {
@@ -44,7 +47,7 @@ contract ExploitTest is Test {
4447
id <<= 4;
4548
}
4649
if (bad) {
47-
console.log("Salt found: %d", salt);
50+
console.log("salt %d", salt);
4851
break;
4952
}
5053
}

src/CaptureTheEther/FuzzyIdentity/FuzzyIdentityChallenge.sol

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ contract FuzzyIdentityChallenge {
99
bool public isComplete;
1010

1111
function authenticate() public {
12-
require(isSmarx(msg.sender));
13-
require(isBadCode(msg.sender));
12+
require(isSmarx(msg.sender), "Not smarx");
13+
require(isBadCode(msg.sender), "Not bad code");
1414

1515
isComplete = true;
1616
}

0 commit comments

Comments
 (0)