Skip to content

Commit

Permalink
feat: module validations (#34)
Browse files Browse the repository at this point in the history
  • Loading branch information
0xJabberwock authored Jul 22, 2024
1 parent 8b25c6d commit a0a9b62
Showing 1 changed file with 40 additions and 4 deletions.
44 changes: 40 additions & 4 deletions solidity/contracts/Module.sol
Original file line number Diff line number Diff line change
Expand Up @@ -73,27 +73,63 @@ abstract contract Module is IModule {
) internal pure returns (bytes32 _responseId) {
bytes32 _requestId = _getId(_request);
_responseId = _getId(_response);

if (_response.requestId != _requestId) revert Module_InvalidResponseBody();
}

/**
* @notice Validates the correctness of a request-response-dispute triplet
* @notice Validates the correctness of a request-dispute pair
*
* @param _request The request to compute the id for
* @param _response The response to compute the id for
* @param _dispute The dispute to compute the id for
* @return _disputeId The id the dispute
*/
function _validateDispute(
IOracle.Request calldata _request,
IOracle.Response calldata _response,
IOracle.Dispute calldata _dispute
) internal pure returns (bytes32 _disputeId) {
bytes32 _requestId = _getId(_request);
_disputeId = _getId(_dispute);

if (_dispute.requestId != _requestId) revert Module_InvalidDisputeBody();
}

/**
* @notice Validates the correctness of a response-dispute pair
*
* @param _response The response to compute the id for
* @param _dispute The dispute to compute the id for
* @return _disputeId The id the dispute
*/
function _validateDispute(
IOracle.Response calldata _response,
IOracle.Dispute calldata _dispute
) internal pure returns (bytes32 _disputeId) {
bytes32 _responseId = _getId(_response);
_disputeId = _getId(_dispute);

if (_dispute.requestId != _requestId || _dispute.responseId != _responseId) revert Module_InvalidDisputeBody();
if (_dispute.responseId != _responseId) revert Module_InvalidDisputeBody();
}

/**
* @notice Validates the correctness of a request-response-dispute triplet
*
* @param _request The request to compute the id for
* @param _response The response to compute the id for
* @param _dispute The dispute to compute the id for
* @return _responseId The id the response
* @return _disputeId The id the dispute
*/
function _validateResponseAndDispute(
IOracle.Request calldata _request,
IOracle.Response calldata _response,
IOracle.Dispute calldata _dispute
) internal pure returns (bytes32 _responseId, bytes32 _disputeId) {
bytes32 _requestId = _getId(_request);
_responseId = _getId(_response);
_disputeId = _getId(_dispute);

if (_response.requestId != _requestId) revert Module_InvalidResponseBody();
if (_dispute.requestId != _requestId || _dispute.responseId != _responseId) revert Module_InvalidDisputeBody();
}
}

0 comments on commit a0a9b62

Please sign in to comment.