Skip to main content

Signature

Description

Creates a composite policy that evaluates authorization by combining the results of two to four existing simple policies. PolicyType ABI-encodes as uint8.
  • UNION — authorizes an account if any child policy authorizes it (OR).
  • INTERSECT — authorizes an account only if every child policy authorizes it (AND).
Authorization is live: each call reads the current membership of every evaluated child. UNION short-circuits on the first authorizing child; INTERSECT short-circuits on the first non-authorizing child. Because composite children are rejected at write time, authorization never recurses beyond depth 1. A composite policy ID can be stored in a B20 policy scope exactly like a simple policy ID. B20 calls isAuthorized generically against the opaque uint64 and requires no code changes.
Always call policyExists(policyId) before storing a composite ID. A well-formed but never-created INTERSECT ID has no children and returns true, behaving identically to ALWAYS_ALLOW.

Parameters

Returns

Revert conditions

Reverts are checked in this order: Panics with Panic(0x11) (arithmetic overflow) if the policy counter has reached its maximum value.

Events emitted

Emitted in this order on success:
  1. PolicyCreated(policyId, creator, policyType)
  2. PolicyAdminUpdated(policyId, address(0), admin)
  3. CompositePolicyUpdated(policyId, creator, childPolicyIds)

Access control

Permissionless creation, but state-changing registry calls require the feature to be active.

Gas

Each child policy evaluated by isAuthorized requires a membership storage read. The worst-case cost occurs when all four children are evaluated. Place the child most likely to short-circuit first to minimize gas.

Example

Create a UNION composite policy