[PR #5012] [MERGED] Anticheat prediction (c): flag moves off the replay, set back to where they agreed #6006

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

📋 Pull Request Information

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

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


📝 Commits (1)

  • 71d7921 Anticheat prediction (c): flag moves off the replay, set back to where they agreed

📊 Changes

13 files changed (+789 additions, -119 deletions)

View changed files

📝 crates/horizon-anticheat/src/lib.rs (+18 -4)
📝 crates/horizon-anticheat/src/prediction.rs (+134 -10)
📝 crates/horizon-client/src/game.rs (+60 -50)
📝 crates/horizon-client/src/game/lan.rs (+1 -1)
📝 crates/horizon-client/src/game/prediction.rs (+119 -20)
📝 crates/horizon-client/src/lan/anticheat.rs (+42 -1)
📝 crates/horizon-client/src/lan/entity.rs (+14 -2)
📝 crates/horizon-client/src/lan/guest.rs (+7 -0)
📝 crates/horizon-client/src/lan/hub.rs (+56 -3)
📝 crates/horizon-client/src/lan/prediction.rs (+328 -25)
📝 docs/anticheat.md (+1 -1)
📝 tools/anticheat_e2e.py (+4 -0)
📝 tools/server_bench.py (+5 -2)

📄 Description

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

Movement prediction (c), after (b1) #4989 and (b2) #5003: the check. The replay now flags moves the player's own keys can't make (speed, step, fly, jesus, anti-knockback…) and sends the player back. Like every check it only runs with [anticheat] in server.toml, which no default server.toml has. [anticheat.prediction] enabled = false turns it off on its own.

How it flags

  • A client tick that lands farther than tolerance (new setting, 0.03 blocks) from the replay counts. Its weight is its offset in tolerances, at most 5 a tick. The default thresholds stay setback = 5, alert = 15, kick = 60, decay = 2: a move 0.15 blocks off sets back at once, and a 1.3× speed hack after about two ticks.

  • The setback sends the player back to where its moves last agreed (Replay::agreed), not to where the server last had it, which by then is the cheater's own position. The teleport restarts the replay.

  • An honest client replays exactly (offset 0.0 on every tick in (b1) and (b2)). Only what the replay can't play yet can make an honest tick land off. Such a tick is excused, and so are the ticks after it until the moves agree again (40 at most):

    • another entity or player within 3 blocks (a push, a boat or shulker to stand on, a firework to fly with);
    • a block change within 4 blocks that the client hadn't seen (the record keeps, for each change near the player, the server tick that sent it, until a client tick has seen it) or that the server hasn't sent yet (World::block_log), and an entity the server removed near the player that the client may still have (a cow just killed);
    • abilities (game mode, flight, a glider put on) the client hadn't seen: the new Change::Abilities;
    • a moving piston, a chunk around the player that the client doesn't have, or a riptide launch;
    • a teleport that keeps the player's motion (an End gateway's).

    Around a fast player (an elytra with a firework) these distances grow by two ticks of its speed: the server's firework trails the player by about a tick.

  • Under an excuse the replay takes the client's velocity: each tick it adds the miss to its own (also on a tick with no move sent: the client stayed where it last said, on a boat say). So a push it never heard is caught up with in two ticks (an_excused_push_is_caught_up_with), instead of drifting for seconds. The excuse ends once a tick agrees within 0.001 blocks, not at the first one under the tolerance, so a glide's velocity is fully caught up with.

  • Three replay fixes found with real clients behind a jittery connection:

    • The replay nudges the player out of a block it stands in (LocalPlayer.moveTowardsClosestSpace): the client walked into a stone it hadn't received yet and was pushed out at 0.1 blocks a tick, which the replay didn't do. The nudge is worked out from the blocks, as the game does for its own player: Game::closest_space_nudge became a function of a body and the world (moved, about 100 of this PR's lines).
    • A setback keeps the replay's body (its jump delay, a glide); while the teleport is awaited the replay plays the ticks but nothing counts.
    • Ticks that come in a burst with a teleport's accept are played before the replay starts again there (Replay::finish). Before, they were skipped: the jump delay they started was lost, and the replay jumped a tick before the client (a_burst_before_a_teleport_is_played_first). Record::teleported keeps the ticks ended before the accept for that.
  • The bots of tools/anticheat_e2e.py (timer and ground checks) and of server_bench.py --anticheat move by their own rules, not vanilla's, so the prediction would flag every one of them. The harness turns it off for those checks. The bench keeps it replaying but sets tolerance = 1000, to measure an honest player's cost. The prediction's own e2e with real clients comes in (d).

Measured

  • A real Horizon client on a dedicated server, survival, with [anticheat] and the prediction at its defaults, through a relay that delays every packet by 20–120 ms (in order). It does everything below and is never flagged (the anticheat log stays empty), in 8 runs out of 8 on the final build:

    • walks, sprint-jumps, turns, strafes, sneaks backwards, with Speed III and Jump Boost given then cleared;
    • sprint-jumps over packed ice, sprints on soul sand, swims across a pool, launches itself with a riptide trident;
    • walks into two cows summoned in front of it, which are then killed; has a stone block set in front of it (which it walks into before it hears of it) and jumps at it, the floor removed from under it then filled back;
    • flies in creative (double jump), then back to survival;
    • glides with an elytra from 60 blocks up, boosted by a firework;
    • boards a boat on a pool, paddles, sneaks out and sprints off it.

    The off ticks are all excused: the cows' pushes, the boat it stands on, the firework, the unseen blocks. Everything else replays exactly. The driver is check_prediction in tools/anticheat_e2e.py, which comes in (d) with the e2e PR; here it ran from that branch against this build.

  • A cheating client: in the same runs, a horizon-bots walker, which moves without sending any keys, is flagged from its first moves (moved up to 0.500 blocks off what its keys allow), 13 times, sent back 12 times and kicked.

  • Unit tests (lan::prediction, real 26.3 data):

    • a client that starts flying mid-walk counts on every tick from then on, weighing its offset (0.06 blocks: weight 2), and the setback point stays where it last walked honestly;
    • a push the server never sent, once excused, is caught up with in 2 ticks, and nothing counts;
    • a burst of ticks that comes with a teleport's accept is played first: the jump delay it started holds the client after the teleport, and the replay with it (fails without Replay::finish);
    • an elytra glide is played again exactly;
    • the honest, speed, fly and anti-knockback tests of (b1)/(b2) still pass.

    horizon-anticheat tests cover the unseen-change bookkeeping (a block change or a removed entity counts until a tick ends after its pong; a change dropped unseen still counts), the ticks a teleport keeps, and reject a tolerance of 0.

  • Cost, 60 walking bots on the ground, Mac mini, 30 s warmup + 120 s (--anticheat now replays every move but, with tolerance = 1000, flags none):

Build MSPT (runs) flags
this PR, anticheat off (the default) 4.52, 4.49 0
this PR, --anticheat 4.63, 4.94 0

About 0.1–0.4 ms a tick for 60 players: the replay of (b2), plus the nudge's look at the blocks around each player. The second --anticheat run is the highest of the four; the Mac mini's runs swing by about that much (the first round: 4.52 off, 4.63 on). The check itself adds a comparison per tick, and the excuse's look around the player (entities, blocks, chunks) runs only for a tick that landed off.

pr_ready

Check Result
Scope ⚠️ 13 files, +789 −119; 906 lines of code: over 500, split it if it can ship in parts (about 100 are closest_space_nudge moved out of Game and re-indented, about 250 are tests; the excuses and replay fixes are what keep honest players from being flagged, so the check can't ship without them)
Cargo.lock ✅ unchanged
Public tree ✅
Python tests ✅ 495 passed (1 min 3 s)
rustfmt ✅ (5 s)
clippy ✅ (45 s)
tests: horizon-anticheat, horizon-client ✅ 1353 passed (3 min 23 s)
doc tests ✅ 0 passed (1 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 ➖ 33 affected, to run in CI (--quick): block_removal, command_exec, composter, crafter, cursor_death, dedicated_server, dispenser, forced_end, friends_integration, hardcore_respawn, lan_integration, locator_bar and 21 more
Label player-facing: feature if players get something new, no label for a fix (release-now if urgent)

Harnesses for the server's players: server_knockback, dedicated_server and server_entities pass, rebased on main at 9d979caa4. tools/anticheat_e2e.py: off, timer and ground pass, their legit bots never flagged (those checks turn the prediction off).

Clean-room: written from vanilla 26.3 (ServerGamePacketListenerImpl.handleMovePlayer, teleport, PlayerList, ClientPacketListener.handlePlayerAbilities, LocalPlayer.aiStep and moveTowardsClosestSpace) and public descriptions of what movement cheats do. 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/5012 **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-check` --- ### 📝 Commits (1) - [`71d7921`](https://github.com/horizon-rust/horizon/commit/71d7921132e1f24bb7b7520e9d37ce5e8f3d2689) Anticheat prediction (c): flag moves off the replay, set back to where they agreed ### 📊 Changes **13 files changed** (+789 additions, -119 deletions) <details> <summary>View changed files</summary> 📝 `crates/horizon-anticheat/src/lib.rs` (+18 -4) 📝 `crates/horizon-anticheat/src/prediction.rs` (+134 -10) 📝 `crates/horizon-client/src/game.rs` (+60 -50) 📝 `crates/horizon-client/src/game/lan.rs` (+1 -1) 📝 `crates/horizon-client/src/game/prediction.rs` (+119 -20) 📝 `crates/horizon-client/src/lan/anticheat.rs` (+42 -1) 📝 `crates/horizon-client/src/lan/entity.rs` (+14 -2) 📝 `crates/horizon-client/src/lan/guest.rs` (+7 -0) 📝 `crates/horizon-client/src/lan/hub.rs` (+56 -3) 📝 `crates/horizon-client/src/lan/prediction.rs` (+328 -25) 📝 `docs/anticheat.md` (+1 -1) 📝 `tools/anticheat_e2e.py` (+4 -0) 📝 `tools/server_bench.py` (+5 -2) </details> ### 📄 Description > 🤖 Opened by Ludovic's AI agent (Claude), not by Ludovic himself. Movement prediction (c), after (b1) #4989 and (b2) #5003: **the check**. The replay now flags moves the player's own keys can't make (speed, step, fly, jesus, anti-knockback…) and sends the player back. Like every check it only runs with `[anticheat]` in server.toml, which no default server.toml has. `[anticheat.prediction] enabled = false` turns it off on its own. ## How it flags - A client tick that lands farther than `tolerance` (new setting, 0.03 blocks) from the replay counts. Its weight is its offset in tolerances, at most 5 a tick. The default thresholds stay `setback = 5`, `alert = 15`, `kick = 60`, `decay = 2`: a move 0.15 blocks off sets back at once, and a 1.3× speed hack after about two ticks. - The setback sends the player back to where its moves **last agreed** (`Replay::agreed`), not to where the server last had it, which by then is the cheater's own position. The teleport restarts the replay. - An honest client replays exactly (offset 0.0 on every tick in (b1) and (b2)). Only what the replay can't play yet can make an honest tick land off. Such a tick is **excused**, and so are the ticks after it until the moves agree again (40 at most): - another entity or player within 3 blocks (a push, a boat or shulker to stand on, a firework to fly with); - a block change within 4 blocks that the client hadn't seen (the record keeps, for each change near the player, the server tick that sent it, until a client tick has seen it) or that the server hasn't sent yet (`World::block_log`), and an entity the server removed near the player that the client may still have (a cow just killed); - abilities (game mode, flight, a glider put on) the client hadn't seen: the new `Change::Abilities`; - a moving piston, a chunk around the player that the client doesn't have, or a riptide launch; - a teleport that keeps the player's motion (an End gateway's). Around a fast player (an elytra with a firework) these distances grow by two ticks of its speed: the server's firework trails the player by about a tick. - Under an excuse the replay takes the client's velocity: each tick it adds the miss to its own (also on a tick with no move sent: the client stayed where it last said, on a boat say). So a push it never heard is caught up with in two ticks (`an_excused_push_is_caught_up_with`), instead of drifting for seconds. The excuse ends once a tick agrees within 0.001 blocks, not at the first one under the tolerance, so a glide's velocity is fully caught up with. - Three replay fixes found with real clients behind a jittery connection: - **The replay nudges the player out of a block it stands in** (`LocalPlayer.moveTowardsClosestSpace`): the client walked into a stone it hadn't received yet and was pushed out at 0.1 blocks a tick, which the replay didn't do. The nudge is worked out from the blocks, as the game does for its own player: `Game::closest_space_nudge` became a function of a body and the world (moved, about 100 of this PR's lines). - **A setback keeps the replay's body** (its jump delay, a glide); while the teleport is awaited the replay plays the ticks but nothing counts. - **Ticks that come in a burst with a teleport's accept are played before the replay starts again there** (`Replay::finish`). Before, they were skipped: the jump delay they started was lost, and the replay jumped a tick before the client (`a_burst_before_a_teleport_is_played_first`). `Record::teleported` keeps the ticks ended before the accept for that. - The bots of `tools/anticheat_e2e.py` (timer and ground checks) and of `server_bench.py --anticheat` move by their own rules, not vanilla's, so the prediction would flag every one of them. The harness turns it off for those checks. The bench keeps it replaying but sets `tolerance = 1000`, to measure an honest player's cost. The prediction's own e2e with real clients comes in (d). ## Measured - **A real Horizon client** on a dedicated server, survival, with `[anticheat]` and the prediction at its defaults, **through a relay that delays every packet by 20–120 ms** (in order). It does everything below and is **never flagged** (the anticheat log stays empty), in 8 runs out of 8 on the final build: - walks, sprint-jumps, turns, strafes, sneaks backwards, with Speed III and Jump Boost given then cleared; - sprint-jumps over packed ice, sprints on soul sand, swims across a pool, launches itself with a riptide trident; - walks into two cows summoned in front of it, which are then killed; has a stone block set in front of it (which it walks into before it hears of it) and jumps at it, the floor removed from under it then filled back; - flies in creative (double jump), then back to survival; - glides with an elytra from 60 blocks up, boosted by a firework; - boards a boat on a pool, paddles, sneaks out and sprints off it. The off ticks are all excused: the cows' pushes, the boat it stands on, the firework, the unseen blocks. Everything else replays exactly. The driver is `check_prediction` in `tools/anticheat_e2e.py`, which comes in (d) with the e2e PR; here it ran from that branch against this build. - **A cheating client:** in the same runs, a horizon-bots walker, which moves without sending any keys, is flagged from its first moves (`moved up to 0.500 blocks off what its keys allow`), 13 times, sent back 12 times and kicked. - **Unit tests** (`lan::prediction`, real 26.3 data): - a client that starts flying mid-walk counts on every tick from then on, weighing its offset (0.06 blocks: weight 2), and the setback point stays where it last walked honestly; - a push the server never sent, once excused, is caught up with in 2 ticks, and nothing counts; - a burst of ticks that comes with a teleport's accept is played first: the jump delay it started holds the client after the teleport, and the replay with it (fails without `Replay::finish`); - an elytra glide is played again exactly; - the honest, speed, fly and anti-knockback tests of (b1)/(b2) still pass. `horizon-anticheat` tests cover the unseen-change bookkeeping (a block change or a removed entity counts until a tick ends after its pong; a change dropped unseen still counts), the ticks a teleport keeps, and reject a tolerance of 0. - **Cost**, 60 walking bots on the ground, Mac mini, 30 s warmup + 120 s (`--anticheat` now replays every move but, with `tolerance = 1000`, flags none): | Build | MSPT (runs) | flags | |---|---|---| | this PR, anticheat off (the default) | 4.52, 4.49 | 0 | | this PR, `--anticheat` | 4.63, 4.94 | 0 | About 0.1–0.4 ms a tick for 60 players: the replay of (b2), plus the nudge's look at the blocks around each player. The second `--anticheat` run is the highest of the four; the Mac mini's runs swing by about that much (the first round: 4.52 off, 4.63 on). The check itself adds a comparison per tick, and the excuse's look around the player (entities, blocks, chunks) runs only for a tick that landed off. ## pr_ready | Check | Result | | --- | --- | | Scope | ⚠️ 13 files, +789 −119; 906 lines of code: over 500, split it if it can ship in parts (about 100 are `closest_space_nudge` moved out of `Game` and re-indented, about 250 are tests; the excuses and replay fixes are what keep honest players from being flagged, so the check can't ship without them) | | Cargo.lock | ✅ unchanged | | Public tree | ✅ | | Python tests | ✅ 495 passed (1 min 3 s) | | rustfmt | ✅ (5 s) | | clippy | ✅ (45 s) | | tests: horizon-anticheat, horizon-client | ✅ 1353 passed (3 min 23 s) | | doc tests | ✅ 0 passed (1 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 | ➖ 33 affected, to run in CI (--quick): block_removal, command_exec, composter, crafter, cursor_death, dedicated_server, dispenser, forced_end, friends_integration, hardcore_respawn, lan_integration, locator_bar and 21 more | | Label | player-facing: `feature` if players get something new, no label for a fix (`release-now` if urgent) | Harnesses for the server's players: `server_knockback`, `dedicated_server` and `server_entities` pass, rebased on main at 9d979caa4. `tools/anticheat_e2e.py`: off, timer and ground pass, their legit bots never flagged (those checks turn the prediction off). Clean-room: written from vanilla 26.3 (`ServerGamePacketListenerImpl.handleMovePlayer`, `teleport`, `PlayerList`, `ClientPacketListener.handlePlayerAbilities`, `LocalPlayer.aiStep` and `moveTowardsClosestSpace`) and public descriptions of what movement cheats do. 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:34 +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#6006
No description provided.