How I Built a Zero-Lag Anti-Cheat for a $100 Browser Game (120 Hz Determinism + SHA-256 Commit-Reveal)
If you put a real $100 prize inside an HTML5 Canvas browser game, you don't have to wonder if someone will open DevTools and try to break it — you only have to wonder how many minutes it will take. I just launched One L
If you put a real $100 prize inside an HTML5 Canvas browser game, you don't have to wonder if someone will open DevTools and try to break it — you only have to wonder how many minutes it will take.
I just launched One Last Gap — a free, zero-ads, zero-login browser skill arcade built solo with TypeScript, Canvas 2D, and a zero-dependency Node.js backend.
The premise takes one second to understand:
- Inside a suspended vault sits a $100 bill.
-
Ball diameter:
3.200 mm -
Top gap width:
3.205 mm(+0.005 mmreal clearance) -
Hit #1 (
1/2): Ricochet off the ceiling into the gap to shatter the glass seal and bounce back out into play. -
Hit #2 (
2/2): Without dropping the ball, thread the open tunnel a second time to strike the $100 bill. First verified human player wins it.
Making a game like this feel crisp on both desktop and mobile is one problem. Making a client-side browser game with a cash prize cheat-resistant without adding network lag is a much more interesting engineering problem.
Here is how I designed the physics determinism, the SHA-256 Commit-Reveal anti-cheat, and the server-side replay verifier.
Why Naive Approaches Break Immediately
-
"Trust the client (
POST /api/win)" — broken in 5 seconds viacurlor DevTools. - "Run physics exclusively on the server and stream positions over WebSockets" — kills arcade game feel. Even 60–120 ms of round-trip jitter makes a millimeter-precision paddle game feel muddy on mobile networks.
-
"Just send the replay to the server and re-simulate it" — necessary, but not sufficient! If the entire physics loop is 100% deterministic and predictable in advance, an attacker can write a DevTools aimbot that calculates the exact paddle offset to thread a
+0.005 mmgap on the very first shot.
So the design goal became:
0 ms input latency on the client + 100% server-authoritative verification + mathematically un-aimbottable trajectories.
Layer 1: Bit-Identical 120 Hz Determinism Across Safari, Chrome, and Node.js
Both the browser client and the Node.js verification server execute the exact same physics module (shared/physics.ts).
-
Fixed timestep:
FIXED_DT = 1 / 120s (120 Hz), decoupled from display refresh rates (60 / 120 / 240 Hz). -
Continuous collision detection: custom swept circle-vs-AABB faces + 4 corner circles (up to 8 substeps per tick). At
1180 u/sagainst a+0.005 mmgap, discrete frame checks would tunnel or clip inconsistently. -
Equalizing mouse and touch: paddle inputs are quantized to
0.5 uincrements and clamped toMAX_PADDLE_SPEED = 1700 u/s, preventing instant teleportation.
The Subtle Cross-Engine Trap: 1-ULP Floating-Point Drift
When you replay 20,000+ ticks on a Linux Node.js (V8) server from inputs recorded on an iPhone (Safari / JavaScriptCore), tiny 1e-16 ULP differences in Math.sin / Math.cos eventually diverge into a completely different bounce trajectory.
To keep replays bit-identical across JavaScriptCore, SpiderMonkey, and V8, velocity vectors are deterministically quantized to 1e-6 after trigonometric bounces:
function quantizeFloat(v: number): number {
return Math.round(v * 1e6) / 1e6;
}
With that in place, 600-tick and multi-minute replays match bit-for-bit across devices and the server.
Layer 2: Killing the God-Mode Aimbot with Zero Lag (SHA-256 Commit-Reveal)
Here is the core trick that prevents offline aimbots while keeping client responsiveness at 0 ms:
- The moment the player strikes the ball upward (
launch,paddle_hit, orglass_cracked), the ball takes ~500 ms to travel up a side corridor to the top ceiling. - At that exact commit tick, the client computes a synchronous SHA-256 hash of all session inputs recorded up to
commitTickand asynchronously sends{ sessionId, commitTick, inputsHash }toPOST /api/ceiling-token. - The server checks that
commitTickis strictly increasing, generates a cryptographically random micro-angledegin[-0.35°, +0.35°], and signs it withHMAC-SHA256(sessionId : seq : commitTick : inputsHash : deg). - The token arrives in ~30–100 ms — long before the ball touches the ceiling — so the player experiences zero lag.
- When the ball hits the top ceiling, that server-signed
degrotates the reflection vector slightly.
Why ±0.35° Is the Sweet Spot
-
For a human player:
±0.35°shifts the landing point on the vault roof by at most±0.22 mm(~2 pixels on a phone screen). Human hands cannot perceive or control that granularity. -
For a theoretical 100%-omniscient God-mode aimbot: because the angle is cryptographically unknown until after the paddle commits the shot, I tested an omniscient solver against it (
test:aimbot):- Without Commit-Reveal (
0.00°): 100.0% hit rate on every shot. - With Commit-Reveal (
±0.35°): drops to ~1.0–1.5% per shot — and ~1 in 5,000 to 9,600 for two consecutive hits (2/2) without dropping.
- Without Commit-Reveal (
-
No pre-fetching or retroactive editing: changing even 1 tick of paddle movement before
commitTickinvalidates the SHA-256inputsHash, and hitting the paddle aftercommitTickbreaks the verifier'slastPaddleHitTick <= token.commitTickinvariant.
Layer 3: Hardening the Verifier Itself
During security self-auditing, several nasty edge cases showed up — and fixing them was half the fun:
- Preventing Quadratic SHA-256 CPU DoS: If a verifier blindly recomputes SHA-256 commitments over a forged 30,000-event replay, an attacker can stall your Node event loop. By validating the O(1) HMAC signature and server-issued token registry before computing any SHA-256 hashes, a forged 30,000-event payload gets rejected in 1.6 ms instead of seconds.
-
Blocking Offline Synthesis (
POST /api/checkpoint): When Hit #1 shatters the glass, the client reports a live one-time checkpoint to the server (tick >= lastCommitTick, non-overwritable). Combined with real-time wall-clock checks, an attacker cannot synthesize a fake replay offline and upload it later. -
Anti-Slow-Mo Without Punishing Mobile Disconnects:
Measuring slow-motion strictly against the arrival time of
POST /api/verifycreates a false positive if an honest winner's mobile network drops for 30 seconds before hitting Retry Verification. Instead, the verifier measures theONE LASTphase against the server timestamp of the last signed ceiling token — blocking 5×–6× debugger slow-motion while letting honest network retries succeed cleanly. -
Zero Backend Supply-Chain Surface:
The entire backend runs on Node.js 24 stdlib only (
node:http,node:crypto, built-innode:sqlitein WAL mode withsynchronous=FULL) — zero external npm packages on the server.
Proving the Gap Isn't Rigged (500 Hours + 200,000 Shots)
With a +0.005 mm gap, the #1 question players ask is: "Is this actually possible, or is it a rigged scam?"
Before launching, I calibrated the exact geometry across 500 hours of real 120 Hz AI simulation (436,116 roof impacts) plus 200,000 targeted Monte Carlo shots:
-
500-hour 120 Hz simulation:
28legitimate Hit #1 glass shatters (~1 in 15,576roof impacts). -
200,000 targeted Monte Carlo shots:
42Hit #1 entries (~1 in 4,762).
Hard enough to survive viral traffic, mathematically proven solvable, and never rigged.
An Honest Threat Model
No browser game is 100% theoretically unbreakable. A determined attacker could still compile a custom Chromium binary to spoof input events and run a real-time 1× bot 24/7. Even then, the ±0.35° Commit-Reveal forces hundreds of hours of real-time runtime per instance, and every first verified win atomically locks the prize for a manual visual replay audit (inspecting the paddle trajectory curve and timing telemetry) before the $100 payout is sent.
Try It (Or Try to Break It)
- Play free in your browser (desktop & mobile, zero ads, zero login): https://onelastgap.com
- itch.io page: https://mooradxo.itch.io/one-last-gap
(There's also a completely absurd $15,000 — Buy a Wider Gap Hall of Shame button tucked inside INFO — it doesn't win the $100, just permanently engraves your name at the top. 100% of it goes toward monthly cancer medication for my mom. I'm not asking for charity — I just built something brutally hard that I'm proud of.)
I'd love to hear your thoughts on the Commit-Reveal design, any edge cases you'd test against it, and your closest miss in mm!
Originally published by Dev.to WebDev. Aggregated on AIWithGhost for educational purposes — full credit and traffic to the original publisher.