From 058432130628d00764663ecf819a9adc6793768d Mon Sep 17 00:00:00 2001 From: salmonik Date: Sun, 8 Nov 2026 03:29:35 +0100 Subject: v5.0.0: protocol v5 and the browser frontend Protocol v5 replaces newline lines with bounded [u32 len][text] frames and REQ/RES/EVT envelopes. Requests carry correlation ids and the server replays the last 256 replies per connection, so a gateway retry cannot double-debit and a late reply cannot clobber a newer request. HELLO/PONG carry server time; crash rounds announce started_at and push coalesced 10 Hz ticks. Crash now commits sha256(seed) before a round and reveals the seed when it ends, so clients recompute the crash point. Adds the webd/ gateway: one blocking thread, one ClientCore and one pinned upstream TLS connection per session, an HttpOnly session cookie, takeover, and a 60-second grace window. The browser sends Command JSON and renders View JSON; it never speaks the game protocol or stores credentials. Adds the vanilla TypeScript browser app at /play/ (login, lobby, all four games, history, notices, crash verification), the nginx /play and /ws routes, and the headless DOM smoke test. webd and the app stay out of the TUI/GUI/server build graph. The client/server version moves to 5.0.0 in lockstep; v4 peers are refused at HELLO. --- tests/crash.rs | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) (limited to 'tests/crash.rs') diff --git a/tests/crash.rs b/tests/crash.rs index 797874b..513f9c8 100644 --- a/tests/crash.rs +++ b/tests/crash.rs @@ -102,3 +102,42 @@ fn crash_points_are_clamped_to_the_liability_cap() { assert_eq!(crash_point_from_uniform(0.999_999), MAX_MULTIPLIER); assert_eq!(crash_point_from_uniform(1.0), MAX_MULTIPLIER); } + +#[test] +fn a_seed_commits_to_its_crash_point_and_can_be_verified() { + use zagan_bet::crash::{ + SEED_LEN, commit_seed, crash_point_from_seed, seed_from_hex, seed_to_uniform, verify_seed, + }; + + let mut seed = [0u8; SEED_LEN]; + let value = (0.67_f64 * 18_446_744_073_709_551_616.0) as u64; + seed[..8].copy_from_slice(&value.to_be_bytes()); + let commit = commit_seed(&seed); + let hex = format!( + "{}", + seed.iter() + .map(|byte| format!("{byte:02x}")) + .collect::() + ); + + assert_eq!(seed_from_hex(&hex).as_deref(), Some(seed.as_slice())); + assert!(verify_seed(&hex, &commit)); + assert!(!verify_seed(&hex, &"00".repeat(32)), "a wrong commit fails"); + assert!(!verify_seed("nope", &commit), "bad hex fails"); + + // The point the client recomputes is the point the server committed to. + close(crash_point_from_seed(&seed), 3.0, 1e-9); + close(crash_point_from_seed(&seed), 3.0, 1e-9); + + // The first eight bytes are the uniform; the rest are still hashed. + close(seed_to_uniform(&seed), 0.67, 1e-9); + let mut altered = seed; + altered[SEED_LEN - 1] = 1; + assert!(!verify_seed( + &altered + .iter() + .map(|byte| format!("{byte:02x}")) + .collect::(), + &commit + )); +} -- cgit v1.2.3