Skip to content
Merged
Show file tree
Hide file tree
Changes from 22 commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
543cb21
feat: implement dataset compatibility check in IexecPoco1Facet
Le-Caignec Sep 26, 2025
d3686d5
refactor: clean up IexecPoco1Facet and add tests for dataset compatib…
Le-Caignec Sep 26, 2025
27c6dbd
feat: deploy and update IexecPocoAccessorsFacet and IexecPoco1Facet
Le-Caignec Sep 26, 2025
1276187
test: enhance dataset compatibility tests in IexecPoco1
Le-Caignec Sep 26, 2025
69fef65
Update contracts/facets/IexecPoco1Facet.sol
Le-Caignec Sep 26, 2025
fd73a64
Update contracts/interfaces/IexecPoco1.v8.sol
Le-Caignec Sep 29, 2025
84d2490
feat: add dataset order compatibility check in IexecPoco1Facet
Le-Caignec Sep 29, 2025
0d9ff9b
refactor: remove deployment address logs for IexecPocoAccessorsFacet …
Le-Caignec Sep 29, 2025
15cc344
refactor: streamline deployment of IexecPocoAccessorsFacet in upgrade…
Le-Caignec Sep 29, 2025
481d526
refactor: remove deployment address logs and update logging for new f…
Le-Caignec Sep 29, 2025
e49ee33
Update test/byContract/IexecPoco/IexecPoco1.test.ts
Le-Caignec Sep 29, 2025
0ce1268
Update test/byContract/IexecPoco/IexecPoco1.test.ts
Le-Caignec Sep 29, 2025
263a7d8
feat: add isDatasetCompatibleWithDeal function to IexecPoco1 interfac…
Le-Caignec Sep 29, 2025
f95d6bc
test: add test for isDatasetCompatibleWithDeal function in IexecPoco1
Le-Caignec Sep 29, 2025
662ccee
feat: enhance isDatasetCompatibleWithDeal function to revert with det…
Le-Caignec Sep 29, 2025
e34696c
Update contracts/facets/IexecPoco1Facet.sol
Le-Caignec Sep 29, 2025
99b7a7b
docs: enhance documentation for isDatasetCompatibleWithDeal function …
Le-Caignec Sep 29, 2025
b9353bb
refactor: simplify isDatasetCompatibleWithDeal function logic in Iexe…
Le-Caignec Sep 29, 2025
4964b3c
Update contracts/facets/IexecPoco1Facet.sol
Le-Caignec Sep 29, 2025
df9fb9e
Update scripts/upgrades/deploy-and-update-some-facet.ts
Le-Caignec Sep 29, 2025
14f454e
Merge branch 'feature/add-isDatasetCompatibleWithDeal-function' into …
Le-Caignec Sep 29, 2025
d02ce06
refactor: update isDatasetCompatibleWithDeal function to return detai…
Le-Caignec Sep 29, 2025
b92e68d
refactor: move Matching struct from IexecPoco1 interface to IexecPoco…
Le-Caignec Sep 30, 2025
fd7434a
Merge branch 'feature/add-isDatasetCompatibleWithDeal-function' into …
Le-Caignec Sep 30, 2025
8c50d28
Update contracts/facets/IexecPoco1Facet.sol
Le-Caignec Sep 30, 2025
025f16b
Merge remote-tracking branch 'origin/main' into feature/add-isDataset…
Le-Caignec Sep 30, 2025
4fccf51
fix: clarify return value description in `isDatasetCompatibleWithDeal…
Le-Caignec Sep 30, 2025
15feec6
fix: improve return value documentation in `isDatasetCompatibleWithDe…
Le-Caignec Sep 30, 2025
5a1e932
test: refactor isDatasetCompatibleWithDeal tests for clarity and cons…
Le-Caignec Sep 30, 2025
ac9aa84
Merge branch 'main' into feature/add-isDatasetCompatibleWithDeal-func…
Le-Caignec Sep 30, 2025
b66c6bc
docs: enhance `isDatasetCompatibleWithDeal` function documentation an…
Le-Caignec Sep 30, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
79 changes: 61 additions & 18 deletions contracts/facets/IexecPoco1Facet.sol
Original file line number Diff line number Diff line change
Expand Up @@ -15,24 +15,7 @@ import {IexecEscrow} from "./IexecEscrow.v8.sol";
import {IexecPocoCommon} from "./IexecPocoCommon.sol";
import {SignatureVerifier} from "./SignatureVerifier.v8.sol";

struct Matching {
bytes32 apporderHash;
address appOwner;
bytes32 datasetorderHash;
address datasetOwner;
bytes32 workerpoolorderHash;
address workerpoolOwner;
bytes32 requestorderHash;
bool hasDataset;
}

contract IexecPoco1Facet is
IexecPoco1,
FacetBase,
IexecEscrow,
SignatureVerifier,
IexecPocoCommon
{
contract IexecPoco1Facet is IexecPoco1, FacetBase, IexecEscrow, SignatureVerifier, IexecPocoCommon {
using Math for uint256;
using IexecLibOrders_v5 for IexecLibOrders_v5.AppOrder;
using IexecLibOrders_v5 for IexecLibOrders_v5.DatasetOrder;
Expand Down Expand Up @@ -65,6 +48,66 @@ contract IexecPoco1Facet is
return _verifySignatureOrPresignature(_identity, _hash, _signature);
}

/**
* @notice Public view function to check if a dataset order is compatible with a deal.
* This function performs all the necessary checks to verify dataset order compatibility with a deal.
*
* @dev This function is mainly consumed by offchain clients. It should be carefully inspected if used inside on-chain code.
* This function should not be used in matchOrders as it does not check the same requirements.
*
* @param datasetOrder The dataset order to verify
* @param dealid The deal ID to check against
* @return result true if the dataset order is compatible with the deal, false otherwise
* @return reason the specific reason why the compatibility check failed, empty string if successful
*/
function isDatasetCompatibleWithDeal(
IexecLibOrders_v5.DatasetOrder calldata datasetOrder,
bytes32 dealid
) external view override returns (bool result, string memory reason) {
PocoStorageLib.PocoStorage storage $ = PocoStorageLib.getPocoStorage();
// Check if deal exists
IexecLibCore_v5.Deal storage deal = $.m_deals[dealid];
if (deal.requester == address(0)) {
return (false, "Deal does not exist");
}
// The specified deal should not have a dataset.
if (deal.dataset.pointer != address(0)) {
return (false, "Deal already has a dataset");
}
// Check dataset order owner signature (including presign and EIP1271)
bytes32 datasetOrderHash = _toTypedDataHash(datasetOrder.hash());
address datasetOwner = IERC5313(datasetOrder.dataset).owner();
if (!_verifySignatureOrPresignature(datasetOwner, datasetOrderHash, datasetOrder.sign)) {
return (false, "Invalid dataset order signature");
}
// Check if dataset order is not fully consumed
if ($.m_consumed[datasetOrderHash] >= datasetOrder.volume) {
return (false, "Dataset order is fully consumed");
}
// Check if deal app is allowed by dataset order apprestrict (including whitelist)
if (!_isAccountAuthorizedByRestriction(datasetOrder.apprestrict, deal.app.pointer)) {
return (false, "App restriction not satisfied");
}
// Check if deal workerpool is allowed by dataset order workerpoolrestrict (including whitelist)
if (
!_isAccountAuthorizedByRestriction(
datasetOrder.workerpoolrestrict,
deal.workerpool.pointer
)
) {
return (false, "Workerpool restriction not satisfied");
}
// Check if deal requester is allowed by dataset order requesterrestrict (including whitelist)
if (!_isAccountAuthorizedByRestriction(datasetOrder.requesterrestrict, deal.requester)) {
return (false, "Requester restriction not satisfied");
}
// Check if deal tag fulfills all the tag bits of the dataset order
if ((deal.tag & datasetOrder.tag) != datasetOrder.tag) {
return (false, "Tag compatibility not satisfied");
}
return (true, "");
}

/***************************************************************************
* ODB order matching *
***************************************************************************/
Expand Down
5 changes: 5 additions & 0 deletions contracts/interfaces/IexecPoco1.sol
Original file line number Diff line number Diff line change
Expand Up @@ -46,4 +46,9 @@ interface IexecPoco1 {
IexecLibOrders_v5.WorkerpoolOrder calldata,
IexecLibOrders_v5.RequestOrder calldata
) external returns (bytes32);

function isDatasetCompatibleWithDeal(
IexecLibOrders_v5.DatasetOrder calldata datasetOrder,
bytes32 dealid
) external view returns (bool result, string memory reason);
}
16 changes: 16 additions & 0 deletions contracts/interfaces/IexecPoco1.v8.sol
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,17 @@ pragma solidity ^0.8.0;
import {IexecLibOrders_v5} from "../libs/IexecLibOrders_v5.sol";

interface IexecPoco1 {
struct Matching {
bytes32 apporderHash;
address appOwner;
bytes32 datasetorderHash;
address datasetOwner;
bytes32 workerpoolorderHash;
address workerpoolOwner;
bytes32 requestorderHash;
bool hasDataset;
}

event SchedulerNotice(address indexed workerpool, bytes32 dealid);
event OrdersMatched(
bytes32 dealid,
Expand Down Expand Up @@ -40,4 +51,9 @@ interface IexecPoco1 {
IexecLibOrders_v5.WorkerpoolOrder calldata,
IexecLibOrders_v5.RequestOrder calldata
) external returns (bytes32);

function isDatasetCompatibleWithDeal(
IexecLibOrders_v5.DatasetOrder calldata datasetOrder,
bytes32 dealid
) external view returns (bool result, string memory reason);
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,21 @@
import { ZeroAddress } from 'ethers';
import { ethers } from 'hardhat';
import { FacetCutAction } from 'hardhat-deploy/dist/types';
import type { IDiamond } from '../../../typechain';
import type { IDiamond } from '../../typechain';
import {
DiamondCutFacet__factory,
DiamondLoupeFacet__factory,
IexecPoco1Facet__factory,
IexecPocoAccessorsFacet__factory,
} from '../../../typechain';
import { Ownable__factory } from '../../../typechain/factories/rlc-faucet-contract/contracts';
import { FactoryDeployer } from '../../../utils/FactoryDeployer';
import config from '../../../utils/config';
import { linkContractToProxy } from '../../../utils/proxy-tools';
import { printFunctions } from '../upgrade-helper';
} from '../../typechain';
import { Ownable__factory } from '../../typechain/factories/rlc-faucet-contract/contracts';
import { FactoryDeployer } from '../../utils/FactoryDeployer';
import config from '../../utils/config';
import { linkContractToProxy } from '../../utils/proxy-tools';
import { printFunctions } from './upgrade-helper';

(async () => {
console.log('Deploying and updating IexecPocoAccessorsFacet...');
console.log('Deploying and updating IexecPocoAccessorsFacet & IexecPoco1Facet...');

const [account] = await ethers.getSigners();
const chainId = (await ethers.provider.getNetwork()).chainId;
Expand Down Expand Up @@ -47,18 +48,25 @@ import { printFunctions } from '../upgrade-helper';
proxyOwnerSigner,
);

console.log('\n=== Step 1: Deploying new IexecPocoAccessorsFacet ===');
console.log('\n=== Step 1: Deploying all new facets ===');
const factoryDeployer = new FactoryDeployer(account, chainId);
const iexecLibOrders = {
['contracts/libs/IexecLibOrders_v5.sol:IexecLibOrders_v5']:
deploymentOptions.IexecLibOrders_v5,
};

const newFacetFactory = new IexecPocoAccessorsFacet__factory(iexecLibOrders);
const newFacetAddress = await factoryDeployer.deployContract(newFacetFactory);
console.log('Deploying new IexecPocoAccessorsFacet...');
const iexecPocoAccessorsFacetFactory = new IexecPocoAccessorsFacet__factory(iexecLibOrders);
const iexecPocoAccessorsFacet = await factoryDeployer.deployContract(
new IexecPocoAccessorsFacet__factory(iexecLibOrders),
);

console.log('Deploying new IexecPoco1Facet...');
const newIexecPoco1FacetFactory = new IexecPoco1Facet__factory(iexecLibOrders);
const newIexecPoco1Facet = await factoryDeployer.deployContract(newIexecPoco1FacetFactory);

console.log(
'\n=== Step 2: Remove old facets (remove all functions of old accessors facets) ===',
'\n=== Step 2: Remove old facets (IexecAccessorsFacet & IexecPocoAccessorsFacet & IexecPoco1Facet) ===',
);

const diamondLoupe = DiamondLoupeFacet__factory.connect(diamondProxyAddress, account);
Expand Down Expand Up @@ -99,16 +107,17 @@ import { printFunctions } from '../upgrade-helper';
});
}

const oldAccessorFacets = [
const oldFacets = [
'0xEa232be31ab0112916505Aeb7A2a94b5571DCc6b', //IexecAccessorsFacet
'0xeb40697b275413241d9b31dE568C98B3EA12FFF0', //IexecPocoAccessorsFacet
'0x46b555fE117DFd8D4eAC2470FA2d739c6c3a0152', //IexecPoco1Facet
];
// Remove ALL functions from the old accessor facets using diamondLoupe.facetFunctionSelectors() except of constant founctions
for (const facetAddress of oldAccessorFacets) {
// Remove ALL functions from the old facets using diamondLoupe.facetFunctionSelectors() except of constant founctions
for (const facetAddress of oldFacets) {
const selectors = await diamondLoupe.facetFunctionSelectors(facetAddress);
if (selectors.length > 0) {
console.log(
`Removing old accessor facet ${facetAddress} with ${selectors.length} functions - will remove ALL`,
`Removing old facet ${facetAddress} with ${selectors.length} functions - will remove ALL`,
);
removalCuts.push({
facetAddress: ZeroAddress,
Expand All @@ -131,12 +140,23 @@ import { printFunctions } from '../upgrade-helper';
console.log('Diamond functions after removing old facets:');
await printFunctions(diamondProxyAddress);
}
console.log('\n=== Step 3: Updating diamond proxy with new facet ===');
await linkContractToProxy(diamondProxyAsOwner, newFacetAddress, newFacetFactory);
console.log('New functions added successfully');
console.log('\n=== Step 3: Updating diamond proxy with all new facets ===');
console.log('Adding new IexecPocoAccessorsFacet...');
await linkContractToProxy(
diamondProxyAsOwner,
iexecPocoAccessorsFacet,
iexecPocoAccessorsFacetFactory,
);
console.log('New IexecPocoAccessorsFacet added successfully');

console.log('Adding new IexecPoco1Facet ...');
await linkContractToProxy(diamondProxyAsOwner, newIexecPoco1Facet, newIexecPoco1FacetFactory);
console.log('New IexecPoco1Facet with isDatasetCompatibleWithDeal added successfully');

console.log('Diamond functions after adding new facet:');
console.log('Diamond functions after adding new facets:');
await printFunctions(diamondProxyAddress);

console.log('\nUpgrade completed successfully!');
console.log(`New IexecPocoAccessorsFacet deployed at: ${iexecPocoAccessorsFacet}`);
console.log(`New IexecPoco1Facet deployed at: ${newIexecPoco1Facet}`);
})();
Loading