|
| 1 | +# Access Control |
| 2 | + |
| 3 | +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). |
| 4 | + |
| 5 | +# Access Control Manager |
| 6 | +The implementation of [AccessControlManager](https://github.com/VenusProtocol/isolated-pools/blob/main/contracts/Governance/AccessControlManager.sol) inherits the [Open Zeppelin AccessControl](https://github.com/OpenZeppelin/openzeppelin-contracts/blob/master/contracts/access/AccessControl.sol) contract as a base for role management logic. There are two role types: admin and granular permissions. |
| 7 | + |
| 8 | +### Granular Roles |
| 9 | + |
| 10 | +Granular roles are built by hashing the contract address and its function signature. |
| 11 | +For example, Given Contract Foo with function Foo.bar() which is guarded by ACM, |
| 12 | +calling `giveRolePermission` for account B do the following: |
| 13 | +1. Compute `keccak256(contractFooAddress,functionSignatureBar)` |
| 14 | +2. Add the computed role to the roles of account B |
| 15 | +3. Account B now can call `ContractFoo.bar()` |
| 16 | + |
| 17 | +### Admin Roles |
| 18 | + |
| 19 | +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. |
| 20 | + |
| 21 | +For Admin roles a null address is hashed in place of the contract address (`keccak256(0x0000000000000000000000000000000000000000,functionSignatureBar)`. |
| 22 | + |
| 23 | +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. |
| 24 | + |
| 25 | +# Solidity API |
| 26 | + |
| 27 | + |
| 28 | + |
| 29 | +## AccessControlManager |
| 30 | + |
| 31 | + |
| 32 | + |
| 33 | +This contract is a wrapper of OpenZeppelin AccessControl extending it in a way to standardise access control within Venus Smart Contract Ecosystem. |
| 34 | + |
| 35 | + |
| 36 | + |
| 37 | +### constructor |
| 38 | + |
| 39 | + |
| 40 | + |
| 41 | +```solidity |
| 42 | +
|
| 43 | +constructor() public |
| 44 | +
|
| 45 | +``` |
| 46 | + |
| 47 | + |
| 48 | + |
| 49 | +### isAllowedToCall |
| 50 | + |
| 51 | + |
| 52 | + |
| 53 | +```solidity |
| 54 | +
|
| 55 | +function isAllowedToCall(address caller, string functionSig) public view returns (bool) |
| 56 | +
|
| 57 | +``` |
| 58 | + |
| 59 | + |
| 60 | + |
| 61 | +Verifies if the given account can call a praticular contract's function |
| 62 | + |
| 63 | + |
| 64 | + |
| 65 | +_Since the contract is calling itself this function, we can get contracts address with msg.sender_ |
| 66 | + |
| 67 | + |
| 68 | + |
| 69 | +#### Parameters |
| 70 | + |
| 71 | + |
| 72 | + |
| 73 | +| Name | Type | Description | |
| 74 | +| ---- | ---- | ----------- | |
| 75 | +| caller | address | contract for which call permissions will be checked | |
| 76 | +| functionSig | string | signature e.g. "functionName(uint,bool)" | |
| 77 | + |
| 78 | + |
| 79 | + |
| 80 | +#### Return Values |
| 81 | + |
| 82 | + |
| 83 | + |
| 84 | +| Name | Type | Description | |
| 85 | +| ---- | ---- | ----------- | |
| 86 | +| [0] | bool | false if the user account cannot call the particular contract function | |
| 87 | + |
| 88 | + |
| 89 | + |
| 90 | +### giveCallPermission |
| 91 | + |
| 92 | + |
| 93 | + |
| 94 | +```solidity |
| 95 | +
|
| 96 | +function giveCallPermission(address contractAddress, string functionSig, address accountToPermit) public |
| 97 | +
|
| 98 | +``` |
| 99 | + |
| 100 | + |
| 101 | + |
| 102 | +Gives a function call permission to one single account |
| 103 | + |
| 104 | + |
| 105 | + |
| 106 | +_this function can be called only from Role Admin or DEFAULT_ADMIN_ROLE |
| 107 | + |
| 108 | +May emit a {RoleGranted} event._ |
| 109 | + |
| 110 | + |
| 111 | + |
| 112 | +#### Parameters |
| 113 | + |
| 114 | + |
| 115 | + |
| 116 | +| Name | Type | Description | |
| 117 | +| ---- | ---- | ----------- | |
| 118 | +| contractAddress | address | address of contract for which call permissions will be granted NOTE: if contractAddress is zero address, we give the account DEFAULT_ADMIN_ROLE, meaning that this account can access the certain function on ANY contract managed by this ACL | |
| 119 | +| functionSig | string | signature e.g. "functionName(uint,bool)" | |
| 120 | +| accountToPermit | address | account that will be given access to the contract function | |
| 121 | + |
| 122 | + |
| 123 | + |
| 124 | +### revokeCallPermission |
| 125 | + |
| 126 | + |
| 127 | + |
| 128 | +```solidity |
| 129 | +
|
| 130 | +function revokeCallPermission(address contractAddress, string functionSig, address accountToRevoke) public |
| 131 | +
|
| 132 | +``` |
| 133 | + |
| 134 | + |
| 135 | + |
| 136 | +Revokes an account's permission to a particular function call |
| 137 | + |
| 138 | + |
| 139 | + |
| 140 | +_this function can be called only from Role Admin or DEFAULT_ADMIN_ROLE |
| 141 | + |
| 142 | +May emit a {RoleRevoked} event._ |
| 143 | + |
| 144 | + |
| 145 | + |
| 146 | +#### Parameters |
| 147 | + |
| 148 | + |
| 149 | + |
| 150 | +| Name | Type | Description | |
| 151 | +| ---- | ---- | ----------- | |
| 152 | +| contractAddress | address | address of contract for which call permissions will be revoked | |
| 153 | +| functionSig | string | signature e.g. "functionName(uint,bool)" | |
| 154 | +| accountToRevoke | address | | |
0 commit comments