Skip to content

feat(id): currency.rate_authorisation + revoke types and fold (#3800) - #3888

Merged
dezren39 merged 4 commits into
mainfrom
queue/5789-3800-rate-authorisation
Nov 1, 2026
Merged

dezren39 merged 4 commits into
mainfrom
queue/5789-3800-rate-authorisation

Conversation

@dezren39

@dezren39 dezren39 commented Nov 1, 2026 •

Copy link
Copy Markdown
Member

Phase 1 of the #2290 RateAuthorisation set. Design record: task 5741 triage comment on #2290; field semantics: #2063 §2. Library-only in pkgs/id — no gateway or control-plane code (Phases 2–3 are #3801 / task 5790 and #3802 / task 5791).

What

New module pkgs/id/src/currency.rs, following the attestation.rs precedent (signed objects as ordinary chain events, state computed by a fold over the objects alone):

  • currency.rate_authorisation — RateAuthorisation body: authorisation_id (u128, stable across versions), version (monotonic), issuer_id (verifying-key bytes; must equal the event author), source_ledger / dest_ledger (one direction only), rate_num / rate_den (u128), min_amount / max_amount, total_cap, authorised_callers (Any | Allowlist | Single), not_before + mandatory expires_at, optional reversal_window_secs and fee_bps.
  • currency.rate_authorisation_revoke — RateAuthorisationRevoke body: {authorisation_id, revoked_version_from, effective_at, reason}.
  • fold_authorisation — live object = highest valid version; an issuer-signed revoke covering that version folds Revoked (terminal — no older version revives); a body naming an issuer other than its event author is invalid and ignored, as is a revoke signed by a stranger.
  • apply_rate — floor(x · rate_num / rate_den), checked arithmetic, rounding down per id: design: conversion engine — linked transfer pairs, rate authorisation, liquidity accounts #2063 §2.
  • Sign helpers (sign_authorisation / sign_revoke) mirroring attestation's.

Tests

cargo test --lib currency:: on the laptop: 7/7 pass —

  • Golden forward: ABC→123 at 0.8123 (8123/10000), 100 → 81 (floor).
  • Golden reverse: separate object 123→ABC at 1.20 (120/100), 100 → 120; neither direction implies the other (folding one id never sees the other).
  • Body issuer ≠ event author → invalid, ignored by the fold.
  • Superseded version does not fold as live.
  • Revoked authorisation folds as revoked from its effective version.
  • Revoke signed by a stranger does not revoke.
  • Signed-event round trip through the fold.

Queue: task 5789 (repo-health-code-pilot), lane A.

Closes #3800


View with [code]smith Autofix with [code]smith
Need help on this PR? Tag @codesmith-bot with what you need.

Phase 1 of the #2290 RateAuthorisation set (design record: task 5741
on #2290; field semantics #2063 section 2). Library-only in pkgs/id:

- RateAuthorisation body: authorisation_id (u128, stable across
  versions), version, issuer_id (must equal event author),
  source/dest ledgers (one direction only), rate_num/rate_den (u128),
  min/max amount, total_cap, authorised_callers (any|allowlist|single),
  not_before + mandatory expires_at, optional reversal_window_secs
  and fee_bps.
- RateAuthorisationRevoke body: {authorisation_id,
  revoked_version_from, effective_at, reason}.
- fold_authorisation: live = highest valid version; an issuer-signed
  revoke covering it folds Revoked (terminal, no older version
  revives); bodies naming another issuer are invalid and ignored.
- apply_rate: floor(x * rate_num / rate_den), checked.

Golden tests: ABC->123 at 0.8123 (8123/10000; 100 -> 81) and the
separate reverse 123->ABC at 1.20; issuer-mismatch invalid;
superseded not live; revoked folds revoked; stranger revoke ignored;
signed-event round trip. 7/7 pass (cargo test --lib currency::).
@dezren39
dezren39 requested a review from a team as a code owner November 1, 2026 17:40
@coderabbitai

coderabbitai Bot commented Nov 1, 2026 •

Copy link
Copy Markdown

Warning

Review limit reached

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Next included review available in 56 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used the included review currently available.

Learn how review limits work.

Review configuration:

Run configuration
  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: ac0940d4-8f24-404b-9544-243002638c19
Commits

Reviewing files that changed from the base of the PR and between f3e9c19 and acf6d40.

Files selected for processing: 3
  • pkgs/id/src/currency.rs
  • pkgs/id/src/idset.rs
  • pkgs/id/src/lib.rs
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 1, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-01T23:14:10.856829Z acf6d40 New commits
ℹ️ About Codex in GitHub

Your team has set up Codex to 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" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector chatgpt-codex-connector 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.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: e955216d9d

ℹ️ About Codex in GitHub

Your team has set up Codex to 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 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread pkgs/id/src/currency.rs Outdated
Comment on lines +280 to +283
.filter(|(_, body)| body.authorisation_id == authorisation_id)
.filter(|(author, body)| body.validate(author).is_ok())
.max_by_key(|(_, body)| body.version)?;
let issuer = live.1.issuer_id;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Bind version selection to the expected issuer

When objects from multiple signers are folded, another signer can reuse an existing authorisation_id, set issuer_id to their own key, and publish a higher version. This passes validate and replaces the original LP's authorisation; the subsequent revoke filter also switches to the new signer, so even a revoked authorisation becomes Live. Matching the body issuer to its own event author does not establish ownership of the existing ID. Require an expected issuer (or an issuer-scoped authorisation key) and filter by it before selecting the highest version.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Fixed in ea1f298 (queue task 5789, lane E): fold_authorisation now takes an expected_issuer and filters version selection to objects whose event author is that issuer before choosing the highest version — a foreign signer reusing the authorisation_id can no longer displace the original issuer's authorisation, and revokes are likewise bound to the expected issuer. Regression test: foreign_signer_cannot_hijack_authorisation_id. Currency tests 9/9 pass on laptop.

Comment thread pkgs/id/src/currency.rs Outdated
.filter(|(author, _)| *author == issuer)
.filter(|(_, body)| body.authorisation_id == authorisation_id)
.filter(|(_, body)| body.revoked_version_from <= live.1.version)
.min_by_key(|(_, body)| body.revoked_version_from);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Preserve the earliest effective covering revocation

When multiple issuer-signed revokes cover the selected version, choosing the smallest revoked_version_from can discard an earlier effective revocation. For example, for version 2, a revoke from version 2 effective at time 100 and another from version 1 effective at time 200 produce a folded effective_at of 200, although version 2 was already revoked at 100. Consumers using the returned timestamp cannot enforce the correct cutoff because the earlier revoke has been discarded. Select the earliest effective covering revoke, with a deterministic tie-breaker.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Fixed in ea1f298 (queue task 5789, lane E): covering-revoke selection now picks the earliest effective_at (deterministic tie-break: smallest revoked_version_from) instead of the smallest revoked_version_from, so an earlier effective revocation is never discarded. Regression test: earliest_effective_covering_revoke_wins (from=2 @ t=100 vs from=1 @ t=200 folds effective_at=100). Currency tests 9/9 pass on laptop.

…voke (#3800)

Codex findings on PR #3888: (P1) fold_authorisation now takes expected_issuer and filters version selection to that issuer before choosing the highest version, so a foreign signer reusing an authorisation_id cannot hijack the fold; (P2) covering revoke selection picks the earliest effective_at (tie-break smallest revoked_version_from) instead of the smallest revoked_version_from. Adds regression tests for both; currency tests 9/9 on laptop.
…authorisation

# Conflicts:
#	pkgs/id/src/lib.rs
Main added ChainExt.note: currency.rs sign helpers now set note: None, and the merge had silently dropped note: None from an idset.rs test literal (restored; file matches main again).
@dezren39
dezren39 merged commit c7f7e1f into main Nov 1, 2026
1 check passed
@dezren39
dezren39 deleted the queue/5789-3800-rate-authorisation branch November 1, 2026 23:13
@dezren39
dezren39 restored the queue/5789-3800-rate-authorisation branch November 8, 2026 04:20
@dezren39
dezren39 deleted the queue/5789-3800-rate-authorisation branch November 9, 2026 13:17
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.

id(currency): RateAuthorisation + revoke schema types and fold in pkgs/id (Phase 1 of #2290)

1 participant