Abstract
P2P(peer-to-peer) multiplayer protocols, such as lockstep and rollback net-code, have historically been the cheaper, direct alternative to the Client-Server model. Recent advances in WebRTC technology raise interesting prospects for independent developers to build serverless, P2P multiplayer games on the browser. P2P has several advantages over the Client-Server model in multiplayer games, such as reduced latency, significantly cheaper servers that only handle handshakes, etc. However, as the browser environment does not allow for third-party anti-cheat software, having a secure protocol that catches potential cheaters is crucial. Furthermore, traditional P2P protocols, such as deterministic lockstep, are unusable in the browser environment because different players could be running the game on different browser engines. This paper introduces a framework called Peercraft for P2P WebRTC games with both security and synchronization. We propose two P2P cheat-proofing protocols, Random Authority Shuffle and Speculation-Based State Verification. Both are built on known secure cryptographic primitives. We also propose a time-based synchronization protocol that does not require determinism, Resynchronizing-at-Root, which tolerates desynchronizations due to browser instability while fixing the entire desynchronization chain with only one re-simulation call, greatly improving the browser game’s performance.
Introduction: The Challenges of Browser-Based P2P
Building multiplayer games for the browser traditionally necessitates a Client-Server model. While robust, this model is expensive to maintain and often introduces significant latency. Peer-to-Peer (P2P) architectures offer a cheaper, faster alternative, but they face two primary "deal-breakers" in the browser environment: the Security Gap and the Determinism Gap.
The Security Gap arises because browsers do not permit third-party anti-cheat software. Since game code is often easily inspectable, malicious actors can manipulate their local state—for instance, by reporting false coordinates or infinite health to gain an unfair advantage.
The Determinism Gap stems from the fact that traditional P2P "lockstep" protocols require every client to calculate identical game states from identical inputs. However, variations in browser engines (e.g., V8 vs. SpiderMonkey) and hardware can lead to floating-point discrepancies. Furthermore, browsers often throttle or pause execution when a tab is inactive, causing immediate desynchronization.
Methodology: The Peercraft Framework
To address these issues, we introduce Peercraft, a framework utilizing novel protocols for security and synchronization.
Random Authority Shuffle and Speculation
To prevent players from reporting fraudulent data about themselves, Peercraft employs a Random Authority Shuffle. Using a hash commitment scheme (SHA-256), the network reaches a consensus every 10 ticks to randomly assign "authority." A player is made responsible for reporting the state of a different random peer. This makes targeted cheating statistically improbable.
Complementing this is Speculation-Based State Verification. Peers run their own "speculative" simulations of the game. If an authoritative player's report deviates significantly from the group's collective speculation, the network votes to reject the data and flags the potential cheater.
Resynchronizing-at-Root and Timing Synchronization
To manage browser-induced desyncs without constant "rubber-banding," Peercraft uses Resynchronizing-at-Root. This protocol identifies the specific "root" tick where a desynchronization originated. It ignores subsequent faulty state patches and corrects the entire chain with a single re-simulation call, optimizing CPU overhead.
Furthermore, instead of waiting for the slowest player, Peercraft utilizes local system time to drive a 15-tick-per-second loop. This allows the game to remain fluid even during network spikes, maintaining a consistent execution timeline across peers.
Results: Performance and Security
Peercraft achieves a synchronized 15-tick-per-second rate (66ms per tick), suitable for fast-paced action games. The timing protocol provides a 66ms error margin between clients without breaking synchronization. By moving networking and simulation logic to a Web-Worker, the framework ensures stability even when the main browser thread is occupied with UI rendering.
The combination of Random Authority Shuffle and Speculation makes subtle state manipulation detectable by the peer network, effectively closing the security gap inherent in browser environments.
Discussion: Limitations and Future Directions
A current limitation is the "Fog of War" problem. Peercraft requires all clients to possess all game data to verify each other's states, making it unsuitable for games with hidden information like Poker. Future research into Zero-Knowledge Proofs (ZKP) may allow players to prove move validity without revealing private data. Additionally, while ideal for lobby-based matches (up to 30 players), the P2P connection overhead currently limits its application in massively multiplayer environments.
Summary updated