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

Add functions which returns the user state is in module enabled or recovery is activated. #28

Merged
merged 10 commits into from
Aug 6, 2024

Conversation

wshino
Copy link
Contributor

@wshino wshino commented Aug 4, 2024

This PR is for adding the functions which returns user state is in module enabled or recovery process is activated.

Currently for rhinestone, they removed the branch named feature/4337-compliance in rhinestonewtf/safe7579.
I used forking repo in zkemail instead, I hope this will be fixed soon.
I'm going to create a PR to them.

Also regarding ether-email-auth, at now we need to use commit hash or branch name to use the latest EmailAccountRecovery.sol. This will be fixed soon as we will use npm package.

wshino added 2 commits August 5, 2024 00:32
1. Add isActivated function to EmailRecoveryManager
2. Add isAuthorizedToBeRecovered to EmailRecoveryModule and UniversalEmailRecoveryModule
3. Update unit tests in some actions.
* @return true if the module is authorized, false otherwise
*/
function isAuthorizedToBeRecovered(address account) external view returns (bool) {
return validatorCount[account] > 0;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should I use return authorized[account] as same as the src/modules/EmailRecoveryModule.sol ?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See comment on modified solution. Let me know what you think

Copy link
Contributor

@SoraSuegami SoraSuegami left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for your PR!
I will check codes.

Copy link
Collaborator

@JohnGuilding JohnGuilding left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks good. Although I think I've thought of a better way of doing this. Wdyt of this idea:

Instead of re-adding the isAuthorizedToBeRecovered logic, we remove that function and related state from each recovery module, and just use the isActivated function as you use it here? There is no need to write a separate function on the modules if you can use isActivated and you can use state from the manager, as the manager is now part of the module

If you agree with this change, could you also re-add the logic for calling isAuthorizedToBeRecovered in the manager too but using isActiviated instead? Like this:

if (!isActivated()) {
    revert RecoveryModuleNotAuthorized();
}

It isn't strictly related to the isActiviated change, but will actually be useful for the native safe module PR (it was my mistake to remove it in hindsight). This will involve:

  1. Adding the equivalent of this logic, but using !isActivated() instead of isAuthorizedToBeRecovered back to acceptGuardian and processRecovery:
if (!isActivated()) {
    revert RecoveryModuleNotAuthorized();
}
  1. Add the tests back for this
  2. Also add a similar check in completeRecovery:
  3. Write a test for new check in completeRecovery
  4. Remove all changes related to isAuthorizedToBeRecovered and associated state in the modules that were added in this PR

Comment on lines 106 to 115
/**
* @notice Checks if the recovery is activated for a given account
* @param recoveredAccount The address of the recovered account for which the activation status is being checked
* @return bool True if the recovery request is activated, false otherwise
*/
function isActivated(address recoveredAccount) public view override returns (bool) {
return guardianConfigs[recoveredAccount].threshold > 0;
}


Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
/**
* @notice Checks if the recovery is activated for a given account
* @param recoveredAccount The address of the recovered account for which the activation status is being checked
* @return bool True if the recovery request is activated, false otherwise
*/
function isActivated(address recoveredAccount) public view override returns (bool) {
return guardianConfigs[recoveredAccount].threshold > 0;
}
/**
* @notice Checks if the recovery is activated for a given account
* @param account The address of the account for which the activation status is being checked
* @return bool True if the recovery request is activated, false otherwise
*/
function isActivated(address account) public view override returns (bool) {
return guardianConfigs[account].threshold > 0;
}

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nitpick - added suggestion for consistent naming with other functions in this file

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nitpick - why do we need assertions for isActivated in these tests? threshold state isn't modified in this function

* @return true if the module is authorized, false otherwise
*/
function isAuthorizedToBeRecovered(address account) external view returns (bool) {
return validatorCount[account] > 0;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See comment on modified solution. Let me know what you think

@JohnGuilding
Copy link
Collaborator

JohnGuilding commented Aug 6, 2024

LGTM @wshino. Pushed some minor changes:

  1. My suggestion to add the isActivated check in completeRecovery wasn't needed as there is already an equivalent check
  2. Added new error selector to assertErrorSelectors.t.sol
  3. Added unit test for isActivated

@JohnGuilding JohnGuilding merged commit 95a3fcb into main Aug 6, 2024
4 checks passed
@JohnGuilding JohnGuilding deleted the feat/add-is-activated-function branch August 6, 2024 09:41
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.

3 participants