@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.
- package/README.md +2 -8
- package/manifest.yaml +24 -11
- package/package.json +2 -5
- package/src/DeployUtils.sol +113 -77
- package/src/IIncoLightning.sol +16 -9
- package/src/IncoLightning.sol +18 -9
- package/src/IncoVerifier.sol +47 -0
- package/src/Lib.alphanet.sol +14 -15
- package/src/Lib.demonet.sol +14 -15
- package/src/Lib.devnet.sol +14 -15
- package/src/Lib.sol +14 -15
- package/src/Lib.template.sol +15 -44
- package/src/Lib.testnet.sol +14 -15
- package/src/Types.sol +7 -0
- package/src/interfaces/IIncoLightning.sol +20 -0
- package/src/interfaces/IIncoVerifier.sol +24 -0
- package/src/interfaces/automata-interfaces/BELE.sol +20 -0
- package/src/interfaces/automata-interfaces/IAutomataEnclaveIdentityDao.sol +28 -0
- package/src/interfaces/automata-interfaces/IFmspcTcbDao.sol +10 -0
- package/src/interfaces/automata-interfaces/IPCCSRouter.sol +94 -0
- package/src/interfaces/automata-interfaces/IPCCSRouterExtended.sol +10 -0
- package/src/interfaces/automata-interfaces/IPcsDao.sol +18 -0
- package/src/interfaces/automata-interfaces/IQuoteVerifier.sol +34 -0
- package/src/interfaces/automata-interfaces/Types.sol +193 -0
- package/src/libs/incoLightning_alphanet_v0_297966649.sol +14 -15
- package/src/libs/incoLightning_demonet_v0_863421733.sol +14 -15
- package/src/libs/incoLightning_devnet_v0_340846814.sol +14 -15
- package/src/libs/incoLightning_testnet_v0_183408998.sol +14 -15
- package/src/libs/incoLightning_testnet_v1_938327937.sol +451 -0
- package/src/lightning-parts/AccessControl/AdvancedAccessControl.sol +133 -0
- package/src/lightning-parts/AccessControl/AdvancedAccessControl.types.sol +18 -0
- package/src/lightning-parts/AccessControl/BaseAccessControlList.sol +42 -3
- package/src/lightning-parts/AccessControl/interfaces/IAdvancedAccessControl.sol +25 -0
- package/src/lightning-parts/AccessControl/interfaces/IBaseAccessControlList.sol +24 -0
- package/src/lightning-parts/AccessControl/test/TestAdvancedAccessControl.t.sol +234 -0
- package/src/lightning-parts/AccessControl/test/TestBaseAccessControl.t.sol +16 -2
- package/src/lightning-parts/DecryptionAttester.sol +45 -0
- package/src/lightning-parts/DecryptionAttester.types.sol +7 -0
- package/src/lightning-parts/EncryptedInput.sol +10 -13
- package/src/lightning-parts/EncryptedOperations.sol +78 -28
- package/src/lightning-parts/TEELifecycle.sol +180 -88
- package/src/lightning-parts/TrivialEncryption.sol +9 -9
- package/src/lightning-parts/interfaces/IDecryptionAttester.sol +9 -0
- package/src/lightning-parts/interfaces/IEncryptedInput.sol +19 -0
- package/src/lightning-parts/interfaces/IEncryptedOperations.sol +31 -0
- package/src/lightning-parts/interfaces/ITEELifecycle.sol +26 -0
- package/src/lightning-parts/interfaces/ITrivialEncryption.sol +10 -0
- package/src/lightning-parts/primitives/EventCounter.sol +15 -3
- package/src/lightning-parts/primitives/HandleGeneration.sol +8 -3
- package/src/lightning-parts/primitives/HandleMetadata.sol +1 -1
- package/src/lightning-parts/primitives/LightningAddressGetter.sol +10 -0
- package/src/lightning-parts/primitives/SignatureVerifier.sol +2 -9
- package/src/lightning-parts/primitives/VerifierAddressGetter.sol +13 -0
- package/src/lightning-parts/primitives/{EventCounter.gen.sol → interfaces/IEventCounter.sol} +4 -2
- package/src/lightning-parts/primitives/interfaces/IHandleGeneration.sol +41 -0
- package/src/lightning-parts/primitives/interfaces/ISignatureVerifier.sol +9 -0
- package/src/lightning-parts/primitives/interfaces/IVerifierAddressGetter.sol +8 -0
- package/src/lightning-parts/test/HandleMetadata.t.sol +25 -6
- package/src/lightning-parts/test/TestDecryptionAttestationInSynchronousFlow.t.sol +78 -0
- package/src/periphery/SessionVerifier.sol +63 -0
- package/src/test/AddTwo.sol +20 -24
- package/src/test/FakeIncoInfra/FakeDecryptionAttester.sol +198 -0
- package/src/test/FakeIncoInfra/FakeIncoInfraBase.sol +0 -15
- package/src/test/FakeIncoInfra/FakeQuoteVerifier.sol +10 -6
- package/src/test/FakeIncoInfra/MockOpHandler.sol +0 -7
- package/src/test/FakeIncoInfra/MockRemoteAttestation.sol +19 -7
- package/src/test/FakeIncoInfra/getOpForSelector.sol +0 -3
- package/src/test/IncoTest.sol +12 -11
- package/src/test/TEELifecycle/TEELifecycleMockTest.t.sol +98 -77
- package/src/test/TestAddTwo.t.sol +16 -9
- package/src/test/TestFakeInfra.t.sol +10 -27
- package/src/test/TestUpgrade.t.sol +11 -4
- package/src/test/TestVersion.t.sol +0 -7
- package/src/version/IncoLightningConfig.sol +4 -3
- package/src/version/SessionVerifierConfig.sol +8 -0
- package/src/version/Version.sol +7 -9
- package/src/version/interfaces/IVersion.sol +8 -0
- package/src/DeployTEE.sol +0 -153
- package/src/IncoLightning.gen.sol +0 -15
- package/src/lightning-parts/AccessControl/BaseAccessControlList.gen.sol +0 -19
- package/src/lightning-parts/DecryptionHandler.gen.sol +0 -54
- package/src/lightning-parts/DecryptionHandler.sol +0 -307
- package/src/lightning-parts/DecryptionHandler.types.sol +0 -34
- package/src/lightning-parts/EncryptedInput.gen.sol +0 -16
- package/src/lightning-parts/EncryptedOperations.gen.sol +0 -59
- package/src/lightning-parts/TEELifecycle.gen.sol +0 -58
- package/src/lightning-parts/TrivialEncryption.gen.sol +0 -15
- package/src/lightning-parts/primitives/HandleGeneration.gen.sol +0 -19
- package/src/lightning-parts/primitives/HandleMetadata.gen.sol +0 -4
- package/src/lightning-parts/primitives/SignatureVerifier.gen.sol +0 -16
- package/src/test/FibonacciDecrypt.sol +0 -49
- package/src/test/TEELifecycle/TEELifecycleHWTest.t.sol +0 -119
- package/src/test/TEELifecycle/addnode_data/eoa.txt +0 -1
- package/src/test/TEELifecycle/addnode_data/quote.bin +0 -0
- package/src/test/TEELifecycle/bootstrap_data/ecies_pubkey.bin +0 -1
- package/src/test/TEELifecycle/bootstrap_data/eip712_signature.bin +0 -1
- package/src/test/TEELifecycle/bootstrap_data/eoa.txt +0 -1
- package/src/test/TEELifecycle/bootstrap_data/qe_identity +0 -1
- package/src/test/TEELifecycle/bootstrap_data/qe_identity_signature.bin +0 -1
- package/src/test/TEELifecycle/bootstrap_data/quote.bin +0 -0
- package/src/test/TEELifecycle/bootstrap_data/tcb_info +0 -1
- package/src/test/TEELifecycle/bootstrap_data/tcb_info_signature.bin +0 -1
- 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/version/Version.gen.sol +0 -14
|
@@ -0,0 +1,198 @@
|
|
|
1
|
+
// SPDX-License-Identifier: No License
|
|
2
|
+
pragma solidity ^0.8;
|
|
3
|
+
|
|
4
|
+
import {FakeIncoInfraBase} from "./FakeIncoInfraBase.sol";
|
|
5
|
+
import {inco} from "../../Lib.sol";
|
|
6
|
+
import {DecryptionAttestation} from "../../lightning-parts/DecryptionAttester.types.sol";
|
|
7
|
+
import {AllowanceProof} from "../../lightning-parts/AccessControl/AdvancedAccessControl.sol";
|
|
8
|
+
import {SenderNotAllowedForHandle, EOps, ETypes} from "../../Types.sol";
|
|
9
|
+
import {FakeComputeServer} from "./FakeComputeServer.sol";
|
|
10
|
+
|
|
11
|
+
/// @notice simulates the TEE / covalidator offchain API for decryption attestations requests
|
|
12
|
+
/// The signing and checking of the decryption request is out of scope of this simulation, it is assumed that when
|
|
13
|
+
/// called in tests, it emulates the act of a requester emitting a decryption request
|
|
14
|
+
/// One can request decryption attestations on one handle, or on a handle not existing onchain resulting from an
|
|
15
|
+
/// operation on existing handles, or on a mix of existing handles and plaintexts values (which get trivial encrypted)
|
|
16
|
+
/// as long as the handles are allowed for the requester
|
|
17
|
+
contract FakeDecryptionAttester is FakeIncoInfraBase, FakeComputeServer {
|
|
18
|
+
struct HandleWithProof {
|
|
19
|
+
bytes32 handle;
|
|
20
|
+
AllowanceProof proof; // sharer == address(0) means no proof
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
// The following 4 functions mimic expected behavior of the TEE / covalidator over offchain API
|
|
24
|
+
|
|
25
|
+
/// @notice request decryption attestation for an existing handle
|
|
26
|
+
function getDecryptionAttestation(
|
|
27
|
+
address requester,
|
|
28
|
+
HandleWithProof memory handle
|
|
29
|
+
)
|
|
30
|
+
internal
|
|
31
|
+
returns (
|
|
32
|
+
DecryptionAttestation memory decryption,
|
|
33
|
+
bytes memory signature
|
|
34
|
+
)
|
|
35
|
+
{
|
|
36
|
+
checkAccessControl(requester, handle);
|
|
37
|
+
(decryption, signature) = _getDecryptionAttestation(
|
|
38
|
+
handle.handle,
|
|
39
|
+
get(handle.handle)
|
|
40
|
+
);
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
// The following 3 functions are for requesting decryption over a handle resulting of an operation
|
|
44
|
+
// only binary ops are supported for now (2 params)
|
|
45
|
+
|
|
46
|
+
/// @notice request decryption attestation for a binary operation on 2 existing handles
|
|
47
|
+
function getDecryptionAttestation(
|
|
48
|
+
address requester,
|
|
49
|
+
HandleWithProof memory lhs,
|
|
50
|
+
HandleWithProof memory rhs,
|
|
51
|
+
EOps op
|
|
52
|
+
)
|
|
53
|
+
internal
|
|
54
|
+
returns (
|
|
55
|
+
DecryptionAttestation memory decryption,
|
|
56
|
+
bytes memory signature
|
|
57
|
+
)
|
|
58
|
+
{
|
|
59
|
+
checkAccessControl(requester, lhs);
|
|
60
|
+
checkAccessControl(requester, rhs);
|
|
61
|
+
bytes32 result = computeBinaryOp(get(lhs.handle), get(rhs.handle), op);
|
|
62
|
+
(decryption, signature) = _getDecryptionAttestation(
|
|
63
|
+
lhs.handle,
|
|
64
|
+
rhs.handle,
|
|
65
|
+
result,
|
|
66
|
+
op
|
|
67
|
+
);
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/// @notice request decryption attestation for a binary operation on a handle and a plaintext value (lhs)
|
|
71
|
+
function getDecryptionAttestation(
|
|
72
|
+
address requester,
|
|
73
|
+
uint256 lhs,
|
|
74
|
+
HandleWithProof memory rhs,
|
|
75
|
+
EOps op
|
|
76
|
+
)
|
|
77
|
+
internal
|
|
78
|
+
returns (
|
|
79
|
+
DecryptionAttestation memory decryption,
|
|
80
|
+
bytes memory signature
|
|
81
|
+
)
|
|
82
|
+
{
|
|
83
|
+
checkAccessControl(requester, rhs);
|
|
84
|
+
bytes32 lhsHandle = inco.getTrivialEncryptHandle(
|
|
85
|
+
bytes32(lhs),
|
|
86
|
+
ETypes.Uint256
|
|
87
|
+
);
|
|
88
|
+
bytes32 result = computeBinaryOp(bytes32(lhs), get(rhs.handle), op);
|
|
89
|
+
(decryption, signature) = _getDecryptionAttestation(
|
|
90
|
+
lhsHandle,
|
|
91
|
+
rhs.handle,
|
|
92
|
+
result,
|
|
93
|
+
op
|
|
94
|
+
);
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
/// @notice request decryption attestation for a binary operation on a handle and a plaintext value (rhs)
|
|
98
|
+
function getDecryptionAttestation(
|
|
99
|
+
address requester,
|
|
100
|
+
HandleWithProof memory lhs,
|
|
101
|
+
uint256 rhs,
|
|
102
|
+
EOps op
|
|
103
|
+
)
|
|
104
|
+
internal
|
|
105
|
+
returns (
|
|
106
|
+
DecryptionAttestation memory decryption,
|
|
107
|
+
bytes memory signature
|
|
108
|
+
)
|
|
109
|
+
{
|
|
110
|
+
checkAccessControl(requester, lhs);
|
|
111
|
+
bytes32 rhsHandle = inco.getTrivialEncryptHandle(
|
|
112
|
+
bytes32(rhs),
|
|
113
|
+
ETypes.Uint256
|
|
114
|
+
);
|
|
115
|
+
|
|
116
|
+
bytes32 result = computeBinaryOp(get(lhs.handle), bytes32(rhs), op);
|
|
117
|
+
(decryption, signature) = _getDecryptionAttestation(
|
|
118
|
+
lhs.handle,
|
|
119
|
+
rhsHandle,
|
|
120
|
+
result,
|
|
121
|
+
op
|
|
122
|
+
);
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
/// Private methods ///
|
|
126
|
+
|
|
127
|
+
function checkAccessControl(
|
|
128
|
+
address requester,
|
|
129
|
+
HandleWithProof memory handle
|
|
130
|
+
) private {
|
|
131
|
+
if (handle.proof.sharer == address(0)) {
|
|
132
|
+
require(
|
|
133
|
+
inco.isAllowed(handle.handle, requester),
|
|
134
|
+
SenderNotAllowedForHandle(handle.handle, requester)
|
|
135
|
+
);
|
|
136
|
+
} else {
|
|
137
|
+
require(
|
|
138
|
+
inco.incoVerifier().isAllowedWithProof(
|
|
139
|
+
handle.handle,
|
|
140
|
+
requester,
|
|
141
|
+
handle.proof
|
|
142
|
+
),
|
|
143
|
+
SenderNotAllowedForHandle(handle.handle, requester)
|
|
144
|
+
);
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
function _getDecryptionAttestation(
|
|
149
|
+
bytes32 handle,
|
|
150
|
+
bytes32 value
|
|
151
|
+
)
|
|
152
|
+
private
|
|
153
|
+
view
|
|
154
|
+
returns (
|
|
155
|
+
DecryptionAttestation memory decryption,
|
|
156
|
+
bytes memory signature
|
|
157
|
+
)
|
|
158
|
+
{
|
|
159
|
+
decryption = DecryptionAttestation({handle: handle, value: value});
|
|
160
|
+
signature = signDecryption(decryption);
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
function signDecryption(
|
|
164
|
+
DecryptionAttestation memory decryption
|
|
165
|
+
) private view returns (bytes memory signature) {
|
|
166
|
+
// todo change this to don't call inco and call verifier directly
|
|
167
|
+
bytes32 digest = inco.incoVerifier().decryptionAttestationDigest(
|
|
168
|
+
decryption
|
|
169
|
+
);
|
|
170
|
+
signature = getSignatureForDigest(digest, teePrivKey);
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
function _getDecryptionAttestation(
|
|
174
|
+
bytes32 lhsHandle,
|
|
175
|
+
bytes32 rhsHandle,
|
|
176
|
+
bytes32 encodedResult,
|
|
177
|
+
EOps op
|
|
178
|
+
)
|
|
179
|
+
private
|
|
180
|
+
view
|
|
181
|
+
returns (
|
|
182
|
+
DecryptionAttestation memory decryption,
|
|
183
|
+
bytes memory signature
|
|
184
|
+
)
|
|
185
|
+
{
|
|
186
|
+
ETypes resultType = opToResultType(op);
|
|
187
|
+
decryption = DecryptionAttestation({
|
|
188
|
+
handle: inco.getOpResultHandle(
|
|
189
|
+
op,
|
|
190
|
+
resultType,
|
|
191
|
+
lhsHandle,
|
|
192
|
+
rhsHandle
|
|
193
|
+
),
|
|
194
|
+
value: encodedResult
|
|
195
|
+
});
|
|
196
|
+
signature = signDecryption(decryption);
|
|
197
|
+
}
|
|
198
|
+
}
|
|
@@ -3,9 +3,7 @@ pragma solidity ^0.8;
|
|
|
3
3
|
|
|
4
4
|
import {ebool, euint256, ETypes} from "../../Types.sol";
|
|
5
5
|
import {inco} from "../../Lib.sol";
|
|
6
|
-
import {Vm} from "forge-std/Test.sol";
|
|
7
6
|
import {TestUtils} from "@inco/shared/src/TestUtils.sol";
|
|
8
|
-
import {DecryptionResult} from "../../lightning-parts/DecryptionHandler.sol";
|
|
9
7
|
import {KVStore} from "./KVStore.sol";
|
|
10
8
|
|
|
11
9
|
/// @notice simulates what inco does offchain but over plaintexts
|
|
@@ -19,19 +17,6 @@ contract FakeIncoInfraBase is TestUtils, KVStore {
|
|
|
19
17
|
(teePrivKey, teePubkeyAddress) = getLabeledKeyPair("tee");
|
|
20
18
|
}
|
|
21
19
|
|
|
22
|
-
function handleDecryptionRequest(
|
|
23
|
-
uint256 requestId,
|
|
24
|
-
bytes32 handle
|
|
25
|
-
) internal {
|
|
26
|
-
DecryptionResult memory result = DecryptionResult({
|
|
27
|
-
abiEncodedResult: get(handle),
|
|
28
|
-
requestId: requestId,
|
|
29
|
-
handle: handle
|
|
30
|
-
});
|
|
31
|
-
vm.prank(teePubkeyAddress);
|
|
32
|
-
inco.fulfillRequest(result, "");
|
|
33
|
-
}
|
|
34
|
-
|
|
35
20
|
function fakePrepareEuint256Ciphertext(
|
|
36
21
|
uint256 value
|
|
37
22
|
) internal pure returns (bytes memory ciphertext) {
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
// SPDX-License-Identifier: No License
|
|
2
2
|
pragma solidity ^0.8;
|
|
3
3
|
|
|
4
|
-
import {IPCCSRouter} from "
|
|
5
|
-
import {Header} from "
|
|
6
|
-
import {IQuoteVerifier} from "automata-
|
|
4
|
+
import {IPCCSRouter} from "../../interfaces/automata-interfaces/IPCCSRouter.sol";
|
|
5
|
+
import {Header} from "../../interfaces/automata-interfaces/Types.sol";
|
|
6
|
+
import {IQuoteVerifier} from "../../interfaces/automata-interfaces/IQuoteVerifier.sol";
|
|
7
7
|
|
|
8
8
|
// This contract is used to test the IncoLightning contract. It is a simple implementation of the QuoteVerifier interface.
|
|
9
9
|
// It is used to test the IncoLightning contract without relying on the real QuoteVerifier contract.
|
|
@@ -18,12 +18,16 @@ contract FakeQuoteVerifier is IQuoteVerifier {
|
|
|
18
18
|
return 4;
|
|
19
19
|
}
|
|
20
20
|
|
|
21
|
-
function verifyQuote(
|
|
21
|
+
function verifyQuote(
|
|
22
|
+
Header calldata,
|
|
23
|
+
bytes calldata quote
|
|
24
|
+
) external pure returns (bool, bytes memory) {
|
|
22
25
|
return (true, quote);
|
|
23
26
|
}
|
|
24
27
|
|
|
25
|
-
function verifyZkOutput(
|
|
28
|
+
function verifyZkOutput(
|
|
29
|
+
bytes calldata quote
|
|
30
|
+
) external pure returns (bool, bytes memory) {
|
|
26
31
|
return (true, quote);
|
|
27
32
|
}
|
|
28
|
-
|
|
29
33
|
}
|
|
@@ -4,7 +4,6 @@ pragma solidity ^0.8;
|
|
|
4
4
|
import {Vm} from "forge-std/Test.sol";
|
|
5
5
|
import {inco} from "../../Lib.sol";
|
|
6
6
|
import {ebool, euint256, ETypes, EOps} from "../../Types.sol";
|
|
7
|
-
import {DecryptionRequested} from "../../lightning-parts/DecryptionHandler.sol";
|
|
8
7
|
import {FakeComputeServer} from "./FakeComputeServer.sol";
|
|
9
8
|
import {FakeIncoInfraBase} from "./FakeIncoInfraBase.sol";
|
|
10
9
|
import {asBytes32} from "@inco/shared/src/TypeUtils.sol";
|
|
@@ -71,12 +70,6 @@ contract MockOpHandler is FakeIncoInfraBase, FakeComputeServer {
|
|
|
71
70
|
(ETypes, bytes, uint256)
|
|
72
71
|
);
|
|
73
72
|
handleEInput(result, inputType, ciphertext);
|
|
74
|
-
} else if (op == EOps.DecryptionRequested) {
|
|
75
|
-
uint256 requestId = uint256(log.topics[1]);
|
|
76
|
-
bytes32 handle = log.topics[2];
|
|
77
|
-
// other fields ignored for now
|
|
78
|
-
// todo cheats to trigger decryption later
|
|
79
|
-
handleDecryptionRequest(requestId, handle);
|
|
80
73
|
}
|
|
81
74
|
}
|
|
82
75
|
|
|
@@ -2,10 +2,11 @@
|
|
|
2
2
|
pragma solidity ^0.8;
|
|
3
3
|
|
|
4
4
|
import {TestUtils} from "@inco/shared/src/TestUtils.sol";
|
|
5
|
-
import {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
5
|
+
import {
|
|
6
|
+
HEADER_LENGTH,
|
|
7
|
+
MINIMUM_QUOTE_LENGTH,
|
|
8
|
+
TDX_TEE
|
|
9
|
+
} from "../../interfaces/automata-interfaces/Types.sol";
|
|
9
10
|
|
|
10
11
|
contract MockRemoteAttestation is TestUtils {
|
|
11
12
|
function createQuote(
|
|
@@ -31,7 +32,18 @@ contract MockRemoteAttestation is TestUtils {
|
|
|
31
32
|
bytes memory prefix = new bytes(HEADER_LENGTH + 136 - 8);
|
|
32
33
|
bytes memory middle = new bytes(520 - 184);
|
|
33
34
|
bytes memory reportDataSuffix = new bytes(44);
|
|
34
|
-
bytes memory suffix = new bytes(
|
|
35
|
-
|
|
35
|
+
bytes memory suffix = new bytes(
|
|
36
|
+
MINIMUM_QUOTE_LENGTH - HEADER_LENGTH - 584
|
|
37
|
+
);
|
|
38
|
+
quote = abi.encodePacked(
|
|
39
|
+
version,
|
|
40
|
+
tdxTEEType,
|
|
41
|
+
prefix,
|
|
42
|
+
mrtd,
|
|
43
|
+
middle,
|
|
44
|
+
abi.encodePacked(signer),
|
|
45
|
+
reportDataSuffix,
|
|
46
|
+
suffix
|
|
47
|
+
);
|
|
36
48
|
}
|
|
37
|
-
}
|
|
49
|
+
}
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
// SPDX-License-Identifier: No License
|
|
2
2
|
pragma solidity ^0.8;
|
|
3
3
|
|
|
4
|
-
import {DecryptionRequested} from "../../lightning-parts/DecryptionHandler.sol";
|
|
5
4
|
import {EncryptedOperations} from "../../lightning-parts/EncryptedOperations.sol";
|
|
6
5
|
import {TrivialEncryption} from "../../lightning-parts/TrivialEncryption.sol";
|
|
7
6
|
import {EncryptedInput} from "../../lightning-parts/EncryptedInput.sol";
|
|
@@ -63,8 +62,6 @@ function getOpForSelector(bytes32 opEventSelector) pure returns (EOps) {
|
|
|
63
62
|
return EOps.Rand;
|
|
64
63
|
} else if (opEventSelector == EncryptedOperations.ERandBounded.selector) {
|
|
65
64
|
return EOps.RandBounded;
|
|
66
|
-
} else if (opEventSelector == DecryptionRequested.selector) {
|
|
67
|
-
return EOps.DecryptionRequested;
|
|
68
65
|
} else {
|
|
69
66
|
revert("getOpForSelector: Unsupported selector");
|
|
70
67
|
}
|
package/src/test/IncoTest.sol
CHANGED
|
@@ -2,14 +2,16 @@
|
|
|
2
2
|
pragma solidity ^0.8;
|
|
3
3
|
|
|
4
4
|
import {MockOpHandler} from "./FakeIncoInfra/MockOpHandler.sol";
|
|
5
|
-
import {
|
|
5
|
+
import {IIncoLightning} from "../interfaces/IIncoLightning.sol";
|
|
6
6
|
import {inco} from "../Lib.sol";
|
|
7
7
|
import {DeployUtils} from "../DeployUtils.sol";
|
|
8
8
|
import {deployedBy} from "../Lib.sol";
|
|
9
|
+
import {FakeDecryptionAttester} from "./FakeIncoInfra/FakeDecryptionAttester.sol";
|
|
9
10
|
import {console} from "forge-std/console.sol";
|
|
10
11
|
import {FakeQuoteVerifier} from "./FakeIncoInfra/FakeQuoteVerifier.sol";
|
|
12
|
+
import {IOwnable} from "@inco/shared/src/IOwnable.sol";
|
|
11
13
|
|
|
12
|
-
contract IncoTest is MockOpHandler, DeployUtils {
|
|
14
|
+
contract IncoTest is MockOpHandler, DeployUtils, FakeDecryptionAttester {
|
|
13
15
|
address immutable owner;
|
|
14
16
|
address immutable testDeployer;
|
|
15
17
|
|
|
@@ -27,16 +29,14 @@ contract IncoTest is MockOpHandler, DeployUtils {
|
|
|
27
29
|
deployCreateX();
|
|
28
30
|
vm.startPrank(testDeployer);
|
|
29
31
|
vm.setEnv("USE_TDX_HW", "false"); // results in the test deployment using the FakeQuoteVerifier
|
|
30
|
-
|
|
32
|
+
(IIncoLightning proxy, ) = deployIncoLightningUsingConfig({
|
|
31
33
|
deployer: testDeployer,
|
|
32
|
-
|
|
34
|
+
// The highest precedent deployment
|
|
33
35
|
pepper: "testnet",
|
|
34
|
-
|
|
35
|
-
patchVersionForSalt: 29,
|
|
36
|
-
includePreviewFeatures: false,
|
|
37
|
-
teeLifecycleAddress: address(0)
|
|
36
|
+
quoteVerifier: new FakeQuoteVerifier()
|
|
38
37
|
});
|
|
39
|
-
proxy.transferOwnership(owner);
|
|
38
|
+
IOwnable(address(proxy)).transferOwnership(owner);
|
|
39
|
+
IOwnable(address(inco.incoVerifier())).transferOwnership(owner);
|
|
40
40
|
vm.stopPrank();
|
|
41
41
|
console.log(
|
|
42
42
|
"Deployed %s (proxy) to: %s",
|
|
@@ -48,8 +48,9 @@ contract IncoTest is MockOpHandler, DeployUtils {
|
|
|
48
48
|
address(proxy) == address(inco),
|
|
49
49
|
"generated inco address in Lib.sol does not match address of inco deployed by IncoTest"
|
|
50
50
|
);
|
|
51
|
-
vm.
|
|
52
|
-
inco.addSigner(teePubkeyAddress);
|
|
51
|
+
vm.startPrank(owner);
|
|
52
|
+
inco.incoVerifier().addSigner(teePubkeyAddress);
|
|
53
|
+
vm.stopPrank();
|
|
53
54
|
vm.recordLogs();
|
|
54
55
|
}
|
|
55
56
|
}
|
|
@@ -1,145 +1,166 @@
|
|
|
1
1
|
// SPDX-License-Identifier: UNLICENSED
|
|
2
2
|
pragma solidity ^0.8.0;
|
|
3
3
|
|
|
4
|
-
import "
|
|
5
|
-
import "
|
|
4
|
+
import {TEELifecycle} from "../../lightning-parts/TEELifecycle.sol";
|
|
5
|
+
import {BootstrapResult} from "../../lightning-parts/TEELifecycle.types.sol";
|
|
6
6
|
import {MockRemoteAttestation} from "../FakeIncoInfra/MockRemoteAttestation.sol";
|
|
7
7
|
import {FakeQuoteVerifier} from "../FakeIncoInfra/FakeQuoteVerifier.sol";
|
|
8
|
-
|
|
9
|
-
import "forge-std/Vm.sol";
|
|
10
|
-
import "forge-std/Test.sol";
|
|
8
|
+
import {Test} from "forge-std/Test.sol";
|
|
11
9
|
|
|
12
10
|
contract TEELifecycleMockTest is Test, MockRemoteAttestation, TEELifecycle {
|
|
13
|
-
|
|
14
11
|
function setUp() public {
|
|
15
12
|
quoteVerifier = new FakeQuoteVerifier();
|
|
16
13
|
}
|
|
17
14
|
|
|
18
|
-
function
|
|
19
|
-
(
|
|
15
|
+
function testSuccessfulBootstrap() public {
|
|
16
|
+
(
|
|
17
|
+
BootstrapResult memory bootstrapResult,
|
|
18
|
+
,
|
|
19
|
+
,
|
|
20
|
+
bytes memory quote,
|
|
21
|
+
bytes memory signature,
|
|
22
|
+
bytes memory mrtd
|
|
23
|
+
) = successfulBootstrapResult();
|
|
20
24
|
vm.startPrank(this.owner());
|
|
21
25
|
this.approveNewTEEVersion(mrtd);
|
|
22
|
-
this.verifyBootstrapResult(
|
|
23
|
-
bootstrapResult,
|
|
24
|
-
quote,
|
|
25
|
-
signature
|
|
26
|
-
);
|
|
26
|
+
this.verifyBootstrapResult(bootstrapResult, quote, signature);
|
|
27
27
|
assertTrue(this.isBootstrapComplete(), "Bootstrap should be complete");
|
|
28
28
|
vm.stopPrank();
|
|
29
29
|
}
|
|
30
|
-
|
|
31
|
-
function test_invalidMrtd() public {
|
|
32
|
-
bytes memory badMrtd = hex"1234567890abcdef1234567890abcdef1234567890abcdef1234567890abcdef1234567890abcdef1234567890abcdef";
|
|
33
30
|
|
|
34
|
-
|
|
31
|
+
function testInvalidMrtd() public {
|
|
32
|
+
bytes
|
|
33
|
+
memory badMrtd = hex"1234567890abcdef1234567890abcdef1234567890abcdef1234567890abcdef1234567890abcdef1234567890abcdef";
|
|
34
|
+
|
|
35
|
+
(
|
|
36
|
+
BootstrapResult memory bootstrapResult,
|
|
37
|
+
,
|
|
38
|
+
address bootstrapPartyAddress,
|
|
39
|
+
bytes memory quote,
|
|
40
|
+
bytes memory signature,
|
|
41
|
+
bytes memory mrtd
|
|
42
|
+
) = successfulBootstrapResult();
|
|
35
43
|
|
|
36
44
|
quote = createQuote(badMrtd, bootstrapPartyAddress); // Replace with bad MRTD
|
|
37
45
|
vm.startPrank(this.owner());
|
|
38
46
|
this.approveNewTEEVersion(mrtd);
|
|
39
|
-
vm.expectRevert(
|
|
40
|
-
this.verifyBootstrapResult(
|
|
41
|
-
bootstrapResult,
|
|
42
|
-
quote,
|
|
43
|
-
signature
|
|
44
|
-
);
|
|
47
|
+
vm.expectRevert(TEELifecycle.InvalidReportMRTD.selector);
|
|
48
|
+
this.verifyBootstrapResult(bootstrapResult, quote, signature);
|
|
45
49
|
vm.stopPrank();
|
|
46
50
|
}
|
|
47
51
|
|
|
48
|
-
function
|
|
49
|
-
(
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
52
|
+
function testInvalidSignature() public {
|
|
53
|
+
(
|
|
54
|
+
BootstrapResult memory bootstrapResult,
|
|
55
|
+
,
|
|
56
|
+
,
|
|
57
|
+
bytes memory quote,
|
|
58
|
+
,
|
|
59
|
+
bytes memory mrtd
|
|
60
|
+
) = successfulBootstrapResult();
|
|
61
|
+
(uint256 bootstrapPartyFakePrivkey, ) = getLabeledKeyPair(
|
|
62
|
+
"bootstrapPartyFake"
|
|
63
|
+
);
|
|
64
|
+
bytes memory signatureInvalid = signBootstrapResult(
|
|
56
65
|
bootstrapResult,
|
|
57
|
-
|
|
58
|
-
signatureInvalid
|
|
66
|
+
bootstrapPartyFakePrivkey
|
|
59
67
|
);
|
|
68
|
+
vm.startPrank(this.owner());
|
|
69
|
+
this.approveNewTEEVersion(mrtd);
|
|
70
|
+
vm.expectRevert(TEELifecycle.InvalidBootstrapDataSignature.selector);
|
|
71
|
+
this.verifyBootstrapResult(bootstrapResult, quote, signatureInvalid);
|
|
60
72
|
vm.stopPrank();
|
|
61
73
|
}
|
|
62
74
|
|
|
63
|
-
function
|
|
64
|
-
(
|
|
75
|
+
function testBootstrapAlreadyComplete() public {
|
|
76
|
+
(
|
|
77
|
+
BootstrapResult memory bootstrapResult,
|
|
78
|
+
,
|
|
79
|
+
,
|
|
80
|
+
bytes memory quote,
|
|
81
|
+
bytes memory signature,
|
|
82
|
+
bytes memory mrtd
|
|
83
|
+
) = successfulBootstrapResult();
|
|
65
84
|
vm.startPrank(this.owner());
|
|
66
85
|
this.approveNewTEEVersion(mrtd);
|
|
67
|
-
this.verifyBootstrapResult(
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
signature
|
|
71
|
-
);
|
|
72
|
-
vm.expectRevert(bytes("Bootstrap already completed"));
|
|
73
|
-
this.verifyBootstrapResult(
|
|
74
|
-
bootstrapResult,
|
|
75
|
-
quote,
|
|
76
|
-
signature
|
|
77
|
-
);
|
|
86
|
+
this.verifyBootstrapResult(bootstrapResult, quote, signature);
|
|
87
|
+
vm.expectRevert(TEELifecycle.BootstrapAlreadyCompleted.selector);
|
|
88
|
+
this.verifyBootstrapResult(bootstrapResult, quote, signature);
|
|
78
89
|
vm.stopPrank();
|
|
79
90
|
}
|
|
80
91
|
|
|
81
|
-
function
|
|
92
|
+
function testApproveNewTEEInvalidMrtd() public {
|
|
82
93
|
bytes memory mrtd = hex"deadbeef";
|
|
83
94
|
vm.startPrank(this.owner());
|
|
84
|
-
vm.expectRevert(
|
|
95
|
+
vm.expectRevert(TEELifecycle.MrtdInvalidLength.selector);
|
|
85
96
|
this.approveNewTEEVersion(mrtd);
|
|
86
97
|
vm.stopPrank();
|
|
87
98
|
}
|
|
88
99
|
|
|
89
|
-
function
|
|
90
|
-
bytes
|
|
100
|
+
function testBootstrapNotCompleteNewCoval() public {
|
|
101
|
+
bytes
|
|
102
|
+
memory mrtd = hex"2a90c8fa38672cafd791d994beb6836b99383b2563736858632284f0f760a6446efd1e7ec457cf08b629ea630f7b4525";
|
|
91
103
|
(, address newCoval) = getLabeledKeyPair("newCoval");
|
|
92
104
|
bytes memory quote = createQuote(mrtd, newCoval);
|
|
93
105
|
vm.startPrank(this.owner());
|
|
94
|
-
vm.expectRevert(
|
|
106
|
+
vm.expectRevert(TEELifecycle.BootstrapNotComplete.selector);
|
|
95
107
|
this.addNewCovalidator(quote);
|
|
96
108
|
vm.stopPrank();
|
|
97
109
|
}
|
|
98
110
|
|
|
99
|
-
function
|
|
100
|
-
(
|
|
111
|
+
function testInvalidMrtdNewCoval() public {
|
|
112
|
+
(
|
|
113
|
+
BootstrapResult memory bootstrapResult,
|
|
114
|
+
,
|
|
115
|
+
,
|
|
116
|
+
bytes memory quote,
|
|
117
|
+
bytes memory signature,
|
|
118
|
+
bytes memory mrtd
|
|
119
|
+
) = successfulBootstrapResult();
|
|
101
120
|
vm.startPrank(this.owner());
|
|
102
121
|
this.approveNewTEEVersion(mrtd);
|
|
103
|
-
this.verifyBootstrapResult(
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
signature
|
|
107
|
-
);
|
|
108
|
-
bytes memory badMrtd = hex"1234567890abcdef1234567890abcdef1234567890abcdef1234567890abcdef1234567890abcdef1234567890abcdef";
|
|
122
|
+
this.verifyBootstrapResult(bootstrapResult, quote, signature);
|
|
123
|
+
bytes
|
|
124
|
+
memory badMrtd = hex"1234567890abcdef1234567890abcdef1234567890abcdef1234567890abcdef1234567890abcdef1234567890abcdef";
|
|
109
125
|
(, address newCoval) = getLabeledKeyPair("newCoval");
|
|
110
126
|
bytes memory quoteNew = createQuote(badMrtd, newCoval);
|
|
111
|
-
|
|
112
|
-
vm.expectRevert(
|
|
127
|
+
|
|
128
|
+
vm.expectRevert(TEELifecycle.InvalidMrtdReport.selector);
|
|
113
129
|
this.addNewCovalidator(quoteNew);
|
|
114
130
|
vm.stopPrank();
|
|
115
131
|
}
|
|
116
132
|
|
|
117
133
|
// Helper function to create a successful bootstrap result
|
|
118
|
-
function successfulBootstrapResult()
|
|
119
|
-
|
|
120
|
-
|
|
134
|
+
function successfulBootstrapResult()
|
|
135
|
+
internal
|
|
136
|
+
returns (
|
|
137
|
+
BootstrapResult memory bootstrapResult,
|
|
138
|
+
uint256 bootstrapPartyPrivkey,
|
|
139
|
+
address bootstrapPartyAddress,
|
|
140
|
+
bytes memory quote,
|
|
141
|
+
bytes memory signature,
|
|
142
|
+
bytes memory mrtd
|
|
143
|
+
)
|
|
144
|
+
{
|
|
145
|
+
(bootstrapPartyPrivkey, bootstrapPartyAddress) = getLabeledKeyPair(
|
|
146
|
+
"bootstrapParty"
|
|
147
|
+
);
|
|
148
|
+
bytes
|
|
149
|
+
memory eciesPubkey = hex"04ff5c6dd72ad7583288b84ee2598e081fe0bc6ef543c342e925a5dfcff9afb2444d25454d7d5dcfadc9ed99477c245efa93caf58d7f58143300d81cc948e7bdf5";
|
|
121
150
|
mrtd = hex"2a90c8fa38672cafd791d994beb6836b99383b2563736858632284f0f760a6446efd1e7ec457cf08b629ea630f7b4525";
|
|
122
151
|
|
|
123
|
-
bootstrapResult = BootstrapResult({
|
|
124
|
-
ecies_pubkey: eciesPubkey
|
|
125
|
-
});
|
|
152
|
+
bootstrapResult = BootstrapResult({ecies_pubkey: eciesPubkey});
|
|
126
153
|
|
|
127
|
-
quote = createQuote(
|
|
128
|
-
mrtd,
|
|
129
|
-
bootstrapPartyAddress
|
|
130
|
-
);
|
|
154
|
+
quote = createQuote(mrtd, bootstrapPartyAddress);
|
|
131
155
|
signature = signBootstrapResult(bootstrapResult, bootstrapPartyPrivkey);
|
|
132
156
|
}
|
|
133
|
-
|
|
157
|
+
|
|
134
158
|
// Helper function to sign the bootstrap result
|
|
135
159
|
function signBootstrapResult(
|
|
136
160
|
BootstrapResult memory bootstrapResult,
|
|
137
161
|
uint256 privateKey
|
|
138
162
|
) internal view returns (bytes memory) {
|
|
139
|
-
bytes32 bootstrapResultDigest = bootstrapResultDigest(
|
|
140
|
-
bootstrapResult
|
|
141
|
-
);
|
|
163
|
+
bytes32 bootstrapResultDigest = bootstrapResultDigest(bootstrapResult);
|
|
142
164
|
return getSignatureForDigest(bootstrapResultDigest, privateKey);
|
|
143
165
|
}
|
|
144
|
-
|
|
145
|
-
}
|
|
166
|
+
}
|
|
@@ -7,9 +7,15 @@ import {IncoTest} from "./IncoTest.sol";
|
|
|
7
7
|
import {AddTwo} from "./AddTwo.sol";
|
|
8
8
|
|
|
9
9
|
contract TestAddTwo is IncoTest {
|
|
10
|
-
|
|
11
|
-
|
|
10
|
+
AddTwo addTwo;
|
|
11
|
+
|
|
12
|
+
function setUp() public override {
|
|
13
|
+
super.setUp();
|
|
14
|
+
addTwo = new AddTwo(inco);
|
|
12
15
|
vm.label(address(addTwo), "addTwo");
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
function testAddTwo() public {
|
|
13
19
|
euint256 a = inco.asEuint256(3);
|
|
14
20
|
inco.allow(euint256.unwrap(a), address(addTwo));
|
|
15
21
|
euint256 b = addTwo.addTwo(a);
|
|
@@ -17,13 +23,14 @@ contract TestAddTwo is IncoTest {
|
|
|
17
23
|
assertEq(getUint256Value(b), 5);
|
|
18
24
|
}
|
|
19
25
|
|
|
20
|
-
function
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
inco.allow(euint256.unwrap(a), address(addTwo));
|
|
25
|
-
euint256 b = addTwo.addTwoScalar(a);
|
|
26
|
+
function testAddTwoEoaAndPublicReveal() public {
|
|
27
|
+
(euint256 result, euint256 revealedResult) = addTwo.addTwoEOA(
|
|
28
|
+
fakePrepareEuint256Ciphertext(3)
|
|
29
|
+
);
|
|
26
30
|
processAllOperations();
|
|
27
|
-
assertEq(getUint256Value(
|
|
31
|
+
assertEq(getUint256Value(result), 5);
|
|
32
|
+
assertEq(getUint256Value(revealedResult), 5);
|
|
33
|
+
assertFalse(inco.isAllowed(euint256.unwrap(result), bob));
|
|
34
|
+
assertTrue(inco.isAllowed(euint256.unwrap(revealedResult), bob));
|
|
28
35
|
}
|
|
29
36
|
}
|