Skip to content

feat(joust): playground scenarios, @Quorum, keyed, MerkleMap and send calls (ADR-0024 M4) - #180

Open
satran004 wants to merge 10 commits into
feat/playground-m3from
feat/playground-m4
Open

satran004 wants to merge 10 commits into
feat/playground-m3from
feat/playground-m4

Conversation

@satran004

Copy link
Copy Markdown
Member

ADR-0024 M4: scenarios, @Quorum co-signing, keyed calls, MerkleMap calls and sends in the playground. Stacked on #179 (M3); the base is feat/playground-m3.

What it adds

  • Map claims in the pre-sign check (js/state-client/src/mpf.js, hostcheck.js):
    • verifyHostResult ports the reference checker's map-claim rules, MPF proofs included.
    • All 333 vectors in fixtures/host/verifier are now decided exactly as the reference decides them. The 31 map vectors were refused wholesale in M1; now nothing is excluded.
    • A differential test against Aiken's merkle-patricia-forestry passes.
  • Map and send calls are enabled. The MapVerifier and the output verifier are anchored in the pinned build: the Gradle snapshot's verifier jar, or the npm runtime engine. Their hashes equal the vectors' anchors.
  • @Quorum:
    • Co-signers are chosen per call from the page's identities.
    • The caller and then each co-signer approve the same checked body, and the witnesses are combined.
    • A CIP-30 wallet cannot be a co-signer, so a quorum call signed by a wallet is disabled with a reason.
  • Keyed calls (ADR-0016 M3 rules):
    • Before the first request, a lovelace-only output of at least 5 ADA is designated and recorded with the operation (in page memory offline, IndexedDB on DevKit).
    • One keyed call is in flight at a time.
    • "Prepare again at slot N" waits.
    • Every attempt is journaled before handout.
  • Scenarios (D10):
    • Export from an offline session names no keys, mnemonics or transaction bytes. Identities are labels, and key hashes and created ids are symbols.
    • Import warns about and names the contracts whose scripts differ.
    • Replay runs in a fresh offline session through the same checks and compares each step's outcome.
  • Unsupported: @Params, governors and @AuthorizedBy are shown disabled with the host's code. ADR-0023 (docs(adr): ADR-0023 the dev host serves @Params contracts and @AuthorizedBy calls (proposed) #157) has no host implementation yet.
  • Runtime fix (julc-state-runtime-wasm Offline.java, a separate commit): the Wasm attack suite now runs range attacks only on the bounds a script binds.
    • All four attacks: a Ctx or Batch redeemer carrying the body's window.
    • Three of them: a Link spend, whose upper bound is the keyed linkedAt.
    • None: an untimed keyed action, whose window is the runtime's bookkeeping.
    • Before this, Registry's change reported four "accepted" bound attacks. They were false positives: its validator reads no time, as the JVM testkit already assumes (Attacks.java, TxModel.hasRange). The rebuilt engine is used by the tests.
  • Docs: README sections for sends and maps, quorum, keyed calls and scenarios.

Tests (local)

Suite Result
state-client (all 333 vectors decided exactly; MPF differential) 670/670
playground.test.js + playground-m4.test.js + playground-devkit.test.js + offline-ledger.test.js (Chromium) 95/95
playground-devkit-e2e.test.js (local DevKit) 6/6
playground-gradle.test.js 35/35
:julc-state-runtime-wasm OfflineTest (new range-attack cases) 5/5
:julc-state-cli PlaygroundTest 20/20

The Chromium walkthrough covers maps (Token), quorum, keyed calls (Registry) and the scenario round trip. Each new call kind is also tested in Node through pageCheck, the function the page runs.

Points for review

  • For keyed calls the page runs only verifyHostResult (the reference's KeyedRules). It skips the dApp's verifyKeyed, which needs a designation journal of another shape. Unkeyed calls run both checks.
  • In an npm project the verifier scripts are read from the server's loaded runtime engine, which is the project's own @julclang/joust-runtime, so the engine files the fingerprint covers. If the two copies differ, the check refuses.
  • mapClaims/encoding is checked by strict shape decoding. It refuses the same vectors under the same problem code, but the check id can differ from the reference's.
  • No DevKit walkthrough yet for the new call kinds; the existing DevKit e2e passes on the merged branch.
  • Sends to wallet(key) land at the identity's enterprise address. The page shows that balance but does not spend it.
  • memoryLedger.fund(address, lovelace, assets) now takes native assets, for tests and simulation.

🤖 Generated with Claude Code

satran004 and others added 8 commits November 24, 2026 09:49
…r MPF proofs, as the reference does (ADR-0024 M4)

- mpf.js: a port of julc-state-api's Mpf and MapWitnesses.verify (the generic
  MapVerifier's on-chain checks): membership, absence, insert/update/delete roots,
  malformed steps fail; the MapClaims redeemer read by its record shapes exactly.
- hostcheck.js: CallRules.checkMaps ported: the map verifier's redeemer at its reward
  pointer, one claim per map field, policy, owner (seed or target), field, proofs,
  the creation's empty root, both roots against the target and continuation datums
  (no pending reads or writes), no writes on a destroy. Map calls are no longer
  refused as notVerifiable.
- hostcheck.test.js: all 333 verifier vectors decided as the reference decides
  them, the 31 map calls included; no exclusions.
- joust-runtime test/mpf.test.js: differential against Aiken's
  merkle-patricia-forestry over random tries (membership, absence, roots after insert,
  update and delete), and claim forgeries.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…s, and replays scenarios (ADR-0024 M4)

- Shared verifiers anchored in the pinned build (check.js anchorsOf): a Gradle
  snapshot's julc-state-verifier entry (snapshotVerifiers), an npm build's runtime
  engine (validatorScript); the server's contract route hands them to the page; a
  host deployment naming other verifiers is refused. Sends and MerkleMap calls are
  enabled; their claims (and MPF proofs) are checked by verifyHostResult.
- check.js pageCheck: the page's whole pre-sign check (verifyHostResult with the
  session clock, and verifyPrepared with the pinned verifiers for unkeyed calls),
  one function for the page and the Node tests.
- @quorum: co-signers chosen among the page's identities; the caller and each
  co-signer approve the same checked body and sign it; witnesses combined.
- Keyed calls (ADR-0016 M3): each operation's designated input (a free lovelace-only
  >= 5 ADA output) and record are persisted before the first request (page memory
  offline, IndexedDB on DevKit); each attempt is journaled before handoff; a
  ledger-refused attempt leaves the journal; mayHaveLanded with nothing handed out
  picks a new designation.
- Scenarios (D10, playground/scenario.js): export (identities as labels, key hashes
  and created ids as symbols, ascending key lists kept ascending; no keys, mnemonics
  or transaction bytes), import with a warning naming contracts whose scripts differ,
  replay in a fresh offline session through the same checks, outcomes compared.
- Identities show what sends left at their enterprise address.
- memoryLedger.fund takes native assets (simulations that need tokens).
- @params and @authorizedby stay disabled with the host's code (ADR-0023 is not
  implemented).
- Tests: playground-m4.test.js (Token maps, Market sends, HostCouncil quorum,
  Registry keyed through pageCheck; D11; scenario data; a Chromium walkthrough of
  maps, quorum, keyed and an export -> import -> replay with the same outcomes);
  CI runs it in the playground step.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…n untimed keyed action's window is bookkeeping)

Offline.attacks ran the four range attacks on every transaction with both bounds,
so a keyed attempt's bookkeeping window (TxRunner.untimedWindow / Compose), which
no script reads, showed as four accepted attacks (Registry's change). As the JVM
testkit gates them on a real range, they now follow what the scripts bind, read from
the body with the request's slot config:
- CTX: a redeemer carries the window as a Ctx (5 fields, validFrom and validTo at 3
  and 4) or a Batch(validFrom, validTo), equal to the bounds in POSIX ms: all four.
- LINK: else a keyed output (a 29-byte 0x4B token at a script address) whose datum's
  linkedAt (field 2) is the upper bound: upper removed, upper a slot later, lower
  removed.
- NONE: otherwise, no range attack.
OfflineTest: an untimed keyed change binds nothing; a Ctx and a Batch bind both
bounds (another window binds nothing); a Link without Ctx binds the upper bound; the
recorded transactions' gate is unchanged. playground-m4: Registry's change has no
accepted attack.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… into feat/playground-m4

Conflicts:
- main.js: one signing path for every call kind. M4's per-signer approvals (the
  caller, then each @quorum co-signer), the keyed attempt journal before handoff and
  the scenario replay's auto-approval, with M3's CIP-30 recheck and recorded handoff
  before the wallet sees the body, the lost-answer recovery (DevKit journal / offline
  reconcile, outcome unknown), and the review's before/after from the checks with the
  host's prediction folded apart.
- gradle.js: M2 round 4's freshness and hardening, with M4's snapshotVerifiers (the
  shared verifiers from the snapshot's julc-state-verifier entry).
- playground-m4.test.js opens the page through the one-time pairing link.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ed only on the caller's untimedWindow hint (#180 M4-D1)

927e804 gated the range attacks on a Ctx or a keyed link in the body, which hid real
ones: a @ValidAfter/@ValidBefore method without Ctx reads tx.validRange directly
(ContractReader, ValidatorGenerator), so its bounds were never attacked. Erring
towards more warnings, never fewer:
- Offline.attacks runs the four range attacks whenever both bounds are there, as
  before 927e804; the LINK/CTX classification is gone.
- joust.attacks takes AttacksRequest(..., untimedWindow): true skips them. Only the
  caller can know the window is bookkeeping.
- memoryLedger.submit(cbor, { untimedWindow }) passes it on; offline() and joust test
  never set it.
- The playground session sets it from the pinned description: a keyed action or
  retire whose method takes no Ctx and has no @ValidAfter/@ValidBefore (such calls
  never link).
- OfflineTest: both bounds are attacked without a Ctx; the hint skips them; a TTL
  alone is not attacked.
- playground-m4: a Deadline contract (@ValidBefore with and without Ctx): each gets
  the four range attacks. With Ctx all are refused; without, the removed upper bound
  is refused and a window moved within the deadline shows as a warning. Registry's
  change gets no range attack and no accepted one.
(session.js also carries the engineFiles field the next commit fills.)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ytes; scenario files over 1 MiB refused (#180 M4-S1, M4-S2)

- An npm session records the hashes of the runtime engine files its fingerprint
  covers. The server takes the shared verifiers' scripts from its loaded engine only
  when that engine has these bytes; otherwise none, so the page refuses sends and
  maps. The comment now says so.
- The page refuses a scenario file over 1 MiB before reading it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… and reconciliation, DevKit keyed windows, scenario roles and clock

- operations.js (new): keyed operation records keyed by the verified chain (a
  DevKit's network, magic and genesis start time; never the build), committed before
  the first request. IndexedDB writes must commit on DevKit (errors stop the call);
  page memory offline. Expiries go to the protocol as safe JSON integers, older
  bigint records included.
- Each attempt's checked hash and expiry are journaled before the body leaves the
  page: before a CIP-30 handoff, before signing. They are kept once handed out,
  across signing errors and reloads.
- mayHaveLanded, and an existing record before a new designation, reconcile the
  recorded attempts with the chain (a new landed route: the ledger's inclusion, or
  Yaci Store's /txs): landed closes the operation; one that can still land waits;
  none that can land is ambiguous and waits for the user's acknowledgement (a pending
  keyed operations panel).
- DevKit keyed windows (windowProblem): a start up to maxStartSlots ahead and an end
  at most start + ttl and now + the page's end limit, which keeps the stability bound.
  The session advertises keyedLimits and the page sends them as pageLimits. A
  cooldown starting inside the allowed future window is no longer fenced.
- Scenarios: positions and map key/value roles kept; only quorum key lists (the
  arguments a @quorum names, and cosigners) are re-sorted, and map arguments go back
  to canonical key order by their schema. Exports carry the offline clock's origin and
  slot length; replay runs on it (sessions/new takes a clock for a new offline ledger).
- Tests: operations (serialization, reconcile, chain keys, a store write that does not
  commit), a keyed second prepare after a retained attempt through JSON (pending,
  then prepared once released), windowProblem, scenario map roles and recanonical,
  verifier anchors per session engine bytes in one server, and a Chromium deadline
  scenario imported 30 days after its clock origin (2/2 the same outcomes).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@satran004

Copy link
Copy Markdown
Member Author

Author reply: round r1 · head f245a36

Review round 1. The security reviewer approved, with P3s. The design reviewer and Codex asked for changes.

Finding Change
Design M4-D1 (P1) / Codex P1: the range-attack gate hid real attacks on @ValidBefore/@ValidAfter methods without Ctx Offline.attacks again runs all four range attacks on any body with both bounds. The only exception is an explicit untimedWindow hint, which the playground sets from the pinned description for keyed actions and retires that use no time. joust test and offline() never set it. Test contract Deadline: bump and bumpCtx each get all four range attacks
Security M4-S1 / Codex P1: npm verifier anchors A session gets the verifier scripts only if the loaded engine's bytes equal the engine files its fingerprint covers; otherwise sends and maps are refused. Tested with two sessions in one server
Security M4-S2: scenario import size Files over 1 MiB are refused before reading
Codex P1: a retained keyed attempt made the next request unserialisable Expiries are safe JSON integers at the protocol boundary (old records too); a second prepare after a retained attempt is tested
Codex P1: the keyed journal was written after the CIP-30 handoff The checked hash and expiry are committed before the body leaves the page, and kept across signing errors and reloads
Codex P1: a landed attempt was not reconciled after a reload Recorded attempts are checked against the chain (landed route). A landed one closes the operation; one that can still land waits; an ambiguous one needs an acknowledgement before a new designation
Codex P1: IndexedDB write failures were ignored on DevKit Every write must commit, or the call stops with a journal error
Codex P1: records keyed by build Records are keyed by the verified chain (network, magic, genesis start time); pending operations survive rebuilds
Codex P1: a future-start keyed window fenced the host A keyed body may start up to 60 slots ahead and end within the TTL and the page's end limit; tested with a cooldown 10 slots ahead
Codex P2: scenario replay reversed map roles Positions and key/value roles are kept; tested with Codex's case
Codex P2: the scenario clock Exports carry the clock's origin and slot length, and replay uses them; tested 30 days later

The branch also merges #179 round 4. Local results: playground, M4, fake-chain DevKit and ledger 111/111; state-client 670/670; DevKit e2e 6/6; Gradle 35/35; OfflineTest 4/4.

satran004 and others added 2 commits November 24, 2026 11:48
…eyed records, recovered creations end the run, engine identity bound at load

- Keyed operation records are kept by the server: DevKit in the chain's journal
  (beside the reservations, under the same lock, keyed by network, magic and genesis
  start time), offline in the session. So a reload, another tab or a restarted
  command on another port sees them, and DevKit no longer depends on IndexedDB: a
  write that does not commit fails the call (journal/storage) before anything is
  prepared or handed out. Each change is one atomic step (create, addAttempt,
  removeAttempt, ambiguous, remove): a replaced tab can only take back an attempt it
  added itself, never overwrite newer state.
- A recovered creation (an existing record's attempt is on the chain) is the run's
  outcome: it is reported, and nothing new is designated or prepared (operations.js
  decide).
- reconcile uses the chain tip observed with the lookups (the landed route returns
  it); an unknown tip keeps attempts pending, never ambiguous.
- Verifier anchors: joust-runtime's loadEngine binds the hashes of the files it loaded
  (read before and after loading) to the engine instance (engineFilesOf). The server
  compares the session's fingerprinted engine with that identity, never with the
  files on disk now (an upgrade while running).
- Tests: reconcile with the observed tip (Codex's 150/99/110/10 case pending),
  decide, records surviving a journal reopen, a stale tab's removeAttempt, a write
  that cannot commit, another genesis seeing none, the engine identity.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…feat/playground-m4

Conflicts:
- devkit.js: M3's re-checked problemOf, with M4's keyed windowProblem in it; the
  session status carries M4's keyedLimits beside M3's fencedUntil.
- main.js: M3's enterprise-address identities (with M4's labelled identities for
  replay; the separate enterprise-holdings line is gone, since the identity's address
  now is its enterprise address), fill and confirmedNotes in M4's approval and signing
  path, both session-start steps, the union of imports.
The keyed operation records stay in the chain's journal beside M3's reservations,
under the same lock and written before the call goes on.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@satran004

Copy link
Copy Markdown
Member Author

Author reply: round r2 · head 16d51cd

Codex's round-2 findings. The design reviewer confirmed the range-attack fix (M4-D1) and approved; the security reviewer approved round 1.

Finding Change
P1: recovering a confirmed creation started another creation An earlier attempt found on the chain is the run's outcome; nothing new is designated or prepared
P1: a replaced tab could erase the active tab's attempt DevKit's keyed operation records moved server-side, into the per-chain journal beside the reservations, under the same lock and write-first rule. Every change is one atomic step, and a tab can take back only an attempt it added itself
P1: the verifier hash check read files on disk while serving a cached engine loadEngine records the hashes of the files it actually loaded; the server compares the session's pinned engine with those
P1: DevKit signed with a memory-only journal when IndexedDB was absent The records are server-side now, so keyed calls no longer depend on IndexedDB. A write that does not commit fails the call before anything is prepared or handed out
P2: reconciliation ignored the lookup's chain tip It uses the tip observed with the lookups; an unknown tip keeps attempts pending (Codex's case is a test)
P2: restarting the DevKit command hid the journal Records are keyed by network, magic and genesis start time, not by page origin

The branch also merges #179 round 5: enterprise-address identities and the single rewind fence. Local results: playground, M4, fake-chain DevKit and ledger 118/118; state-client 670/670; joust-runtime 22/22; DevKit e2e 6/6; Gradle 45/45; PlaygroundTest 21/21.

This branch has not been deployed

No deployments
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.

1 participant