From 24259ed689fd2cb83145c6c3edac613042c2fe8d Mon Sep 17 00:00:00 2001 From: Ashitaka <96790496+ashitakah@users.noreply.github.com> Date: Tue, 16 Jul 2024 13:24:08 -0300 Subject: [PATCH] fix: checks bytes32 (#44) --- .../modules/dispute/RootVerificationModule.sol | 1 + .../modules/dispute/IRootVerificationModule.sol | 9 +++++++++ .../modules/dispute/RootVerificationModule.t.sol | 16 ++++++++++++++++ 3 files changed, 26 insertions(+) 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..f0a51f83 100644 --- a/solidity/test/unit/modules/dispute/RootVerificationModule.t.sol +++ b/solidity/test/unit/modules/dispute/RootVerificationModule.t.sol @@ -162,6 +162,22 @@ 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); + + // 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 */