Skip to content
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

Open
wants to merge 8 commits into
base: next
Choose a base branch
from
Open

revokeAll function #459

wants to merge 8 commits into from

Conversation

juslar
Copy link

@juslar juslar commented Nov 15, 2018

Fixes #333

Implements revokeAll(address _app, bytes32 _role)

@coveralls
Copy link

coveralls commented Nov 15, 2018

Coverage Status

Coverage increased (+0.8%) to 99.543% when pulling 9294f59 on espresso-org:revoke-all into 96d9940 on aragon:dev.

@juslar
Copy link
Author

juslar commented Nov 15, 2018

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?

@sohkai sohkai requested review from izqui and bingen November 19, 2018 10:44
@sohkai sohkai added this to the aragonOS 5.0 milestone Nov 19, 2018
@sohkai
Copy link
Contributor

sohkai commented Nov 19, 2018

@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.

@juslar
Copy link
Author

juslar commented Nov 19, 2018

Thanks! I added the backwards-compatible line.

Regarding the coverage decreasing, it's due to this line:

require(newRoleEra >= roleEras[roleHash(_app, _role)], ERROR_ROLE_ERA_INCREMENT);

Do you have an idea how I could cover this? Is it ok to leave it this way?

external
onlyPermissionManager(_app, _role)
{
uint256 newRoleEra = roleEras[roleHash(_app, _role)] + 1;
Copy link
Contributor

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 :).

Copy link
Contributor

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?

Copy link
Author

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 :)

uint256 roleEra = roleEras[roleHash(_where, _what)];

// Backward compatibility for DAOs with earlier versions of the ACL
if (roleEra == 0)
Copy link
Contributor

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.

@sohkai
Copy link
Contributor

sohkai commented Jan 11, 2019

Do you have an idea how I could cover this? Is it ok to leave it this way?

See #459 (comment); most of the time that check should be covered by SafeMath.

@sohkai sohkai modified the milestones: aragonOS 5.0, A1 Sprint: 3.2 Jan 14, 2019
@juslar
Copy link
Author

juslar commented Jan 14, 2019

Thank you @sohkai. I made the changes :)

external
onlyPermissionManager(_app, _role)
{
uint256 newRoleEra = roleEras[roleHash(_app, _role)] + 1;
Copy link
Contributor

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?

{
uint256 newRoleEra = roleEras[roleHash(_app, _role)] + 1;
require(newRoleEra >= roleEras[roleHash(_app, _role)], ERROR_ROLE_ERA_INCREMENT);
roleEras[roleHash(_app, _role)] = newRoleEra;
Copy link
Contributor

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.

Copy link
Author

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.

Copy link
Contributor

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.

Copy link
Contributor

@sohkai sohkai Jan 18, 2019

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.

Copy link
Author

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);
Copy link
Contributor

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.

Copy link
Author

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 :)

Copy link
Contributor

@sohkai sohkai left a 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 :).

@sohkai
Copy link
Contributor

sohkai commented May 18, 2019

@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 :).

@sohkai sohkai removed this from the A1 Sprint: 4.1 milestone May 18, 2019
@sohkai sohkai added this to the aragonOS 5.0 milestone May 18, 2019
@sohkai sohkai changed the base branch from dev to next July 11, 2019 09:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Revoke all granted permissions for a role
4 participants