-
Notifications
You must be signed in to change notification settings - Fork 246
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
revokeAll function #459
base: next
Are you sure you want to change the base?
revokeAll function #459
Conversation
I thought about a potential breaking change with the implementation I submitted. If a DAO currently in production upgrades to this version of the ACL, all the permissions would be invalid. Not too sure how to address this. An easy fix would be to add something like: function permissionHash(address _who, address _where, bytes32 _what) internal view returns (bytes32) {
uint256 roleEra = roleEras[roleHash(_where, _what)];
if (roleEra == 0)
return keccak256(abi.encodePacked("PERMISSION", _who, _where, _what));
return keccak256(abi.encodePacked("PERMISSION", roleEra, _who, _where, _what));
} But that would consume a bit more gas. What do you think? |
@juslar Nice! I think the backwards-compatible version isn't a terrible cost to swallow, and we should make sure to comment it. An interesting thing we might want to set up in the future is upgradability tests between compatible versions. |
Thanks! I added the backwards-compatible line. Regarding the coverage decreasing, it's due to this line:
Do you have an idea how I could cover this? Is it ok to leave it this way? |
contracts/acl/ACL.sol
Outdated
external | ||
onlyPermissionManager(_app, _role) | ||
{ | ||
uint256 newRoleEra = roleEras[roleHash(_app, _role)] + 1; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We might as well use SafeMath
here :).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure, although it seems really unlikely that this function gets called 2^256
times for the same app and role, I guess you mean instead of the next line, right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I added SafeMath and will remove the require on the next line :)
contracts/acl/ACL.sol
Outdated
uint256 roleEra = roleEras[roleHash(_where, _what)]; | ||
|
||
// Backward compatibility for DAOs with earlier versions of the ACL | ||
if (roleEra == 0) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's add braces around the if
.
See #459 (comment); most of the time that check should be covered by |
Thank you @sohkai. I made the changes :) |
contracts/acl/ACL.sol
Outdated
external | ||
onlyPermissionManager(_app, _role) | ||
{ | ||
uint256 newRoleEra = roleEras[roleHash(_app, _role)] + 1; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure, although it seems really unlikely that this function gets called 2^256
times for the same app and role, I guess you mean instead of the next line, right?
contracts/acl/ACL.sol
Outdated
{ | ||
uint256 newRoleEra = roleEras[roleHash(_app, _role)] + 1; | ||
require(newRoleEra >= roleEras[roleHash(_app, _role)], ERROR_ROLE_ERA_INCREMENT); | ||
roleEras[roleHash(_app, _role)] = newRoleEra; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wonder if using a pointer to roleEras[roleHash(_app, _role)]
could save some gas here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you mean using a storage pointer? I don't think I can on a uint256 value. Maybe I'm missing something though.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, yes, you are right, sorry for the confusion. We could still save 2 calls to roleHash
function, but as it's going to be one less if you remove the require
, I don't know if that's a big gain.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Probably still a decent net gain, since there also wouldn't be another SLOAD
as well.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good :) Pushed the optimization.
onlyPermissionManager(_app, _role) | ||
{ | ||
bytes32 hash = roleHash(_app, _role); | ||
roleEras[hash] = roleEras[hash].add(1); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just realized, we should definitely emit an event here as otherwise it'd be very difficult to know this happened in a frontend.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry for the delay! I added a RevokeAllPermissions
event :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM! Going to merge this after @aragon/[email protected]
is released and stage it for the next release :).
@juslar Because this wasn't pulled into some of the minor aragonOS 4.x releases (and because we didn't want to risk re-deploying the ACL for 0.7), we'll roll this into aragonOS 5 :). |
Fixes #333
Implements
revokeAll(address _app, bytes32 _role)