Documentation Β· Pythagoras Β· Audit

Stoicism Precision Audit

v0.7.11 β€” Pythagoras Β· stamped against H.1.19

Every Stoicism point earned is preserved exactly. Forever.

The Ancient Holdings Hub stores, computes, and audits every Stoicism balance using arbitrary-precision decimal arithmetic. No floating-point drift. No accumulation noise. No rounding loss. Replay the events log on any other instance running the same code and migrations β€” you'll arrive at byte-identical balances.

Numerical contract

QuantityDecimalsNotes
server_score6stays f64 β€” input, not balance
tunneler_fee_promile1 (= 2-dec percent)capped + enforced server + UI
Stoicism balances12 exactdecimal.js, TEXT-stored
BASE_POINTS_PER_SECexact const = 0.001spec-locked
tick durationexact const = 60sspec-locked

Smallest non-zero per-tick accrual under this contract:0.001 Γ— 60 Γ— 1e-6 (server_score) Γ— 1e-4 (1-dec promile / 1000) = 6e-12Fits in 12 decimals exactly, by design.

Test suite β€” final acceptance gate

βœ“ 90/90 tests passing

npm test Β· 10 files Β· ~3s runtime

  • 31 unit tests on the decimal core (lib/stoic-decimal.ts) β€” every helper, every edge case.
  • 8 property tests with fast-check, 1000 random cases each, proving 5 mathematical invariants.
  • 14 integration tests on the schema migration (056).
  • 6 dual-write tests verifying every accrual path produces matching decimal results.
  • 5 read-path tests verifying the read swap to decimal columns.
  • 5 drift tests with random scenarios (1000 random tips, mixed warmup cycles, 500 Tunneler-fee ticks, mining bonuses, daily mint).
  • 1 reproducibility test β€” replay 1000+ synthetic events twice on fresh DBs, asserts byte-identical state.
  • 2 performance tests β€” 500-node tick in ~250ms (0.4% of the 60s budget).
  • 6 fee-precision tests β€” validator accepts integer + 1-decimal, rejects 2- and 3-decimal.
  • 3 sanity tests confirming the test harness itself works.

Five proven invariants

  1. Round-trip safety: fromDb(toDb(x)).equals(x) β€” any Stoicism value survives canonical 12-decimal TEXT round-trip exactly.
  2. Conservation: floor(x) + frac(x) === x β€” exact mint math; no fractional Stoicism leaks during floor().
  3. Associativity: (a + b) + c === a + (b + c) β€” f64 fails this for tiny values; Decimal honours it.
  4. Commutativity: a + b === b + a.
  5. Identities: x + 0 === x, x Γ— 1 === x, x Γ— 0 === 0.

Lint guard

scripts/check-stoicism-precision.ts scans lib/ and worker/ for any reference to the dropped legacy REAL column names. Wired into npm run prebuild β€” the build fails if anyone reintroduces them. Status: clean.

Sign-off

All gates green. Pythagoras is ready for production.

Source-controlled audit record: docs/stoicism-audit-report.md in the repo commits this audit alongside the code that produced it.

← back to Releases Β· The Stoic System