You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: Governance/Access Control Manager.md
+17-27Lines changed: 17 additions & 27 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,23 +1,26 @@
1
1
# Access Control
2
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).
3
+
Access control plays a crucial role in the Venus governance model. It is used to restrict functions so tha they can only be called from one account or list of accounts (EOA or Contract Accounts).
4
4
5
+
# Access Control Manager
6
+
The implementation of [AccessControlManagemer](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.
5
7
8
+
### Granular Roles
6
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:
2. Add the computed role to the roles of account B
15
+
3. Account B now can call `ContractFoo.bar()`
7
16
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:
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:
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.
21
24
22
25
# Solidity API
23
26
@@ -72,11 +75,8 @@ _Since the contract is calling itself this function, we can get contracts addres
72
75
73
76
74
77
| Name | Type | Description |
75
-
76
78
| ---- | ---- | ----------- |
77
-
78
79
| caller | address | contract for which call permissions will be checked |
79
-
80
80
| functionSig | string | signature e.g. "functionName(uint,bool)" |
81
81
82
82
@@ -86,9 +86,7 @@ _Since the contract is calling itself this function, we can get contracts addres
86
86
87
87
88
88
| Name | Type | Description |
89
-
90
89
| ---- | ---- | ----------- |
91
-
92
90
|[0]| bool | false if the user account cannot call the particular contract function |
93
91
94
92
@@ -120,13 +118,9 @@ May emit a {RoleGranted} event._
120
118
121
119
122
120
| Name | Type | Description |
123
-
124
121
| ---- | ---- | ----------- |
125
-
126
122
| 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
123
| functionSig | string | signature e.g. "functionName(uint,bool)" |
129
-
130
124
| accountToPermit | address | account that will be given access to the contract function |
131
125
132
126
@@ -158,11 +152,7 @@ May emit a {RoleRevoked} event._
158
152
159
153
160
154
| Name | Type | Description |
161
-
162
155
| ---- | ---- | ----------- |
163
-
164
156
| contractAddress | address | address of contract for which call permissions will be revoked |
165
-
166
157
| functionSig | string | signature e.g. "functionName(uint,bool)" |
0 commit comments