Skip to content

Commit

Permalink
fix: remove ipfs hash
Browse files Browse the repository at this point in the history
  • Loading branch information
0xShaito committed Dec 11, 2024
1 parent 3e1078a commit 835b91d
Show file tree
Hide file tree
Showing 10 changed files with 28 additions and 46 deletions.
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,5 +48,6 @@
"solhint-plugin-defi-wonderland": "1.1.2",
"sort-package-json": "2.4.1",
"standard-version": "9.5.0"
}
},
"packageManager": "[email protected]+sha512.a6b2f7906b721bba3d67d4aff083df04dad64c399707841b7acf00f6b133b7ac24255f2652fa22ae3534329dc6180534e98d17432037ff6fd140556e2bb3137e"
}
10 changes: 3 additions & 7 deletions solidity/contracts/Oracle.sol
Original file line number Diff line number Diff line change
Expand Up @@ -98,23 +98,21 @@ contract Oracle is IOracle, OracleAccessController {
/// @inheritdoc IOracle
function createRequest(
Request calldata _request,
bytes32 _ipfsHash,
AccessControl calldata _accessControl
) external returns (bytes32 _requestId) {
_requestId = _createRequest(_request, _ipfsHash, _accessControl);
_requestId = _createRequest(_request, _accessControl);
}

/// @inheritdoc IOracle
function createRequests(
Request[] calldata _requestsData,
bytes32[] calldata _ipfsHashes,
AccessControl[] calldata _accessControl
) external returns (bytes32[] memory _batchRequestsIds) {
uint256 _requestsAmount = _requestsData.length;
_batchRequestsIds = new bytes32[](_requestsAmount);

for (uint256 _i; _i < _requestsAmount;) {
_batchRequestsIds[_i] = _createRequest(_requestsData[_i], _ipfsHashes[_i], _accessControl[_i]);
_batchRequestsIds[_i] = _createRequest(_requestsData[_i], _accessControl[_i]);
unchecked {
++_i;
}
Expand Down Expand Up @@ -430,13 +428,11 @@ contract Oracle is IOracle, OracleAccessController {
* @notice Stores a request in the contract and configures it in the modules
*
* @param _request The request to be created
* @param _ipfsHash The hashed IPFS CID of the metadata json
* @param _accessControl The access control struct
* @return _requestId The id of the created request
*/
function _createRequest(
Request memory _request,
bytes32 _ipfsHash,
AccessControl calldata _accessControl
)
internal
Expand Down Expand Up @@ -465,6 +461,6 @@ contract Oracle is IOracle, OracleAccessController {

IRequestModule(_request.requestModule).createRequest(_requestId, _request.requestModuleData, _accessControl.user);

emit RequestCreated(_requestId, _request, _ipfsHash);
emit RequestCreated(_requestId, _request);
}
}
3 changes: 1 addition & 2 deletions solidity/contracts/utils/OracleTypehash.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@
pragma solidity ^0.8.19;

library OracleTypehash {
bytes32 public constant CREATE_TYPEHASH =
keccak256('createRequest(Request _request,bytes32 _ipfsHash,AccessControl _accessControl');
bytes32 public constant CREATE_TYPEHASH = keccak256('createRequest(Request _request,AccessControl _accessControl');

bytes32 public constant PROPOSE_TYPEHASH =
keccak256('proposeResponse(Request _request,Response _response,AccessControl _accessControl)');
Expand Down
7 changes: 1 addition & 6 deletions solidity/interfaces/IOracle.sol
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,8 @@ interface IOracle is IOracleAccessController {
* @notice Emitted when a request is created
* @param _requestId The id of the created request
* @param _request The request that has been created
* @param _ipfsHash The hashed IPFS CID of the metadata json
*/
event RequestCreated(bytes32 indexed _requestId, Request _request, bytes32 _ipfsHash);
event RequestCreated(bytes32 indexed _requestId, Request _request);

/**
* @notice Emitted when a response is proposed
Expand Down Expand Up @@ -366,13 +365,11 @@ interface IOracle is IOracleAccessController {
*
* @dev The modules must be real contracts following the IModule interface
* @param _request The request data
* @param _ipfsHash The hashed IPFS CID of the metadata json
* @param _accessControl The access control data
* @return _requestId The id of the request, can be used to propose a response or query results
*/
function createRequest(
Request memory _request,
bytes32 _ipfsHash,
AccessControl calldata _accessControl
) external returns (bytes32 _requestId);

Expand All @@ -381,12 +378,10 @@ interface IOracle is IOracleAccessController {
*
* @param _requestsData The array of calldata for each request
* @return _batchRequestsIds The array of request IDs
* @param _ipfsHashes The array of hashed IPFS CIDs of the metadata files
* @param _accessControl The array of access control datas
*/
function createRequests(
Request[] calldata _requestsData,
bytes32[] calldata _ipfsHashes,
AccessControl[] calldata _accessControl
) external returns (bytes32[] memory _batchRequestsIds);

Expand Down
2 changes: 1 addition & 1 deletion solidity/test/integration/EscalateDispute.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ contract Integration_EscalateDispute is IntegrationBase {
function test_escalateDispute() public {
// Create the request
mockAccessControl.user = requester;
oracle.createRequest(mockRequest, _ipfsHash, mockAccessControl);
oracle.createRequest(mockRequest, mockAccessControl);

// Submit a response
mockAccessControl.user = proposer;
Expand Down
12 changes: 6 additions & 6 deletions solidity/test/integration/Finalization.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ contract Integration_Finalization is IntegrationBase {
);

mockAccessControl.user = requester;
oracle.createRequest(mockRequest, _ipfsHash, mockAccessControl);
oracle.createRequest(mockRequest, mockAccessControl);

_jumpToFinalization();

Expand All @@ -39,7 +39,7 @@ contract Integration_Finalization is IntegrationBase {
abi.encode(IMockFinalityModule.RequestParameters({target: _callbackTarget, data: _calldata}));

mockAccessControl.user = requester;
bytes32 _requestId = oracle.createRequest(mockRequest, _ipfsHash, mockAccessControl);
bytes32 _requestId = oracle.createRequest(mockRequest, mockAccessControl);

_jumpToFinalization();

Expand All @@ -60,7 +60,7 @@ contract Integration_Finalization is IntegrationBase {
*/
function test_finalizeWithoutResponse() public {
mockAccessControl.user = requester;
oracle.createRequest(mockRequest, _ipfsHash, mockAccessControl);
oracle.createRequest(mockRequest, mockAccessControl);
vm.stopPrank();

mockResponse.requestId = bytes32(0);
Expand Down Expand Up @@ -88,7 +88,7 @@ contract Integration_Finalization is IntegrationBase {
mockDispute.responseId = _getId(mockResponse);

mockAccessControl.user = requester;
oracle.createRequest(mockRequest, _ipfsHash, mockAccessControl);
oracle.createRequest(mockRequest, mockAccessControl);

mockAccessControl.user = proposer;
oracle.proposeResponse(mockRequest, mockResponse, mockAccessControl);
Expand All @@ -109,7 +109,7 @@ contract Integration_Finalization is IntegrationBase {
abi.encode(IMockFinalityModule.RequestParameters({target: _callbackTarget, data: bytes('')}));

mockAccessControl.user = requester;
oracle.createRequest(mockRequest, _ipfsHash, mockAccessControl);
oracle.createRequest(mockRequest, mockAccessControl);
}

/**
Expand All @@ -121,7 +121,7 @@ contract Integration_Finalization is IntegrationBase {

mockAccessControl.user = requester;
vm.expectCall(_callbackTarget, _calldata);
oracle.createRequest(mockRequest, _ipfsHash, mockAccessControl);
oracle.createRequest(mockRequest, mockAccessControl);

_jumpToFinalization();

Expand Down
1 change: 0 additions & 1 deletion solidity/test/integration/IntegrationBase.sol
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@ contract IntegrationBase is TestConstants, Helpers {
uint256 internal _expectedDeadline;
uint256 internal _expectedCallbackValue = 42;
uint256 internal _baseDisputeWindow = 12 hours;
bytes32 internal _ipfsHash = bytes32('QmR4uiJH654k3Ta2uLLQ8r');

function setUp() public virtual {
vm.createSelectFork(vm.rpcUrl('optimism'), FORK_BLOCK);
Expand Down
2 changes: 1 addition & 1 deletion solidity/test/integration/ResponseDispute.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ contract Integration_ResponseDispute is IntegrationBase {
mockRequest.nonce = uint96(oracle.totalRequestCount());

mockAccessControl.user = requester;
_requestId = oracle.createRequest(mockRequest, _ipfsHash, mockAccessControl);
_requestId = oracle.createRequest(mockRequest, mockAccessControl);

mockResponse.requestId = _requestId;

Expand Down
6 changes: 3 additions & 3 deletions solidity/test/integration/ResponseProposal.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ contract Integration_ResponseProposal is IntegrationBase {
vm.expectRevert(
abi.encodeWithSelector(IOracleAccessController.OracleAccessController_AccessModuleNotApproved.selector)
);
oracle.createRequest(mockRequest, _ipfsHash, mockAccessControl);
oracle.createRequest(mockRequest, mockAccessControl);

vm.stopPrank();

Expand All @@ -41,11 +41,11 @@ contract Integration_ResponseProposal is IntegrationBase {

// Revert if access control is an EOA
vm.expectRevert();
oracle.createRequest(mockRequest, _ipfsHash, mockAccessControl);
oracle.createRequest(mockRequest, mockAccessControl);

// Create request
mockRequest.accessModule = address(_accessModule);
_requestId = oracle.createRequest(mockRequest, _ipfsHash, mockAccessControl);
_requestId = oracle.createRequest(mockRequest, mockAccessControl);
}

function test_proposeResponse_validResponse(bytes memory _response) public {
Expand Down
28 changes: 10 additions & 18 deletions solidity/test/unit/Oracle.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -94,11 +94,8 @@ contract BaseTest is Test, Helpers {
IFinalityModule public finalityModule = IFinalityModule(_mockContract('finalityModule'));
IAccessModule public accessModule = IAccessModule(_mockContract('accessModule'));

// Mock IPFS hash
bytes32 internal _ipfsHash = bytes32('QmR4uiJH654k3Ta2uLLQ8r');

// Events
event RequestCreated(bytes32 indexed _requestId, IOracle.Request _request, bytes32 _ipfsHash);
event RequestCreated(bytes32 indexed _requestId, IOracle.Request _request);
event ResponseProposed(bytes32 indexed _requestId, bytes32 indexed _responseId, IOracle.Response _response);
event ResponseDisputed(bytes32 indexed _responseId, bytes32 indexed _disputeId, IOracle.Dispute _dispute);
event OracleRequestFinalized(bytes32 indexed _requestId, bytes32 indexed _responseId);
Expand Down Expand Up @@ -172,10 +169,10 @@ contract Oracle_Unit_CreateRequest is BaseTest {

// Check: emits RequestCreated event?
_expectEmit(address(oracle));
emit RequestCreated(_getId(mockRequest), mockRequest, _ipfsHash);
emit RequestCreated(_getId(mockRequest), mockRequest);

// Test: create the request
bytes32 _requestId = oracle.createRequest(mockRequest, _ipfsHash, mockAccessControl);
bytes32 _requestId = oracle.createRequest(mockRequest, mockAccessControl);

// Check: Adds the requester to the list of participants
assertTrue(oracle.isParticipant(_requestId, requester));
Expand Down Expand Up @@ -211,7 +208,7 @@ contract Oracle_Unit_CreateRequest is BaseTest {
vm.expectRevert(IOracleAccessController.OracleAccessController_AccessModuleNotApproved.selector);

// Test: try to create the request
oracle.createRequest(mockRequest, _ipfsHash, mockAccessControl);
oracle.createRequest(mockRequest, mockAccessControl);
}

/**
Expand All @@ -228,7 +225,7 @@ contract Oracle_Unit_CreateRequest is BaseTest {

// Test: try to create the request
vm.prank(_caller);
oracle.createRequest(mockRequest, _ipfsHash, mockAccessControl);
oracle.createRequest(mockRequest, mockAccessControl);
}

/**
Expand All @@ -244,7 +241,7 @@ contract Oracle_Unit_CreateRequest is BaseTest {
vm.expectRevert(IOracle.Oracle_InvalidRequestBody.selector);

// Test: try to create the request
oracle.createRequest(mockRequest, _ipfsHash, mockAccessControl);
oracle.createRequest(mockRequest, mockAccessControl);
}

/**
Expand All @@ -260,7 +257,7 @@ contract Oracle_Unit_CreateRequest is BaseTest {
vm.expectRevert(IOracle.Oracle_InvalidRequestBody.selector);

// Test: try to create the request
oracle.createRequest(mockRequest, _ipfsHash, mockAccessControl);
oracle.createRequest(mockRequest, mockAccessControl);
}
}

Expand All @@ -278,7 +275,6 @@ contract Oracle_Unit_CreateRequests is BaseTest {
IOracle.Request[] memory _requests = new IOracle.Request[](_requestsAmount);
bytes32[] memory _precalculatedIds = new bytes32[](_requestsAmount);
bool _useResolutionAndFinality = _requestData.length % 2 == 0;
bytes32[] memory _ipfsHashes = new bytes32[](_requestsAmount);
IAccessController.AccessControl[] memory _accessControls = new IAccessController.AccessControl[](_requestsAmount);

vm.startPrank(requester);
Expand All @@ -295,16 +291,15 @@ contract Oracle_Unit_CreateRequests is BaseTest {
bytes32 _theoreticalRequestId = _getId(mockRequest);
_requests[_i] = mockRequest;
_precalculatedIds[_i] = _theoreticalRequestId;
_ipfsHashes[_i] = keccak256(abi.encode(_theoreticalRequestId, mockRequest.nonce));

_accessControls[_i].user = requester;

// Check: emits RequestCreated event?
_expectEmit(address(oracle));
emit RequestCreated(_theoreticalRequestId, mockRequest, _ipfsHashes[_i]);
emit RequestCreated(_theoreticalRequestId, mockRequest);
}

bytes32[] memory _requestsIds = oracle.createRequests(_requests, _ipfsHashes, _accessControls);
bytes32[] memory _requestsIds = oracle.createRequests(_requests, _accessControls);

for (uint256 _i = 0; _i < _requestsIds.length; _i++) {
assertEq(_requestsIds[_i], _precalculatedIds[_i]);
Expand Down Expand Up @@ -345,7 +340,6 @@ contract Oracle_Unit_CreateRequests is BaseTest {
uint256 _requestsAmount = 5;
IOracle.Request[] memory _requests = new IOracle.Request[](_requestsAmount);
bytes32[] memory _precalculatedIds = new bytes32[](_requestsAmount);
bytes32[] memory _ipfsHashes = new bytes32[](_requestsAmount);
IAccessController.AccessControl[] memory _accessControls = new IAccessController.AccessControl[](_requestsAmount);

mockRequest.requestModuleData = _requestData;
Expand All @@ -355,19 +349,17 @@ contract Oracle_Unit_CreateRequests is BaseTest {
mockRequest.nonce = uint96(0);

bytes32 _theoreticalRequestId = _getId(mockRequest);
bytes32 _ipfsHash = keccak256(abi.encode(_theoreticalRequestId, uint96(0)));

// Generate requests batch
for (uint256 _i = 0; _i < _requestsAmount; _i++) {
_requests[_i] = mockRequest;
_precalculatedIds[_i] = _theoreticalRequestId;
_ipfsHashes[_i] = _ipfsHash;
_accessControls[_i].user = requester;
}

vm.startPrank(requester);
oracle.mock_setAccessModuleApproved(requester, address(accessModule), true);
oracle.createRequests(_requests, _ipfsHashes, _accessControls);
oracle.createRequests(_requests, _accessControls);

uint256 _newNonce = oracle.totalRequestCount();
assertEq(_newNonce, _initialNonce + _requestsAmount);
Expand Down

0 comments on commit 835b91d

Please sign in to comment.