fix: reject composite policyType in createPolicy / createPolicyWithAccounts#176
Open
rayyan224 wants to merge 1 commit into
Open
fix: reject composite policyType in createPolicy / createPolicyWithAccounts#176rayyan224 wants to merge 1 commit into
rayyan224 wants to merge 1 commit into
Conversation
…counts The IPolicyRegistry natspec documents that createPolicy and createPolicyWithAccounts revert IncompatiblePolicyType for composite gates (UNION/INTERSECT), but the mock never enforced it — a caller could mint a degenerate 0-child composite whose isAuthorized short-circuits. Add the guard to both simple-policy constructors (after the zero-admin check, before the batch-size check), factor out _isCompositeType, and cover it with revert + revert-order tests. Addresses #174 (comment) Generated with Claude Code Co-Authored-By: Claude <noreply@anthropic.com>
rayyan224
requested review from
amiecorso,
eric-ships,
ilikesymmetry and
stevieraykatz
as code owners
July 24, 2026 22:17
Interface Coverage✅ All interface functions have test coverage. |
📊 Forge Coverage (
|
| File | Lines | Stmts | Branches | Funcs |
|---|---|---|---|---|
| 🟢 B20FactoryLib.sol | 100.00% | 100.00% | 100.00% | 100.00% |
| 🔴 test/lib/ForceFeeder.sol | 0.00% | 0.00% | 100.00% | 0.00% |
| 🔴 test/lib/PrecompileProbe.sol | 0.00% | 0.00% | 0.00% | 0.00% |
| 🟢 MockActivationRegistry.sol | 100.00% | 100.00% | 100.00% | 100.00% |
| 🟢 MockActivationRegistryStorage.sol | 100.00% | 100.00% | 100.00% | 100.00% |
| 🟢 MockB20.sol | 100.00% | 100.00% | 100.00% | 100.00% |
| 🟢 MockB20Asset.sol | 100.00% | 100.00% | 100.00% | 100.00% |
| 🟡 MockB20Factory.sol | 98.96% | 99.10% | 100.00% | 100.00% |
| 🟢 MockB20Stablecoin.sol | 100.00% | 100.00% | 100.00% | 100.00% |
| 🟢 MockB20Storage.sol | 100.00% | 100.00% | 100.00% | 100.00% |
| 🟡 MockPolicyRegistry.sol | 100.00% | 99.52% | 97.56% | 100.00% |
| 🟢 MockPolicyRegistryStorage.sol | 100.00% | 100.00% | 100.00% | 100.00% |
| Total | 96.92% | 97.38% | 97.84% | 97.06% |
Full report: download artifact. To browse locally: make coverage (runs forge coverage + genhtml + opens the HTML report).
❌ Fork tests did not runThe build or setup step failed before any tests could execute. Check the workflow logs for details. |
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
Addresses @robriks' review comment on #174 (#174 (comment)).
The
IPolicyRegistrynatspec states thatcreatePolicyandcreatePolicyWithAccountsrevertIncompatiblePolicyTypewhenpolicyTypeis a composite gate, butMockPolicyRegistrynever enforced it:A 0-child composite is degenerate:
isAuthorizedfolds an empty child set (UNION → false, INTERSECT → true), silently minting an always-deny / always-authorize policy.Changes
MockPolicyRegistry:createPolicyandcreatePolicyWithAccountsnow revertIncompatiblePolicyTypefor UNION/INTERSECT, matching the documented precedence — after the zero-admin check, and (forcreatePolicyWithAccounts) before the batch-size check. Factored the type test into a shared_isCompositeType(PolicyType)helper (reused bycreateCompositePolicyand_isComposite).test_createPolicy_revert_incompatiblePolicyTypeandtest_createPolicyWithAccounts_revert_incompatiblePolicyType, and extended both*_revertOrderwalks with the new step.Composites remain creatable only through
createCompositePolicy, which requires a UNION/INTERSECT gate and a[2, 4]child set.Testing
forge test→ 661 passed, 0 failed, 4 skipped.python3 script/check-coverage.py→ all covered (exit 0).forge fmt --checkclean.