Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 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
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
b92e68d
refactor: move Matching struct from IexecPoco1 interface to IexecPoco…
Le-Caignec Sep 30, 2025
566d791
Update test/byContract/IexecPoco/IexecPoco1.test.ts
Le-Caignec Sep 30, 2025
b98a455
refactor: replace ethers.keccak256 with ethers.id for message hash ge…
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
67 changes: 60 additions & 7 deletions contracts/facets/IexecPoco1Facet.sol
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,7 @@ struct Matching {
bool hasDataset;
}

contract IexecPoco1Facet is
IexecPoco1,
FacetBase,
IexecEscrow,
SignatureVerifier,
IexecPocoCommon
{
contract IexecPoco1Facet is IexecPoco1, FacetBase, IexecEscrow, SignatureVerifier, IexecPocoCommon {
Copy link

Copilot AI Sep 30, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nitpick] The contract declaration formatting was changed from multi-line to single-line. While this works, the multi-line format is more readable for contracts with multiple inheritance, especially when the line becomes long.

Suggested change
contract IexecPoco1Facet is IexecPoco1, FacetBase, IexecEscrow, SignatureVerifier, IexecPocoCommon {
contract IexecPoco1Facet is
IexecPoco1,
FacetBase,
IexecEscrow,
SignatureVerifier,
IexecPocoCommon
{

Copilot uses AI. Check for mistakes.
using Math for uint256;
using IexecLibOrders_v5 for IexecLibOrders_v5.AppOrder;
using IexecLibOrders_v5 for IexecLibOrders_v5.DatasetOrder;
Expand Down Expand Up @@ -65,6 +59,65 @@ 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 true if the dataset order is compatible with the deal, false otherwise
*/
function isDatasetCompatibleWithDeal(
IexecLibOrders_v5.DatasetOrder calldata datasetOrder,
bytes32 dealid
) external view override returns (bool) {
PocoStorageLib.PocoStorage storage $ = PocoStorageLib.getPocoStorage();
// Check if deal exists
IexecLibCore_v5.Deal storage deal = $.m_deals[dealid];
if (deal.requester == address(0)) {
return false;
}
// The specified deal should not have a dataset.
if (deal.dataset.pointer != address(0)) {
return false;
}
// 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;
}
// Check if dataset order is not fully consumed
if ($.m_consumed[datasetOrderHash] >= datasetOrder.volume) {
return false;
}
// Check if deal app is allowed by dataset order apprestrict (including whitelist)
if (!_isAccountAuthorizedByRestriction(datasetOrder.apprestrict, deal.app.pointer)) {
return false;
}
// Check if deal workerpool is allowed by dataset order workerpoolrestrict (including whitelist)
if (
!_isAccountAuthorizedByRestriction(
datasetOrder.workerpoolrestrict,
deal.workerpool.pointer
)
) {
return false;
}
// Check if deal requester is allowed by dataset order requesterrestrict (including whitelist)
if (!_isAccountAuthorizedByRestriction(datasetOrder.requesterrestrict, deal.requester)) {
return false;
}
// Check if deal tag fulfills all the tag bits of the dataset order
if ((deal.tag & datasetOrder.tag) != datasetOrder.tag) {
return false;
}
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);
}
5 changes: 5 additions & 0 deletions contracts/interfaces/IexecPoco1.v8.sol
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,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);
}
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),
Copy link

Copilot AI Sep 30, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The IexecPocoAccessorsFacet__factory is instantiated twice - once assigned to iexecPocoAccessorsFacetFactory and again in the deployContract call. Use the existing iexecPocoAccessorsFacetFactory variable instead of creating a new instance.

Suggested change
new IexecPocoAccessorsFacet__factory(iexecLibOrders),
iexecPocoAccessorsFacetFactory,

Copilot uses AI. Check for mistakes.
);

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