-
Notifications
You must be signed in to change notification settings - Fork 11.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feature/Access Control - Roles by account #2139 #2298
Feature/Access Control - Roles by account #2139 #2298
Conversation
Deployment Cost Analysis I did a comparison as requested for the Deployment costs of this new version of
Previous implementation: 615116 I also did a check with the same code on Remix and got a similar result. Remix Previous implementation: Transaction cost 740684 (Execution cost: 522556 ) Screenshots provided below
|
ByteCode Analysis By checking the build/contracts/*.json files using the length of Previous version: build/contracts/AccountRolesPrev.json: 2644.5. bytes New version: build/contracts/AccountRoles.json: 3291.5. bytes. (increment by 24%) |
Gas Execution Analysis I used Remix to check the transaction costs for Grant and Revoke roles functions which were modified in this change. Previous version - Gas Costs New version - Gas Costs |
This looks great @julianmrodri, short and to the point! Your grant gas costs seem a bit high, and revoke a bit low. Did you perform the measurements on a brand new contract? If so, then they likely include both the fee when storage is first set (15k gas) and the refund when a slot is cleared, which disrupt the comparison a bit. Could you repeat the measurements in a scenario where there an account already has a few roles, which themselves have been granted to some other accounts, and then add/revoke a new one? This data would be helpful in making a comparison. Thanks a lot! |
Thanks @nventuro for the suggestion. Good catch. It adds the 15K the first time I setup a Role for a new account. Everytime I These are the values for executing in the new scenario: Grant Role
Revoke Role
|
Thanks! Those numbers make more sense, the 50k increase in grant comes from:
|
Awesome. Thanks to you for the explanation! Let me know if you want to do some more analysis I can prepare a more formal script if required with some more cases if you need. Just wanted to provide some initial numbers for you to better understand if its worth proceeding. Thanks! |
Hi all! |
@frangio what's your take on this? |
Hi all! |
Hi folks! |
@julianmrodri Sorry for the long delay in replying. I guess it's tough for me to decide on this because as far as I can tell we haven't received too many requests for this feature, and in this scenario I think I favor keeping the contract slimmer and the costs down. It's in our plans to do some general research about the state of gas costs across OpenZeppelin Contracts, and with that research we will be able to come back to this feature and evaluate with more information. Thanks for all the work in this regardless! |
@frangio No problem at all! I agree with you, changes like this you have a compelling case. Thanks to you for the support. |
2139
Fixes #2139
This PR introduces the required changes to be able to enumerate all
Roles
for a specificAccount
.It is developed following the same approach currently implemented for getting all role members. It implements two functions that need to be used together. One to get the count of roles for a specific account and then another one to get each individual Role. (Requires to iterate from outside the contract).
function getAccountRoleCount(address account) public view returns (uint256)
function getAccountRole(address account, uint256 index) public view returns (bytes32)
In addition to this, I had to create a new implementation for
EnumerableSet
namedBytes32Set
.