Skip to content

Commit

Permalink
change to only 1 relayer address per arbitration policy (#334)
Browse files Browse the repository at this point in the history
  • Loading branch information
Spablob authored Dec 10, 2024
1 parent 5d709c6 commit bd1d8ce
Show file tree
Hide file tree
Showing 7 changed files with 31 additions and 62 deletions.
20 changes: 7 additions & 13 deletions contracts/interfaces/modules/dispute/IDisputeModule.sol
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,10 @@ interface IDisputeModule {
/// @param allowed Indicates if the arbitration policy is whitelisted
event ArbitrationPolicyWhitelistUpdated(address arbitrationPolicy, bool allowed);

/// @notice Event emitted when an arbitration relayer whitelist status is updated
/// @notice Event emitted when an arbitration relayer address is updated
/// @param arbitrationPolicy The address of the arbitration policy
/// @param arbitrationRelayer The address of the arbitration relayer
/// @param allowed Indicates if the arbitration relayer is whitelisted
event ArbitrationRelayerWhitelistUpdated(address arbitrationPolicy, address arbitrationRelayer, bool allowed);
event ArbitrationRelayerUpdated(address arbitrationPolicy, address arbitrationRelayer);

/// @notice Event emitted when the base arbitration policy is set
/// @param arbitrationPolicy The address of the arbitration policy
Expand Down Expand Up @@ -145,14 +144,10 @@ interface IDisputeModule {
/// @return allowed Indicates if the arbitration policy is whitelisted
function isWhitelistedArbitrationPolicy(address arbitrationPolicy) external view returns (bool allowed);

/// @notice Indicates if an arbitration relayer is whitelisted for a given arbitration policy
/// @notice Returns the arbitration relayer for a given arbitration policy
/// @param arbitrationPolicy The address of the arbitration policy
/// @param arbitrationRelayer The address of the arbitration relayer
/// @return allowed Indicates if the arbitration relayer is whitelisted
function isWhitelistedArbitrationRelayer(
address arbitrationPolicy,
address arbitrationRelayer
) external view returns (bool allowed);
/// @return arbitrationRelayer The address of the arbitration relayer
function arbitrationRelayer(address arbitrationPolicy) external view returns (address arbitrationRelayer);

/// @notice Arbitration policy for a given ipId
/// @param ipId The ipId
Expand All @@ -169,11 +164,10 @@ interface IDisputeModule {
/// @param allowed Indicates if the arbitration policy is whitelisted or not
function whitelistArbitrationPolicy(address arbitrationPolicy, bool allowed) external;

/// @notice Whitelists an arbitration relayer for a given arbitration policy
/// @notice Sets the arbitration relayer for a given arbitration policy
/// @param arbitrationPolicy The address of the arbitration policy
/// @param arbPolicyRelayer The address of the arbitration relayer
/// @param allowed Indicates if the arbitration relayer is whitelisted or not
function whitelistArbitrationRelayer(address arbitrationPolicy, address arbPolicyRelayer, bool allowed) external;
function setArbitrationRelayer(address arbitrationPolicy, address arbPolicyRelayer) external;

/// @notice Sets the base arbitration policy
/// @param arbitrationPolicy The address of the arbitration policy
Expand Down
7 changes: 2 additions & 5 deletions contracts/lib/Errors.sol
Original file line number Diff line number Diff line change
Expand Up @@ -392,9 +392,6 @@ library Errors {
/// @notice Zero address provided for Arbitration Policy.
error DisputeModule__ZeroArbitrationPolicy();

/// @notice Zero address provided for Arbitration Relayer.
error DisputeModule__ZeroArbitrationRelayer();

/// @notice Zero bytes provided for Dispute Tag.
error DisputeModule__ZeroDisputeTag();

Expand All @@ -407,8 +404,8 @@ library Errors {
/// @notice Not a whitelisted arbitration policy.
error DisputeModule__NotWhitelistedArbitrationPolicy();

/// @notice Not a whitelisted arbitration relayer.
error DisputeModule__NotWhitelistedArbitrationRelayer();
/// @notice Not the arbitration relayer.
error DisputeModule__NotArbitrationRelayer();

/// @notice Not a whitelisted dispute tag.
error DisputeModule__NotWhitelistedDisputeTag();
Expand Down
34 changes: 11 additions & 23 deletions contracts/modules/dispute/DisputeModule.sol
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,7 @@ contract DisputeModule is
/// @param disputes Returns the dispute information for a given dispute id
/// @param isWhitelistedDisputeTag Indicates if a dispute tag is whitelisted
/// @param isWhitelistedArbitrationPolicy Indicates if an arbitration policy is whitelisted
/// @param isWhitelistedArbitrationRelayer Indicates if an arbitration relayer
/// is whitelisted for a given arbitration policy
/// @param arbitrationRelayer The arbitration relayer address for a given arbitration policy
/// @param arbitrationPolicies Arbitration policy for a given ipId
/// @param nextArbitrationPolicies Next arbitration policy for a given ipId
/// @param arbitrationUpdateTimestamps Timestamp of when the arbitration policy will be updated for a given ipId
Expand All @@ -50,7 +49,7 @@ contract DisputeModule is
mapping(uint256 disputeId => Dispute) disputes;
mapping(bytes32 tag => bool) isWhitelistedDisputeTag;
mapping(address arbitrationPolicy => bool) isWhitelistedArbitrationPolicy;
mapping(address arbitrationPolicy => mapping(address relayer => bool)) isWhitelistedArbitrationRelayer;
mapping(address arbitrationPolicy => address relayer) arbitrationRelayer;
mapping(address ipId => address) arbitrationPolicies;
mapping(address ipId => address) nextArbitrationPolicies;
mapping(address ipId => uint256) nextArbitrationUpdateTimestamps;
Expand Down Expand Up @@ -125,22 +124,16 @@ contract DisputeModule is
emit ArbitrationPolicyWhitelistUpdated(arbitrationPolicy, allowed);
}

/// @notice Whitelists an arbitration relayer for a given arbitration policy
/// @notice Sets the arbitration relayer for a given arbitration policy
/// @param arbitrationPolicy The address of the arbitration policy
/// @param arbPolicyRelayer The address of the arbitration relayer
/// @param allowed Indicates if the arbitration relayer is whitelisted or not
function whitelistArbitrationRelayer(
address arbitrationPolicy,
address arbPolicyRelayer,
bool allowed
) external restricted {
function setArbitrationRelayer(address arbitrationPolicy, address arbPolicyRelayer) external restricted {
if (arbitrationPolicy == address(0)) revert Errors.DisputeModule__ZeroArbitrationPolicy();
if (arbPolicyRelayer == address(0)) revert Errors.DisputeModule__ZeroArbitrationRelayer();

DisputeModuleStorage storage $ = _getDisputeModuleStorage();
$.isWhitelistedArbitrationRelayer[arbitrationPolicy][arbPolicyRelayer] = allowed;
$.arbitrationRelayer[arbitrationPolicy] = arbPolicyRelayer;

emit ArbitrationRelayerWhitelistUpdated(arbitrationPolicy, arbPolicyRelayer, allowed);
emit ArbitrationRelayerUpdated(arbitrationPolicy, arbPolicyRelayer);
}

/// @notice Sets the base arbitration policy
Expand Down Expand Up @@ -247,9 +240,8 @@ contract DisputeModule is
Dispute memory dispute = $.disputes[disputeId];

if (dispute.currentTag != IN_DISPUTE) revert Errors.DisputeModule__NotInDisputeState();
if (!$.isWhitelistedArbitrationRelayer[dispute.arbitrationPolicy][msg.sender]) {
revert Errors.DisputeModule__NotWhitelistedArbitrationRelayer();
}
if ($.arbitrationRelayer[dispute.arbitrationPolicy] != msg.sender)
revert Errors.DisputeModule__NotArbitrationRelayer();

if (decision) {
$.disputes[disputeId].currentTag = dispute.targetTag;
Expand Down Expand Up @@ -434,14 +426,10 @@ contract DisputeModule is
return _getDisputeModuleStorage().isWhitelistedArbitrationPolicy[arbitrationPolicy];
}

/// @notice Indicates if an arbitration relayer is whitelisted for a given arbitration policy
/// @notice Returns the arbitration relayer for a given arbitration policy
/// @param arbitrationPolicy The address of the arbitration policy
/// @param arbitrationRelayer The address of the arbitration relayer
function isWhitelistedArbitrationRelayer(
address arbitrationPolicy,
address arbitrationRelayer
) external view returns (bool allowed) {
return _getDisputeModuleStorage().isWhitelistedArbitrationRelayer[arbitrationPolicy][arbitrationRelayer];
function arbitrationRelayer(address arbitrationPolicy) external view returns (address) {
return _getDisputeModuleStorage().arbitrationRelayer[arbitrationPolicy];
}

/// @notice Returns the arbitration policy for a given ipId
Expand Down
2 changes: 1 addition & 1 deletion script/foundry/utils/DeployHelper.sol
Original file line number Diff line number Diff line change
Expand Up @@ -757,7 +757,7 @@ contract DeployHelper is Script, BroadcastManager, JsonDeploymentHandler, Storag
disputeModule.whitelistDisputeTag("IMPROPER_PAYMENT", true);
disputeModule.whitelistDisputeTag("CONTENT_STANDARDS_VIOLATION", true);
disputeModule.whitelistArbitrationPolicy(address(arbitrationPolicyUMA), true);
disputeModule.whitelistArbitrationRelayer(address(arbitrationPolicyUMA), address(arbitrationPolicyUMA), true);
disputeModule.setArbitrationRelayer(address(arbitrationPolicyUMA), address(arbitrationPolicyUMA));
disputeModule.setBaseArbitrationPolicy(address(arbitrationPolicyUMA));
arbitrationPolicyUMA.setOOV3(address(oov3));
arbitrationPolicyUMA.setLiveness(30 days, 365 days, 66_666_666);
Expand Down
22 changes: 8 additions & 14 deletions test/foundry/modules/dispute/DisputeModule.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import { MockArbitrationPolicy } from "test/foundry/mocks/dispute/MockArbitratio
contract DisputeModuleTest is BaseTest {
event TagWhitelistUpdated(bytes32 tag, bool allowed);
event ArbitrationPolicyWhitelistUpdated(address arbitrationPolicy, bool allowed);
event ArbitrationRelayerWhitelistUpdated(address arbitrationPolicy, address arbitrationRelayer, bool allowed);
event ArbitrationRelayerUpdated(address arbitrationPolicy, address arbitrationRelayer);
event DisputeRaised(
uint256 disputeId,
address targetIpId,
Expand Down Expand Up @@ -156,26 +156,20 @@ contract DisputeModuleTest is BaseTest {
assertEq(disputeModule.isWhitelistedArbitrationPolicy(address(1)), true);
}

function test_DisputeModule_whitelistArbitrationRelayer_revert_ZeroArbitrationPolicy() public {
function test_DisputeModule_setArbitrationRelayer_revert_ZeroArbitrationPolicy() public {
vm.startPrank(u.admin);
vm.expectRevert(Errors.DisputeModule__ZeroArbitrationPolicy.selector);
disputeModule.whitelistArbitrationRelayer(address(0), arbitrationRelayer, true);
disputeModule.setArbitrationRelayer(address(0), arbitrationRelayer);
}

function test_DisputeModule_whitelistArbitrationRelayer_revert_ZeroArbitrationRelayer() public {
vm.startPrank(u.admin);
vm.expectRevert(Errors.DisputeModule__ZeroArbitrationRelayer.selector);
disputeModule.whitelistArbitrationRelayer(address(mockArbitrationPolicy), address(0), true);
}

function test_DisputeModule_whitelistArbitrationRelayer() public {
function test_DisputeModule_setArbitrationRelayer() public {
vm.startPrank(u.admin);
vm.expectEmit(true, true, true, true, address(disputeModule));
emit ArbitrationRelayerWhitelistUpdated(address(mockArbitrationPolicy), address(1), true);
emit ArbitrationRelayerUpdated(address(mockArbitrationPolicy), address(1));

disputeModule.whitelistArbitrationRelayer(address(mockArbitrationPolicy), address(1), true);
disputeModule.setArbitrationRelayer(address(mockArbitrationPolicy), address(1));

assertEq(disputeModule.isWhitelistedArbitrationRelayer(address(mockArbitrationPolicy), address(1)), true);
assertEq(disputeModule.arbitrationRelayer(address(mockArbitrationPolicy)), address(1));
}

function test_DisputeModule_setBaseArbitrationPolicy_revert_NotWhitelistedArbitrationPolicy() public {
Expand Down Expand Up @@ -414,7 +408,7 @@ contract DisputeModuleTest is BaseTest {
disputeModule.raiseDispute(ipAddr, disputeEvidenceHashExample, "IMPROPER_REGISTRATION", "");
vm.stopPrank();

vm.expectRevert(Errors.DisputeModule__NotWhitelistedArbitrationRelayer.selector);
vm.expectRevert(Errors.DisputeModule__NotArbitrationRelayer.selector);
disputeModule.setDisputeJudgement(1, true, "");
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,11 +88,7 @@ contract ArbitrationPolicyUMATest is BaseTest {
// whitelist dispute tag, arbitration policy and arbitration relayer
newDisputeModule.whitelistDisputeTag("IMPROPER_REGISTRATION", true);
newDisputeModule.whitelistArbitrationPolicy(address(newArbitrationPolicyUMA), true);
newDisputeModule.whitelistArbitrationRelayer(
address(newArbitrationPolicyUMA),
address(newArbitrationPolicyUMA),
true
);
newDisputeModule.setArbitrationRelayer(address(newArbitrationPolicyUMA), address(newArbitrationPolicyUMA));
newDisputeModule.setBaseArbitrationPolicy(address(newArbitrationPolicyUMA));

vm.label(newOOV3, "newOOV3");
Expand Down
2 changes: 1 addition & 1 deletion test/foundry/utils/BaseTest.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ contract BaseTest is Test, DeployHelper, LicensingHelper {
mockArbitrationPolicy = new MockArbitrationPolicy(address(disputeModule), address(USDC), ARBITRATION_PRICE);
vm.startPrank(u.admin);
disputeModule.whitelistArbitrationPolicy(address(mockArbitrationPolicy), true);
disputeModule.whitelistArbitrationRelayer(address(mockArbitrationPolicy), address(u.relayer), true);
disputeModule.setArbitrationRelayer(address(mockArbitrationPolicy), address(u.relayer));
disputeModule.setBaseArbitrationPolicy(address(mockArbitrationPolicy));
mockArbitrationPolicy.setTreasury(TREASURY_ADDRESS);
vm.stopPrank();
Expand Down

0 comments on commit bd1d8ce

Please sign in to comment.