Skip to content

Add std::evm::auth ownership and role capabilities - #1673

Draft
cburgdorf wants to merge 4 commits into
masterfrom
std-access-control
Draft

cburgdorf wants to merge 4 commits into
masterfrom
std-access-control

Conversation

@cburgdorf

@cburgdorf cburgdorf commented Oct 1, 2026 •

Copy link
Copy Markdown
Collaborator

Add std::evm::auth: ownership and role-based access control as capabilities

Ports Solady's Ownable and OwnableRoles to 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:

  function mint(address to, uint256 amount) public onlyRoles(MINTER) { _mint(to, amount); }

The protection sits on the entry point, not on the privileged logic. _mint itself is unprotected, and a second entry point or helper that reaches it without the modifier compiles fine. Missing access checks
are a recurring audit finding.

Design

Authorization produces a proof value that only std::evm::auth can construct (its fields are private):

  • Ownable::authorize() checks the caller and returns an OnlyOwner.
  • Roles::authorize<ROLES>() checks the caller's role bits and returns a Role<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:

  const MINTER: u256 = 1 << 0

  fn mint(to: Address, amount: u256) uses (minter: Role<MINTER>, store: mut Store) { ... }

  recv Admin {
      GrantMinter { account } uses (ownable, mut roles, ctx, mut log) {
          with (OnlyOwner = ownable.authorize()) {
              roles.grant_roles(account, MINTER)
          }
      }
      Mint { to, amount } uses (roles, mut store, ctx) {
          with (Role<MINTER> = roles.authorize<MINTER>()) {
              mint(to, amount)
          }
      }
  }

Every function that can reach mint has to list Role<MINTER> in its uses clause or provide it with with, so privileged code paths are visible in signatures.

What the compiler rejects

Verified manually:

Attempt Diagnostic
Calling mint(...) without providing the proof missing effect Role<MINTER> required by mint
Forging a proof: OnlyOwner { owner: ... } owner is not visible
Providing the wrong role (Role<BURNER>) missing effect Role<MINTER>

API

Ownable (storage component, used as a contract field)

  • init_owner(owner): sets the initial owner, emits OwnershipTransferred(0, owner)
  • owner(), authorize(), try_authorize()
  • transfer_ownership(new_owner) and renounce_ownership(), both requiring OnlyOwner
  • Solady's two-step handover: request_handover(), cancel_handover(), complete_handover(pending_owner) (requires OnlyOwner), handover_expiry(pending_owner); requests are valid for 48 hours

Roles

  • Role bit sets per account, as in Solady
  • grant_roles / revoke_roles require OnlyOwner; Roles does not depend on Ownable except through that effect type
  • renounce_roles(roles) lets accounts drop their own roles
  • roles_of, has_any_role, has_all_roles
  • authorize<ROLES>() accepts callers holding any bit of ROLES, so Role<MINTER | BURNER> admits both

Errors (Unauthorized() = 0x82b42900, NewOwnerIsZeroAddress(), NoHandoverRequest()) and events (OwnershipTransferred, OwnershipHandoverRequested, OwnershipHandoverCanceled, RolesUpdated) match
Solady. 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:

Call Capabilities Hand-written Diff
Grant role (owner check) 24,650 24,645 +5
Mint (role check) 23,044 23,044 0
Transfer ownership 2,535 2,540 -5

The proof values are optimized away; the cost is the check you would write by hand.

Limitations

  • Proofs can be materialized from storage. A contract field of type OnlyOwner or Role<...> yields a proof without calling authorize(). Storage is zero-initialized, so such a field works as a valid
    proof 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.
  • Depends on Separate StorageMap slots from contract fields in borrow checking #1659. The handover methods write a StorageMap from a mut self method 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 tests
    pass.

@cburgdorf

Copy link
Copy Markdown
Collaborator Author

I think this is an interesting approach but needs more exploration. E.g. I would like to make it so that OnlyOwner Role<…> become somewhat "marked" (e.g. some special marker trait) so that one can not save them to storage. That would eliminate one possible footgun.

@cburgdorf
cburgdorf force-pushed the std-access-control branch 2 times, most recently from 90d34bb to c343d03 Compare October 3, 2026 01:03
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.

This branch has not been deployed

No deployments
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