Skip to content

feat(kernel): implement deterministic in-memory ledger - #10

Merged
kaikisegfault merged 9 commits into
mainfrom
feat/8-ledger-kernel
Jul 23, 2026
Merged

feat(kernel): implement deterministic in-memory ledger#10
kaikisegfault merged 9 commits into
mainfrom
feat/8-ledger-kernel

Conversation

@kaikisegfault

Copy link
Copy Markdown
Owner

Outcome

Implements the accepted version-one in-memory C++20 ledger kernel end to end:

  • strict signed-transfer admission through the pinned libsodium adapter;
  • checked native transfer execution and all specified receipts;
  • bounded canonical genesis loading;
  • typed state, transaction, and block commitments;
  • exact-next-height ordered block execution with atomic commit;
  • canonical Bech32m address encoding and decoding;
  • deterministic property, differential, boundary, and fuzz evidence.

Closes #8.

Scope and effects

The kernel remains an in-memory, single-native-asset application-state authority. It adds no persistence, RPC, networking, consensus adapter, deployment surface, public asset creation, or post-genesis issuance.

Consensus-visible behavior implements the already accepted v1 specifications. The normative primitive and ledger-transition vector files are unchanged. Account, chain, transaction, state-root, transaction-root, and block identifiers are distinct C++ types without changing their canonical 32-byte representations. Address text is an input/display boundary only and never enters ledger state.

The generic commitment path reproduces the specified zero-supply empty-state primitive vector; canonical genesis continues to require nonzero supply and at least one funded account. Cryptographic arithmetic remains isolated behind pinned libsodium 1.0.22.

Verification

All repository entry-point presets passed from this branch:

  • PROTOCOL_STACK_PRESET=gcc-debug tools/verify.sh — 12/12 CTest tests;
  • PROTOCOL_STACK_PRESET=gcc-sanitizers tools/verify.sh — 12/12 with ASan+UBSan;
  • PROTOCOL_STACK_PRESET=clang-debug tools/verify.sh — 12/12;
  • PROTOCOL_STACK_PRESET=clang-sanitizers tools/verify.sh — 15/15 with ASan+UBSan and three fixed-seed 512-run libFuzzer smokes.

Additional evidence:

  • 9,000 deterministic property scenarios cover all nine execution results, overlap precedence, exact post-state, atomicity, conservation, and roots;
  • 10,000 nonempty seeded differential sequences plus 11 directed sequences compare the public C++ ledger with an independent standard-library-only Python model across 19,972 blocks and 60,432 raw inputs;
  • frozen vector SHA-256 values remain c00e85ff9798ea907700e898113923b10411161c9bf2ba8c71fadec93a1b95a6 and 474bc322de153731f90506a29ae49cc5858197bfeefcfe11f91be36c6d4008d9;
  • CMake/JSON/TOML/YAML parsing, Python bytecode compilation, shell syntax, internal Markdown links, fuzz configuration guards, instrumentation checks, and git diff --check passed;
  • independent final reviews found no correctness, bounds, sanitizer, compatibility, or acceptance blockers.

Specifications and decisions

  • docs/specifications/protocol-primitives-v1.md
  • docs/specifications/ledger-transition-v1.md
  • docs/decisions/0004-protocol-primitives-v1.md
  • docs/decisions/0005-reproducible-cpp-toolchain.md
  • docs/decisions/0006-ledger-transition-v1.md
  • docs/architecture/ledger-kernel.md

Known limitations and follow-up

This PR deliberately stops at the in-memory kernel. The next M1 dependency is a replaceable persistent-state adapter with atomic commit, reopen, replay, snapshot, corruption, and crash-recovery evidence. Long-running fuzz campaigns remain separate from the bounded CI smoke sessions.

Implement the accepted transfer-result ordering, checked monetary writes, fee routing, self-transfer handling, and internal invariant failures behind a kernel-private helper. Reproduce the frozen ledger scenario and assert conservation and failure atomicity across all result codes.\n\nProtocol behavior follows ADR 0006 and ledger-transition-v1 without compatibility changes.\n\nRefs #8
Narrow version-one genesis to 21,844 accounts so its 46-byte prefix and 48-byte entries remain within the accepted 1,048,576-byte canonical-object limit. Clarify that strict Ed25519 canonicality and equation failures collapse to INVALID_SIGNATURE after the chain check.\n\nThe existing canonical fixture bytes and transition meaning are unchanged.\n\nRefs #8
Parse exact version-one genesis bytes with bounded account counts, ordered identifiers, checked supply conservation, and domain-separated chain IDs. Cover malformed, parameter, ordering, overflow, and 21,844/21,845 size boundaries under the full compiler and sanitizer matrix.\n\nRefs #8
Implement checked state conservation, ordered RFC 9162-style state and transaction trees, exact receipt and block-header encodings, and validated block identifiers. Reproduce every frozen commitment and exercise Merkle power-of-two and 65,535-leaf boundaries under all compiler and sanitizer presets.\n\nRefs #8
Add distinct protocol digest types and an owning public ledger that loads canonical genesis, enforces exact block height and input bounds, executes admitted transfers against tentative state, and publishes canonical receipts and commitments at one no-throw commit point.

Cover frozen outputs, public error boundaries, ordering, duplicates, resource limits, failure precedence, determinism, and ownership semantics across the full compiler and sanitizer matrix. Document adapter lifetimes and operational exception handling.

Refs #8
Add 9,000 deterministic invariant scenarios with exact success-state comparison and first-error precedence, plus an independent standard-library Python model and public C++ runner.

The fixed SplitMix64-v1 corpus checks 10,000 nonempty randomized sequences and 11 directed sequences after every successful block, including admission and execution outcomes, typed and encoded receipts, full state, roots, headers, and block IDs. Random coverage is enforced independently.

Refs #8
Run the unchanged primitive vectors through the production hash, signature, admission, Bech32m address, and commitment paths. Add bounded Clang libFuzzer smoke targets for admission, address decoding, and genesis loading under ASan and UBSan.

The generic commitment path now reproduces the specified zero-supply empty-state root; canonical genesis continues to require nonzero supply.

Refs #8
Point the durable handoff at PR #10 and the next persistence dependency so main will not inherit an obsolete branch-opening action.

Refs #8
@kaikisegfault
kaikisegfault merged commit 869129c into main Jul 23, 2026
4 checks passed
@kaikisegfault
kaikisegfault deleted the feat/8-ledger-kernel branch July 23, 2026 16:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Implement and differentially verify the in-memory C++20 ledger kernel

1 participant