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

fix: address inconsistent parameter and mapping order (OZ N-05) #1034

Merged
merged 9 commits into from
Oct 9, 2024

Conversation

MoonBoi9001
Copy link
Member

@MoonBoi9001 MoonBoi9001 commented Sep 18, 2024

Motivation:

Title:

N-05 Inconsistent Parameter and Mapping Order

Details:

In the HorizonStaking contract, the _isAuthorized function has the following parameter order: _operator, _serviceProvider, _verifier. On the other hand, the _operatorAuth mapping uses this order: _serviceProvider, _verifier, _operator. In addition, the _legacyOperatorAuth variable is defined as a mapping from an operator to a service provider to a boolean status. However, it is being used as a mapping from a service provider to an operator to a boolean status.

These inconsistencies can lead to confusion and potential errors during integration or modification, as developers may misinterpret the correct parameter order.

Consider aligning the parameter order in both the _isAuthorized function and the _operatorAuth mapping for improved consistency. Moreover, consider updating the keys and value names in the _legacyOperatorAuth mapping definition to match its usage.

Key changes:

  • Aligned the parameter order in the _isAuthorized function
  • Aligned the parameter order in the isAuthorized function
  • Aligned the parameter order in the _operatorAuth function
  • Aligned the parameter order in the ProvisionManagerNotAuthorized function
  • Aligned the parameter order in the HorizonStakingNotAuthorized function
  • Aligned the parameter order in the SetOperator function
  • Aligned the parameter order in the SetOperatorLocked function

Consistent peramater order:

  • ServiceProvider, Verifier, Operator

@MoonBoi9001
Copy link
Member Author

Did not address:

  • In addition, the _legacyOperatorAuth variable is defined as a mapping from an operator to a service provider to a boolean status. However, it is being used as a mapping from a service provider to an operator to a boolean status.

    • This point was already addressed.
  • Moreover, consider updating the keys and value names in the _legacyOperatorAuth mapping definition to match its usage.

    • I'm unsure what changes need to happen given:
    • mapping(address serviceProvider => mapping(address legacyOperator => bool authorized)) internal _legacyOperatorAuth;
    • I presume the suggestion is to change authorized to allowed? See here

Copy link

openzeppelin-code bot commented Sep 18, 2024

fix: address inconsistent parameter and mapping order (OZ N-05)

Generated at commit: 0f1522d58427e292aa8d596b8657e2c303a63f7d

🚨 Report Summary

Severity Level Results
Contracts Critical
High
Medium
Low
Note
Total
2
4
0
15
40
61
Dependencies Critical
High
Medium
Low
Note
Total
0
0
0
0
0
0

For more details view the full report in OpenZeppelin Code Inspector

Copy link
Contributor

@tmigone tmigone left a comment

Choose a reason for hiding this comment

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

We should also update isAuthorized() external function, and probably in the tests/ folder there are cases where we call this function and we need to switch the param order as well. For example:

bool beforeOperatorAllowedGetter = staking.isAuthorized(operator, msgSender, verifier);

@MoonBoi9001
Copy link
Member Author

MoonBoi9001 commented Sep 20, 2024

Presumably this would also imply updating the relative ordering of many other things too, for example:

bool beforeOperatorAllowed = _getStorage_OperatorAuth(msgSender, operator, verifier, legacy);

function setOperator(address operator, address verifier, bool allowed) external;

_graphStaking().isAuthorized(msg.sender, serviceProvider, address(this)),

ProvisionManagerNotAuthorized(msg.sender, serviceProvider)

HorizonStakingNotAuthorized(msg.sender, serviceProvider, verifier)

Proposed consistent order: (ServiceProvider, Verifier, Operator)
New proposed consistent order: (ServiceProvider, Operator, Verifier)

Copy link

codecov bot commented Sep 20, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 92.51%. Comparing base (e33bf12) to head (edc5c3e).
Report is 37 commits behind head on horizon.

Additional details and impacted files
@@           Coverage Diff            @@
##           horizon    #1034   +/-   ##
========================================
  Coverage    92.51%   92.51%           
========================================
  Files           46       46           
  Lines         2392     2392           
  Branches       428      428           
========================================
  Hits          2213     2213           
  Misses         179      179           
Flag Coverage Δ
unittests 92.51% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@tmigone
Copy link
Contributor

tmigone commented Sep 20, 2024

Yes good idea being consistent. I wouldn't mind keeping _getStorage_OperatorAuth as is because its an internal test only function, but anything that's externally accessible it does seem like a good idea to be consistent.

@MoonBoi9001 MoonBoi9001 marked this pull request as draft October 1, 2024 16:44
@MoonBoi9001
Copy link
Member Author

New Proposed consistent order after discussions with Pablo:

(ServiceProvider, Operator, Verifier)

@MoonBoi9001 MoonBoi9001 force-pushed the fix_oz_n-05 branch 13 times, most recently from 8a5b876 to edc5c3e Compare October 4, 2024 15:09
@MoonBoi9001 MoonBoi9001 marked this pull request as ready for review October 4, 2024 16:25
@tmigone
Copy link
Contributor

tmigone commented Oct 4, 2024

Hey @MoonBoi9001 @pcarranzav curious why you chose (ServiceProvider, Operator, Verifier) over (ServiceProvider, Verifier, Operator)? All the other staking functions follow the (ServiceProvider, Verifier, ...) pattern

@pcarranzav
Copy link
Member

Hey @MoonBoi9001 @pcarranzav curious why you chose (ServiceProvider, Operator, Verifier) over (ServiceProvider, Verifier, Operator)? All the other staking functions follow the (ServiceProvider, Verifier, ...) pattern

I don't feel strongly about it, but to me it made intuitive sense that:

  • Operator and service provider are closely related, so it made sense to have them close to each other
  • It is coherent with other functions having (serviceProvider, verifier) because the ordering is transitive, i.e. (serviceProvider, operator), (operator, verifier), (serviceProvider, verifier) are valid orderings for functions that have only two of the three. And we already have some functions with (operator, verifier).

But if you think the other ordering is cleaner I'm happy with that too; but would prefer if the "transitiveness" was enforced, e.g. setOperator and setOperatorLocked should be changed to (verifier, operator, allowed) as well

@tmigone
Copy link
Contributor

tmigone commented Oct 4, 2024

I see. I think I still prefer to keep the (serviceProvider, verifier, ...) pattern, I feel like it's easier to remember, but I do agree we need to change SetOperator and SetOperatorLocked as well to enforce the transitiveness.

@pcarranzav
Copy link
Member

I'm happy with that, @MoonBoi9001 sorry for the churn, how do you feel about changing it to (serviceProvider, verifier, operator) and checking it's transitively consistent everywhere?

@MoonBoi9001
Copy link
Member Author

Okay, will do that.

@MoonBoi9001 MoonBoi9001 force-pushed the fix_oz_n-05 branch 2 times, most recently from aa8a4b6 to b7a3ddb Compare October 7, 2024 13:37
Copy link
Member

@pcarranzav pcarranzav left a comment

Choose a reason for hiding this comment

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

Looks great 👍

@MoonBoi9001 MoonBoi9001 merged commit f0294b0 into horizon Oct 9, 2024
9 checks passed
@MoonBoi9001 MoonBoi9001 deleted the fix_oz_n-05 branch October 9, 2024 09:34
@tmigone
Copy link
Contributor

tmigone commented Nov 13, 2024

thanks @MoonBoi9001 and sorry for the trouble 👍

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