Skip to content

feat: adopt ERC-8153 exportSelectors for on-chain facet self-description#29

Merged
dadadave80 merged 3 commits into
devfrom
feat/erc-8153-export-selectors
Jul 10, 2026
Merged

feat: adopt ERC-8153 exportSelectors for on-chain facet self-description#29
dadadave80 merged 3 commits into
devfrom
feat/erc-8153-export-selectors

Conversation

@dadadave80

Copy link
Copy Markdown
Owner

What & why

Adopts ERC-8153 "Facet-Based Diamonds" at the facet level: every facet now implements exportSelectors() external pure returns (bytes memory), reporting its own selectors on-chain. This replaces the off-chain FFI selector extraction (forge inspect via GetSelectors.sol) — removing the --ffi requirement (a Foundry security foot-gun), speeding up tests, and giving upgraders/tooling an on-chain source of truth.

The library stays ERC-2535diamondCut, the DiamondCut event, existing errors, and the loupe are unchanged. upgradeDiamond, the new facet events/errors, and the fallback rename are deliberately out of scope.

Changes

  • New IFacet + exportSelectors() on all core facets (DiamondCut, DiamondLoupe, ERC165, Ownable) and mocks. Selectors referenced as this.<fn>.selector (the one form that compiles pure for both public and external functions), self-excluded per ERC-8153.
  • New Selectors.decode helper; deleted FFI-based GetSelectors.sol.
  • Deploy script + tests read selectors via exportSelectors(); ffi = false; --ffi dropped from CONTRIBUTING.
  • New ExportSelectorsTester: exact-set (independent, non-circular), self-exclusion, ×4 invariant, decoder fuzz + revert.
  • Documented the self-reported-selector trust caveat and a selector-drift discipline rule.

Verification

forge build ✅ · forge test 91/91 ✅ (ffi disabled) · forge fmt --check ✅ · facets ≪ 24 KB ✅

Reviewed by a multi-agent (Fable) security + quality pass — verdict: meets the production bar, no critical/high/medium findings; the surfaced low/nice-to-have items are applied.

Deferred decision

A mechanical selector-drift guard (CI forge inspect methodIdentifiers cross-check) was not added because it reintroduces FFI at the CI gate — counter to this PR's goal. Mitigated instead by the independent test assertions + CONTRIBUTING rule. Open to adding it if maintainers prefer the stronger guard.

Note: pre-1.0, unaudited — do not use in production until audited.

Merge 'dev' changes to 'main'
Every facet now implements ERC-8153's `exportSelectors() external pure`,
reporting its own selectors on-chain. Selector discovery moves from the
off-chain FFI helper (`forge inspect`) to this on-chain source of truth.

- Add `IFacet` interface + `exportSelectors()` to all core facets and mocks
  (selectors referenced as `this.<fn>.selector`, self-excluded per ERC-8153)
- Add `Selectors.decode` helper; delete FFI-based `GetSelectors.sol`
- Rewire deploy script and tests to read selectors via `exportSelectors()`
- Set `ffi = false`; drop `--ffi` from CONTRIBUTING
- Add `ExportSelectorsTester` (exact-set, self-exclusion, decoder fuzz)
- Document self-reported-selector trust caveat and the selector-drift
  discipline rule

Out of scope (kept ERC-2535): upgradeDiamond, facet events/errors, loupe.
@dadadave80
dadadave80 merged commit 58de958 into dev Jul 10, 2026
2 checks passed
@dadadave80
dadadave80 deleted the feat/erc-8153-export-selectors branch July 10, 2026 22:42
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.

1 participant