@inco/lightning 0.3.2 → 0.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (108) hide show
  1. package/README.md +2 -8
  2. package/manifest.yaml +24 -11
  3. package/package.json +2 -5
  4. package/src/DeployUtils.sol +113 -77
  5. package/src/IIncoLightning.sol +16 -9
  6. package/src/IncoLightning.sol +18 -9
  7. package/src/IncoVerifier.sol +47 -0
  8. package/src/Lib.alphanet.sol +14 -15
  9. package/src/Lib.demonet.sol +14 -15
  10. package/src/Lib.devnet.sol +14 -15
  11. package/src/Lib.sol +14 -15
  12. package/src/Lib.template.sol +15 -44
  13. package/src/Lib.testnet.sol +14 -15
  14. package/src/Types.sol +7 -0
  15. package/src/interfaces/IIncoLightning.sol +20 -0
  16. package/src/interfaces/IIncoVerifier.sol +24 -0
  17. package/src/interfaces/automata-interfaces/BELE.sol +20 -0
  18. package/src/interfaces/automata-interfaces/IAutomataEnclaveIdentityDao.sol +28 -0
  19. package/src/interfaces/automata-interfaces/IFmspcTcbDao.sol +10 -0
  20. package/src/interfaces/automata-interfaces/IPCCSRouter.sol +94 -0
  21. package/src/interfaces/automata-interfaces/IPCCSRouterExtended.sol +10 -0
  22. package/src/interfaces/automata-interfaces/IPcsDao.sol +18 -0
  23. package/src/interfaces/automata-interfaces/IQuoteVerifier.sol +34 -0
  24. package/src/interfaces/automata-interfaces/Types.sol +193 -0
  25. package/src/libs/incoLightning_alphanet_v0_297966649.sol +14 -15
  26. package/src/libs/incoLightning_demonet_v0_863421733.sol +14 -15
  27. package/src/libs/incoLightning_devnet_v0_340846814.sol +14 -15
  28. package/src/libs/incoLightning_testnet_v0_183408998.sol +14 -15
  29. package/src/libs/incoLightning_testnet_v1_938327937.sol +451 -0
  30. package/src/lightning-parts/AccessControl/AdvancedAccessControl.sol +133 -0
  31. package/src/lightning-parts/AccessControl/AdvancedAccessControl.types.sol +18 -0
  32. package/src/lightning-parts/AccessControl/BaseAccessControlList.sol +42 -3
  33. package/src/lightning-parts/AccessControl/interfaces/IAdvancedAccessControl.sol +25 -0
  34. package/src/lightning-parts/AccessControl/interfaces/IBaseAccessControlList.sol +24 -0
  35. package/src/lightning-parts/AccessControl/test/TestAdvancedAccessControl.t.sol +234 -0
  36. package/src/lightning-parts/AccessControl/test/TestBaseAccessControl.t.sol +16 -2
  37. package/src/lightning-parts/DecryptionAttester.sol +45 -0
  38. package/src/lightning-parts/DecryptionAttester.types.sol +7 -0
  39. package/src/lightning-parts/EncryptedInput.sol +10 -13
  40. package/src/lightning-parts/EncryptedOperations.sol +78 -28
  41. package/src/lightning-parts/TEELifecycle.sol +180 -88
  42. package/src/lightning-parts/TrivialEncryption.sol +9 -9
  43. package/src/lightning-parts/interfaces/IDecryptionAttester.sol +9 -0
  44. package/src/lightning-parts/interfaces/IEncryptedInput.sol +19 -0
  45. package/src/lightning-parts/interfaces/IEncryptedOperations.sol +31 -0
  46. package/src/lightning-parts/interfaces/ITEELifecycle.sol +26 -0
  47. package/src/lightning-parts/interfaces/ITrivialEncryption.sol +10 -0
  48. package/src/lightning-parts/primitives/EventCounter.sol +15 -3
  49. package/src/lightning-parts/primitives/HandleGeneration.sol +8 -3
  50. package/src/lightning-parts/primitives/HandleMetadata.sol +1 -1
  51. package/src/lightning-parts/primitives/LightningAddressGetter.sol +10 -0
  52. package/src/lightning-parts/primitives/SignatureVerifier.sol +2 -9
  53. package/src/lightning-parts/primitives/VerifierAddressGetter.sol +13 -0
  54. package/src/lightning-parts/primitives/{EventCounter.gen.sol → interfaces/IEventCounter.sol} +4 -2
  55. package/src/lightning-parts/primitives/interfaces/IHandleGeneration.sol +41 -0
  56. package/src/lightning-parts/primitives/interfaces/ISignatureVerifier.sol +9 -0
  57. package/src/lightning-parts/primitives/interfaces/IVerifierAddressGetter.sol +8 -0
  58. package/src/lightning-parts/test/HandleMetadata.t.sol +25 -6
  59. package/src/lightning-parts/test/TestDecryptionAttestationInSynchronousFlow.t.sol +78 -0
  60. package/src/periphery/SessionVerifier.sol +63 -0
  61. package/src/test/AddTwo.sol +20 -24
  62. package/src/test/FakeIncoInfra/FakeDecryptionAttester.sol +198 -0
  63. package/src/test/FakeIncoInfra/FakeIncoInfraBase.sol +0 -15
  64. package/src/test/FakeIncoInfra/FakeQuoteVerifier.sol +10 -6
  65. package/src/test/FakeIncoInfra/MockOpHandler.sol +0 -7
  66. package/src/test/FakeIncoInfra/MockRemoteAttestation.sol +19 -7
  67. package/src/test/FakeIncoInfra/getOpForSelector.sol +0 -3
  68. package/src/test/IncoTest.sol +12 -11
  69. package/src/test/TEELifecycle/TEELifecycleMockTest.t.sol +98 -77
  70. package/src/test/TestAddTwo.t.sol +16 -9
  71. package/src/test/TestFakeInfra.t.sol +10 -27
  72. package/src/test/TestUpgrade.t.sol +11 -4
  73. package/src/test/TestVersion.t.sol +0 -7
  74. package/src/version/IncoLightningConfig.sol +4 -3
  75. package/src/version/SessionVerifierConfig.sol +8 -0
  76. package/src/version/Version.sol +7 -9
  77. package/src/version/interfaces/IVersion.sol +8 -0
  78. package/src/DeployTEE.sol +0 -153
  79. package/src/IncoLightning.gen.sol +0 -15
  80. package/src/lightning-parts/AccessControl/BaseAccessControlList.gen.sol +0 -19
  81. package/src/lightning-parts/DecryptionHandler.gen.sol +0 -54
  82. package/src/lightning-parts/DecryptionHandler.sol +0 -307
  83. package/src/lightning-parts/DecryptionHandler.types.sol +0 -34
  84. package/src/lightning-parts/EncryptedInput.gen.sol +0 -16
  85. package/src/lightning-parts/EncryptedOperations.gen.sol +0 -59
  86. package/src/lightning-parts/TEELifecycle.gen.sol +0 -58
  87. package/src/lightning-parts/TrivialEncryption.gen.sol +0 -15
  88. package/src/lightning-parts/primitives/HandleGeneration.gen.sol +0 -19
  89. package/src/lightning-parts/primitives/HandleMetadata.gen.sol +0 -4
  90. package/src/lightning-parts/primitives/SignatureVerifier.gen.sol +0 -16
  91. package/src/test/FibonacciDecrypt.sol +0 -49
  92. package/src/test/TEELifecycle/TEELifecycleHWTest.t.sol +0 -119
  93. package/src/test/TEELifecycle/addnode_data/eoa.txt +0 -1
  94. package/src/test/TEELifecycle/addnode_data/quote.bin +0 -0
  95. package/src/test/TEELifecycle/bootstrap_data/ecies_pubkey.bin +0 -1
  96. package/src/test/TEELifecycle/bootstrap_data/eip712_signature.bin +0 -1
  97. package/src/test/TEELifecycle/bootstrap_data/eoa.txt +0 -1
  98. package/src/test/TEELifecycle/bootstrap_data/qe_identity +0 -1
  99. package/src/test/TEELifecycle/bootstrap_data/qe_identity_signature.bin +0 -1
  100. package/src/test/TEELifecycle/bootstrap_data/quote.bin +0 -0
  101. package/src/test/TEELifecycle/bootstrap_data/tcb_info +0 -1
  102. package/src/test/TEELifecycle/bootstrap_data/tcb_info_signature.bin +0 -1
  103. package/src/test/TEELifecycle/test_cert/AttestationReportSigningCA.crl +0 -0
  104. package/src/test/TEELifecycle/test_cert/Intel_SGX_Attestation_RootCA.cer +0 -0
  105. package/src/test/TEELifecycle/test_cert/Intel_SGX_PCK_CRL.crl +0 -0
  106. package/src/test/TEELifecycle/test_cert/Intel_SGX_PCK_PlatformCA.cer +0 -0
  107. package/src/test/TEELifecycle/test_cert/Intel_SGX_TCB_Signing.cer +0 -0
  108. package/src/version/Version.gen.sol +0 -14
@@ -1,307 +0,0 @@
1
- // SPDX-License-Identifier: No License
2
- pragma solidity ^0.8;
3
-
4
- import "./DecryptionHandler.gen.sol";
5
- import "./DecryptionHandler.types.sol";
6
- import {BaseAccessControlList} from "./AccessControl/BaseAccessControlList.sol";
7
- import {EIP712} from "@openzeppelin/contracts/utils/cryptography/EIP712.sol";
8
- import {EventCounter} from "./primitives/EventCounter.sol";
9
- import {IDecryptionHandlerEip712CheckerGen} from "./DecryptionHandler.gen.sol";
10
- import {SenderNotAllowedForHandle} from "../Types.sol";
11
- import {SignatureVerifier} from "./primitives/SignatureVerifier.sol";
12
-
13
- contract DecryptionHandlerStorage {
14
- struct DecryptionStorage {
15
- // The next request ID to assign. This and higher numbers have never been used,
16
- // hence there are no pending requests in that range.
17
- uint256 nextRequestId;
18
- mapping(uint256 => Request) requests;
19
- // A requestId for which all previous requests have been fulfilled or are expired.
20
- // Must be less than or equal to nextRequestId. Only increases.
21
- uint256 lowWatermark;
22
- }
23
-
24
- bytes32 private constant DecryptionStorageLocation =
25
- keccak256("inco.storage.DecryptionHandler");
26
-
27
- function getDecryptionStorage()
28
- internal
29
- pure
30
- returns (DecryptionStorage storage $)
31
- {
32
- bytes32 loc = DecryptionStorageLocation;
33
- assembly {
34
- $.slot := loc
35
- }
36
- }
37
- }
38
-
39
- abstract contract DecryptionHandlerEip712Checker is IDecryptionHandlerEip712CheckerGen, EIP712, SignatureVerifier {
40
- bytes32 constant DecryptionResultStructHash =
41
- keccak256(
42
- "DecryptionResult(bytes32 abiEncodedResult,uint256 requestId)"
43
- );
44
-
45
- function decryptionResultDigest(
46
- DecryptionResult memory result
47
- ) public view returns (bytes32) {
48
- return
49
- _hashTypedDataV4(
50
- keccak256(
51
- abi.encode(
52
- DecryptionResultStructHash,
53
- result.abiEncodedResult,
54
- result.requestId
55
- )
56
- )
57
- );
58
- }
59
-
60
- function isValidResult(
61
- DecryptionResult memory result,
62
- bytes memory signature
63
- ) internal view returns (bool) {
64
- return isValidSignature(decryptionResultDigest(result), signature);
65
- }
66
- }
67
-
68
- abstract contract DecryptionHandler is
69
- IDecryptionHandlerGen,
70
- BaseAccessControlList,
71
- EventCounter,
72
- DecryptionHandlerStorage,
73
- DecryptionHandlerEip712Checker
74
- {
75
- // The Covalidator callback machinery relies on these exact error signatures which are hardcoded in eth_callback.go
76
- error AllRequestsAlreadyFulfilledOrExpired();
77
- // Thrown when either msg.sender is not a valid signer or the signature is not from a valid signer
78
- error InvalidResultSignature(address msgSender, bytes signature);
79
-
80
- event RequestFulfilled(
81
- uint256 indexed requestId,
82
- bool success,
83
- uint256 eventId,
84
- bytes32 handle
85
- );
86
-
87
- // Maximum number of request mappings to access on any operation.
88
- uint256 constant ITERATION_BOUND = 100;
89
-
90
- function pending(Request memory r) internal view returns (bool) {
91
- return !r.fulfilled && r.maxTimestamp >= block.timestamp;
92
- }
93
-
94
- /// @dev callback function MUST be of form `function name(bytes32 requestId, bytes32 result, bytes memory data)`
95
- function requestDecryption(
96
- // todo support multiple handles per request
97
- bytes4 callbackSelector,
98
- uint256 maxTimestamp,
99
- bytes32 handle,
100
- bytes memory data
101
- ) external returns (uint256 requestId) {
102
- require(
103
- isAllowed(handle, msg.sender),
104
- SenderNotAllowedForHandle(handle, msg.sender)
105
- );
106
-
107
- DecryptionStorage storage $ = getDecryptionStorage();
108
- requestId = $.nextRequestId;
109
- $.nextRequestId++;
110
- $.requests[requestId] = Request({
111
- maxTimestamp: maxTimestamp,
112
- callbackContract: msg.sender,
113
- callbackSelector: callbackSelector,
114
- fulfilled: false,
115
- data: data,
116
- handle: handle,
117
- requestId: requestId
118
- });
119
-
120
- advanceLowWatermark(ITERATION_BOUND);
121
-
122
- emit DecryptionRequested(
123
- requestId,
124
- handle,
125
- maxTimestamp,
126
- getNewEventId()
127
- );
128
- }
129
-
130
- function fulfillRequest(
131
- DecryptionResult memory result,
132
- bytes memory signature
133
- ) external {
134
- SignedDecryptionResult[]
135
- memory signedResults = new SignedDecryptionResult[](1);
136
- signedResults[0] = SignedDecryptionResult({
137
- result: result,
138
- signature: signature
139
- });
140
- fulfillRequestsBatch(signedResults);
141
- }
142
-
143
- function fulfillRequestsBatch(
144
- SignedDecryptionResult[] memory results
145
- ) public {
146
- DecryptionStorage storage $ = getDecryptionStorage();
147
-
148
- bool fulfilledSome = false;
149
-
150
- for (uint i = 0; i < results.length; i++) {
151
- Request storage request = $.requests[results[i].result.requestId];
152
-
153
- if (!pending(request)) {
154
- // The request was already fulfilled, or has expired. Neither is an error.
155
- continue;
156
- }
157
- // Support either an EIP712 signature or a direct call from the signer
158
- require(
159
- isSigner(msg.sender) ||
160
- isValidResult(results[i].result, results[i].signature),
161
- InvalidResultSignature(msg.sender, results[i].signature)
162
- );
163
-
164
- bytes memory callbackCalldata = abi.encodeWithSelector(
165
- request.callbackSelector,
166
- results[i].result.requestId,
167
- results[i].result.abiEncodedResult,
168
- request.data
169
- // TODO: add handle as an integrity check - already added to DecryptionResult but adding here would mean
170
- // dapp callback function signatures would need to change - which would be a breaking change
171
- // request.handle
172
- );
173
-
174
- (bool success, ) = request.callbackContract.call(callbackCalldata);
175
-
176
- request.fulfilled = true;
177
- fulfilledSome = true;
178
-
179
- emit RequestFulfilled(
180
- results[i].result.requestId,
181
- success,
182
- getNewEventId(),
183
- results[i].result.handle
184
- );
185
- }
186
- // If we did not advance we revert, so that we can detect if everything is fulfilled during gas estimation
187
- require(fulfilledSome, AllRequestsAlreadyFulfilledOrExpired());
188
-
189
- // Otherwise, do some work to advance the low water mark.
190
- advanceLowWatermark(ITERATION_BOUND);
191
- }
192
-
193
- /**
194
- * @dev Get some pending requests.
195
- * @param offset A parameter for paginating through the whole set of pending requests.
196
- * Use zero for an initial query, then use the previous query's nextOffset to continue traversal.
197
- * @param maxRequests The maximum number of pending to return.
198
- * @param iterationBound The maximum number of non-pending requests to iterate over before returning.
199
- * @return nextOffset The next offset to use to continue to scan through the pending request set.
200
- * Returns the input offset if the whole set has been scanned. Can re-query with this offset
201
- * to see any new pending requests, or re-query with a zero offset to return the whole set again.
202
-
203
- * @return requests Some pending requests. May be fewer than requested, possibly zero. There may be
204
- * more requests available if the returned nextOffset is greater than the input offset.
205
- */
206
- function getPendingRequests(
207
- uint256 offset,
208
- uint256 maxRequests,
209
- uint256 iterationBound
210
- ) external view returns (uint256 nextOffset, Request[] memory requests) {
211
- DecryptionStorage storage $ = getDecryptionStorage();
212
-
213
- uint256 lwm = $.lowWatermark;
214
- uint256 nextRequestId = $.nextRequestId;
215
-
216
- // Start at the higher of offset and lwm, possibly skipping many completed requests.
217
- uint256 id = offset;
218
- if (id < lwm) {
219
- id = lwm;
220
- }
221
-
222
- // Don't scan more than iterationBound extra entries or pass the nextRequestId.
223
- uint256 limit = id + maxRequests + iterationBound;
224
- if (limit > nextRequestId) {
225
- limit = nextRequestId;
226
- }
227
-
228
- // Now id >= lmw and limit <= nextRequestId.
229
- // It's possible that id >= limit, which is fine,
230
- // and the next two loops will exit immediately.
231
-
232
- // First calculate the size of array we need to allocate.
233
- // (It's cheaper to scan the requests twice instead of allocating too much.)
234
- uint256 numRequests = 0;
235
- for (uint256 i = id; i < limit && numRequests < maxRequests; i++) {
236
- Request memory request = $.requests[i];
237
- if (pending(request)) {
238
- numRequests++;
239
- }
240
- }
241
-
242
- // Now populate the array
243
- requests = new Request[](numRequests);
244
- for (uint256 n = 0; id < limit && n < numRequests; id++) {
245
- Request memory request = $.requests[id];
246
- if (pending(request)) {
247
- requests[n] = request;
248
- n++;
249
- }
250
- }
251
- nextOffset = id;
252
- }
253
-
254
- /**
255
-
256
- * @param offset A parameter for paginating through the whole set of pending requests.
257
- * Use zero for an initial query, then use the previous query's nextOffset to continue traversal.
258
- * @param maxRequests The maximum number of pending to return.
259
- * @return nextOffset The next offset to use to continue to scan through the pending request set.
260
- * Returns the input offset if the whole set has been scanned. Can re-query with this offset
261
- * to see any new pending requests, or re-query with a zero offset to return the whole set again.
262
- * @return requests Some pending requests. May be fewer than requested, possibly zero. There may be
263
- * more requests available if the returned nextOffset is greater than the input offset.
264
- */
265
- function getPendingRequests(
266
- uint256 offset,
267
- uint256 maxRequests
268
- ) external view returns (uint256 nextOffset, Request[] memory requests) {
269
- return this.getPendingRequests(offset, maxRequests, ITERATION_BOUND);
270
- }
271
-
272
- function getNextRequestId() external view returns (uint256) {
273
- return getDecryptionStorage().nextRequestId;
274
- }
275
-
276
- function getLowWatermarkRequestId() external view returns (uint256) {
277
- return getDecryptionStorage().lowWatermark;
278
- }
279
-
280
- /**
281
- * @dev Advance the low watermark until we hit a pending request, the requestId counter, or iterationBound steps.
282
- * @param iterationBound The maximum number of requests to iterate over.
283
- * @notice This function is public so that we can externally drive the low watermark in extreme cases.
284
- */
285
- function advanceLowWatermark(uint256 iterationBound) public {
286
- DecryptionStorage storage $ = getDecryptionStorage();
287
- uint256 lwm = $.lowWatermark;
288
- uint256 nextRequestId = $.nextRequestId;
289
- // Calling advanceLowWatermark with a 0 iterationBound will have no effect, but it will waste gas, and previously
290
- // has been indicative of a bug, so leaving this revert as a affordance to callers.
291
- require(iterationBound > 0, "iterateBound is zero!");
292
- uint256 limit = lwm + iterationBound;
293
- if (limit > nextRequestId) {
294
- limit = nextRequestId;
295
- }
296
-
297
- while (lwm < limit) {
298
- Request storage request = $.requests[lwm];
299
- // Stop advancing when we hit the first still pending request
300
- if (pending(request)) {
301
- break;
302
- }
303
- lwm++;
304
- }
305
- $.lowWatermark = lwm;
306
- }
307
- }
@@ -1,34 +0,0 @@
1
- // SPDX-License-Identifier: No License
2
- pragma solidity ^0.8;
3
-
4
- struct Request {
5
- uint256 maxTimestamp;
6
- address callbackContract;
7
- bytes4 callbackSelector;
8
- bool fulfilled;
9
- bytes data;
10
- // Adding at end of struct which should be unused state slot for version 0.2.0
11
- bytes32 handle;
12
- // This value is redundant for the contract but required for getPendingRequests, rather than duplicate this struct
13
- // adding it here redundantly for now
14
- uint256 requestId;
15
- }
16
-
17
- struct DecryptionResult {
18
- bytes32 abiEncodedResult;
19
- uint256 requestId;
20
- // Added in 0.2.0 to offer an integrity check
21
- bytes32 handle;
22
- }
23
-
24
- struct SignedDecryptionResult {
25
- DecryptionResult result;
26
- bytes signature;
27
- }
28
-
29
- event DecryptionRequested(
30
- uint256 indexed requestId,
31
- bytes32 indexed handle,
32
- uint256 maxTimestamp,
33
- uint256 eventId
34
- );
@@ -1,16 +0,0 @@
1
- /// SPDX-License-Identifier: No License
2
- pragma solidity ^0.8;
3
-
4
- import { BaseAccessControlList } from "./AccessControl/BaseAccessControlList.sol";
5
- import { EventCounter } from "./primitives/EventCounter.sol";
6
- import { HandleGeneration } from "./primitives/HandleGeneration.sol";
7
- import { euint256, ebool, eaddress, ETypes, EVM_HOST_CHAIN_PREFIX, HANDLE_VERSION, HANDLE_INDEX } from "../Types.sol";
8
- import { HandleAlreadyExists } from "../Errors.sol";
9
-
10
- interface IEncryptedInputGen {
11
- function newEuint256(bytes memory ciphertext, address user) external returns (euint256 newValue);
12
-
13
- function newEbool(bytes memory ciphertext, address user) external returns (ebool newValue);
14
-
15
- function newEaddress(bytes memory ciphertext, address user) external returns (eaddress newValue);
16
- }
@@ -1,59 +0,0 @@
1
- /// SPDX-License-Identifier: No License
2
- pragma solidity ^0.8;
3
-
4
- import { euint256, ebool, EOps, SenderNotAllowedForHandle, ETypes, isTypeSupported, typeToBitMask } from "../Types.sol";
5
- import { BaseAccessControlList } from "./AccessControl/BaseAccessControlList.sol";
6
- import { EventCounter } from "./primitives/EventCounter.sol";
7
- import { HandleGeneration } from "./primitives/HandleGeneration.sol";
8
-
9
- interface IEncryptedOperationsGen {
10
- function eAdd(euint256 lhs, euint256 rhs) external returns (euint256 result);
11
-
12
- function eSub(euint256 lhs, euint256 rhs) external returns (euint256 result);
13
-
14
- function eMul(euint256 lhs, euint256 rhs) external returns (euint256 result);
15
-
16
- function eDiv(euint256 lhs, euint256 rhs) external returns (euint256 result);
17
-
18
- function eRem(euint256 lhs, euint256 rhs) external returns (euint256 result);
19
-
20
- function eBitAnd(bytes32 lhs, bytes32 rhs) external returns (bytes32 result);
21
-
22
- function eBitOr(bytes32 lhs, bytes32 rhs) external returns (bytes32 result);
23
-
24
- function eBitXor(bytes32 lhs, bytes32 rhs) external returns (bytes32 result);
25
-
26
- function eShl(euint256 lhs, euint256 rhs) external returns (euint256 result);
27
-
28
- function eShr(euint256 lhs, euint256 rhs) external returns (euint256 result);
29
-
30
- function eRotl(euint256 lhs, euint256 rhs) external returns (euint256 result);
31
-
32
- function eRotr(euint256 lhs, euint256 rhs) external returns (euint256 result);
33
-
34
- function eEq(bytes32 lhs, bytes32 rhs) external returns (ebool result);
35
-
36
- function eNe(bytes32 lhs, bytes32 rhs) external returns (ebool result);
37
-
38
- function eGe(euint256 lhs, euint256 rhs) external returns (ebool result);
39
-
40
- function eGt(euint256 lhs, euint256 rhs) external returns (ebool result);
41
-
42
- function eLe(euint256 lhs, euint256 rhs) external returns (ebool result);
43
-
44
- function eLt(euint256 lhs, euint256 rhs) external returns (ebool result);
45
-
46
- function eMin(euint256 lhs, euint256 rhs) external returns (euint256 result);
47
-
48
- function eMax(euint256 lhs, euint256 rhs) external returns (euint256 result);
49
-
50
- function eNot(ebool operand) external returns (ebool result);
51
-
52
- function eCast(bytes32 ct, ETypes toType) external returns (bytes32 result);
53
-
54
- function eRand(ETypes randType) external returns (bytes32 result);
55
-
56
- function eRandBounded(bytes32 upperBound, ETypes randType) external returns (bytes32 result);
57
-
58
- function eIfThenElse(ebool control, bytes32 ifTrue, bytes32 ifFalse) external returns (bytes32 result);
59
- }
@@ -1,58 +0,0 @@
1
- /// SPDX-License-Identifier: No License
2
- pragma solidity ^0.8.19;
3
-
4
- import "./TEELifecycle.types.sol";
5
- import { ECDSA } from "@openzeppelin/contracts/utils/cryptography/ECDSA.sol";
6
- import { EIP712 } from "@openzeppelin/contracts/utils/cryptography/EIP712.sol";
7
- import { OwnableUpgradeable } from "@openzeppelin/contracts-upgradeable/access/OwnableUpgradeable.sol";
8
- import { IQuoteVerifier } from "automata-dcap-attestation/interfaces/IQuoteVerifier.sol";
9
- import { BELE } from "automata-dcap-attestation/utils/BELE.sol";
10
- import { HEADER_LENGTH } from "automata-dcap-attestation/types/Constants.sol";
11
- import { TD10ReportBody, Header } from "automata-dcap-attestation/types/V4Structs.sol";
12
- import { EIP712Upgradeable } from "@openzeppelin/contracts-upgradeable/utils/cryptography/EIP712Upgradeable.sol";
13
- import { EnclaveIdentityJsonObj, IdentityObj } from "@automata-network/on-chain-pccs/helpers/EnclaveIdentityHelper.sol";
14
- import { TcbInfoJsonObj } from "@automata-network/on-chain-pccs/helpers/FmspcTcbHelper.sol";
15
- import { AutomataFmspcTcbDao } from "@automata-network/on-chain-pccs/automata_pccs/AutomataFmspcTcbDao.sol";
16
- import { AutomataEnclaveIdentityDao } from "@automata-network/on-chain-pccs/automata_pccs/AutomataEnclaveIdentityDao.sol";
17
-
18
- interface ITEELifecycleGen {
19
- function initialize(address owner, string memory eip712Name, string memory eip712Version, address quoteVerifierAddress) external;
20
-
21
- /// @notice Uploads the collateral to the contract
22
- /// @param tcbInfo - The TCB info to upload
23
- /// @param identity - The identity to upload
24
- function uploadCollateral(TcbInfoJsonObj memory tcbInfo, EnclaveIdentityJsonObj memory identity) external;
25
-
26
- /// @notice Verifies the bootstrap data against the provided quote and signature
27
- /// @param bootstrapResult - The bootstrap data to verify
28
- /// @param quote - The quote to verify against
29
- /// @param signature - The signature to verify against
30
- function verifyBootstrapResult(BootstrapResult calldata bootstrapResult, bytes calldata quote, bytes calldata signature) external;
31
-
32
- /// @notice Approves a new TEE version and updates the TEEVersionHistory
33
- /// @param newMRTD - The MRTD bytes of the new TEE version
34
- /// @dev This function increments the version number automatically based on the current history
35
- function approveNewTEEVersion(bytes calldata newMRTD) external;
36
-
37
- /// @notice Adds a new covalidator to the contract state
38
- /// @param quote - The quote from the new covalidator that contains the current MRTD and the eoa address of the new party in the report data
39
- function addNewCovalidator(bytes calldata quote) external;
40
-
41
- /// @notice Checks if the bootstrap is complete, meaning that there is an active TEE version.
42
- /// @return true if the bootstrap is complete, false otherwise
43
- function isBootstrapComplete() external view returns (bool);
44
-
45
- /// @notice From https://github.com/automata-network/automata-dcap-attestation/blob/evm-v1.0.0/evm/contracts/verifiers/V4QuoteVerifier.sol#L309
46
- /// @notice Parses the TD10 report body from the raw quote
47
- /// @param rawQuote - The raw quote bytes
48
- /// @return report - The parsed TD10 report body
49
- function parseTD10ReportBody(bytes calldata rawQuote) external pure returns (TD10ReportBody memory report);
50
-
51
- /// @notice Parses the TD10 report to extract the report data and MRTD
52
- /// @param tdReport - The TD10 report body
53
- /// @return reportDataSigner - The signing address of the report data signer
54
- /// @return reportMRTD - The MRTD bytes from the report
55
- function parseReport(TD10ReportBody memory tdReport) external pure returns (address, bytes memory);
56
-
57
- function bootstrapResultDigest(BootstrapResult memory bootstrapResult) external view returns (bytes32);
58
- }
@@ -1,15 +0,0 @@
1
- /// SPDX-License-Identifier: No License
2
- pragma solidity ^0.8;
3
-
4
- import { EventCounter } from "./primitives/EventCounter.sol";
5
- import { euint256, ebool, eaddress, ETypes } from "../Types.sol";
6
- import { BaseAccessControlList } from "./AccessControl/BaseAccessControlList.sol";
7
- import { HandleGeneration } from "./primitives/HandleGeneration.sol";
8
-
9
- interface ITrivialEncryptionGen {
10
- function asEuint256(uint256 value) external returns (euint256 newEuint256);
11
-
12
- function asEbool(bool value) external returns (ebool newEbool);
13
-
14
- function asEaddress(address value) external returns (eaddress newEaddress);
15
- }
@@ -1,19 +0,0 @@
1
- /// SPDX-License-Identifier: No License
2
- pragma solidity ^0.8;
3
-
4
- import { ETypes, EOps, EVM_HOST_CHAIN_PREFIX, HANDLE_INDEX } from "../../Types.sol";
5
- import { HandleMetadata } from "./HandleMetadata.sol";
6
-
7
- interface IHandleGenerationGen {
8
- function getTrivialEncryptHandle(bytes32 plaintextBytes, ETypes handleType) external view returns (bytes32 generatedHandle);
9
-
10
- function getInputHandle(bytes memory ciphertext, address user, address contractAddress, ETypes inputType) external view returns (bytes32 generatedHandle);
11
-
12
- function getOpResultHandle(EOps op, ETypes returnType, bytes32 lhs, bytes32 rhs) external pure returns (bytes32 generatedHandle);
13
-
14
- function getOpResultHandle(EOps op, ETypes returnType, uint256 counter, bytes32 upperBound) external pure returns (bytes32 generatedHandle);
15
-
16
- function getOpResultHandle(EOps op, ETypes returnType, bytes32 value) external pure returns (bytes32 generatedHandle);
17
-
18
- function getOpResultHandle(EOps op, ETypes returnType, bytes32 inputA, bytes32 inputB, bytes32 inputC) external pure returns (bytes32 generatedHandle);
19
- }
@@ -1,4 +0,0 @@
1
- /// SPDX-License-Identifier: No License
2
- pragma solidity ^0.8;
3
-
4
- import { HANDLE_VERSION, HANDLE_INDEX, ETypes } from "../../Types.sol";
@@ -1,16 +0,0 @@
1
- /// SPDX-License-Identifier: No License
2
- pragma solidity ^0.8;
3
-
4
- import { OwnableUpgradeable } from "@openzeppelin/contracts-upgradeable/access/OwnableUpgradeable.sol";
5
- import { ECDSA } from "@openzeppelin/contracts/utils/cryptography/ECDSA.sol";
6
- import { TEELifecycle } from "../TEELifecycle.sol";
7
-
8
- interface ISignatureVerifierGen {
9
- function addSigner(address signerAddress) external;
10
-
11
- function removeSigner(address signerAddress) external;
12
-
13
- function isSigner(address signerAddress) external view returns (bool);
14
-
15
- function isValidSignature(bytes32 hash, bytes memory signature) external view returns (bool);
16
- }
@@ -1,49 +0,0 @@
1
- // SPDX-License-Identifier: No License
2
- pragma solidity ^0.8;
3
-
4
- import {IncoLightning} from "../IncoLightning.sol";
5
- import {euint256} from "../Types.sol";
6
-
7
- contract FibonacciDecrypt {
8
- IncoLightning immutable inco;
9
-
10
- constructor(IncoLightning _inco) {
11
- inco = _inco;
12
- }
13
-
14
- // Stores the result of the last callback.
15
- uint256 public lastResult;
16
-
17
- function fib(
18
- uint256 n
19
- ) external returns (uint256 lastRequestId, euint256 nthTerm) {
20
- require(address(inco) != address(0), "IncoLightning not set");
21
- euint256 prev = inco.asEuint256(0);
22
- lastRequestId = emitTerm(prev);
23
- nthTerm = inco.asEuint256(1);
24
- lastRequestId = emitTerm(nthTerm);
25
- for (uint256 i = 0; i < n-2; i++) {
26
- euint256 temp = nthTerm;
27
- nthTerm = inco.eAdd(prev, nthTerm);
28
- prev = temp;
29
- lastRequestId = emitTerm(nthTerm);
30
- }
31
- }
32
-
33
- function emitTerm(euint256 term) internal returns (uint256 requestId) {
34
- requestId = inco.requestDecryption(
35
- this.callback.selector,
36
- block.timestamp + 2 hours,
37
- euint256.unwrap(term),
38
- ""
39
- );
40
- }
41
-
42
- function callback(
43
- uint256 /* requestId */,
44
- uint256 result,
45
- bytes memory /* data */
46
- ) external {
47
- lastResult = result;
48
- }
49
- }