diff --git a/solidity/contracts/modules/dispute/RootVerificationModule.sol b/solidity/contracts/modules/dispute/RootVerificationModule.sol index dadd45a4..c32016fe 100644 --- a/solidity/contracts/modules/dispute/RootVerificationModule.sol +++ b/solidity/contracts/modules/dispute/RootVerificationModule.sol @@ -71,6 +71,7 @@ contract RootVerificationModule is Module, IRootVerificationModule { IOracle.Response calldata _response, IOracle.Dispute calldata _dispute ) external onlyOracle { + if (_response.response.length != 32) revert RootVerificationModule_InvalidResponseLength(); RequestParameters memory _params = decodeRequestData(_request.disputeModuleData); bytes32 _correctRoot = _params.treeVerifier.calculateRoot(_params.treeData, _params.leavesToInsert); diff --git a/solidity/interfaces/modules/dispute/IRootVerificationModule.sol b/solidity/interfaces/modules/dispute/IRootVerificationModule.sol index 4b4c52d0..1877d2cf 100644 --- a/solidity/interfaces/modules/dispute/IRootVerificationModule.sol +++ b/solidity/interfaces/modules/dispute/IRootVerificationModule.sol @@ -17,6 +17,15 @@ import {IAccountingExtension} from '../../extensions/IAccountingExtension.sol'; * @dev This module is a pre-dispute module. It allows disputing and resolving a response in a single call. */ interface IRootVerificationModule is IDisputeModule { + /*/////////////////////////////////////////////////////////////// + ERRORS + //////////////////////////////////////////////////////////////*/ + + /** + * @notice Thrown when the response length is invalid + */ + error RootVerificationModule_InvalidResponseLength(); + /*/////////////////////////////////////////////////////////////// STRUCTS //////////////////////////////////////////////////////////////*/ diff --git a/solidity/test/unit/modules/dispute/RootVerificationModule.t.sol b/solidity/test/unit/modules/dispute/RootVerificationModule.t.sol index 63268009..ae6a06c2 100644 --- a/solidity/test/unit/modules/dispute/RootVerificationModule.t.sol +++ b/solidity/test/unit/modules/dispute/RootVerificationModule.t.sol @@ -162,6 +162,23 @@ contract RootVerificationModule_Unit_ModuleData is BaseTest { } contract RootVerificationModule_Unit_DisputeResponse is BaseTest { + /** + * @notice Test if dispute response reverts when the response length is invalid + */ + function test_revertIfResponseLengthIsInvalid(uint8 _length) public { + vm.assume(_length != 32); + mockRequest.disputeModuleData; + + // Create new Response memory struct with random values + mockResponse.response = new bytes(_length); + + // Check: revert if response length is invalid? + vm.expectRevert(IRootVerificationModule.RootVerificationModule_InvalidResponseLength.selector); + + vm.prank(address(oracle)); + rootVerificationModule.disputeResponse(mockRequest, mockResponse, mockDispute); + } + /** * @notice Test if dispute incorrect response returns the correct status */