@inco/lightning 0.2.17 → 0.3.2-alpha.3
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.
- package/README.md +0 -8
- package/manifest.yaml +42 -0
- package/package.json +5 -1
- package/src/DeployTEE.sol +153 -0
- package/src/DeployUtils.sol +17 -9
- package/src/Errors.sol +4 -0
- package/src/IncoLightning.gen.sol +1 -1
- package/src/IncoLightning.sol +2 -1
- package/src/Lib.alphanet.sol +12 -0
- package/src/Lib.demonet.sol +12 -0
- package/src/Lib.devnet.sol +12 -0
- package/src/Lib.sol +12 -0
- package/src/Lib.template.sol +12 -0
- package/src/Lib.testnet.sol +12 -0
- package/src/Types.sol +45 -3
- package/src/libs/incoLightning_alphanet_v0_297966649.sol +12 -0
- package/src/libs/incoLightning_demonet_v0_863421733.sol +12 -0
- package/src/libs/incoLightning_devnet_v0_340846814.sol +12 -0
- package/src/libs/incoLightning_testnet_v0_183408998.sol +12 -0
- package/src/lightning-parts/AccessControl/BaseAccessControlList.gen.sol +5 -0
- package/src/lightning-parts/AccessControl/BaseAccessControlList.sol +20 -1
- package/src/lightning-parts/AccessControl/test/TestBaseAccessControl.t.sol +15 -2
- package/src/lightning-parts/EncryptedInput.gen.sol +2 -1
- package/src/lightning-parts/EncryptedInput.sol +5 -3
- package/src/lightning-parts/EncryptedOperations.gen.sol +1 -1
- package/src/lightning-parts/EncryptedOperations.sol +84 -32
- package/src/lightning-parts/TEELifecycle.gen.sol +58 -0
- package/src/lightning-parts/TEELifecycle.sol +255 -0
- package/src/lightning-parts/TEELifecycle.types.sol +21 -0
- package/src/lightning-parts/TrivialEncryption.gen.sol +1 -1
- package/src/lightning-parts/TrivialEncryption.sol +4 -2
- package/src/lightning-parts/primitives/EventCounter.gen.sol +2 -0
- package/src/lightning-parts/primitives/EventCounter.sol +13 -1
- package/src/lightning-parts/primitives/SignatureVerifier.gen.sol +1 -0
- package/src/lightning-parts/primitives/SignatureVerifier.sol +11 -0
- package/src/lightning-parts/test/HandleMetadata.t.sol +1 -1
- package/src/test/AddTwo.sol +13 -2
- package/src/test/FakeIncoInfra/FakeQuoteVerifier.sol +29 -0
- package/src/test/FakeIncoInfra/MockRemoteAttestation.sol +37 -0
- package/src/test/FibonacciDecrypt.sol +1 -0
- package/src/test/IncoTest.sol +5 -1
- package/src/test/TEELifecycle/README.md +53 -0
- package/src/test/TEELifecycle/TEELifecycleHWTest.t.sol +119 -0
- package/src/test/TEELifecycle/TEELifecycleMockTest.t.sol +145 -0
- package/src/test/TEELifecycle/addnode_data/eoa.txt +1 -0
- package/src/test/TEELifecycle/addnode_data/quote.bin +0 -0
- package/src/test/TEELifecycle/bootstrap_data/ecies_pubkey.bin +1 -0
- package/src/test/TEELifecycle/bootstrap_data/eip712_signature.bin +1 -0
- package/src/test/TEELifecycle/bootstrap_data/eoa.txt +1 -0
- package/src/test/TEELifecycle/bootstrap_data/qe_identity +1 -0
- package/src/test/TEELifecycle/bootstrap_data/qe_identity_signature.bin +1 -0
- package/src/test/TEELifecycle/bootstrap_data/quote.bin +0 -0
- package/src/test/TEELifecycle/bootstrap_data/tcb_info +1 -0
- package/src/test/TEELifecycle/bootstrap_data/tcb_info_signature.bin +1 -0
- package/src/test/TEELifecycle/test_cert/AttestationReportSigningCA.crl +0 -0
- package/src/test/TEELifecycle/test_cert/Intel_SGX_Attestation_RootCA.cer +0 -0
- package/src/test/TEELifecycle/test_cert/Intel_SGX_PCK_CRL.crl +0 -0
- package/src/test/TEELifecycle/test_cert/Intel_SGX_PCK_PlatformCA.cer +0 -0
- package/src/test/TEELifecycle/test_cert/Intel_SGX_TCB_Signing.cer +0 -0
- package/src/test/TestFakeInfra.t.sol +18 -1
- package/src/test/TestUpgrade.t.sol +314 -0
|
@@ -7,6 +7,7 @@ import {IBaseAccessControlListGen} from "./BaseAccessControlList.gen.sol";
|
|
|
7
7
|
contract AccessControlListStorage {
|
|
8
8
|
struct ACLStorage {
|
|
9
9
|
mapping(bytes32 handle => mapping(address account => bool isAllowed)) persistedAllowedPairs;
|
|
10
|
+
mapping(bytes32 handle => bool isAllowed) persistedAllowedForDecryption;
|
|
10
11
|
}
|
|
11
12
|
|
|
12
13
|
bytes32 private constant ACLStorageLocation = keccak256("inco.storage.ACL");
|
|
@@ -30,6 +31,16 @@ contract BaseAccessControlList is IBaseAccessControlListGen, AccessControlListSt
|
|
|
30
31
|
allowInternal(handle, account);
|
|
31
32
|
}
|
|
32
33
|
|
|
34
|
+
/// @dev Permanently allows public decryption/reencryption access to anyone for the given handle.
|
|
35
|
+
function reveal(bytes32 handle) public {
|
|
36
|
+
require(
|
|
37
|
+
isAllowed(handle, msg.sender),
|
|
38
|
+
SenderNotAllowedForHandle(handle, msg.sender)
|
|
39
|
+
);
|
|
40
|
+
ACLStorage storage $ = getACLStorage();
|
|
41
|
+
$.persistedAllowedForDecryption[handle] = true;
|
|
42
|
+
}
|
|
43
|
+
|
|
33
44
|
/// @dev persistent
|
|
34
45
|
function allowInternal(bytes32 handle, address account) internal {
|
|
35
46
|
ACLStorage storage $ = getACLStorage();
|
|
@@ -101,6 +112,14 @@ contract BaseAccessControlList is IBaseAccessControlListGen, AccessControlListSt
|
|
|
101
112
|
) public view returns (bool) {
|
|
102
113
|
return
|
|
103
114
|
allowedTransient(handle, account) ||
|
|
104
|
-
persistAllowed(handle, account)
|
|
115
|
+
persistAllowed(handle, account) ||
|
|
116
|
+
isRevealed(handle);
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
function isRevealed(
|
|
120
|
+
bytes32 handle
|
|
121
|
+
) public view returns (bool) {
|
|
122
|
+
ACLStorage storage $ = getACLStorage();
|
|
123
|
+
return $.persistedAllowedForDecryption[handle];
|
|
105
124
|
}
|
|
106
125
|
}
|
|
@@ -1,12 +1,25 @@
|
|
|
1
1
|
// SPDX-License-Identifier: No License
|
|
2
2
|
pragma solidity ^0.8;
|
|
3
3
|
|
|
4
|
-
import {TestUtils} from "@inco/shared/src/TestUtils.sol";
|
|
5
4
|
import {BaseAccessControlList} from "../BaseAccessControlList.sol";
|
|
5
|
+
import {inco, e, euint256} from "@inco/lightning/src/Lib.sol";
|
|
6
|
+
import {IncoTest} from "@inco/lightning/src/test/IncoTest.sol";
|
|
7
|
+
|
|
8
|
+
contract TestBaseAccessControl is BaseAccessControlList, IncoTest {
|
|
9
|
+
using e for euint256;
|
|
6
10
|
|
|
7
|
-
contract TestBaseAccessControl is BaseAccessControlList, TestUtils {
|
|
8
11
|
function testHandleZeroIsDisallowed() public view {
|
|
9
12
|
bytes32 handle = bytes32(0);
|
|
10
13
|
assert(!isAllowed(handle, alice));
|
|
11
14
|
}
|
|
15
|
+
|
|
16
|
+
function testReveal() public {
|
|
17
|
+
euint256 secret = inco.asEuint256(1337);
|
|
18
|
+
assert(inco.isAllowed(euint256.unwrap(secret), address(this)));
|
|
19
|
+
assert(!inco.isAllowed(euint256.unwrap(secret), alice));
|
|
20
|
+
|
|
21
|
+
inco.reveal(euint256.unwrap(secret));
|
|
22
|
+
assert(inco.isAllowed(euint256.unwrap(secret), address(this)));
|
|
23
|
+
assert(inco.isAllowed(euint256.unwrap(secret), alice));
|
|
24
|
+
}
|
|
12
25
|
}
|
|
@@ -4,7 +4,8 @@ pragma solidity ^0.8;
|
|
|
4
4
|
import { BaseAccessControlList } from "./AccessControl/BaseAccessControlList.sol";
|
|
5
5
|
import { EventCounter } from "./primitives/EventCounter.sol";
|
|
6
6
|
import { HandleGeneration } from "./primitives/HandleGeneration.sol";
|
|
7
|
-
import { euint256, ebool, eaddress, ETypes, EVM_HOST_CHAIN_PREFIX, HANDLE_VERSION, HANDLE_INDEX } from "../Types.sol";
|
|
7
|
+
import { euint256, ebool, eaddress, EOps, ETypes, EVM_HOST_CHAIN_PREFIX, HANDLE_VERSION, HANDLE_INDEX } from "../Types.sol";
|
|
8
|
+
import { HandleAlreadyExists } from "../Errors.sol";
|
|
8
9
|
|
|
9
10
|
interface IEncryptedInputGen {
|
|
10
11
|
function newEuint256(bytes memory ciphertext, address user) external returns (euint256 newValue);
|
|
@@ -4,8 +4,9 @@ pragma solidity ^0.8;
|
|
|
4
4
|
import {BaseAccessControlList} from "./AccessControl/BaseAccessControlList.sol";
|
|
5
5
|
import {EventCounter} from "./primitives/EventCounter.sol";
|
|
6
6
|
import {HandleGeneration} from "./primitives/HandleGeneration.sol";
|
|
7
|
-
import {euint256, ebool, eaddress, ETypes, EVM_HOST_CHAIN_PREFIX, HANDLE_VERSION, HANDLE_INDEX} from "../Types.sol";
|
|
7
|
+
import {euint256, ebool, eaddress, EOps, ETypes, EVM_HOST_CHAIN_PREFIX, HANDLE_VERSION, HANDLE_INDEX} from "../Types.sol";
|
|
8
8
|
import {IEncryptedInputGen} from "./EncryptedInput.gen.sol";
|
|
9
|
+
import {HandleAlreadyExists} from "../Errors.sol";
|
|
9
10
|
|
|
10
11
|
abstract contract EncryptedInput is
|
|
11
12
|
IEncryptedInputGen,
|
|
@@ -13,7 +14,6 @@ abstract contract EncryptedInput is
|
|
|
13
14
|
EventCounter,
|
|
14
15
|
HandleGeneration
|
|
15
16
|
{
|
|
16
|
-
error HandleAlreadyExists();
|
|
17
17
|
|
|
18
18
|
event NewInput(
|
|
19
19
|
bytes32 indexed result,
|
|
@@ -57,13 +57,15 @@ abstract contract EncryptedInput is
|
|
|
57
57
|
// We allow to user since this is harmless and it is convenient to use the allow mapping to track existing
|
|
58
58
|
allowInternal(newHandle, user);
|
|
59
59
|
allowTransientInternal(newHandle, msg.sender);
|
|
60
|
+
uint256 id = getNextEventId();
|
|
60
61
|
emit NewInput(
|
|
61
62
|
newHandle,
|
|
62
63
|
msg.sender,
|
|
63
64
|
user,
|
|
64
65
|
inputType,
|
|
65
66
|
ciphertext,
|
|
66
|
-
|
|
67
|
+
id
|
|
67
68
|
);
|
|
69
|
+
setDigest(abi.encodePacked(newHandle, id));
|
|
68
70
|
}
|
|
69
71
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/// SPDX-License-Identifier: No License
|
|
2
2
|
pragma solidity ^0.8;
|
|
3
3
|
|
|
4
|
-
import { euint256, ebool, EOps, SenderNotAllowedForHandle, ETypes, isTypeSupported } from "../Types.sol";
|
|
4
|
+
import { euint256, ebool, EOps, SenderNotAllowedForHandle, ETypes, isTypeSupported, typeToBitMask } from "../Types.sol";
|
|
5
5
|
import { BaseAccessControlList } from "./AccessControl/BaseAccessControlList.sol";
|
|
6
6
|
import { EventCounter } from "./primitives/EventCounter.sol";
|
|
7
7
|
import { HandleGeneration } from "./primitives/HandleGeneration.sol";
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
// SPDX-License-Identifier: No License
|
|
2
2
|
pragma solidity ^0.8;
|
|
3
3
|
|
|
4
|
-
import {euint256, ebool, EOps, SenderNotAllowedForHandle, ETypes, isTypeSupported} from "../Types.sol";
|
|
4
|
+
import {euint256, ebool, EOps, SenderNotAllowedForHandle, ETypes, isTypeSupported, typeToBitMask} from "../Types.sol";
|
|
5
5
|
import {BaseAccessControlList} from "./AccessControl/BaseAccessControlList.sol";
|
|
6
6
|
import {EventCounter} from "./primitives/EventCounter.sol";
|
|
7
7
|
import {HandleGeneration} from "./primitives/HandleGeneration.sol";
|
|
@@ -16,7 +16,7 @@ abstract contract EncryptedOperations is
|
|
|
16
16
|
error UnexpectedType(ETypes actual, bytes32 expectedTypes);
|
|
17
17
|
error UnsupportedType(ETypes actual);
|
|
18
18
|
|
|
19
|
-
uint256
|
|
19
|
+
uint256 internal randCounter;
|
|
20
20
|
|
|
21
21
|
bytes32 constant EBOOL = bytes32(1 << uint256(ETypes.Bool));
|
|
22
22
|
bytes32 constant EUINT160 = bytes32(1 << uint256(ETypes.AddressOrUint160OrBytes20));
|
|
@@ -175,10 +175,6 @@ abstract contract EncryptedOperations is
|
|
|
175
175
|
uint256 eventId
|
|
176
176
|
);
|
|
177
177
|
|
|
178
|
-
function typeToBitMask(ETypes t) internal pure returns (bytes32) {
|
|
179
|
-
return bytes32(1 << uint256(t));
|
|
180
|
-
}
|
|
181
|
-
|
|
182
178
|
modifier checked(euint256 lhs, euint256 rhs) {
|
|
183
179
|
checkInput(euint256.unwrap(lhs), typeToBitMask(ETypes.Uint256));
|
|
184
180
|
checkInput(euint256.unwrap(rhs), typeToBitMask(ETypes.Uint256));
|
|
@@ -252,7 +248,9 @@ abstract contract EncryptedOperations is
|
|
|
252
248
|
euint256.unwrap(rhs)
|
|
253
249
|
)
|
|
254
250
|
);
|
|
255
|
-
|
|
251
|
+
uint256 id = getNextEventId();
|
|
252
|
+
emit EAdd(lhs, rhs, result, id);
|
|
253
|
+
setDigest(abi.encodePacked(result, id));
|
|
256
254
|
}
|
|
257
255
|
|
|
258
256
|
function eSub(
|
|
@@ -267,7 +265,9 @@ abstract contract EncryptedOperations is
|
|
|
267
265
|
euint256.unwrap(rhs)
|
|
268
266
|
)
|
|
269
267
|
);
|
|
270
|
-
|
|
268
|
+
uint256 id = getNextEventId();
|
|
269
|
+
emit ESub(lhs, rhs, result, id);
|
|
270
|
+
setDigest(abi.encodePacked(result, id));
|
|
271
271
|
}
|
|
272
272
|
|
|
273
273
|
function eMul(
|
|
@@ -282,8 +282,10 @@ abstract contract EncryptedOperations is
|
|
|
282
282
|
euint256.unwrap(rhs)
|
|
283
283
|
)
|
|
284
284
|
);
|
|
285
|
-
|
|
286
|
-
|
|
285
|
+
uint256 id = getNextEventId();
|
|
286
|
+
emit EMul(lhs, rhs, result, id);
|
|
287
|
+
setDigest(abi.encodePacked(result, id));
|
|
288
|
+
}
|
|
287
289
|
|
|
288
290
|
function eDiv(
|
|
289
291
|
euint256 lhs,
|
|
@@ -297,7 +299,9 @@ abstract contract EncryptedOperations is
|
|
|
297
299
|
euint256.unwrap(rhs)
|
|
298
300
|
)
|
|
299
301
|
);
|
|
300
|
-
|
|
302
|
+
uint256 id = getNextEventId();
|
|
303
|
+
emit EDiv(lhs, rhs, result, id);
|
|
304
|
+
setDigest(abi.encodePacked(result, id));
|
|
301
305
|
}
|
|
302
306
|
|
|
303
307
|
function eRem(
|
|
@@ -312,7 +316,9 @@ abstract contract EncryptedOperations is
|
|
|
312
316
|
euint256.unwrap(rhs)
|
|
313
317
|
)
|
|
314
318
|
);
|
|
315
|
-
|
|
319
|
+
uint256 id = getNextEventId();
|
|
320
|
+
emit ERem(lhs, rhs, result, id);
|
|
321
|
+
setDigest(abi.encodePacked(result, id));
|
|
316
322
|
}
|
|
317
323
|
|
|
318
324
|
function eBitAnd(
|
|
@@ -325,7 +331,9 @@ abstract contract EncryptedOperations is
|
|
|
325
331
|
checkInput(rhs, typeToBitMask(rhsType));
|
|
326
332
|
require(lhsType == rhsType, UnexpectedType(lhsType, typeToBitMask(rhsType)));
|
|
327
333
|
result = createResultHandle(EOps.BitAnd, lhsType, lhs, rhs);
|
|
328
|
-
|
|
334
|
+
uint256 id = getNextEventId();
|
|
335
|
+
emit EBitAnd(lhs, rhs, result, id);
|
|
336
|
+
setDigest(abi.encodePacked(result, id));
|
|
329
337
|
}
|
|
330
338
|
|
|
331
339
|
function eBitOr(
|
|
@@ -338,7 +346,9 @@ abstract contract EncryptedOperations is
|
|
|
338
346
|
checkInput(rhs, typeToBitMask(rhsType));
|
|
339
347
|
require(lhsType == rhsType, UnexpectedType(lhsType, typeToBitMask(rhsType)));
|
|
340
348
|
result = createResultHandle(EOps.BitOr, lhsType, lhs, rhs);
|
|
341
|
-
|
|
349
|
+
uint256 id = getNextEventId();
|
|
350
|
+
emit EBitOr(lhs, rhs, result, id);
|
|
351
|
+
setDigest(abi.encodePacked(result, id));
|
|
342
352
|
}
|
|
343
353
|
|
|
344
354
|
function eBitXor(
|
|
@@ -351,7 +361,9 @@ abstract contract EncryptedOperations is
|
|
|
351
361
|
checkInput(rhs, typeToBitMask(rhsType));
|
|
352
362
|
require(lhsType == rhsType, UnexpectedType(lhsType, typeToBitMask(rhsType)));
|
|
353
363
|
result = createResultHandle(EOps.BitXor, lhsType, lhs, rhs);
|
|
354
|
-
|
|
364
|
+
uint256 id = getNextEventId();
|
|
365
|
+
emit EBitXor(lhs, rhs, result, id);
|
|
366
|
+
setDigest(abi.encodePacked(result, id));
|
|
355
367
|
}
|
|
356
368
|
|
|
357
369
|
function eShl(
|
|
@@ -366,7 +378,9 @@ abstract contract EncryptedOperations is
|
|
|
366
378
|
euint256.unwrap(rhs)
|
|
367
379
|
)
|
|
368
380
|
);
|
|
369
|
-
|
|
381
|
+
uint256 id = getNextEventId();
|
|
382
|
+
emit EShl(lhs, rhs, result, id);
|
|
383
|
+
setDigest(abi.encodePacked(result, id));
|
|
370
384
|
}
|
|
371
385
|
|
|
372
386
|
function eShr(
|
|
@@ -381,7 +395,9 @@ abstract contract EncryptedOperations is
|
|
|
381
395
|
euint256.unwrap(rhs)
|
|
382
396
|
)
|
|
383
397
|
);
|
|
384
|
-
|
|
398
|
+
uint256 id = getNextEventId();
|
|
399
|
+
emit EShr(lhs, rhs, result, id);
|
|
400
|
+
setDigest(abi.encodePacked(result, id));
|
|
385
401
|
}
|
|
386
402
|
|
|
387
403
|
function eRotl(
|
|
@@ -396,7 +412,9 @@ abstract contract EncryptedOperations is
|
|
|
396
412
|
euint256.unwrap(rhs)
|
|
397
413
|
)
|
|
398
414
|
);
|
|
399
|
-
|
|
415
|
+
uint256 id = getNextEventId();
|
|
416
|
+
emit ERotl(lhs, rhs, result, id);
|
|
417
|
+
setDigest(abi.encodePacked(result, id));
|
|
400
418
|
}
|
|
401
419
|
|
|
402
420
|
function eRotr(
|
|
@@ -411,7 +429,9 @@ abstract contract EncryptedOperations is
|
|
|
411
429
|
euint256.unwrap(rhs)
|
|
412
430
|
)
|
|
413
431
|
);
|
|
414
|
-
|
|
432
|
+
uint256 id = getNextEventId();
|
|
433
|
+
emit ERotr(lhs, rhs, result, id);
|
|
434
|
+
setDigest(abi.encodePacked(result, id));
|
|
415
435
|
}
|
|
416
436
|
|
|
417
437
|
function eEq(
|
|
@@ -429,7 +449,9 @@ abstract contract EncryptedOperations is
|
|
|
429
449
|
rhs
|
|
430
450
|
)
|
|
431
451
|
);
|
|
432
|
-
|
|
452
|
+
uint256 id = getNextEventId();
|
|
453
|
+
emit EEq(lhs, rhs, result, id);
|
|
454
|
+
setDigest(abi.encodePacked(result, id));
|
|
433
455
|
}
|
|
434
456
|
|
|
435
457
|
function eNe(
|
|
@@ -447,7 +469,9 @@ abstract contract EncryptedOperations is
|
|
|
447
469
|
rhs
|
|
448
470
|
)
|
|
449
471
|
);
|
|
450
|
-
|
|
472
|
+
uint256 id = getNextEventId();
|
|
473
|
+
emit ENe(lhs, rhs, result, id);
|
|
474
|
+
setDigest(abi.encodePacked(result, id));
|
|
451
475
|
}
|
|
452
476
|
|
|
453
477
|
function eGe(
|
|
@@ -462,7 +486,9 @@ abstract contract EncryptedOperations is
|
|
|
462
486
|
euint256.unwrap(rhs)
|
|
463
487
|
)
|
|
464
488
|
);
|
|
465
|
-
|
|
489
|
+
uint256 id = getNextEventId();
|
|
490
|
+
emit EGe(lhs, rhs, result, id);
|
|
491
|
+
setDigest(abi.encodePacked(result, id));
|
|
466
492
|
}
|
|
467
493
|
|
|
468
494
|
function eGt(
|
|
@@ -477,7 +503,9 @@ abstract contract EncryptedOperations is
|
|
|
477
503
|
euint256.unwrap(rhs)
|
|
478
504
|
)
|
|
479
505
|
);
|
|
480
|
-
|
|
506
|
+
uint256 id = getNextEventId();
|
|
507
|
+
emit EGt(lhs, rhs, result, id);
|
|
508
|
+
setDigest(abi.encodePacked(result, id));
|
|
481
509
|
}
|
|
482
510
|
|
|
483
511
|
function eLe(
|
|
@@ -492,7 +520,9 @@ abstract contract EncryptedOperations is
|
|
|
492
520
|
euint256.unwrap(rhs)
|
|
493
521
|
)
|
|
494
522
|
);
|
|
495
|
-
|
|
523
|
+
uint256 id = getNextEventId();
|
|
524
|
+
emit ELe(lhs, rhs, result, id);
|
|
525
|
+
setDigest(abi.encodePacked(result, id));
|
|
496
526
|
}
|
|
497
527
|
|
|
498
528
|
function eLt(
|
|
@@ -507,7 +537,9 @@ abstract contract EncryptedOperations is
|
|
|
507
537
|
euint256.unwrap(rhs)
|
|
508
538
|
)
|
|
509
539
|
);
|
|
510
|
-
|
|
540
|
+
uint256 id = getNextEventId();
|
|
541
|
+
emit ELt(lhs, rhs, result, id);
|
|
542
|
+
setDigest(abi.encodePacked(result, id));
|
|
511
543
|
}
|
|
512
544
|
|
|
513
545
|
function eMin(
|
|
@@ -522,7 +554,9 @@ abstract contract EncryptedOperations is
|
|
|
522
554
|
euint256.unwrap(rhs)
|
|
523
555
|
)
|
|
524
556
|
);
|
|
525
|
-
|
|
557
|
+
uint256 id = getNextEventId();
|
|
558
|
+
emit EMin(lhs, rhs, result, id);
|
|
559
|
+
setDigest(abi.encodePacked(result, id));
|
|
526
560
|
}
|
|
527
561
|
|
|
528
562
|
function eMax(
|
|
@@ -537,7 +571,9 @@ abstract contract EncryptedOperations is
|
|
|
537
571
|
euint256.unwrap(rhs)
|
|
538
572
|
)
|
|
539
573
|
);
|
|
540
|
-
|
|
574
|
+
uint256 id = getNextEventId();
|
|
575
|
+
emit EMax(lhs, rhs, result, id);
|
|
576
|
+
setDigest(abi.encodePacked(result, id));
|
|
541
577
|
}
|
|
542
578
|
|
|
543
579
|
function eNot(ebool operand) external returns (ebool result) {
|
|
@@ -545,7 +581,9 @@ abstract contract EncryptedOperations is
|
|
|
545
581
|
result = ebool.wrap(
|
|
546
582
|
createResultHandle(EOps.Not, ETypes.Bool, ebool.unwrap(operand))
|
|
547
583
|
);
|
|
548
|
-
|
|
584
|
+
uint256 id = getNextEventId();
|
|
585
|
+
emit ENot(operand, result, id);
|
|
586
|
+
setDigest(abi.encodePacked(result, id));
|
|
549
587
|
}
|
|
550
588
|
|
|
551
589
|
function eCast(
|
|
@@ -555,7 +593,9 @@ abstract contract EncryptedOperations is
|
|
|
555
593
|
bytes32 baseHandle = keccak256(abi.encodePacked(EOps.Cast, ct, toType));
|
|
556
594
|
result = embedTypeVersion(baseHandle, toType);
|
|
557
595
|
allowTransientInternal(result, msg.sender);
|
|
558
|
-
|
|
596
|
+
uint256 id = getNextEventId();
|
|
597
|
+
emit ECast(ct, uint8(toType), result, id);
|
|
598
|
+
setDigest(abi.encodePacked(result, id));
|
|
559
599
|
}
|
|
560
600
|
|
|
561
601
|
function eRand(
|
|
@@ -569,7 +609,12 @@ abstract contract EncryptedOperations is
|
|
|
569
609
|
bytes32(randCounter++),
|
|
570
610
|
bytes32(uint256(randType))
|
|
571
611
|
);
|
|
572
|
-
|
|
612
|
+
//NOTE: We pass the incremented randCounter which is incremented using postfix increment above.
|
|
613
|
+
// Due to postfix returning the value before incrementing, the emitted randCounter will be larger by one than the number used to build the handle.
|
|
614
|
+
// So for security and replayability reasons, we always use the incremented randCounter when seeding on the covalidator side, which is fine for as long as we're consistent.
|
|
615
|
+
uint256 id = getNextEventId();
|
|
616
|
+
emit ERand(randCounter, randType, result, id);
|
|
617
|
+
setDigest(abi.encodePacked(result, id));
|
|
573
618
|
}
|
|
574
619
|
|
|
575
620
|
function eRandBounded(
|
|
@@ -586,7 +631,12 @@ abstract contract EncryptedOperations is
|
|
|
586
631
|
upperBound,
|
|
587
632
|
bytes32(uint256(randType))
|
|
588
633
|
);
|
|
589
|
-
|
|
634
|
+
//NOTE: We pass the incremented randCounter which is incremented using postfix increment above.
|
|
635
|
+
// Due to postfix returning the value before incrementing, the emitted randCounter will be larger by one than the number used to build the handle.
|
|
636
|
+
// So for security and replayability reasons, we always use the incremented randCounter when seeding on the covalidator side, which is fine for as long as we're consistent.
|
|
637
|
+
uint256 id = getNextEventId();
|
|
638
|
+
emit ERandBounded(randCounter, randType, upperBound, result, id);
|
|
639
|
+
setDigest(abi.encodePacked(result, id));
|
|
590
640
|
}
|
|
591
641
|
|
|
592
642
|
// todo add support in testing framework
|
|
@@ -606,7 +656,9 @@ abstract contract EncryptedOperations is
|
|
|
606
656
|
);
|
|
607
657
|
result = embedTypeVersion(baseHandle, returnType);
|
|
608
658
|
allowTransientInternal(result, msg.sender);
|
|
609
|
-
|
|
659
|
+
uint256 id = getNextEventId();
|
|
660
|
+
emit EIfThenElse(control, ifTrue, ifFalse, result, id);
|
|
661
|
+
setDigest(abi.encodePacked(result, id));
|
|
610
662
|
}
|
|
611
663
|
|
|
612
664
|
function checkEIfThenElseInputs(
|
|
@@ -0,0 +1,58 @@
|
|
|
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
|
+
}
|