[PR #4989] [MERGED] Anticheat prediction (b): play each client tick again and compare #5990

Closed
opened 2026-11-03 05:16:28 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/horizon-rust/horizon/pull/4989
Author: @ludovic111
Created: 10/31/2026
Status: ✅ Merged
Merged: 10/31/2026
Merged by: @ludovic111

Base: main ← Head: feat/anticheat-prediction-replay


📝 Commits (1)

  • 7f969cb Anticheat prediction (b): play each client tick again and compare

📊 Changes

12 files changed (+508 additions, -7 deletions)

View changed files

📝 crates/horizon-anticheat/src/lib.rs (+2 -2)
📝 crates/horizon-anticheat/src/prediction.rs (+56 -1)
📝 crates/horizon-client/src/game.rs (+1 -0)
📝 crates/horizon-client/src/game/lan_actions.rs (+1 -0)
➕ crates/horizon-client/src/game/prediction.rs (+63 -0)
📝 crates/horizon-client/src/lan/anticheat.rs (+1 -1)
📝 crates/horizon-client/src/lan/guest.rs (+3 -0)
📝 crates/horizon-client/src/lan/hub.rs (+5 -0)
📝 crates/horizon-client/src/lan/mod.rs (+1 -0)
➕ crates/horizon-client/src/lan/prediction.rs (+350 -0)
📝 crates/horizon-client/src/motion.rs (+24 -2)
📝 docs/anticheat.md (+1 -1)

📄 Description

🤖 Opened by Ludovic's AI agent (Claude), not by Ludovic himself.

Movement prediction (b) (plan with @rdbtCVS on #4735; (a) #4919 records the client ticks, (b0) #4954 made PlayerMotion Clone). The server now plays each client tick again and compares it with the client's move. It still flags nothing: the check, (c), is the next PR. Like every check it only runs with [anticheat] on, which no default server.toml has.

How a tick is played

  • MotionWorld::replayed_tick: the client's own local tick (LocalPlayer.aiStep and its travel, the code Horizon's client runs), with the client's keys and its reported sprinting instead of the sprint-key logic. controlled_simulation_tick and the replay share local_tick, so nothing changes for the local player.
  • lan::prediction::Replay keeps the player as its client moves it. It starts at an accepted teleport (Record::teleported), standing still, as the client does. It plays each new tick of the record from where the last one ended and measures how far it lands from where the client said. Then it carries on from the client's own position, so small errors never add up, and a client that cheats a little every tick is measured against its own last position each time. The server's own decisions (attributes, effects, abilities, item use, glider, border) come from the server's copy of the player. All the rest is the client's movement state.
  • What gets tried (rdbtCVS's "simulate all possible valid inputs"): the keys and sprinting are known exactly. A vanilla client sends ServerboundPlayerInputPacket after its aiStep (auto-jump included), its sprinting just before the move, and its item use from the key handling before the tick. So guessing them would only let cheats through: trying "sprinting" lets a 1.3× speed hack pass, and trying "no item slowdown" lets NoSlow pass. Instead, every combination of what the server can't know is tried, the tick as heard first, and the closest outcome is kept. Those unknowns are the ground on the first tick after a teleport, and the old item use on the tick the server's own use changed. Most ticks have nothing to try, and the body itself plays them, with no copy.
  • Not played: riding, sleeping, dead, spectators, a teleport not yet accepted. Each ends with a teleport (dismountTo, stopSleeping, respawn), and the replay starts again there.
  • Next, (b2): the history rdbtCVS asked for. That means what the server sent the player (velocity and explosion knockback, UpdateAttributes, effects), placed on the client tick that first saw it through the pong brackets (anti-knockback is then caught too), plus the recent block changes around the player.

Measured

  • A real Horizon client on a dedicated server with [anticheat] on: walking, sprint-jumping, a 90° turn, strafing, sneaking backwards. All 262 ticks replayed exactly: no offset above 1e-6, no disagreement about the ground. (I used a throwaway script with a temporary log line, not committed. (d) brings the committed e2e.)
  • Unit tests (lan::prediction, real 26.3 data): a client walking, sprint-jumping, stepping onto a slab, strafing while turning and stopping replays to ≤ 1e-6 on all 50 ticks. A client moving 1.3× too fast is off by more than 0.01 on more than 30 of 50 ticks, and one flying 0.1 up a tick on every tick.
  • Cost, 60 walking bots, Mac mini, 30 s warmup + 120 s:
Build MSPT (runs)
main + #4954 4.45, 4.42, 4.34
this PR, anticheat off (the default) 4.37
this PR, --anticheat 4.76, 4.80, 4.83

Timed directly in the server: 5.6 µs per player per tick, 0.34 ms a tick for 60 players, and nothing when off. About a quarter of it is copying the server's attributes every tick. (b2) copies them only when the server sends the client UpdateAttributes.

pr_ready

Check Result
Scope ⚠️ 12 files, +508 −7; 513 lines of code: over 500, split it if it can ship in parts
Cargo.lock ✅ unchanged
Public tree ✅
Python tests ✅ 495 passed (1 min 7 s)
rustfmt ✅ (5 s)
clippy ✅ (1 min 24 s)
tests: horizon-anticheat, horizon-client ❌ 932 passed, 1 failed (2 min 57 s)
doc tests ✅ 0 passed (2 s)
content root tests ➖ content root untouched
tokens.css up to date ➖ theme untouched
launcher rustfmt ➖ launcher untouched
launcher clippy ➖ launcher untouched
launcher tests ➖ launcher untouched
Parity ➖ 59 affected, to run in CI (--quick): arrow, auto_jump, block_removal, command_exec, composter, container_title, crafter, cursor_death, dedicated_server, dispenser, entity_components, entity_death_loot and 47 more
Label player-facing: feature if players get something new, no label for a fix (release-now if urgent)

The failing test, motion::tests::a_swimming_passenger_sits_up_even_when_standing_does_not_fit, comes from #4662 and fails on main whenever .local data is present; not touched here. The size is 13 lines over the 500 guideline: about 130 of the lines are the replay's tests, and the replay can't ship without its glue.

Harnesses for the movement code and the server: auto_jump, lunge_motion, mace, trident, server_knockback, dedicated_server and server_entities pass. pearl_wind_charge failed once with the machine at 90 % CPU, then passed on two reruns; it also passes on main.

Clean-room: written from vanilla 26.3 (LocalPlayer.tick, aiStep, sendChanges, sendPosition, ServerGamePacketListenerImpl) and public descriptions only. No other project's code.

🤖 Generated with Claude Code


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/horizon-rust/horizon/pull/4989 **Author:** [@ludovic111](https://github.com/ludovic111) **Created:** 10/31/2026 **Status:** ✅ Merged **Merged:** 10/31/2026 **Merged by:** [@ludovic111](https://github.com/ludovic111) **Base:** `main` ← **Head:** `feat/anticheat-prediction-replay` --- ### 📝 Commits (1) - [`7f969cb`](https://github.com/horizon-rust/horizon/commit/7f969cb3a5e41d2a22e0cb3f1b08682ab905e931) Anticheat prediction (b): play each client tick again and compare ### 📊 Changes **12 files changed** (+508 additions, -7 deletions) <details> <summary>View changed files</summary> 📝 `crates/horizon-anticheat/src/lib.rs` (+2 -2) 📝 `crates/horizon-anticheat/src/prediction.rs` (+56 -1) 📝 `crates/horizon-client/src/game.rs` (+1 -0) 📝 `crates/horizon-client/src/game/lan_actions.rs` (+1 -0) ➕ `crates/horizon-client/src/game/prediction.rs` (+63 -0) 📝 `crates/horizon-client/src/lan/anticheat.rs` (+1 -1) 📝 `crates/horizon-client/src/lan/guest.rs` (+3 -0) 📝 `crates/horizon-client/src/lan/hub.rs` (+5 -0) 📝 `crates/horizon-client/src/lan/mod.rs` (+1 -0) ➕ `crates/horizon-client/src/lan/prediction.rs` (+350 -0) 📝 `crates/horizon-client/src/motion.rs` (+24 -2) 📝 `docs/anticheat.md` (+1 -1) </details> ### 📄 Description > 🤖 Opened by Ludovic's AI agent (Claude), not by Ludovic himself. Movement prediction (b) (plan with @rdbtCVS on #4735; (a) #4919 records the client ticks, (b0) #4954 made `PlayerMotion` `Clone`). The server now plays each client tick again and compares it with the client's move. It still **flags nothing**: the check, (c), is the next PR. Like every check it only runs with `[anticheat]` on, which no default server.toml has. ## How a tick is played - `MotionWorld::replayed_tick`: the client's own local tick (`LocalPlayer.aiStep` and its travel, the code Horizon's client runs), with the client's keys and its reported sprinting instead of the sprint-key logic. `controlled_simulation_tick` and the replay share `local_tick`, so nothing changes for the local player. - `lan::prediction::Replay` keeps the player as its client moves it. It starts at an accepted teleport (`Record::teleported`), standing still, as the client does. It plays each new tick of the record from where the last one ended and measures how far it lands from where the client said. Then it carries on from the client's own position, so small errors never add up, and a client that cheats a little every tick is measured against its own last position each time. The server's own decisions (attributes, effects, abilities, item use, glider, border) come from the server's copy of the player. All the rest is the client's movement state. - **What gets tried** (rdbtCVS's "simulate all possible valid inputs"): the keys and sprinting are known exactly. A vanilla client sends `ServerboundPlayerInputPacket` after its `aiStep` (auto-jump included), its sprinting just before the move, and its item use from the key handling before the tick. So guessing them would only let cheats through: trying "sprinting" lets a 1.3× speed hack pass, and trying "no item slowdown" lets NoSlow pass. Instead, every combination of what the server *can't* know is tried, the tick as heard first, and the closest outcome is kept. Those unknowns are the ground on the first tick after a teleport, and the old item use on the tick the server's own use changed. Most ticks have nothing to try, and the body itself plays them, with no copy. - Not played: riding, sleeping, dead, spectators, a teleport not yet accepted. Each ends with a teleport (`dismountTo`, `stopSleeping`, respawn), and the replay starts again there. - Next, (b2): the history rdbtCVS asked for. That means what the server sent the player (velocity and explosion knockback, `UpdateAttributes`, effects), placed on the client tick that first saw it through the pong brackets (anti-knockback is then caught too), plus the recent block changes around the player. ## Measured - **A real Horizon client** on a dedicated server with `[anticheat]` on: walking, sprint-jumping, a 90° turn, strafing, sneaking backwards. All **262 ticks replayed exactly**: no offset above 1e-6, no disagreement about the ground. (I used a throwaway script with a temporary log line, not committed. (d) brings the committed e2e.) - **Unit tests** (`lan::prediction`, real 26.3 data): a client walking, sprint-jumping, stepping onto a slab, strafing while turning and stopping replays to ≤ 1e-6 on all 50 ticks. A client moving 1.3× too fast is off by more than 0.01 on more than 30 of 50 ticks, and one flying 0.1 up a tick on every tick. - **Cost**, 60 walking bots, Mac mini, 30 s warmup + 120 s: | Build | MSPT (runs) | |---|---| | main + #4954 | 4.45, 4.42, 4.34 | | this PR, anticheat off (the default) | 4.37 | | this PR, `--anticheat` | 4.76, 4.80, 4.83 | Timed directly in the server: **5.6 µs per player per tick, 0.34 ms a tick for 60 players**, and nothing when off. About a quarter of it is copying the server's attributes every tick. (b2) copies them only when the server sends the client `UpdateAttributes`. ## pr_ready | Check | Result | | --- | --- | | Scope | ⚠️ 12 files, +508 −7; 513 lines of code: over 500, split it if it can ship in parts | | Cargo.lock | ✅ unchanged | | Public tree | ✅ | | Python tests | ✅ 495 passed (1 min 7 s) | | rustfmt | ✅ (5 s) | | clippy | ✅ (1 min 24 s) | | tests: horizon-anticheat, horizon-client | ❌ 932 passed, 1 failed (2 min 57 s) | | doc tests | ✅ 0 passed (2 s) | | content root tests | ➖ content root untouched | | tokens.css up to date | ➖ theme untouched | | launcher rustfmt | ➖ launcher untouched | | launcher clippy | ➖ launcher untouched | | launcher tests | ➖ launcher untouched | | Parity | ➖ 59 affected, to run in CI (--quick): arrow, auto_jump, block_removal, command_exec, composter, container_title, crafter, cursor_death, dedicated_server, dispenser, entity_components, entity_death_loot and 47 more | | Label | player-facing: `feature` if players get something new, no label for a fix (`release-now` if urgent) | The failing test, `motion::tests::a_swimming_passenger_sits_up_even_when_standing_does_not_fit`, comes from #4662 and fails on main whenever `.local` data is present; not touched here. The size is 13 lines over the 500 guideline: about 130 of the lines are the replay's tests, and the replay can't ship without its glue. Harnesses for the movement code and the server: `auto_jump`, `lunge_motion`, `mace`, `trident`, `server_knockback`, `dedicated_server` and `server_entities` pass. `pearl_wind_charge` failed once with the machine at 90 % CPU, then passed on two reruns; it also passes on main. Clean-room: written from vanilla 26.3 (`LocalPlayer.tick`, `aiStep`, `sendChanges`, `sendPosition`, `ServerGamePacketListenerImpl`) and public descriptions only. No other project's code. 🤖 Generated with [Claude Code](https://claude.com/claude-code) --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-11-03 05:16:28 +07:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
horizon-rust/horizon#5990
No description provided.