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: request id validation #51

Merged
merged 10 commits into from
Jul 26, 2024
41 changes: 26 additions & 15 deletions solidity/contracts/modules/dispute/BondEscalationModule.sol
Original file line number Diff line number Diff line change
Expand Up @@ -33,24 +33,27 @@ contract BondEscalationModule is Module, IBondEscalationModule {
IOracle.Response calldata _response,
IOracle.Dispute calldata _dispute
) external onlyOracle {
bytes32 _requestId = _getId(_request);
if (_requestId != _dispute.requestId) revert BondEscalationModule_InvalidRequestId();

RequestParameters memory _params = decodeRequestData(_request.disputeModuleData);

if (block.number > ORACLE.createdAt(_dispute.responseId) + _params.disputeWindow) {
revert BondEscalationModule_DisputeWindowOver();
}

BondEscalation storage _escalation = _escalations[_dispute.requestId];
BondEscalation storage _escalation = _escalations[_requestId];
bytes32 _disputeId = _getId(_dispute);

_params.accountingExtension.bond({
_bonder: _dispute.disputer,
_requestId: _dispute.requestId,
_requestId: _requestId,
_token: _params.bondToken,
_amount: _params.bondSize
});

emit ResponseDisputed({
_requestId: _dispute.requestId,
_requestId: _requestId,
_responseId: _dispute.responseId,
_disputeId: _disputeId,
_dispute: _dispute,
Expand All @@ -63,7 +66,7 @@ contract BondEscalationModule is Module, IBondEscalationModule {
if (block.timestamp > _params.bondEscalationDeadline) revert BondEscalationModule_BondEscalationOver();
_escalation.status = BondEscalationStatus.Active;
_escalation.disputeId = _disputeId;
emit BondEscalationStatusUpdated(_dispute.requestId, _disputeId, BondEscalationStatus.Active);
emit BondEscalationStatusUpdated(_requestId, _disputeId, BondEscalationStatus.Active);
} else if (_disputeId != _escalation.disputeId) {
ORACLE.escalateDispute(_request, _response, _dispute);
}
Expand All @@ -76,8 +79,11 @@ contract BondEscalationModule is Module, IBondEscalationModule {
IOracle.Response calldata,
IOracle.Dispute calldata _dispute
) external onlyOracle {
bytes32 _requestId = _getId(_request);
if (_requestId != _dispute.requestId) revert BondEscalationModule_InvalidRequestId();

RequestParameters memory _params = decodeRequestData(_request.disputeModuleData);
BondEscalation storage _escalation = _escalations[_dispute.requestId];
BondEscalation storage _escalation = _escalations[_requestId];
IOracle.DisputeStatus _disputeStatus = ORACLE.disputeStatus(_disputeId);
BondEscalationStatus _newStatus;

Expand All @@ -103,7 +109,7 @@ contract BondEscalationModule is Module, IBondEscalationModule {

if (_escalation.amountOfPledgesForDispute + _escalation.amountOfPledgesAgainstDispute > 0) {
_params.accountingExtension.onSettleBondEscalation({
_requestId: _dispute.requestId,
_requestId: _requestId,
_disputeId: _disputeId,
_token: _params.bondToken,
_amountPerPledger: _params.bondSize,
Expand All @@ -112,7 +118,7 @@ contract BondEscalationModule is Module, IBondEscalationModule {
}

_params.accountingExtension.release({
_requestId: _dispute.requestId,
_requestId: _requestId,
_bonder: _dispute.disputer,
_token: _params.bondToken,
_amount: _params.bondSize
Expand All @@ -134,7 +140,7 @@ contract BondEscalationModule is Module, IBondEscalationModule {
+ FixedPointMathLib.mulDivDown(_pledgesForDispute, _params.bondSize, _pledgesAgainstDispute);

_params.accountingExtension.onSettleBondEscalation({
_requestId: _dispute.requestId,
_requestId: _requestId,
_disputeId: _escalation.disputeId,
_token: _params.bondToken,
_amountPerPledger: _amountToPay,
Expand All @@ -143,7 +149,7 @@ contract BondEscalationModule is Module, IBondEscalationModule {
}

_params.accountingExtension.pay({
_requestId: _dispute.requestId,
_requestId: _requestId,
_payer: _won ? _dispute.proposer : _dispute.disputer,
_receiver: _won ? _dispute.disputer : _dispute.proposer,
_token: _params.bondToken,
Expand All @@ -152,7 +158,7 @@ contract BondEscalationModule is Module, IBondEscalationModule {

if (_won) {
_params.accountingExtension.release({
_requestId: _dispute.requestId,
_requestId: _requestId,
_bonder: _dispute.disputer,
_token: _params.bondToken,
_amount: _params.bondSize
Expand All @@ -170,7 +176,7 @@ contract BondEscalationModule is Module, IBondEscalationModule {
// Refund the disputer, the bond escalation status stays Escalated
_newStatus = BondEscalationStatus.Escalated;
_params.accountingExtension.release({
_requestId: _dispute.requestId,
_requestId: _requestId,
_bonder: _dispute.disputer,
_token: _params.bondToken,
_amount: _params.bondSize
Expand All @@ -182,7 +188,7 @@ contract BondEscalationModule is Module, IBondEscalationModule {
_newStatus = _won ? BondEscalationStatus.DisputerWon : BondEscalationStatus.DisputerLost;

_params.accountingExtension.pay({
_requestId: _dispute.requestId,
_requestId: _requestId,
_payer: _won ? _dispute.proposer : _dispute.disputer,
_receiver: _won ? _dispute.disputer : _dispute.proposer,
_token: _params.bondToken,
Expand All @@ -191,7 +197,7 @@ contract BondEscalationModule is Module, IBondEscalationModule {

if (_won) {
_params.accountingExtension.release({
_requestId: _dispute.requestId,
_requestId: _requestId,
_bonder: _dispute.disputer,
_token: _params.bondToken,
_amount: _params.bondSize
Expand All @@ -201,7 +207,7 @@ contract BondEscalationModule is Module, IBondEscalationModule {
}

_escalation.status = _newStatus;
emit BondEscalationStatusUpdated(_dispute.requestId, _disputeId, _newStatus);
emit BondEscalationStatusUpdated(_requestId, _disputeId, _newStatus);
emit DisputeStatusChanged({_disputeId: _disputeId, _dispute: _dispute, _status: _disputeStatus});
}

Expand Down Expand Up @@ -252,6 +258,8 @@ contract BondEscalationModule is Module, IBondEscalationModule {
IOracle.Dispute calldata _dispute
) external {
bytes32 _requestId = _getId(_request);
if (_requestId != _dispute.requestId) revert BondEscalationModule_InvalidRequestId();

RequestParameters memory _params = decodeRequestData(_request.disputeModuleData);
BondEscalation storage _escalation = _escalations[_requestId];

Expand Down Expand Up @@ -294,7 +302,10 @@ contract BondEscalationModule is Module, IBondEscalationModule {
IOracle.Dispute calldata _dispute,
bool _forDispute
) internal view returns (RequestParameters memory _params) {
BondEscalation memory _escalation = _escalations[_dispute.requestId];
bytes32 _requestId = _getId(_request);
if (_requestId != _dispute.requestId) revert BondEscalationModule_InvalidRequestId();

BondEscalation memory _escalation = _escalations[_requestId];

if (_disputeId != _escalation.disputeId) {
revert BondEscalationModule_InvalidDispute();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,8 @@ contract BondEscalationResolutionModule is Module, IBondEscalationResolutionModu
IOracle.Response calldata _response,
IOracle.Dispute calldata _dispute
) external onlyOracle {
bytes32 _requestId = _dispute.requestId;
bytes32 _requestId = _getId(_request);
if (_requestId != _dispute.requestId) revert BondEscalationResolutionModule_InvalidRequestId();

Escalation storage _escalation = escalations[_disputeId];

Expand Down Expand Up @@ -124,8 +125,10 @@ contract BondEscalationResolutionModule is Module, IBondEscalationResolutionModu

/// @inheritdoc IBondEscalationResolutionModule
function claimPledge(IOracle.Request calldata _request, IOracle.Dispute calldata _dispute) external {
bytes32 _requestId = _getId(_request);
if (_requestId != _dispute.requestId) revert BondEscalationResolutionModule_InvalidRequestId();

bytes32 _disputeId = _getId(_dispute);
bytes32 _requestId = _dispute.requestId;
Escalation storage _escalation = escalations[_disputeId];

if (_escalation.resolution == Resolution.Unresolved) revert BondEscalationResolutionModule_NotResolved();
Expand Down Expand Up @@ -204,8 +207,10 @@ contract BondEscalationResolutionModule is Module, IBondEscalationResolutionModu
uint256 _pledgeAmount,
bool _pledgingFor
) internal {
bytes32 _requestId = _getId(_request);
if (_requestId != _dispute.requestId) revert BondEscalationResolutionModule_InvalidRequestId();

bytes32 _disputeId = _getId(_dispute);
bytes32 _requestId = _dispute.requestId;
Escalation storage _escalation = escalations[_disputeId];

if (_escalation.startTime == 0) revert BondEscalationResolutionModule_NotEscalated();
Expand Down
17 changes: 13 additions & 4 deletions solidity/contracts/modules/resolution/ERC20ResolutionModule.sol
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,9 @@ contract ERC20ResolutionModule is Module, IERC20ResolutionModule {
IOracle.Dispute calldata _dispute,
uint256 _numberOfVotes
) public {
bytes32 _requestId = _getId(_request);
if (_requestId != _dispute.requestId) revert ERC20ResolutionModule_InvalidRequestId();

bytes32 _disputeId = _getId(_dispute);
Escalation memory _escalation = escalations[_disputeId];
if (_escalation.startTime == 0) revert ERC20ResolutionModule_DisputeNotEscalated();
Expand All @@ -72,7 +75,7 @@ contract ERC20ResolutionModule is Module, IERC20ResolutionModule {
_voters[_disputeId].add(msg.sender);
escalations[_disputeId].totalVotes += _numberOfVotes;

_params.accountingExtension.bond(msg.sender, _dispute.requestId, _params.votingToken, _numberOfVotes);
_params.accountingExtension.bond(msg.sender, _requestId, _params.votingToken, _numberOfVotes);
emit VoteCast(msg.sender, _disputeId, _numberOfVotes);
}

Expand All @@ -83,6 +86,9 @@ contract ERC20ResolutionModule is Module, IERC20ResolutionModule {
IOracle.Response calldata _response,
IOracle.Dispute calldata _dispute
) external onlyOracle {
bytes32 _requestId = _getId(_request);
if (_requestId != _dispute.requestId) revert ERC20ResolutionModule_InvalidRequestId();

// Check disputeId actually exists and that it isn't resolved already
if (ORACLE.disputeStatus(_disputeId) != IOracle.DisputeStatus.Escalated) {
revert ERC20ResolutionModule_AlreadyResolved();
Expand All @@ -102,15 +108,18 @@ contract ERC20ResolutionModule is Module, IERC20ResolutionModule {
// Update status
if (_quorumReached == 1) {
ORACLE.updateDisputeStatus(_request, _response, _dispute, IOracle.DisputeStatus.Won);
emit DisputeResolved(_dispute.requestId, _disputeId, IOracle.DisputeStatus.Won);
emit DisputeResolved(_requestId, _disputeId, IOracle.DisputeStatus.Won);
} else {
ORACLE.updateDisputeStatus(_request, _response, _dispute, IOracle.DisputeStatus.Lost);
emit DisputeResolved(_dispute.requestId, _disputeId, IOracle.DisputeStatus.Lost);
emit DisputeResolved(_requestId, _disputeId, IOracle.DisputeStatus.Lost);
}
}

/// @inheritdoc IERC20ResolutionModule
function claimVote(IOracle.Request calldata _request, IOracle.Dispute calldata _dispute) external {
bytes32 _requestId = _getId(_request);
if (_requestId != _dispute.requestId) revert ERC20ResolutionModule_InvalidRequestId();

bytes32 _disputeId = _getId(_dispute);
Escalation memory _escalation = escalations[_disputeId];

Expand All @@ -121,7 +130,7 @@ contract ERC20ResolutionModule is Module, IERC20ResolutionModule {

// Transfer the tokens back to the voter
uint256 _amount = votes[_disputeId][msg.sender];
_params.accountingExtension.release(msg.sender, _dispute.requestId, _params.votingToken, _amount);
_params.accountingExtension.release(msg.sender, _requestId, _params.votingToken, _amount);

emit VoteClaimed(msg.sender, _disputeId, _amount);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,9 @@ contract PrivateERC20ResolutionModule is Module, IPrivateERC20ResolutionModule {

/// @inheritdoc IPrivateERC20ResolutionModule
function commitVote(IOracle.Request calldata _request, IOracle.Dispute calldata _dispute, bytes32 _commitment) public {
bytes32 _requestId = _getId(_request);
if (_requestId != _dispute.requestId) revert PrivateERC20ResolutionModule_InvalidRequestId();

bytes32 _disputeId = _getId(_dispute);
if (ORACLE.createdAt(_disputeId) == 0) revert PrivateERC20ResolutionModule_NonExistentDispute();
if (ORACLE.disputeStatus(_disputeId) != IOracle.DisputeStatus.Escalated) {
Expand All @@ -78,6 +81,9 @@ contract PrivateERC20ResolutionModule is Module, IPrivateERC20ResolutionModule {
uint256 _numberOfVotes,
bytes32 _salt
) public {
bytes32 _requestId = _getId(_request);
if (_requestId != _dispute.requestId) revert PrivateERC20ResolutionModule_InvalidRequestId();

bytes32 _disputeId = _getId(_dispute);
Escalation memory _escalation = escalations[_disputeId];
if (_escalation.startTime == 0) revert PrivateERC20ResolutionModule_DisputeNotEscalated();
Expand Down Expand Up @@ -113,6 +119,9 @@ contract PrivateERC20ResolutionModule is Module, IPrivateERC20ResolutionModule {
IOracle.Response calldata _response,
IOracle.Dispute calldata _dispute
) external onlyOracle {
bytes32 _requestId = _getId(_request);
if (_requestId != _dispute.requestId) revert PrivateERC20ResolutionModule_InvalidRequestId();

if (ORACLE.createdAt(_disputeId) == 0) revert PrivateERC20ResolutionModule_NonExistentDispute();
if (ORACLE.disputeStatus(_disputeId) != IOracle.DisputeStatus.Escalated) {
revert PrivateERC20ResolutionModule_AlreadyResolved();
Expand All @@ -134,10 +143,10 @@ contract PrivateERC20ResolutionModule is Module, IPrivateERC20ResolutionModule {

if (_quorumReached == 1) {
ORACLE.updateDisputeStatus(_request, _response, _dispute, IOracle.DisputeStatus.Won);
emit DisputeResolved(_dispute.requestId, _disputeId, IOracle.DisputeStatus.Won);
emit DisputeResolved(_requestId, _disputeId, IOracle.DisputeStatus.Won);
} else {
ORACLE.updateDisputeStatus(_request, _response, _dispute, IOracle.DisputeStatus.Lost);
emit DisputeResolved(_dispute.requestId, _disputeId, IOracle.DisputeStatus.Lost);
emit DisputeResolved(_requestId, _disputeId, IOracle.DisputeStatus.Lost);
}

address _voter;
Expand Down
4 changes: 4 additions & 0 deletions solidity/interfaces/modules/dispute/IBondEscalationModule.sol
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,10 @@ interface IBondEscalationModule is IDisputeModule {
ERRORS
//////////////////////////////////////////////////////////////*/

/**
* @notice Thrown when a request does not match a request id.
*/
error BondEscalationModule_InvalidRequestId();
/**
* @notice Thrown when trying to escalate a dispute going through the bond escalation module before its deadline.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,11 @@ interface IBondEscalationResolutionModule is IResolutionModule {
ERRORS
//////////////////////////////////////////////////////////////*/

/**
* @notice Thrown when a request does not match a request id.
*/
error BondEscalationResolutionModule_InvalidRequestId();

/**
* @notice Thrown when the user tries to resolve a dispute that has already been resolved.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,11 @@ interface IERC20ResolutionModule is IResolutionModule {
*/
error ERC20ResolutionModule_OnlyDisputeModule();
Copy link
Member Author

Choose a reason for hiding this comment

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

This custom error is not being used anywhere. 🙄


/**
* @notice Thrown when a request does not match a request id
*/
error ERC20ResolutionModule_InvalidRequestId();

/**
* @notice Throws if the dispute doesn't exist or has not been escalated
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,11 @@ interface IPrivateERC20ResolutionModule is IResolutionModule {
ERRORS
//////////////////////////////////////////////////////////////*/

/**
* @notice Thrown when a request does not match a request id
*/
error PrivateERC20ResolutionModule_InvalidRequestId();

/**
* @notice Thrown when the dispute has not been escalated
*/
Expand Down
Loading
Loading