Access Controls

The Access Control system implements granular, function-level permissions across all contracts of Cap. It provides a sophisticated role-based access control mechanism that allows precise management of who can call specific functions on specific contracts, building on OpenZeppelin's AccessControlEnumberablearrow-up-right Integration.

Roles are managed by the Access Control admin, currently set to Cap's multisig address

Mechanics

  • Each function on each contract has its own unique 32-byte role ID

  • The role ID is generated by combining:

    • The function selector (first 4 bytes of the function signature)

    • The contract address

  • Permissions can be granted/revoked at the function level

  • Contracts inherit access control through the Access abstract contract and uses the checkAccess modifier on protected functions

Architecture

  • Access.sol: Inheritable abstract contract that provides the base functionality for access control

  • AccessControl.sol: Central contract that implements the access control logic

Access Control

Core Functions

grantAccess: Grants permission to call a specific function on a specific contract

  • _selector: Function selector (4-byte identifier) of the method to grant access to

  • _contract: Address of the contract containing the method

  • _address: Address to grant access to

revokeAccess: Revokes permission to call a specific function on a specific contract

  • _selector: Function selector (4-byte identifier) of the method to revoke access from

  • _contract: Address of the contract containing the method

  • _address: Address to revoke access from

checkAccess: Verifies if an address has permission to call a specific function

  • Returns: True if access is granted, false otherwise

When a access controlled function is called, the checkAccess modifier calls _checkRolearrow-up-right with the function's selector, contract and message sender.

role: Gets the role identifier for a specific function selector on a contract

  • _selector: Function selector (4-byte identifier) of the method

  • _contract: Address of the contract containing the method

  • Returns: Unique role identifier derived from selector and contract address

Role Hierarchy

  1. DEFAULT_ADMIN_ROLE: Can upgrade the AccessControl contract

  2. Access Management Roles: Can grant/revoke permissions

  3. Function-Specific Roles: Control access to individual functions

Permission Types

1. Administrative Permissions

  • Contract upgrades (bytes4(0))

  • Access management (grantAccess, revokeAccess)

2. Operational Permissions

  • Vault operations (borrow, repay, mint, burn)

  • Oracle managements (setOracleData, setStaleness, setRates)

  • Asset management (addAsset, removeAsset, pauseAsset, setReserve)

  • Fee Auctions (setDuration, setStartPrice ,setPaymentToken)

  • Delegations ( addAgent, modifyAgent ,registerNetwork)

3. Emergency Permissions

  • Protocol pause (pauseProtocol, unpauseProtocol)

  • Emergency functions (emergencyWithdraw, rescueERC20)

Last updated