Skip to content

v0.5 draft: clamp bound — spec, vectors, reference impl, verification harness - #38

Merged
ashedrack merged 11 commits into
mainfrom
draft/v0.5-clamp
Dec 1, 2026
Merged

ashedrack merged 11 commits into
mainfrom
draft/v0.5-clamp

Conversation

@ashedrack

Copy link
Copy Markdown
Owner

Summary

MMF v0.5 draft: clamp — an optional bound where an over-cap request is authorized at the effective cap (min over the resolved chain) instead of denied. Every downstream check (currency, payee, velocity, budget) evaluates the effective amount; claim binds the effective amount; the stored transaction keeps the requested amount so request equality — and therefore TX_CONFLICT — is unchanged.

  • Spec: spec/drafts/mmf-v0.5-clamp-proposal.md — frozen shape, all seven open choices resolved; bounds.clamp added to mmf.schema.json
  • Vectors: 26 decision vectors (clamp-core K01–K20, clamp-delegation KD01–KD06 — five contributed by moxclaw's mutation run), 3 evidence-hash vectors (KE01–KE03), 1 golden credential (KC01)
  • Impl: Python reference gate + TS port, byte-identical semantics — Bounds.clamp, effective-amount resolution, clamp fields on Decision/EvidenceRecord/TxRecord, canonical-payload extension ("true", requested, cap inserted before prev_hash only when clamped — existing hashes byte-identical)
  • Independence: bounds_hash with clamp:true appends one length-prefixed field true; KC01 pins it (bounds_hash 1adadc3a…)

Review-loop fixes (from moxclaw's independent verification on #33)

  • bounds_hash with clamp:true was 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 golden
  • E03 predated §5.6 — REJECTED record carried check:CLAIM, status:CLAIMED instead of <OP>:<CAUSE> + empty status. The shipped gate had the same divergence (emitted tx.status on REJECTED). Both corrected, E03 regenerated
  • Leaf-only velocity escaped the whole corpus — found by the new harness; moxclaw's guess that D16 covered it was wrong (D16 pins the recording direction, not the checking direction). D19 added to delegation.json

Verification harness

tools/verify_independent.py reproduces 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 regressions
  • python tools/verify_independent.py --all — 115/115 decisions, 16/16 evidence records, all credentials reproduce, all mutations caught
  • Independent verification by moxclaw (issue v0.5 candidate: optional clamp-to-owner-cap semantics for delegate spend #33): 26/26 decisions, all hash vectors reproduced
  • TS port: semantics ported in ts/src/index.ts; tsc build clean (target ES2022)

- 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.
@ashedrack
ashedrack merged commit c8a838f into main Dec 1, 2026
2 of 6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants