PoC: IPolicyRegistry with AND/OR composition + stateful primitives forward-compat#5
Draft
amiecorso wants to merge 1 commit into
Draft
PoC: IPolicyRegistry with AND/OR composition + stateful primitives forward-compat#5amiecorso wants to merge 1 commit into
amiecorso wants to merge 1 commit into
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
PoC for the future-extensible IPolicyRegistry design discussed in chat. Goal: structure the registry interface so we can ship a minimal v1 (just adds the redeemer slot to compound) without locking ourselves out of the obvious next year of evolution (rate limits, time locks, amount caps, AND/OR composition).
Not for merge. Posting so the team can react to the design before we commit to anything.
What ships in v1 (the only structural change)
redeemerPolicyIdslot. Required for the redeem-on-default work in Apply PRD DEFAULT row decisions across token interfaces #3.What's drafted as forward-compat (signatures present, implementations stub until future hardforks)
MAX_COMBINATOR_CONSTITUENTSandMAX_COMPOSITION_DEPTH. Cycles structurally impossible (every constituent must already exist when the combinator is created, so the policy graph is a DAG with edges always pointing from higher IDs to lower).Key forward-compat property
The hot-path authorize signatures take `amount` from day one even though no v1 policy uses it. This means tokens written today work with policies invented in 2027 without any code or ABI changes. New stateful policy types just plug into the existing graph composition.
Composition example: "KYC AND rate-limit on sender, KYC on recipient"
```
kycPolicyId = createPolicy(adminAddr, WHITELIST) // ID 17
rateLimitPolicyId = createRateLimitPolicy(adminAddr, 1000e6, 86400) // ID 23
senderAndPolicyId = createAndPolicy([17, 23]) // ID 31
compoundPolicyId = createCompoundPolicy(
senderPolicyId = 31, // AND[KYC, rate-limit]
recipientPolicyId = 17, // KYC only
mintRecipientPolicyId = 1, // always-allow
redeemerPolicyId = 0 // no redemption
) // ID 47
token.changeTransferPolicyId(47)
```
Token only ever stores ONE policy ID. The composition tree lives in the registry. AND/OR can nest arbitrarily up to `MAX_COMPOSITION_DEPTH` (sketched as 8 levels).
Notable design decisions
Open questions
Status
Draft. Looking for team reaction on the overall shape before committing to any of this.