Skip to content

Commit

Permalink
feat: checks bytes32
Browse files Browse the repository at this point in the history
  • Loading branch information
ashitakah committed Jul 8, 2024
1 parent 8a5f3f3 commit 5430f93
Show file tree
Hide file tree
Showing 3 changed files with 27 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
17 changes: 17 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,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
*/
Expand Down

0 comments on commit 5430f93

Please sign in to comment.