Skip to content

Commit 5645e3d

Browse files
committed
refactor: Use a common function to ignore dataset bits
1 parent 81778ee commit 5645e3d

File tree

1 file changed

+38
-20
lines changed

1 file changed

+38
-20
lines changed

contracts/facets/IexecPoco1Facet.sol

Lines changed: 38 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -125,16 +125,17 @@ contract IexecPoco1Facet is
125125
if (!_isAccountAuthorizedByRestriction(datasetOrder.requesterrestrict, deal.requester)) {
126126
revert IncompatibleDatasetOrder("Requester restriction not satisfied");
127127
}
128-
// The deal's tag should include all tag bits of the dataset order.
129-
// For dataset orders: ignore Scone, Gramine, and TDX framework bits to allow
130-
// dataset orders from SGX workerpools to be consumed on TDX workerpools and vice versa.
131-
// Examples after masking:
132-
// Deal: 0b0101, Dataset: 0b0101 => Masked Dataset: 0b0001 => ok
133-
// Deal: 0b0101, Dataset: 0b0001 => Masked Dataset: 0b0001 => ok
134-
// Deal: 0b1001 (TDX), Dataset: 0b0011 (Scone) => Masked Dataset: 0b0001 => ok (cross-framework compatibility)
135-
bytes32 maskedDatasetTag = datasetOrder.tag &
136-
0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF1;
137-
if ((deal.tag & maskedDatasetTag) != maskedDatasetTag) {
128+
// The deal's tag should include all activated tag bits of the dataset order.
129+
// For the dataset tag, bits of TEE frameworks (Scone, Gramine, and TDX) must be ignored
130+
// to allow existing dataset orders with SGX tags to be consumed on TDX workerpools.
131+
// Examples:
132+
// Deal: 0b0101, Dataset: 0b0101 (final: 0b0001) => ok
133+
// Deal: 0b0101, Dataset: 0b0001 (final: 0b0001) => ok
134+
// Deal: 0b0000, Dataset: 0b0001 (final: 0b0001) => !ok
135+
// Cross-framework examples:
136+
// Deal: 0b1001 (TDX), Dataset: 0b0011 (Scone) (final: 0b0001) => ok
137+
bytes32 finalDatasetTag = _ignoreTeeFramework(datasetOrder.tag);
138+
if ((deal.tag & finalDatasetTag) != finalDatasetTag) {
138139
revert IncompatibleDatasetOrder("Tag compatibility not satisfied");
139140
}
140141
}
@@ -229,8 +230,7 @@ contract IexecPoco1Facet is
229230
/**
230231
* Check orders compatibility
231232
*/
232-
233-
// computation environment & allowed enough funds
233+
// Check computation environment & prices.
234234
require(_requestorder.category == _workerpoolorder.category, "iExecV5-matchOrders-0x00");
235235
require(_requestorder.category < $.m_categories.length, "iExecV5-matchOrders-0x01");
236236
require(_requestorder.trust <= _workerpoolorder.trust, "iExecV5-matchOrders-0x02");
@@ -243,14 +243,11 @@ contract IexecPoco1Facet is
243243
_requestorder.workerpoolmaxprice >= _workerpoolorder.workerpoolprice,
244244
"iExecV5-matchOrders-0x05"
245245
);
246-
// The workerpool tag should include all tag bits of dataset, app, and requester orders.
247-
// For dataset orders: ignore Scone, Gramine, and TDX framework bits to allow
248-
// dataset orders from SGX workerpools to be consumed on TDX workerpools and vice versa.
249-
// Bit positions: bit 0 = TEE, bit 1 = Scone, bit 2 = Gramine, bit 3 = TDX
250-
// Mask: ~(BIT_SCONE | BIT_GRAMINE | BIT_TDX) = ~0xE = 0xFFF...FF1
251-
bytes32 maskedDatasetTag = _datasetorder.tag &
252-
0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF1;
253-
bytes32 tag = _apporder.tag | maskedDatasetTag | _requestorder.tag;
246+
// Check tags compatibility:
247+
// - The workerpool tag should include all activated tag bits of dataset, app, and requester orders.
248+
// - For the dataset tag, bits of TEE frameworks (Scone, Gramine, and TDX) must be ignored
249+
// to allow existing dataset orders with SGX tags to be consumed on TDX workerpools.
250+
bytes32 tag = _apporder.tag | _ignoreTeeFramework(_datasetorder.tag) | _requestorder.tag;
254251
require(tag & ~_workerpoolorder.tag == 0x0, "iExecV5-matchOrders-0x06");
255252
require((tag ^ _apporder.tag)[31] & 0x01 == 0x0, "iExecV5-matchOrders-0x07");
256253

@@ -474,4 +471,25 @@ contract IexecPoco1Facet is
474471

475472
return dealid;
476473
}
474+
475+
/**
476+
* Ignore TEE framework bits (Scone, Gramine, TDX) in the provided tag to allow
477+
* cross-framework compatibility.
478+
*
479+
* Ignored bit positions in the tag:
480+
* 0b(31 bytes...)1111
481+
* ||||
482+
* |||└─ bit 0: TEE
483+
* ||└── bit 1: Scone (ignored)
484+
* |└─── bit 2: Gramine (ignored)
485+
* └──── bit 3: TDX (ignored)
486+
*
487+
* @param tag original tag
488+
* @return tag with TEE framework bits ignored
489+
*/
490+
function _ignoreTeeFramework(bytes32 tag) private pure returns (bytes32) {
491+
// (BIT_SCONE | BIT_GRAMINE | BIT_TDX) → 0b 0000 1110 = 0x0E
492+
// Mask = ~0x0E = 0xF1 → 0xFFF...FF1
493+
return tag & 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF1;
494+
}
477495
}

0 commit comments

Comments
 (0)