Skip to content

fix: no re-verification under the locks in policy mint and registration (TC-2986 F) - #596

Merged
samgbafa merged 2 commits into
mainfrom
feat/tc-2986-mint-no-revalidation
Nov 13, 2026
Merged

samgbafa merged 2 commits into
mainfrom
feat/tc-2986-mint-no-revalidation

Conversation

@samgbafa

@samgbafa samgbafa commented Nov 13, 2026 •

Copy link
Copy Markdown
Contributor

Linear: TC-2986 (item F; parent TC-2954). Stacked on #595 (E): it uses E's PreVerified. Review the top commit; retarget to main once #595 merges.

Behaviour

POST /policy/v3/delegations (mint) evaluates the request before BEGIN:

  • the claim, or credential admission v3/v4, plus the presentation;
  • the requested capabilities against the ceiling;
  • the allow decision;
  • the roots' signatures (authorize_roots → validate_persisted_root).

Under the locks (sequence locks, then FOR UPDATE on the challenge, registration and both roots), it used to run all of that again on the same caller JSON. Now:

  • Kept under the locks. The existing equality checks stay:
    • the challenge's fields;
    • the registration's policy bytes, root CIDs and enforcer binding;
    • the roots' projection (CID ↔ bytes, policy, node audience, role) and their time window;
    • liveness, revocation and freshness, and the admission-epoch compare-and-swap;
    • the account-owner re-check.
  • Not re-run under the locks:
    • the root signatures. The CID content-addresses the bytes authorize_roots verified, so validate_verified_persisted_root checks everything except the signature.
    • the claim/presentation, credential admission, requested-capability and allow evaluations. They are deterministic in inputs the checks above prove equal, at the same now. The two "changed" refusals (credential-evaluation-changed, policy-evaluation-changed) could therefore never fire, and are removed.
  • Node-minted session: its signature is verified before the locks (preverify_delegation) and passed as pre-verified, so the graph registration does not verify it under them.

POST /policy/v3/policies (register):

  • The two roots are verified before any lock by preverify_root. It enforces the same rules (UCAN, time window, signature) and the same refusal codes, with the signature checked by the core.
  • The registration's transaction registers them as pre-verified, so it no longer verifies them again under the sequence locks.

Core:

  • PreVerified is public, with union.
  • New: SpaceDatabase::preverify_delegation and delegate_batch_in_transaction_verified.
  • delegate_batch_in_transaction keeps its behaviour, verifying everything.

Tests

New, tinycloud-node-server/src/policy_v3/mint_locked_inputs_tests.rs (SQLite and PostgreSQL). Each test holds the content space's write order, sends a mint, changes one input of the dropped in-lock evaluations once the mint waits, then releases the order:

  • a_challenge_changed_while_the_mint_waits_is_refused: the challenge's expiry moves later. The checks before the locks accept it, so only the comparison under the locks refuses the mint: 401 challenge-invalid, no session stored.
  • a_registration_changed_while_the_mint_waits_is_refused: the attested enforcer binding is rewritten as the same JSON with other whitespace. That's still valid, but the bytes changed: 409 policy-registration-changed, no session stored.
  • a_root_revoked_while_the_mint_waits_is_refused: the policy root is revoked after its signature and state were checked, before BEGIN: 403 root-revoked, no session stored.
  • a_registration_repointed_while_the_mint_waits_is_refused (from Bobbie's review, M2a): the registration's policy root CID is repointed at another live registered root: 409 policy-registration-changed. This covers a gap that predates this PR.
  • root_bytes_replaced_while_the_mint_waits_are_refused (from Bobbie's review, M2b): the root row's bytes are replaced by the same root with a forged signature: 403 policy-root-projection-mismatch. With the signature no longer re-checked under the locks, the binding of the stored bytes to the registration's root CID is what refuses them. Without that binding, the existing suite stays green and the forged root is admitted.

The core side of the CID binding (a PreVerified for one delegation doesn't cover another, M4b) is tested in #595: a_pre_verified_delegation_does_not_cover_another.

In the first two, a change that landed before the mint's checks would let the mint succeed and fail the test, so they can't pass by timing.

There's no test for the CPU saved under the locks: the node has no seam to observe it without a test-only hook.

  • Coverage of unchanged behaviour: the existing Policy/v3 harness (register, mint, read, decrypt, reshare, revoke, on SQLite and PostgreSQL) and the policy unit tests, all in the node lib suite.
  • No existing test changed. The harness's register_policy_writes stays as a test-only wrapper that verifies everything.

@samgbafa
samgbafa force-pushed the feat/tc-2986-mint-no-revalidation branch from 092db6a to 46c89c9 Compare November 13, 2026 19:44
@samgbafa
samgbafa force-pushed the feat/tc-2986-verify-before-locks branch from b626aa3 to 95ba3f8 Compare November 13, 2026 20:09
@samgbafa
samgbafa force-pushed the feat/tc-2986-mint-no-revalidation branch from 46c89c9 to 710be12 Compare November 13, 2026 20:09
@samgbafa
samgbafa force-pushed the feat/tc-2986-verify-before-locks branch from 95ba3f8 to c109828 Compare November 13, 2026 22:11
@samgbafa
samgbafa force-pushed the feat/tc-2986-mint-no-revalidation branch from 710be12 to 8a3558e Compare November 13, 2026 22:11
@samgbafa
samgbafa changed the base branch from feat/tc-2986-verify-before-locks to main November 13, 2026 22:39
@samgbafa samgbafa closed this Nov 13, 2026
@samgbafa samgbafa reopened this Nov 13, 2026
@samgbafa
samgbafa force-pushed the feat/tc-2986-mint-no-revalidation branch from 8a3558e to 520cc64 Compare November 13, 2026 23:05
@samgbafa
samgbafa marked this pull request as ready for review November 13, 2026 23:06
@samgbafa
samgbafa merged commit c92e768 into main Nov 13, 2026
28 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.

1 participant