Repository navigation
Conversation
Collaborator
Author
|
I think this is an interesting approach but needs more exploration. E.g. I would like to make it so that |
cburgdorf
force-pushed
the
std-access-control
branch
2 times, most recently
from
October 3, 2026 01:03
90d34bb to
c343d03
Compare
Port Solady's Ownable and OwnableRoles with authorization as values
instead of modifiers. Ownable::authorize checks the caller and returns
an OnlyOwner proof; Roles::authorize<ROLES> returns a Role<ROLES> proof.
Only std can construct either, and privileged code declares the proof it
needs as an effect, so reaching it without authorizing first is a
compile error, and every function that can reach it says so in its
signature:
fn mint(to: Address, amount: u256) uses (minter: Role<MINTER>, ...)
with (Role<MINTER> = roles.authorize<MINTER>()) { mint(to, amount) }
Ownable covers one-step transfer, renouncing and Solady's two-step
handover with a 48-hour window. Roles keeps per-account role bit sets
that the owner grants and revokes and accounts can renounce; a
Role<ROLES> with several bits accepts any of them. Errors and events
match Solady's.
cburgdorf
force-pushed
the
std-access-control
branch
from
October 16, 2026 22:11
c343d03 to
f8e3c5f
Compare
This branch has not been deployed
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.
Add
std::evm::auth: ownership and role-based access control as capabilitiesPorts Solady's
OwnableandOwnableRolesto Fe, but expresses authorization as a value checked by the type system instead of a modifier.Motivation
In Solidity, access control is a modifier on the public entry point:
The protection sits on the entry point, not on the privileged logic.
_mintitself is unprotected, and a second entry point or helper that reaches it without the modifier compiles fine. Missing access checksare a recurring audit finding.
Design
Authorization produces a proof value that only
std::evm::authcan construct (its fields are private):Ownable::authorize()checks the caller and returns anOnlyOwner.Roles::authorize<ROLES>()checks the caller's role bits and returns aRole<ROLES>.Privileged code declares the proof it needs as an effect. Effects are resolved by type, so the call only compiles where such a proof is in scope:
Every function that can reach
minthas to listRole<MINTER>in itsusesclause or provide it withwith, so privileged code paths are visible in signatures.What the compiler rejects
Verified manually:
mint(...)without providing the proofmissing effect Role<MINTER> required by mintOnlyOwner { owner: ... }owner is not visibleRole<BURNER>)missing effect Role<MINTER>API
Ownable(storage component, used as a contract field)init_owner(owner): sets the initial owner, emitsOwnershipTransferred(0, owner)owner(),authorize(),try_authorize()transfer_ownership(new_owner)andrenounce_ownership(), both requiringOnlyOwnerrequest_handover(),cancel_handover(),complete_handover(pending_owner)(requiresOnlyOwner),handover_expiry(pending_owner); requests are valid for 48 hoursRolesgrant_roles/revoke_rolesrequireOnlyOwner;Rolesdoes not depend onOwnableexcept through that effect typerenounce_roles(roles)lets accounts drop their own rolesroles_of,has_any_role,has_all_rolesauthorize<ROLES>()accepts callers holding any bit ofROLES, soRole<MINTER | BURNER>admits bothErrors (
Unauthorized()=0x82b42900,NewOwnerIsZeroAddress(),NoHandoverRequest()) and events (OwnershipTransferred,OwnershipHandoverRequested,OwnershipHandoverCanceled,RolesUpdated) matchSolady. The storage layout is Fe's own, not Solady's slots.
Gas
Compared against the same contract written with hand-rolled
if caller != owner/ role-bit checks, with identical events and errors:The proof values are optimized away; the cost is the check you would write by hand.
Limitations
OnlyOwnerorRole<...>yields a proof without callingauthorize(). Storage is zero-initialized, so such a field works as a validproof even if nothing was ever written to it. Fe currently has no way to mark a type as non-storable. The guarantee therefore protects against forgotten checks, not against a contract that declares a
proof-typed storage field. A language-level marker for call-scoped values would close this; happy to discuss.
StorageMapfrom amut selfmethod on a struct that also has a scalar field, which the borrow checker currently rejects. With Separate StorageMap slots from contract fields in borrow checking #1659 merged, all testspass.