Why Invoice Reconciliation Pipelines Leak Cents (and How Fixed-Point BigInt + SHA-256 Merkle Trees Fix It)
Binary IEEE-754 float64 numbers cannot represent 0.10 USD without approximation (0.1 + 0.2 === 0.30000000000000004). Across ten thousand automated payouts, partial tax withholdings, or split fees, unquantized floats accumulate penny drift that breaks trial balances and audit trails.
1. Integer Micro-Dollars (10^-6 USD) and Banker's Rounding
In financial backends (mcp-automation-demo and the browser ledger workbench), internal arithmetic runs strictly on signed integers scaled at 10^-6 USD (1,000,000 micro-dollars per dollar) or Python Decimal:
- Intermediate fee and percentage calculations (such as
0.8%ACH fees capped at$5.00or35%estimated tax reserves) retain exact sub-cent precision until statement output. - Converting micro-dollars to GAAP cents uses
ROUND_HALF_EVEN(banker's rounding):$10.005rounds down to$10.00while$10.015rounds up to$10.02, eliminating systemic upward rounding bias. - Every double-entry posting credits and debits identically, holding trial balance drift strictly equal to
0($0.000000) across 1,000+ randomized transactions.
2. Read-Only Ingestion (mode=ro) and Two-Flag Write Gates
Automated reconciliation tools should never alter source accounting books implicitly. Opening SQLite sources in read-only URI mode (mode=ro + PRAGMA query_only = ON) and separating --allow-write from --apply turns dry-run inspection into the safe default.
3. Verifiable History via SHA-256 Merkle Inclusion Proofs
Logging reconciled exports alongside a binary SHA-256 Merkle tree (0x00 || leaf domain separation for leaves, 0x01 || left || right for internal nodes) lets auditors verify any single invoice row against the root digest in O(log N) hashes. Altering even $0.01 invalidates the inclusion proof immediately.
Run live 128-bit BigInt ledger balancing, bank CSV matching, and Merkle leaf tamper checks in the browser: https://nahianakhtar.github.io/demos/ledger-audit/.