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

feat: access control #52

Merged
merged 20 commits into from
Nov 12, 2024
Merged

feat: access control #52

merged 20 commits into from
Nov 12, 2024

Conversation

ashitakah
Copy link
Contributor

@ashitakah ashitakah commented Oct 17, 2024

Closes OPT-493

Copy link

linear bot commented Oct 24, 2024


/// @inheritdoc IOracle
function finalize(IOracle.Request calldata _request, IOracle.Response calldata _response) external {
function finalize(
Copy link
Member

Choose a reason for hiding this comment

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

Why do we need the msg.senders in finalize? Is there a use for it? If not sure, can you ask in the prophet channel what the intended use is?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

commented in the discord channel

Copy link
Member

Choose a reason for hiding this comment

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

It would be meaningful to revise what each existing implementation of the Prophet modules expects as to the _finalizer parameter of finalizeRequest().

  • Apparently, all dispute and resolution modules don't utilize it.
  • Moreover, all request and finality modules only do it upon the emission of RequestFinalized event (except for EBORequestModule).
  • However, the unique response module does so with the aim of identifying whether the argument is an Oracle::allowedModule, apart from for the event emission.
  • Lastly, mind that CircuitResolverModule and RootVerificationModule (both dispute modules) and EBO's CouncilArbitrator (not a module) call Oracle::finalize.

Copy link
Member

@0xShaito 0xShaito left a comment

Choose a reason for hiding this comment

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

Great PR! I think some more testing is missing though. AccessController is also not tested in all of its cases individually. Close to ready!

solidity/contracts/Oracle.sol Show resolved Hide resolved

/// @inheritdoc IOracle
function finalize(IOracle.Request calldata _request, IOracle.Response calldata _response) external {
function finalize(
Copy link
Member

Choose a reason for hiding this comment

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

It would be meaningful to revise what each existing implementation of the Prophet modules expects as to the _finalizer parameter of finalizeRequest().

  • Apparently, all dispute and resolution modules don't utilize it.
  • Moreover, all request and finality modules only do it upon the emission of RequestFinalized event (except for EBORequestModule).
  • However, the unique response module does so with the aim of identifying whether the argument is an Oracle::allowedModule, apart from for the event emission.
  • Lastly, mind that CircuitResolverModule and RootVerificationModule (both dispute modules) and EBO's CouncilArbitrator (not a module) call Oracle::finalize.

solidity/contracts/Oracle.sol Show resolved Hide resolved
solidity/contracts/Oracle.sol Outdated Show resolved Hide resolved
solidity/contracts/Oracle.sol Outdated Show resolved Hide resolved
Comment on lines 165 to 166
// The caller must be the proposer, unless the response is coming from a dispute module
if (msg.sender != _response.proposer && msg.sender != address(_request.disputeModule)) {
if (_accessControl.user != _response.proposer && _accessControl.user != address(_request.disputeModule)) {
Copy link
Member

Choose a reason for hiding this comment

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

If I correctly understand the new intended behaviour:

  • the user, not the caller, must be the proposer,
  • even though the response may come from a dispute module (i.e., CircuitResolverModule or RootVerificationModule).

Copy link
Member

@0xJabberwock 0xJabberwock Nov 4, 2024

Choose a reason for hiding this comment

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

Such dispute modules may set themselves as the access control users but not as the proposers; considering that that is the new expected behaviour:

  • The user, not the caller, must be the proposer,
  • unless the response is coming from a dispute module (i.e., CircuitResolverModule or RootVerificationModule).

The code comment should be updated accordingly.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

👍

solidity/contracts/Oracle.sol Show resolved Hide resolved
solidity/contracts/Oracle.sol Show resolved Hide resolved
solidity/contracts/Oracle.sol Show resolved Hide resolved
solidity/contracts/AccessController.sol Outdated Show resolved Hide resolved
Comment on lines 155 to 160
external
isApproved(_accessControl.user, _request.accessControlModule)
hasAccess(_request.accessControlModule, PROPOSE_TYPEHASH, abi.encode(_request, _response), _accessControl)
returns (bytes32 _responseId)
{
_responseId = ValidatorLib._validateResponse(_request, _response);
Copy link
Member

Choose a reason for hiding this comment

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

Reminder: executing isApproved and hasAccess modifiers before any other validation might pose a security vulnerability, given that Oracle would perform an external call to an arbitrary address with arbitrary data from the user.

Copy link
Contributor

Choose a reason for hiding this comment

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

Tracked as part of OPT-521

Copy link

linear bot commented Nov 7, 2024

Comment on lines 272 to 276
// Needed to avoid stack too deep error
Request memory _usedRequest = _request;
Response memory _usedResponse = _response;
Dispute memory _usedDispute = _dispute;

Copy link
Member

Choose a reason for hiding this comment

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

How come defining even more variables fixes the problem?

Copy link
Contributor

Choose a reason for hiding this comment

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

I'll create a task to track this, but probably we shouldn't merge this PR without fixing it.

Copy link
Member

Choose a reason for hiding this comment

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

Fixed in d34d4ba

@@ -94,10 +101,13 @@ contract BaseTest is Test, Helpers {
event RequestCreated(bytes32 indexed _requestId, IOracle.Request _request, bytes32 _ipfsHash);
event ResponseProposed(bytes32 indexed _requestId, bytes32 indexed _responseId, IOracle.Response _response);
event ResponseDisputed(bytes32 indexed _responseId, bytes32 indexed _disputeId, IOracle.Dispute _dispute);
event OracleRequestFinalized(bytes32 indexed _requestId, bytes32 indexed _responseId, address indexed _caller);
event OracleRequestFinalized(bytes32 indexed _requestId, bytes32 indexed _responseId);
Copy link
Member

@gas1cent gas1cent Nov 12, 2024

Choose a reason for hiding this comment

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

This is not blocking the PR, but FYI we can import events from IOracle instead of defining them in unit tests. For example:

vm.expectEmit(address(_staking));
emit IStaking.Staked(_user, _fuzz.amount);

Note that the emit call includes the full "path" to the event, starting from the interface name. This allows to pull events from anywhere really, reducing the duplication and as well avoiding issues with mismatching declarations of events in interfaces and tests.

Copy link
Contributor

Choose a reason for hiding this comment

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

Very nice! Tracked in OPT-536

Copy link
Member

@0xJabberwock 0xJabberwock left a comment

Choose a reason for hiding this comment

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

🚀

@gas1cent gas1cent merged commit 0e46031 into dev Nov 12, 2024
3 checks passed
@gas1cent gas1cent deleted the feat/access-controller branch November 12, 2024 14:21
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.

5 participants