diff --git a/solidity/contracts/Oracle.sol b/solidity/contracts/Oracle.sol index e7d4ffa..cc3ed26 100644 --- a/solidity/contracts/Oracle.sol +++ b/solidity/contracts/Oracle.sol @@ -60,7 +60,7 @@ contract Oracle is IOracle { uint256 public totalRequestCount; /// @inheritdoc IOracle - function createRequest(NewRequest memory _request) external returns (bytes32 _requestId) { + function createRequest(NewRequest calldata _request) external returns (bytes32 _requestId) { _requestId = _createRequest(_request); } @@ -230,8 +230,8 @@ contract Oracle is IOracle { /// @inheritdoc IOracle function deleteResponse(bytes32 _responseId) external { - Response memory _response = _responses[_responseId]; - Request memory _request = _requests[_response.requestId]; + Response storage _response = _responses[_responseId]; + Request storage _request = _requests[_response.requestId]; if (disputeOf[_responseId] != bytes32(0)) { revert Oracle_CannotDeleteWhileDisputing(_responseId); @@ -241,11 +241,10 @@ contract Oracle is IOracle { } _request.responseModule.deleteResponse(_response.requestId, _responseId, msg.sender); - - delete _responses[_responseId]; _responseIds[_response.requestId].remove(_responseId); emit ResponseDeleted(_response.requestId, msg.sender, _responseId); + delete _responses[_responseId]; } /// @inheritdoc IOracle @@ -254,7 +253,7 @@ contract Oracle is IOracle { bytes32 _responseId, bytes calldata _moduleData ) external returns (bytes32 _disputeId) { - Request memory _request = _requests[_requestId]; + Request storage _request = _requests[_requestId]; if (_request.finalizedAt != 0) { revert Oracle_AlreadyFinalized(_requestId); } @@ -299,7 +298,7 @@ contract Oracle is IOracle { // Change the dispute status _dispute.status = DisputeStatus.Escalated; - Request memory _request = _requests[_dispute.requestId]; + Request storage _request = _requests[_dispute.requestId]; // Notify the dispute module about the escalation _request.disputeModule.disputeEscalated(_disputeId, _moduleData); @@ -314,7 +313,7 @@ contract Oracle is IOracle { /// @inheritdoc IOracle function resolveDispute(bytes32 _disputeId, bytes calldata _moduleData) external { - Dispute memory _dispute = _disputes[_disputeId]; + Dispute storage _dispute = _disputes[_disputeId]; if (_dispute.createdAt == 0) revert Oracle_InvalidDisputeId(_disputeId); // Revert if the dispute is not active nor escalated @@ -322,7 +321,7 @@ contract Oracle is IOracle { revert Oracle_CannotResolve(_disputeId); } - Request memory _request = _requests[_dispute.requestId]; + Request storage _request = _requests[_dispute.requestId]; if (address(_request.resolutionModule) == address(0)) { revert Oracle_NoResolutionModule(_disputeId); } @@ -335,7 +334,7 @@ contract Oracle is IOracle { /// @inheritdoc IOracle function updateDisputeStatus(bytes32 _disputeId, DisputeStatus _status, bytes calldata _moduleData) external { Dispute storage _dispute = _disputes[_disputeId]; - Request memory _request = _requests[_dispute.requestId]; + Request storage _request = _requests[_dispute.requestId]; if (msg.sender != address(_request.disputeModule) && msg.sender != address(_request.resolutionModule)) { revert Oracle_NotDisputeOrResolutionModule(msg.sender); } @@ -347,7 +346,7 @@ contract Oracle is IOracle { /// @inheritdoc IOracle function allowedModule(bytes32 _requestId, address _module) external view returns (bool _allowedModule) { - Request memory _request = _requests[_requestId]; + Request storage _request = _requests[_requestId]; _allowedModule = address(_request.requestModule) == _module || address(_request.responseModule) == _module || address(_request.disputeModule) == _module || address(_request.resolutionModule) == _module || address(_request.finalityModule) == _module; @@ -397,7 +396,7 @@ contract Oracle is IOracle { if (_request.finalizedAt != 0) { revert Oracle_AlreadyFinalized(_requestId); } - Response memory _response = _responses[_finalizedResponseId]; + Response storage _response = _responses[_finalizedResponseId]; if (_response.requestId != _requestId) { revert Oracle_InvalidFinalizedResponse(_finalizedResponseId); } @@ -407,7 +406,7 @@ contract Oracle is IOracle { } _finalizedResponses[_requestId] = _finalizedResponseId; - _request.finalizedAt = block.timestamp; + _request.finalizedAt = uint128(block.timestamp); _finalize(_requestId, _request); } @@ -435,7 +434,7 @@ contract Oracle is IOracle { } } } - _request.finalizedAt = block.timestamp; + _request.finalizedAt = uint128(block.timestamp); _finalize(_requestId, _request); } @@ -463,7 +462,7 @@ contract Oracle is IOracle { * @param _request The request to be created * @return _requestId The id of the created request */ - function _createRequest(NewRequest memory _request) internal returns (bytes32 _requestId) { + function _createRequest(NewRequest calldata _request) internal returns (bytes32 _requestId) { uint256 _requestNonce = totalRequestCount++; // bytes32 _requestHash = keccak256( // abi.encodePacked( @@ -509,8 +508,8 @@ contract Oracle is IOracle { // resolutionModule: _request.resolutionModule, // finalityModule: _request.finalityModule, // requester: msg.sender, - // nonce: _requestNonce, - // createdAt: block.timestamp, + // nonce: uint96(_requestNonce), + // createdAt: uint128(block.timestamp), // finalizedAt: 0 // }); diff --git a/solidity/interfaces/IOracle.sol b/solidity/interfaces/IOracle.sol index e2547c6..ea89745 100644 --- a/solidity/interfaces/IOracle.sol +++ b/solidity/interfaces/IOracle.sol @@ -200,15 +200,15 @@ interface IOracle { */ struct Request { bytes32 ipfsHash; + uint128 createdAt; + uint128 finalizedAt; + uint96 nonce; + address requester; IRequestModule requestModule; IResponseModule responseModule; IDisputeModule disputeModule; IResolutionModule resolutionModule; IFinalityModule finalityModule; - address requester; - uint256 nonce; - uint256 createdAt; - uint256 finalizedAt; } /** diff --git a/solidity/test/integration/ResponseProposal.t.sol b/solidity/test/integration/ResponseProposal.t.sol index 4db7f18..94efe76 100644 --- a/solidity/test/integration/ResponseProposal.t.sol +++ b/solidity/test/integration/ResponseProposal.t.sol @@ -98,7 +98,7 @@ // } // function test_proposeResponse_finalizedRequest(bytes memory _responseData, uint256 _timestamp) public { -// vm.assume(_timestamp > _expectedDeadline + _baseDisputeWindow); +// _timestamp = bound(_timestamp, _expectedDeadline + _baseDisputeWindow, type(uint128).max); // vm.prank(proposer); // bytes32 _responseId = oracle.proposeResponse(_requestId, _responseData); diff --git a/solidity/test/unit/Oracle.t.sol b/solidity/test/unit/Oracle.t.sol index 86819e3..69d5731 100644 --- a/solidity/test/unit/Oracle.t.sol +++ b/solidity/test/unit/Oracle.t.sol @@ -630,14 +630,14 @@ // // Mock and expect the responseModule propose call: // _mockAndExpect( // address(responseModule), -// abi.encodeCall(IResponseModule.propose, (_requestId, proposer, _responseData, _responseData, proposer)), +// abi.encodeCall(IResponseModule.propose, (_requestId, proposer, _responseData, proposer)), // abi.encode(mockResponse) // ); // // Test: propose the response // vm.expectRevert(abi.encodeWithSelector(IOracle.Oracle_CannotTamperParticipant.selector)); // vm.prank(proposer); -// oracle.proposeResponse(_requestId, _responseData, _responseData); +// oracle.proposeResponse(_requestId, _responseData); // // Change the proposer address // mockResponse.proposer = proposer; @@ -645,7 +645,7 @@ // // Mock and expect the responseModule propose call: // _mockAndExpect( // address(responseModule), -// abi.encodeCall(IResponseModule.propose, (_requestId, proposer, _responseData, _responseData, proposer)), +// abi.encodeCall(IResponseModule.propose, (_requestId, proposer, _responseData, proposer)), // abi.encode(mockResponse) // ); @@ -655,7 +655,7 @@ // // Test: propose the response // vm.prank(proposer); -// bytes32 _actualResponseId = oracle.proposeResponse(_requestId, _responseData, _responseData); +// bytes32 _actualResponseId = oracle.proposeResponse(_requestId, _responseData); // // Check: emits ResponseProposed event? // vm.expectEmit(true, true, true, true); @@ -664,7 +664,7 @@ // ); // vm.prank(proposer); -// bytes32 _secondResponseId = oracle.proposeResponse(_requestId, _responseData, _responseData); +// bytes32 _secondResponseId = oracle.proposeResponse(_requestId, _responseData); // // Check: correct response id returned? // assertEq(_actualResponseId, _responseId); @@ -689,7 +689,7 @@ // assertEq(_responseIds[1], _secondResponseId); // } -// function test_proposeResponseRevertsIfAlreadyFinalized(bytes calldata _responseData, uint256 _finalizedAt) public { +// function test_proposeResponseRevertsIfAlreadyFinalized(bytes calldata _responseData, uint128 _finalizedAt) public { // vm.assume(_finalizedAt > 0); // // Create mock request @@ -702,7 +702,7 @@ // // Should revert with already finalized // vm.expectRevert(abi.encodeWithSelector(IOracle.Oracle_AlreadyFinalized.selector, (_requestId))); -// oracle.proposeResponse(_requestId, _responseData, _responseData); +// oracle.proposeResponse(_requestId, _responseData); // } // } @@ -730,12 +730,12 @@ // // Test: revert if called by a random dude (not dispute module) // vm.expectRevert(abi.encodeWithSelector(IOracle.Oracle_NotDisputeModule.selector, _proposer)); // vm.prank(_proposer); -// oracle.proposeResponse(_proposer, _requestId, _responseData, _responseData); +// oracle.proposeResponse(_proposer, _requestId, _responseData); // // Mock and expect the responseModule propose call: // _mockAndExpect( // address(responseModule), -// abi.encodeCall(IResponseModule.propose, (_requestId, _proposer, _responseData, _responseData, address(disputeModule))), +// abi.encodeCall(IResponseModule.propose, (_requestId, _proposer, _responseData, address(disputeModule))), // abi.encode(mockResponse) // ); @@ -745,7 +745,7 @@ // // Test: propose the response // vm.prank(address(disputeModule)); -// bytes32 _actualResponseId = oracle.proposeResponse(_proposer, _requestId, _responseData, _responseData); +// bytes32 _actualResponseId = oracle.proposeResponse(_proposer, _requestId, _responseData); // // Check: emits ResponseProposed event? // vm.expectEmit(true, true, true, true); @@ -754,7 +754,7 @@ // ); // vm.prank(address(disputeModule)); -// bytes32 _secondResponseId = oracle.proposeResponse(_proposer, _requestId, _responseData, _responseData); +// bytes32 _secondResponseId = oracle.proposeResponse(_proposer, _requestId, _responseData); // // Check: correct response id returned? // assertEq(_actualResponseId, _responseId); @@ -793,12 +793,12 @@ // _mockAndExpect( // address(responseModule), -// abi.encodeCall(IResponseModule.propose, (_requestId, proposer, bytes('response'), bytes('response'), proposer)), +// abi.encodeCall(IResponseModule.propose, (_requestId, proposer, bytes('response'), proposer)), // abi.encode(mockResponse) // ); // vm.prank(proposer); -// bytes32 _responseId = oracle.proposeResponse(_requestId, bytes('response'), bytes('response')); +// bytes32 _responseId = oracle.proposeResponse(_requestId, bytes('response')); // _mockAndExpect( // address(responseModule),