Skip to content

Commit 165d9d6

Browse files
Le-CaignecCopilotgfournierProzguesmi
authored
feat: enhance isDatasetCompatibleWithDeal function to return with a reason (#267)
Co-authored-by: Copilot <[email protected]> Co-authored-by: gfournieriExec <[email protected]> Co-authored-by: Zied Guesmi <[email protected]>
1 parent ab11bb4 commit 165d9d6

File tree

5 files changed

+147
-151
lines changed

5 files changed

+147
-151
lines changed

contracts/facets/IexecPoco1Facet.sol

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -68,35 +68,36 @@ contract IexecPoco1Facet is IexecPoco1, FacetBase, IexecEscrow, SignatureVerifie
6868
*
6969
* @param datasetOrder The dataset order to verify
7070
* @param dealid The deal ID to check against
71-
* @return true if the dataset order is compatible with the deal, false otherwise
71+
* @return result true if the dataset order is compatible with the deal, false otherwise
72+
* @return reason the specific reason why the compatibility check failed, empty string if successful
7273
*/
7374
function isDatasetCompatibleWithDeal(
7475
IexecLibOrders_v5.DatasetOrder calldata datasetOrder,
7576
bytes32 dealid
76-
) external view override returns (bool) {
77+
) external view override returns (bool result, string memory reason) {
7778
PocoStorageLib.PocoStorage storage $ = PocoStorageLib.getPocoStorage();
7879
// Check if deal exists
7980
IexecLibCore_v5.Deal storage deal = $.m_deals[dealid];
8081
if (deal.requester == address(0)) {
81-
return false;
82+
return (false, "Deal does not exist");
8283
}
8384
// The specified deal should not have a dataset.
8485
if (deal.dataset.pointer != address(0)) {
85-
return false;
86+
return (false, "Deal already has a dataset");
8687
}
8788
// Check dataset order owner signature (including presign and EIP1271)
8889
bytes32 datasetOrderHash = _toTypedDataHash(datasetOrder.hash());
8990
address datasetOwner = IERC5313(datasetOrder.dataset).owner();
9091
if (!_verifySignatureOrPresignature(datasetOwner, datasetOrderHash, datasetOrder.sign)) {
91-
return false;
92+
return (false, "Invalid dataset order signature");
9293
}
9394
// Check if dataset order is not fully consumed
9495
if ($.m_consumed[datasetOrderHash] >= datasetOrder.volume) {
95-
return false;
96+
return (false, "Dataset order is fully consumed");
9697
}
9798
// Check if deal app is allowed by dataset order apprestrict (including whitelist)
9899
if (!_isAccountAuthorizedByRestriction(datasetOrder.apprestrict, deal.app.pointer)) {
99-
return false;
100+
return (false, "App restriction not satisfied");
100101
}
101102
// Check if deal workerpool is allowed by dataset order workerpoolrestrict (including whitelist)
102103
if (
@@ -105,17 +106,17 @@ contract IexecPoco1Facet is IexecPoco1, FacetBase, IexecEscrow, SignatureVerifie
105106
deal.workerpool.pointer
106107
)
107108
) {
108-
return false;
109+
return (false, "Workerpool restriction not satisfied");
109110
}
110111
// Check if deal requester is allowed by dataset order requesterrestrict (including whitelist)
111112
if (!_isAccountAuthorizedByRestriction(datasetOrder.requesterrestrict, deal.requester)) {
112-
return false;
113+
return (false, "Requester restriction not satisfied");
113114
}
114115
// Check if deal tag fulfills all the tag bits of the dataset order
115116
if ((deal.tag & datasetOrder.tag) != datasetOrder.tag) {
116-
return false;
117+
return (false, "Tag compatibility not satisfied");
117118
}
118-
return true;
119+
return (true, "");
119120
}
120121

121122
/***************************************************************************

contracts/interfaces/IexecPoco1.sol

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,5 +50,5 @@ interface IexecPoco1 {
5050
function isDatasetCompatibleWithDeal(
5151
IexecLibOrders_v5.DatasetOrder calldata datasetOrder,
5252
bytes32 dealid
53-
) external view returns (bool);
53+
) external view returns (bool result, string memory reason);
5454
}

contracts/interfaces/IexecPoco1.v8.sol

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,5 +44,5 @@ interface IexecPoco1 {
4444
function isDatasetCompatibleWithDeal(
4545
IexecLibOrders_v5.DatasetOrder calldata datasetOrder,
4646
bytes32 dealid
47-
) external view returns (bool);
47+
) external view returns (bool result, string memory reason);
4848
}

docs/solidity/index.md

Lines changed: 112 additions & 111 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ function verifyPresignatureOrSignature(address _identity, bytes32 _hash, bytes _
7474
### isDatasetCompatibleWithDeal
7575

7676
```solidity
77-
function isDatasetCompatibleWithDeal(struct IexecLibOrders_v5.DatasetOrder datasetOrder, bytes32 dealid) external view returns (bool)
77+
function isDatasetCompatibleWithDeal(struct IexecLibOrders_v5.DatasetOrder datasetOrder, bytes32 dealid) external view returns (bool result, string reason)
7878
```
7979

8080
Public view function to check if a dataset order is compatible with a deal.
@@ -94,7 +94,8 @@ This function should not be used in matchOrders as it does not check the same re
9494

9595
| Name | Type | Description |
9696
| ---- | ---- | ----------- |
97-
| [0] | bool | true if the dataset order is compatible with the deal, false otherwise |
97+
| result | bool | true if the dataset order is compatible with the deal, false otherwise |
98+
| reason | string | the specific reason why the compatibility check failed, empty string if successful |
9899

99100
### matchOrders
100101

@@ -456,6 +457,115 @@ function groupmember_purpose() external pure returns (uint256)
456457
function eip712domain_separator() external view returns (bytes32)
457458
```
458459

460+
## IexecPocoBoostAccessorsFacet
461+
462+
Access to PoCo Boost tasks must be done with PoCo Classic `IexecAccessors`.
463+
464+
### viewDealBoost
465+
466+
```solidity
467+
function viewDealBoost(bytes32 id) external view returns (struct IexecLibCore_v5.DealBoost deal)
468+
```
469+
470+
Get a deal created by PoCo Boost facet.
471+
472+
#### Parameters
473+
474+
| Name | Type | Description |
475+
| ---- | ---- | ----------- |
476+
| id | bytes32 | The ID of the deal. |
477+
478+
## IexecPocoBoostFacet
479+
480+
Works for deals with requested trust = 0.
481+
482+
### matchOrdersBoost
483+
484+
```solidity
485+
function matchOrdersBoost(struct IexecLibOrders_v5.AppOrder appOrder, struct IexecLibOrders_v5.DatasetOrder datasetOrder, struct IexecLibOrders_v5.WorkerpoolOrder workerpoolOrder, struct IexecLibOrders_v5.RequestOrder requestOrder) external returns (bytes32)
486+
```
487+
488+
This boost match orders is only compatible with trust <= 1.
489+
The requester gets debited.
490+
491+
#### Parameters
492+
493+
| Name | Type | Description |
494+
| ---- | ---- | ----------- |
495+
| appOrder | struct IexecLibOrders_v5.AppOrder | The order signed by the application developer. |
496+
| datasetOrder | struct IexecLibOrders_v5.DatasetOrder | The order signed by the dataset provider. |
497+
| workerpoolOrder | struct IexecLibOrders_v5.WorkerpoolOrder | The order signed by the workerpool manager. |
498+
| requestOrder | struct IexecLibOrders_v5.RequestOrder | The order signed by the requester. |
499+
500+
#### Return Values
501+
502+
| Name | Type | Description |
503+
| ---- | ---- | ----------- |
504+
| [0] | bytes32 | The ID of the deal. |
505+
506+
### sponsorMatchOrdersBoost
507+
508+
```solidity
509+
function sponsorMatchOrdersBoost(struct IexecLibOrders_v5.AppOrder appOrder, struct IexecLibOrders_v5.DatasetOrder datasetOrder, struct IexecLibOrders_v5.WorkerpoolOrder workerpoolOrder, struct IexecLibOrders_v5.RequestOrder requestOrder) external returns (bytes32)
510+
```
511+
512+
Sponsor match orders boost for a requester.
513+
Unlike the standard `matchOrdersBoost(..)` hook where the requester pays for
514+
the deal, this current hook makes it possible for any `msg.sender` to pay for
515+
a third party requester.
516+
517+
Be aware that anyone seeing a valid request order on the network
518+
(via an off-chain public marketplace, via a `sponsorMatchOrdersBoost(..)`
519+
pending transaction in the mempool or by any other means) might decide
520+
to call the standard `matchOrdersBoost(..)` hook which will result in the
521+
requester being debited instead. Therefore, such a front run would result
522+
in a loss of some of the requester funds deposited in the iExec account
523+
(a loss value equivalent to the price of the deal).
524+
525+
#### Parameters
526+
527+
| Name | Type | Description |
528+
| ---- | ---- | ----------- |
529+
| appOrder | struct IexecLibOrders_v5.AppOrder | The app order. |
530+
| datasetOrder | struct IexecLibOrders_v5.DatasetOrder | The dataset order. |
531+
| workerpoolOrder | struct IexecLibOrders_v5.WorkerpoolOrder | The workerpool order. |
532+
| requestOrder | struct IexecLibOrders_v5.RequestOrder | The requester order. |
533+
534+
### pushResultBoost
535+
536+
```solidity
537+
function pushResultBoost(bytes32 dealId, uint256 index, bytes results, bytes resultsCallback, bytes authorizationSign, address enclaveChallenge, bytes enclaveSign) external
538+
```
539+
540+
Accept results of a task computed by a worker during Boost workflow.
541+
542+
#### Parameters
543+
544+
| Name | Type | Description |
545+
| ---- | ---- | ----------- |
546+
| dealId | bytes32 | The id of the target deal. |
547+
| index | uint256 | The index of the target task of the deal. |
548+
| results | bytes | The results of the task computed by the worker. |
549+
| resultsCallback | bytes | The results of the task computed by the worker that will be forwarded as call data to the callback address set by the requester. |
550+
| authorizationSign | bytes | The authorization signed by the scheduler. authorizing the worker to push a result. |
551+
| enclaveChallenge | address | The enclave address which can produce enclave signature. |
552+
| enclaveSign | bytes | The signature generated from the enclave. |
553+
554+
### claimBoost
555+
556+
```solidity
557+
function claimBoost(bytes32 dealId, uint256 index) external
558+
```
559+
560+
Claim task to get a refund if task is not completed after deadline.
561+
562+
#### Parameters
563+
564+
| Name | Type | Description |
565+
| ---- | ---- | ----------- |
566+
| dealId | bytes32 | The ID of the deal. |
567+
| index | uint256 | The index of the task. |
568+
459569
## IexecLibCore_v5
460570

461571
### Account
@@ -1651,112 +1761,3 @@ function manageWorkerpoolOrder(struct IexecLibOrders_v5.WorkerpoolOrderOperation
16511761
function manageRequestOrder(struct IexecLibOrders_v5.RequestOrderOperation _requestorderoperation) external
16521762
```
16531763

1654-
## IexecPocoBoostAccessorsFacet
1655-
1656-
Access to PoCo Boost tasks must be done with PoCo Classic `IexecAccessors`.
1657-
1658-
### viewDealBoost
1659-
1660-
```solidity
1661-
function viewDealBoost(bytes32 id) external view returns (struct IexecLibCore_v5.DealBoost deal)
1662-
```
1663-
1664-
Get a deal created by PoCo Boost facet.
1665-
1666-
#### Parameters
1667-
1668-
| Name | Type | Description |
1669-
| ---- | ---- | ----------- |
1670-
| id | bytes32 | The ID of the deal. |
1671-
1672-
## IexecPocoBoostFacet
1673-
1674-
Works for deals with requested trust = 0.
1675-
1676-
### matchOrdersBoost
1677-
1678-
```solidity
1679-
function matchOrdersBoost(struct IexecLibOrders_v5.AppOrder appOrder, struct IexecLibOrders_v5.DatasetOrder datasetOrder, struct IexecLibOrders_v5.WorkerpoolOrder workerpoolOrder, struct IexecLibOrders_v5.RequestOrder requestOrder) external returns (bytes32)
1680-
```
1681-
1682-
This boost match orders is only compatible with trust <= 1.
1683-
The requester gets debited.
1684-
1685-
#### Parameters
1686-
1687-
| Name | Type | Description |
1688-
| ---- | ---- | ----------- |
1689-
| appOrder | struct IexecLibOrders_v5.AppOrder | The order signed by the application developer. |
1690-
| datasetOrder | struct IexecLibOrders_v5.DatasetOrder | The order signed by the dataset provider. |
1691-
| workerpoolOrder | struct IexecLibOrders_v5.WorkerpoolOrder | The order signed by the workerpool manager. |
1692-
| requestOrder | struct IexecLibOrders_v5.RequestOrder | The order signed by the requester. |
1693-
1694-
#### Return Values
1695-
1696-
| Name | Type | Description |
1697-
| ---- | ---- | ----------- |
1698-
| [0] | bytes32 | The ID of the deal. |
1699-
1700-
### sponsorMatchOrdersBoost
1701-
1702-
```solidity
1703-
function sponsorMatchOrdersBoost(struct IexecLibOrders_v5.AppOrder appOrder, struct IexecLibOrders_v5.DatasetOrder datasetOrder, struct IexecLibOrders_v5.WorkerpoolOrder workerpoolOrder, struct IexecLibOrders_v5.RequestOrder requestOrder) external returns (bytes32)
1704-
```
1705-
1706-
Sponsor match orders boost for a requester.
1707-
Unlike the standard `matchOrdersBoost(..)` hook where the requester pays for
1708-
the deal, this current hook makes it possible for any `msg.sender` to pay for
1709-
a third party requester.
1710-
1711-
Be aware that anyone seeing a valid request order on the network
1712-
(via an off-chain public marketplace, via a `sponsorMatchOrdersBoost(..)`
1713-
pending transaction in the mempool or by any other means) might decide
1714-
to call the standard `matchOrdersBoost(..)` hook which will result in the
1715-
requester being debited instead. Therefore, such a front run would result
1716-
in a loss of some of the requester funds deposited in the iExec account
1717-
(a loss value equivalent to the price of the deal).
1718-
1719-
#### Parameters
1720-
1721-
| Name | Type | Description |
1722-
| ---- | ---- | ----------- |
1723-
| appOrder | struct IexecLibOrders_v5.AppOrder | The app order. |
1724-
| datasetOrder | struct IexecLibOrders_v5.DatasetOrder | The dataset order. |
1725-
| workerpoolOrder | struct IexecLibOrders_v5.WorkerpoolOrder | The workerpool order. |
1726-
| requestOrder | struct IexecLibOrders_v5.RequestOrder | The requester order. |
1727-
1728-
### pushResultBoost
1729-
1730-
```solidity
1731-
function pushResultBoost(bytes32 dealId, uint256 index, bytes results, bytes resultsCallback, bytes authorizationSign, address enclaveChallenge, bytes enclaveSign) external
1732-
```
1733-
1734-
Accept results of a task computed by a worker during Boost workflow.
1735-
1736-
#### Parameters
1737-
1738-
| Name | Type | Description |
1739-
| ---- | ---- | ----------- |
1740-
| dealId | bytes32 | The id of the target deal. |
1741-
| index | uint256 | The index of the target task of the deal. |
1742-
| results | bytes | The results of the task computed by the worker. |
1743-
| resultsCallback | bytes | The results of the task computed by the worker that will be forwarded as call data to the callback address set by the requester. |
1744-
| authorizationSign | bytes | The authorization signed by the scheduler. authorizing the worker to push a result. |
1745-
| enclaveChallenge | address | The enclave address which can produce enclave signature. |
1746-
| enclaveSign | bytes | The signature generated from the enclave. |
1747-
1748-
### claimBoost
1749-
1750-
```solidity
1751-
function claimBoost(bytes32 dealId, uint256 index) external
1752-
```
1753-
1754-
Claim task to get a refund if task is not completed after deadline.
1755-
1756-
#### Parameters
1757-
1758-
| Name | Type | Description |
1759-
| ---- | ---- | ----------- |
1760-
| dealId | bytes32 | The ID of the deal. |
1761-
| index | uint256 | The index of the task. |
1762-

0 commit comments

Comments
 (0)