From a0a9b628019551035db5bf8c2fae88b281d413ac Mon Sep 17 00:00:00 2001 From: 0xJabberwock <0xjabberwock@defi.sucks> Date: Mon, 22 Jul 2024 15:07:20 -0300 Subject: [PATCH] feat: module validations (#34) --- solidity/contracts/Module.sol | 44 +++++++++++++++++++++++++++++++---- 1 file changed, 40 insertions(+), 4 deletions(-) diff --git a/solidity/contracts/Module.sol b/solidity/contracts/Module.sol index be016f09..fe1eb343 100644 --- a/solidity/contracts/Module.sol +++ b/solidity/contracts/Module.sol @@ -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(); } }