Propose composite policy interface (UNION/INTERSECT)#174
Conversation
Interface-only proposal for composite policies on IPolicyRegistry: - Extend PolicyType with UNION and INTERSECT (append-only; leaf discriminants 0/1 unchanged, gate rides the policy ID top byte). - Add createCompositePolicy(admin, gate, operands) and updateCompositeOperands(policyId, operands). Update is a full-set overwrite (replace-all), re-validated as at creation. - Add CompositePolicyCreated and CompositeOperandsUpdated events, and EmptyOperandSet / InvalidOperand errors. - Note on createPolicy/createPolicyWithAccounts that composite gates revert IncompatiblePolicyType. Operands are flat-only (leaf ALLOWLIST/BLOCKLIST), capped at the composite operand limit, and the set may not be empty. This changes only the interface; MockPolicyRegistry and the Rust precompile implementation follow in a separate PR, so the mock will not compile against this interface until then. Generated with Claude Code Co-Authored-By: Claude <noreply@anthropic.com>
Interface Coverage❌ Interface functions with no test coverage found. |
❌ Fork tests did not runThe build or setup step failed before any tests could execute. Check the workflow logs for details. |
| function createPolicy(address admin, PolicyType policyType) external returns (uint64 newPolicyId); | ||
|
|
||
| /// @notice Creates a new policy seeded with `accounts` as initial members. Permissionless. | ||
| /// @notice Creates a new leaf policy seeded with `accounts` as initial members. Permissionless. |
There was a problem hiding this comment.
Remove leaf here
Drop the "not an incremental edit" binary contrast and the "silently" adverb; make the flat-only note active. Wording only, no signature or behavior change. Generated with Claude Code Co-Authored-By: Claude <noreply@anthropic.com>
|
|
||
| /// @notice A composite policy (UNION or INTERSECT) was created over `operands`. | ||
| event CompositePolicyCreated( | ||
| uint64 indexed policyId, address indexed creator, PolicyType policyType, uint64[] operands |
There was a problem hiding this comment.
feel like I want to see the clarification of "policy" in there
| uint64 indexed policyId, address indexed creator, PolicyType policyType, uint64[] operands | |
| uint64 indexed policyId, address indexed creator, PolicyType policyType, uint64[] operandPolicies |
There was a problem hiding this comment.
Do we even need this event? Why not just use PolicyCreated as-is and then combine with the event below for declaring operand policies updated?
There was a problem hiding this comment.
I think we can use policy created. Only thing is I would assume a user want's an event that lists the new childPolicyIds for the composite, when a policy is created / updated.
There was a problem hiding this comment.
The existing PolicyCreated event does declare the policy type so I think your goal is met as-is
There was a problem hiding this comment.
But it wouldn't solve the event that the user can see the new childPoloicyId's
There was a problem hiding this comment.
Updated to PolicyCreated, and a UpdateCompositePolicyEvent both being emitted
Co-authored-by: katzman <steve.katzman@coinbase.com>
Co-authored-by: Conner Swenberg <conner.swenberg@coinbase.com>
Co-authored-by: katzman <steve.katzman@coinbase.com>
Co-authored-by: Conner Swenberg <conner.swenberg@coinbase.com>
| /// @notice A composite policy (UNION or INTERSECT) was created over `childPolicyIds`. | ||
| event CompositePolicyCreated( | ||
| uint64 indexed policyId, address indexed creator, PolicyType policyType, uint64[] childPolicyIds | ||
| ); |
There was a problem hiding this comment.
Seems to ignore discussion here: #174 (comment).
As we keep adding policy types with more nuance, we'll continually run up against the desire to have custom created events that have all of the content of PolicyCreated, but with a new field(s). I think we should take the opinionated stance that we have one canonical creation event (PolicyCreated) and we use *Updated events for the type-specific field(s). This gives indexers the cleanest experience where this is only one path for creation to look at ever and only one path for field updates to look at (regardless of creation/update).
| /// @notice A composite policy (UNION or INTERSECT) was created over `childPolicyIds`. | |
| event CompositePolicyCreated( | |
| uint64 indexed policyId, address indexed creator, PolicyType policyType, uint64[] childPolicyIds | |
| ); |
There was a problem hiding this comment.
So the create function fires two events fires two events, Created and UpdatePolicy ?
Use the canonical PolicyCreated event for every policy type and surface composite child policies via CompositePolicyUpdated (now emitted on both creation and update). Gives indexers one creation path and one per-field update path. Addresses PR #174 review. Generated with Claude Code Co-Authored-By: Claude <noreply@anthropic.com>
| /// @param provided Number of child policy IDs supplied. | ||
| /// @param minimum Minimum required (2). | ||
| error TooFewChildPolicies(uint256 provided, uint256 minimum); |
There was a problem hiding this comment.
I don't think this error needs params. The natspec says you need at least two and the user will know how many they provided.
There was a problem hiding this comment.
Is there any, downside of having it ?
There was a problem hiding this comment.
gas if a reverting tx ever lands onchain
| /// @dev Reverts with `PolicyNotFound` when any child policy does not exist. | ||
| /// @dev Reverts with `InvalidChildPolicy` when any child policy is itself a composite | ||
| /// (not a simple policy). | ||
| /// @dev Panics with arithmetic overflow (Panic 0x11) when the policy counter has reached its maximum value. |
There was a problem hiding this comment.
Aren't we going to explicitly check that 2 < childPolicyIds <= 4? What risk is there of overflow?
There was a problem hiding this comment.
They share the create counter which can overflow
There was a problem hiding this comment.
oooh for the global policy id. i don't think this needs explicit callout here...
Co-authored-by: katzman <steve.katzman@coinbase.com>
Co-authored-by: katzman <steve.katzman@coinbase.com>
Co-authored-by: katzman <steve.katzman@coinbase.com>
Co-authored-by: katzman <steve.katzman@coinbase.com>
…com/base/base-std into composite-policy-interface-proposal
Proposal (interface-only)
Adds the composite-policy surface to
IPolicyRegistryas a design proposal. This PR changes only the interface — noMockPolicyRegistryor Rust precompile implementation — so the mock will not compile against it until a follow-up lands. Opened as a draft for design review.What changes
PolicyTypegainsUNIONandINTERSECT. Append-only: leaf discriminants (BLOCKLIST=0,ALLOWLIST=1) are unchanged, and the gate rides the policy ID top byte, so composites need no separate type storage.createCompositePolicy(address admin, PolicyType gate, uint64[] operands)— creates a UNION/INTERSECT over existing flat leaf policies (never other composites). Operands reference smaller, already-assigned IDs, so the reference graph is a DAG and cannot cycle.updateCompositeOperands(uint64 policyId, uint64[] operands)— replace-all: overwrites the whole operand set, re-validated exactly as at creation. The gate is fixed in the ID and cannot change.CompositePolicyCreated,CompositeOperandsUpdated(carries the full post-update set for single-log indexing).EmptyOperandSet,InvalidOperand(operandId).createPolicy/createPolicyWithAccountsnow notes they revertIncompatiblePolicyTypefor composite gates.Why replace-all for update
Operands live in a
uint64[](evaluation folds them in order). The registry has nouint64[]-mutation code today, so incremental add/remove would introduce the module's first swap-remove + length + dedup path. With the operand set capped small, sending the full list is the simpler design and reuses create's validation. Mirrors theIB20.updatePolicyfull-replace precedent over theupdateAllowlistincremental one.Open question for reviewers
The
CompositeOperandsUpdatedevent carries new operands only. A design council flagged anold → newshape (matchingupdatePolicy) as an option that closes a silent lost-update detection gap, at the cost of one warm SLOAD. Event surface is frozen at the fork, so this is worth settling before implementation.Follow-ups (not in this PR)
MockPolicyRegistryimplementation +test/unit/PolicyRegistry/tests (create, update, revert-order, fold truth tables).V2(versioned, new fork),composite_operandsstorage slot, dispatcher wiring.Generated with Claude Code