Expand description
Rust authoring crate for Caputchin server-validated game replay.
Caputchin hosts a deterministic-replay captcha: a game records a trace, and the server re-runs the same sim over that trace and trusts only the replayed verdict. A conforming replay artifact is a freestanding WASM module exporting a tiny C-ABI the host marshals into. This crate writes that C-ABI for you.
Author a deterministic run (no clock, no RNG beyond the seed, no host
calls), then invoke caputchin_replay! once at your crate root:
use caputchin_replay_rs::{caputchin_replay, Verdict};
fn run(seed: [u32; 4], config: &[i32], trace: &[u8]) -> Verdict {
// decode config + trace, step the deterministic sim, return the result.
Verdict { passed: true, score: 0, duration_ms: 0 }
}
caputchin_replay!(run);The generated cap_alloc / cap_run exports, compiled to
wasm32-unknown-unknown with crate-type = ["cdylib"], are a complete
headless replay artifact: no wasm-bindgen, no imports.
config and trace are opaque to this crate. The host writes whatever
bytes (trace) and i32 array (config) your game encoded; your run decodes
them. The JS host glue lives in @caputchin/replay-wasm; the shapes are
owned by @caputchin/replay-contract.
Macros§
- caputchin_
live - Emit the Caputchin live-stepping C-ABI (
live_new,live_step,live_state,live_trace,live_free) for a type implementingLiveGame. Pairs withcaputchin_replay!: both compile from the SAME sim into ONE wasm, so the browser steps the identical module the server replays, and floats agree by construction. The JS host glue lives in@caputchin/replay-wasm. - caputchin_
replay - Emit the Caputchin replay C-ABI (
cap_alloc,cap_run) from arunfunction with signaturefn([u32; 4], &[i32], &[u8]) -> Verdict.
Structs§
- Verdict
- The result of a replay run. Matches the
Verdictshape in@caputchin/replay-contract: a pass/fail flag, an integer score, and a duration in milliseconds. Serialized across the C-ABI as three little-endiani32s[passed, score, duration_ms].
Traits§
- Live
Game - A live-steppable game: the SAME deterministic sim the replay
rundrives, exposed for frame-by-frame stepping by a browser renderer (the Lane 2 pattern). Thecaputchin_live!macro emits the browser C-ABI over a type implementing this, so the renderer drives the identical wasm the server replays. Inputs, the render state, and the trace are opaque to this crate.