Skip to content

Commit

Permalink
chore: lint
Browse files Browse the repository at this point in the history
  • Loading branch information
leovct committed Sep 19, 2024
1 parent 0aca155 commit 87d389f
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 9 deletions.
19 changes: 15 additions & 4 deletions src/Ethernaut/GatekeeperOne.sol
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,24 @@ contract GatekeeperOne {
}

modifier gateThree(bytes8 _gateKey) {
require(uint32(uint64(_gateKey)) == uint16(uint64(_gateKey)), "GatekeeperOne: invalid gateThree part one");
require(uint32(uint64(_gateKey)) != uint64(_gateKey), "GatekeeperOne: invalid gateThree part two");
require(uint32(uint64(_gateKey)) == uint16(uint160(tx.origin)), "GatekeeperOne: invalid gateThree part three");
require(
uint32(uint64(_gateKey)) == uint16(uint64(_gateKey)),
'GatekeeperOne: invalid gateThree part one'
);
require(
uint32(uint64(_gateKey)) != uint64(_gateKey),
'GatekeeperOne: invalid gateThree part two'
);
require(
uint32(uint64(_gateKey)) == uint16(uint160(tx.origin)),
'GatekeeperOne: invalid gateThree part three'
);
_;
}

function enter(bytes8 _gateKey) public gateOne gateTwo gateThree(_gateKey) returns (bool) {
function enter(
bytes8 _gateKey
) public gateOne gateTwo gateThree(_gateKey) returns (bool) {
entrant = tx.origin;
return true;
}
Expand Down
13 changes: 8 additions & 5 deletions test/Ethernaut/GatekeeperOneExploit.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,10 @@ contract Helper {
// 4. Iteratively narrowed down:
// - base + 267 gas (82,177) failed
// - base + 268 gas (82,178) succeeded
require(GatekeeperOne(_target).enter{gas: 8191*10 + 268}(_gateKey), "Exploit succeeded");
require(
GatekeeperOne(_target).enter{gas: 8191 * 10 + 268}(_gateKey),
'Exploit succeeded'
);
}
}

Expand Down Expand Up @@ -48,9 +51,9 @@ contract GatekeeperOneExploit is Test {
// - uint32(uint64(_gateKey)) == uint16(uint64(_gateKey))
// - uint32(uint64(_gateKey)) != uint64(_gateKey)
(uint64(0x1100000000000000) & 0xFF00000000000000) |
// Set the two last significant bytes to the two last significant bytes of tx.origin.
// This enables to have: uint32(uint64(_gateKey)) == uint16(uint160(tx.origin))
(uint64(uint16(uint160(address(exploiter)))) & 0x000000000000FFFF)
// Set the two last significant bytes to the two last significant bytes of tx.origin.
// This enables to have: uint32(uint64(_gateKey)) == uint16(uint160(tx.origin))
(uint64(uint16(uint160(address(exploiter)))) & 0x000000000000FFFF)
);
new Helper(address(target), gateKey);
vm.stopPrank();
Expand All @@ -59,4 +62,4 @@ contract GatekeeperOneExploit is Test {
console2.log('New entrant: %s', entrant);
assertEq(entrant, address(exploiter));
}
}
}

0 comments on commit 87d389f

Please sign in to comment.