|
| 1 | +# Access Control |
| 2 | + |
| 3 | +Access control play a crucial role in our Governance model. We use it to restrict certain functions to be called only from one account or list of accounts (EOA or Contract Accounts). |
| 4 | + |
| 5 | + |
| 6 | + |
| 7 | + |
| 8 | +# Access Control Manager |
| 9 | +The implementation of our AC Management we implemented [**AccessControlManager.sol**](https://github.com/VenusProtocol/isolated-pools/blob/main/contracts/Governance/AccessControlManager.sol) which is a contract that inherits [**@openzeppelin/contracts/access/AccessControl.sol**](https://github.com/OpenZeppelin/openzeppelin-contracts/blob/master/contracts/access/AccessControl.sol) as a base of our role management logic. |
| 10 | +Roles are built by hashing the contract address and its function signature. |
| 11 | +E.g We have a Contract A with function A.try() which is guarded by ACM. |
| 12 | +Calling giveRolePermission for account B will basically do: |
| 13 | +1. compute keccak256({addrress-of-a},{function-sig-of-try()}) |
| 14 | +2. add the computed role to the roles of account B |
| 15 | +3. Account B now can call try() of Contract A |
| 16 | + |
| 17 | +**NOTE:** because of the existence of factory contracts, in some cases we don't need that granular permissions (e.g in PoolRegistry). So we introduced **DEFAULT_ADMIN_FUNCTION_ROLE**. |
| 18 | +This role is computed the same way, but instead of computing `keccak256({addrress-of-a},{function-sig-of-try()})`, we do `keccak256({zero-address},{function-sig-of-try()})`. |
| 19 | +If we consider the same case above and give account B the **DEFAULT_ADMIN_FUNCTION_ROLE** , account B will have permissions to call try() function on any contract that is guarded by ACM, not only contract A. |
| 20 | +Lets' take a look at each interface function of the contract: |
| 21 | + |
| 22 | +# Solidity API |
| 23 | + |
| 24 | + |
| 25 | + |
| 26 | +## AccessControlManager |
| 27 | + |
| 28 | + |
| 29 | + |
| 30 | +This contract is a wrapper of OpenZeppelin AccessControl |
| 31 | + |
| 32 | +extending it in a way to standardise access control |
| 33 | + |
| 34 | +within Venus Smart Contract Ecosystem_ |
| 35 | + |
| 36 | + |
| 37 | + |
| 38 | +### constructor |
| 39 | + |
| 40 | + |
| 41 | + |
| 42 | +```solidity |
| 43 | +
|
| 44 | +constructor() public |
| 45 | +
|
| 46 | +``` |
| 47 | + |
| 48 | + |
| 49 | + |
| 50 | +### isAllowedToCall |
| 51 | + |
| 52 | + |
| 53 | + |
| 54 | +```solidity |
| 55 | +
|
| 56 | +function isAllowedToCall(address caller, string functionSig) public view returns (bool) |
| 57 | +
|
| 58 | +``` |
| 59 | + |
| 60 | + |
| 61 | + |
| 62 | +Verifies if the given account can call a praticular contract's function |
| 63 | + |
| 64 | + |
| 65 | + |
| 66 | +_Since the contract is calling itself this function, we can get contracts address with msg.sender_ |
| 67 | + |
| 68 | + |
| 69 | + |
| 70 | +#### Parameters |
| 71 | + |
| 72 | + |
| 73 | + |
| 74 | +| Name | Type | Description | |
| 75 | + |
| 76 | +| ---- | ---- | ----------- | |
| 77 | + |
| 78 | +| caller | address | contract for which call permissions will be checked | |
| 79 | + |
| 80 | +| functionSig | string | signature e.g. "functionName(uint,bool)" | |
| 81 | + |
| 82 | + |
| 83 | + |
| 84 | +#### Return Values |
| 85 | + |
| 86 | + |
| 87 | + |
| 88 | +| Name | Type | Description | |
| 89 | + |
| 90 | +| ---- | ---- | ----------- | |
| 91 | + |
| 92 | +| [0] | bool | false if the user account cannot call the particular contract function | |
| 93 | + |
| 94 | + |
| 95 | + |
| 96 | +### giveCallPermission |
| 97 | + |
| 98 | + |
| 99 | + |
| 100 | +```solidity |
| 101 | +
|
| 102 | +function giveCallPermission(address contractAddress, string functionSig, address accountToPermit) public |
| 103 | +
|
| 104 | +``` |
| 105 | + |
| 106 | + |
| 107 | + |
| 108 | +Gives a function call permission to one single account |
| 109 | + |
| 110 | + |
| 111 | + |
| 112 | +_this function can be called only from Role Admin or DEFAULT_ADMIN_ROLE |
| 113 | + |
| 114 | +May emit a {RoleGranted} event._ |
| 115 | + |
| 116 | + |
| 117 | + |
| 118 | +#### Parameters |
| 119 | + |
| 120 | + |
| 121 | + |
| 122 | +| Name | Type | Description | |
| 123 | + |
| 124 | +| ---- | ---- | ----------- | |
| 125 | + |
| 126 | +| 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 | |
| 127 | + |
| 128 | +| functionSig | string | signature e.g. "functionName(uint,bool)" | |
| 129 | + |
| 130 | +| accountToPermit | address | account that will be given access to the contract function | |
| 131 | + |
| 132 | + |
| 133 | + |
| 134 | +### revokeCallPermission |
| 135 | + |
| 136 | + |
| 137 | + |
| 138 | +```solidity |
| 139 | +
|
| 140 | +function revokeCallPermission(address contractAddress, string functionSig, address accountToRevoke) public |
| 141 | +
|
| 142 | +``` |
| 143 | + |
| 144 | + |
| 145 | + |
| 146 | +Revokes an account's permission to a particular function call |
| 147 | + |
| 148 | + |
| 149 | + |
| 150 | +_this function can be called only from Role Admin or DEFAULT_ADMIN_ROLE |
| 151 | + |
| 152 | +May emit a {RoleRevoked} event._ |
| 153 | + |
| 154 | + |
| 155 | + |
| 156 | +#### Parameters |
| 157 | + |
| 158 | + |
| 159 | + |
| 160 | +| Name | Type | Description | |
| 161 | + |
| 162 | +| ---- | ---- | ----------- | |
| 163 | + |
| 164 | +| contractAddress | address | address of contract for which call permissions will be revoked | |
| 165 | + |
| 166 | +| functionSig | string | signature e.g. "functionName(uint,bool)" | |
| 167 | + |
| 168 | +| accountToRevoke | address | | |
0 commit comments