AccessControlManager
AccessControlManager
Section titled “AccessControlManager”This page follows AccessControlManager.sol at governance-contracts v2.15.0. The BNB mainnet instance uses an older deployed ABI without hasPermission; the destination-mainnet v2.15.0 artifacts include that selector. isAllowedToCall remains the permission hook on both generations.
Access control plays a crucial role in the Venus governance model. It is used to restrict functions so that they can only be called from one account or list of accounts (EOA or Contract Accounts).
The AccessControlManager implementation
inherits the Open Zeppelin AccessControl
contract as a base for role management logic. There are two role types: admin and granular permissions.
Granular Roles
Section titled “Granular Roles”Granular roles are built by hashing the contract address and its function signature. For example, given contract Foo with function Foo.bar() which
is guarded by ACM, calling giveCallPermission for account B does the following:
- Compute
keccak256(abi.encodePacked(contractFooAddress, functionSignatureBar)) - Add the computed role to the roles of account B
- Account B now can call
ContractFoo.bar()
Admin Roles
Section titled “Admin Roles”Admin roles allow for an address to call a function signature on any contract guarded by the AccessControlManager. This is particularly useful for
contracts created by factories.
For Admin roles a null address is hashed in place of the contract address (keccak256(0x0000000000000000000000000000000000000000,functionSignatureBar).
In the previous example, giving account B the admin role, account B will have permissions to call the bar() function on any contract that is guarded by
ACM, not only contract A.
Protocol Integration
Section titled “Protocol Integration”All restricted functions in Venus Protocol use a hook to ACM in order to check if the caller has the right permission to call the guarded function.
AccessControlledV5 and AccessControlledV8 abstract contract makes this integration easier. They call ACM’s external method
isAllowedToCall(address caller, string functionSig). Here is an example of how setCollateralFactor function in Comptroller is integrated with ACM:
contract Comptroller is [...] AccessControlledV8 { [...] function setCollateralFactor(VToken vToken, uint256 newCollateralFactorMantissa, uint256 newLiquidationThresholdMantissa) external { _checkAccessAllowed("setCollateralFactor(address,uint256,uint256)"); [...] } }Solidity API
Section titled “Solidity API”giveCallPermission
Section titled “giveCallPermission”Gives a function call permission to one single account
function giveCallPermission(address contractAddress, string functionSig, address accountToPermit) publicParameters
Section titled “Parameters”| Name | Type | Description |
|---|---|---|
| contractAddress | address | address of contract for which call permissions will be granted |
| functionSig | string | signature e.g. “functionName(uint256,bool)” |
| accountToPermit | address | account that will be given access to the contract function |
📅 Events
Section titled “📅 Events”- Emits a {RoleGranted} and {PermissionGranted} events.
revokeCallPermission
Section titled “revokeCallPermission”Revokes an account’s permission to a particular function call
function revokeCallPermission(address contractAddress, string functionSig, address accountToRevoke) publicParameters
Section titled “Parameters”| Name | Type | Description |
|---|---|---|
| contractAddress | address | address of contract for which call permissions will be revoked |
| functionSig | string | signature e.g. “functionName(uint256,bool)” |
| accountToRevoke | address |
📅 Events
Section titled “📅 Events”- Emits {RoleRevoked} and {PermissionRevoked} events.
isAllowedToCall
Section titled “isAllowedToCall”Verifies if the given account can call a contract’s guarded function
function isAllowedToCall(address account, string functionSig) public view returns (bool)Parameters
Section titled “Parameters”| Name | Type | Description |
|---|---|---|
| account | address | for which call permissions will be checked |
| functionSig | string | restricted function signature e.g. “functionName(uint256,bool)” |
Return Values
Section titled “Return Values”| Name | Type | Description |
|---|---|---|
| [0] | bool | false if the user account cannot call the particular contract function |
hasPermission
Section titled “hasPermission”Verifies if the given account can call a contract’s guarded function
This convenience view exists in the current source and destination-mainnet deployments. It is not present in the BNB mainnet AccessControlManager ABI; offchain tools querying that instance must compute the role and use hasRole, or call the guarded contract’s normal permission path.
function hasPermission(address account, address contractAddress, string functionSig) public view returns (bool)Parameters
Section titled “Parameters”| Name | Type | Description |
|---|---|---|
| account | address | for which call permissions will be checked against |
| contractAddress | address | address of the restricted contract |
| functionSig | string | signature of the restricted function e.g. “functionName(uint256,bool)” |
Return Values
Section titled “Return Values”| Name | Type | Description |
|---|---|---|
| [0] | bool | false if the user account cannot call the particular contract function |