Skip to content

Commit 5bffaf8

Browse files
authored
feat: improve TaskDescription with SGX or TDX requirements instead of generic TEE (#151)
1 parent 4aface8 commit 5bffaf8

File tree

4 files changed

+76
-17
lines changed

4 files changed

+76
-17
lines changed

src/main/java/com/iexec/commons/poco/task/TaskDescription.java

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,10 @@ public class TaskDescription {
6969
int botSize;
7070

7171
// TEE from tag
72+
/**
73+
* @deprecated use more specialized requiresSgx()/requiresTdx() instead
74+
*/
75+
@Deprecated(forRemoval = true)
7276
boolean isTeeTask;
7377
TeeFramework teeFramework;
7478

@@ -133,15 +137,14 @@ public boolean isBulkRequest() {
133137
* A task is eligible to the Contribute And Finalize flow
134138
* if it matches the following conditions:
135139
* <ul>
136-
* <li>It is a TEE task
137-
* <li>Its trust is 1
138-
* <li>It does not contain a callback - bug in the PoCo, should be fixed
140+
* <li>Its trust is 1
141+
* <li>It is a TEE task requiring a known SGX or TDX framework
139142
* </ul>
140143
*
141144
* @return {@literal true} if eligible, {@literal false} otherwise.
142145
*/
143146
public boolean isEligibleToContributeAndFinalize() {
144-
return isTeeTask && BigInteger.ONE.equals(trust);
147+
return BigInteger.ONE.equals(trust) && (requiresSgx() || requiresTdx());
145148
}
146149

147150
/**
@@ -153,6 +156,24 @@ public boolean requiresPreCompute() {
153156
return containsDataset() || containsInputFiles() || isBulkRequest();
154157
}
155158

159+
/**
160+
* Returns whether the SGX TEE framework is required or not
161+
*
162+
* @return {@literal true} if SGX is needed, {@literal false} otherwise
163+
*/
164+
public boolean requiresSgx() {
165+
return teeFramework == TeeFramework.SCONE || teeFramework == TeeFramework.GRAMINE;
166+
}
167+
168+
/**
169+
* Returns whether the TDX TEE framework is required or not
170+
*
171+
* @return {@literal true} if TDX is needed, {@literal false} otherwise
172+
*/
173+
public boolean requiresTdx() {
174+
return teeFramework == TeeFramework.TDX;
175+
}
176+
156177
/**
157178
* Create a {@link TaskDescription} from the provided chain deal. This method
158179
* if preferred to constructors or the builder method.

src/main/java/com/iexec/commons/poco/tee/TeeUtils.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,12 +42,16 @@ public class TeeUtils {
4242

4343
/**
4444
* Check if hexTag asks for a known TEE runtime framework.
45+
* <p>
46+
* To avoid breaking change, this will only deal with SGX
4547
*
4648
* @param hexTag tag of the deal
4749
* @return true if a known TEE runtime framework is requested
50+
* @deprecated for dedicated methods in {@code TaskDescription}
4851
*/
52+
@Deprecated(forRemoval = true)
4953
public static boolean isTeeTag(final String hexTag) {
50-
return hasTeeSconeInTag(hexTag) || hasTeeGramineInTag(hexTag) || hasTeeTdxInTag(hexTag);
54+
return hasTeeSconeInTag(hexTag) || hasTeeGramineInTag(hexTag);
5155
}
5256

5357
/**

src/test/java/com/iexec/commons/poco/task/TaskDescriptionTests.java

Lines changed: 44 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
import org.junit.jupiter.params.provider.Arguments;
2727
import org.junit.jupiter.params.provider.MethodSource;
2828
import org.junit.jupiter.params.provider.NullSource;
29-
import org.junit.jupiter.params.provider.ValueSource;
29+
import org.web3j.utils.Numeric;
3030

3131
import java.math.BigInteger;
3232
import java.util.Collections;
@@ -344,38 +344,72 @@ private static Stream<Arguments> provideDealParamsWithoutBulkCid() {
344344

345345
// region isEligibleToContributeAndFinalize
346346
@ParameterizedTest
347-
@ValueSource(strings = {"", CALLBACK})
348-
void shouldBeEligibleToContributeAndFinalize(final String callback) {
347+
@MethodSource("provideEligibleToContributeAndFinalizeParams")
348+
void shouldBeEligibleToContributeAndFinalize(final String tag, final String callback) {
349349
final TaskDescription taskDescription = TaskDescription.builder()
350-
.isTeeTask(true)
351350
.trust(BigInteger.ONE)
351+
.tag(tag)
352352
.callback(callback)
353+
.teeFramework(TeeUtils.getTeeFramework(tag))
353354
.build();
354355

355356
assertTrue(taskDescription.isEligibleToContributeAndFinalize());
356357
}
357358

358-
@Test
359-
void shouldNotBeEligibleToContributeAndFinalizeSinceNotTee() {
359+
static Stream<Arguments> provideEligibleToContributeAndFinalizeParams() {
360+
return Stream.of(
361+
Arguments.of(TeeUtils.TEE_SCONE_ONLY_TAG, ""),
362+
Arguments.of(TeeUtils.TEE_SCONE_ONLY_TAG, CALLBACK),
363+
Arguments.of(TeeUtils.TEE_GRAMINE_ONLY_TAG, ""),
364+
Arguments.of(TeeUtils.TEE_GRAMINE_ONLY_TAG, CALLBACK),
365+
Arguments.of(TeeUtils.TEE_TDX_ONLY_TAG, ""),
366+
Arguments.of(TeeUtils.TEE_TDX_ONLY_TAG, CALLBACK)
367+
);
368+
}
369+
370+
@ParameterizedTest
371+
@MethodSource("provideNotEligibleToContributeAndFinalizeTags")
372+
void shouldNotBeEligibleToContributeAndFinalizeWithInvalidTag(final String tag) {
360373
final TaskDescription taskDescription = TaskDescription.builder()
361-
.isTeeTask(false)
362374
.trust(BigInteger.ONE)
375+
.tag(tag)
363376
.callback("")
377+
.teeFramework(TeeUtils.getTeeFramework(tag))
364378
.build();
365379

366380
assertFalse(taskDescription.isEligibleToContributeAndFinalize());
367381
}
368382

369-
@Test
370-
void shouldNotBeEligibleToContributeAndFinalizeSinceWrongTrust() {
383+
static Stream<String> provideNotEligibleToContributeAndFinalizeTags() {
384+
return Stream.of(
385+
Numeric.toHexStringWithPrefixZeroPadded(BigInteger.valueOf(0x0), 32),
386+
Numeric.toHexStringWithPrefixZeroPadded(BigInteger.valueOf(0x1), 32),
387+
Numeric.toHexStringWithPrefixZeroPadded(BigInteger.valueOf(0x2), 32),
388+
Numeric.toHexStringWithPrefixZeroPadded(BigInteger.valueOf(0x4), 32),
389+
Numeric.toHexStringWithPrefixZeroPadded(BigInteger.valueOf(0x8), 32)
390+
);
391+
}
392+
393+
@ParameterizedTest
394+
@MethodSource("provideEligibleToContributeAndFinalizeTags")
395+
void shouldNotBeEligibleToContributeAndFinalizeSinceWrongTrust(final String tag) {
371396
final TaskDescription taskDescription = TaskDescription.builder()
372-
.isTeeTask(true)
373397
.trust(BigInteger.TEN)
398+
.tag(tag)
374399
.callback("")
400+
.teeFramework(TeeUtils.getTeeFramework(tag))
375401
.build();
376402

377403
assertFalse(taskDescription.isEligibleToContributeAndFinalize());
378404
}
405+
406+
static Stream<String> provideEligibleToContributeAndFinalizeTags() {
407+
return Stream.of(
408+
TeeUtils.TEE_SCONE_ONLY_TAG,
409+
TeeUtils.TEE_GRAMINE_ONLY_TAG,
410+
TeeUtils.TEE_TDX_ONLY_TAG
411+
);
412+
}
379413
// endregion
380414

381415
// region requiresPreCompute

src/test/java/com/iexec/commons/poco/tee/TeeUtilsTests.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ void areValidFields() {
4444
}
4545

4646
@ParameterizedTest
47-
@ValueSource(ints = {0x3, 0x5, 0x9, 0xf3, 0xf5, 0xf9})
47+
@ValueSource(ints = {0x3, 0x5, 0xf3, 0xf5})
4848
void isTeeTag(int tag) {
4949
assertThat(TeeUtils.isTeeTag(toByte32HexString(tag))).isTrue();
5050
}
@@ -53,7 +53,7 @@ void isTeeTag(int tag) {
5353
@ValueSource(ints = {
5454
0b0000, 0b0001, 0b0010,
5555
0b0100, 0b0110, 0b0111,
56-
0b1000, 0b1010, 0b1011,
56+
0b1000, 0b1001, 0b1010, 0b1011,
5757
0b1100, 0b1101, 0b1110, 0b1111
5858
})
5959
void isNotTeeTag(int tag) {

0 commit comments

Comments
 (0)