aien-sovereign-core-mv
AienOS host runtime: inference scheduling, paged KV state, the aien CLI and Spark verification tooling. Its inference engine is in alpha testing (DGX Spark GB10); Omega is the implementation destination.
Brought by drakestapleton
GitHub aien-dev/aien-sovereign-core-mv#794 (code only)
Fetch it
curl -fsSL https://interplane.io/drakestapleton/aien-sovereign-core-mv/patches/a9ad69f02d41fdbc.bundle -o a9ad69f02d41fdbc.bundle git fetch a9ad69f02d41fdbc.bundle refs/pull/794/head
Provenance
github-import 1
aien-dev/aien-sovereign-core-mv
794
5b3b644eed359aa4c96377cdfdba76d11330a95d
{"kind":"github-import","owner":"aien-dev","repo":"aien-sovereign-core-mv","number":794,"url":"https://github.com/aien-dev/aien-sovereign-core-mv/pull/794","export_sha256":"967c79e26a893657b5cdaa45efd442be5dbd2ecfe68e25f9a8c1b5da4d60d452","imported_utc":"2026-11-18T16:38:02Z","metadata":"unavailable","state_derived":true}
Changes
diff --git a/.crumb b/.crumb index 312484df..4eb58b8b 100644 --- a/.crumb +++ b/.crumb @@ -65,68 +65,68 @@ "children": [ { "digest": "e5a81587d398cafcc737337c51428c09697768967eea61386a6ab34f7f871903", - "last_commit": "e8cc3aa", + "last_commit": "1604a72", "name": "crates/aien-allen", "purpose": "ALLEN identity gate: resolve-only subject check, host pin record, deployment record (ADR 0035). " }, { "digest": "a6f60499665540ddd49ad3122d016232b15d9cc878cb68febb725cd711dfbb6d", - "last_commit": "e8cc3aa", + "last_commit": "1604a72", "name": "crates/aien-allen-memory", "purpose": "ALLEN scoped memory store: scopes enforced at recall, inspect/correct/export, key-destroying for" }, { "digest": "3b65ec8698bac001b1d2aef39c1fce13a3475280186147af40a319212ed76d42", - "last_commit": "e8cc3aa", + "last_commit": "1604a72", "name": "crates/aien-allen-profile", "purpose": "ALLEN persona profile v1: versioned, user-editable profile bound to the engaged ALLEN identity; " }, { "digest": "36e3535aec78167f5eb088201510562ec415c3ee8293278d65623f299a9f954b", - "last_commit": "53beb96", + "last_commit": "1604a72", "name": "crates/aien-cli", "purpose": "" }, { "digest": "246e54412a28d811dc38af14bb943890fbafd85f55864c2468a04e6ea698062e", - "last_commit": "e8cc3aa", + "last_commit": "1604a72", "name": "crates/aien-scheduler/src/bin", "purpose": "" }, { "digest": "a684b3e7bb1d356b05a499af3962db5b12b37d565bf9bfdf31de6188af457131", - "last_commit": "53beb96", + "last_commit": "1604a72", "name": "crates/spark-cockpit-rs", "purpose": "" }, { "digest": "af5f9d6a21e7bdc0bce013df14b00648a9571513c9b719874799917e19e4e203", - "last_commit": "53beb96", + "last_commit": "1604a72", "name": "scripts", "purpose": "" }, { "digest": "75e439cb2ae120e1807af894b70b6454971028f5527f56451f9d6558f503c88b", - "last_commit": "9de5838", + "last_commit": "1604a72", "name": "skills", "purpose": "" }, { "digest": "0c9537893eb0ffd62f7403770bb3d2f815f3a415c8067f3c4fa2fd24418543c6", - "last_commit": "ca99c4b", + "last_commit": "1604a72", "name": "tools/aien-local-ci", "purpose": "Local CI sandbox exec contract (C8), aien-run user/caches install, Forgejo trigger hook, health " } ], "children_root": "sha256:31b31d0c22430a2b7dbaf536741c122daa8e98b3e30440b78e6f0b153415c048", - "compiled_at": "2026-10-28T03:03:48Z", + "compiled_at": "2026-10-28T11:56:45Z", "compiler": "crumb-compile/1", - "digest": "sha256:5d5f4a49f603535a52385349535b36056e7339e5409a035de71141c76edbea72", - "evidence_files": 3563, - "evidence_root": "sha256:dcebb871a65c368d29c9a58cecfcd272c04c00f1c5416f108888f16769983516", - "files": 8004, - "generated_at_commit": "28162550641982c66b50912ca61246af1e27ba0a", - "source_tree": "sha256:de489531c40307a568b3de2ff6316a1a38ddb75d7f4f40b16c2999bffcad3515" + "digest": "sha256:e9983f483ea9cabcdebffac46f4a66f91fa39fcb2320c30cd5c5c2ce72520304", + "evidence_files": 3586, + "evidence_root": "sha256:ee29710af304de14c30917f3cc8eb87c5b5e9a42b75dd9d009e842279d8075d0", + "files": 8028, + "generated_at_commit": "842914c94b12939c7163beefa5ee9ff41bd5b895", + "source_tree": "sha256:4890dcc27f56c57b2240354d7df8f21ea3b89b5040e789ebd13eb1a3dd99700c" } }, "history": [], diff --git a/evidence/aienet0-tur-ledger-20261027/README.md b/evidence/aienet0-tur-ledger-20261027/README.md index f22f18bc..7701bd67 100644 --- a/evidence/aienet0-tur-ledger-20261027/README.md +++ b/evidence/aienet0-tur-ledger-20261027/README.md @@ -48,3 +48,164 @@ Each mutant is the source with one guard removed by `sed`; the same suite must t power loss. Power-loss durability rests on `fsync` before the reply (strace order), not on a test. - Arithmetic values come from the #791 oracle (requester 70, provider 27, verifier 3, observer 0, escrow 0 of 100) and from differential runs (crash journal byte-identical to the control journal). + +## Authentication v2 addendum (2026-10-28, Core #793) + +The sections above and their three receipts describe unsigned v1. They are preserved byte for +byte and do not qualify admission or authorization. This addendum fixes the findings in +[the full #792 review](https://github.com/aien-dev/aien-sovereign-core-mv/pull/792#issuecomment-6466130214) +forward from main `1604a72b248aba8b0e41e5379814372d8fd59304`. + +**HOST_TESTED**, same Linux ARM64 host, no GPU, production key, live model, network service, +wallet or cryptocurrency. Source: `om/tur-ledger/tur-ledger.om`; native signature verification: +`om/vendor/ec.om`, copied unchanged from omega-mv +`6999fa9e6dae4847c155ef4eacaece74f491d3ca:om/tls/ec.om`, sha256 +`909f37c797e187bd0663bde9f57c75d6ce41eb2c9726a6b50d6fc714e424c060`. +Seeded compiler sha256: +`d6290c7663c2b4bafb59eb3fdf812476e977f4c144def71095c6248ef9b96b84`. +OpenSSL **3.0.13 (30 Jan 2024)** only creates test signatures; it is not linked into, invoked by +or needed to run the ledger. Disposable test private keys were generated in private tmpfs and +removed by the gate. No signer or key-management implementation is shipped here. + +The journal genesis and trusted `authority` config pin the issuer, a distinct verifier, ledger +identity, policy and exact requester/provider/verifier owner-account map. Every external +mutation has a canonical-record issuer signature. Settle additionally requires the verifier to +sign the **same complete authorization**, including reservation commitment, published quote, +exact payout split and signed-job/result/AN0V digests. This follows the design review's decisive +point: "The verifier must sign the complete settlement authorization, including reservation +commitment and payout split, not just result digests." Distinct keys alone are not operational +independence. Complete unauthorized records refuse replay rather than becoming recoverable tails. +Version-1 journals refuse unchanged; reconciliation requires an explicitly provisioned new +ledger identity, never silent migration. + +### New receipts + +`auth-v2-SHA256SUMS` covers only the new receipts and current source inputs. The original +`SHA256SUMS`, `check.out`, `tur_r0_check.out` and `fsync-and-journal.out` are unchanged. + +| Receipt / command | Observed | +|---|---| +| `auth-v2-before.out`: `OMC=/tmp/ledger-auth-omega/seed/out/omc TUR_LEDGER_AUTH_ONLY=/tmp/ledger-auth-before bash om/tur-ledger/check.sh` | Exit 1: **FAIL auth.unsigned-prefund**, actual ledger exit 0, expected 2; journal changed. Before binary `6ea978c7f0ae080c6bb0d0254f9fa56b78da2e74d577c092a98cd50bd945be4a`, built from main's v1 source and original SHA unit using the same compiler. | +| `auth-v2-after.out`: same command with `TUR_LEDGER_AUTH_ONLY=/tmp/ledger-auth-bin-final` | Exit 0: **PASS auth.unsigned-prefund**, ledger exit 2, unchanged journal. Exactly the same assertion. | +| `auth-v2-check.out`: `OMC=/tmp/ledger-auth-omega/seed/out/omc CRASH_N=200 MUTANT_CRASH_N=0 TUR_LEDGER_OUT=/tmp/ledger-auth-bin bash om/tur-ledger/check.sh` | Exit 0: **SUITE PASS**, **10/10 mutants killed**, **TUR_LEDGER gate: PASS**. Mutant crash trials omitted explicitly; honest-binary crash trials executed. | + +The suite exercised unsigned prefund/reserve/settle/refund refusal; wrong issuer and verifier +keys; altered amount, job, quote, result, signed-job and AN0V digest refusal; account spoofing; +issuer-key substitution for verifier; validly re-signed changed evidence conflicting with an +already-settled job; complete unsigned/wrong-key journal tails; v1 refusal and changed policy. +Each rejection asserts the journal hash is unchanged. The concurrent double-debit control +accepted exactly one reserve with only one unit funded. Honest settle paid provider 27 once; +the same signed semantics replayed as `already-settled`. + +A deterministic strace SIGKILL at stdout-write entry occurred **after fsync, before acknowledgement**; +the gate observed exit 137, successful fsync, an already-settled retry and provider balance 27. +The additional random-delay kill run killed all 200 attempted processes before a new durable +write (durable-before-kill 0). Each was audited and retried, final balances matched the control. +Journal bytes did not match the independently signed control because ECDSA signatures differ. +Do not read this run as 200 post-fsync kills: that boundary is the separate deterministic control. +Injected torn tails test framing recovery, not hardware power loss. + +The full gate compiled source hash +`960f4bb581e3c63cb193ef164736cf5394441ff580515be563b60cc42a53f4af`. +Only its build-instruction and exit-code comments were corrected afterwards: final source +`b188d4c8324eb1d99f9d5e0d08549c54358afca369171974433b456f59ae4ca6`. +Recompilation and `cmp /tmp/ledger-auth-bin /tmp/ledger-auth-bin-final` exited 0; both binaries +hash `d12d05cda56604410b8716602a7e3988a0e90901d28294f04f6ea7d8081f435c`. +The unsigned-after receipt uses that final binary. + +The shared SHA unit changed only its private `hs` state name to `hstate` and its explanatory +header, avoiding a name collision with the vendored EC parameter. Compiling `om/effects/world.om` +with original versus renamed SHA produced byte-identical binaries: +`08e1a63d722250d93dbec0574f902458262eb5e64b0b5e63b2f0eb70f9e3af0d`. +Both executions on `abc`, authorization 2, intent 3, returned 0, state DONE and record digest +`6281e53eed299bdb5467ccbfa7f87ae78c547a08660b9971df362c1680f048d1`. +This is a consumer smoke/parity check, not a claim that its separately pinned full Rust suite ran. + +### Scope boundary + +There is no `scripts/aienet0/settle-run.sh` or Core ledger RPC in this Core revision. +The external signer must verify the actual signed-job/MJR1/AN0V artifacts and quote/policy before +issuing these typed authorizations. The ledger verifies canonical bytes and signatures, not +those artifact parsers. Mutated-AN0V-digest refusal is **not** an external AN0V parser test; +lost CLI acknowledgement is **not** interrupted-RPC qualification. The application contract is +documented in `om/tur-ledger/README.md`; no compiler or shared guide language feature changed. +No deployment, malicious-filesystem-write/rollback resistance or public economic authority is claimed. + +## Capacity-discharge addendum (2026-10-28, Core #794) + +An additional review finding was reproduced: the old shared append guard required +four unused key slots even for settlement/refund, which allocate no keys. With a +full production-size signed journal, both commands returned exit 14 and left +existing escrow open. This affects the authenticated source at Core `6a0bfc0` too, +not only the original unsigned implementation. + +Capacity admission now belongs to the two allocating operations. Prefund counts +its new PID and a missing requester; reserve counts its new job and missing +provider/verifier accounts. Both refuse before append if those slots cannot fit. +Existing settlement/refund and authorized identical retries need no new slot. + +The native source exercised for this correction is +`f47d8c6374f5e8a49068cc5372e97582e3eb81e87c5e53a661ea62ebb4279713`; +the production binary is +`afd2fbe7b68a9f5fe44ff67b28830ab2499a482b1a922b237bc1877716a3ef93`. +`capacity-v2-before.out` shows the small-table regression failing before the fix. +`capacity-v2-check.out` records the complete fixed gate: SUITE PASS, twelve +mutants killed, clean capacity refusals, settlement and refund at capacity, +last-slot admission, unchanged duplicate retries, and the existing 200 kill/retry +trials. As in the earlier run, all random-delay kills preceded a new durable +write; the deterministic post-fsync/pre-ack kill remains a separate control. + +`capacity-v2-full.*` preserves a replayable production-size fixture: 65,536 +occupied key slots, valid issuer signatures on all prefunds/reservations and two +open reservations. The old binary returned 14 for both discharge commands; +the fixed binary refused new prefund/reserve with unchanged journal and then +successfully settled one job and refunded the other. These are synthetic +capacity-test authorizations, not receipts for real work or economic credits. +The compressed public journal and signed command vectors contain no private keys. +`capacity-v2-notes.txt` records provisioning, exact replay commands, hashes, +outputs and evidence limits; `capacity-v2-SHA256SUMS` seals these new receipts. +Original receipts and earlier authentication receipts remain unchanged. + +The companion actual-artifact caller migration is +[protocols #67](https://github.com/aien-dev/aien-protocols-mv/pull/67), stacked +on #65. It exercises genuine MJR1 forgery and AN0V countersignature refusal before +the test signers authorize a payout. It does not add a Core RPC or independent +operator qualification. + +## Independent audit corrections (2026-10-28, Core #794) + +The later audit found additional ledger defects in the authenticated implementation. +`audit-v2-before-final.out` exercises the frozen pre-audit source and exits 1; +`audit-v2-after.out` exercises the corrected source and exits 0. The frozen source +is retained as `audit-v2-before.om.at-run` for reproducible negative controls. + +| Finding | Before | After | +|---|---|---| +| A1, failed fsync then unsynced duplicate | Failed append left a record; retry and all four duplicate kinds could acknowledge without journal fsync | Repeated injected failures return 3 without acknowledgement and restore the original file; every duplicate must sync the actual journal fd and directory before success | +| A2, full key table | Existing settlement and refund returned 14 | New allocations refuse 14 unchanged; existing discharge succeeds even with all 65,536 production slots occupied | +| A3, missing authorities | Original unsigned prefund accepted; settlement lacked issuer/verifier authorization | Native canonical-record issuer/verifier signatures, pinned config/genesis and explicit v1 refusal; the authorization controls still pass | +| A10, complete corrupt final record | Audit could discard an acknowledged settlement as torn and permit refund | Newline-terminated corrupt records refuse 5 unchanged, including a validly signed body with only a bad final hash; only unterminated tails recover | +| A11, fused argv fields | Whitespace inside an argument was silently re-split into accepted fields | Each actual argument is checked before joining; all three fused-field controls refuse 2 unchanged | +| A12, terminal reserve retry | Returned `already-reserved` after settlement or refund | Open retry still succeeds; terminal retries refuse 10 unchanged | + +Final native source: +`8e16f25dd7be21d9dea94252b4ad0ab3b30ac107e4445ed81224d29982e1aadd`. +Final native binary: +`0338edb18a1fba9ecd7fa8ae294045184bfeb2e72530340017ce719acc682768`. +`audit-v2-check.out` records the complete final gate: SUITE PASS, seventeen +guard mutants killed and TUR_LEDGER gate: PASS. It retains 200 random-delay +kill/audit/retry trials (all before a new durable write) and the separate +deterministic post-fsync/pre-stdout kill; these are not RPC or power-loss tests. + +`audit-v2-full-capacity.results.tsv` replays the preserved public production-size +fixture using that final binary: prefund/reserve refuse 14 unchanged, settle and +refund return 0, and `audit-v2-full-capacity.out` reports open 0, settled 1, +refunded 1, balances equal prefunded and escrow 0. No fixture signatures were +reissued and no private keys are included. + +`audit-v2-notes.txt` records commands, individual controls, mutants, pins and +limitations; `audit-v2-SHA256SUMS` seals these later receipts separately. +`audit-v2-omega-tools.txt` records mounted Omega lookups and a sandboxed guard +negative control, explicitly distinguishing that older server pin from the +newer compiler used for the actual ledger gate. The existing application README +was updated; no shared language/compiler/harness contract changed. diff --git a/evidence/aienet0-tur-ledger-20261027/audit-v2-SHA256SUMS b/evidence/aienet0-tur-ledger-20261027/audit-v2-SHA256SUMS new file mode 100644 index 00000000..d5a956a8 --- /dev/null +++ b/evidence/aienet0-tur-ledger-20261027/audit-v2-SHA256SUMS @@ -0,0 +1,9 @@ +3fb8228d515c541cc4bead70b4b81d431e8f7efd382030721fc8426d156e43da audit-v2-before.out +dc20a4982c66f848b27a6f568d5a272cde4a466cc31944d4ae8c63560bcdc5a6 audit-v2-before-final.out +f47d8c6374f5e8a49068cc5372e97582e3eb81e87c5e53a661ea62ebb4279713 audit-v2-before.om.at-run +5181837bd4baf4a393c81a06324855fc03f12cdfa323052c0911e315ef510a77 audit-v2-after.out +f7f421090688a4b183ac06d15f6847d0bbc9e3dac9eb6573e67216e3435afa37 audit-v2-check.out +fc8912a80ad491cd8658ab1ca2b25e6d0515690c8535187322acd2a5ffceff51 audit-v2-full-capacity.results.tsv +8d7b7ae669df953de8bdf71c372ad5774ea9898c2e69e487fae4d2f46a5f6aa9 audit-v2-full-capacity.out +7de557e758c0f597604ed2fbf6c5e3a3b9d9d8d63cf0402930d8486486994a4a audit-v2-notes.txt +ab8346346d93e89167c0c67b4574bb82a6d463cb60cdd8b51fc5a1102498ad5a audit-v2-omega-tools.txt diff --git a/evidence/aienet0-tur-ledger-20261027/audit-v2-after.out b/evidence/aienet0-tur-ledger-20261027/audit-v2-after.out new file mode 100644 index 00000000..78025662 --- /dev/null +++ b/evidence/aienet0-tur-ledger-20261027/audit-v2-after.out @@ -0,0 +1,32 @@ +omc d6290c7663c2b4bafb59eb3fdf812476e977f4c144def71095c6248ef9b96b84 +src 8e16f25dd7be21d9dea94252b4ad0ab3b30ac107e4445ed81224d29982e1aadd om/tur-ledger/tur-ledger.om +sha 4f88dad60464eacd1655ba980f66b74000c6966ec0becbb80346ac1898e87a76 om/vendor/sha256.om +ec 909f37c797e187bd0663bde9f57c75d6ce41eb2c9726a6b50d6fc714e424c060 omega-mv@6999fa9e6dae4847c155ef4eacaece74f491d3ca +gate 8f96325dc3db714edf6837d4c78fb3e8ccc27dcc8e7a56798a5079fa152b2c21 +OpenSSL 3.0.13 30 Jan 2024 (Library: OpenSSL 3.0.13 30 Jan 2024) +audit-source 8e16f25dd7be21d9dea94252b4ad0ab3b30ac107e4445ed81224d29982e1aadd +PASS io.failed-sync-rollback-1 (exit 3, original journal, size 1047) +PASS io.failed-sync-rollback-2 (exit 3, original journal, size 1047) +PASS io.no-torn-tail-after-rollback +PASS io.retry-writes-and-syncs +PASS io.duplicate-prefund-needs-sync +PASS io.duplicate-prefund-retry-synced +PASS io.duplicate-reserve-needs-sync +PASS io.duplicate-reserve-retry-synced +PASS io.duplicate-settle-needs-sync +PASS io.duplicate-settle-retry-synced +PASS io.duplicate-refund-needs-sync +PASS io.duplicate-refund-retry-synced +PASS corrupt.acknowledged-settle +PASS corrupt.acknowledged-tail-audit (exit 5, unchanged journal) +PASS corrupt.acknowledged-tail-refund (exit 5, unchanged journal) +PASS corrupt.acknowledged-tail-show (exit 5, unchanged journal) +PASS corrupt.signed-tail-bad-hash (exit 5, unchanged journal) +PASS corrupt.original-settlement-preserved +PASS usage.fused-name-arguments (exit 2, unchanged journal) +PASS usage.fused-command-argument (exit 2, unchanged journal) +PASS usage.fused-role-arguments (exit 2, unchanged journal) +PASS phase.reserve +PASS phase.reserve-open-retry +PASS phase.reserve-after-settle (exit 10, unchanged journal) +PASS phase.reserve-after-refund (exit 10, unchanged journal) diff --git a/evidence/aienet0-tur-ledger-20261027/audit-v2-before-final.out b/evidence/aienet0-tur-ledger-20261027/audit-v2-before-final.out new file mode 100644 index 00000000..432ba249 --- /dev/null +++ b/evidence/aienet0-tur-ledger-20261027/audit-v2-before-final.out @@ -0,0 +1,32 @@ +omc d6290c7663c2b4bafb59eb3fdf812476e977f4c144def71095c6248ef9b96b84 +src 8e16f25dd7be21d9dea94252b4ad0ab3b30ac107e4445ed81224d29982e1aadd om/tur-ledger/tur-ledger.om +sha 4f88dad60464eacd1655ba980f66b74000c6966ec0becbb80346ac1898e87a76 om/vendor/sha256.om +ec 909f37c797e187bd0663bde9f57c75d6ce41eb2c9726a6b50d6fc714e424c060 omega-mv@6999fa9e6dae4847c155ef4eacaece74f491d3ca +gate 8f96325dc3db714edf6837d4c78fb3e8ccc27dcc8e7a56798a5079fa152b2c21 +OpenSSL 3.0.13 30 Jan 2024 (Library: OpenSSL 3.0.13 30 Jan 2024) +audit-source f47d8c6374f5e8a49068cc5372e97582e3eb81e87c5e53a661ea62ebb4279713 +FAIL io.failed-sync-rollback-1: exit 3 out '', journal restored no +FAIL io.failed-sync-rollback-2: exit 0 out 'dup unsynced req 5', journal restored no +PASS io.no-torn-tail-after-rollback +FAIL io.retry-writes-and-syncs: exit 0 out 'dup unsynced req 5' +FAIL io.duplicate-prefund-needs-sync: exit 0 out 'dup base req 100' +FAIL io.duplicate-prefund-retry-synced: exit 0, missing fsync or changed journal +FAIL io.duplicate-reserve-needs-sync: exit 0 out 'already-reserved 7777777777777777777777777777777777777777777777777777777777777777 req prov ver 40' +FAIL io.duplicate-reserve-retry-synced: exit 0, missing fsync or changed journal +FAIL io.duplicate-settle-needs-sync: exit 0 out 'already-settled 7777777777777777777777777777777777777777777777777777777777777777 aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa 27 3 10' +FAIL io.duplicate-settle-retry-synced: exit 0, missing fsync or changed journal +FAIL io.duplicate-refund-needs-sync: exit 0 out 'already-refunded 8888888888888888888888888888888888888888888888888888888888888888' +FAIL io.duplicate-refund-retry-synced: exit 0, missing fsync or changed journal +PASS corrupt.acknowledged-settle +FAIL corrupt.acknowledged-tail-audit: exit 0 expected 5, before 'b183d8e3d8c5015eee4dab480a092520dd1f2be07f022877832872cb2ea0ed06 /tmp/tmp.0oIjRHJwnB/audit-tail/journal' after 'f4814073f4e65755cc5da9634bb07b071282fb2a454c7ac3f087d32fdaa6cf08 /tmp/tmp.0oIjRHJwnB/audit-tail/journal' +FAIL corrupt.acknowledged-tail-refund: exit 0 expected 5, before 'b183d8e3d8c5015eee4dab480a092520dd1f2be07f022877832872cb2ea0ed06 /tmp/tmp.0oIjRHJwnB/audit-tail/journal' after '5055a7848827088241c5c606fc2d48643451c6c7c88197db88ee0f348f8a8ad0 /tmp/tmp.0oIjRHJwnB/audit-tail/journal' +FAIL corrupt.acknowledged-tail-show: exit 0 expected 5, before 'b183d8e3d8c5015eee4dab480a092520dd1f2be07f022877832872cb2ea0ed06 /tmp/tmp.0oIjRHJwnB/audit-tail/journal' after 'f4814073f4e65755cc5da9634bb07b071282fb2a454c7ac3f087d32fdaa6cf08 /tmp/tmp.0oIjRHJwnB/audit-tail/journal' +FAIL corrupt.signed-tail-bad-hash: exit 0 expected 5, before '3d9188b8ec85b672956dd64a81449028c6474997d2aada6b67d1bd6fed5d7e49 /tmp/tmp.0oIjRHJwnB/audit-tail/journal' after '31b555cf10275255230864665c19c68495b9c954feaf6338f4a73d712246d605 /tmp/tmp.0oIjRHJwnB/audit-tail/journal' +PASS corrupt.original-settlement-preserved +FAIL usage.fused-name-arguments: exit 0 expected 2, before '1e21269a05c637d510a4ce219ce8a81b0e4505e32fa238463dd1789d1d4e56e4 /tmp/tmp.0oIjRHJwnB/audit-argv/journal' after '6cbeb155b5193e72e34a847f997cd85c44fa146605fa159f7a0864ef5be32891 /tmp/tmp.0oIjRHJwnB/audit-argv/journal' +FAIL usage.fused-command-argument: exit 0 expected 2, before '6cbeb155b5193e72e34a847f997cd85c44fa146605fa159f7a0864ef5be32891 /tmp/tmp.0oIjRHJwnB/audit-argv/journal' after '03fb8db4f3d8c4420b864d5221113a23b4084cc5637a1b3eafde0c73eda55bda /tmp/tmp.0oIjRHJwnB/audit-argv/journal' +FAIL usage.fused-role-arguments: exit 0 expected 2, before '03fb8db4f3d8c4420b864d5221113a23b4084cc5637a1b3eafde0c73eda55bda /tmp/tmp.0oIjRHJwnB/audit-argv/journal' after 'b266e0fc6eac7fb95a248322849ebb54b09b37aca8035511b36dbc216ddc0d88 /tmp/tmp.0oIjRHJwnB/audit-argv/journal' +PASS phase.reserve +PASS phase.reserve-open-retry +FAIL phase.reserve-after-settle: exit 0 expected 10, before '32cfc8c8483aa6e6198fa39779c986e0e60cb27012b56b36c4d6f71503097702 /tmp/tmp.0oIjRHJwnB/audit-phase/journal' after '32cfc8c8483aa6e6198fa39779c986e0e60cb27012b56b36c4d6f71503097702 /tmp/tmp.0oIjRHJwnB/audit-phase/journal' +FAIL phase.reserve-after-refund: exit 0 expected 10, before '62aaeb3f6040f5b975f684e6993bc00b8bd2bad1822f634511f50fb05301c20a /tmp/tmp.0oIjRHJwnB/audit-phase/journal' after '62aaeb3f6040f5b975f684e6993bc00b8bd2bad1822f634511f50fb05301c20a /tmp/tmp.0oIjRHJwnB/audit-phase/journal' diff --git a/evidence/aienet0-tur-ledger-20261027/audit-v2-before.om.at-run b/evidence/aienet0-tur-ledger-20261027/audit-v2-before.om.at-run new file mode 100644 index 00000000..eef0a103 --- /dev/null +++ b/evidence/aienet0-tur-ledger-20261027/audit-v2-before.om.at-run @@ -0,0 +1,1609 @@ +note SPDX-License-Identifier: Apache-2.0 +note tur-ledger: the Aienet-0 TUR test-credit escrow ledger. One append-only journal, one writer +note at a time, settle exactly once per JOB. Arithmetic is tests/turing-network/tur_r0_oracle.om +note applied per JOB: reserve moves AMOUNT from REQ into that JOB's escrow; settle pays PAYP to +note PROV, PAYV to VER and BACK to REQ, refused unless PAYP <= escrow, PAYV <= escrow - PAYP and +note BACK = escrow - PAYP - PAYV; a JOB is reserved once and settled or refunded once. +note Build: check.sh composes om2, vendor/sha256.om, vendor/ec.om and this program for pinned omc. +note All external mutations require an issuer DER P-256/SHA-256 signature (hex final argument). +note Settle additionally requires the independent verifier signature; reserve adds QUOTE_SHA256; +note settle adds SIGNED_JOB_SHA256 AN0V_SHA256 before its two signatures. See README for canonical bytes. +note Journal DIR/journal: SEQ PREV KIND FIELDS... HASH. Genesis is the exact DIR/authority config. +note Version 2 refuses unsigned/version-1 journals. The hash chain is not an authorization mechanism. +note Every command opens DIR/journal, takes flock LOCK_EX on it for the whole command and replays +note it: SEQ, PREV and HASH are checked on every line, then the record is applied. A LAST line that +note is unterminated, unparseable or whose HASH does not match its own bytes is a torn tail: it is +note truncated, fsynced, and a "recover N SHA" record (N torn bytes, SHA their sha256) is appended. +note A complete self-consistent line whose SEQ or PREV does not link (a deleted or reordered +note record), or any bad line before the last, is corruption and the ledger refuses (exit 5). +note After replay the ledger checks conservation (exit 6): the sum +note of balances plus open escrow equals the sum of prefunds, open escrow equals the open JOBs' +note amounts, and every settled JOB paid out exactly its amount. A new record is written with +note pwrite and fsynced before the command prints its result. +note Exit: 0 ok (also dup / already-*), 2 usage, 3 journal io, 4 lock, 5 journal corrupt, +note 6 conservation violated, 7 insufficient funds, 8 unknown job, 9 job conflict, 10 wrong phase, +note 11 settle receipt conflict, 12 escrow rule, 13 prefund id conflict, 14 capacity, 15 overflow, +note 16 missing config or unauthorized signer/policy. Missing signature arguments are usage (2). +note Accounts, PIDs and JOBs: KCAP keys in all. A name is 1..64 bytes of [A-Za-z0-9._:-]; JOB and +note RECEIPT_SHA256 are 64 lowercase hex bytes; amounts are decimal u64 without leading zeros. +const KCAP ulong 65536 +const KIX ulong 131072 +const KW ulong 64 +const SPRE ulong 0 +const SESC ulong 1 +const SSEQ ulong 2 +const SGOOD ulong 3 +const SKEYS ulong 4 +const SRECS ulong 5 +const SNF ulong 6 +const SLN ulong 7 +const SOB ulong 8 +const SOVF ulong 9 +const SBAD ulong 10 +const SFLEN ulong 11 +const SFSZ ulong 12 +const SFD ulong 13 +const SSLOT ulong 14 +const SRF ulong 15 +const SLONG ulong 16 +const STORN ulong 17 +const SWB ulong 18 +global st ulong 32 +global ga uchar 8192 +global gs ulong 16 +global gl ulong 16 +global pb uchar 4200 +global lb uchar 1024 +global fo ulong 16 +global fl ulong 16 +global ob uchar 4096 +global wb uchar 2048 +global rb uchar 65536 +global ph uchar 64 +global th uchar 64 +global kb uchar 4194304 +global kl ulong 65536 +global kt ulong 65536 +global ki ulong 131072 +global d0 ulong 65536 +global d1 ulong 65536 +global d2 ulong 65536 +global d3 ulong 65536 +global d4 ulong 65536 +global d5 ulong 65536 +global d6 ulong 65536 +global d7 ulong 65536 +global rc uchar 4194304 +note Authority config is provisioned externally; no private keys or automatic trust establishment. +global cfg uchar 1024 +global cfgn ulong 1 +global cfo ulong 12 +global cfl ulong 12 +global ah uchar 64 +global pa uchar 4194304 +global ja uchar 4194304 +global sa uchar 4194304 +text apath "/authority" +text auerr "refused 16 authorization\n" + +fn authdie to void +e = write 2 auerr 0 len auerr +exit 16 +end + +fn hexf i ulong n ulong to bool +if ne get fl i n +ret false +end +for j ulong n +c = get lb add get fo i j +if not or and ge c 48 le c 57 and ge c 97 le c 102 +ret false +end +end +ret true +end + +fn cfeq f ulong b ulong to bool +if ne get cfl f get fl b +ret false +end +for i ulong get cfl f +if ne get cfg add get cfo f i get lb add get fo b i +ret false +end +end +ret true +end + +note acfg reads one canonical genesis body, no LF. Fixed policy names bind account and node owners. +fn acfg to void +n = get gl 2 +if or eq n 0 gt n 4000 +die 2 +end +for i ulong n +put pb i get ga add get gs 2 i +end +for i ulong len apath +put pb add n i get apath i +end +fd = fopen pb 0 add n len apath 524288 0 +if lt fd 0 +authdie +end +k = read int fd lb 0 len lb +if or le k 0 ge k long len lb +authdie +end +z = read int fd pb 0 1 +cl = fclose int fd +if or ne z 0 ne cl 0 +authdie +end +if not split ulong k +authdie +end +if ne get st SNF 12 +authdie +end +if not and fis 0 22 fis 1 24 +authdie +end +if not and fhex 2 and hexf 3 130 and hexf 4 130 fhex 5 +authdie +end +if not and fname 6 and fname 7 fname 8 +authdie +end +if not and fhex 9 and fhex 10 fhex 11 +authdie +end +put cfgn 0 ulong k +for i ulong ulong k +put cfg i get lb i +end +for i ulong 12 +put cfo i get fo i +put cfl i get fl i +end +if cfeq 3 4 +authdie +end +if or cfeq 6 7 or cfeq 6 8 cfeq 7 8 +authdie +end +put st SLN 0 +end + +note ahash: SHA256(config || LF || canonical unsigned body || LF [|| reserve-auth-hash || LF]). +note Signatures and journal framing are excluded; operation identity is the semantic hash. +fn ahash b ulong sig ulong job bool to void +hreset +for i ulong get cfgn 0 +x = hpush get cfg i +end +x = hpush 10 +o = get fo b +for i ulong sub sub get fo sig 1 o +x = hpush get lb add o i +end +x = hpush 10 +if job +j = kfind 1 add b 1 +if ne j 0 +for i ulong 64 +x = hpush get ja add mul sub j 1 KW i +end +x = hpush 10 +end +end +y = hfinal +for i ulong 64 +put ah i get hd i +end +end + +fn authsig f ulong key ulong to bool +pub = new uchar 65 0 +sg = new uchar 104 0 +n = get fl f +if or lt n 16 gt n 144 +ret false +end +if ne rem n 2 0 +ret false +end +if not hexf f n +ret false +end +for i ulong 65 +o = add get cfo key mul i 2 +v = or shl hnibble get cfg o 4 hnibble get cfg add o 1 +put pub i uchar v +end +for i ulong 32 +o = mul i 2 +put sg i uchar or shl hnibble get ah o 4 hnibble get ah add o 1 +end +for i ulong div n 2 +o = add get fo f mul i 2 +v = shl hnibble get lb o 4 +v = or v hnibble get lb add o 1 +put sg add 32 i uchar v +end +sz = add 32 div n 2 +ret eq ecdsa_verify 256 pub part sg 0 sz 32 0 +end + +fn authrec b ulong fields ulong job bool dual bool to bool +need = add fields 1 +if dual +need = add need 1 +end +if ne get st SRF need +ret false +end +ahash b add b fields job +if not authsig add b fields 3 +ret false +end +if dual +if not authsig add add b fields 1 4 +ret false +end +end +ret true +end + +fn aeqhash mode ulong k ulong to bool +for i ulong 64 +o = add mul k KW i +v = get pa o +if eq mode 1 +v = get ja o +end +if eq mode 2 +v = get sa o +end +if ne v get ah i +ret false +end +end +ret true +end + +fn asave mode ulong k ulong to void +for i ulong 64 +o = add mul k KW i +if eq mode 0 +put pa o get ah i +end +if eq mode 1 +put ja o get ah i +end +if eq mode 2 +put sa o get ah i +end +end +end +note tw: words, separated by ~ (byte 126). Word c - 1 is the reason for exit code c (2..15). +text tw "refused ~usage~journal-io~lock~journal-corrupt~conservation-violated~insufficient-funds~unknown-job~job-conflict~wrong-phase~settle-receipt-conflict~escrow-rule~prefund-id-conflict~capacity~overflow~prefund~reserve~settle~refund~balance~show~audit~genesis~recover~tur-ledger-2~prefunded~dup~reserved~already-reserved~settled~already-settled~refunded~already-refunded~job ~audit ok records ~ head ~ accounts ~ jobs ~ open ~ settled ~ refunded ~ prefunded ~ balances ~ escrow ~recovered torn-tail ~ bytes sha256 ~--journal~/journal~usage: tur-ledger --journal DIR COMMAND (see om/tur-ledger/README.md for signed v2 commands)~balance ~" +text hx "0123456789abcdef" + +note fst: start of word k in tw; its length goes to st SFLEN. +fn fst k ulong to ulong +c = ulong 0 +s = ulong 0 +for i ulong len tw +if eq get tw i 126 +if eq c k +put st SFLEN sub i s +ret s +end +c = add c 1 +s = add i 1 +end +end +put st SFLEN 0 +ret 0 +end + +note cadd: a + b; an overflow sets st SOVF. +fn cadd a ulong b ulong to ulong +s = add a b +if lt s a +put st SOVF 1 +end +ret s +end + +note oput / ofr / odec / ofld / okey / ohex: append to the output line ob. +fn oput c uchar to void +n = get st SOB +if lt n len ob +put ob n c +put st SOB add n 1 +end +end + +fn ofr k ulong to void +s = fst k +for i ulong get st SFLEN +oput get tw add s i +end +end + +fn odec v ulong to void +p = ulong 1 +while le p div v 10 +p = mul p 10 +end +x = v +while gt p 0 +oput uchar add 48 div x p +x = rem x p +p = div p 10 +end +end + +fn ofld i ulong to void +o = get fo i +for j ulong get fl i +oput get lb add o j +end +end + +fn okey k ulong to void +b = mul k KW +for j ulong get kl k +oput get kb add b j +end +end + +fn orc k ulong to void +b = mul k KW +for j ulong 64 +oput get rc add b j +end +end + +note oflush: write ob to fd and empty it. +fn oflush fd int to void +o = ulong 0 +m = get st SOB +while lt o m +w = write fd ob o sub m o +if ne w -4 +if le w 0 +put st SOB 0 +ret +end +o = add o ulong w +end +end +put st SOB 0 +end + +note die: "refused C reason" on stderr, exit C. +fn die c int to void +put st SOB 0 +ofr 0 +odec ulong c +oput 32 +ofr sub ulong c 1 +oput 10 +oflush 2 +exit c +end + +note lbput / lbfr / lbdec / lbarg / lbhex: build a record body in lb (length st SLN). +fn lbput c uchar to void +n = get st SLN +if ge n len lb +die 2 +ret +end +put lb n c +put st SLN add n 1 +end + +fn lbfr k ulong to void +s = fst k +for i ulong get st SFLEN +lbput get tw add s i +end +end + +fn lbdec v ulong to void +p = ulong 1 +while le p div v 10 +p = mul p 10 +end +x = v +while gt p 0 +lbput uchar add 48 div x p +x = rem x p +p = div p 10 +end +end + +fn lbarg i ulong to void +s = get gs i +for j ulong get gl i +lbput get ga add s j +end +end + +note split: fields of lb[0 .. n) separated by single spaces into fo / fl, count in st SNF. +fn split n ulong to bool +nf = ulong 0 +s = ulong 0 +for i ulong n +if eq get lb i 32 +if or eq i s ge nf 15 +ret false +end +put fo nf s +put fl nf sub i s +nf = add nf 1 +s = add i 1 +end +end +if eq n s +ret false +end +put fo nf s +put fl nf sub n s +put st SNF add nf 1 +ret true +end + +note fis: field i equals word k. +fn fis i ulong k ulong to bool +s = fst k +n = get fl i +if ne n get st SFLEN +ret false +end +o = get fo i +for j ulong n +if ne get lb add o j get tw add s j +ret false +end +end +ret true +end + +fn namec c uchar to bool +if and ge c 48 le c 57 +ret true +end +if and ge c 65 le c 90 +ret true +end +if and ge c 97 le c 122 +ret true +end +if or or eq c 46 eq c 95 or eq c 58 eq c 45 +ret true +end +ret false +end + +note fname: field i is a name, 1..64 bytes of [A-Za-z0-9._:-]. +fn fname i ulong to bool +n = get fl i +if or eq n 0 gt n 64 +ret false +end +o = get fo i +for j ulong n +if not namec get lb add o j +ret false +end +end +ret true +end + +note fhex: field i is 64 lowercase hex bytes. +fn fhex i ulong to bool +if ne get fl i 64 +ret false +end +o = get fo i +for j ulong 64 +c = get lb add o j +if not or and ge c 48 le c 57 and ge c 97 le c 102 +ret false +end +end +ret true +end + +note fnum: field i as a decimal u64 (no sign, no leading zero); a bad field sets st SBAD. +fn fnum i ulong to ulong +n = get fl i +o = get fo i +if or eq n 0 gt n 20 +put st SBAD 1 +ret 0 +end +if and gt n 1 eq get lb o 48 +put st SBAD 1 +ret 0 +end +v = ulong 0 +for j ulong n +c = get lb add o j +if or lt c 48 gt c 57 +put st SBAD 1 +ret 0 +end +d = ulong sub c 48 +if gt v div sub 18446744073709551615 d 10 +put st SBAD 1 +ret 0 +end +v = add mul v 10 d +end +ret v +end + +note Keys: type 0 account (d0 balance), 1 job (d0 req, d1 prov, d2 ver key ids, d3 amount, +note d4 phase 1 reserved 2 settled 3 refunded, d5 payp, d6 payv, d7 back, rc receipt), +note 2 prefund id (d0 account key id, d1 amount). ki is an open-addressed index of key id + 1. +fn khash t ulong i ulong to ulong +h = xor 14695981039346656037 t +o = get fo i +for j ulong get fl i +h = mul xor h ulong get lb add o j 1099511628211 +end +ret h +end + +fn keq k ulong t ulong i ulong to bool +if ne get kt k t +ret false +end +n = get fl i +if ne get kl k n +ret false +end +b = mul k KW +o = get fo i +for j ulong n +if ne get kb add b j get lb add o j +ret false +end +end +ret true +end + +note kfind: key id + 1 of (t, field i), or 0 with the free slot in st SSLOT. +fn kfind t ulong i ulong to ulong +m = sub KIX 1 +s = and khash t i m +for p ulong KIX +e = get ki s +if eq e 0 +put st SSLOT s +ret 0 +end +if keq sub e 1 t i +ret e +end +s = and add s 1 m +end +trap 9 +end + +note kget: key id + 1 of (t, field i), added when new; 0 when the table is full. +fn kget t ulong i ulong to ulong +e = kfind t i +if ne e 0 +ret e +end +k = get st SKEYS +if ge k KCAP +ret 0 +end +n = get fl i +b = mul k KW +o = get fo i +for j ulong n +put kb add b j get lb add o j +end +put kl k n +put kt k t +put ki get st SSLOT add k 1 +put st SKEYS add k 1 +ret add k 1 +end + +note cred: account k += v; esub: open escrow -= v. Overflow and underflow set st SOVF. +fn cred k ulong v ulong to void +put d0 k cadd get d0 k v +end + +fn esub v ulong to void +e = get st SESC +if lt e v +put st SOVF 1 +ret +end +put st SESC sub e v +end + +note Record checks at field base b (the KIND). live is a command, not replay. Result: 0 apply, +note 1 identical repeat (live only), else a refusal code. Replay refuses any nonzero result. +fn vpre b ulong live bool to int +if ne get st SRF 5 +ret 2 +end +if not and fname add b 1 fname add b 2 +ret 2 +end +put st SBAD 0 +a = fnum add b 3 +if or ne get st SBAD 0 eq a 0 +ret 2 +end +if not and cfeq 6 add b 2 authrec b 4 false false +ret 16 +end +p = kfind 2 add b 1 +if ne p 0 +k = sub p 1 +if and aeqhash 0 k and eq get d1 k a keq get d0 k 0 add b 2 +ret 1 +end +ret 13 +end +ac = kfind 0 add b 2 +bal = ulong 0 +if ne ac 0 +bal = get d0 sub ac 1 +end +put st SOVF 0 +x = cadd bal a +y = cadd get st SPRE a +if or ne get st SOVF 0 lt y x +ret 15 +end +note New prefund id plus requester only if the account is not present. +needed = ulong 1 +if eq ac 0 +needed = ulong 2 +end +if gt add get st SKEYS needed KCAP +ret 14 +end +ret 0 +end + +fn apre b ulong to int +p = kget 2 add b 1 +ac = kget 0 add b 2 +if or eq p 0 eq ac 0 +ret 14 +end +put st SBAD 0 +a = fnum add b 3 +k = sub p 1 +c = sub ac 1 +put d0 k c +put d1 k a +asave 0 k +cred c a +put st SPRE cadd get st SPRE a +ret 0 +end + +fn jsame k ulong b ulong a ulong to bool +if ne get d3 k a +ret false +end +if not keq get d0 k 0 add b 2 +ret false +end +if not keq get d1 k 0 add b 3 +ret false +end +if not keq get d2 k 0 add b 4 +ret false +end +ret true +end + +fn vres b ulong live bool to int +if ne get st SRF 8 +ret 2 +end +if not fhex add b 1 +ret 2 +end +if not and fname add b 2 and fname add b 3 fname add b 4 +ret 2 +end +put st SBAD 0 +a = fnum add b 5 +if or ne get st SBAD 0 eq a 0 +ret 2 +end +if not and cfeq 6 add b 2 and cfeq 7 add b 3 cfeq 8 add b 4 +ret 16 +end +if not and fhex add b 6 authrec b 7 false false +ret 16 +end +j = kfind 1 add b 1 +if ne j 0 +if and and live aeqhash 1 sub j 1 jsame sub j 1 b a +ret 1 +end +ret 9 +end +r = kfind 0 add b 2 +if eq r 0 +ret 7 +end +if lt get d0 sub r 1 a +ret 7 +end +note Reserve allocates its job and any missing distinct pinned role accounts. +needed = ulong 1 +p = kfind 0 add b 3 +v = kfind 0 add b 4 +if eq p 0 +needed = add needed 1 +end +if eq v 0 +needed = add needed 1 +end +if gt add get st SKEYS needed KCAP +ret 14 +end +ret 0 +end + +fn ares b ulong to int +j = kget 1 add b 1 +r = kget 0 add b 2 +p = kget 0 add b 3 +v = kget 0 add b 4 +if or or eq j 0 eq r 0 or eq p 0 eq v 0 +ret 14 +end +put st SBAD 0 +a = fnum add b 5 +k = sub j 1 +q = sub r 1 +put d0 k q +asave 1 k +put d1 k sub p 1 +put d2 k sub v 1 +put d3 k a +put d4 k 1 +put d0 q sub get d0 q a +put st SESC cadd get st SESC a +ret 0 +end + +note ssame: settled JOB k carries the receipt and amounts of the settle record at b. +fn ssame k ulong b ulong to bool +o = get fo add b 2 +r = mul k KW +for j ulong 64 +if ne get rc add r j get lb add o j +ret false +end +end +put st SBAD 0 +if ne get d5 k fnum add b 3 +ret false +end +if ne get d6 k fnum add b 4 +ret false +end +if ne get d7 k fnum add b 5 +ret false +end +ret true +end + +note sdup: a settle of an already settled JOB: an identical repeat is 1, anything else 11. +fn sdup k ulong b ulong live bool to int +if and and live aeqhash 2 k ssame k b +ret 1 +end +ret 11 +end + +note vrule: the oracle's settle rule on escrow e. +fn vrule e ulong pp ulong pv ulong bk ulong to int +if gt pp e +ret 12 +end +r = sub e pp +if gt pv r +ret 12 +end +r = sub r pv +if ne bk r +ret 12 +end +ret 0 +end + +fn vset b ulong live bool to int +if ne get st SRF 10 +ret 2 +end +if not and fhex add b 1 fhex add b 2 +ret 2 +end +put st SBAD 0 +pp = fnum add b 3 +pv = fnum add b 4 +bk = fnum add b 5 +if ne get st SBAD 0 +ret 2 +end +if not and fhex add b 6 fhex add b 7 +ret 2 +end +if not authrec b 8 true true +ret 16 +end +j = kfind 1 add b 1 +if eq j 0 +ret 8 +end +k = sub j 1 +sph = get d4 k +if eq sph 2 +ret sdup k b live +end +if eq sph 3 +ret 10 +end +if live +ret vrule get d3 k pp pv bk +end +ret 0 +end + +fn aset b ulong to int +j = kfind 1 add b 1 +k = sub j 1 +put st SBAD 0 +pp = fnum add b 3 +pv = fnum add b 4 +bk = fnum add b 5 +put d4 k 2 +asave 2 k +put d5 k pp +put d6 k pv +put d7 k bk +o = get fo add b 2 +r = mul k KW +for i ulong 64 +put rc add r i get lb add o i +end +cred get d0 k bk +cred get d1 k pp +cred get d2 k pv +esub get d3 k +ret 0 +end + +fn vref b ulong live bool to int +if ne get st SRF 3 +ret 2 +end +if not fhex add b 1 +ret 2 +end +if not authrec b 2 true false +ret 16 +end +j = kfind 1 add b 1 +if eq j 0 +ret 8 +end +rph = get d4 sub j 1 +if and live eq rph 3 +ret 1 +end +if ne rph 1 +ret 10 +end +ret 0 +end + +fn aref b ulong to int +j = kfind 1 add b 1 +k = sub j 1 +put d4 k 3 +cred get d0 k get d3 k +esub get d3 k +ret 0 +end + +note rapply: check and apply the record at field 2 of a replayed line; 0 or a refusal code. +fn rapply to int +b = ulong 2 +if eq get st SSEQ 0 +o = get fo b +n = sub sub get fo sub get st SNF 1 1 o +if ne n get cfgn 0 +ret 5 +end +for i ulong n +if ne get cfg i get lb add o i +ret 5 +end +end +ret 0 +end +if fis b 15 +if ne vpre b false 0 +ret 5 +end +ret apre b +end +if fis b 16 +if ne vres b false 0 +ret 5 +end +ret ares b +end +if fis b 17 +if ne vset b false 0 +ret 5 +end +ret aset b +end +if fis b 18 +if ne vref b false 0 +ret 5 +end +ret aref b +end +if fis b 23 +put st SBAD 0 +x = fnum 3 +if and and eq get st SRF 3 eq get st SBAD 0 fhex 4 +ret 0 +end +ret 5 +end +ret 5 +end + +fn hsame h ulong to bool +o = get fo h +for j ulong 64 +if ne get hd j get lb add o j +ret false +end +end +ret true +end + +fn psame to bool +if not fhex 1 +ret false +end +o = get fo 1 +for j ulong 64 +if ne get ph j get lb add o j +ret false +end +end +ret true +end + +note chain: the line's HASH is the sha256 of its bytes before " HASH" (else 1: the line itself is +note damaged) and its PREV is the previous line's HASH (else 2: the line does not link). 0 when both hold. +fn chain h ulong to int +hreset +m = sub get fo h 1 +for i ulong m +x = hpush get lb i +end +y = hfinal +if not hsame h +ret 1 +end +if not psame +ret 2 +end +ret 0 +end + +note rline: format and chain checks of lb[0 .. n). 0 when the line belongs to the chain, 1 when the +note line itself is damaged (could be a torn write), 2 when an intact line does not link. +fn rline n ulong to int +if not split n +ret 1 +end +nf = get st SNF +if lt nf 4 +ret 1 +end +h = sub nf 1 +if not fhex h +ret 1 +end +c = chain h +if ne c 0 +ret c +end +put st SBAD 0 +sq = fnum 0 +if or ne get st SBAD 0 ne sq add get st SSEQ 1 +ret 2 +end +put st SRF sub nf 3 +ret 0 +end + +note rend: a complete line ends at file offset e. 0, or the code that refuses the journal. +fn rend e ulong to int +c = int 1 +if eq get st SLONG 0 +c = rline get st SLN +end +if ne c 0 +if and eq c 1 eq e get st SFSZ +put st STORN 1 +ret 0 +end +ret 5 +end +put st SOVF 0 +r = rapply +if ne get st SOVF 0 +ret 15 +end +if ne r 0 +ret r +end +o = get fo sub get st SNF 1 +for j ulong 64 +put ph j get lb add o j +end +put st SSEQ add get st SSEQ 1 +put st SGOOD e +put st SRECS add get st SRECS 1 +put st SLN 0 +ret 0 +end + +note replay: read the journal; st SGOOD ends the last good line. 0, or a refusal code. +fn replay to int +fd = int get st SFD +z = long 0 +fsz = fseek fd 0 2 +if lt fsz 0 +ret 3 +end +put st SFSZ ulong fsz +pos = ulong 0 +while lt pos ulong fsz +r = pread fd rb 0 len rb long pos +if ne r -4 +if le r 0 +ret 3 +end +for i ulong ulong r +c = get rb i +if eq c 10 +e = rend add add pos i 1 +if ne e 0 +ret e +end +else +n = get st SLN +if lt n 1023 +put lb n c +put st SLN add n 1 +else +put st SLONG 1 +end +end +end +pos = add pos ulong r +end +end +ret 0 +end + +note tornh: sha256 of the torn bytes [st SGOOD, st SFSZ) into th. +fn tornh to bool +fd = int get st SFD +pos = get st SGOOD +end1 = get st SFSZ +hreset +while lt pos end1 +m = sub end1 pos +if gt m len rb +m = len rb +end +r = pread fd rb 0 m long pos +if ne r -4 +if le r 0 +ret false +end +for i ulong ulong r +x = hpush get rb i +end +pos = add pos ulong r +end +end +y = hfinal +for j ulong 64 +put th j get hd j +end +ret true +end + +note wput: append to the write buffer wb (st SWB). +fn wput c uchar to void +n = get st SWB +put wb n c +put st SWB add n 1 +end + +note wrec: append the record whose body is lb[0 .. st SLN) and fsync it. 0, or 3. +fn wrec to int +put st SWB 0 +v = add get st SSEQ 1 +p = ulong 1 +while le p div v 10 +p = mul p 10 +end +while gt p 0 +wput uchar add 48 div v p +v = rem v p +p = div p 10 +end +wput 32 +for i ulong 64 +wput get ph i +end +wput 32 +for i ulong get st SLN +wput get lb i +end +hreset +for i ulong get st SWB +x = hpush get wb i +end +y = hfinal +wput 32 +for i ulong 64 +wput get hd i +end +wput 10 +fd = int get st SFD +off = get st SGOOD +m = get st SWB +o = ulong 0 +while lt o m +w = pwrite fd wb o sub m o long add off o +if ne w -4 +if le w 0 +ret 3 +end +o = add o ulong w +end +end +sy = fsync fd +if ne sy 0 +ret 3 +end +for i ulong 64 +put ph i get hd i +end +put st SSEQ add get st SSEQ 1 +put st SGOOD add off m +put st SRECS add get st SRECS 1 +ret 0 +end + +note conserve: sum of balances + open escrow = sum of prefunds; open escrow = open JOB amounts; +note every settled JOB paid out exactly its amount. +fn conserve to bool +sum = ulong 0 +esc = ulong 0 +put st SOVF 0 +for k ulong get st SKEYS +t = get kt k +if eq t 0 +sum = cadd sum get d0 k +end +if eq t 1 +cph = get d4 k +if eq cph 1 +esc = cadd esc get d3 k +end +if eq cph 2 +paid = cadd cadd get d5 k get d6 k get d7 k +if ne paid get d3 k +ret false +end +end +end +end +if ne esc get st SESC +ret false +end +if ne cadd sum esc get st SPRE +ret false +end +ret eq get st SOVF 0 +end + +note body: lb = arguments 3 .. c - 1 joined by spaces, split into fields; st SRF is the count. +fn body c ulong to void +put st SLN 0 +for i ulong c +if ge i 3 +if gt i 3 +lbput 32 +end +lbarg i +end +end +if not split get st SLN +die 2 +end +put st SRF get st SNF +end + +note reply: word k, then the command's fields after the KIND, on stdout. +fn reply k ulong to void +put st SOB 0 +ofr k +n = get st SNF +if fis 0 15 +n = sub n 1 +end +if fis 0 16 +n = sub n 2 +end +if fis 0 17 +n = sub n 4 +end +if fis 0 18 +n = sub n 1 +end +for i ulong n +if gt i 0 +oput 32 +ofld i +end +end +oput 10 +oflush 1 +end + +note wcmd: finish a write command whose check gave r: print the repeat word d, refuse, or +note write the record, fsync it, and print the word w. +fn wcmd r int w ulong d ulong to void +if eq r 1 +reply d +ret +end +if ne r 0 +if eq r 16 +authdie +end +die r +end +if ne wrec 0 +die 3 +end +reply w +end + +fn cbal to void +if or ne get st SRF 2 not fname 1 +die 2 +end +a = kfind 0 1 +v = ulong 0 +if ne a 0 +v = get d0 sub a 1 +end +put st SOB 0 +ofr 49 +ofld 1 +oput 32 +odec v +oput 10 +oflush 1 +end + +fn cshow to void +if or ne get st SRF 2 not fhex 1 +die 2 +end +j = kfind 1 1 +if eq j 0 +die 8 +end +k = sub j 1 +p = get d4 k +put st SOB 0 +ofr 33 +ofld 1 +oput 32 +if eq p 1 +ofr 27 +end +if eq p 2 +ofr 29 +end +if eq p 3 +ofr 31 +end +oput 32 +okey get d0 k +oput 32 +okey get d1 k +oput 32 +okey get d2 k +oput 32 +odec get d3 k +if eq p 2 +oput 32 +orc k +oput 32 +odec get d5 k +oput 32 +odec get d6 k +oput 32 +odec get d7 k +end +oput 10 +oflush 1 +end + +fn caudit to void +if ne get st SRF 1 +die 2 +end +na = ulong 0 +nj = ulong 0 +no = ulong 0 +ns = ulong 0 +nr = ulong 0 +sum = ulong 0 +for k ulong get st SKEYS +t = get kt k +if eq t 0 +na = add na 1 +sum = add sum get d0 k +end +if eq t 1 +nj = add nj 1 +p = get d4 k +if eq p 1 +no = add no 1 +end +if eq p 2 +ns = add ns 1 +end +if eq p 3 +nr = add nr 1 +end +end +end +put st SOB 0 +ofr 34 +odec get st SRECS +ofr 35 +for i ulong 64 +oput get ph i +end +ofr 36 +odec na +ofr 37 +odec nj +ofr 38 +odec no +ofr 39 +odec ns +ofr 40 +odec nr +ofr 41 +odec get st SPRE +ofr 42 +odec sum +ofr 43 +odec get st SESC +oput 10 +oflush 1 +end + +note aeq: argument i equals word k. +fn aeq i ulong k ulong to bool +s = fst k +n = get gl i +if ne n get st SFLEN +ret false +end +o = get gs i +for j ulong n +if ne get ga add o j get tw add s j +ret false +end +end +ret true +end + +note opendb: DIR (argument 2) made if absent (0700), DIR/journal opened O_RDWR | O_CREAT | +note O_CLOEXEC = 524354, created 0600. +fn opendb to void +n = get gl 2 +if or eq n 0 gt n 4000 +die 2 +end +o = get gs 2 +for j ulong n +put pb j get ga add o j +end +md = makedir pb 0 n 448 +if and lt md 0 ne md -17 +die 3 +end +s = fst 47 +for j ulong get st SFLEN +put pb add n j get tw add s j +end +fd = fopen pb 0 add n get st SFLEN 524354 384 +if lt fd 0 +die 3 +end +put st SFD ulong fd +end + +note dsync: fsync DIR so a newly created journal's directory entry is durable. +note Flags: O_RDONLY | O_DIRECTORY (arm64 0x4000) | O_CLOEXEC = 540672. +fn dsync to void +dfd = fopen pb 0 get gl 2 540672 0 +if lt dfd 0 +die 3 +end +if ne fsync int dfd 0 +die 3 +end +x = fclose int dfd +end + +note recover: truncate a torn tail, then write genesis (empty journal) and the recover record. +fn recover to void +tb = sub get st SFSZ get st SGOOD +if gt tb 0 +if not tornh +die 3 +end +fd = int get st SFD +if ne ftrunc fd long get st SGOOD 0 +die 3 +end +if ne fsync fd 0 +die 3 +end +end +if eq get st SSEQ 0 +put st SLN 0 +for i ulong get cfgn 0 +lbput get cfg i +end +if ne wrec 0 +die 3 +end +dsync +end +if gt tb 0 +put st SLN 0 +lbfr 23 +lbput 32 +lbdec tb +lbput 32 +for i ulong 64 +lbput get th i +end +if ne wrec 0 +die 3 +end +put st SOB 0 +ofr 44 +odec tb +ofr 45 +for i ulong 64 +oput get th i +end +oput 10 +oflush 2 +end +end + +fn main to int +c = argcnt +if or lt c 4 gt c 13 +put st SOB 0 +ofr 48 +oput 10 +oflush 2 +ret 2 +end +o = ulong 0 +for i ulong ulong c +r = argread i ga o sub len ga o +if lt r 0 +die 2 +end +put gs i o +put gl i ulong r +o = add o ulong r +end +if not aeq 1 46 +die 2 +end +acfg +for i ulong 64 +put ph i 48 +end +opendb +fd = int get st SFD +lk = flock fd 2 +if ne lk 0 +die 4 +end +rp = replay +if ne rp 0 +die rp +end +recover +if not conserve +die 6 +end +n = ulong c +body n +if fis 0 15 +wcmd vpre 0 true 25 26 +ret 0 +end +if fis 0 16 +wcmd vres 0 true 27 28 +ret 0 +end +if fis 0 17 +wcmd vset 0 true 29 30 +ret 0 +end +if fis 0 18 +wcmd vref 0 true 31 32 +ret 0 +end +if fis 0 19 +cbal +ret 0 +end +if fis 0 20 +cshow +ret 0 +end +if fis 0 21 +caudit +ret 0 +end +die 2 +ret 2 +end diff --git a/evidence/aienet0-tur-ledger-20261027/audit-v2-before.out b/evidence/aienet0-tur-ledger-20261027/audit-v2-before.out new file mode 100644 index 00000000..9f5bb324 --- /dev/null +++ b/evidence/aienet0-tur-ledger-20261027/audit-v2-before.out @@ -0,0 +1,32 @@ +omc d6290c7663c2b4bafb59eb3fdf812476e977f4c144def71095c6248ef9b96b84 +src f47d8c6374f5e8a49068cc5372e97582e3eb81e87c5e53a661ea62ebb4279713 om/tur-ledger/tur-ledger.om +sha 4f88dad60464eacd1655ba980f66b74000c6966ec0becbb80346ac1898e87a76 om/vendor/sha256.om +ec 909f37c797e187bd0663bde9f57c75d6ce41eb2c9726a6b50d6fc714e424c060 omega-mv@6999fa9e6dae4847c155ef4eacaece74f491d3ca +gate 48f0cbd7b067cb5bfd5cf1a8292a36294169b1aeb6c5f554f3936dcd0046670d +OpenSSL 3.0.13 30 Jan 2024 (Library: OpenSSL 3.0.13 30 Jan 2024) +audit-source f47d8c6374f5e8a49068cc5372e97582e3eb81e87c5e53a661ea62ebb4279713 +FAIL io.failed-sync-rollback-1: exit 3 out '', journal restored no +FAIL io.failed-sync-rollback-2: exit 0 out 'dup unsynced req 5', journal restored no +PASS io.no-torn-tail-after-rollback +FAIL io.retry-writes-and-syncs: exit 0 out 'dup unsynced req 5' +FAIL io.duplicate-prefund-needs-sync: exit 0 out 'dup base req 100' +FAIL io.duplicate-prefund-retry-synced: exit 0, missing fsync or changed journal +FAIL io.duplicate-reserve-needs-sync: exit 0 out 'already-reserved 7777777777777777777777777777777777777777777777777777777777777777 req prov ver 40' +FAIL io.duplicate-reserve-retry-synced: exit 0, missing fsync or changed journal +FAIL io.duplicate-settle-needs-sync: exit 0 out 'already-settled 7777777777777777777777777777777777777777777777777777777777777777 aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa 27 3 10' +FAIL io.duplicate-settle-retry-synced: exit 0, missing fsync or changed journal +FAIL io.duplicate-refund-needs-sync: exit 0 out 'already-refunded 8888888888888888888888888888888888888888888888888888888888888888' +FAIL io.duplicate-refund-retry-synced: exit 0, missing fsync or changed journal +PASS corrupt.acknowledged-settle +FAIL corrupt.acknowledged-tail-audit: exit 0 expected 5, before 'd507b1cd5da31bc8006bf530e86d06e2ab9e4e82acfe9a4fb9725bb812bfc7cd /tmp/tmp.0WtTMZw3J2/audit-tail/journal' after '592bc72be329a159b5ac7e8190d3355220ce1f945c7ed480c6d8d910061c2a67 /tmp/tmp.0WtTMZw3J2/audit-tail/journal' +FAIL corrupt.acknowledged-tail-refund: exit 0 expected 5, before 'd507b1cd5da31bc8006bf530e86d06e2ab9e4e82acfe9a4fb9725bb812bfc7cd /tmp/tmp.0WtTMZw3J2/audit-tail/journal' after '7c5274389713289775269723cd9f105ae8057f1076004b75b67fb2749eda5709 /tmp/tmp.0WtTMZw3J2/audit-tail/journal' +FAIL corrupt.acknowledged-tail-show: exit 0 expected 5, before 'd507b1cd5da31bc8006bf530e86d06e2ab9e4e82acfe9a4fb9725bb812bfc7cd /tmp/tmp.0WtTMZw3J2/audit-tail/journal' after '592bc72be329a159b5ac7e8190d3355220ce1f945c7ed480c6d8d910061c2a67 /tmp/tmp.0WtTMZw3J2/audit-tail/journal' +FAIL corrupt.signed-tail-bad-hash: exit 0 expected 5, before '9ad3c5ff6494e2b83d61a32f76f52fd7a823a6afd7788e1e399b226e23d91d30 /tmp/tmp.0WtTMZw3J2/audit-tail/journal' after 'cb310fd19936451bc336b8d7d0c142995622bdb7b43b50984106160565e65252 /tmp/tmp.0WtTMZw3J2/audit-tail/journal' +PASS corrupt.original-settlement-preserved +FAIL usage.fused-name-arguments: exit 0 expected 2, before '92f189182ce77d34885fedc09949e23cd659121e87b76583ba722170c3a8ea76 /tmp/tmp.0WtTMZw3J2/audit-argv/journal' after 'ddee479a9684f3d1a5067b6467b311cb04840f82d838e073544fe6109c386e9c /tmp/tmp.0WtTMZw3J2/audit-argv/journal' +FAIL usage.fused-command-argument: exit 0 expected 2, before 'ddee479a9684f3d1a5067b6467b311cb04840f82d838e073544fe6109c386e9c /tmp/tmp.0WtTMZw3J2/audit-argv/journal' after 'a55f9fe57c75dccf78bc665368068fa80d7f133ac8a9bb7f5294e9a77b2a38ff /tmp/tmp.0WtTMZw3J2/audit-argv/journal' +FAIL usage.fused-role-arguments: exit 0 expected 2, before 'a55f9fe57c75dccf78bc665368068fa80d7f133ac8a9bb7f5294e9a77b2a38ff /tmp/tmp.0WtTMZw3J2/audit-argv/journal' after 'e569546181fd0c7e62ac595707c76f2c353d3b18be0389a1dac6b139f029e400 /tmp/tmp.0WtTMZw3J2/audit-argv/journal' +FAIL phase.reserve: exit 0 out 'already-reserved 7777777777777777777777777777777777777777777777777777777777777777 req prov ver 40' err '', wanted exit 0 out 'reserved 7777777777777777777777777777777777777777777777777777777777777777 req prov ver 40' +PASS phase.reserve-open-retry +FAIL phase.reserve-after-settle: exit 0 expected 10, before '6b9d0bc2e20ddf5ce6ba0c7de104ec2f9da888492d3b134c5fed9868beac895d /tmp/tmp.0WtTMZw3J2/audit-argv/journal' after '6b9d0bc2e20ddf5ce6ba0c7de104ec2f9da888492d3b134c5fed9868beac895d /tmp/tmp.0WtTMZw3J2/audit-argv/journal' +FAIL phase.reserve-after-refund: exit 0 expected 10, before '1f4eaf7edfaeb1c2c731c7c24da04a849c0248f7578db0f86eced3fd2f54e89f /tmp/tmp.0WtTMZw3J2/audit-argv/journal' after '1f4eaf7edfaeb1c2c731c7c24da04a849c0248f7578db0f86eced3fd2f54e89f /tmp/tmp.0WtTMZw3J2/audit-argv/journal' diff --git a/evidence/aienet0-tur-ledger-20261027/audit-v2-check.out b/evidence/aienet0-tur-ledger-20261027/audit-v2-check.out new file mode 100644 index 00000000..cd43735f --- /dev/null +++ b/evidence/aienet0-tur-ledger-20261027/audit-v2-check.out @@ -0,0 +1,154 @@ +omc d6290c7663c2b4bafb59eb3fdf812476e977f4c144def71095c6248ef9b96b84 +src 8e16f25dd7be21d9dea94252b4ad0ab3b30ac107e4445ed81224d29982e1aadd om/tur-ledger/tur-ledger.om +sha 4f88dad60464eacd1655ba980f66b74000c6966ec0becbb80346ac1898e87a76 om/vendor/sha256.om +ec 909f37c797e187bd0663bde9f57c75d6ce41eb2c9726a6b50d6fc714e424c060 omega-mv@6999fa9e6dae4847c155ef4eacaece74f491d3ca +gate 8f96325dc3db714edf6837d4c78fb3e8ccc27dcc8e7a56798a5079fa152b2c21 +OpenSSL 3.0.13 30 Jan 2024 (Library: OpenSSL 3.0.13 30 Jan 2024) +bin 0338edb18a1fba9ecd7fa8ae294045184bfeb2e72530340017ce719acc682768 +PASS oracle.prefund +PASS oracle.overdraft-101 +PASS oracle.reserve-7-40 +PASS oracle.req-after-reserve +PASS oracle.second-reservation +PASS oracle.settle-unknown-job +PASS oracle.change-mismatch +PASS oracle.settle +PASS oracle.zero-replay +PASS oracle.requester +PASS oracle.provider +PASS oracle.verifier +PASS oracle.observer +PASS oracle.audit +PASS oracle.chain-sha256sum +PASS prefund.first +PASS prefund.dup +PASS prefund.conflict-amount +PASS prefund.conflict-account +PASS prefund.balance +PASS usage.bad-job +PASS usage.leading-zero +PASS usage.zero-amount +PASS usage.arity +PASS usage.command +PASS usage.u64-overflow +PASS once.settle +PASS once.same-receipt +PASS once.other-receipt +PASS once.same-receipt-other-split +PASS once.refund-after-settle +PASS once.journal-unchanged +PASS concurrent.settle-distinct (settled 1, already 0, refused 19) +PASS concurrent.settle-same (settled 1, already 19, refused 0) +PASS concurrent.double-debit (one reserve, nineteen insufficient-funds) +PASS lock.blocks-while-held (timeout exit 124, then exit 0) +PASS fsync.before-ack (pwrite64 line 1 < fsync(3) line 2 < write(1) line 4) +PASS torn.unterminated (recovered torn-tail 138 bytes sha256 3e44b72d48977086fbd8675d072b748fe547ca43e7e124f9769f7c54d76db3ff) +PASS corrupt.terminated-bad-hash (exit 5, unchanged journal) +PASS torn.cut-last-record (recovered torn-tail 194 bytes sha256 54a19b41e44c3889a37b3f266238ae691ec3dec938d458eb55b518fe0a3e83c7) +PASS corrupt.amount-edited +PASS corrupt.journal-untouched +PASS corrupt.line-deleted +PASS corrupt.lines-swapped +PASS corrupt.genesis-edited +PASS conserve.forged-chain-valid +PASS conserve.payout-over-escrow +PASS conserve.refused-for-every-command +PASS auth.unsigned-prefund (exit 2, unchanged journal) +PASS auth.unsigned-reserve (exit 2, unchanged journal) +PASS auth.unsigned-settle (exit 2, unchanged journal) +PASS auth.unsigned-refund (exit 2, unchanged journal) +PASS auth.wrong-issuer-key (exit 16, unchanged journal) +PASS auth.changed-amount (exit 16, unchanged journal) +PASS auth.changed-quote (exit 16, unchanged journal) +PASS auth.account-spoof (exit 16, unchanged journal) +PASS auth.wrong-verifier-key (exit 16, unchanged journal) +PASS auth.unauthorized-settle (exit 16, unchanged journal) +PASS auth.changed-job (exit 16, unchanged journal) +PASS auth.forged-receipt-hash (exit 16, unchanged journal) +PASS auth.mutated-attestation-digest (exit 16, unchanged journal) +PASS auth.mutated-signed-job-digest (exit 16, unchanged journal) +PASS auth.issuer-is-not-verifier (exit 16, unchanged journal) +PASS auth.kill-after-fsync-before-ack +PASS auth.lost-response-retry +PASS auth.honest-provider +PASS auth.changed-evidence-conflicts-even-when-signed (exit 11, unchanged journal) +PASS auth.unsigned-replay-last (exit 5, unchanged journal) +PASS auth.wrong-key-replay-last (exit 5, unchanged journal) +PASS auth.old-journal-refused (exit 5, unchanged journal) +PASS auth.changed-policy-pins (exit 5, unchanged journal) +PASS io.failed-sync-rollback-1 (exit 3, original journal, size 1049) +PASS io.failed-sync-rollback-2 (exit 3, original journal, size 1049) +PASS io.no-torn-tail-after-rollback +PASS io.retry-writes-and-syncs +PASS io.duplicate-prefund-needs-sync +PASS io.duplicate-prefund-retry-synced +PASS io.duplicate-reserve-needs-sync +PASS io.duplicate-reserve-retry-synced +PASS io.duplicate-settle-needs-sync +PASS io.duplicate-settle-retry-synced +PASS io.duplicate-refund-needs-sync +PASS io.duplicate-refund-retry-synced +PASS corrupt.acknowledged-settle +PASS corrupt.acknowledged-tail-audit (exit 5, unchanged journal) +PASS corrupt.acknowledged-tail-refund (exit 5, unchanged journal) +PASS corrupt.acknowledged-tail-show (exit 5, unchanged journal) +PASS corrupt.signed-tail-bad-hash (exit 5, unchanged journal) +PASS corrupt.original-settlement-preserved +PASS usage.fused-name-arguments (exit 2, unchanged journal) +PASS usage.fused-command-argument (exit 2, unchanged journal) +PASS usage.fused-role-arguments (exit 2, unchanged journal) +PASS phase.reserve +PASS phase.reserve-open-retry +PASS phase.reserve-after-settle (exit 10, unchanged journal) +PASS phase.reserve-after-refund (exit 10, unchanged journal) +crash: n 200 killed 200 (durable-before-kill 0, not-yet-durable 200) completed-before-kill 0 journal-identical-to-control no +crash: audit ok records 202 head 8c781d7f07569f3b82b297f9d3a553a6b839615b6d82bed479d56ad9d444a462 accounts 3 jobs 100 open 0 settled 100 refunded 0 prefunded 1000000 balances 1000000 escrow 0 +PASS crash.kill9-200 (audit after every kill, no double settle, balances equal control) +capacity-source 8e16f25dd7be21d9dea94252b4ad0ab3b30ac107e4445ed81224d29982e1aadd KCAP=10 +capacity-bin 71f18b249c8503b2acec91711eb1b111eb7c9d42f4a56e1dab07e5a6ee0359f5 +PASS capacity.prefund +PASS capacity.reserve-settle +PASS capacity.reserve-refund +PASS capacity.fill-p2 +PASS capacity.fill-p3 +PASS capacity.fill-p4 +PASS capacity.fill-p5 +PASS capacity.new-prefund-refused (exit 14, unchanged journal) +PASS capacity.new-reserve-refused (exit 14, unchanged journal) +PASS capacity.settle +PASS capacity.refund +PASS capacity.settle-repeat (exit 0, unchanged journal) +PASS capacity.refund-repeat (exit 0, unchanged journal) +PASS capacity.provider +PASS capacity.verifier +PASS capacity.audit-closed +PASS capacity.partial-prefund +PASS capacity.partial-fill-p2 +PASS capacity.partial-fill-p3 +PASS capacity.partial-fill-p4 +PASS capacity.partial-fill-p5 +PASS capacity.partial-fill-p6 +PASS capacity.partial-fill-p7 +PASS capacity.partial-fill-p8 +PASS capacity.partial-reserve-refused (exit 14, unchanged journal) +PASS capacity.last-slot-prefund +PASS capacity.partial-full-prefund-refused (exit 14, unchanged journal) +SUITE PASS +PASS mutant no-fsync killed (4 failing: fsync.before-ack io.failed-sync-rollback-1 io.failed-sync-rollback-2 io.retry-writes-and-syncs ) +PASS mutant no-lock killed (1 failing: lock.blocks-while-held ) +PASS mutant no-exactly-once killed (19 failing: oracle.zero-replay once.same-receipt once.other-receipt once.same-receipt-other-split once.refund-after-settle once.journal-unchanged concurrent.settle-distinct concurrent.settle-same auth.lost-response-retry auth.honest-provider auth.changed-evidence-conflicts-even-when-signed io.duplicate-settle-retry-synced io.duplicate-refund-needs-sync io.duplicate-refund-retry-synced capacity.settle-repeat capacity.refund-repeat capacity.provider capacity.verifier capacity.audit-closed ) +PASS mutant no-hash-chain killed (1 failing: corrupt.signed-tail-bad-hash ) +PASS mutant no-conservation killed (2 failing: conserve.payout-over-escrow conserve.refused-for-every-command ) +PASS mutant no-escrow-rule killed (8 failing: oracle.change-mismatch oracle.settle oracle.zero-replay oracle.requester oracle.provider oracle.verifier oracle.observer oracle.audit ) +PASS mutant no-torn-recovery killed (2 failing: torn.unterminated torn.cut-last-record ) +PASS mutant no-issuer-signature killed (5 failing: auth.wrong-issuer-key auth.changed-amount auth.changed-quote auth.unauthorized-settle auth.wrong-key-replay-last ) +PASS mutant no-verifier-signature killed (2 failing: auth.wrong-verifier-key auth.issuer-is-not-verifier ) +PASS mutant no-owner-pins killed (1 failing: auth.account-spoof ) +PASS mutant capacity-lockup killed (13 failing: capacity.fill-p3 capacity.fill-p4 capacity.fill-p5 capacity.settle capacity.refund capacity.settle-repeat capacity.refund-repeat capacity.provider capacity.verifier capacity.audit-closed capacity.partial-fill-p7 capacity.partial-fill-p8 capacity.last-slot-prefund ) +PASS mutant no-slot-preflight killed (10 failing: capacity.new-prefund-refused capacity.settle capacity.refund capacity.settle-repeat capacity.refund-repeat capacity.provider capacity.verifier capacity.audit-closed capacity.partial-reserve-refused capacity.last-slot-prefund ) +PASS mutant no-sync-rollback killed (3 failing: io.failed-sync-rollback-1 io.failed-sync-rollback-2 io.retry-writes-and-syncs ) +PASS mutant no-duplicate-sync killed (8 failing: io.duplicate-prefund-needs-sync io.duplicate-prefund-retry-synced io.duplicate-reserve-needs-sync io.duplicate-reserve-retry-synced io.duplicate-settle-needs-sync io.duplicate-settle-retry-synced io.duplicate-refund-needs-sync io.duplicate-refund-retry-synced ) +PASS mutant terminated-tail-recovery killed (6 failing: corrupt.terminated-bad-hash corrupt.line-deleted corrupt.acknowledged-tail-audit corrupt.acknowledged-tail-refund corrupt.acknowledged-tail-show corrupt.signed-tail-bad-hash ) +PASS mutant argv-whitespace killed (3 failing: usage.fused-name-arguments usage.fused-command-argument usage.fused-role-arguments ) +PASS mutant reserve-closed-phase killed (2 failing: phase.reserve-after-settle phase.reserve-after-refund ) +TUR_LEDGER gate: PASS diff --git a/evidence/aienet0-tur-ledger-20261027/audit-v2-full-capacity.out b/evidence/aienet0-tur-ledger-20261027/audit-v2-full-capacity.out new file mode 100644 index 00000000..68cf9fd9 --- /dev/null +++ b/evidence/aienet0-tur-ledger-20261027/audit-v2-full-capacity.out @@ -0,0 +1 @@ +audit ok records 65536 head 26ebc6a04f4f8ace9a78669e4fdb013508dde61deddb99b5df31a7731aee68be accounts 3 jobs 2 open 0 settled 1 refunded 1 prefunded 65630 balances 65630 escrow 0 diff --git a/evidence/aienet0-tur-ledger-20261027/audit-v2-full-capacity.results.tsv b/evidence/aienet0-tur-ledger-20261027/audit-v2-full-capacity.results.tsv new file mode 100644 index 00000000..0c50be4b --- /dev/null +++ b/evidence/aienet0-tur-ledger-20261027/audit-v2-full-capacity.results.tsv @@ -0,0 +1,5 @@ +operation exit stdout stderr journal_unchanged +prefund 14 refused 14 capacity True +reserve 14 refused 14 capacity True +settle 0 settled 7777777777777777777777777777777777777777777777777777777777777777 aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa 27 3 10 False +refund 0 refunded 8888888888888888888888888888888888888888888888888888888888888888 False diff --git a/evidence/aienet0-tur-ledger-20261027/audit-v2-notes.txt b/evidence/aienet0-tur-ledger-20261027/audit-v2-notes.txt new file mode 100644 index 00000000..d132f11d --- /dev/null +++ b/evidence/aienet0-tur-ledger-20261027/audit-v2-notes.txt @@ -0,0 +1,108 @@ +HOST_TESTED: Core #794 independent-audit fixes (2026-10-28). +No Core RPC, GPU access, physical power loss, deployment or economic qualification is claimed. +Original v1 receipts, authentication receipts and the earlier capacity receipts are unchanged. + +Pins +---- +Compiler source: omega-mv 6999fa9e6dae4847c155ef4eacaece74f491d3ca. +omc SHA256: d6290c7663c2b4bafb59eb3fdf812476e977f4c144def71095c6248ef9b96b84. +Final native source: 8e16f25dd7be21d9dea94252b4ad0ab3b30ac107e4445ed81224d29982e1aadd. +Final native binary: 0338edb18a1fba9ecd7fa8ae294045184bfeb2e72530340017ce719acc682768. +Final gate: 8f96325dc3db714edf6837d4c78fb3e8ccc27dcc8e7a56798a5079fa152b2c21. +SHA and EC unit pins are printed in audit-v2-check.out. +Before-audit source: f47d8c6374f5e8a49068cc5372e97582e3eb81e87c5e53a661ea62ebb4279713. +The byte-identical frozen source is audit-v2-before.om.at-run. This before specimen already +has the authorization and capacity corrections, isolating the added audit regressions. +The source/gate called final in capacity-v2-notes.txt are final for that earlier capacity run, +not the later audit run. Its evidence remains historical; the pins above are the later ones. + +Regression commands and observations +----------------------------------- +Working directory: the Core checkout. OMC below is /tmp/ledger-auth-omega/seed/out/omc. + +OMC="$OMC" TUR_LEDGER_AUDIT_SOURCE=/tmp/ledger-auth-audit-before.om bash om/tur-ledger/check.sh + exit 1; audit-v2-before-final.out. The frozen temp source is the archived before specimen above. +OMC="$OMC" TUR_LEDGER_AUDIT_SOURCE=om/tur-ledger/tur-ledger.om bash om/tur-ledger/check.sh + exit 0; audit-v2-after.out, all audit regression assertions PASS. +OMC="$OMC" CRASH_N=200 MUTANT_CRASH_N=0 TUR_LEDGER_OUT=/tmp/ledger-auth-audit-bin bash om/tur-ledger/check.sh + exit 0; audit-v2-check.out: SUITE PASS, all 17 mutants killed, TUR_LEDGER gate: PASS. + +These are the regression entry points; the archived sources and printed hashes make the +before/after reproducible without retaining any ephemeral private signing key. OpenSSL +3.0.13 is the independent signing oracle; verification and ledger transitions are native Omega. +The targeted runs use fresh randomized test signatures, so byte sizes can differ across runs. + +A1: failed fsync followed by an unsynchronized duplicate acknowledgement +--------------------------------------------------------------------- +Before: first injected fsync EIO returned 3 but left the prefund record in the journal; +the second injected invocation returned 0/dup. All four mutation duplicates returned 0 +without any journal fsync. The same audit assertions fail against the archived before source. +After: each of two injected fsync failures returns 3, emits no acknowledgement, and restores +exact original bytes and size; audit finds no torn tail. The clean retry actually writes, +fsyncs and acknowledges prefunded. For prefund/reserve/settle/refund duplicates, injected +fsync EIO returns 3 without output or journal mutation; clean retry synchronizes the actual +journal fd before stdout. The test resolves that fd from strace openat output, so a directory +fsync cannot accidentally satisfy this assertion. Directory durability is also required. +The append's rollback is best-effort: if rollback itself fails, no success is acknowledged; +a later valid retry must still cross a fresh journal and directory durability barrier. +Mutants no-sync-rollback and no-duplicate-sync are both killed. Existing no-fsync is killed too. + +A2: capacity can trap existing escrow +------------------------------------ +Before and the first fixed run are preserved in capacity-v2-* and their SHA256 manifest. +The production fixture has 65,536 occupied slots and valid signatures. Before, both settle +and refund returned 14. Fixed, new allocating operations refuse cleanly while existing +settle/refund succeed. The final audit source also passes the ten-slot CLI boundary tests; +capacity-lockup and no-slot-preflight mutants die. audit-v2-full-capacity.results.tsv and +.out separately record a replay of the same production fixture with the final binary above. +See capacity-v2-notes.txt for the public gzip fixture and exact four signed CLI vectors. + +A3: issuer/verifier authorization +-------------------------------- +The original unsigned prefund reproducer and authentication-v2 controls are preserved in +auth-v2-*. The final gate still refuses unsigned calls (2), wrong keys or changed canonical +fields (16), invalid/unsigned complete replay records (5), old journals (5), and config/policy +changes (5). Honest issuer+verifier settlement pays exactly once. Issuer-only settlement, +issuer substitution for the verifier, altered job/amount/receipt/quote/attestation/job-envelope +hashes are refused. Native no-issuer-signature, no-verifier-signature and no-owner-pins mutants +die. This does not claim the ledger parses artifacts: protocols #67 is the bounded signer +adapter that checks actual bytes/signatures before authorizing them. + +A10: newline-terminated corrupt last record must not be rolled back +---------------------------------------------------------------- +Before: after an acknowledged settlement, changing its amount in the complete final line +made audit, refund and show succeed instead of refusing; the old tail-recovery rule discarded +that acknowledged line. After: all three return 5 and preserve identical corrupted bytes. +A separate control changes only its final chain hash, keeping the signed body valid: it too +returns 5 unchanged. Restoring the trusted good fixture shows the original settled 27/3/10. +Only unterminated tails recover; the existing cut/unclosed-tail tests still pass. Mutant +terminated-tail-recovery dies; the independent signed-tail hash assertion kills no-hash-chain. + +A11: whitespace argv must not be silently re-split +------------------------------------------------ +Before: separately signed canonical records passed as a fused PID/account argument, a fused +command/PID argument, or fused account arguments were accepted (0). After: each returns 2 +before dispatch and leaves the journal unchanged. lbarg rejects ASCII whitespace/control +bytes within every actual argv element before joining fields. The argv-whitespace mutant dies. + +A12: already-reserved is not a terminal-phase acknowledgement +---------------------------------------------------------- +Before: replaying the identical signed reservation after either settlement or refund returned +0/already-reserved. After: the same open-job retry still returns 0/already-reserved; the two +terminal-phase retries return 10 and leave the journal unchanged. This regression has an +independent fresh fixture, so the whitespace tests cannot contaminate its outcome. +The reserve-closed-phase mutant dies. + +Crash controls and limits +------------------------- +The final run killed 200 actual processes; all 200 kills happened before a new durable record +(durable-before-kill 0). Each kill was followed by audit and signed retry, and final balances +matched the control: 100 settled jobs, open 0, prefunded/balances 1000000, escrow 0. Different +randomized signatures mean independent journal byte hashes need not match. Do not call these +200 post-fsync kills. The separate deterministic strace SIGKILL occurs after successful fsync +and before stdout, then requires an already-settled retry with no second payment. +No interrupted-RPC or physical power-failure qualification is inferred from local CLI tests. + +Mounted Omega tool use is separately recorded in audit-v2-omega-tools.txt. That server's older +pin is not silently substituted for the actual newer compiler/gate pins above. Application +README/evidence were updated; no language/compiler/shared-harness example or ownership changed. diff --git a/evidence/aienet0-tur-ledger-20261027/audit-v2-omega-tools.txt b/evidence/aienet0-tur-ledger-20261027/audit-v2-omega-tools.txt new file mode 100644 index 00000000..33ad515f --- /dev/null +++ b/evidence/aienet0-tur-ledger-20261027/audit-v2-omega-tools.txt @@ -0,0 +1,41 @@ +HOST_TESTED mounted Omega MCP assistance; not a substitute for the newer local native gate. + +Mounted server pin: omega-mv e5b32567a7aff3ce594e3254a622a846a6cd190b. +Mounted omc sha256: 2c82480596bbdc50cda9626866209ef662d5834f278f839ff4ce0250c495029f. +Actual ledger/gate pin: omega-mv 6999fa9e6dae4847c155ef4eacaece74f491d3ca. +Actual local omc sha256: d6290c7663c2b4bafb59eb3fdf812476e977f4c144def71095c6248ef9b96b84. + +mcp__omega_lookup({"query":"ftrunc"}) +Observed form: ftrunc fd length; fd int, length long, result long, -errno on failure. +Citations: pinned seed keyword table 799-800; OMEGESE line 811. + +mcp__omega_lookup({"query":"fsync"}) +Observed form: fsync fd; fd int, result long, -errno on failure; sync data and metadata. +Citations: pinned seed keyword table 1177-1178; OMEGESE line 792. + +mcp__omega_run input (older-pin-compatible pure argv guard only): +fn valid c uchar to bool +if le c 32 +ret false +end +ret true +end +fn main to int +if valid uchar 32 +ret 1 +end +if not valid uchar 65 +ret 2 +end +ret 0 +end + +Observed: compile ok, 348 bytes, sha256 8f069ea8f43e682cb356e6b3fa8e56cfaba8e1577eef14d9257743aa8d2fd9b6. +Run: normal exit 0, stdout/stderr empty, isolated bwrap + prlimit, no host files/network. +Negative control: change only `if le c 32` to `if le c 31`. +Observed: compile ok, 348 bytes, sha256 5bb09f97b7481daaa061095325042239fb1fd7ce6dc8081fd41f29cb7dfe2197. +Run: normal exit 1, stdout/stderr empty, same isolated sandbox. + +These calls checked the documented host-word types and a compatible guard expression. +They did not exercise filesystem durability, the newer compiler, an RPC, GPU, power loss, +or hardware qualification. audit-v2-check.out records the actual newer-pin ledger behavior. diff --git a/evidence/aienet0-tur-ledger-20261027/auth-v2-SHA256SUMS b/evidence/aienet0-tur-ledger-20261027/auth-v2-SHA256SUMS new file mode 100644 index 00000000..3b16cd84 --- /dev/null +++ b/evidence/aienet0-tur-ledger-20261027/auth-v2-SHA256SUMS @@ -0,0 +1,7 @@ +b188d4c8324eb1d99f9d5e0d08549c54358afca369171974433b456f59ae4ca6 om/tur-ledger/tur-ledger.om +437cd267a17d0aaa20cf24673fba537375c01103c6e6d3b38129a80560a14813 om/tur-ledger/check.sh +4f88dad60464eacd1655ba980f66b74000c6966ec0becbb80346ac1898e87a76 om/vendor/sha256.om +909f37c797e187bd0663bde9f57c75d6ce41eb2c9726a6b50d6fc714e424c060 om/vendor/ec.om +2672531a13450d995ec0a8906efef69d8e201cd94970de2bc3b44e4f4e19e99a evidence/aienet0-tur-ledger-20261027/auth-v2-before.out +740ac62d07e43cf9de720e926609b6b2207afec5639ce2ce9bd46cad7e6288b0 evidence/aienet0-tur-ledger-20261027/auth-v2-after.out +21c6c31415f1ec2d0471d085c267c43908c7f69503170fdaf2696fad92df1340 evidence/aienet0-tur-ledger-20261027/auth-v2-check.out diff --git a/evidence/aienet0-tur-ledger-20261027/auth-v2-after.out b/evidence/aienet0-tur-ledger-20261027/auth-v2-after.out new file mode 100644 index 00000000..44b51e7b --- /dev/null +++ b/evidence/aienet0-tur-ledger-20261027/auth-v2-after.out @@ -0,0 +1,7 @@ +omc d6290c7663c2b4bafb59eb3fdf812476e977f4c144def71095c6248ef9b96b84 +src b188d4c8324eb1d99f9d5e0d08549c54358afca369171974433b456f59ae4ca6 om/tur-ledger/tur-ledger.om +sha 4f88dad60464eacd1655ba980f66b74000c6966ec0becbb80346ac1898e87a76 om/vendor/sha256.om +ec 909f37c797e187bd0663bde9f57c75d6ce41eb2c9726a6b50d6fc714e424c060 omega-mv@6999fa9e6dae4847c155ef4eacaece74f491d3ca +gate 437cd267a17d0aaa20cf24673fba537375c01103c6e6d3b38129a80560a14813 +OpenSSL 3.0.13 30 Jan 2024 (Library: OpenSSL 3.0.13 30 Jan 2024) +PASS auth.unsigned-prefund (exit 2, unchanged journal) diff --git a/evidence/aienet0-tur-ledger-20261027/auth-v2-before.out b/evidence/aienet0-tur-ledger-20261027/auth-v2-before.out new file mode 100644 index 00000000..a9dd8237 --- /dev/null +++ b/evidence/aienet0-tur-ledger-20261027/auth-v2-before.out @@ -0,0 +1,7 @@ +omc d6290c7663c2b4bafb59eb3fdf812476e977f4c144def71095c6248ef9b96b84 +src 960f4bb581e3c63cb193ef164736cf5394441ff580515be563b60cc42a53f4af om/tur-ledger/tur-ledger.om +sha 4f88dad60464eacd1655ba980f66b74000c6966ec0becbb80346ac1898e87a76 om/vendor/sha256.om +ec 909f37c797e187bd0663bde9f57c75d6ce41eb2c9726a6b50d6fc714e424c060 omega-mv@6999fa9e6dae4847c155ef4eacaece74f491d3ca +gate 437cd267a17d0aaa20cf24673fba537375c01103c6e6d3b38129a80560a14813 +OpenSSL 3.0.13 30 Jan 2024 (Library: OpenSSL 3.0.13 30 Jan 2024) +FAIL auth.unsigned-prefund: exit 0 expected 2, before '2892cc02644ff349d80dc04fb2235f7898acef2828e8a78293c3f02f2f91c95f /tmp/tmp.HgKglInmXi/unsigned/journal' after 'ba4a479494254e68718f8d0b84bd623cd8ce16a03301723b0969c78bfceb672e /tmp/tmp.HgKglInmXi/unsigned/journal' diff --git a/evidence/aienet0-tur-ledger-20261027/auth-v2-check.out b/evidence/aienet0-tur-ledger-20261027/auth-v2-check.out new file mode 100644 index 00000000..34693ff3 --- /dev/null +++ b/evidence/aienet0-tur-ledger-20261027/auth-v2-check.out @@ -0,0 +1,93 @@ +omc d6290c7663c2b4bafb59eb3fdf812476e977f4c144def71095c6248ef9b96b84 +src 960f4bb581e3c63cb193ef164736cf5394441ff580515be563b60cc42a53f4af om/tur-ledger/tur-ledger.om +sha 4f88dad60464eacd1655ba980f66b74000c6966ec0becbb80346ac1898e87a76 om/vendor/sha256.om +ec 909f37c797e187bd0663bde9f57c75d6ce41eb2c9726a6b50d6fc714e424c060 omega-mv@6999fa9e6dae4847c155ef4eacaece74f491d3ca +gate 437cd267a17d0aaa20cf24673fba537375c01103c6e6d3b38129a80560a14813 +OpenSSL 3.0.13 30 Jan 2024 (Library: OpenSSL 3.0.13 30 Jan 2024) +bin d12d05cda56604410b8716602a7e3988a0e90901d28294f04f6ea7d8081f435c +PASS oracle.prefund +PASS oracle.overdraft-101 +PASS oracle.reserve-7-40 +PASS oracle.req-after-reserve +PASS oracle.second-reservation +PASS oracle.settle-unknown-job +PASS oracle.change-mismatch +PASS oracle.settle +PASS oracle.zero-replay +PASS oracle.requester +PASS oracle.provider +PASS oracle.verifier +PASS oracle.observer +PASS oracle.audit +PASS oracle.chain-sha256sum +PASS prefund.first +PASS prefund.dup +PASS prefund.conflict-amount +PASS prefund.conflict-account +PASS prefund.balance +PASS usage.bad-job +PASS usage.leading-zero +PASS usage.zero-amount +PASS usage.arity +PASS usage.command +PASS usage.u64-overflow +PASS once.settle +PASS once.same-receipt +PASS once.other-receipt +PASS once.same-receipt-other-split +PASS once.refund-after-settle +PASS once.journal-unchanged +PASS concurrent.settle-distinct (settled 1, already 0, refused 19) +PASS concurrent.settle-same (settled 1, already 19, refused 0) +PASS concurrent.double-debit (one reserve, nineteen insufficient-funds) +PASS lock.blocks-while-held (timeout exit 124, then exit 0) +PASS fsync.before-ack (pwrite64 line 1 < fsync(3) line 2 < write(1) line 3) +PASS torn.unterminated (recovered torn-tail 138 bytes sha256 3e44b72d48977086fbd8675d072b748fe547ca43e7e124f9769f7c54d76db3ff) +PASS torn.bad-hash-last-line (recovered torn-tail 204 bytes sha256 d1bab7e525f517f7353e30d7e84e9872b8514061454647fa5b343e8c301dfc7b) +PASS torn.cut-last-record (recovered torn-tail 199 bytes sha256 1e5f4971b1f86745ea8dfc0c3fcf9c638ccfba80cffecd8a627d7b3414b4e3b3) +PASS corrupt.amount-edited +PASS corrupt.journal-untouched +PASS corrupt.line-deleted +PASS corrupt.lines-swapped +PASS corrupt.genesis-edited +PASS conserve.forged-chain-valid +PASS conserve.payout-over-escrow +PASS conserve.refused-for-every-command +PASS auth.unsigned-prefund (exit 2, unchanged journal) +PASS auth.unsigned-reserve (exit 2, unchanged journal) +PASS auth.unsigned-settle (exit 2, unchanged journal) +PASS auth.unsigned-refund (exit 2, unchanged journal) +PASS auth.wrong-issuer-key (exit 16, unchanged journal) +PASS auth.changed-amount (exit 16, unchanged journal) +PASS auth.changed-quote (exit 16, unchanged journal) +PASS auth.account-spoof (exit 16, unchanged journal) +PASS auth.wrong-verifier-key (exit 16, unchanged journal) +PASS auth.unauthorized-settle (exit 16, unchanged journal) +PASS auth.changed-job (exit 16, unchanged journal) +PASS auth.forged-receipt-hash (exit 16, unchanged journal) +PASS auth.mutated-attestation-digest (exit 16, unchanged journal) +PASS auth.mutated-signed-job-digest (exit 16, unchanged journal) +PASS auth.issuer-is-not-verifier (exit 16, unchanged journal) +PASS auth.kill-after-fsync-before-ack +PASS auth.lost-response-retry +PASS auth.honest-provider +PASS auth.changed-evidence-conflicts-even-when-signed (exit 11, unchanged journal) +PASS auth.unsigned-replay-last (exit 5, unchanged journal) +PASS auth.wrong-key-replay-last (exit 5, unchanged journal) +PASS auth.old-journal-refused (exit 5, unchanged journal) +PASS auth.changed-policy-pins (exit 5, unchanged journal) +crash: n 200 killed 200 (durable-before-kill 0, not-yet-durable 200) completed-before-kill 0 journal-identical-to-control no +crash: audit ok records 202 head 4055b195c66f99cddf5dc6a9f8effab1cc104ea8762786b1b504bfe3288bc517 accounts 3 jobs 100 open 0 settled 100 refunded 0 prefunded 1000000 balances 1000000 escrow 0 +PASS crash.kill9-200 (audit after every kill, no double settle, balances equal control) +SUITE PASS +PASS mutant no-fsync killed (2 failing: fsync.before-ack auth.kill-after-fsync-before-ack ) +PASS mutant no-lock killed (1 failing: lock.blocks-while-held ) +PASS mutant no-exactly-once killed (11 failing: oracle.zero-replay once.same-receipt once.other-receipt once.same-receipt-other-split once.refund-after-settle once.journal-unchanged concurrent.settle-distinct concurrent.settle-same auth.lost-response-retry auth.honest-provider auth.changed-evidence-conflicts-even-when-signed ) +PASS mutant no-hash-chain killed (1 failing: torn.bad-hash-last-line ) +PASS mutant no-conservation killed (2 failing: conserve.payout-over-escrow conserve.refused-for-every-command ) +PASS mutant no-escrow-rule killed (8 failing: oracle.change-mismatch oracle.settle oracle.zero-replay oracle.requester oracle.provider oracle.verifier oracle.observer oracle.audit ) +PASS mutant no-torn-recovery killed (1 failing: torn.bad-hash-last-line ) +PASS mutant no-issuer-signature killed (6 failing: auth.wrong-issuer-key auth.changed-amount auth.changed-quote auth.unauthorized-settle auth.kill-after-fsync-before-ack auth.wrong-key-replay-last ) +PASS mutant no-verifier-signature killed (3 failing: auth.wrong-verifier-key auth.issuer-is-not-verifier auth.kill-after-fsync-before-ack ) +PASS mutant no-owner-pins killed (1 failing: auth.account-spoof ) +TUR_LEDGER gate: PASS diff --git a/evidence/aienet0-tur-ledger-20261027/capacity-v2-SHA256SUMS b/evidence/aienet0-tur-ledger-20261027/capacity-v2-SHA256SUMS new file mode 100644 index 00000000..a23920e4 --- /dev/null +++ b/evidence/aienet0-tur-ledger-20261027/capacity-v2-SHA256SUMS @@ -0,0 +1,8 @@ +414d05afa4a96c6d643c51852a273368e45e32ce0215a0c73827ee6efdccff0c capacity-v2-before.out +659d13b26857ba4616fb5777d0d85a1d24215ef72602d62a2630d3a04e7c6835 capacity-v2-check.out +3cdc3f31b62d1395d5266701252747f1342bfde375deacd289038d336f0c1ae8 capacity-v2-full.journal.gz +28e7ddf85460e71cacf491825b69f719e68c27a0e128212e76133a281df36eeb capacity-v2-full.authority +43270c3879522ffc9e0533917a35ed4dbb43b20e2d1e69d50d41aa0b98f64cab capacity-v2-full.commands +bb6d1f7535019b3185f9be120cd953d25e5176d86a8c7ae46224652029548b4a capacity-v2-full.results.tsv +8d7b7ae669df953de8bdf71c372ad5774ea9898c2e69e487fae4d2f46a5f6aa9 capacity-v2-full-audit.out +d4d1e812c641f324a9a86ffe9ef5806f9327c5e572423472b85daecba16143f9 capacity-v2-notes.txt diff --git a/evidence/aienet0-tur-ledger-20261027/capacity-v2-before.out b/evidence/aienet0-tur-ledger-20261027/capacity-v2-before.out new file mode 100644 index 00000000..9ba7b118 --- /dev/null +++ b/evidence/aienet0-tur-ledger-20261027/capacity-v2-before.out @@ -0,0 +1,33 @@ +omc d6290c7663c2b4bafb59eb3fdf812476e977f4c144def71095c6248ef9b96b84 +src f47d8c6374f5e8a49068cc5372e97582e3eb81e87c5e53a661ea62ebb4279713 om/tur-ledger/tur-ledger.om +sha 4f88dad60464eacd1655ba980f66b74000c6966ec0becbb80346ac1898e87a76 om/vendor/sha256.om +ec 909f37c797e187bd0663bde9f57c75d6ce41eb2c9726a6b50d6fc714e424c060 omega-mv@6999fa9e6dae4847c155ef4eacaece74f491d3ca +gate 74afc74427421f13da849ee9983748ea2ec0c95ab6a03e131eb4f29929e82f4f +OpenSSL 3.0.13 30 Jan 2024 (Library: OpenSSL 3.0.13 30 Jan 2024) +PASS capacity.prefund +PASS capacity.reserve-settle +PASS capacity.reserve-refund +PASS capacity.fill-p2 +FAIL capacity.fill-p3: exit 14 out '' err 'refused 14 capacity', wanted exit 0 out 'prefunded p3 req 1' +FAIL capacity.fill-p4: exit 14 out '' err 'refused 14 capacity', wanted exit 0 out 'prefunded p4 req 1' +FAIL capacity.fill-p5: exit 14 out '' err 'refused 14 capacity', wanted exit 0 out 'prefunded p5 req 1' +PASS capacity.new-prefund-refused (exit 14, unchanged journal) +PASS capacity.new-reserve-refused (exit 14, unchanged journal) +FAIL capacity.settle: exit 14 out '' err 'refused 14 capacity', wanted exit 0 out 'settled 7777777777777777777777777777777777777777777777777777777777777777 aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa 27 3 10' +FAIL capacity.refund: exit 14 out '' err 'refused 14 capacity', wanted exit 0 out 'refunded 8888888888888888888888888888888888888888888888888888888888888888' +FAIL capacity.settle-repeat: exit 14 expected 0, before '581bde5f2d0024ead1602da9559498467bf9e8574b321e1d436ce43dd0d720e1 /tmp/tmp.wFm1CtSkxJ/capacity/journal' after '581bde5f2d0024ead1602da9559498467bf9e8574b321e1d436ce43dd0d720e1 /tmp/tmp.wFm1CtSkxJ/capacity/journal' +FAIL capacity.refund-repeat: exit 14 expected 0, before '581bde5f2d0024ead1602da9559498467bf9e8574b321e1d436ce43dd0d720e1 /tmp/tmp.wFm1CtSkxJ/capacity/journal' after '581bde5f2d0024ead1602da9559498467bf9e8574b321e1d436ce43dd0d720e1 /tmp/tmp.wFm1CtSkxJ/capacity/journal' +FAIL capacity.provider: exit 0 out 'balance prov 0' err '', wanted exit 0 out 'balance prov 27' +FAIL capacity.verifier: exit 0 out 'balance ver 0' err '', wanted exit 0 out 'balance ver 3' +FAIL capacity.audit-closed: exit 0 out 'audit ok records 5 head 3594a618908392b408a08a7257294f25712fc1f5191f1e357b7cc8cb6b989cd2 accounts 3 jobs 2 open 2 settled 0 refunded 0 prefunded 101 balances 21 escrow 80' +PASS capacity.partial-prefund +PASS capacity.partial-fill-p2 +PASS capacity.partial-fill-p3 +PASS capacity.partial-fill-p4 +PASS capacity.partial-fill-p5 +PASS capacity.partial-fill-p6 +FAIL capacity.partial-fill-p7: exit 14 out '' err 'refused 14 capacity', wanted exit 0 out 'prefunded p7 req 1' +FAIL capacity.partial-fill-p8: exit 14 out '' err 'refused 14 capacity', wanted exit 0 out 'prefunded p8 req 1' +PASS capacity.partial-reserve-refused (exit 14, unchanged journal) +FAIL capacity.last-slot-prefund: exit 14 out '' err 'refused 14 capacity', wanted exit 0 out 'prefunded p9 req 1' +PASS capacity.partial-full-prefund-refused (exit 14, unchanged journal) diff --git a/evidence/aienet0-tur-ledger-20261027/capacity-v2-check.out b/evidence/aienet0-tur-ledger-20261027/capacity-v2-check.out new file mode 100644 index 00000000..7f82eea7 --- /dev/null +++ b/evidence/aienet0-tur-ledger-20261027/capacity-v2-check.out @@ -0,0 +1,124 @@ +omc d6290c7663c2b4bafb59eb3fdf812476e977f4c144def71095c6248ef9b96b84 +src f47d8c6374f5e8a49068cc5372e97582e3eb81e87c5e53a661ea62ebb4279713 om/tur-ledger/tur-ledger.om +sha 4f88dad60464eacd1655ba980f66b74000c6966ec0becbb80346ac1898e87a76 om/vendor/sha256.om +ec 909f37c797e187bd0663bde9f57c75d6ce41eb2c9726a6b50d6fc714e424c060 omega-mv@6999fa9e6dae4847c155ef4eacaece74f491d3ca +gate 2bb20abca2e6757ee30763644f87d8ec13df8bb9cdcf255168ec6f18970d0647 +OpenSSL 3.0.13 30 Jan 2024 (Library: OpenSSL 3.0.13 30 Jan 2024) +bin afd2fbe7b68a9f5fe44ff67b28830ab2499a482b1a922b237bc1877716a3ef93 +PASS oracle.prefund +PASS oracle.overdraft-101 +PASS oracle.reserve-7-40 +PASS oracle.req-after-reserve +PASS oracle.second-reservation +PASS oracle.settle-unknown-job +PASS oracle.change-mismatch +PASS oracle.settle +PASS oracle.zero-replay +PASS oracle.requester +PASS oracle.provider +PASS oracle.verifier +PASS oracle.observer +PASS oracle.audit +PASS oracle.chain-sha256sum +PASS prefund.first +PASS prefund.dup +PASS prefund.conflict-amount +PASS prefund.conflict-account +PASS prefund.balance +PASS usage.bad-job +PASS usage.leading-zero +PASS usage.zero-amount +PASS usage.arity +PASS usage.command +PASS usage.u64-overflow +PASS once.settle +PASS once.same-receipt +PASS once.other-receipt +PASS once.same-receipt-other-split +PASS once.refund-after-settle +PASS once.journal-unchanged +PASS concurrent.settle-distinct (settled 1, already 0, refused 19) +PASS concurrent.settle-same (settled 1, already 19, refused 0) +PASS concurrent.double-debit (one reserve, nineteen insufficient-funds) +PASS lock.blocks-while-held (timeout exit 124, then exit 0) +PASS fsync.before-ack (pwrite64 line 1 < fsync(3) line 2 < write(1) line 3) +PASS torn.unterminated (recovered torn-tail 138 bytes sha256 3e44b72d48977086fbd8675d072b748fe547ca43e7e124f9769f7c54d76db3ff) +PASS torn.bad-hash-last-line (recovered torn-tail 204 bytes sha256 d15143e33a5a4a3e64efc24dcbb7b86564bba419d163c8167854f90e96219cef) +PASS torn.cut-last-record (recovered torn-tail 199 bytes sha256 e0051db625f9398b07c5a99801ee953dc16908fd140ccf22ff27952650d3bc0e) +PASS corrupt.amount-edited +PASS corrupt.journal-untouched +PASS corrupt.line-deleted +PASS corrupt.lines-swapped +PASS corrupt.genesis-edited +PASS conserve.forged-chain-valid +PASS conserve.payout-over-escrow +PASS conserve.refused-for-every-command +PASS auth.unsigned-prefund (exit 2, unchanged journal) +PASS auth.unsigned-reserve (exit 2, unchanged journal) +PASS auth.unsigned-settle (exit 2, unchanged journal) +PASS auth.unsigned-refund (exit 2, unchanged journal) +PASS auth.wrong-issuer-key (exit 16, unchanged journal) +PASS auth.changed-amount (exit 16, unchanged journal) +PASS auth.changed-quote (exit 16, unchanged journal) +PASS auth.account-spoof (exit 16, unchanged journal) +PASS auth.wrong-verifier-key (exit 16, unchanged journal) +PASS auth.unauthorized-settle (exit 16, unchanged journal) +PASS auth.changed-job (exit 16, unchanged journal) +PASS auth.forged-receipt-hash (exit 16, unchanged journal) +PASS auth.mutated-attestation-digest (exit 16, unchanged journal) +PASS auth.mutated-signed-job-digest (exit 16, unchanged journal) +PASS auth.issuer-is-not-verifier (exit 16, unchanged journal) +PASS auth.kill-after-fsync-before-ack +PASS auth.lost-response-retry +PASS auth.honest-provider +PASS auth.changed-evidence-conflicts-even-when-signed (exit 11, unchanged journal) +PASS auth.unsigned-replay-last (exit 5, unchanged journal) +PASS auth.wrong-key-replay-last (exit 5, unchanged journal) +PASS auth.old-journal-refused (exit 5, unchanged journal) +PASS auth.changed-policy-pins (exit 5, unchanged journal) +crash: n 200 killed 200 (durable-before-kill 0, not-yet-durable 200) completed-before-kill 0 journal-identical-to-control no +crash: audit ok records 202 head 7fc67318745ceebc674c2bdb1270342f8f06df0576b2c7b63a13a6bc6e0b39c0 accounts 3 jobs 100 open 0 settled 100 refunded 0 prefunded 1000000 balances 1000000 escrow 0 +PASS crash.kill9-200 (audit after every kill, no double settle, balances equal control) +capacity-source f47d8c6374f5e8a49068cc5372e97582e3eb81e87c5e53a661ea62ebb4279713 KCAP=10 +capacity-bin 36b27f1f364f0b8a348d91669db592953b6d7b6094fef1e4b574ca6e0693028f +PASS capacity.prefund +PASS capacity.reserve-settle +PASS capacity.reserve-refund +PASS capacity.fill-p2 +PASS capacity.fill-p3 +PASS capacity.fill-p4 +PASS capacity.fill-p5 +PASS capacity.new-prefund-refused (exit 14, unchanged journal) +PASS capacity.new-reserve-refused (exit 14, unchanged journal) +PASS capacity.settle +PASS capacity.refund +PASS capacity.settle-repeat (exit 0, unchanged journal) +PASS capacity.refund-repeat (exit 0, unchanged journal) +PASS capacity.provider +PASS capacity.verifier +PASS capacity.audit-closed +PASS capacity.partial-prefund +PASS capacity.partial-fill-p2 +PASS capacity.partial-fill-p3 +PASS capacity.partial-fill-p4 +PASS capacity.partial-fill-p5 +PASS capacity.partial-fill-p6 +PASS capacity.partial-fill-p7 +PASS capacity.partial-fill-p8 +PASS capacity.partial-reserve-refused (exit 14, unchanged journal) +PASS capacity.last-slot-prefund +PASS capacity.partial-full-prefund-refused (exit 14, unchanged journal) +SUITE PASS +PASS mutant no-fsync killed (2 failing: fsync.before-ack auth.kill-after-fsync-before-ack ) +PASS mutant no-lock killed (1 failing: lock.blocks-while-held ) +PASS mutant no-exactly-once killed (16 failing: oracle.zero-replay once.same-receipt once.other-receipt once.same-receipt-other-split once.refund-after-settle once.journal-unchanged concurrent.settle-distinct concurrent.settle-same auth.lost-response-retry auth.honest-provider auth.changed-evidence-conflicts-even-when-signed capacity.settle-repeat capacity.refund-repeat capacity.provider capacity.verifier capacity.audit-closed ) +PASS mutant no-hash-chain killed (1 failing: torn.bad-hash-last-line ) +PASS mutant no-conservation killed (2 failing: conserve.payout-over-escrow conserve.refused-for-every-command ) +PASS mutant no-escrow-rule killed (8 failing: oracle.change-mismatch oracle.settle oracle.zero-replay oracle.requester oracle.provider oracle.verifier oracle.observer oracle.audit ) +PASS mutant no-torn-recovery killed (1 failing: torn.bad-hash-last-line ) +PASS mutant no-issuer-signature killed (6 failing: auth.wrong-issuer-key auth.changed-amount auth.changed-quote auth.unauthorized-settle auth.kill-after-fsync-before-ack auth.wrong-key-replay-last ) +PASS mutant no-verifier-signature killed (3 failing: auth.wrong-verifier-key auth.issuer-is-not-verifier auth.kill-after-fsync-before-ack ) +PASS mutant no-owner-pins killed (1 failing: auth.account-spoof ) +PASS mutant capacity-lockup killed (13 failing: capacity.fill-p3 capacity.fill-p4 capacity.fill-p5 capacity.settle capacity.refund capacity.settle-repeat capacity.refund-repeat capacity.provider capacity.verifier capacity.audit-closed capacity.partial-fill-p7 capacity.partial-fill-p8 capacity.last-slot-prefund ) +PASS mutant no-slot-preflight killed (10 failing: capacity.new-prefund-refused capacity.settle capacity.refund capacity.settle-repeat capacity.refund-repeat capacity.provider capacity.verifier capacity.audit-closed capacity.partial-reserve-refused capacity.last-slot-prefund ) +TUR_LEDGER gate: PASS diff --git a/evidence/aienet0-tur-ledger-20261027/capacity-v2-full-audit.out b/evidence/aienet0-tur-ledger-20261027/capacity-v2-full-audit.out new file mode 100644 index 00000000..68cf9fd9 --- /dev/null +++ b/evidence/aienet0-tur-ledger-20261027/capacity-v2-full-audit.out @@ -0,0 +1 @@ +audit ok records 65536 head 26ebc6a04f4f8ace9a78669e4fdb013508dde61deddb99b5df31a7731aee68be accounts 3 jobs 2 open 0 settled 1 refunded 1 prefunded 65630 balances 65630 escrow 0 diff --git a/evidence/aienet0-tur-ledger-20261027/capacity-v2-full.authority b/evidence/aienet0-tur-ledger-20261027/capacity-v2-full.authority new file mode 100644 index 00000000..19f53ef3 --- /dev/null +++ b/evidence/aienet0-tur-ledger-20261027/capacity-v2-full.authority @@ -0,0 +1 @@ +genesis tur-ledger-2 0000000000000000000000000000000000000000000000000000000000000000 042d70cdf162d37ab2efdf3cb05f8cbf8e083d14088d92734a9999fecded2db41e3b8a9e51ca60fbb93272fe05c3199230cec89bcd1e5ceb73662a397665b520e4 04e05e8063543371322e4f3b925d99281379bf7fd08c41446c432a4664fdd65e8294ca2284bca94f12645b9492ffeb4bd771d56dc90a27ed763574813389bc6e2b aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa req prov ver aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb 7777777777777777777777777777777777777777777777777777777777777777 \ No newline at end of file diff --git a/evidence/aienet0-tur-ledger-20261027/capacity-v2-full.commands b/evidence/aienet0-tur-ledger-20261027/capacity-v2-full.commands new file mode 100644 index 00000000..a535ff8d --- /dev/null +++ b/evidence/aienet0-tur-ledger-20261027/capacity-v2-full.commands @@ -0,0 +1,4 @@ +prefund overflow req 1 3046022100b4609841c495ec7ffc9e40bdcf6b6429a3d570a54de1f75d6ca262700fa90b9d022100eb5433043e326e2edf5432b0da45957a80c838d417a2e6591e173f245664fdf6 +reserve bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb req prov ver 1 aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa 3046022100aac1417db0a137b79726efb9bdaaa91f207cdf2ac3ff513f085c036dec84f540022100e4a0dbc3f7b9ea867df44f4145c1bf1d8742ca38ceea3563378c38c2ef55491a +settle 7777777777777777777777777777777777777777777777777777777777777777 aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa 27 3 10 7777777777777777777777777777777777777777777777777777777777777777 bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb 304402206199389a3101e24b9d0671cb286de24358babff6b7c8350c093394ee0a159f1102201de0d8c21da40949c7da44ff69ac2d31ea44c6e2e9ad7dca1496e512024e6a70 3046022100d7e128fe370f510039fcd1ff47def0125919ca53d3faf49a023fca102c748879022100f370f89250af532699aaf08702d5554d1f7ed97ecba3df6ecbe8d003471f4ac1 +refund 8888888888888888888888888888888888888888888888888888888888888888 3044022028d3a5bf8fd666e1b7439a2dd94dabab7313c152249845a0a932fb672948034a02203462dd6fc9dd003cffbbcf7e15a6a2e86e2da85d2d7c798f1fa471988906ca2d diff --git a/evidence/aienet0-tur-ledger-20261027/capacity-v2-full.journal.gz b/evidence/aienet0-tur-ledger-20261027/capacity-v2-full.journal.gz new file mode 100644 index 00000000..69cfaf66 Binary files /dev/null and b/evidence/aienet0-tur-ledger-20261027/capacity-v2-full.journal.gz differ diff --git a/evidence/aienet0-tur-ledger-20261027/capacity-v2-full.results.tsv b/evidence/aienet0-tur-ledger-20261027/capacity-v2-full.results.tsv new file mode 100644 index 00000000..133482da --- /dev/null +++ b/evidence/aienet0-tur-ledger-20261027/capacity-v2-full.results.tsv @@ -0,0 +1,7 @@ +phase operation exit stdout stderr journal_unchanged +before settle 14 refused 14 capacity True +before refund 14 refused 14 capacity True +after prefund 14 refused 14 capacity True +after reserve 14 refused 14 capacity True +after settle 0 settled 7777777777777777777777777777777777777777777777777777777777777777 aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa 27 3 10 False +after refund 0 refunded 8888888888888888888888888888888888888888888888888888888888888888 False diff --git a/evidence/aienet0-tur-ledger-20261027/capacity-v2-notes.txt b/evidence/aienet0-tur-ledger-20261027/capacity-v2-notes.txt new file mode 100644 index 00000000..90e05ba5 --- /dev/null +++ b/evidence/aienet0-tur-ledger-20261027/capacity-v2-notes.txt @@ -0,0 +1,135 @@ +CAPACITY-DISCHARGE CORRECTION: HOST_TESTED ON THE DGX SPARK + +Finding and cause +The shared wcmd append precheck required SKEYS + 4 <= KCAP for every new +mutation, including settle/refund. Those operations touch only the reserved job +and its existing account IDs; they allocate no keys. Near capacity, legitimate +escrow could therefore become impossible to discharge. The defect is present in +the authenticated source at Core #794's initial commit +6a0bfc0bb0b08d6fa08bc8109536218f50dd8b2c, not just merged #792. + +Fix +Remove the blanket append guard. vpre counts its new PID plus a missing requester; +vres counts its new job plus missing distinct provider/verifier accounts, with +an existing requester required. Refuse 14 before append if the exact slots do +not fit. Settlement/refund remain allocation-free, including at a full table. +No signature, ownership, conservation, single-writer or fsync gate is weakened. +No journal-format or authorization-message change from the earlier v2 commit. + +Pins +- Pre-fix source SHA-256: + b188d4c8324eb1d99f9d5e0d08549c54358afca369171974433b456f59ae4ca6 +- Pre-fix native binary /tmp/ledger-auth-bin-final: + d12d05cda56604410b8716602a7e3988a0e90901d28294f04f6ea7d8081f435c +- Fixed source SHA-256: + f47d8c6374f5e8a49068cc5372e97582e3eb81e87c5e53a661ea62ebb4279713 +- Fixed production binary /tmp/ledger-auth-capacity-bin and the independently + gate-built /tmp/ledger-auth-capacity-gate-bin: + afd2fbe7b68a9f5fe44ff67b28830ab2499a482b1a922b237bc1877716a3ef93 +- Compiler omega-mv 6999fa9e6dae4847c155ef4eacaece74f491d3ca seed/out/omc: + d6290c7663c2b4bafb59eb3fdf812476e977f4c144def71095c6248ef9b96b84 +- Final check.sh SHA-256: + 2bb20abca2e6757ee30763644f87d8ec13df8bb9cdcf255168ec6f18970d0647 + +Fast reproducible before/after regression +Actual pre-fix command: + OMC=/tmp/ledger-auth-omega/seed/out/omc \ + TUR_LEDGER_CAPACITY_SOURCE=/tmp/ledger-auth-capacity-before.om \ + bash om/tur-ledger/check.sh +Exit 1; capacity-v2-before.out. The overridden input source is the frozen +pre-fix b188d4c8 above. The top-level `src` line describes the repository's +current source, not this override. The current harness also prints the explicit +capacity-source pin to avoid that ambiguity. The assertions are unchanged. +Both capacity.settle and capacity.refund returned 14; escrow remained open. + +The fixed ten-slot fixture fills all slots through actual signed CLI commands, +refuses new prefund/reserve without journal changes, settles one reservation, +refunds the other and accepts unchanged once-only retries. A second case has +one slot left but needs a new job and two account slots: reserve refuses before +append and a one-slot prefund can still use the last slot. The full gate below +runs this exact regression and records every PASS. + +Production-size fill-to-capacity fixture +- Raw snapshot: 65,534 correctly chained records; 3 accounts, 2 jobs and 65,531 + distinct prefund IDs, occupying all 65,536 keys. Two jobs remain reserved. +- Raw snapshot SHA-256: + f37746ce5790659d49ae32f423dd109921c59b46c779561e41dce907f46aafd7 +- capacity-v2-full.journal.gz is 8,306,185 bytes; SHA-256: + 3cdc3f31b62d1395d5266701252747f1342bfde375deacd289038d336f0c1ae8 +- Public authority config: capacity-v2-full.authority, no trailing LF. +- Exact pre-signed argument vectors: capacity-v2-full.commands. +- Actual outcomes: capacity-v2-full.results.tsv. journal_unchanged is a measured + SHA-256 equality before/after each command, not an inferred phase label. + +A one-off fixture oracle generated native P-256 keys in memory, signed every +canonical prefund/reserve record and the two final authorizations, and built the +SHA-256 chain. Oracle: installed Python cryptography 41.0.7, OpenSSL 3.0.13; +private key objects were dropped after signing and never written to the repository. +The oracle is verification-only, not ledger implementation or a production +runtime dependency; no Python source is added. Native Omega verified every +signature and replayed the actual production-size table. This is a bulk-built +signed test history, not a claim that the old live writer accepted every fill: +the old blanket guard stops admitting earlier, which the CLI regression also +catches. Synthetic job/evidence IDs intentionally test capacity, not real work. + +Actual invocations were [BINARY, --journal, DIR, *ARGS] for each argument vector: +- Before, same full snapshot: settle -> exit 14, refused 14 capacity, unchanged; + refund -> exit 14, refused 14 capacity, unchanged. +- After, same full snapshot: prefund -> 14, unchanged; reserve -> 14, unchanged; + settle -> 0, settled JOB7 RECEIPT_A 27 3 10; refund -> 0, refunded JOB8. +- Final native audit -> exit 0: + audit ok records 65536 head 26ebc6a04f4f8ace9a78669e4fdb013508dde61deddb99b5df31a7731aee68be accounts 3 jobs 2 open 0 settled 1 refunded 1 prefunded 65630 balances 65630 escrow 0 + Raw output is capacity-v2-full-audit.out. + +To replay against a built ledger, from this evidence directory, in Bash without +set -e (the first two exit-14 results are expected): + D=$(mktemp -d) + gzip -dc capacity-v2-full.journal.gz > "$D/journal" + cp capacity-v2-full.authority "$D/authority" + while read -r -a args; do + before=$(sha256sum "$D/journal") + "$LEDGER" --journal "$D" "${args[@]}"; rc=$? + case "${args[0]}" in prefund|reserve) expected=14;; *) expected=0;; esac + test "$rc" = "$expected" || exit 1 + if test "$expected" = 14; then + test "$(sha256sum "$D/journal")" = "$before" || exit 1 + fi + done < capacity-v2-full.commands + "$LEDGER" --journal "$D" audit +The old binary fails the settlement assertion; the fixed binary gives the audit +above. The journal fixture and public signatures are replayable without any +private key. Reconstructing this test context is not provisioning a real ledger. + +Full final gate and mutants +Actual command: + OMC=/tmp/ledger-auth-omega/seed/out/omc CRASH_N=200 MUTANT_CRASH_N=0 \ + TUR_LEDGER_OUT=/tmp/ledger-auth-capacity-gate-bin \ + bash om/tur-ledger/check.sh +Exit 0; SUITE PASS; TUR_LEDGER gate: PASS. Raw stdout: capacity-v2-check.out. +All twelve mutants were killed. capacity-lockup restores the exact blanket +append guard and fails thirteen capacity assertions. no-slot-preflight deletes +the allocating-operation checks and fails ten assertions, including unchanged +journal and partial-reserve refusal. The other ten existing authentication, +exactly-once, integrity, conservation, durability and recovery mutants still die. +All 200 random-delay SIGKILL attempts preceded a new durable write; each was +audited/retried and final balances matched control. The separate strace injection +proved the post-fsync/pre-ack SIGKILL and once-only retry. Do not describe the +random-delay trials as 200 post-fsync kills or as interrupted RPC qualification. + +Required Core preflight + TINYLLAMA_MODEL_PATH=/home/drakestapleton/.cache/huggingface/hub/models--TinyLlama--TinyLlama-1.1B-Chat-v1.0/blobs/6e6001da2106d4757498752a021df6c2bdc332c650aae4bae6b0c004dcf14933 \ + bash scripts/agent-preflight.sh +Exit 0, PREFLIGHT VERIFICATION COMPLETE; branch/secrets/style/workspace/advisory +checks pass. aien-proof reported 58 stamped passes and 0 newly run crates; these +are reused valid Rust results, not a fresh execution claim. Six pre-existing +allowed advisory warnings remain. The changed native ledger path above was +actually compiled/exercised independently of those stamps. The physical model +blob path is the supported test override; no symlink/advisory gate was relaxed. + +Scope +Local native host evidence only; no GPU, live 18091, deployment, real economic +authority, malicious filesystem rollback resistance or Core RPC is qualified. +The actual signed-artifact caller is separately migrated/tested in protocols #67. +No compiler/language/host primitive/shared harness example changes here; the +application README and evidence are updated, and no Omega harness guide is stale +because of this application-specific capacity correction. diff --git a/om/README.md b/om/README.md index bc91e0d1..54b80574 100644 --- a/om/README.md +++ b/om/README.md @@ -8,8 +8,9 @@ aien-architecture-mv#300). | Path | What it is | Status | |---|---|---| | `effects/world.om` | The restart world check of the effect ledger: reads the target file, hashes it, decides DONE / NOT_DONE / UNRESOLVED like `effects::state_from`, and writes the reconcile record text and its sha256 like `effects::reconcile_text`. | Byte-identical to the Rust on 24 fixtures (`effects/run.sh`). Not wired into the daemon. | -| `tur-ledger/tur-ledger.om` | Aienet-0 TUR escrow ledger CLI (`tur-ledger --journal DIR prefund\|reserve\|settle\|refund\|balance\|show\|audit`): hash-chained append-only journal, flock for the whole command, fsync before the reply, torn-tail recovery, exactly-once settle, the escrow rules of `tests/turing-network/tur_r0_oracle.om` per JOB. See `tur-ledger/README.md`. | HOST_TESTED by `tur-ledger/check.sh` (oracle scenario, concurrency, kill -9, torn tail, corruption, 7 mutants). New component, no Rust counterpart. | +| `tur-ledger/tur-ledger.om` | Aienet-0 test-credit ledger CLI: v2 genesis pins issuer, independent verifier and account/node policy. Canonical mutations require issuer signatures; settlement also requires verifier authorization over signed-job, result and attestation digests and the reserved quote. Single-writer hash chain, fsync, recovery, integer conservation and exactly-once settle remain. See `tur-ledger/README.md`. | Host admission/durability tests and guard mutants in `tur-ledger/check.sh`; no wallet, Core RPC or public economic qualification. Historical unsigned v1 receipts remain historical. | | `vendor/sha256.om` | Incremental SHA-256 in Omega, vendored from benchmarks-mv. | Exercised through `world.om` and `tur-ledger.om`. | +| `vendor/ec.om` | Native Omega ECDSA P-256/P-384 verification, byte-identical to omega-mv `6999fa9e6dae4847c155ef4eacaece74f491d3ca` `om/tls/ec.om`. | P-256/SHA-256 strict DER verification used by `tur-ledger.om`; OpenSSL is a test-only signing oracle, not a runtime dependency. | Run: `OMEGA_OMC=<path to seed omc> bash om/effects/run.sh` (needs the offline cargo cache for the Rust reference, `crates/aien-runtime/examples/om_world_reference.rs`). diff --git a/om/tur-ledger/README.md b/om/tur-ledger/README.md index fcd15104..d40ed60f 100644 --- a/om/tur-ledger/README.md +++ b/om/tur-ledger/README.md @@ -1,58 +1,200 @@ -# tur-ledger: the Aienet-0 TUR escrow ledger in seeded Omega +# tur-ledger: authenticated Aienet-0 TUR test-credit escrow -One persistent, crash-safe escrow ledger for prefunded TUR test credits. It applies, per JOB, the -escrow rules of `tests/turing-network/tur_r0_oracle.om` (#791): reserve needs funds and one -reservation per JOB; settle needs a reserved JOB and `PAYP + PAYV + BACK = AMOUNT`, and happens -exactly once. Source: `tur-ledger.om` (built after `om/vendor/sha256.om`). No Rust, C or Python. +The native Omega CLI keeps an append-only, single-writer journal with integer conservation, +exactly-once settlement, torn-tail recovery and fsync before acknowledgement. Version 2 adds +issuer authorization for every external mutation and independent verifier authorization for +settlement. It is a local test-credit ledger, not a wallet, currency or public economic service. -Build: `cat om/vendor/sha256.om om/tur-ledger/tur-ledger.om | $OMC > tur-ledger && chmod +x tur-ledger` -with the seeded omc (omega-mv `seed/out/omc`, sha256 `2c82480596bbdc50cda9626866209ef662d5834f278f839ff4ce0250c495029f`). +Build with omega-mv `6999fa9e6dae4847c155ef4eacaece74f491d3ca`, seeded omc sha256 +`d6290c7663c2b4bafb59eb3fdf812476e977f4c144def71095c6248ef9b96b84`: -Gate: `OMC=<seed omc> bash om/tur-ledger/check.sh` (needs `strace`, util-linux `flock`, `timeout`). +```sh +{ printf 'om2\n'; cat om/vendor/sha256.om om/vendor/ec.om om/tur-ledger/tur-ledger.om; } | "$OMC" > tur-ledger && chmod +x tur-ledger +OMC="$OMC" bash om/tur-ledger/check.sh +``` + +`om/vendor/ec.om` is byte-identical to omega-mv's `om/tls/ec.om` at that revision, sha256 +`909f37c797e187bd0663bde9f57c75d6ce41eb2c9726a6b50d6fc714e424c060` (Apache-2.0). +It verifies strict DER ECDSA P-256 signatures entirely in Omega; no host crypto runtime is used. +The SHA-256 unit's private state global is renamed `hstate` to avoid an EC parameter collision. +The gate uses OpenSSL only as an independent signing oracle, plus strace, flock and timeout. +Disposable test keys live in a private tmpfs directory and are removed on exit. No production +private key belongs in this repository or in a ledger directory. + +## Provisioning and authority + +Before any CLI invocation, the trusted Core service operator provisions `DIR/authority` as +exactly these ASCII bytes, with single spaces and **no trailing LF**: + +```text +genesis tur-ledger-2 LEDGER_ID ISSUER_SEC1 VERIFIER_SEC1 POLICY_SHA256 REQUESTER PROVIDER VERIFIER_ACCOUNT REQUESTER_OWNER PROVIDER_NODE VERIFIER_NODE +``` + +`LEDGER_ID`, the policy digest and three owner/node identity pins are 64 lowercase hex characters. +Each public key is 130 lowercase hex characters: SEC1 uncompressed P-256 (`04 || X || Y`). The +issuer and verifier keys must differ. The three account names must differ and are 1..64 bytes +of `[A-Za-z0-9._:-]`. This bounded policy maps exactly one requester owner, provider node and +verifier node to their account names. Only the pinned requester account can be funded; reserve +must name those exact three accounts. Arbitrary account registration is deliberately absent. + +The issuer is the sole Core service authority, not an arbitrary local CLI caller. Its signature +means funding-source approval for the unique funding event `PID`, or approval of the reserved +job, published quote, account-owner/node mapping and policy. `PID` identifies one funding event; +reusing it with different content is refused. The issuer must not assign another PID to that +same funding event. The verifier signature means it independently checked the signed job, +MJR1 result, AN0V attestation, published quote, pinned owner/node identities and policy and +approved this exact payout. Distinct keys do not by themselves establish operational independence. + +Both signers are external authorities. The ledger verifies their typed authorizations, not +MJR1/AN0V artifact parsers or signer policy implementation. Signing unverified caller-provided +hashes violates this contract. No arbitrary receipt hash or issuer-only authorization can settle. +The ledger needs neither private keys nor a new wallet/cryptocurrency primitive. + +Protect the directory, config, provisioning process and authority keys with the service's OS +permissions. This design does not protect against an actor who can replace both config and +journal, roll back a valid signed history or clone an existing ledger identity. The SHA chain is +integrity/recovery evidence, not a signature or malicious-file-write defense. + +## Canonical signed bytes + +Algorithm is fixed for v2: ECDSA P-256 over SHA-256, signature encoded as strict DER then lowercase +hex (no whitespace). Sign the SHA-256 digest of these bytes, not an externally supplied digest: + +```text +EXACT_AUTHORITY_CONFIG LF +CANONICAL_UNSIGNED_COMMAND LF +``` + +For `settle` and `refund`, append the 64 lowercase hex SHA-256 digest of the reserved job's +canonical signed bytes (excluding its signature), followed by LF. This commits settlement to +the exact reserve: JOB, requester/provider/verifier accounts, amount, published quote and +config's owner/node/policy pins. Journal SEQ/PREV/HASH and signatures are excluded from signing. +Each CLI argument must be a separate field and must not contain ASCII whitespace/control bytes; +only then are arguments joined with one ASCII space. Amounts are canonical decimal u64 with no +leading zeros. Every field is covered. The ledger recomputes this digest during admission and +replay. Signatures are checked **before** idempotent success, and re-signing identical semantic +content cannot create another economic action. ## Commands -`tur-ledger --journal DIR <cmd>`. One record per line on stdout, exit 0 on success. +`tur-ledger --journal DIR COMMAND`. `ISIG` is the issuer signature; `VSIG` is the independent +verifier signature over the **same canonical bytes**. | Command | Success output | |---|---| -| `prefund PID ACCT AMOUNT` | `prefunded PID ACCT AMOUNT`; an identical repeat prints `dup PID ACCT AMOUNT` | -| `reserve JOB REQ PROV VER AMOUNT` | `reserved JOB REQ PROV VER AMOUNT`; an identical repeat prints `already-reserved ...` | -| `settle JOB RECEIPT_SHA256 PAYP PAYV BACK` | `settled JOB RECEIPT PAYP PAYV BACK`; the identical repeat prints `already-settled ...` and writes nothing | -| `refund JOB` | `refunded JOB`; a repeat prints `already-refunded JOB` | +| `prefund PID REQUESTER AMOUNT ISIG` | `prefunded PID REQUESTER AMOUNT`; repeat: `dup ...` | +| `reserve JOB REQUESTER PROVIDER VERIFIER_ACCOUNT AMOUNT QUOTE_SHA256 ISIG` | `reserved JOB REQUESTER PROVIDER VERIFIER_ACCOUNT AMOUNT`; repeat: `already-reserved ...` | +| `settle JOB RECEIPT_SHA256 PAYP PAYV BACK SIGNED_JOB_SHA256 AN0V_SHA256 ISIG VSIG` | `settled JOB RECEIPT_SHA256 PAYP PAYV BACK`; repeat: `already-settled ...` | +| `refund JOB ISIG` | `refunded JOB`; repeat: `already-refunded JOB` | | `balance ACCT` | `balance ACCT N` | -| `show JOB` | `job JOB reserved\|settled\|refunded REQ PROV VER AMOUNT [RECEIPT PAYP PAYV BACK]` | +| `show JOB` | `job JOB reserved\|settled\|refunded REQUESTER PROVIDER VERIFIER_ACCOUNT AMOUNT [RECEIPT PAYP PAYV BACK]` | | `audit` | `audit ok records R head H accounts A jobs J open O settled S refunded F prefunded P balances B escrow E` | -JOB and RECEIPT are 64 lowercase hex (JOB is the MJB1 dag_id). Amounts are decimal u64 without -leading zeros, nonzero except PAYP/PAYV/BACK. Names are 1..64 bytes of `[A-Za-z0-9._:-]`. +JOB is the 64-lowercase-hex MJB1 dag_id. QUOTE_SHA256 hashes the exact published quote bytes; +SIGNED_JOB_SHA256 hashes the exact signed MJB1 envelope bytes; RECEIPT_SHA256 hashes the exact +signed MJR1 result bytes; AN0V_SHA256 hashes the exact signed AN0V attestation bytes, including +signatures. All digests are lowercase hex. Amounts are nonzero except PAYP/PAYV/BACK. A duplicate +reserve conflicts if its quote changes; a duplicate settle conflicts if any evidence digest or +payout changes, even when both replacement signatures are valid. +An identical reserve retry returns `already-reserved` only while that job is still open. +After settlement or refund it refuses 10; callers must inspect the actual terminal phase +rather than interpreting an old reservation authorization as current escrow. ## Refusals -A refusal prints `refused C reason` on stderr, writes nothing and exits C. +Refusals print `refused C reason` on stderr and exit C. On an intact journal, an unsuccessful +admission writes nothing. Recovery is a separate internal operation and can run before dispatch. | C | reason | when | |---|---|---| -| 2 | usage | bad arguments, field syntax or command | -| 3 | journal-io | the journal cannot be opened, read, written or fsynced | -| 4 | lock | flock on the journal failed | -| 5 | journal-corrupt | a bad line before the last, an intact last line that does not link (SEQ/PREV), or a record the rules reject on replay | -| 6 | conservation-violated | after replay: balances + open escrow != prefunds, open escrow != open JOB amounts, or a settled JOB paid out != its amount | -| 7 | insufficient-funds | reserve beyond the requester's balance | -| 8 | unknown-job | settle/refund/show of a JOB never reserved | -| 9 | job-conflict | a second, different reservation for a JOB | -| 10 | wrong-phase | refund of a settled JOB, settle of a refunded JOB | -| 11 | settle-receipt-conflict | settle of a settled JOB with a different receipt or split | -| 12 | escrow-rule | `PAYP + PAYV + BACK != AMOUNT` | -| 13 | prefund-id-conflict | a PID reused with a different account or amount | -| 14 | capacity | the in-memory index (65536 keys) is full | -| 15 | overflow | a sum would exceed u64 | - -## Journal - -`DIR/journal`, one line per record: `SEQ PREV KIND FIELDS... HASH`, where HASH is the sha256 -(lowercase hex) of the line's bytes before ` HASH` and PREV is the previous line's HASH (64 zeros on -line 1, `genesis tur-ledger-1`). Every command takes `flock(LOCK_EX)` on the journal for its whole -run, replays and checks the chain and conservation, then appends with `pwrite` and `fsync`s before -it prints. A last line that is unterminated or fails its own HASH is a torn write: it is truncated -and a `recover N SHA` record (N bytes, their sha256) is appended, with a note on stderr. +| 2 | usage | missing signatures, bad arity, whitespace inside an argument, noncanonical fields or unknown command | +| 3 | journal-io | journal open/read/write/fsync or directory-fsync failure; reconcile before treating it as aborted | +| 4 | lock | flock failed | +| 5 | journal-corrupt | old genesis, config mismatch, invalid complete record/signature, bad interior line or linked-chain failure | +| 6 | conservation-violated | replayed balances/open escrow/payout totals disagree | +| 7 | insufficient-funds | reserve exceeds requester balance | +| 8 | unknown-job | authenticated settle/refund/show for unknown JOB | +| 9 | job-conflict | different reservation authorization for JOB | +| 10 | wrong-phase | reserve of a terminal JOB, refund of settled JOB or settle of refunded JOB | +| 11 | settle-receipt-conflict | different settlement authorization for settled JOB | +| 12 | escrow-rule | payout split differs from escrow | +| 13 | prefund-id-conflict | PID reused with different authorization | +| 14 | capacity | an operation would allocate more than 65,536 keys | +| 15 | overflow | u64 total would overflow | +| 16 | authorization | missing/invalid authority config, account policy mismatch or invalid issuer/verifier signature | + +## Journal version and recovery + +`DIR/journal` has `SEQ PREV KIND FIELDS... HASH` records. HASH is SHA-256 of the line before +` HASH`; PREV is the previous HASH (64 zeros for genesis). Genesis is the exact authority config. +Every mutation's record retains its signature(s). Every invocation locks the journal for the +entire command and verifies every admission signature on replay. Every malformed +**newline-terminated** record is corruption, including a bad hash on the final record. +It refuses 5 without modifying the file; it never rolls back a complete acknowledged +settlement as a torn tail. Missing/invalid admission signatures also refuse, even when +the hash chain is otherwise valid. Only an unterminated final line is recoverable: +truncate those incomplete bytes, fsync, then append unsigned internal `recover N SHA`. +This internal recovery cannot mint, debit or pay credits. + +Version-1 journals are refused without modification, not automatically upgraded. There is no +implicit migration: archive the old journal, explicitly reconcile its test credits outside this +CLI, provision a **new unique ledger identity** and authorize fresh funding under the new policy. +This does not confer signatures or economic qualification on historical unsigned receipts. +Changing pins requires a new ledger identity and explicit reconciliation, not editing a running +journal's config. + +Every successful mutation acknowledgement, including `dup` and `already-*`, follows a +journal fsync and directory fsync. A failed append fsync attempts to restore the last +good length and sync that rollback, then returns 3 without acknowledgement. Rollback +itself can fail, so an I/O refusal is not proof that an operation is absent. A retry +must verify replayed authority/state and cross a fresh durability barrier before it +can acknowledge an existing record. Callers reconcile the job's actual phase; they +must not blindly refund an already-settled job. + +## Key-table capacity cannot trap existing escrow + +Accounts, prefund IDs and jobs share a bounded table. Before appending, a new +prefund checks its new PID plus the requester account only if missing. A new +reservation checks its job plus any missing provider/verifier accounts; the +requester must already exist. The pinned role names are distinct. An operation +that would exceed the table refuses with exit 14 and leaves the journal unchanged. +An identical authorized retry needs no new key and still succeeds at capacity. + +Settlement and refund use only the job and account slots created by its +reservation. They never allocate a key, so both remain available with a completely +full table. There is deliberately no shared “four spare slots” append guard. + +## Tests and evidence limits + +The gate retains the arithmetic oracle, exactly-once, lock/fsync, recovery, corruption and +conservation controls. It adds unsigned/wrong-key/mutated-record admission, exact policy/account +pins, independent verifier, evidence digest/quote/job binding, complete unauthorized tail refusal, +old-format refusal and a competing double-debit race. A deterministic strace injection kills the +process at stdout-write entry, after journal fsync and before acknowledgement; retry must pay +nothing twice. Separate mutants remove issuer/verifier/owner guards. `CRASH_N=200` also kills +actual ledger processes and retries signed commands, auditing after every interruption. +`MUTANT_CRASH_N=0` can omit redundant crash trials on mutants, not on the honest binary. + +`TUR_LEDGER_AUTH_ONLY=/path/to/binary` runs the unsigned-prefund regression against another binary, +so the same assertion can be shown failing against the pre-fix source and passing after the fix. + +The suite also fills a ten-slot build of the same native ledger, checks clean +prefund/reserve refusal, settles one existing job and refunds another, and checks +once-only retries and conservation. Only `KCAP` changes for this fast boundary +fixture; record parsing, signature verification, replay and append are unchanged. +`TUR_LEDGER_CAPACITY_SOURCE=/path/to/source.om` runs just this regression, allowing +the same test to fail before the fix and pass after it. The `capacity-lockup` +mutant restores the blanket append guard and must be killed. Separate evidence +records exercise the production 65,536-slot binary with a full signed journal. + +`TUR_LEDGER_AUDIT_SOURCE=/path/to/source.om` runs the independent-audit regressions: +repeated injected fsync failure and rollback size, synchronized duplicate replies +for all four operations, acknowledged final-record corruption, fused argv fields, +and reserve retries after either terminal phase. The corresponding five guard +mutants (rollback, duplicate sync, complete-tail recovery, argv and phase) must die. + +HOST_TESTED means local CLI behavior only. No Core ledger RPC exists in this checkout, so lost +CLI output is not an interrupted-RPC qualification. Mutating a signed AN0V digest tests admission +binding; it does not exercise an external signer's AN0V parser. No hardware, deployment, public +participant or economic-authority qualification is claimed. Historical evidence remains under +`evidence/aienet0-tur-ledger-20261027/`; the authentication addendum records the new runs separately. diff --git a/om/tur-ledger/check.sh b/om/tur-ledger/check.sh index ebfb0965..98ca2293 100755 --- a/om/tur-ledger/check.sh +++ b/om/tur-ledger/check.sh @@ -3,7 +3,7 @@ # suite against it (must PASS), then builds each mutant and runs the same suite (each must FAIL). # Usage: OMC=/path/to/seed/out/omc bash om/tur-ledger/check.sh (OMEGA_OMC is accepted too) # Env: TUR_LEDGER_OUT=path copies the built binary; CRASH_N (200), MUTANT_CRASH_N, CRASH_SEED (7). -# Needs: sha256sum, strace, flock(1), timeout(1). Host only; no network, no GPU. +# Needs: sha256sum, OpenSSL 3, strace (syscall injection), flock(1), timeout(1). Host only; no network, no GPU. set -u here=$(cd "$(dirname "$0")" && pwd) root=$(cd "$here/../.." && pwd) @@ -11,11 +11,19 @@ src="$here/tur-ledger.om" sha="$root/om/vendor/sha256.om" OMC=${OMC:-${OMEGA_OMC:-}} : "${OMC:?set OMC to the seed compiler (omega-mv seed/out/omc)}" -PIN=2c82480596bbdc50cda9626866209ef662d5834f278f839ff4ce0250c495029f +PIN=d6290c7663c2b4bafb59eb3fdf812476e977f4c144def71095c6248ef9b96b84 got=$(sha256sum < "$OMC" | cut -d' ' -f1) [ "$got" = "$PIN" ] || { echo "FAIL omc sha256 $got, pinned $PIN"; exit 1; } CRASH_N=${CRASH_N:-200} -b=$(mktemp -d); trap 'rm -rf "$b"' EXIT +b=$(mktemp -d); keys=$(mktemp -d /dev/shm/tur-ledger-test-keys.XXXXXX) +trap 'rm -rf "$b" "$keys"' EXIT +umask 077 +# Disposable test-only oracle keys, never production credentials or implementation dependencies. +for role in issuer verifier stranger; do + openssl genpkey -algorithm EC -pkeyopt ec_paramgen_curve:P-256 -out "$keys/$role" || exit 1 +done +pubhex() { openssl pkey -in "$keys/$1" -pubout -outform DER 2>/dev/null | od -An -v -tx1 | tr -d ' \n' | cut -c53-; } +issuer=$(pubhex issuer); verifier=$(pubhex verifier) zero=$(printf '0%.0s' $(seq 64)) hexn() { printf '%064x' "$1"; } @@ -23,17 +31,55 @@ J7=$(printf '7%.0s' $(seq 64)); J8=$(printf '8%.0s' $(seq 64)) RA=$(printf 'a%.0s' $(seq 64)); RB=$(printf 'b%.0s' $(seq 64)) build() { # out source - cat "$sha" "$2" | "$OMC" > "$1" 2> "$1.err" || { echo "compile: $(cat "$1.err")"; return 1; } + { printf 'om2\n'; cat "$sha" "$root/om/vendor/ec.om" "$2"; } | "$OMC" > "$1" 2> "$1.err" || { echo "compile: $(cat "$1.err")"; return 1; } chmod 700 "$1" } +# Trusted provisioning and signing are TEST ORACLES. The ledger never signs and never creates pins. +provision() { + local d=$1 req=req + [ "$d" = "$b/pf" ] && req=acct + mkdir -p "$d" + [ -f "$d/authority" ] || printf 'genesis tur-ledger-2 %s %s %s %s %s prov ver %s %s %s' "$zero" "$issuer" "$verifier" "$RA" "$req" "$RA" "$RB" "$J7" > "$d/authority" +} +canonical() { # config, unsigned body, optional reservation authorization digest + cat "$1/authority"; printf '\n%s\n' "$2" + [ -z "${3:-}" ] || printf '%s\n' "$3" +} +reservehash() { + local d=$1 job=$2 line rec + [ -f "$d/journal" ] || return 0 + line=$(grep " reserve $job " "$d/journal" | head -n 1) + [ -n "$line" ] || return 0 + rec=${line#* }; rec=${rec#* }; rec=${rec% *}; rec=${rec% *} + canonical "$d" "$rec" | sha256sum | cut -c1-64 +} +sign() { # key, dir, unsigned body, reserve digest + canonical "$2" "$3" "${4:-}" | openssl dgst -sha256 -sign "$keys/$1" | od -An -v -tx1 | tr -d ' \n' +} +prepare() { # d original-command... -> signed argv + local d=$1; shift; provision "$d" + argv=("$@") + local rh= body isig vsig + case "$1" in + prefund) ;; + reserve) argv+=("$RA") ;; + settle) [ "$#" = 6 ] || return 0; argv+=("$J7" "$RB"); rh=$(reservehash "$d" "$2") ;; + refund) rh=$(reservehash "$d" "$2") ;; + *) return 0 ;; + esac + body="${argv[*]}"; isig=$(sign issuer "$d" "$body" "$rh"); argv+=("$isig") + if [ "$1" = settle ]; then vsig=$(sign verifier "$d" "$body" "$rh"); argv+=("$vsig"); fi +} +invoke() { local d=$1; shift; prepare "$d" "$@"; "$T" --journal "$d" "${argv[@]}"; } + # ---- suite: every test prints PASS/FAIL; T is the binary, f counts failures ---- f=0 ok() { echo "PASS $1"; } no() { echo "FAIL $1: $2"; f=$((f + 1)); } x() { # dir args... -> sets o (stdout) e (stderr) r (rc) local d=$1; shift - o=$("$T" --journal "$d" "$@" 2> "$b/err"); r=$?; e=$(cat "$b/err") + o=$(invoke "$d" "$@" 2> "$b/err"); r=$?; e=$(cat "$b/err") } want() { # name rc stdout dir args... local n=$1 wr=$2 wo=$3; shift 3 @@ -90,7 +136,7 @@ t_prefund() { want prefund.first 0 "prefunded p1 acct 5" "$d" prefund p1 acct 5 want prefund.dup 0 "dup p1 acct 5" "$d" prefund p1 acct 5 want prefund.conflict-amount 13 "" "$d" prefund p1 acct 6 - want prefund.conflict-account 13 "" "$d" prefund p1 other 5 + want prefund.conflict-account 16 "" "$d" prefund p1 other 5 want prefund.balance 0 "balance acct 5" "$d" balance acct want usage.bad-job 2 "" "$d" reserve "$(printf 'A%.0s' $(seq 64))" acct p v 1 want usage.leading-zero 2 "" "$d" prefund p2 acct 05 @@ -118,7 +164,8 @@ t_concurrent() { # 20 concurrent settle processes: exactly one settlement rm -rf "$d"; x "$d" prefund p1 req 50; x "$d" reserve "$J7" req prov ver 20 for i in $(seq 1 20); do if [ $mode = distinct ]; then rc=$(hexn "$i"); else rc=$RA; fi - ( "$T" --journal "$d" settle "$J7" "$rc" 15 4 1 > "$b/c.$i.out" 2>/dev/null; echo $? > "$b/c.$i.rc" ) & + prepare "$d" settle "$J7" "$rc" 15 4 1 + ( "$T" --journal "$d" "${argv[@]}" > "$b/c.$i.out" 2>/dev/null; echo $? > "$b/c.$i.rc" ) & done wait n0=$(cat "$b"/c.*.rc | grep -cx 0); n11=$(cat "$b"/c.*.rc | grep -cx 11) @@ -132,11 +179,14 @@ t_concurrent() { # 20 concurrent settle processes: exactly one settlement if [ $c = 0 ] && [ "$(nsettle "$J7" "$d")" = 1 ] && [ "$ar" = 0 ]; then ok "concurrent.settle-$mode (settled $nst, already $nalr, refused $n11)"; else no "concurrent.settle-$mode" "exit0 $n0 refused11 $n11 settled $nst already $nalr journal-settles $(nsettle "$J7" "$d") audit $ar"; fi rm -f "$b"/c.* done - rm -rf "$d"; x "$d" prefund p1 req 50 - for i in $(seq 1 20); do ( "$T" --journal "$d" reserve "$(hexn "$i")" req prov ver 1 > /dev/null 2>&1; echo $? > "$b/c.$i.rc" ) & done + rm -rf "$d"; x "$d" prefund p1 req 1 + for i in $(seq 1 20); do + prepare "$d" reserve "$(hexn "$i")" req prov ver 1 + ( "$T" --journal "$d" "${argv[@]}" > /dev/null 2>&1; echo $? > "$b/c.$i.rc" ) & + done wait - n0=$(cat "$b"/c.*.rc | grep -cx 0); x "$d" audit - case "$r $o" in "0 audit ok records 22 "*" jobs 20 open 20 "*) ok "concurrent.reserve-20 ($n0 reserved, no lost update)" ;; *) no concurrent.reserve-20 "exit0 $n0 audit $r '$o'" ;; esac + n0=$(cat "$b"/c.*.rc | grep -cx 0); n7=$(cat "$b"/c.*.rc | grep -cx 7); x "$d" audit + case "$r $o $n0 $n7" in "0 audit ok records 3 "*" jobs 1 open 1 "*" 1 19") ok "concurrent.double-debit (one reserve, nineteen insufficient-funds)" ;; *) no concurrent.double-debit "exit0 $n0 exit7 $n7 audit $r '$o'" ;; esac rm -f "$b"/c.* } @@ -152,7 +202,8 @@ t_lock() { # the whole command waits for flock(LOCK_EX) on the journal t_fsync() { # the record is pwritten and fsynced before the reply reaches stdout local d=$b/fs; rm -rf "$d"; x "$d" prefund p1 req 5 - strace -f -qq -e trace=pwrite64,fsync,write -o "$b/st" "$T" --journal "$d" reserve "$J7" req prov ver 1 > /dev/null 2>&1 || true + prepare "$d" reserve "$J7" req prov ver 1 + strace -f -qq -e trace=pwrite64,fsync,write -o "$b/st" "$T" --journal "$d" "${argv[@]}" > /dev/null 2>&1 || true # order of the journal pwrite, the fsync of the same fd, and the reply on fd 1 local wl fl ol fd wl=$(grep -n 'pwrite64(' "$b/st" | tail -n 1); fd=$(printf '%s' "$wl" | sed -n 's/.*pwrite64(\([0-9]*\),.*/\1/p'); wl=${wl%%:*} @@ -169,8 +220,9 @@ t_crash() { # kill -9 at random points over CRASH_N reserve/settle commands, ret for i in $(seq 1 "$CRASH_N"); do j=$(( (i + 1) / 2 )) if [ $((i % 2)) = 1 ]; then op="reserve $(hexn "$j") req prov ver 10"; else op="settle $(hexn "$j") $(hexn $((j + 4096))) 6 3 1"; fi - "$T" --journal "$k" $op > /dev/null 2>&1 || badretry=$((badretry + 1)) - "$T" --journal "$c" $op > /dev/null 2>&1 & p=$! + invoke "$k" $op > /dev/null 2>&1 || badretry=$((badretry + 1)) + prepare "$c" $op + "$T" --journal "$c" "${argv[@]}" > /dev/null 2>&1 & p=$! sleep "0.00$((RANDOM % 8))$((RANDOM % 10))" kill -9 $p 2> /dev/null; { wait $p; } 2> /dev/null; rc0=$? if [ "$rc0" = 137 ]; then killed=$((killed + 1)); else done0=$((done0 + 1)); fi @@ -202,13 +254,12 @@ t_torn() { # a torn last line is truncated and recorded; the records before it s local n; n=$(( $(stat -c %s "$d/journal") - $(stat -c %s "$b/torn.good") )) x "$d" balance req if [ "$r" = 0 ] && [ "$o" = "$before" ] && [ "$e" = "recovered torn-tail $n bytes sha256 $want" ] && cmp -s "$b/torn.good" <(head -c "$(stat -c %s "$b/torn.good")" "$d/journal") && tail -n 1 "$d/journal" | grep -q " recover $n $want " && chaincheck "$d/journal"; then ok "torn.unterminated ($e)"; else no torn.unterminated "exit $r out '$o' err '$e'"; fi - # a complete last line whose HASH is wrong - cp "$d/journal" "$b/torn.good2" + # A newline-terminated bad record is corruption, never an automatic rollback. local last; last=$(tail -n 1 "$d/journal" | cut -d' ' -f1); local lh; lh=$(tail -n 1 "$d/journal"); lh=${lh##* } printf '%s %s refund %s %s\n' $((last + 1)) "$lh" "$J7" "$zero" >> "$d/journal" - x "$d" show "$J7" - if [ "$r" = 0 ] && [ "$o" = "job $J7 reserved req prov ver 4" ] && [ "${e#recovered torn-tail }" != "$e" ] && chaincheck "$d/journal" && cmp -s "$b/torn.good2" <(head -c "$(stat -c %s "$b/torn.good2")" "$d/journal"); then ok "torn.bad-hash-last-line ($e)"; else no torn.bad-hash-last-line "exit $r out '$o' err '$e'"; fi - # the last record cut short (no newline): the whole partial line is the torn tail + cp "$d/journal" "$b/torn.bad" + raw_want corrupt.terminated-bad-hash 5 "$d" show "$J7" + # The same final record cut short without its newline is an incomplete tail. local s keep; s=$(stat -c %s "$d/journal"); keep=$(head -n -1 "$d/journal" | wc -c) truncate -s $((s - 10)) "$d/journal" x "$d" audit @@ -227,30 +278,260 @@ t_corrupt() { # a bad line before the last refuses the ledger and changes nothin want corrupt.line-deleted 5 "" "$d" audit { sed -n 1p "$b/cor.good"; sed -n 3p "$b/cor.good"; sed -n 2p "$b/cor.good"; } > "$d/journal" want corrupt.lines-swapped 5 "" "$d" audit - cp "$b/cor.good" "$d/journal"; sed -i '1s/genesis tur-ledger-1/genesis tur-ledger-2/' "$d/journal" + cp "$b/cor.good" "$d/journal"; sed -i '1s/genesis tur-ledger-2/genesis tur-ledger-1/' "$d/journal" want corrupt.genesis-edited 5 "" "$d" audit } -t_conserve() { # a journal with a valid chain whose settle pays out more than its escrow is refused - local d=$b/cons; rm -rf "$d"; mkdir -p "$d" - printf '%s\n' "genesis tur-ledger-1" "prefund p1 req 100" "reserve $J7 req prov ver 40" "settle $J7 $RA 27 3 10" | forge "$d/journal" - want conserve.forged-valid-control 0 "balance prov 27" "$d" balance prov - printf '%s\n' "genesis tur-ledger-1" "prefund p1 req 100" "reserve $J7 req prov ver 40" "settle $J7 $RA 30 30 10" | forge "$d/journal" - if chaincheck "$d/journal"; then ok conserve.forged-chain-valid; else no conserve.forged-chain-valid "forge broke the chain"; fi +t_conserve() { # valid signatures do not bypass escrow/conservation rules, including replay + local d=$b/cons; rm -rf "$d"; provision "$d" + x "$d" prefund p1 req 100; x "$d" reserve "$J7" req prov ver 40 + cp "$d/journal" "$b/cons.before" + prepare "$d" settle "$J7" "$RA" 30 30 10 + local rec="${argv[*]}" prev n body h + prev=$(tail -n 1 "$d/journal"); prev=${prev##* }; n=4 + body="$n $prev $rec"; h=$(printf '%s' "$body" | sha256sum | cut -c1-64) + printf '%s %s\n' "$body" "$h" >> "$d/journal" + if chaincheck "$d/journal"; then ok conserve.forged-chain-valid; else no conserve.forged-chain-valid "forge broke chain"; fi want conserve.payout-over-escrow 6 "" "$d" audit want conserve.refused-for-every-command 6 "" "$d" balance prov } +raw_want() { # name rc d exact args (no oracle signing) + local name=$1 expected=$2 d=$3; shift 3 + local before after rr + before=$(sha256sum "$d/journal" 2>/dev/null || true) + "$T" --journal "$d" "$@" > "$b/raw.out" 2> "$b/raw.err"; rr=$? + after=$(sha256sum "$d/journal" 2>/dev/null || true) + if [ "$rr" = "$expected" ] && [ "$before" = "$after" ]; then ok "$name (exit $rr, unchanged journal)"; else no "$name" "exit $rr expected $expected, before '$before' after '$after'"; fi +} +t_unsigned() { + local d=$b/unsigned; rm -rf "$d"; provision "$d" + "$T" --journal "$d" audit > /dev/null 2>&1 + raw_want auth.unsigned-prefund 2 "$d" prefund forged req 100 +} +t_auth() { + local d=$b/auth body rh sig + t_unsigned + rm -rf "$d"; x "$d" prefund p1 req 100; x "$d" reserve "$J7" req prov ver 40 + raw_want auth.unsigned-reserve 2 "$d" reserve "$J8" req prov ver 5 "$RA" + raw_want auth.unsigned-settle 2 "$d" settle "$J7" "$RA" 27 3 10 "$J7" "$RB" + raw_want auth.unsigned-refund 2 "$d" refund "$J7" + prepare "$d" prefund p2 req 5 + body="prefund p2 req 5"; argv[4]=$(sign stranger "$d" "$body") + raw_want auth.wrong-issuer-key 16 "$d" "${argv[@]}" + prepare "$d" prefund p2 req 5; argv[3]=6 + raw_want auth.changed-amount 16 "$d" "${argv[@]}" + prepare "$d" reserve "$J8" req prov ver 5; argv[6]=$RB + raw_want auth.changed-quote 16 "$d" "${argv[@]}" + prepare "$d" reserve "$J8" req thief ver 5 + raw_want auth.account-spoof 16 "$d" "${argv[@]}" + prepare "$d" settle "$J7" "$RA" 27 3 10 + body="${argv[*]:0:8}"; rh=$(reservehash "$d" "$J7") + argv[9]=$(sign stranger "$d" "$body" "$rh") + raw_want auth.wrong-verifier-key 16 "$d" "${argv[@]}" + prepare "$d" settle "$J7" "$RA" 27 3 10 + argv[8]=$(sign stranger "$d" "$body" "$rh") + raw_want auth.unauthorized-settle 16 "$d" "${argv[@]}" + prepare "$d" settle "$J7" "$RA" 27 3 10; argv[1]=$J8 + raw_want auth.changed-job 16 "$d" "${argv[@]}" + prepare "$d" settle "$J7" "$RA" 27 3 10; argv[2]=$RB + raw_want auth.forged-receipt-hash 16 "$d" "${argv[@]}" + prepare "$d" settle "$J7" "$RA" 27 3 10; argv[7]=$RA + raw_want auth.mutated-attestation-digest 16 "$d" "${argv[@]}" + prepare "$d" settle "$J7" "$RA" 27 3 10; argv[6]=$RB + raw_want auth.mutated-signed-job-digest 16 "$d" "${argv[@]}" + prepare "$d" settle "$J7" "$RA" 27 3 10; argv[9]="${argv[8]}" + raw_want auth.issuer-is-not-verifier 16 "$d" "${argv[@]}" + # SIGKILL at stdout write entry is after journal pwrite + fsync and before acknowledgement. + prepare "$d" settle "$J7" "$RA" 27 3 10 + strace -qq -e trace=pwrite64,fsync,write -e inject=write:signal=SIGKILL -o "$b/kill-after-fsync" "$T" --journal "$d" "${argv[@]}" > /dev/null 2>&1 + local killed=$? + if [ "$killed" = 137 ] && grep -q 'fsync(.*) *= 0' "$b/kill-after-fsync"; then ok auth.kill-after-fsync-before-ack; else no auth.kill-after-fsync-before-ack "exit $killed, missing fsync"; fi + want auth.lost-response-retry 0 "already-settled $J7 $RA 27 3 10" "$d" settle "$J7" "$RA" 27 3 10 + want auth.honest-provider 0 "balance prov 27" "$d" balance prov + prepare "$d" settle "$J7" "$RA" 27 3 10 + body="settle $J7 $RA 27 3 10 $J7 $RA" + argv[7]=$RA; argv[8]=$(sign issuer "$d" "$body" "$rh"); argv[9]=$(sign verifier "$d" "$body" "$rh") + raw_want auth.changed-evidence-conflicts-even-when-signed 11 "$d" "${argv[@]}" + cp "$d/journal" "$b/auth.good" + { cat "$d/authority"; printf '\nprefund forged req 100\n'; } | forge "$d/journal" + raw_want auth.unsigned-replay-last 5 "$d" audit + prepare "$d" prefund p2 req 5; argv[4]=$(sign stranger "$d" "prefund p2 req 5") + { cat "$d/authority"; printf '\n%s\n' "${argv[*]}"; } | forge "$d/journal" + raw_want auth.wrong-key-replay-last 5 "$d" audit + printf 'genesis tur-ledger-1\nprefund p1 req 100\n' | forge "$d/journal" + raw_want auth.old-journal-refused 5 "$d" audit + cp "$b/auth.good" "$d/journal" + local authority; authority=$(cat "$d/authority") + printf '%s' "${authority/$RA/$J8}" > "$d/authority" + raw_want auth.changed-policy-pins 5 "$d" audit +} + +# Exercise the production allocator/record path with a small, completely full +# key table. Only KCAP changes; crypto, replay, accounting and append are intact. +t_capacity() { + local source=$1 d=$b/capacity T=$b/capacity-ledger id + sed 's/^const KCAP ulong 65536$/const KCAP ulong 10/' "$source" > "$b/capacity.om" + if ! build "$T" "$b/capacity.om"; then no capacity.build "compile failed"; return; fi + echo "capacity-source $(sha256sum "$source" | cut -c1-64) KCAP=10" + echo "capacity-bin $(sha256sum "$T" | cut -c1-64)" + rm -rf "$d" + want capacity.prefund 0 "prefunded p1 req 100" "$d" prefund p1 req 100 + want capacity.reserve-settle 0 "reserved $J7 req prov ver 40" "$d" reserve "$J7" req prov ver 40 + want capacity.reserve-refund 0 "reserved $J8 req prov ver 40" "$d" reserve "$J8" req prov ver 40 + # Three accounts, two jobs and five prefund IDs occupy all ten slots. + for id in p2 p3 p4 p5; do + want "capacity.fill-$id" 0 "prefunded $id req 1" "$d" prefund "$id" req 1 + done + prepare "$d" prefund overflow req 1 + raw_want capacity.new-prefund-refused 14 "$d" "${argv[@]}" + prepare "$d" reserve "$RB" req prov ver 1 + raw_want capacity.new-reserve-refused 14 "$d" "${argv[@]}" + want capacity.settle 0 "settled $J7 $RA 27 3 10" "$d" settle "$J7" "$RA" 27 3 10 + want capacity.refund 0 "refunded $J8" "$d" refund "$J8" + prepare "$d" settle "$J7" "$RA" 27 3 10 + raw_want capacity.settle-repeat 0 "$d" "${argv[@]}" + prepare "$d" refund "$J8" + raw_want capacity.refund-repeat 0 "$d" "${argv[@]}" + want capacity.provider 0 "balance prov 27" "$d" balance prov + want capacity.verifier 0 "balance ver 3" "$d" balance ver + x "$d" audit + if [ "$r" = 0 ] && [[ "$o" = *" open 0 settled 1 refunded 1 "* ]]; then + ok capacity.audit-closed + else no capacity.audit-closed "exit $r out '$o'"; fi + d=$b/capacity-partial + rm -rf "$d" + want capacity.partial-prefund 0 "prefunded p1 req 100" "$d" prefund p1 req 100 + for id in p2 p3 p4 p5 p6 p7 p8; do + want "capacity.partial-fill-$id" 0 "prefunded $id req 1" "$d" prefund "$id" req 1 + done + # Only one slot remains, but a first reservation needs a job and two role accounts. + prepare "$d" reserve "$J7" req prov ver 40 + raw_want capacity.partial-reserve-refused 14 "$d" "${argv[@]}" + want capacity.last-slot-prefund 0 "prefunded p9 req 1" "$d" prefund p9 req 1 + prepare "$d" prefund overflow req 1 + raw_want capacity.partial-full-prefund-refused 14 "$d" "${argv[@]}" +} + +t_audit_io() { + local d=$b/audit-io attempt before before_size rr jfd fl ol + rm -rf "$d"; x "$d" prefund base req 100 + before=$(sha256sum "$d/journal") + before_size=$(stat -c %s "$d/journal") + prepare "$d" prefund unsynced req 5 + for attempt in 1 2; do + strace -qq -e trace=pwrite64,fsync,ftruncate,write -e inject=fsync:error=EIO -o "$b/io.$attempt.trace" "$T" --journal "$d" "${argv[@]}" > "$b/io.out" 2> "$b/io.err"; rr=$? + if [ "$rr" = 3 ] && [ ! -s "$b/io.out" ] && [ "$(sha256sum "$d/journal")" = "$before" ] && [ "$(stat -c %s "$d/journal")" = "$before_size" ]; then + ok "io.failed-sync-rollback-$attempt (exit 3, original journal, size $before_size)" + else no "io.failed-sync-rollback-$attempt" "exit $rr out '$(cat "$b/io.out")', journal restored $([ "$(sha256sum "$d/journal")" = "$before" ] && echo yes || echo no)"; fi + done + x "$d" audit + if [ "$r" = 0 ] && [ -z "$e" ]; then ok io.no-torn-tail-after-rollback; else no io.no-torn-tail-after-rollback "exit $r err '$e'"; fi + prepare "$d" prefund unsynced req 5 + strace -qq -e trace=pwrite64,fsync,write -o "$b/io.retry.trace" "$T" --journal "$d" "${argv[@]}" > "$b/io.out" 2> "$b/io.err"; rr=$? + if [ "$rr" = 0 ] && [ "$(cat "$b/io.out")" = 'prefunded unsynced req 5' ] && grep -q 'fsync(.*) *= 0' "$b/io.retry.trace"; then + ok io.retry-writes-and-syncs + else no io.retry-writes-and-syncs "exit $rr out '$(cat "$b/io.out")'"; fi + # Each duplicate acknowledgement must cross a fresh durability barrier too. + local op + for op in prefund reserve settle refund; do + case $op in + prefund) prepare "$d" prefund base req 100 ;; + reserve) x "$d" reserve "$J7" req prov ver 40; prepare "$d" reserve "$J7" req prov ver 40 ;; + settle) x "$d" settle "$J7" "$RA" 27 3 10; prepare "$d" settle "$J7" "$RA" 27 3 10 ;; + refund) x "$d" reserve "$J8" req prov ver 40; x "$d" refund "$J8"; prepare "$d" refund "$J8" ;; + esac + before=$(sha256sum "$d/journal") + strace -qq -e trace=openat,pwrite64,fsync,write -e inject=fsync:error=EIO -o "$b/dup.$op.trace" "$T" --journal "$d" "${argv[@]}" > "$b/io.out" 2> "$b/io.err"; rr=$? + jfd=$(sed -n 's/.*openat(.*\/journal",.*) *= \([0-9][0-9]*\)$/\1/p' "$b/dup.$op.trace" | head -n 1) + if [ "$rr" = 3 ] && [ ! -s "$b/io.out" ] && [ "$(sha256sum "$d/journal")" = "$before" ] && [ -n "$jfd" ] && grep -q "fsync($jfd) *= -1 EIO" "$b/dup.$op.trace"; then + ok "io.duplicate-$op-needs-sync" + else no "io.duplicate-$op-needs-sync" "exit $rr out '$(cat "$b/io.out")'"; fi + strace -qq -e trace=openat,pwrite64,fsync,write -o "$b/dup.$op.retry.trace" "$T" --journal "$d" "${argv[@]}" > "$b/io.out" 2> "$b/io.err"; rr=$? + jfd=$(sed -n 's/.*openat(.*\/journal",.*) *= \([0-9][0-9]*\)$/\1/p' "$b/dup.$op.retry.trace" | head -n 1) + fl=$(grep -n "fsync($jfd) *= 0" "$b/dup.$op.retry.trace" | tail -n 1); fl=${fl%%:*} + ol=$(grep -n 'write(1, "' "$b/dup.$op.retry.trace" | head -n 1); ol=${ol%%:*} + if [ "$rr" = 0 ] && [ -n "$jfd" ] && [ -n "$fl" ] && [ -n "$ol" ] && [ "$fl" -lt "$ol" ] && [ "$(sha256sum "$d/journal")" = "$before" ]; then + ok "io.duplicate-$op-retry-synced" + else no "io.duplicate-$op-retry-synced" "exit $rr, missing fsync or changed journal"; fi + done +} + +t_audit_corrupt() { + local d=$b/audit-tail line body hash first + rm -rf "$d"; x "$d" prefund base req 100; x "$d" reserve "$J7" req prov ver 40 + want corrupt.acknowledged-settle 0 "settled $J7 $RA 27 3 10" "$d" settle "$J7" "$RA" 27 3 10 + cp "$d/journal" "$b/audit-tail.good" + sed '$s/ 27 3 10 / 28 3 10 /' "$b/audit-tail.good" > "$d/journal" + cp "$d/journal" "$b/audit-tail.bad" + raw_want corrupt.acknowledged-tail-audit 5 "$d" audit + cp "$b/audit-tail.bad" "$d/journal" + prepare "$d" refund "$J7" + raw_want corrupt.acknowledged-tail-refund 5 "$d" "${argv[@]}" + cp "$b/audit-tail.bad" "$d/journal" + raw_want corrupt.acknowledged-tail-show 5 "$d" show "$J7" + # Keep body/signatures valid but damage only the final chain hash. + line=$(tail -n 1 "$b/audit-tail.good"); body=${line% *}; hash=${line##* } + first=0; [ "${hash:0:1}" = 0 ] && first=1 + { head -n -1 "$b/audit-tail.good"; printf '%s %s%s\n' "$body" "$first" "${hash:1}"; } > "$d/journal" + raw_want corrupt.signed-tail-bad-hash 5 "$d" audit + cp "$b/audit-tail.good" "$d/journal" + want corrupt.original-settlement-preserved 0 "job $J7 settled req prov ver 40 $RA 27 3 10" "$d" show "$J7" +} + +t_audit_argv_phase() { + local d=$b/audit-argv + rm -rf "$d"; x "$d" prefund base req 100 + prepare "$d" prefund p2 req 5 + raw_want usage.fused-name-arguments 2 "$d" prefund 'p2 req' 5 "${argv[4]}" + prepare "$d" prefund p3 req 5 + raw_want usage.fused-command-argument 2 "$d" 'prefund p3' req 5 "${argv[4]}" + prepare "$d" reserve "$J7" req prov ver 40 + raw_want usage.fused-role-arguments 2 "$d" reserve "$J7" 'req prov' ver 40 "$RA" "${argv[7]}" + d=$b/audit-phase + rm -rf "$d"; x "$d" prefund base req 100 + want phase.reserve 0 "reserved $J7 req prov ver 40" "$d" reserve "$J7" req prov ver 40 + want phase.reserve-open-retry 0 "already-reserved $J7 req prov ver 40" "$d" reserve "$J7" req prov ver 40 + x "$d" settle "$J7" "$RA" 27 3 10 + prepare "$d" reserve "$J7" req prov ver 40 + raw_want phase.reserve-after-settle 10 "$d" "${argv[@]}" + x "$d" reserve "$J8" req prov ver 40; x "$d" refund "$J8" + prepare "$d" reserve "$J8" req prov ver 40 + raw_want phase.reserve-after-refund 10 "$d" "${argv[@]}" +} + +t_audit() { t_audit_io; t_audit_corrupt; t_audit_argv_phase; } + suite() { f=0 - t_oracle; t_prefund; t_once; t_concurrent; t_lock; t_fsync; t_torn; t_corrupt; t_conserve; t_crash + t_oracle; t_prefund; t_once; t_concurrent; t_lock; t_fsync; t_torn; t_corrupt; t_conserve; t_auth; t_audit; t_crash + t_capacity "${1:-$src}" [ "$f" = 0 ] } echo "omc $(sha256sum "$OMC" | cut -c1-64)" echo "src $(sha256sum "$src" | cut -c1-64) om/tur-ledger/tur-ledger.om" echo "sha $(sha256sum "$sha" | cut -c1-64) om/vendor/sha256.om" +echo "ec $(sha256sum "$root/om/vendor/ec.om" | cut -c1-64) omega-mv@6999fa9e6dae4847c155ef4eacaece74f491d3ca" +echo "gate $(sha256sum "$0" | cut -c1-64)" +openssl version gate=0 +if [ -n "${TUR_LEDGER_AUTH_ONLY:-}" ]; then + T=$TUR_LEDGER_AUTH_ONLY + t_unsigned + [ "$f" = 0 ]; exit $? +fi +if [ -n "${TUR_LEDGER_CAPACITY_SOURCE:-}" ]; then + t_capacity "$TUR_LEDGER_CAPACITY_SOURCE" + [ "$f" = 0 ]; exit $? +fi +if [ -n "${TUR_LEDGER_AUDIT_SOURCE:-}" ]; then + T=$b/audit-ledger + build "$T" "$TUR_LEDGER_AUDIT_SOURCE" || exit 1 + echo "audit-source $(sha256sum "$TUR_LEDGER_AUDIT_SOURCE" | cut -c1-64)" + t_audit + [ "$f" = 0 ]; exit $? +fi T=$b/tur-ledger if build "$T" "$src"; then echo "bin $(sha256sum "$T" | cut -c1-64)" @@ -266,7 +547,7 @@ mutant() { # name sed-expression: the suite must fail against the mutant if cmp -s "$src" "$m"; then echo "FAIL mutant $1: mutation did not apply"; gate=1; return; fi T=$b/$1 if ! build "$T" "$m" > "$b/$1.build"; then echo "FAIL mutant $1: $(cat "$b/$1.build")"; gate=1; return; fi - suite > "$b/$1.log" 2>&1 + suite "$m" > "$b/$1.log" 2>&1 if [ "$f" != 0 ]; then echo "PASS mutant $1 killed ($f failing: $(grep '^FAIL' "$b/$1.log" | cut -d: -f1 | sed 's/^FAIL //' | tr '\n' ' '))"; else echo "FAIL mutant $1 survived"; gate=1; fi } CRASH_N=${MUTANT_CRASH_N:-$CRASH_N} @@ -276,7 +557,17 @@ mutant no-exactly-once '/^if eq sph 2$/,/^end$/d' mutant no-hash-chain '/^if not hsame h$/,/^end$/d;/^if not psame$/,/^end$/d' mutant no-conservation '/^if not conserve$/,/^end$/d' mutant no-escrow-rule '/^ret vrule get d3 k pp pv bk$/s/.*/ret 0/' -mutant no-torn-recovery '/^if and eq c 1 eq e get st SFSZ$/s/.*/if eq e 0/' +mutant no-torn-recovery '/^tb = sub get st SFSZ get st SGOOD$/s/.*/tb = ulong 0/' +mutant no-issuer-signature '/^if not authsig add b fields 3$/,/^end$/d' +mutant no-verifier-signature '/^if not authsig add add b fields 1 4$/,/^end$/d' +mutant no-owner-pins '/^if not and cfeq 6 add b 2 and cfeq 7 add b 3 cfeq 8 add b 4$/,/^end$/d' +mutant capacity-lockup '/^if ne wrec 0$/i\if gt add get st SKEYS 4 KCAP\ndie 14\nend' +mutant no-slot-preflight '/^if gt add get st SKEYS needed KCAP$/,/^end$/d' +mutant no-sync-rollback '/^rollback fd off$/d' +mutant no-duplicate-sync '/^if ne fsync int get st SFD 0$/,/^end$/d' +mutant terminated-tail-recovery '/^fn rend e ulong to int$/,/^put st SOVF 0$/s/^ret 5$/if eq e get st SFSZ\nret 0\nend\nret 5/' +mutant argv-whitespace '/^if le c 32$/,/^end$/d' +mutant reserve-closed-phase '/^if ne get d4 sub j 1 1$/,/^end$/d' [ "$gate" = 0 ] && echo "TUR_LEDGER gate: PASS" || echo "TUR_LEDGER gate: FAIL" [ "$gate" = 0 ] diff --git a/om/tur-ledger/tur-ledger.om b/om/tur-ledger/tur-ledger.om index a3207c15..e5ef47ee 100644 --- a/om/tur-ledger/tur-ledger.om +++ b/om/tur-ledger/tur-ledger.om @@ -4,25 +4,26 @@ note at a time, settle exactly once per JOB. Arithmetic is tests/turing-network/ note applied per JOB: reserve moves AMOUNT from REQ into that JOB's escrow; settle pays PAYP to note PROV, PAYV to VER and BACK to REQ, refused unless PAYP <= escrow, PAYV <= escrow - PAYP and note BACK = escrow - PAYP - PAYV; a JOB is reserved once and settled or refunded once. -note Build: cat om/vendor/sha256.om om/tur-ledger/tur-ledger.om | omc > tur-ledger -note Usage: tur-ledger --journal DIR prefund PID ACCT AMOUNT | reserve JOB REQ PROV VER AMOUNT | -note settle JOB RECEIPT_SHA256 PAYP PAYV BACK | refund JOB | balance ACCT | show JOB | audit -note Journal DIR/journal, one record per line: SEQ PREV KIND FIELDS... HASH. SEQ counts from 1. -note PREV is the HASH of the line before (64 zeros for line 1). HASH is the sha256, lowercase hex, -note of the line's bytes before " HASH". Line 1 is "genesis tur-ledger-1". +note Build: check.sh composes om2, vendor/sha256.om, vendor/ec.om and this program for pinned omc. +note All external mutations require an issuer DER P-256/SHA-256 signature (hex final argument). +note Settle additionally requires the independent verifier signature; reserve adds QUOTE_SHA256; +note settle adds SIGNED_JOB_SHA256 AN0V_SHA256 before its two signatures. See README for canonical bytes. +note Journal DIR/journal: SEQ PREV KIND FIELDS... HASH. Genesis is the exact DIR/authority config. +note Version 2 refuses unsigned/version-1 journals. The hash chain is not an authorization mechanism. note Every command opens DIR/journal, takes flock LOCK_EX on it for the whole command and replays -note it: SEQ, PREV and HASH are checked on every line, then the record is applied. A LAST line that -note is unterminated, unparseable or whose HASH does not match its own bytes is a torn tail: it is -note truncated, fsynced, and a "recover N SHA" record (N torn bytes, SHA their sha256) is appended. -note A complete self-consistent line whose SEQ or PREV does not link (a deleted or reordered -note record), or any bad line before the last, is corruption and the ledger refuses (exit 5). +note it: SEQ, PREV and HASH are checked on every line, then the record is applied. Only an +note unterminated final line is a torn tail: it is truncated, fsynced, and a "recover N SHA" +note record (N torn bytes, SHA their sha256) is appended. Any malformed newline-terminated +note record is corruption (exit 5), including a damaged final acknowledged settlement. +note Failed append syncs are rolled back best-effort; every duplicate ack forces a fresh sync. note After replay the ledger checks conservation (exit 6): the sum note of balances plus open escrow equals the sum of prefunds, open escrow equals the open JOBs' note amounts, and every settled JOB paid out exactly its amount. A new record is written with note pwrite and fsynced before the command prints its result. note Exit: 0 ok (also dup / already-*), 2 usage, 3 journal io, 4 lock, 5 journal corrupt, note 6 conservation violated, 7 insufficient funds, 8 unknown job, 9 job conflict, 10 wrong phase, -note 11 settle receipt conflict, 12 escrow rule, 13 prefund id conflict, 14 capacity, 15 overflow. +note 11 settle receipt conflict, 12 escrow rule, 13 prefund id conflict, 14 capacity, 15 overflow, +note 16 missing config or unauthorized signer/policy. Missing signature arguments are usage (2). note Accounts, PIDs and JOBs: KCAP keys in all. A name is 1..64 bytes of [A-Za-z0-9._:-]; JOB and note RECEIPT_SHA256 are 64 lowercase hex bytes; amounts are decimal u64 without leading zeros. const KCAP ulong 65536 @@ -45,7 +46,6 @@ const SFD ulong 13 const SSLOT ulong 14 const SRF ulong 15 const SLONG ulong 16 -const STORN ulong 17 const SWB ulong 18 global st ulong 32 global ga uchar 8192 @@ -73,8 +73,221 @@ global d5 ulong 65536 global d6 ulong 65536 global d7 ulong 65536 global rc uchar 4194304 +note Authority config is provisioned externally; no private keys or automatic trust establishment. +global cfg uchar 1024 +global cfgn ulong 1 +global cfo ulong 12 +global cfl ulong 12 +global ah uchar 64 +global pa uchar 4194304 +global ja uchar 4194304 +global sa uchar 4194304 +text apath "/authority" +text auerr "refused 16 authorization\n" + +fn authdie to void +e = write 2 auerr 0 len auerr +exit 16 +end + +fn hexf i ulong n ulong to bool +if ne get fl i n +ret false +end +for j ulong n +c = get lb add get fo i j +if not or and ge c 48 le c 57 and ge c 97 le c 102 +ret false +end +end +ret true +end + +fn cfeq f ulong b ulong to bool +if ne get cfl f get fl b +ret false +end +for i ulong get cfl f +if ne get cfg add get cfo f i get lb add get fo b i +ret false +end +end +ret true +end + +note acfg reads one canonical genesis body, no LF. Fixed policy names bind account and node owners. +fn acfg to void +n = get gl 2 +if or eq n 0 gt n 4000 +die 2 +end +for i ulong n +put pb i get ga add get gs 2 i +end +for i ulong len apath +put pb add n i get apath i +end +fd = fopen pb 0 add n len apath 524288 0 +if lt fd 0 +authdie +end +k = read int fd lb 0 len lb +if or le k 0 ge k long len lb +authdie +end +z = read int fd pb 0 1 +cl = fclose int fd +if or ne z 0 ne cl 0 +authdie +end +if not split ulong k +authdie +end +if ne get st SNF 12 +authdie +end +if not and fis 0 22 fis 1 24 +authdie +end +if not and fhex 2 and hexf 3 130 and hexf 4 130 fhex 5 +authdie +end +if not and fname 6 and fname 7 fname 8 +authdie +end +if not and fhex 9 and fhex 10 fhex 11 +authdie +end +put cfgn 0 ulong k +for i ulong ulong k +put cfg i get lb i +end +for i ulong 12 +put cfo i get fo i +put cfl i get fl i +end +if cfeq 3 4 +authdie +end +if or cfeq 6 7 or cfeq 6 8 cfeq 7 8 +authdie +end +put st SLN 0 +end + +note ahash: SHA256(config || LF || canonical unsigned body || LF [|| reserve-auth-hash || LF]). +note Signatures and journal framing are excluded; operation identity is the semantic hash. +fn ahash b ulong sig ulong job bool to void +hreset +for i ulong get cfgn 0 +x = hpush get cfg i +end +x = hpush 10 +o = get fo b +for i ulong sub sub get fo sig 1 o +x = hpush get lb add o i +end +x = hpush 10 +if job +j = kfind 1 add b 1 +if ne j 0 +for i ulong 64 +x = hpush get ja add mul sub j 1 KW i +end +x = hpush 10 +end +end +y = hfinal +for i ulong 64 +put ah i get hd i +end +end + +fn authsig f ulong key ulong to bool +pub = new uchar 65 0 +sg = new uchar 104 0 +n = get fl f +if or lt n 16 gt n 144 +ret false +end +if ne rem n 2 0 +ret false +end +if not hexf f n +ret false +end +for i ulong 65 +o = add get cfo key mul i 2 +v = or shl hnibble get cfg o 4 hnibble get cfg add o 1 +put pub i uchar v +end +for i ulong 32 +o = mul i 2 +put sg i uchar or shl hnibble get ah o 4 hnibble get ah add o 1 +end +for i ulong div n 2 +o = add get fo f mul i 2 +v = shl hnibble get lb o 4 +v = or v hnibble get lb add o 1 +put sg add 32 i uchar v +end +sz = add 32 div n 2 +ret eq ecdsa_verify 256 pub part sg 0 sz 32 0 +end + +fn authrec b ulong fields ulong job bool dual bool to bool +need = add fields 1 +if dual +need = add need 1 +end +if ne get st SRF need +ret false +end +ahash b add b fields job +if not authsig add b fields 3 +ret false +end +if dual +if not authsig add add b fields 1 4 +ret false +end +end +ret true +end + +fn aeqhash mode ulong k ulong to bool +for i ulong 64 +o = add mul k KW i +v = get pa o +if eq mode 1 +v = get ja o +end +if eq mode 2 +v = get sa o +end +if ne v get ah i +ret false +end +end +ret true +end + +fn asave mode ulong k ulong to void +for i ulong 64 +o = add mul k KW i +if eq mode 0 +put pa o get ah i +end +if eq mode 1 +put ja o get ah i +end +if eq mode 2 +put sa o get ah i +end +end +end note tw: words, separated by ~ (byte 126). Word c - 1 is the reason for exit code c (2..15). -text tw "refused ~usage~journal-io~lock~journal-corrupt~conservation-violated~insufficient-funds~unknown-job~job-conflict~wrong-phase~settle-receipt-conflict~escrow-rule~prefund-id-conflict~capacity~overflow~prefund~reserve~settle~refund~balance~show~audit~genesis~recover~tur-ledger-1~prefunded~dup~reserved~already-reserved~settled~already-settled~refunded~already-refunded~job ~audit ok records ~ head ~ accounts ~ jobs ~ open ~ settled ~ refunded ~ prefunded ~ balances ~ escrow ~recovered torn-tail ~ bytes sha256 ~--journal~/journal~usage: tur-ledger --journal DIR prefund PID ACCT AMOUNT | reserve JOB REQ PROV VER AMOUNT | settle JOB RECEIPT_SHA256 PAYP PAYV BACK | refund JOB | balance ACCT | show JOB | audit~balance ~" +text tw "refused ~usage~journal-io~lock~journal-corrupt~conservation-violated~insufficient-funds~unknown-job~job-conflict~wrong-phase~settle-receipt-conflict~escrow-rule~prefund-id-conflict~capacity~overflow~prefund~reserve~settle~refund~balance~show~audit~genesis~recover~tur-ledger-2~prefunded~dup~reserved~already-reserved~settled~already-settled~refunded~already-refunded~job ~audit ok records ~ head ~ accounts ~ jobs ~ open ~ settled ~ refunded ~ prefunded ~ balances ~ escrow ~recovered torn-tail ~ bytes sha256 ~--journal~/journal~usage: tur-ledger --journal DIR COMMAND (see om/tur-ledger/README.md for signed v2 commands)~balance ~" text hx "0123456789abcdef" note fst: start of word k in tw; its length goes to st SFLEN. @@ -217,7 +430,11 @@ end fn lbarg i ulong to void s = get gs i for j ulong get gl i -lbput get ga add s j +c = get ga add s j +if le c 32 +die 2 +end +lbput c end end @@ -424,7 +641,7 @@ end note Record checks at field base b (the KIND). live is a command, not replay. Result: 0 apply, note 1 identical repeat (live only), else a refusal code. Replay refuses any nonzero result. fn vpre b ulong live bool to int -if ne get st SRF 4 +if ne get st SRF 5 ret 2 end if not and fname add b 1 fname add b 2 @@ -435,10 +652,13 @@ a = fnum add b 3 if or ne get st SBAD 0 eq a 0 ret 2 end +if not and cfeq 6 add b 2 authrec b 4 false false +ret 16 +end p = kfind 2 add b 1 if ne p 0 k = sub p 1 -if and eq get d1 k a keq get d0 k 0 add b 2 +if and aeqhash 0 k and eq get d1 k a keq get d0 k 0 add b 2 ret 1 end ret 13 @@ -454,6 +674,14 @@ y = cadd get st SPRE a if or ne get st SOVF 0 lt y x ret 15 end +note New prefund id plus requester only if the account is not present. +needed = ulong 1 +if eq ac 0 +needed = ulong 2 +end +if gt add get st SKEYS needed KCAP +ret 14 +end ret 0 end @@ -469,6 +697,7 @@ k = sub p 1 c = sub ac 1 put d0 k c put d1 k a +asave 0 k cred c a put st SPRE cadd get st SPRE a ret 0 @@ -491,7 +720,7 @@ ret true end fn vres b ulong live bool to int -if ne get st SRF 6 +if ne get st SRF 8 ret 2 end if not fhex add b 1 @@ -505,9 +734,18 @@ a = fnum add b 5 if or ne get st SBAD 0 eq a 0 ret 2 end +if not and cfeq 6 add b 2 and cfeq 7 add b 3 cfeq 8 add b 4 +ret 16 +end +if not and fhex add b 6 authrec b 7 false false +ret 16 +end j = kfind 1 add b 1 if ne j 0 -if and live jsame sub j 1 b a +if ne get d4 sub j 1 1 +ret 10 +end +if and and live aeqhash 1 sub j 1 jsame sub j 1 b a ret 1 end ret 9 @@ -519,6 +757,19 @@ end if lt get d0 sub r 1 a ret 7 end +note Reserve allocates its job and any missing distinct pinned role accounts. +needed = ulong 1 +p = kfind 0 add b 3 +v = kfind 0 add b 4 +if eq p 0 +needed = add needed 1 +end +if eq v 0 +needed = add needed 1 +end +if gt add get st SKEYS needed KCAP +ret 14 +end ret 0 end @@ -535,6 +786,7 @@ a = fnum add b 5 k = sub j 1 q = sub r 1 put d0 k q +asave 1 k put d1 k sub p 1 put d2 k sub v 1 put d3 k a @@ -568,7 +820,7 @@ end note sdup: a settle of an already settled JOB: an identical repeat is 1, anything else 11. fn sdup k ulong b ulong live bool to int -if and live ssame k b +if and and live aeqhash 2 k ssame k b ret 1 end ret 11 @@ -591,7 +843,7 @@ ret 0 end fn vset b ulong live bool to int -if ne get st SRF 6 +if ne get st SRF 10 ret 2 end if not and fhex add b 1 fhex add b 2 @@ -604,6 +856,12 @@ bk = fnum add b 5 if ne get st SBAD 0 ret 2 end +if not and fhex add b 6 fhex add b 7 +ret 2 +end +if not authrec b 8 true true +ret 16 +end j = kfind 1 add b 1 if eq j 0 ret 8 @@ -630,6 +888,7 @@ pp = fnum add b 3 pv = fnum add b 4 bk = fnum add b 5 put d4 k 2 +asave 2 k put d5 k pp put d6 k pv put d7 k bk @@ -646,12 +905,15 @@ ret 0 end fn vref b ulong live bool to int -if ne get st SRF 2 +if ne get st SRF 3 ret 2 end if not fhex add b 1 ret 2 end +if not authrec b 2 true false +ret 16 +end j = kfind 1 add b 1 if eq j 0 ret 8 @@ -679,11 +941,18 @@ note rapply: check and apply the record at field 2 of a replayed line; 0 or a re fn rapply to int b = ulong 2 if eq get st SSEQ 0 -if and fis b 22 and eq get st SRF 2 fis 3 24 -ret 0 +o = get fo b +n = sub sub get fo sub get st SNF 1 1 o +if ne n get cfgn 0 +ret 5 end +for i ulong n +if ne get cfg i get lb add o i ret 5 end +end +ret 0 +end if fis b 15 if ne vpre b false 0 ret 5 @@ -794,10 +1063,6 @@ if eq get st SLONG 0 c = rline get st SLN end if ne c 0 -if and eq c 1 eq e get st SFSZ -put st STORN 1 -ret 0 -end ret 5 end put st SOVF 0 @@ -894,6 +1159,14 @@ put wb n c put st SWB add n 1 end +note rollback: best-effort restore the last good length after a failed append sync; never ack it. +fn rollback fd int off ulong to void +if ne ftrunc fd long off 0 +ret +end +x = fsync fd +end + note wrec: append the record whose body is lb[0 .. st SLN) and fsync it. 0, or 3. fn wrec to int put st SWB 0 @@ -940,6 +1213,7 @@ end end sy = fsync fd if ne sy 0 +rollback fd off ret 3 end for i ulong 64 @@ -1005,7 +1279,20 @@ note reply: word k, then the command's fields after the KIND, on stdout. fn reply k ulong to void put st SOB 0 ofr k -for i ulong get st SNF +n = get st SNF +if fis 0 15 +n = sub n 1 +end +if fis 0 16 +n = sub n 2 +end +if fis 0 17 +n = sub n 4 +end +if fis 0 18 +n = sub n 1 +end +for i ulong n if gt i 0 oput 32 ofld i @@ -1019,18 +1306,23 @@ note wcmd: finish a write command whose check gave r: print the repeat word d, r note write the record, fsync it, and print the word w. fn wcmd r int w ulong d ulong to void if eq r 1 +if ne fsync int get st SFD 0 +die 3 +end +dsync reply d ret end if ne r 0 -die r +if eq r 16 +authdie end -if gt add get st SKEYS 4 KCAP -die 14 +die r end if ne wrec 0 die 3 end +dsync reply w end @@ -1226,9 +1518,9 @@ end end if eq get st SSEQ 0 put st SLN 0 -lbfr 22 -lbput 32 -lbfr 24 +for i ulong get cfgn 0 +lbput get cfg i +end if ne wrec 0 die 3 end @@ -1260,7 +1552,7 @@ end fn main to int c = argcnt -if or lt c 4 gt c 9 +if or lt c 4 gt c 13 put st SOB 0 ofr 48 oput 10 @@ -1280,6 +1572,7 @@ end if not aeq 1 46 die 2 end +acfg for i ulong 64 put ph i 48 end diff --git a/om/vendor/ec.om b/om/vendor/ec.om new file mode 100644 index 00000000..4b3d8225 --- /dev/null +++ b/om/vendor/ec.om @@ -0,0 +1,685 @@ +note SPDX-License-Identifier: Apache-2.0 +note om/tls/ec.om: ECDSA signature verification on NIST P-256 and P-384 (FIPS 186-4 section 6.4.2). +note Library unit (no om2 line, no main). Module code EC: functions ec_* and ecdsa_*, consts EC*. +note +note API (all inputs are public; this module is variable time by design, see "Timing" below): +note ecdsa_verify crv pub hs hlen crv 256 or 384; pub = 0x04 || X || Y (SEC1 uncompressed); +note hs = digest (hlen bytes) || DER Ecdsa-Sig-Value +note ecdsa_verify_raw crv pub hs hlen same, signature r || s, each 32 (P-256) or 48 (P-384) bytes +note Return codes: 0 valid, 1 signature mismatch (computed point at infinity included), +note 2 bad DER or encoding (also hlen > len hs), 3 bad public key (format, coordinate >= p, +note not on the curve), 4 r or s not in [1, n-1], 5 unsupported crv. +note The digest may have any length: e = its leftmost min(hlen, 32|48) bytes (bits2int; the bit +note length of n is 256 or 384, byte aligned), reduced mod n. +note +note Arithmetic: 32-bit limbs held in ulong cells, little-endian, L = 8 (P-256) or 12 (P-384). +note Generic Montgomery multiplication (CIOS) for p and for n; n0' = -m^-1 mod 2^32 (Newton +note iteration), R mod m and R^2 mod m (R = 2^(32L), by repeated doubling) are computed at run +note time. Points in Jacobian coordinates (a = -3), Z = 0 is the point at infinity. Shamir's +note joint double-scalar multiplication u1*G + u2*Q with the table G, Q, G+Q. +note +note Timing: signature verification handles only public values (key, digest, signature), so this +note module is NOT constant time and does not try to be: DER parsing, range checks, the Shamir +note loop (branches on the bits of u1 and u2), point addition (branches on Z = 0, H = 0, r = 0), +note ec_csub (branch on the borrow), ec_cmp (early exit) and the Fermat inversions (branch on the +note exponent bits of the public moduli) all take data-dependent time. Do not reuse these helpers +note on secret data (e.g. ECDH or signing) without a constant-time rewrite. Compiler caveat: omc +note emits plain AArch64 and no DIT bit is set. No secret is held, so nothing is wiped. +note Untrusted input never traps: every length and offset is checked before indexing (fuzzed by +note test/ec/gen_fuzz.py). +note +note Workspace w (ECWN ulong cells) layout, slot stride 12 cells: +note 0 L; 2..15 Montgomery accumulator T (L+2 cells) +note ECCP 16 / ECCN 56: modulus context: +0 m, +12 n0', +16 R mod m, +28 R^2 mod m +note ECZ zero, ECON plain 1, ECB curve b (Montgomery), points ECG ECQ ECGQ ECR (X,Y,Z), +note scalars ECSR r, ECSS s, ECE e, ECU1, ECU2, ECSI s^-1, temporaries ECA0..ECA9, ECAC. + +const ECWN ulong 480 +const ECCP ulong 16 +const ECCN ulong 56 +const ECZ ulong 96 +const ECON ulong 108 +const ECB ulong 120 +const ECG ulong 132 +const ECQ ulong 168 +const ECGQ ulong 204 +const ECR ulong 240 +const ECSR ulong 276 +const ECSS ulong 288 +const ECE ulong 300 +const ECU1 ulong 312 +const ECU2 ulong 324 +const ECSI ulong 336 +const ECA0 ulong 348 +const ECA1 ulong 360 +const ECA2 ulong 372 +const ECA3 ulong 384 +const ECA4 ulong 396 +const ECA5 ulong 408 +const ECA6 ulong 420 +const ECA7 ulong 432 +const ECA8 ulong 444 +const ECA9 ulong 456 +const ECAC ulong 468 + +note Curve constants, verbatim from FIPS 186-4 Appendix D.1.2.3 (P-256) and D.1.2.4 (P-384) +note (same values as SEC 2 v2 sections 2.4.2 secp256r1 and 2.5.1 secp384r1). a = -3 for both. +note Checked with Wolfram (WolframLanguageEvaluator, 2026-10-26; exact query and output in +note test/ec/wolfram.txt): PrimeQ[p], PrimeQ[n], Mod[Gy^2-(Gx^3-3Gx+b),p]==0, n*G == O (affine +note double-and-add mod p), BitLength[p]==BitLength[n] (256, 384), n<p<2n: all True for both curves. +fn ec_p256 w edit ulong ECWN to void +put w 0 8 +note p = 0xffffffff00000001000000000000000000000000ffffffffffffffffffffffff (limbs little-endian) +put w 16 0xffffffff +put w 17 0xffffffff +put w 18 0xffffffff +put w 19 0x0 +put w 20 0x0 +put w 21 0x0 +put w 22 0x1 +put w 23 0xffffffff +note n = 0xffffffff00000000ffffffffffffffffbce6faada7179e84f3b9cac2fc632551 (limbs little-endian) +put w 56 0xfc632551 +put w 57 0xf3b9cac2 +put w 58 0xa7179e84 +put w 59 0xbce6faad +put w 60 0xffffffff +put w 61 0xffffffff +put w 62 0x0 +put w 63 0xffffffff +note b = 0x5ac635d8aa3a93e7b3ebbd55769886bc651d06b0cc53b0f63bce3c3e27d2604b (limbs little-endian) +put w 120 0x27d2604b +put w 121 0x3bce3c3e +put w 122 0xcc53b0f6 +put w 123 0x651d06b0 +put w 124 0x769886bc +put w 125 0xb3ebbd55 +put w 126 0xaa3a93e7 +put w 127 0x5ac635d8 +note gx = 0x6b17d1f2e12c4247f8bce6e563a440f277037d812deb33a0f4a13945d898c296 (limbs little-endian) +put w 132 0xd898c296 +put w 133 0xf4a13945 +put w 134 0x2deb33a0 +put w 135 0x77037d81 +put w 136 0x63a440f2 +put w 137 0xf8bce6e5 +put w 138 0xe12c4247 +put w 139 0x6b17d1f2 +note gy = 0x4fe342e2fe1a7f9b8ee7eb4a7c0f9e162bce33576b315ececbb6406837bf51f5 (limbs little-endian) +put w 144 0x37bf51f5 +put w 145 0xcbb64068 +put w 146 0x6b315ece +put w 147 0x2bce3357 +put w 148 0x7c0f9e16 +put w 149 0x8ee7eb4a +put w 150 0xfe1a7f9b +put w 151 0x4fe342e2 +end + +fn ec_p384 w edit ulong ECWN to void +put w 0 12 +note p = 0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffeffffffff0000000000000000ffffffff (limbs little-endian) +put w 16 0xffffffff +put w 17 0x0 +put w 18 0x0 +put w 19 0xffffffff +put w 20 0xfffffffe +put w 21 0xffffffff +put w 22 0xffffffff +put w 23 0xffffffff +put w 24 0xffffffff +put w 25 0xffffffff +put w 26 0xffffffff +put w 27 0xffffffff +note n = 0xffffffffffffffffffffffffffffffffffffffffffffffffc7634d81f4372ddf581a0db248b0a77aecec196accc52973 (limbs little-endian) +put w 56 0xccc52973 +put w 57 0xecec196a +put w 58 0x48b0a77a +put w 59 0x581a0db2 +put w 60 0xf4372ddf +put w 61 0xc7634d81 +put w 62 0xffffffff +put w 63 0xffffffff +put w 64 0xffffffff +put w 65 0xffffffff +put w 66 0xffffffff +put w 67 0xffffffff +note b = 0xb3312fa7e23ee7e4988e056be3f82d19181d9c6efe8141120314088f5013875ac656398d8a2ed19d2a85c8edd3ec2aef (limbs little-endian) +put w 120 0xd3ec2aef +put w 121 0x2a85c8ed +put w 122 0x8a2ed19d +put w 123 0xc656398d +put w 124 0x5013875a +put w 125 0x314088f +put w 126 0xfe814112 +put w 127 0x181d9c6e +put w 128 0xe3f82d19 +put w 129 0x988e056b +put w 130 0xe23ee7e4 +put w 131 0xb3312fa7 +note gx = 0xaa87ca22be8b05378eb1c71ef320ad746e1d3b628ba79b9859f741e082542a385502f25dbf55296c3a545e3872760ab7 (limbs little-endian) +put w 132 0x72760ab7 +put w 133 0x3a545e38 +put w 134 0xbf55296c +put w 135 0x5502f25d +put w 136 0x82542a38 +put w 137 0x59f741e0 +put w 138 0x8ba79b98 +put w 139 0x6e1d3b62 +put w 140 0xf320ad74 +put w 141 0x8eb1c71e +put w 142 0xbe8b0537 +put w 143 0xaa87ca22 +note gy = 0x3617de4a96262c6f5d9e98bf9292dc29f8f41dbd289a147ce9da3113b5f0b8c00a60b1ce1d7e819d7a431d7c90ea0e5f (limbs little-endian) +put w 144 0x90ea0e5f +put w 145 0x7a431d7c +put w 146 0x1d7e819d +put w 147 0xa60b1ce +put w 148 0xb5f0b8c0 +put w 149 0xe9da3113 +put w 150 0x289a147c +put w 151 0xf8f41dbd +put w 152 0x9292dc29 +put w 153 0x5d9e98bf +put w 154 0x96262c6f +put w 155 0x3617de4a +end + +note T[0..L+1] += a[0..L-1] * y (a at w offset a, y < 2^32); each step fits: (2^32-1) + +note (2^32-1)^2 + (2^32-1) = 2^64 - 1 +fn ec_row w edit ulong ECWN a ulong y ulong to void +n = get w 0 +c = ulong 0 +x = ulong 0 +for j ulong n +x = add add get w add 2 j mul get w add a j y c +put w add 2 j and x 0xffffffff +c = shr x 32 +end +x = add get w add 2 n c +put w add 2 n and x 0xffffffff +put w add 3 n add get w add 3 n shr x 32 +end + +note o = T - m if T >= m else T (T has L+1 limbs, T < 2m); modulus m at offset c +fn ec_csub w edit ulong ECWN c ulong o ulong to void +n = get w 0 +br = ulong 0 +x = ulong 0 +for j ulong n +x = sub sub get w add 2 j get w add c j br +br = shr x 63 +end +x = sub get w add 2 n br +if eq shr x 63 0 +br = 0 +for j ulong n +x = sub sub get w add 2 j get w add c j br +put w add o j and x 0xffffffff +br = shr x 63 +end +ret +end +for j ulong n +put w add o j get w add 2 j +end +end + +note T = a + b as L+1 limbs +fn ec_sum w edit ulong ECWN a ulong b ulong to void +n = get w 0 +cy = ulong 0 +x = ulong 0 +for j ulong n +x = add add get w add a j get w add b j cy +put w add 2 j and x 0xffffffff +cy = shr x 32 +end +put w add 2 n cy +end + +note o = a + b mod m (a, b < m; also a < 2m with b = 0 reduces a) +fn ec_add w edit ulong ECWN c ulong o ulong a ulong b ulong to void +ec_sum w a b +ec_csub w c o +end + +note o = a - b mod m (a, b < m): T = a + m - b, in (0, 2m), then one conditional subtraction +fn ec_sub w edit ulong ECWN c ulong o ulong a ulong b ulong to void +ec_sum w a c +n = get w 0 +br = ulong 0 +x = ulong 0 +for j ulong n +x = sub sub get w add 2 j get w add b j br +put w add 2 j and x 0xffffffff +br = shr x 63 +end +put w add 2 n sub get w add 2 n br +ec_csub w c o +end + +note one CIOS step: T = (T + a*y + q*m) / 2^32 with q = (T + a*y)[0] * n0' mod 2^32 +fn ec_step w edit ulong ECWN c ulong a ulong y ulong to void +ec_row w a y +q = and mul get w 2 get w add c 12 0xffffffff +ec_row w c q +n = get w 0 +for j ulong add n 1 +put w add 2 j get w add 3 j +end +put w add 3 n 0 +end + +note o = a * b * R^-1 mod m (Montgomery, CIOS; a, b < m). o may alias a or b. +fn ec_mul w edit ulong ECWN c ulong o ulong a ulong b ulong to void +n = get w 0 +for j ulong add n 2 +put w add 2 j 0 +end +for i ulong n +ec_step w c a get w add b i +end +ec_csub w c o +end + +note compare L-limb numbers: 0 equal, 1 a < b, 2 a > b +fn ec_cmp w edit ulong ECWN a ulong b ulong to ulong +n = get w 0 +for k ulong n +j = sub sub n 1 k +x = get w add a j +y = get w add b j +if lt x y +ret 1 +end +if gt x y +ret 2 +end +end +ret 0 +end + +fn ec_copy w edit ulong ECWN o ulong a ulong to void +for j ulong get w 0 +put w add o j get w add a j +end +end + +note copy a point (three slots) +fn ec_pcopy w edit ulong ECWN o ulong a ulong to void +for j ulong 36 +put w add o j get w add a j +end +end + +note bit i of the L-limb number at a +fn ec_bit w edit ulong ECWN a ulong i ulong to ulong +ret and shr get w add a shr i 5 and i 31 1 +end + +note modulus context at c (m already stored): n0' = -m^-1 mod 2^32 by Newton iteration +note (x = m0 is right to 3 bits; each step doubles the bits: 3, 6, 12, 24, 48 >= 32), +note R mod m = 2^(32L) mod m and R^2 mod m by repeated modular doubling from 1. +fn ec_ctx w edit ulong ECWN c ulong to void +n = get w 0 +m0 = get w c +x = m0 +for k ulong 5 +x = and mul x sub 2 mul m0 x 0xffffffff +end +put w add c 12 and sub 0 x 0xffffffff +for j ulong n +put w add add c 16 j 0 +end +put w add c 16 1 +for k ulong mul n 32 +ec_add w c add c 16 add c 16 add c 16 +end +ec_copy w add c 28 add c 16 +for k ulong mul n 32 +ec_add w c add c 28 add c 28 add c 28 +end +end + +note o = a^(m-2) (Montgomery domain; m prime, so a^-1 for a != 0). m - 2: m0 >= 2 for all four +note moduli, so only limb 0 changes. +fn ec_inv w edit ulong ECWN c ulong o ulong a ulong to void +ec_copy w ECAC add c 16 +nb = mul get w 0 32 +for k ulong nb +i = sub sub nb 1 k +ec_mul w c ECAC ECAC ECAC +v = get w add c shr i 5 +if eq shr i 5 0 +v = sub v 2 +end +if eq and shr v and i 31 1 1 +ec_mul w c ECAC ECAC a +end +end +ec_copy w o ECAC +end + +note load the big-endian bytes of b (len b <= 4L) as an L-limb number at o +fn ec_load w edit ulong ECWN o ulong b view uchar * to void +for j ulong get w 0 +put w add o j 0 +end +k = len b +for i ulong k +bv = shl ulong get b sub sub k i 1 mul and i 3 8 +li = add o shr i 2 +put w li or get w li bv +end +end + +note P = 2P in place, a = -3 (dbl-2001-b). Infinity (Z = 0) stays infinity. +fn ec_dbl w edit ulong ECWN p ulong to void +y = add p 12 +z = add p 24 +ec_mul w ECCP ECA0 z z +ec_mul w ECCP ECA1 y y +ec_mul w ECCP ECA2 p ECA1 +ec_sub w ECCP ECA4 p ECA0 +ec_add w ECCP ECA5 p ECA0 +ec_mul w ECCP ECA3 ECA4 ECA5 +ec_add w ECCP ECA4 ECA3 ECA3 +ec_add w ECCP ECA3 ECA4 ECA3 +ec_add w ECCP ECA4 y z +ec_mul w ECCP ECA4 ECA4 ECA4 +ec_sub w ECCP ECA4 ECA4 ECA1 +ec_sub w ECCP z ECA4 ECA0 +ec_add w ECCP ECA2 ECA2 ECA2 +ec_add w ECCP ECA2 ECA2 ECA2 +ec_add w ECCP ECA5 ECA2 ECA2 +ec_mul w ECCP p ECA3 ECA3 +ec_sub w ECCP p p ECA5 +ec_sub w ECCP ECA2 ECA2 p +ec_mul w ECCP ECA2 ECA3 ECA2 +ec_mul w ECCP ECA1 ECA1 ECA1 +ec_add w ECCP ECA1 ECA1 ECA1 +ec_add w ECCP ECA1 ECA1 ECA1 +ec_add w ECCP ECA1 ECA1 ECA1 +ec_sub w ECCP y ECA2 ECA1 +end + +note P = P + Q (add-1998-cmo-2). Q infinity: P unchanged; P infinity: P = Q; H = 0 and R = 0 +note (P == Q): doubling; H = 0, R != 0 (P == -Q): infinity. +fn ec_padd w edit ulong ECWN p ulong q ulong to void +if eq ec_cmp w add q 24 ECZ 0 +ret +end +if eq ec_cmp w add p 24 ECZ 0 +ec_pcopy w p q +ret +end +ec_mul w ECCP ECA0 add p 24 add p 24 +ec_mul w ECCP ECA1 add q 24 add q 24 +ec_mul w ECCP ECA2 p ECA1 +ec_mul w ECCP ECA3 q ECA0 +ec_mul w ECCP ECA4 add p 12 add q 24 +ec_mul w ECCP ECA4 ECA4 ECA1 +ec_mul w ECCP ECA5 add q 12 add p 24 +ec_mul w ECCP ECA5 ECA5 ECA0 +ec_sub w ECCP ECA3 ECA3 ECA2 +ec_sub w ECCP ECA5 ECA5 ECA4 +if eq ec_cmp w ECA3 ECZ 0 +if eq ec_cmp w ECA5 ECZ 0 +ec_dbl w p +ret +end +ec_copy w add p 24 ECZ +ret +end +ec_mul w ECCP ECA6 ECA3 ECA3 +ec_mul w ECCP ECA7 ECA3 ECA6 +ec_mul w ECCP ECA2 ECA2 ECA6 +ec_mul w ECCP p ECA5 ECA5 +ec_sub w ECCP p p ECA7 +ec_sub w ECCP p p ECA2 +ec_sub w ECCP p p ECA2 +ec_sub w ECCP ECA2 ECA2 p +ec_mul w ECCP ECA2 ECA5 ECA2 +ec_mul w ECCP ECA4 ECA4 ECA7 +ec_sub w ECCP add p 12 ECA2 ECA4 +ec_mul w ECCP add p 24 add p 24 add q 24 +ec_mul w ECCP add p 24 add p 24 ECA3 +end + +note ECR = u1*G + u2*Q (Shamir, table G, Q, G+Q; variable time) +fn ec_smul w edit ulong ECWN to void +ec_pcopy w ECGQ ECG +ec_padd w ECGQ ECQ +ec_pcopy w ECR ECG +ec_copy w add ECR 24 ECZ +nb = mul get w 0 32 +for k ulong nb +i = sub sub nb 1 k +ec_dbl w ECR +t = or ec_bit w ECU1 i shl ec_bit w ECU2 i 1 +if eq t 1 +ec_padd w ECR ECG +end +if eq t 2 +ec_padd w ECR ECQ +end +if eq t 3 +ec_padd w ECR ECGQ +end +end +end + +note curve setup: constants, both Montgomery contexts, b and G into the Montgomery domain +fn ec_setup w edit ulong ECWN crv ulong to ulong +if eq crv 256 +ec_p256 w +else +if eq crv 384 +ec_p384 w +else +ret 5 +end +end +ec_ctx w ECCP +ec_ctx w ECCN +put w ECON 1 +ec_mul w ECCP ECB ECB add ECCP 28 +ec_mul w ECCP ECG ECG add ECCP 28 +ec_mul w ECCP add ECG 12 add ECG 12 add ECCP 28 +ec_copy w add ECG 24 add ECCP 16 +ret 0 +end + +note public key: exactly 0x04 || X || Y, X < p, Y < p, Y^2 = X^3 - 3X + b; Q in Montgomery form +fn ec_pub w edit ulong ECWN pub view uchar * to ulong +nb = mul get w 0 4 +if ne len pub add 1 mul nb 2 +ret 3 +end +if ne get pub 0 4 +ret 3 +end +ec_load w ECQ part pub 1 nb +ec_load w add ECQ 12 part pub add 1 nb nb +if ne ec_cmp w ECQ ECCP 1 +ret 3 +end +if ne ec_cmp w add ECQ 12 ECCP 1 +ret 3 +end +ec_mul w ECCP ECQ ECQ add ECCP 28 +ec_mul w ECCP add ECQ 12 add ECQ 12 add ECCP 28 +ec_copy w add ECQ 24 add ECCP 16 +ec_mul w ECCP ECA0 add ECQ 12 add ECQ 12 +ec_mul w ECCP ECA1 ECQ ECQ +ec_add w ECCP ECA2 add ECCP 16 add ECCP 16 +ec_add w ECCP ECA2 ECA2 add ECCP 16 +ec_sub w ECCP ECA1 ECA1 ECA2 +ec_mul w ECCP ECA1 ECA1 ECQ +ec_add w ECCP ECA1 ECA1 ECB +if ne ec_cmp w ECA0 ECA1 0 +ret 3 +end +ret 0 +end + +note one DER INTEGER at hs[p..e): tag 2, short-form length 1..127 inside e, non-negative, +note minimal (a leading 0x00 only before a byte >= 0x80). Writes the value to o; a value longer +note than 4L bytes is replaced by n so the range check rejects it. Returns the bytes used, 0 bad. +fn ec_int w edit ulong ECWN o ulong hs view uchar * p ulong e ulong to ulong +if lt sub e p 3 +ret 0 +end +if ne get hs p 2 +ret 0 +end +il = ulong get hs add p 1 +if or ge il 128 eq il 0 +ret 0 +end +if gt il sub e add p 2 +ret 0 +end +v = add p 2 +if ge get hs v 128 +ret 0 +end +k = il +if and eq get hs v 0 gt il 1 +if lt get hs add v 1 128 +ret 0 +end +v = add v 1 +k = sub k 1 +end +if gt k mul get w 0 4 +ec_copy w o ECCN +else +ec_load w o part hs v k +end +ret add il 2 +end + +note strict DER Ecdsa-Sig-Value at hs[h..]: SEQUENCE (short-form length; every valid signature +note on these curves is < 128 bytes, so a long form is never minimal) of two INTEGERs, and no +note byte after it. +fn ec_der w edit ulong ECWN hs view uchar * h ulong to ulong +k = len hs +if lt sub k h 2 +ret 2 +end +if ne get hs h 0x30 +ret 2 +end +sl = ulong get hs add h 1 +if ge sl 128 +ret 2 +end +if ne add add h 2 sl k +ret 2 +end +c = ec_int w ECSR hs add h 2 k +if eq c 0 +ret 2 +end +d = ec_int w ECSS hs add add h 2 c k +if eq d 0 +ret 2 +end +if ne add add add h 2 c d k +ret 2 +end +ret 0 +end + +note raw r || s at hs[h..], each 4L bytes, nothing after +fn ec_raw w edit ulong ECWN hs view uchar * h ulong to ulong +nb = mul get w 0 4 +if ne sub len hs h mul nb 2 +ret 2 +end +ec_load w ECSR part hs h nb +ec_load w ECSS part hs add h nb nb +ret 0 +end + +note r, s in [1, n-1], then u1 = e s^-1, u2 = r s^-1 mod n, R = u1 G + u2 Q, accept iff R is +note finite and x(R) mod n == r. digest = hs[0..hlen). +fn ec_core w edit ulong ECWN hs view uchar * hlen ulong to ulong +if eq ec_cmp w ECSR ECZ 0 +ret 4 +end +if ne ec_cmp w ECSR ECCN 1 +ret 4 +end +if eq ec_cmp w ECSS ECZ 0 +ret 4 +end +if ne ec_cmp w ECSS ECCN 1 +ret 4 +end +k = mul get w 0 4 +if lt hlen k +k = hlen +end +ec_load w ECE part hs 0 k +ec_add w ECCN ECE ECE ECZ +ec_mul w ECCN ECSI ECSS add ECCN 28 +ec_inv w ECCN ECSI ECSI +ec_mul w ECCN ECU1 ECE ECSI +ec_mul w ECCN ECU2 ECSR ECSI +ec_smul w +if eq ec_cmp w add ECR 24 ECZ 0 +ret 1 +end +ec_inv w ECCP ECA8 add ECR 24 +ec_mul w ECCP ECA9 ECA8 ECA8 +ec_mul w ECCP ECA9 ECA9 ECR +ec_mul w ECCP ECA9 ECA9 ECON +ec_add w ECCN ECA9 ECA9 ECZ +if eq ec_cmp w ECA9 ECSR 0 +ret 0 +end +ret 1 +end + +fn ecdsa_verify crv ulong pub view uchar * hs view uchar * hlen ulong to ulong +w = new ulong ECWN 0 +rc = ec_setup w crv +if ne rc 0 +ret rc +end +rc = ec_pub w pub +if ne rc 0 +ret rc +end +if gt hlen len hs +ret 2 +end +rc = ec_der w hs hlen +if ne rc 0 +ret rc +end +ret ec_core w hs hlen +end + +fn ecdsa_verify_raw crv ulong pub view uchar * hs view uchar * hlen ulong to ulong +w = new ulong ECWN 0 +rc = ec_setup w crv +if ne rc 0 +ret rc +end +rc = ec_pub w pub +if ne rc 0 +ret rc +end +if gt hlen len hs +ret 2 +end +rc = ec_raw w hs hlen +if ne rc 0 +ret rc +end +ret ec_core w hs hlen +end diff --git a/om/vendor/sha256.om b/om/vendor/sha256.om index 35025236..1668936d 100644 --- a/om/vendor/sha256.om +++ b/om/vendor/sha256.om @@ -1,14 +1,14 @@ note SPDX-License-Identifier: Apache-2.0 note Vendored from aien-dev/benchmarks-mv om/data/sha256.om at 567c5da595ebc9abebcd4dd195b1b8d7fb7507f4 (branch note refactor/om-rewrite), written before that repository adopted Apache-2.0 tree-wide (d3f3b40). -note Only this header differs; checked against sha256sum by om/effects/run.sh through world.om. +note Header and hash-state global name differ (hstate avoids the ECDSA hs parameter); algorithm unchanged. note Incremental SHA-256 in native Omega. No runtime library calls. note Algorithm and constants checked against Omega seed/atlas/atlas.s2 and src/sha256.c note at seed ancestor 29b12760. Those files are references, never build inputs. note hmeta: buffered bytes, message bytes, state (0 active, 1 finalized, 2 error). note hfinal exposes 64 lowercase hexadecimal bytes in hd; reset before another message. global hk uint 64 -global hs uint 8 +global hstate uint 8 global hm uint 64 global hb uchar 64 global hd uchar 64 @@ -37,7 +37,7 @@ v = uint 0 for j ulong 8 v = or shl v 4 hnibble get hseed add mul i 8 j end -put hs i v +put hstate i v end for i ulong 3 put hmeta i 0 @@ -78,14 +78,14 @@ v = add hsmall1 get hm sub i 2 get hm sub i 7 v = add v hsmall0 get hm sub i 15 put hm i add v get hm sub i 16 end -a = get hs 0 -b = get hs 1 -c = get hs 2 -d = get hs 3 -e = get hs 4 -f = get hs 5 -g = get hs 6 -h = get hs 7 +a = get hstate 0 +b = get hstate 1 +c = get hstate 2 +d = get hstate 3 +e = get hstate 4 +f = get hstate 5 +g = get hstate 6 +h = get hstate 7 for i ulong 64 t1 = add h hbig1 e t1 = add t1 xor and e f and not e g @@ -102,14 +102,14 @@ c = b b = a a = add t1 t2 end -put hs 0 add get hs 0 a -put hs 1 add get hs 1 b -put hs 2 add get hs 2 c -put hs 3 add get hs 3 d -put hs 4 add get hs 4 e -put hs 5 add get hs 5 f -put hs 6 add get hs 6 g -put hs 7 add get hs 7 h +put hstate 0 add get hstate 0 a +put hstate 1 add get hstate 1 b +put hstate 2 add get hstate 2 c +put hstate 3 add get hstate 3 d +put hstate 4 add get hstate 4 e +put hstate 5 add get hstate 5 f +put hstate 6 add get hstate 6 g +put hstate 7 add get hstate 7 h end fn hraw c uchar to void @@ -150,7 +150,7 @@ shift = mul sub 7 i 8 hraw uchar and shr bits shift 255 end for i ulong 8 -v = get hs i +v = get hstate i for j ulong 8 shift = uint mul sub 7 j 4 digit = ulong and shr v shift 15