CNG · Financial Market Infrastructure — Clearing & Settlement
cNGN Stablecoin Settlement Hub
A C++23 clearing-and-settlement engine for a cNGN regional settlement hub: double-entry internal clearing, multilateral netting and CCP-style default management. Pre-production: settlement approvals are not yet cryptographically signed.
Maturity. Pre-production. Vlaander's internal review (7 October 2026) verified one critical and five high-severity defects in the earlier source. All six are fixed in the source you receive (commit b39bd88), each with a regression test that fails on the earlier code. Still open: settlement approvals count signer ids rather than verifying signatures, ingress frames are authenticated but not encrypted, and the keyed audit checkpoints are not published by the reference hub. Do not use this code to move real funds until those are addressed and an external security audit is done.
Overview
CNG is a C++23 settlement core for a hub where member institutions clear cNGN obligations against one another internally, and only the net positions are settled on-chain and over Nigerian bank rails at the end of a cycle.
At its centre is a single-writer, event-sourced double-entry ledger. It uses integer money and checked arithmetic, and checks conservation of value and non-negative balances on every command. Around it sit an authenticated ingress and compliance gate, a write-ahead log with replay recovery, a multilateral netting engine, a settlement-cycle orchestrator, connector code for an EVM chain and for NIBSS, and a default-management module (loss waterfall, settlement unwind and a Cover-N adequacy test).
The performance figures below come from building the exact source archive buyers receive and running it on the machine named, with the compiler and the archive's SHA-256 recorded.
The problem
A stablecoin hub that settles every payment gross on-chain pays settlement cost and needs intraday liquidity in proportion to gross volume. A hub that nets internally also needs a way to absorb a member that fails to fund its position. CNG is designed to provide internal clearing, netting and default handling in one codebase.
What it does
- Internal clearing on a single-writer double-entry ledger, with conservation and non-negativity checked on every transfer and integer money throughout. The sharded router rejects a reused command id before either leg posts.
- Authenticated ingress: every inbound frame is sealed with HMAC-SHA256 under the sending member's own key, the sender must own the debtor account, and each instruction's idempotency key is scoped to its sender, so one member cannot block or forge another's instructions. Frames are not encrypted; run the listener on a private network or behind TLS.
- Multilateral netting: net positions always sum to zero, and the settlement plan has at most k−1 instructions for k members with a non-zero position (property-tested).
- Compliance gate at ingress: KYB member registry, sanctions and watchlist screening, AML monitoring (large value, velocity, structuring), FATF Travel Rule (IVMS101) completeness and per-transaction, daily and counterparty limits. Each decision, including its parties and amount, is appended to a SHA-256 hash-chained log, and a replayed instruction does not consume limits again.
- Settlement-cycle orchestration with a cNGN ERC-20 connector (EVM JSON-RPC client, confirmation depth, reorg handling, and reverted transfers marked failed) and a NIBSS NIP client with NIP or RTGS chosen by amount. The HTTP/TLS transport and the transaction signer are interfaces: only test mocks are included.
- Default management: loss waterfall across prefunded tranches, settlement unwind that re-nets the surviving members, and a Cover-N adequacy test (Cover-2 is the usual setting).
- ISO 20022 pain.001 ingest with a strict cNGN profile. Other ISO 20022 messages (pacs, camt) are not implemented.
- Write-ahead log with CRC-checked records written in one system call per batch, fsync failures treated as fatal, torn tails trimmed on restart, and recovery by replay to the same hash-chain head. HMAC-keyed checkpoints of the ledger and compliance chains are available for publishing outside the hub.
Performance
Measured 2026-10-11| Metric | Figure | Basis |
|---|---|---|
| Clearing decision latency, per transfer | 331 ns median, 541 ns p99 | Measured by Vlaander |
| Clearing throughput, single core | 2,480,000 transfers per second | Measured by Vlaander |
| Hub end to end (sealed pain.001 in, sender authenticated, compliance gate, ledger applied, WAL group commit) | 80,000 messages per second | Measured by Vlaander |
| Ledger apply latency inside the hub | 480 ns median, 1,408 ns p99, 12,288 ns p99.9 | Measured by Vlaander |
| Recovery | Ledger rebuilt from the WAL has the same hash-chain head as the live ledger (5 of 5 runs) | Measured by Vlaander |
| Test suite | 211 test cases and 6 integration and smoke programs, 0 failures, with g++ 13.3 and clang 18.1, and under AddressSanitizer + UndefinedBehaviorSanitizer and ThreadSanitizer | Measured by Vlaander |
| Fuzzing | 2,000,000 generated inputs (two seeds), executed 6,000,000 times across Release and AddressSanitizer + UndefinedBehaviorSanitizer builds on both compilers (4,000,000 under the sanitizers), 0 failures | Measured by Vlaander |
- Date
- 2026-10-11
- Hardware
- AMD EPYC 7763, GitHub Codespace (shared Azure VM), 4 vCPU (2 cores), 15 GiB
- Toolchain
- g++ 13.3.0 (Ubuntu 24.04), -std=c++23 -O3, CMake Release build of the archive; tests, sanitizers and fuzzing also with clang 18.1.3
- Source archive SHA-256
- e394e54669424fe542d39f573fb9d930bc68bdfe0152d4feb5c34e9f725941f3
- Method
- Built from the extracted archive. Clearing: cngn_clearing_bench pinned to one core, 1,000,000 in-memory transfers across 64 accounts, each timed, median of 5 runs. Hub: cngn_hub, 20,000 sealed ISO 20022 messages end to end, then a fresh ledger recovered from the WAL and its hash-chain head compared with the live ledger, median of 5 runs. Both interleaved with the same tools built from the previous archive. Tests: ctest (cngn_tests plus the hub, settlement, compliance, go-live, default-management and fuzz smokes) on both compilers, in Release and under the sanitizers. Fuzz: cngn_fuzz, 1,000,000 inputs per run, two seeds under the sanitizers on each compiler and one Release run on each.
- Measured on the archive above. The archive delivered since 21 October 2026 (SHA-256 9c38e1e6c3670b1ef13be5c1db9473dfcb48c7ae56cba6bf98494f55da247012) was rebuilt from it with only its LICENSE file rewritten for licensing; the code, tests and benchmark tools are byte-identical.
- The machine is a shared cloud VM, not a dedicated benchmark host. The 1-minute load average was 2.7 to 3.2 during the runs, including the benchmarks' own threads.
- On the same machine, interleaved, the previous archive (SHA-256 aa5832b7…21b3) measured 1,223 ns median and 3,366 ns p99 per clearing decision, 670,000 transfers per second, and 100,000 hub messages per second with 1,792 ns median apply latency. The clearing gain comes from hardware SHA-256 instructions for the two audit hashes per decision and a pre-sized event log.
- The hub figure is lower than the previous archive's because every message is now sealed by the simulated member and its HMAC verified at the gateway. cngn_hub reports throughput to the nearest 10,000 messages per second.
- The two audit hashes per decision use the CPU's SHA instructions where present (x86 SHA-NI here); on CPUs without them a portable implementation is used and clearing is slower.
- The README in earlier archives quoted older, faster figures that Vlaander could not reproduce; they have been removed from this source.
Value in your own metrics
- Clearing decision latency
- Measured 331 ns median and 541 ns p99 per transfer, including two SHA-256 audit hashes.
- Throughput
- Measured 2,480,000 transfers per second on one core in memory; 80,000 authenticated ISO 20022 messages per second through the hub with WAL group commit.
- Recovery
- A ledger rebuilt from the WAL reached the same hash-chain head as the live ledger in all 5 runs (measured 11 October 2026).
- On-chain settlement volume
- Only net positions are settled, rather than every gross obligation.
Assurance and build
- Language
- C++23 with CMake; no third-party code in the archive; liburing optional for the io_uring TCP ingress. THIRD_PARTY_NOTICES.md lists the system libraries a build links
- Measured build
- g++ 13.3.0 -std=c++23 -O3 (Ubuntu 24.04), Release build of the archive
- Compilers
- Builds with -Werror and passes all tests with g++ 13.3 and clang 18.1 (measured 2026-10-11)
- Benchmark hardware
- AMD EPYC 7763, GitHub Codespace (shared Azure VM), 4 vCPU (2 cores), 15 GiB
- Source archive SHA-256
- 9c38e1e6c3670b1ef13be5c1db9473dfcb48c7ae56cba6bf98494f55da247012
- Formal specification
- TLA+ specs for the ledger (conservation, non-negativity) and netting (zero sum, gross bound), with bounded models that TLC v1.7.4 checked with no error found (measured 2026-10-11). The first check found a Redeem guard in the ledger spec that let issued supply go negative; it now mirrors the C++ code
- Sanitizers
- AddressSanitizer + UndefinedBehaviorSanitizer and ThreadSanitizer: all tests and smokes pass with no reports on both compilers (measured 2026-10-11); the included CI configuration runs both
- Fuzzing
- 2,000,000 generated inputs (two seeds of 1,000,000; the fuzzer produces the same inputs for a given seed), executed 6,000,000 times across Release and sanitizer builds on both compilers, 0 failures (measured 2026-10-11). The fuzzer is mutation-based, not coverage-guided; few inputs get past the XML and JSON layers
- Test surface
- 211 test cases and 6 integration and smoke programs, 0 failures (measured 2026-10-11)
- Test coverage
- Lines 96.9%, functions 99.5%, branches 82.9% (excluding exception paths) of the library code in engine/src and engine/include, from the project's own test suite (ctest 7/7 passing). g++ 13.3 and gcovr 8.8, measured by Vlaander on the delivered archive, 16 November 2026
- Developer's review
- docs/FORENSIC-REVIEW.md records the developer's own review and 17 findings it fixed before delivery; Vlaander has not verified who carried it out
- Internal review
- Vlaander quality gate, 7 October 2026: 1 critical and 5 high findings verified, all fixed in the delivered source (commit b39bd88) with regression tests that fail on the earlier code; of the 6 verified medium findings, 4 are fixed, 1 partly (audit chain keys) and 1 is open (signed approvals); 4 of the 5 low findings are fixed. The status of each is listed below. The review is by Vlaander, not an external firm.
- Decision records
- Architecture decision records in docs/adr, one per design decision listed in the README
- Licence
- Proprietary; licensed under the Licence Agreement, and Vlaander keeps ownership
Releases are not yet cryptographically signed, and no release manifests or external audit summaries are published. Check the source tarball you receive against its SHA-256 in Schedule 1 of your Licence Agreement, which you see before you sign.
Scope and maturity
What is real today, what is deliberately excluded, and what is pending — published unprompted.
Included today
- The source archive above: the ledger core, WAL and recovery, authenticated ingress, compliance gate, netting, settlement orchestration, default management, the EVM and NIBSS connector code, and the reference programs (hub, settle, comply, go-live, default demo, fuzz, clearing benchmark).
- Unit, property, differential, simulation and regression tests, TLA+ specs with TLC models, a CI configuration, architecture decision records, a runbook, a threat model, a go-live checklist and third-party notices.
Explicitly scoped out
- A production HTTP/TLS transport and a transaction signer (RLP and secp256k1). These are interfaces only, so the buyer must supply them, for example backed by a custody HSM.
- Transport encryption for the ingress listener (terminate TLS or WireGuard in front of it) and provisioning of the per-member ingress keys.
- Outbound ISO 20022 messages (pacs.008, pacs.002, camt statements).
- A network replication protocol and failover. The included replica is an in-process follower fed the same ordered commands.
Pending
- Critical, fixed in the delivered source (commit b39bd88): a cross-shard transfer that reused a command id could credit the payee with no debit, or debit the payer with no credit.
- High, fixed in the delivered source (commit b39bd88): the EVM connector counted confirmations for a reverted ERC-20 transfer. Only successful receipts count now, and a reverted settlement is marked failed for re-submission.
- High, fixed in the delivered source (commit b39bd88): a failed fdatasync was still counted as durable. The journal now stops and reports the failure, and a test injects the failing sync.
- High, fixed in the delivered source (commit b39bd88): replayed instructions used up a member's daily and counterparty limits again.
- High, fixed in the delivered source (commit b39bd88): the TCP ingress took the debtor from the message with no authentication and bound all interfaces. Frames must now be sealed with the sending member's key, the sender must own the debtor account, and the listener binds loopback unless configured. Frames are still not encrypted.
- High, fixed in the delivered source (commit b39bd88): command ids were chosen by the sender in one global namespace, so one member could block another's instructions, and colliding ids caused a 56-fold slowdown. Ids are now scoped per member and hashed with a secret key.
- Medium, fixed in the delivered source (commit b39bd88): a torn WAL write followed by more appends made the log unrecoverable; Shamir split and combine accepted bad parameters and short shares (an out-of-bounds read); the WAL wrote each record with two system calls (about half TigerBeetle 0.16.78's durable throughput in Vlaander's test).
- Medium, partly fixed (commit b39bd88): the audit hash chains have no key. HMAC-keyed checkpoints that expose a rewritten history are now included, but the reference hub does not issue or publish them.
- Medium (open): settlement approval counts bare signer ids; the Shamir key custody is used only in tests. Signed approvals or a threshold signature are needed before moving real funds.
- Reported by the review but not reproduced (open): NIBSS treats an ambiguous timeout as a final failure without a status query; the event log, idempotency set and limit histories grow without bound; the bridge trusts the RPC node's transaction hash.
Who it's for
- Licensed Nigerian financial institutions or consortia planning to operate a regional cNGN settlement hub, with an engineering team able to finish and harden it.
- Industry-utility or central-bank-adjacent vehicles evaluating CCP-style default management for digital-asset settlement.
- Regional clearing houses extending into digital-asset settlement.
Before you buy
- The review findings and their status are listed above, and docs/SECURITY.md in the source lists the open issues; each fix has a regression test you can run.
- Budget for the open work before any live use: signed settlement approvals, transport encryption at the ingress, key provisioning for members, publishing the audit checkpoints, bounded memory with snapshots, and a production HTTP/TLS transport and transaction signer.
- The figures above were measured by Vlaander on the stated hardware, a shared cloud VM, from the archive whose fingerprint is published above. The benchmark ships with the source, so you can rerun it after delivery; there is no way to run it before purchase, and no refund is available after delivery, except where a remedy cannot lawfully be excluded.
- Commission an external security audit before the system holds or moves real funds.
- Have counsel confirm the regulatory perimeter the hub would operate under, including CBN payment licensing and settlement-finality treatment; jurisdictional compliance risk sits with the buyer.
- Test the Cover-2 adequacy model against your intended member set and concentration profile, not the reference configuration.
What you get
- The asset's source, licensedSubject to the Licence Agreement, Vlaander grants the verified Buyer a perpetual, worldwide, non-exclusive, non-transferable licence to use, copy and modify the Asset, build it into the Buyer’s own products, and run, host and distribute those products to the Buyer’s customers in non-source form. The licence is for one company: it doesn’t cover affiliates. The source code stays confidential to the Buyer’s own staff and contractors, and may not be passed on, published or resold. Vlaander keeps ownership and licenses the same Asset to other businesses.
- Its testsThe test suite the published assurance claims rest on, as delivered in the source archive.
- Its audit artefactsSpecifications, model-checking output, reviews and the software bill of materials, where the asset has them.
- Not includedThird-party and open-source materials are not sold, assigned or licensed by Vlaander. They remain under their own licences, listed in each asset’s software bill of materials (SBOM.md in the archive), and the Buyer is responsible for complying with those licences.
Licence
Before you buy. Sold as a pre-production reference implementation: not for moving real money. Settlement approvals are not yet cryptographically signed; read the maturity notice and the open findings before buying.
$3,500 paid once · or ₦4,725,000
Included
- The engine's source archive, with its tests and audit artefacts, matching the SHA-256 in Schedule 1
- A perpetual, non-exclusive licence for one company under the Licence Agreement
Not included
- No updates
- No support
One price per engine, in US dollars, paid once. The source is what you get: Vlaander does not sell updates, support or bundles. The Licence Agreement you sign is the binding text.
First described in: VLA-GEN catalogue, 3 August 2026, §3.2. Revised by Vlaander against the delivered source; every figure is labelled with its basis.
From test to source
- 01
Check
Read the engine's page: what Vlaander measured and on which hardware, what it has not measured, and the open review findings. Nothing runs before purchase.
- 02
Buy
Verified businesses only. Choose an engine, give your company's details, have your authorised signatory sign the Licence Agreement, then pay the invoice in naira by bank transfer, or in USDC on Polygon. Once the payment is verified, your account shows Paid.
- 03
Receive
We confirm the funds and release the source tarball to you. Delivering, then Download ready. Check it against the SHA-256 in Schedule 1, then rerun the tests and benchmarks yourself.