Skip to content
embedded, verification, gaming, sas, formal-methods, konami, rust, c++

Proof-Backed Floor Software

I write C++ for Konami Gaming, slot floors, accounting protocols, timing that does not forgive a late reply. For the protocol host and the bench automation around the analyzer workflow, I picked Rust. C++ can be disciplined and I already live that on the floor. What I wanted here was a crate graph, a compiler, and a warning culture that lets me run the same gates without a secret map. One script before merge. clippy -D warnings as policy. Evidence that survives an auditor's questions and a teammate's Friday debug session.

I wrote the analyzer. I wrote the simulator. I designed the test system and ran the captures against my own code. The bench, the checks, and the protocol host are my work. Rust won because rustc and clippy argue with me before merge, not after a capture file is already wrong on disk.

What runs before merge

  1. Fast gates

    fmt, clippy, unit tests, vector drift

  2. Properties

    Ephyra on protocol state machines

  3. Formal

    loom, Kani, Miri, proof mutants

  4. End to end

    simulator timing, analyzer verdict

  5. RTSan

    no block or alloc on the polling loop

  6. Box probes

    latency harness, SCHED_FIFO, mlock

Rust toolchain in one table

The host is Rust because these tools turn intent into rules you can actually enforce.

ToolRole on the host
rustc / cargoWorkspace with locked deps; board targets share the same gates as the laptop
rustfmtMechanical style before anyone argues about taste
clippy-D warnings; no unwrap, panic, or unchecked indexing in shipped code
cargo-denyLicense and advisory policy before a crate lands in the tree
EphyraProperty tests on protocol state machines with shrinking
loomEvery interleaving of producer and consumer on the wait-free ring
KaniBounded proofs on index arithmetic and queue invariants
MiriStrict provenance when I need to stress unsafe hand-offs
RTSanReal-time regions on the SAS polling loop: block or alloc is a failure
Mutation testingProof patches must kill mutants named in their headers

Short answer when someone asks why this service is Rust while most of the floor stack around me stays C++.

Where the bench sits

I built the rendering test bench on purpose. A gaming machine simulator I wrote plays the EGM side with realistic byte timing. The protocol host sits in the middle with its middleware link and SAS polling loop. Captures land in the analyzer; headless tools replay them; scripts drive the same paths the UI uses.

I do not ship "I added a decode in the library" when the UI still cannot reach the button.

I keep the host honest: fixed buffers on the hot path, conformance tables that cannot silently drift from the analyzer codecs, and scenarios that hit tickets, funds, TLS, and mid-transfer restarts against the simulator, not a mocked socket that always behaves.

Money paths get the same respect as poll loops. An AFT transfer that restarts mid-flight must still reconcile with the middleware ledger. Wager-refund policy stays on the real bank path, not a second pretend wallet in test code. When I inject faults, I label them synthetic. Acknowledged-but-uncredited behavior is a test knob, not a claim about what a vendor did in 2009.

The bench docs describe simulator plus analyzer so anyone can press buttons, record captures, and open them in the same rule engine compliance uses. That is why I insist on headless parity with the UI. If only the GUI can run a scenario, CI cannot keep the tree honest.

~20 mspolling loopreply before the next byte
The SAS side expects an answer on a human-scale timer, not “eventually.”

Why Rust from a C++ mindset

In C++ I own memory layout, inlining discipline, and linker reality. Rust does not replace that mental model on the floor. It channels it. The borrow checker is loud early; clippy with warnings denied is loud at merge time. The workspace Cargo.toml and lint tables are the contract. I do not maintain a style guide that drifts from the build.

A C++ shop already gets "-Wall -Werror" culture. For this host, the crate graph is the win: conformance generators, the host binary, proof crates, and bench drivers share types without a bespoke CMake graph that drifts every quarter. cargo test --workspace --locked is one verb.

I still reach for C++ where the codebase, the vendor SDK, or the device image is already there. Rust is the language of this host because the compiler gives me the same feedback before bytes hit a capture file.

Layer 1: fast gates

The first minutes of feedback are boring on purpose. check.sh runs checks in the order failures are cheapest to find:

run "rustfmt" cargo fmt --all -- --check
run "clippy (host)" cargo clippy --workspace --all-targets --locked -- -D warnings
run "tests" cargo test --workspace --locked

On the full path, clippy also runs for ARM board targets. The workspace forbids unwrap, panic paths, and unchecked indexing in shipped code. That is -D warnings in Cargo.toml, not a comment in a README.

Conformance is not "I have tests." Generated conformance vectors from the analyzer codecs are regenerated and diffed. If TypeScript moved a field and Rust did not, merge stops before anyone flashes an edge device. The same script runs cargo-deny, rustdoc with warnings denied, and checks that capture writers and the analyzer agree field-for-field on .sascap round trips.

Deeper in the same script: conformance generation, property tests under a deep budget, board release builds for our ARM triples. Optional realtime work, loom on the ring, latency scripts, FIFO checks, sits behind a flag so laptops are not held hostage to six-minute proof runs on every save.

run "real time: RTSan, nothing on the SAS loop blocks or allocates" scripts/rtsan.sh 30 --strict
# Optional slow bundle: rt-ring proofs, benches, latency, SCHED_FIFO / mlock checks

This is what I want anyone to run first. Fast, deterministic, and it catches mistakes that look clever in a diff and embarrassing on a floor.

Layer 2: property tests

Binary protocols are state machines wearing byte masks. I use Ephyra-style property tests with a bounded budget per property (props-deep.sh). Not coverage theater. The framework explores weird interleavings of polls, exceptions, and hand-offs humans rarely type by hand.

Properties fail with shrinking. That matters when the bug is "ticket validation mode X with an EPR restart" rather than "wrong constant in a table."

Layer 3: formal methods on the hand-off

Concurrency on the floor is not "maybe I will add threads later." The SAS polling loop already hands work to recorder threads, middleware, and reporting without blocking. The wait-free SPSC ring (rt-ring) is the smallest building block I insist on proving.

Module documentation states the contract plainly:

//! - `push` and `pop` finish in a bounded number of steps (wait-free).
//! - Every pushed element is popped exactly once, in order; a full ring returns `Err(value)`.
//! - Release/Acquire pairs on the two indices order each hand-off.

A dedicated proof script runs loom (every interleaving of producer and consumer under the C11 model), Kani (index arithmetic against a reference queue), optional Miri with strict provenance, and mutation testing on proof patches. Each mutant must die on the proof named in its header.

proofs=(test loom kani)
((miri)) && proofs+=(miri)
for name in "${proofs[@]}"; do
  if proof "${name}"; then echo "PASS ${name}"
  else failed=1; fi
done

I rank design alternatives by measured latency and by whether they survive loom, not by how well they read in a design doc.

Layer 4: end to end with a verdict

Fast unit tests lie unless something exercises full packets on the wire with EGM-like timing. End-to-end scripts drive the protocol host against the native simulator for tens of seconds, often with --realistic-timing. They cover TLS to the middleware, legacy cipher suites, client certificates, ticket ledger modes, and funds paths with restart in the middle of a transfer.

Success is not "the process exited zero." Captures are judged by the analyzer headless stack. A small TypeScript entry builds a unified capture (SAS frames plus middleware and client events on one clock) and emits one JSON line of counts:

console.log(JSON.stringify({
  frames: h.session.frames.length,
  packets,
  clientPackets,
  errors: count("error"),
  warnings: count("warning"),
  findings,
}));

Merge is blocked when errors or warnings are non-zero. Same bar I would show a compliance reviewer: the analyzer's rule set applied to bytes I actually sent.

Layer 5: real-time discipline

SAS replies sit inside human-scale windows, on the order of twenty milliseconds from the write that committed a frame to the reply the EGM still accepts. The polling thread cannot hide behind "async will finish later."

RealtimeSanitizer builds the host with a pinned nightly and runs end-to-end while treating one turn of the polling loop as a real-time region. Blocking calls and heap allocations from that region are failures:

# One turn of the polling loop is the RT region; port wait stays outside.
# --gate: fail on lock, write, syscall, or allocation from the loop
# --strict: also fail host-state allocations on the poll path

I pair RTSan with allocation counting probes, latency harnesses against the realistic simulator, and optional checks that SCHED_FIFO and mlockall are refused for unprivileged runs but applied when capabilities allow. Privilege mistakes fail in CI instead of on a casino VLAN.

The loop uses fixed receive buffers, poll(2) on the SAS port, and nonblocking host steps. The shape I want on the hot path:

// Fixed port buffer; encode wide SAS frames into a kept buffer.
let mut port_buf = [0u8; 512];
loop {
    let n = port.wait_readable(&mut port_buf)?;
    host.step_nonblocking(|poll| {
        sas.on_bytes(&port_buf[..n], poll)
    })?;
    // Hand events to other threads via try_push on rt-ring; never block here.
}

Fixed poll buffers and inline frame storage removed the last accidental Vec growth on the hot path; RTSan went from dozens of intercepted blocking sites to zero on the loop. Latency harnesses record percentiles against the realistic simulator so I compare designs with numbers, not vibes.

If the polling thread allocates, locks, or writes to the console while the EGM still listens, you do not have a performance problem. You have a correctness problem in a profiler costume.

One script, same bar every time

Before a pull request I ask one thing: did check.sh pass? The script is the curriculum. With clippy -D warnings, nobody gets to "try unwrap and see." The build fails with the same message every time. That is how the compiler nudges me toward the boring-right fix the first time.

Touch the hand-off queue? Run rt-ring proofs. Touch polls? RTSan fails before hardware. Touch codecs? Vector regeneration fails if the analyzer moved. A design pitch without latency numbers or sanitizer cleanliness ranks below one that has both.

Fault injection, synthetic stalls, duplicated tickets, restart mid-transfer, lives in the bench, not on a slide. The simulator and analyzer are the oracle; the host is the system under test.

What I show an auditor vs. a teammate

To an auditor: ordered evidence. Conformance drift checks. Capture verdict JSON with zero errors. The mapping from analyzer rules to scenarios I run in CI (TLS, funds, tickets). Separate facts: service listening, bench configured, device ready, without conflating them. Retention and redaction boundaries on captures as the analyzer documents them.

To a teammate: how to run check.sh --quick on a laptop, when to flip the slow realtime bundle, how to read a failed verdict.ts line without opening three apps. One e2e directory, one RTSan worklist, so the next bug is hours, not weeks.

Closing

C++ is still the language around me on the floor: devices, legacy services, the parts that were hardened before this host existed. Rust is the language of the protocol host and the pre-merge script because rustc and clippy speak before hardware does.

Floor software at Konami scale is not one heroic debugger. It is a stack of fences. Fast gates keep the tree green. Properties and formal proofs keep scary concurrency from becoming "I only saw it once in the field." End-to-end verdicts keep the UI bench and the Rust host on the same bytes. Real-time sanitizers keep optimism off the SAS thread.

I am still on the floor in Las Vegas, still finishing my master's at UNLV, and still treating every regression as a question of money and time. This site is the notebook version: one script, cheap-to-expensive, captures as the judge, so I get a straight answer the first time I run it.

The pinned post is that notebook. The code lives in the tools I ship beside the analyzer and simulator. Something you can run on a Friday and trust on a Monday install.