Skip to content

Commit 543cb21

Browse files
committed
feat: implement dataset compatibility check in IexecPoco1Facet
Added a new public view function `isDatasetCompatibleWithDeal` to verify the compatibility of a dataset order with a deal. This function includes multiple checks such as deal existence, dataset order owner signature, and restrictions on app, workerpool, and requester. Removed the `Matching` struct from `IexecPoco1Facet` and moved it to the `IexecPoco1` interface.
1 parent ccfe6e5 commit 543cb21

File tree

2 files changed

+84
-18
lines changed

2 files changed

+84
-18
lines changed

contracts/facets/IexecPoco1Facet.sol

Lines changed: 68 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -15,24 +15,7 @@ import {IexecEscrow} from "./IexecEscrow.v8.sol";
1515
import {IexecPocoCommon} from "./IexecPocoCommon.sol";
1616
import {SignatureVerifier} from "./SignatureVerifier.v8.sol";
1717

18-
struct Matching {
19-
bytes32 apporderHash;
20-
address appOwner;
21-
bytes32 datasetorderHash;
22-
address datasetOwner;
23-
bytes32 workerpoolorderHash;
24-
address workerpoolOwner;
25-
bytes32 requestorderHash;
26-
bool hasDataset;
27-
}
28-
29-
contract IexecPoco1Facet is
30-
IexecPoco1,
31-
FacetBase,
32-
IexecEscrow,
33-
SignatureVerifier,
34-
IexecPocoCommon
35-
{
18+
contract IexecPoco1Facet is IexecPoco1, FacetBase, IexecEscrow, SignatureVerifier, IexecPocoCommon {
3619
using Math for uint256;
3720
using IexecLibOrders_v5 for IexecLibOrders_v5.AppOrder;
3821
using IexecLibOrders_v5 for IexecLibOrders_v5.DatasetOrder;
@@ -387,4 +370,71 @@ contract IexecPoco1Facet is
387370

388371
return dealid;
389372
}
373+
374+
/**
375+
* @notice Public view function to check if a dataset order is compatible with a deal.
376+
* This function performs all the necessary checks to verify dataset order compatibility with a deal.
377+
*
378+
* @param datasetOrder The dataset order to verify
379+
* @param dealid The deal ID to check against
380+
* @return true if the dataset order is compatible with the deal, false otherwise
381+
*/
382+
function isDatasetCompatibleWithDeal(
383+
IexecLibOrders_v5.DatasetOrder calldata datasetOrder,
384+
bytes32 dealid
385+
) external view override returns (bool) {
386+
PocoStorageLib.PocoStorage storage $ = PocoStorageLib.getPocoStorage();
387+
388+
// Check if deal exists
389+
//TODO: check
390+
IexecLibCore_v5.Deal storage deal = $.m_deals[dealid];
391+
if (deal.requester == address(0)) {
392+
return false;
393+
}
394+
395+
// Check if deal dataset is address 0 (no dataset in deal)
396+
if (deal.dataset.pointer != address(0)) {
397+
return false;
398+
}
399+
400+
// Check dataset order owner signature (including presign and EIP1271)
401+
bytes32 datasetOrderHash = _toTypedDataHash(datasetOrder.hash());
402+
address datasetOwner = IERC5313(datasetOrder.dataset).owner();
403+
if (!_verifySignatureOrPresignature(datasetOwner, datasetOrderHash, datasetOrder.sign)) {
404+
return false; // Invalid signature
405+
}
406+
407+
// Check if dataset order is not fully consumed
408+
if ($.m_consumed[datasetOrderHash] >= datasetOrder.volume) {
409+
return false;
410+
}
411+
412+
// Check if deal app is allowed by dataset order apprestrict (including whitelist)
413+
if (!_isAccountAuthorizedByRestriction(datasetOrder.apprestrict, deal.app.pointer)) {
414+
return false;
415+
}
416+
417+
// Check if deal workerpool is allowed by dataset order workerpoolrestrict (including whitelist)
418+
if (
419+
!_isAccountAuthorizedByRestriction(
420+
datasetOrder.workerpoolrestrict,
421+
deal.workerpool.pointer
422+
)
423+
) {
424+
return false;
425+
}
426+
427+
// Check if deal requester is allowed by dataset order requesterrestrict (including whitelist)
428+
if (!_isAccountAuthorizedByRestriction(datasetOrder.requesterrestrict, deal.requester)) {
429+
return false;
430+
}
431+
432+
// Check if deal tag fulfills all the tag bits of the dataset order
433+
if ((deal.tag & datasetOrder.tag) != datasetOrder.tag) {
434+
return false;
435+
}
436+
437+
// All checks passed
438+
return true;
439+
}
390440
}

contracts/interfaces/IexecPoco1.v8.sol

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,17 @@ pragma solidity ^0.8.0;
66
import {IexecLibOrders_v5} from "../libs/IexecLibOrders_v5.sol";
77

88
interface IexecPoco1 {
9+
struct Matching {
10+
bytes32 apporderHash;
11+
address appOwner;
12+
bytes32 datasetorderHash;
13+
address datasetOwner;
14+
bytes32 workerpoolorderHash;
15+
address workerpoolOwner;
16+
bytes32 requestorderHash;
17+
bool hasDataset;
18+
}
19+
920
event SchedulerNotice(address indexed workerpool, bytes32 dealid);
1021
event OrdersMatched(
1122
bytes32 dealid,
@@ -40,4 +51,9 @@ interface IexecPoco1 {
4051
IexecLibOrders_v5.WorkerpoolOrder calldata,
4152
IexecLibOrders_v5.RequestOrder calldata
4253
) external returns (bytes32);
54+
55+
function isDatasetCompatibleWithDeal(
56+
IexecLibOrders_v5.DatasetOrder calldata datasetOrder,
57+
bytes32 dealid
58+
) external view returns (bool);
4359
}

0 commit comments

Comments
 (0)