Skip to content

feat(repo): add quoter-signer deterministic policy checks - #178

Open
julien-devatom wants to merge 7 commits into
mainfrom
kms-middleware-checks-f85533
Open

feat(repo): add quoter-signer deterministic policy checks#178
julien-devatom wants to merge 7 commits into
mainfrom
kms-middleware-checks-f85533

Conversation

@julien-devatom

@julien-devatom julien-devatom commented Aug 26, 2026

Copy link
Copy Markdown
Collaborator

What

Third increment of TIB-2026-08-12 (quoter-bot KMS signing middleware): the deterministic deployment-policy checks, still entirely fail-closed — the image holds no KMS access, implements no signing surface, and denies every intent.

  • Policy document (src/policy.utils.ts): the new QUOTER_SIGNER_POLICY env var carries one strictly-parsed JSON document — signing-surface pin (quote / ratify / routine-revoke / break-glass-revoke / setup-remediation), ratifier mode, chain/maker/ratifier pins, offer time windows, per-market allowlist (maturity, tick bounds ≤ protocol MAX_TICK, continuous-fee ceiling ≤ MAX_CONTINUOUS_FEE, lend-exposure cap), maker-wide cap, routine+protected fee ceilings, remediation variants. Parse-time deployment validation enforces quote↔Ecrecover / ratify↔Setter coherence and the TIB's emergency-bump reserve (protected ≥ max(floor(routine×1125/1000), routine+1), protected.gas ≥ routine.gas). Missing/invalid policy refuses to serve (PolicyNotConfiguredError).
  • Check stage (src/policy-check.utils.ts): surface/intent-kind, chain and maker pins, per-kind fee ceilings (protected only on the break-glass surface, per-variant for remediation), cancel-root/unratify-root mode coherence, remediation allowlist; and for quote/ratify offer sets: market allowlist, tick bounds, field pins (configured ratifier; no callback surface; zero receiver on buys, maker on sells), reduce-only side pins, fee-cap ceilings, time windows (start < expiry, unexpired, expiry ≤ min(maturity, now+freshness), start-age), group coherence, and static lend-exposure caps charged once per consumption domain (market, group, side, cap) so per-book rungs sharing a group count once. Violations deny with IntentPolicyViolationError; the middleware.intent_denied log line now carries the violated check id (TIB Observability).
  • Handler pipeline (src/index.ts): parse → policy load → checks → SigningNotImplementedError, each stage mapping unexpected faults to its own typed denial; the handler still never throws.
  • @morpho-org/midnight-sdk (+ @morpho-org/morpho-ts peer) added for the protocol constants, mirroring quoter-bot.

Why

The TIB's caller-to-surface scoping, parameter pins, and bounds must be enforceable before any signing surface exists — this lands every check decidable from deployment parameters and the middleware clock alone, so later increments (independent reads, reservation ledger, KMS) only add stages to an already fail-closed pipeline. Nothing policy-relevant comes from the request.

Reviewer notes

  • The TIB's "owned group namespace" does not exist on-chain (groups are content-addressed; consumption keyed per maker via onBehalf). It materializes here as the static group-coherence rule (one group id binds one market/side/cap inside an intent) with canonical re-derivation deferred to the encoding increment — recorded in TIB Addendum C, which also carries the sequencing note: today's builders pin expiry = maturity, so the §3 builder change is a prerequisite of the increment that enables quote/ratify signing.
  • The policy parser's structural helpers deliberately mirror intent.utils.ts rather than sharing a module (each fail-closed parser independently auditable; noted in a comment).
  • Repo reviewer and protocol-engineer agent passes ran pre-PR; all findings applied (fail-closed market-lookup branch, per-offer helper extraction, env-stub in tests) or documented (README operator guidance on tick-band drift, maxContinuousFeeCap defaulting to the protocol max, start-age sizing).
  • Validation: 186 quoter-signer tests (break-one-assertion verification done), pnpm lint 0 warnings, pnpm format, typecheck clean, esbuild bundle smoke-tested end to end (no-policy / in-policy / out-of-policy denials). Full pnpm test: only the fork/e2e suites requiring RPC_URL_8453 fail, identically to main (env-gated). knip: known worktree false positives only.

🤖 Generated with Claude Code

CI rider (superseded)

This branch briefly carried a foundry-toolchain v1.9.1 bump for the repo-wide binary-foundryup CI breakage; main merged its own hardened fix (SHA-256-pinned direct Foundry download, PR #174), which this branch now uses via merge — the final diff no longer touches the workflows.

julien-devatom and others added 3 commits August 25, 2026 15:49
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
- pin offer tick to uint256 and maxAssets to uint128 per the Midnight struct
- require an alias-qualified quoter-signer Lambda ARN (no version/unqualified)
- clear foreign signer sources for CLI middleware overrides in both directions
- report the fail-closed middleware identity as a sanitized signer observation

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Third TIB-2026-08-12 increment: the middleware now parses a strict
QUOTER_SIGNER_POLICY deployment document (surface/mode/chain/maker pins,
market allowlist with tick and fee ceilings, offer time windows, routine
and protected fee ceilings with the emergency-bump reserve, remediation
variants) and denies out-of-policy intents with a typed violation naming
the violated check. Still fail-closed: no KMS access, nothing signed.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@julien-devatom julien-devatom self-assigned this Aug 26, 2026
…-f85533

# Conflicts:
#	docs/decisions/TIB-2026-08-12-quoter-bot-kms-signing-middleware.md
#	pnpm-lock.yaml
#	services/quoter-signer/README.md
#	services/quoter-signer/package.json
#	services/quoter-signer/src/index.ts
#	services/quoter-signer/src/intent.utils.ts
#	services/quoter-signer/test/index.test.ts
@julien-devatom

Copy link
Copy Markdown
Collaborator Author

@codex review

@julien-devatom

Copy link
Copy Markdown
Collaborator Author

@prd-carapulse[bot] can you review and approve if all good

@prd-carapulse

prd-carapulse Bot commented Aug 26, 2026

Copy link
Copy Markdown
Contributor

Approved PR #178.

• No blocking correctness or security findings.
• Local verification: 186 quoter-signer tests passed; typecheck passed.
• CI: Lint, Typecheck, Dead-Code pass. Test job failed in Foundry installation before tests ran: foundryup: cannot execute binary file. Contract, unit, and browser tests were skipped. Rerun/fix CI before merge.

@prd-carapulse prd-carapulse Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed the policy parser/check stage and the added tests. No blocking correctness or security findings.

Local verification: 186 quoter-signer tests passed; quoter-signer typecheck passed. The PR Test check is red before test execution because the Foundry installer failed with /home/runner/.foundry/bin/foundryup: cannot execute binary file; contract, unit, and browser suites were skipped.

chatgpt-codex-connector[bot]

This comment was marked as resolved.

The pinned v1 SHA runs the downloaded foundryup via bash, which broke
repo-wide (main included) when upstream foundryup became a binary:
'cannot execute binary file' before any test executes. v1.9.1 downloads
the pinned foundryup-init.sh installer and executes foundryup directly.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@julien-devatom

Copy link
Copy Markdown
Collaborator Author

@codex review

- viem-first bytes32 identity: market/group keys via hexToBigInt instead
  of toLowerCase in the policy parser, the check stage, and the intent
  parser's market count
- refuse to serve a setup-remediation deployment with an empty
  remediation manifest (empty policy) instead of denying per intent
- README create-function command now passes the policy via
  --environment file://environment.json

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@julien-devatom

Copy link
Copy Markdown
Collaborator Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Hooray!

Reviewed commit: 43dbb4e13a

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

@linear-code

linear-code Bot commented Aug 26, 2026

Copy link
Copy Markdown

MKT-2101

@julien-devatom
julien-devatom marked this pull request as ready for review August 26, 2026 09:02

@devin-ai-integration devin-ai-integration Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ Devin Review: No Issues Found

Devin Review analyzed this PR and found no bugs or issues to report.

Open in Devin Review

…-f85533

Takes main's SHA-256-pinned direct Foundry download (PR #174) for the
checks workflow, superseding this branch's foundry-toolchain v1.9.1 bump
for the same binary-foundryup breakage.
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