Repository navigation
v0.5 draft: clamp bound — spec, vectors, reference impl, verification harness - #38
Merged
Merged
Conversation
- effective_cap REQUIRED on clamped decisions (anchor for the future owner-tightening proposal and for replay determinism) - 5.1: explicit rule that a check id on an allowed decision names the adjusting bound and MUST NOT be read as a denial - 7: mark same-amount-new-tx_id-after-cap-change as deliberately deferred pending a tighten op - 9/11: resolve register-time (strict), check shape (Shape 2), naming (CAP_EXCEEDED), tighten scoping per second impl review
Second implementation confirmed the three remaining opens: clamp inside bounds and signed, leaf-only governance, and the three-field canonical payload extension (byte-identical hashes for unclamped records). Shape frozen pending their 21-vector TS harness run on #33.
Mutation testing of the frozen draft found five escapes the 21-vector set missed. New vectors cover: clamped spend not charged to the parent budget (KD06), REPLAY record carrying the effective amount rather than the requested one (K17), settle of a clamped spend re-charging the requested amount (K18), clamp applying to max_amount but never to remaining budget (K19), and the exact boundary one above the cap (K20). Contributed by moxclaw in #33.
Bounds.clamp (leaf-governed) turns an over-cap request into an authorization at effective_cap = min(chain max_amount), check CAP_EXCEEDED, allowed=true. Reservations, velocity and budget charge the effective amount; claim binds it; the ledger keeps the requested request for equality so a retry of the effective amount is TX_CONFLICT. Decision/EvidenceRecord/TxRecord carry clamped, requested_amount, effective_amount, effective_cap; the canonical payload gains exactly three fields before prev_hash, only when clamped, so existing hashes stay byte-identical. - tests/test_clamp.py: all 26 draft vectors pass (K01-K20, KD01-KD06) - spec/drafts/vectors/clamp-evidence.json: golden hash vectors KE01-03 - mmf.schema.json: bounds.clamp boolean - ts port: same semantics; tsconfig target ES2022 (pre-existing .at(-1) build failure)
Two finds from moxclaw's independent verification run: - Draft section 2 said omit clamp from the canonical bounds serialization when false but never said how it encodes when true. Now specified: a single appended length-prefixed field 'true' after budget_window_days, pinned by golden credential vector KC01. Two implementations could otherwise disagree on bounds_hash and reject each other's credentials for a clamped mandate. - The REJECTED record in E03 predated the <OP>:<CAUSE> and empty- status rules in section 5.6 (check was 'CLAIM', status 'CLAIMED'). Regenerated with CLAIM:STATUS and empty status; downstream hash and head recomputed. The reference gate had the same divergence: it emitted the transaction's current status on REJECTED records rather than the empty string the table mandates. Both corrected.
tools/verify_independent.py reproduces the external review protocol from issue #33: a canonicalizer written from the spec text (not from the implementation) recomputes every golden payload/hash; the full corpus runs through the gate; then wrong rules are applied one at a time via source-transform mutation and each must be caught. Running it surfaced a real corpus gap: a gate that checks velocity only on the leaf passes every vector. moxclaw listed leaf-only velocity among the uncaught escapes and guessed D16 covered it — D16 actually pins the recording direction (child spend lands in the parent's bucket), not the checking direction (a parent-exhausted velocity must deny a child transaction). D19 adds the missing case.
…t/v0.5-clamp # Conflicts: # ts/src/index.ts # ts/tsconfig.json
The earlier clamp changes lived in the single-file sketch that main's full port replaced. This re-implements them against the real modules, mirroring the Python gate: - Bounds.clamp (validated boolean); effective cap resolves as min over the resolved chain; only the leaf's clamp authorizes an over-cap request — check CAP_EXCEEDED with clamped/effective fields. - Currency/payee/velocity/budget evaluate the effective amount; the reservation records it on every chain node. - TxRecord keeps the requested amount for request equality plus the clamp fields; authorized_amount is the effective amount, which is what claim binds and what CLAIM/SETTLE/VOID records carry. - EvidenceRecord gains the three canonical fields inserted before prev_hash only when clamped; boundsHash appends 'true' only when clamp is true (KC01 reproduces). - SQLiteStore: same migration as Python — 4 txs + 3 evidence columns. - REJECTED records emit the spec-mandated empty status (the same conformance fix as the Python side; E03 hashes reproduce). - vectors.test.ts now runs the draft corpus: 123 tests, all green, including every K/KD/KE/KC golden.
Posted on issue #33 'use them freely' — vendored verbatim under tools/third-party/moxclaw with run instructions. evh.py recomputes all 16 golden evidence records and re-runs the 8 hash mutations; kc.py reproduces KC01 byte-identically including an Ed25519 implemented from RFC 8032 in pure Python. Both run clean against the repo's vectors.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
MMF v0.5 draft: clamp — an optional bound where an over-cap request is authorized at the effective cap (
minover the resolved chain) instead of denied. Every downstream check (currency, payee, velocity, budget) evaluates the effective amount;claimbinds the effective amount; the stored transaction keeps the requested amount so request equality — and thereforeTX_CONFLICT— is unchanged.spec/drafts/mmf-v0.5-clamp-proposal.md— frozen shape, all seven open choices resolved;bounds.clampadded tommf.schema.jsonclamp-coreK01–K20,clamp-delegationKD01–KD06 — five contributed by moxclaw's mutation run), 3 evidence-hash vectors (KE01–KE03), 1 golden credential (KC01)Bounds.clamp, effective-amount resolution, clamp fields onDecision/EvidenceRecord/TxRecord, canonical-payload extension ("true", requested, capinserted beforeprev_hashonly when clamped — existing hashes byte-identical)bounds_hashwithclamp:trueappends one length-prefixed fieldtrue; KC01 pins it (bounds_hash 1adadc3a…)Review-loop fixes (from moxclaw's independent verification on #33)
bounds_hashwithclamp:truewas unpinned — spec never said how the true case encodes; two impls could pass every vector and still reject each other's credentials. Fixed: draft §2 sentence + KC01 goldencheck:CLAIM,status:CLAIMEDinstead of<OP>:<CAUSE>+ empty status. The shipped gate had the same divergence (emittedtx.statuson REJECTED). Both corrected, E03 regenerateddelegation.jsonVerification harness
tools/verify_independent.pyreproduces the external review protocol: a canonicalizer written from the spec text (zero shared code with the shipped serialization) recomputes all golden payloads/hashes; the full corpus runs through the gate; then 24 wrong rules (16 decision mutations via source-transform exec, 8 hash mutations) are applied one at a time — every one is caught.Test plan
pytest tests/— 266 pass, zero regressionspython tools/verify_independent.py --all— 115/115 decisions, 16/16 evidence records, all credentials reproduce, all mutations caughtts/src/index.ts;tscbuild clean (target ES2022)