Skip to content

Commit

Permalink
fix: incrrect requestid calculation (#70)
Browse files Browse the repository at this point in the history
  • Loading branch information
0xShaito authored Oct 21, 2024
1 parent 99f7143 commit b72dcda
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 7 deletions.
10 changes: 6 additions & 4 deletions solidity/contracts/modules/response/BondedResponseModule.sol
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,11 @@ contract BondedResponseModule is Module, IBondedResponseModule {
) external override(IBondedResponseModule, Module) onlyOracle {
RequestParameters memory _params = decodeRequestData(_request.responseModuleData);

bool _isModule = ORACLE.allowedModule(_response.requestId, _finalizer);
bytes32 _requestId = _getId(_request);

if (!_isModule && block.timestamp < ORACLE.requestCreatedAt(_response.requestId) + _params.deadline) {
bool _isModule = ORACLE.allowedModule(_requestId, _finalizer);

if (!_isModule && block.timestamp < ORACLE.requestCreatedAt(_requestId) + _params.deadline) {
revert BondedResponseModule_TooEarlyToFinalize();
}

Expand All @@ -88,13 +90,13 @@ contract BondedResponseModule is Module, IBondedResponseModule {

_params.accountingExtension.release({
_bonder: _response.proposer,
_requestId: _response.requestId,
_requestId: _requestId,
_token: _params.bondToken,
_amount: _params.bondSize
});
}

emit RequestFinalized(_response.requestId, _response, _finalizer);
emit RequestFinalized(_requestId, _response, _finalizer);
}

/// @inheritdoc IBondedResponseModule
Expand Down
8 changes: 5 additions & 3 deletions solidity/test/integration/ContractCallRequest.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -47,18 +47,20 @@ contract Integration_ContractCallRequest is IntegrationBase {
function test_createRequest_finalizeEmptyResponse() public {
vm.prank(requester);
bytes32 _requestId = oracle.createRequest(mockRequest, _ipfsHash);
uint256 _requestCreatedAt = oracle.requestCreatedAt(_requestId);

// mock an empty response
mockResponse =
IOracle.Response({proposer: makeAddr('not-the-proposer'), requestId: bytes32(0), response: bytes('')});
mockResponse = IOracle.Response({proposer: address(0), requestId: bytes32(0), response: bytes('')});

assertEq(oracle.responseCreatedAt(_getId(mockResponse)), 0);

// expect call to accounting to release requester's funds
vm.expectCall(
address(_accountingExtension),
abi.encodeCall(IAccountingExtension.release, (mockRequest.requester, _requestId, usdc, _expectedReward))
);

vm.warp(block.timestamp + 2 days);
vm.warp(_requestCreatedAt + _expectedDeadline);
vm.prank(_finalizer);
oracle.finalize(mockRequest, mockResponse);
}
Expand Down
41 changes: 41 additions & 0 deletions solidity/test/unit/modules/response/BondedResponseModule.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -464,6 +464,47 @@ contract BondedResponseModule_Unit_FinalizeRequest is BaseTest {
vm.prank(address(oracle));
bondedResponseModule.finalizeRequest(mockRequest, mockResponse, _finalizer);
}

function test_finalizeWithoutResponse(
IERC20 _token,
uint256 _bondSize,
uint256 _disputeWindow,
address _proposer,
uint256 _deadline
) public {
_disputeWindow = bound(_disputeWindow, 61, 365 days);

// Check correct calls are made if deadline has passed
_deadline = bound(_deadline, 1, type(uint248).max);
mockRequest.responseModuleData = abi.encode(accounting, _token, _bondSize, _deadline, _disputeWindow);
bytes32 _requestId = _getId(mockRequest);
mockResponse.requestId = _requestId;
mockResponse.proposer = _proposer;

// Mock and expect IOracle.allowedModule to be called
_mockAndExpect(
address(oracle), abi.encodeCall(IOracle.allowedModule, (_requestId, address(this))), abi.encode(false)
);

_mockAndExpect(
address(oracle), abi.encodeCall(IOracle.requestCreatedAt, (_getId(mockRequest))), abi.encode(requestCreatedAt)
);

// Empty response
mockResponse = IOracle.Response({proposer: address(0), requestId: bytes32(0), response: bytes('')});

// Response does not exist
_mockAndExpect(address(oracle), abi.encodeCall(IOracle.responseCreatedAt, (_getId(mockResponse))), abi.encode(0));

// Check: is event emitted?
vm.expectEmit(true, true, true, true, address(bondedResponseModule));
emit RequestFinalized({_requestId: _getId(mockRequest), _response: mockResponse, _finalizer: address(this)});

vm.warp(requestCreatedAt + _deadline + _disputeWindow);

vm.prank(address(oracle));
bondedResponseModule.finalizeRequest(mockRequest, mockResponse, address(this));
}
}

contract BondedResponseModule_Unit_ReleaseUnutilizedResponse is BaseTest {
Expand Down

0 comments on commit b72dcda

Please sign in to comment.