Skip to content

Commit 91566eb

Browse files
authored
feat: add new 0x9 tag for TDX TEE framework (#148)
1 parent c65e59e commit 91566eb

File tree

4 files changed

+87
-66
lines changed

4 files changed

+87
-66
lines changed

src/main/java/com/iexec/commons/poco/order/OrderTag.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2020-2023 IEXEC BLOCKCHAIN TECH
2+
* Copyright 2020-2025 IEXEC BLOCKCHAIN TECH
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -20,13 +20,14 @@
2020
import com.iexec.commons.poco.utils.BytesUtils;
2121
import lombok.Getter;
2222

23-
@Getter
2423
public enum OrderTag {
2524

2625
STANDARD(BytesUtils.EMPTY_HEX_STRING_32),
2726
TEE_SCONE(TeeUtils.TEE_SCONE_ONLY_TAG),
28-
TEE_GRAMINE(TeeUtils.TEE_GRAMINE_ONLY_TAG);
27+
TEE_GRAMINE(TeeUtils.TEE_GRAMINE_ONLY_TAG),
28+
TEE_TDX(TeeUtils.TEE_TDX_ONLY_TAG);
2929

30+
@Getter
3031
private final String value;
3132

3233
OrderTag(String value) {

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

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2020-2023 IEXEC BLOCKCHAIN TECH
2+
* Copyright 2020-2025 IEXEC BLOCKCHAIN TECH
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -17,8 +17,7 @@
1717
package com.iexec.commons.poco.tee;
1818

1919
public enum TeeFramework {
20-
2120
SCONE,
22-
GRAMINE
23-
21+
GRAMINE,
22+
TDX
2423
}

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

Lines changed: 31 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2020-2023 IEXEC BLOCKCHAIN TECH
2+
* Copyright 2020-2025 IEXEC BLOCKCHAIN TECH
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -17,65 +17,77 @@
1717
package com.iexec.commons.poco.tee;
1818

1919
import com.iexec.commons.poco.utils.BytesUtils;
20+
import lombok.AccessLevel;
21+
import lombok.NoArgsConstructor;
2022
import org.web3j.utils.Numeric;
2123

2224
import java.math.BigInteger;
2325
import java.util.Map;
2426

27+
@NoArgsConstructor(access = AccessLevel.PRIVATE)
2528
public class TeeUtils {
2629

2730
public static final int TEE_SCONE_BITS = 0b0011;
2831
public static final int TEE_GRAMINE_BITS = 0b0101;
32+
public static final int TEE_TDX_BITS = 0b1001;
2933
private static final Map<Integer, TeeFramework> TEE_BITS_TO_FRAMEWORK = Map.of(
3034
TEE_SCONE_BITS, TeeFramework.SCONE,
31-
TEE_GRAMINE_BITS, TeeFramework.GRAMINE
35+
TEE_GRAMINE_BITS, TeeFramework.GRAMINE,
36+
TEE_TDX_BITS, TeeFramework.TDX
3237
);
3338
public static final String TEE_SCONE_ONLY_TAG = BytesUtils.toByte32HexString(TEE_SCONE_BITS);
3439
public static final String TEE_GRAMINE_ONLY_TAG = BytesUtils.toByte32HexString(TEE_GRAMINE_BITS);
40+
public static final String TEE_TDX_ONLY_TAG = BytesUtils.toByte32HexString(TEE_TDX_BITS);
3541
private static final int TEE_RUNTIME_FRAMEWORK_MASK = 0b1111; //last nibble (4 bits)
3642

37-
private TeeUtils() {
38-
throw new UnsupportedOperationException();
39-
}
40-
4143
/**
4244
* Check if hexTag asks for a known TEE runtime framework.
4345
*
4446
* @param hexTag tag of the deal
4547
* @return true if a known TEE runtime framework is requested
4648
*/
47-
public static boolean isTeeTag(String hexTag) {
48-
return hasTeeSconeInTag(hexTag) || hasTeeGramineInTag(hexTag);
49+
public static boolean isTeeTag(final String hexTag) {
50+
return hasTeeSconeInTag(hexTag) || hasTeeGramineInTag(hexTag) || hasTeeTdxInTag(hexTag);
4951
}
5052

5153
/**
52-
* Check if tag asks for Scone TEE runtime framework.
54+
* Check if tag asks for Scone TEE framework.
5355
*
5456
* @param hexTag tag of the deal
55-
* @return true if Scone TEE runtime framework is requested
57+
* @return true if Scone TEE framework is requested
5658
*/
57-
public static boolean hasTeeSconeInTag(String hexTag) {
59+
static boolean hasTeeSconeInTag(final String hexTag) {
5860
return hasTeeRuntimeFrameworkBitsInTag(TEE_SCONE_BITS, hexTag);
5961
}
6062

6163
/**
62-
* Check if tag asks for Gramine TEE runtime framework.
64+
* Check if tag asks for Gramine TEE framework.
6365
*
6466
* @param hexTag tag of the deal
65-
* @return true if Gramine TEE runtime framework is requested
67+
* @return true if Gramine TEE framework is requested
6668
*/
67-
public static boolean hasTeeGramineInTag(String hexTag) {
69+
static boolean hasTeeGramineInTag(final String hexTag) {
6870
return hasTeeRuntimeFrameworkBitsInTag(TEE_GRAMINE_BITS, hexTag);
6971
}
7072

73+
/**
74+
* Check if tag asks for TDX TEE framework.
75+
*
76+
* @param hexTag tag of the deal
77+
* @return true if TDX TEE framework is requested
78+
*/
79+
static boolean hasTeeTdxInTag(final String hexTag) {
80+
return hasTeeRuntimeFrameworkBitsInTag(TEE_TDX_BITS, hexTag);
81+
}
82+
7183
/**
7284
* Check if some bits are set on the TEE runtime framework range.
7385
*
7486
* @param expectedBits some bits expected to be in the tag
7587
* @param hexTag tag of the deal
7688
* @return true if bits are set
7789
*/
78-
static boolean hasTeeRuntimeFrameworkBitsInTag(int expectedBits, String hexTag) {
90+
static boolean hasTeeRuntimeFrameworkBitsInTag(final int expectedBits, final String hexTag) {
7991
return hexTag != null && Numeric.toBigInt(hexTag)
8092
.and(BigInteger.valueOf(TEE_RUNTIME_FRAMEWORK_MASK))
8193
.equals(BigInteger.valueOf(expectedBits));
@@ -98,6 +110,10 @@ public static TeeFramework getTeeFramework(String hexTag) {
98110
return null;
99111
}
100112

113+
/**
114+
* @deprecated not used
115+
*/
116+
@Deprecated(forRemoval = true)
101117
public static boolean isTeeChallenge(String challenge) {
102118
return challenge != null && !challenge.equals(BytesUtils.EMPTY_ADDRESS);
103119
}
Lines changed: 49 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2020-2023 IEXEC BLOCKCHAIN TECH
2+
* Copyright 2020-2025 IEXEC BLOCKCHAIN TECH
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -16,7 +16,6 @@
1616

1717
package com.iexec.commons.poco.tee;
1818

19-
import org.junit.jupiter.api.Assertions;
2019
import org.junit.jupiter.api.Test;
2120
import org.junit.jupiter.params.ParameterizedTest;
2221
import org.junit.jupiter.params.provider.Arguments;
@@ -27,65 +26,74 @@
2726
import java.util.stream.Stream;
2827

2928
import static com.iexec.commons.poco.utils.BytesUtils.toByte32HexString;
29+
import static org.assertj.core.api.Assertions.assertThat;
3030

3131
class TeeUtilsTests {
3232

3333
@Test
3434
void areValidFields() {
35-
Assertions.assertEquals(0b0011, TeeUtils.TEE_SCONE_BITS);
36-
Assertions.assertEquals(0b0101, TeeUtils.TEE_GRAMINE_BITS);
37-
Assertions.assertEquals("0x0000000000000000000000000000000000000000000000000000000000000003",
38-
TeeUtils.TEE_SCONE_ONLY_TAG);
39-
Assertions.assertEquals("0x0000000000000000000000000000000000000000000000000000000000000005",
40-
TeeUtils.TEE_GRAMINE_ONLY_TAG);
35+
assertThat(TeeUtils.TEE_SCONE_BITS).isEqualTo(0b0011);
36+
assertThat(TeeUtils.TEE_GRAMINE_BITS).isEqualTo(0b0101);
37+
assertThat(TeeUtils.TEE_TDX_BITS).isEqualTo(0b1001);
38+
assertThat(TeeUtils.TEE_SCONE_ONLY_TAG)
39+
.isEqualTo("0x0000000000000000000000000000000000000000000000000000000000000003");
40+
assertThat(TeeUtils.TEE_GRAMINE_ONLY_TAG)
41+
.isEqualTo("0x0000000000000000000000000000000000000000000000000000000000000005");
42+
assertThat(TeeUtils.TEE_TDX_ONLY_TAG)
43+
.isEqualTo("0x0000000000000000000000000000000000000000000000000000000000000009");
4144
}
4245

4346
@ParameterizedTest
44-
@ValueSource(ints = {
45-
0b0011, // 0x3: Scone
46-
0b0101, // : 0x5: Gramine
47-
0b11110011, // 0xf3: any (above TEE runtime framework mask) + Scone
48-
})
47+
@ValueSource(ints = {0x3, 0x5, 0x9, 0xf3, 0xf5, 0xf9})
4948
void isTeeTag(int tag) {
50-
Assertions.assertTrue(TeeUtils.isTeeTag(toByte32HexString(tag)));
49+
assertThat(TeeUtils.isTeeTag(toByte32HexString(tag))).isTrue();
5150
}
5251

5352
@ParameterizedTest
5453
@ValueSource(ints = {
55-
0b0000, // 0x0: empty
56-
0b0001, // 0x1: missing TEE runtime framework
57-
0b1001, // 0x9: no third TEE runtime framework existing for now ({Scone, Gramine, ?})
54+
0b0000, 0b0001, 0b0010,
55+
0b0100, 0b0110, 0b0111,
56+
0b1000, 0b1010, 0b1011,
57+
0b1100, 0b1101, 0b1110, 0b1111
5858
})
5959
void isNotTeeTag(int tag) {
60-
Assertions.assertFalse(TeeUtils.isTeeTag(toByte32HexString(tag)));
60+
assertThat(TeeUtils.isTeeTag(toByte32HexString(tag))).isFalse();
6161
}
6262

6363
@ParameterizedTest
64-
@ValueSource(ints = {
65-
0b0011, // 0x3: Scone
66-
0b11110011, // 0xf3: any (above TEE runtime framework mask) + Scone
67-
})
68-
void hasTeeSconeInTag(int tag) {
69-
Assertions.assertTrue(TeeUtils.hasTeeSconeInTag(toByte32HexString(tag)));
64+
@ValueSource(ints = {0x3, 0xf3})
65+
void hasTeeSconeInTag(final int tag) {
66+
assertThat(TeeUtils.hasTeeSconeInTag(toByte32HexString(tag))).isTrue();
7067
}
7168

72-
@Test
73-
void hasNotTeeSconeInTag() {
74-
Assertions.assertFalse(TeeUtils.hasTeeSconeInTag(toByte32HexString(0b0101))); // 0x5: Gramine
69+
@ParameterizedTest
70+
@ValueSource(ints = {0x5, 0x9, 0xf5, 0xf9})
71+
void hasNotTeeSconeInTag(final int tag) {
72+
assertThat(TeeUtils.hasTeeSconeInTag(toByte32HexString(tag))).isFalse();
7573
}
7674

7775
@ParameterizedTest
78-
@ValueSource(ints = {
79-
0b0101, // 0x5: Gramine
80-
0b11110101, // 0xf5: any (above TEE runtime framework mask) + Gramine
81-
})
82-
void hasTeeGramineInTag(int tag) {
83-
Assertions.assertTrue(TeeUtils.hasTeeGramineInTag(toByte32HexString(tag)));
76+
@ValueSource(ints = {0x5, 0xf5})
77+
void hasTeeGramineInTag(final int tag) {
78+
assertThat(TeeUtils.hasTeeGramineInTag(toByte32HexString(tag))).isTrue();
8479
}
8580

86-
@Test
87-
void hasNotTeeGramineInTag() {
88-
Assertions.assertFalse(TeeUtils.hasTeeGramineInTag(toByte32HexString(0b0011))); // 0x3: Scone
81+
@ParameterizedTest
82+
@ValueSource(ints = {0x3, 0x9, 0xf3, 0xf9})
83+
void hasNotTeeGramineInTag(final int tag) {
84+
assertThat(TeeUtils.hasTeeGramineInTag(toByte32HexString(tag))).isFalse();
85+
}
86+
87+
@ParameterizedTest
88+
@ValueSource(ints = {0x9, 0xf9})
89+
void hasTeeTdxInTag(final int tag) {
90+
assertThat(TeeUtils.hasTeeTdxInTag(toByte32HexString(tag))).isTrue();
91+
}
92+
93+
@ParameterizedTest
94+
@ValueSource(ints = {0x3, 0x5, 0xf3, 0xf5})
95+
void hasNotTeeTdxInTag(final int tag) {
96+
assertThat(TeeUtils.hasTeeTdxInTag(toByte32HexString(tag))).isFalse();
8997
}
9098

9199
// ensures some bits are present within TEE runtime framework mask
@@ -101,20 +109,17 @@ static Stream<Arguments> validData() {
101109

102110
@ParameterizedTest
103111
@MethodSource("validData")
104-
void hasTeeRuntimeFrameworkBitsInTag(int expectedBits, int tag) {
105-
Assertions.assertTrue(TeeUtils.hasTeeRuntimeFrameworkBitsInTag(expectedBits,
106-
toByte32HexString(tag)));
112+
void hasTeeRuntimeFrameworkBitsInTag(final int expectedBits, final int tag) {
113+
assertThat(TeeUtils.hasTeeRuntimeFrameworkBitsInTag(expectedBits, toByte32HexString(tag))).isTrue();
107114
}
108115

109116
@ParameterizedTest
110117
@NullSource
111118
@ValueSource(strings = {
112-
"abc", // missing prefix
119+
"abc", // after mask, 0xc -> 0b1100 does not match expected 0b1010
113120
"0x1", // no match
114121
})
115122
void hasNotTeeRuntimeFrameworkBitsInTag(String tag) {
116-
int anyBits = 0b1010;
117-
Assertions.assertFalse(TeeUtils.hasTeeRuntimeFrameworkBitsInTag(anyBits,
118-
tag));
123+
assertThat(TeeUtils.hasTeeRuntimeFrameworkBitsInTag(0b1010, tag)).isFalse();
119124
}
120-
}
125+
}

0 commit comments

Comments
 (0)