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 module #77

Merged
merged 11 commits into from
Nov 10, 2024
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
"package.json": "sort-package-json"
},
"dependencies": {
"@defi-wonderland/prophet-core": "0.0.0-3afab791",
"@defi-wonderland/prophet-core": "0.0.0-823459fc",
"@openzeppelin/contracts": "4.9.5",
"solmate": "https://github.com/transmissions11/solmate.git#bfc9c25865a274a7827fea5abf6e4fb64fc64e6c"
},
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.19;

import {AccessController} from '@defi-wonderland/prophet-core/solidity/contracts/AccessController.sol';
import {CommonAccessController} from '@defi-wonderland/prophet-core/solidity/contracts/CommonAccessController.sol';

import {IModuleAccessController} from '../../../interfaces/modules/access/IModuleAccessController.sol';
import {Module} from '@defi-wonderland/prophet-core/solidity/contracts/Module.sol';
import {IOracle} from '@defi-wonderland/prophet-core/solidity/interfaces/IOracle.sol';

abstract contract AccessControllerModule is AccessController, Module {
abstract contract ModuleAccessController is IModuleAccessController, CommonAccessController, Module {
constructor(IOracle _oracle) Module(_oracle) {}

/**
Expand All @@ -19,7 +21,6 @@ abstract contract AccessControllerModule is AccessController, Module {
}

/**
* // todo: update name to _selfAccessControl
* @notice Returns an access control object using the contract address as user, and empty data
*
* @dev should only be used by modules as the self-access-control object
Expand All @@ -28,4 +29,19 @@ abstract contract AccessControllerModule is AccessController, Module {
function _defaultAccessControl() internal view returns (AccessControl memory _accessControl) {
_accessControl = _defaultAccessControl(bytes(''));
}

modifier hasAccess(
address _accessModule,
bytes32 _typehash,
bytes memory _params,
AccessControl memory _accessControl
) {
// Revert if sender is acting for a user without module approval
if (msg.sender != _accessControl.user && !ORACLE.isAccessModuleApproved(_accessControl.user, _accessModule)) {
revert ModuleAccessController_AccessModuleNotApproved();
0xJabberwock marked this conversation as resolved.
Show resolved Hide resolved
}
// todo: probably a change name is required here, something like `_ensureAccess`?
_hasAccess(_accessModule, _typehash, _params, _accessControl);
_;
}
}
16 changes: 6 additions & 10 deletions solidity/contracts/modules/dispute/BondEscalationModule.sol
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,10 @@ import {FixedPointMathLib} from 'solmate/src/utils/FixedPointMathLib.sol';
import {IBondEscalationModule} from '../../../interfaces/modules/dispute/IBondEscalationModule.sol';

import {_PLEDGE_AGAINST_DISPUTE_TYPEHASH, _PLEDGE_FOR_DISPUTE_TYPEHASH} from '../../utils/Typehash.sol';
import {AccessControllerModule} from '../accessControl/AccessControllerModule.sol';

contract BondEscalationModule is AccessControllerModule, IBondEscalationModule {
import {ModuleAccessController} from '../access/ModuleAccessController.sol';

contract BondEscalationModule is ModuleAccessController, IBondEscalationModule {
/// @inheritdoc IBondEscalationModule
mapping(bytes32 _requestId => mapping(address _pledger => uint256 pledges)) public pledgesForDispute;

Expand All @@ -22,7 +23,7 @@ contract BondEscalationModule is AccessControllerModule, IBondEscalationModule {
*/
mapping(bytes32 _requestId => BondEscalation) internal _escalations;

constructor(IOracle _oracle) AccessControllerModule(_oracle) {}
constructor(IOracle _oracle) ModuleAccessController(_oracle) {}

/// @inheritdoc IModule
function moduleName() external pure returns (string memory _moduleName) {
Expand Down Expand Up @@ -217,7 +218,7 @@ contract BondEscalationModule is AccessControllerModule, IBondEscalationModule {
AccessControl calldata _accessControl
)
external
hasAccess(_request.accessControlModule, _PLEDGE_FOR_DISPUTE_TYPEHASH, abi.encode(_request, _dispute), _accessControl)
hasAccess(_request.accessModule, _PLEDGE_FOR_DISPUTE_TYPEHASH, abi.encode(_request, _dispute), _accessControl)
{
bytes32 _disputeId = _getId(_dispute);
RequestParameters memory _params = _pledgeChecks(_request, _dispute, true);
Expand All @@ -244,12 +245,7 @@ contract BondEscalationModule is AccessControllerModule, IBondEscalationModule {
AccessControl calldata _accessControl
)
external
hasAccess(
_request.accessControlModule,
_PLEDGE_AGAINST_DISPUTE_TYPEHASH,
abi.encode(_request, _dispute),
_accessControl
)
hasAccess(_request.accessModule, _PLEDGE_AGAINST_DISPUTE_TYPEHASH, abi.encode(_request, _dispute), _accessControl)
{
bytes32 _disputeId = _getId(_dispute);
RequestParameters memory _params = _pledgeChecks(_request, _dispute, false);
Expand Down
6 changes: 3 additions & 3 deletions solidity/contracts/modules/dispute/CircuitResolverModule.sol
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@ import {IOracle} from '@defi-wonderland/prophet-core/solidity/interfaces/IOracle
import {IProphetVerifier} from '../../../interfaces/IProphetVerifier.sol';
import {ICircuitResolverModule} from '../../../interfaces/modules/dispute/ICircuitResolverModule.sol';

import {AccessControllerModule} from '../accessControl/AccessControllerModule.sol';
import {ModuleAccessController} from '../access/ModuleAccessController.sol';

contract CircuitResolverModule is AccessControllerModule, ICircuitResolverModule {
contract CircuitResolverModule is ModuleAccessController, ICircuitResolverModule {
0xJabberwock marked this conversation as resolved.
Show resolved Hide resolved
/// @notice Keeps track of the correct responses to requests
mapping(bytes32 _requestId => bytes _correctResponse) internal _correctResponses;

constructor(IOracle _oracle) AccessControllerModule(_oracle) {}
constructor(IOracle _oracle) ModuleAccessController(_oracle) {}

/// @inheritdoc IModule
function moduleName() external pure returns (string memory _moduleName) {
Expand Down
6 changes: 3 additions & 3 deletions solidity/contracts/modules/dispute/RootVerificationModule.sol
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,17 @@ import {IOracle} from '@defi-wonderland/prophet-core/solidity/interfaces/IOracle

import {IRootVerificationModule} from '../../../interfaces/modules/dispute/IRootVerificationModule.sol';
import {MerkleLib} from '../../libraries/MerkleLib.sol';
import {AccessControllerModule} from '../accessControl/AccessControllerModule.sol';
import {ModuleAccessController} from '../access/ModuleAccessController.sol';

contract RootVerificationModule is AccessControllerModule, IRootVerificationModule {
contract RootVerificationModule is ModuleAccessController, IRootVerificationModule {
using MerkleLib for MerkleLib.Tree;

/**
* @notice The calculated correct root for a given request
*/
mapping(bytes32 _requestId => bytes32 _correctRoot) internal _correctRoots;

constructor(IOracle _oracle) AccessControllerModule(_oracle) {}
constructor(IOracle _oracle) ModuleAccessController(_oracle) {}

/// @inheritdoc IModule
function moduleName() external pure returns (string memory _moduleName) {
Expand Down
7 changes: 3 additions & 4 deletions solidity/contracts/modules/resolution/ArbitratorModule.sol
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,15 @@ import {IOracle} from '@defi-wonderland/prophet-core/solidity/interfaces/IOracle

import {IArbitrator} from '../../../interfaces/IArbitrator.sol';
import {IArbitratorModule} from '../../../interfaces/modules/resolution/IArbitratorModule.sol';
import {ModuleAccessController} from '../access/ModuleAccessController.sol';

import {AccessControllerModule} from '../accessControl/AccessControllerModule.sol';

contract ArbitratorModule is AccessControllerModule, IArbitratorModule {
contract ArbitratorModule is ModuleAccessController, IArbitratorModule {
/**
* @notice The status of all disputes
*/
mapping(bytes32 _disputeId => ArbitrationStatus _status) internal _disputeData;

constructor(IOracle _oracle) AccessControllerModule(_oracle) {}
constructor(IOracle _oracle) ModuleAccessController(_oracle) {}

/// @inheritdoc IModule
function moduleName() external pure returns (string memory _moduleName) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

// solhint-disable-next-line no-unused-import

import {IERC20} from '@openzeppelin/contracts/token/ERC20/IERC20.sol';

Check warning on line 6 in solidity/contracts/modules/resolution/BondEscalationResolutionModule.sol

View workflow job for this annotation

GitHub Actions / Run Linters (16.x)

imported name IERC20 is not used
import {SafeERC20} from '@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol';
import {FixedPointMathLib} from 'solmate/src/utils/FixedPointMathLib.sol';

Expand All @@ -16,15 +16,15 @@

import {IBondEscalationResolutionModule} from
'../../../interfaces/modules/resolution/IBondEscalationResolutionModule.sol';
import {AccessControllerModule} from '../accessControl/AccessControllerModule.sol';
import {ModuleAccessController} from '../access/ModuleAccessController.sol';

import {
_CLAIM_PLEDGE_TYPEHASH,
_PLEDGE_AGAINST_DISPUTE_TYPEHASH,
_PLEDGE_FOR_DISPUTE_TYPEHASH
} from '../../utils/Typehash.sol';

contract BondEscalationResolutionModule is AccessControllerModule, IBondEscalationResolutionModule {
contract BondEscalationResolutionModule is ModuleAccessController, IBondEscalationResolutionModule {
using SafeERC20 for IERC20;

/// @inheritdoc IBondEscalationResolutionModule
Expand All @@ -42,7 +42,7 @@
/// @inheritdoc IBondEscalationResolutionModule
mapping(bytes32 _disputeId => mapping(address _pledger => uint256 pledges)) public pledgesAgainstDispute;

constructor(IOracle _oracle) AccessControllerModule(_oracle) {}
constructor(IOracle _oracle) ModuleAccessController(_oracle) {}

/// @inheritdoc IModule
function moduleName() external pure returns (string memory _moduleName) {
Expand Down Expand Up @@ -74,7 +74,7 @@
)
external
hasAccess(
_request.accessControlModule,
_request.accessModule,
_PLEDGE_FOR_DISPUTE_TYPEHASH,
abi.encode(_request, _dispute, _pledgeAmount),
_accessControl
Expand All @@ -98,7 +98,7 @@
)
external
hasAccess(
_request.accessControlModule,
_request.accessModule,
_PLEDGE_AGAINST_DISPUTE_TYPEHASH,
abi.encode(_request, _dispute, _pledgeAmount),
_accessControl
Expand Down Expand Up @@ -162,10 +162,7 @@
IOracle.Request calldata _request,
IOracle.Dispute calldata _dispute,
AccessControl calldata _accessControl
)
external
hasAccess(_request.accessControlModule, _CLAIM_PLEDGE_TYPEHASH, abi.encode(_request, _dispute), _accessControl)
{
) external hasAccess(_request.accessModule, _CLAIM_PLEDGE_TYPEHASH, abi.encode(_request, _dispute), _accessControl) {
bytes32 _disputeId = _validateDispute(_request, _dispute);
Escalation storage _escalation = escalations[_disputeId];

Expand Down
13 changes: 5 additions & 8 deletions solidity/contracts/modules/resolution/ERC20ResolutionModule.sol
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ import {IOracle} from '@defi-wonderland/prophet-core/solidity/interfaces/IOracle
import {IERC20ResolutionModule} from '../../../interfaces/modules/resolution/IERC20ResolutionModule.sol';

import {_CAST_VOTE_TYPEHASH, _CLAIM_VOTE_TYPEHASH} from '../../utils/Typehash.sol';
import {AccessControllerModule} from '../accessControl/AccessControllerModule.sol';
import {ModuleAccessController} from '../access/ModuleAccessController.sol';

contract ERC20ResolutionModule is AccessControllerModule, IERC20ResolutionModule {
contract ERC20ResolutionModule is ModuleAccessController, IERC20ResolutionModule {
using SafeERC20 for IERC20;
using EnumerableSet for EnumerableSet.AddressSet;

Expand All @@ -29,7 +29,7 @@ contract ERC20ResolutionModule is AccessControllerModule, IERC20ResolutionModule
*/
mapping(bytes32 _disputeId => EnumerableSet.AddressSet _votersSet) internal _voters;

constructor(IOracle _oracle) AccessControllerModule(_oracle) {}
constructor(IOracle _oracle) ModuleAccessController(_oracle) {}

/// @inheritdoc IModule
function moduleName() external pure returns (string memory _moduleName) {
Expand Down Expand Up @@ -61,7 +61,7 @@ contract ERC20ResolutionModule is AccessControllerModule, IERC20ResolutionModule
)
external
hasAccess(
_request.accessControlModule,
_request.accessModule,
_CAST_VOTE_TYPEHASH,
abi.encode(_request, _dispute, _numberOfVotes, _numberOfVotes),
_accessControl
Expand Down Expand Up @@ -138,10 +138,7 @@ contract ERC20ResolutionModule is AccessControllerModule, IERC20ResolutionModule
IOracle.Request calldata _request,
IOracle.Dispute calldata _dispute,
AccessControl calldata _accessControl
)
external
hasAccess(_request.accessControlModule, _CLAIM_VOTE_TYPEHASH, abi.encode(_request, _dispute), _accessControl)
{
) external hasAccess(_request.accessModule, _CLAIM_VOTE_TYPEHASH, abi.encode(_request, _dispute), _accessControl) {
bytes32 _disputeId = _validateDispute(_request, _dispute);
Escalation memory _escalation = escalations[_disputeId];

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ import {IModule, Module} from '@defi-wonderland/prophet-core/solidity/contracts/
import {IOracle} from '@defi-wonderland/prophet-core/solidity/interfaces/IOracle.sol';

import {IPrivateERC20ResolutionModule} from '../../../interfaces/modules/resolution/IPrivateERC20ResolutionModule.sol';
import {AccessControllerModule} from '../accessControl/AccessControllerModule.sol';
import {ModuleAccessController} from '../access/ModuleAccessController.sol';

contract PrivateERC20ResolutionModule is AccessControllerModule, IPrivateERC20ResolutionModule {
contract PrivateERC20ResolutionModule is ModuleAccessController, IPrivateERC20ResolutionModule {
using SafeERC20 for IERC20;
using EnumerableSet for EnumerableSet.AddressSet;

Expand All @@ -28,7 +28,7 @@ contract PrivateERC20ResolutionModule is AccessControllerModule, IPrivateERC20Re
*/
mapping(bytes32 _disputeId => EnumerableSet.AddressSet _votersSet) internal _voters;

constructor(IOracle _oracle) AccessControllerModule(_oracle) {}
constructor(IOracle _oracle) ModuleAccessController(_oracle) {}

/// @inheritdoc IModule
function moduleName() external pure returns (string memory _moduleName) {
Expand Down Expand Up @@ -59,12 +59,7 @@ contract PrivateERC20ResolutionModule is AccessControllerModule, IPrivateERC20Re
AccessControl calldata _accessControl
)
external
hasAccess(
_request.accessControlModule,
_COMMIT_VOTE_TYPEHASH,
abi.encode(_request, _dispute, _commitment),
_accessControl
)
hasAccess(_request.accessModule, _COMMIT_VOTE_TYPEHASH, abi.encode(_request, _dispute, _commitment), _accessControl)
{
bytes32 _disputeId = _validateDispute(_request, _dispute);
if (ORACLE.disputeStatus(_disputeId) != IOracle.DisputeStatus.Escalated) {
Expand Down Expand Up @@ -94,7 +89,7 @@ contract PrivateERC20ResolutionModule is AccessControllerModule, IPrivateERC20Re
)
external
hasAccess(
_request.accessControlModule,
_request.accessModule,
_REVEAL_VOTE_TYPEHASH,
abi.encode(_request, _dispute, _numberOfVotes, _salt),
_accessControl
Expand Down
5 changes: 2 additions & 3 deletions solidity/contracts/modules/response/BondedResponseModule.sol
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,9 @@ import {IModule, Module} from '@defi-wonderland/prophet-core/solidity/contracts/
import {IOracle} from '@defi-wonderland/prophet-core/solidity/interfaces/IOracle.sol';

import {IBondedResponseModule} from '../../../interfaces/modules/response/IBondedResponseModule.sol';
import {AccessControllerModule} from '../accessControl/AccessControllerModule.sol';

contract BondedResponseModule is AccessControllerModule, IBondedResponseModule {
constructor(IOracle _oracle) AccessControllerModule(_oracle) {}
contract BondedResponseModule is Module, IBondedResponseModule {
constructor(IOracle _oracle) Module(_oracle) {}

/// @inheritdoc IModule
function moduleName() public pure returns (string memory _moduleName) {
Expand Down
35 changes: 35 additions & 0 deletions solidity/interfaces/modules/access/IModuleAccessController.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.19;

import {IAccessController} from '@defi-wonderland/prophet-core/solidity/interfaces/IAccessController.sol';

/**
* @title Module Access Controller Interface
* @notice Interface for the module access controller
*/
interface IModuleAccessController is IAccessController {
/*///////////////////////////////////////////////////////////////
EVENTS
//////////////////////////////////////////////////////////////*/

/*///////////////////////////////////////////////////////////////
STRUCTS
//////////////////////////////////////////////////////////////*/

/*///////////////////////////////////////////////////////////////
ERRORS
//////////////////////////////////////////////////////////////*/

/**
* @notice Thrown when user has not approved the access module
*/
error ModuleAccessController_AccessModuleNotApproved();

/*///////////////////////////////////////////////////////////////
VARIABLES
//////////////////////////////////////////////////////////////*/

/*///////////////////////////////////////////////////////////////
LOGIC
//////////////////////////////////////////////////////////////*/
}
5 changes: 3 additions & 2 deletions solidity/test/integration/IntegrationBase.sol
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@ pragma solidity ^0.8.19;
import {console} from 'forge-std/console.sol';

import {
AccessController, IAccessController
} from '@defi-wonderland/prophet-core/solidity/contracts/AccessController.sol';
CommonAccessController,
IAccessController
} from '@defi-wonderland/prophet-core/solidity/contracts/CommonAccessController.sol';
import {IOracle, Oracle} from '@defi-wonderland/prophet-core/solidity/contracts/Oracle.sol';
import {IDisputeModule} from '@defi-wonderland/prophet-core/solidity/interfaces/modules/dispute/IDisputeModule.sol';
import {IFinalityModule} from '@defi-wonderland/prophet-core/solidity/interfaces/modules/finality/IFinalityModule.sol';
Expand Down
Loading
Loading