Skip to content

Commit

Permalink
fix: checks bytes32 (#44)
Browse files Browse the repository at this point in the history
  • Loading branch information
ashitakah authored Jul 16, 2024
1 parent cad5c3b commit 24259ed
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
//////////////////////////////////////////////////////////////*/
Expand Down
16 changes: 16 additions & 0 deletions solidity/test/unit/modules/dispute/RootVerificationModule.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand Down

0 comments on commit 24259ed

Please sign in to comment.