@inco/lightning 0.6.8 → 0.6.9
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 +29 -2
- package/manifest.yaml +0 -42
- package/package.json +5 -2
- package/src/CreateXHelper.sol +3 -1
- package/src/DeployUtils.sol +36 -71
- package/src/Errors.sol +1 -1
- package/src/IIncoLightning.sol +2 -0
- package/src/IncoLightning.sol +5 -17
- package/src/IncoVerifier.sol +12 -18
- package/src/Lib.template.sol +40 -159
- package/src/Types.sol +233 -97
- package/src/interfaces/IIncoLightning.sol +2 -0
- package/src/interfaces/IIncoVerifier.sol +7 -12
- package/src/interfaces/automata-interfaces/BELE.sol +2 -0
- package/src/interfaces/automata-interfaces/IAutomataEnclaveIdentityDao.sol +9 -11
- package/src/interfaces/automata-interfaces/IFmspcTcbDao.sol +3 -3
- package/src/interfaces/automata-interfaces/IPCCSRouter.sol +13 -47
- package/src/interfaces/automata-interfaces/IPCCSRouterExtended.sol +2 -0
- package/src/interfaces/automata-interfaces/IPcsDao.sol +6 -11
- package/src/interfaces/automata-interfaces/IQuoteVerifier.sol +4 -7
- package/src/interfaces/automata-interfaces/Types.sol +7 -6
- package/src/libs/incoLightning_devnet_v1_887305889.sol +5 -3
- package/src/libs/incoLightning_testnet_v1_938327937.sol +5 -3
- package/src/lightning-parts/AccessControl/AdvancedAccessControl.sol +41 -75
- package/src/lightning-parts/AccessControl/BaseAccessControlList.sol +31 -62
- package/src/lightning-parts/AccessControl/interfaces/IAdvancedAccessControl.sol +8 -15
- package/src/lightning-parts/AccessControl/interfaces/IBaseAccessControlList.sol +5 -12
- package/src/lightning-parts/AccessControl/test/TestAdvancedAccessControl.t.sol +42 -83
- package/src/lightning-parts/AccessControl/test/TestBaseAccessControl.t.sol +2 -0
- package/src/lightning-parts/DecryptionAttester.sol +14 -28
- package/src/lightning-parts/EncryptedInput.sol +23 -52
- package/src/lightning-parts/EncryptedOperations.sol +93 -440
- package/src/lightning-parts/Fee.sol +3 -1
- package/src/lightning-parts/TEELifecycle.sol +95 -225
- package/src/lightning-parts/TEELifecycle.types.sol +4 -3
- package/src/lightning-parts/TrivialEncryption.sol +6 -20
- package/src/lightning-parts/interfaces/IDecryptionAttester.sol +7 -2
- package/src/lightning-parts/interfaces/IEncryptedInput.sol +5 -12
- package/src/lightning-parts/interfaces/IEncryptedOperations.sol +17 -61
- package/src/lightning-parts/interfaces/ITEELifecycle.sol +7 -11
- package/src/lightning-parts/interfaces/ITrivialEncryption.sol +2 -0
- package/src/lightning-parts/primitives/EventCounter.sol +7 -8
- package/src/lightning-parts/primitives/HandleGeneration.sol +20 -32
- package/src/lightning-parts/primitives/HandleMetadata.sol +7 -17
- package/src/lightning-parts/primitives/LightningAddressGetter.sol +3 -0
- package/src/lightning-parts/primitives/SignatureVerifier.sol +91 -27
- package/src/lightning-parts/primitives/VerifierAddressGetter.sol +3 -0
- package/src/lightning-parts/primitives/interfaces/IEventCounter.sol +2 -0
- package/src/lightning-parts/primitives/interfaces/IHandleGeneration.sol +10 -2
- package/src/lightning-parts/primitives/interfaces/ISignatureVerifier.sol +4 -2
- package/src/lightning-parts/primitives/interfaces/IVerifierAddressGetter.sol +2 -0
- package/src/lightning-parts/primitives/test/SignatureVerifier.t.sol +838 -0
- package/src/lightning-parts/test/Fee.t.sol +6 -6
- package/src/lightning-parts/test/HandleMetadata.t.sol +21 -76
- package/src/lightning-parts/test/InputsFee.t.sol +7 -28
- package/src/lightning-parts/test/TestDecryptionAttestationInSynchronousFlow.t.sol +16 -48
- package/src/pasted-dependencies/CreateX.sol +146 -419
- package/src/pasted-dependencies/ICreateX.sol +58 -102
- package/src/periphery/SessionVerifier.sol +5 -7
- package/src/shared/IOwnable.sol +3 -0
- package/src/shared/IUUPSUpgradable.sol +5 -1
- package/src/shared/JsonUtils.sol +3 -5
- package/src/shared/TestUtils.sol +14 -13
- package/src/test/AddTwo.sol +9 -7
- package/src/test/FakeIncoInfra/FakeComputeServer.sol +11 -53
- package/src/test/FakeIncoInfra/FakeDecryptionAttester.sol +35 -118
- package/src/test/FakeIncoInfra/FakeIncoInfraBase.sol +31 -48
- package/src/test/FakeIncoInfra/FakeQuoteVerifier.sol +4 -7
- package/src/test/FakeIncoInfra/KVStore.sol +2 -0
- package/src/test/FakeIncoInfra/MockOpHandler.sol +9 -31
- package/src/test/FakeIncoInfra/MockRemoteAttestation.sol +44 -21
- package/src/test/IncoTest.sol +15 -9
- package/src/test/OpsTest.sol +429 -0
- package/src/test/TEELifecycle/TEELifecycleMockTest.t.sol +58 -104
- package/src/test/TestAddTwo.t.sol +4 -3
- package/src/test/TestDeploy.t.sol +5 -6
- package/src/test/TestExtractDataOfEventTooLarge.t.sol +7 -14
- package/src/test/TestFakeInfra.t.sol +15 -38
- package/src/test/TestUpgrade.t.sol +40 -135
- package/src/test/TestVersion.t.sol +6 -5
- package/src/version/IncoLightningConfig.sol +1 -1
- package/src/version/Version.sol +48 -51
- package/src/version/interfaces/IVersion.sol +6 -0
|
@@ -0,0 +1,429 @@
|
|
|
1
|
+
// SPDX-License-Identifier: No License
|
|
2
|
+
pragma solidity ^0.8;
|
|
3
|
+
|
|
4
|
+
import {IncoLightning} from "../IncoLightning.sol";
|
|
5
|
+
import {euint256, ebool, eaddress, ETypes} from "../Types.sol";
|
|
6
|
+
import {Fee} from "../lightning-parts/Fee.sol";
|
|
7
|
+
|
|
8
|
+
contract OpsTest is Fee {
|
|
9
|
+
|
|
10
|
+
IncoLightning inco;
|
|
11
|
+
|
|
12
|
+
constructor(IncoLightning _inco) {
|
|
13
|
+
inco = _inco;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
// ============ ARITHMETIC OPERATIONS ============
|
|
17
|
+
|
|
18
|
+
function testAdd(euint256 a, euint256 b) external returns (euint256) {
|
|
19
|
+
euint256 result = inco.eAdd(a, b);
|
|
20
|
+
inco.allow(euint256.unwrap(result), address(this));
|
|
21
|
+
inco.allow(euint256.unwrap(result), msg.sender);
|
|
22
|
+
return result;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
function testAddScalar(euint256 a, uint256 b) external returns (euint256) {
|
|
26
|
+
euint256 result = inco.eAdd(a, inco.asEuint256(b));
|
|
27
|
+
inco.allow(euint256.unwrap(result), address(this));
|
|
28
|
+
inco.allow(euint256.unwrap(result), msg.sender);
|
|
29
|
+
return result;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
function testSub(euint256 a, euint256 b) external returns (euint256) {
|
|
33
|
+
euint256 result = inco.eSub(a, b);
|
|
34
|
+
inco.allow(euint256.unwrap(result), address(this));
|
|
35
|
+
inco.allow(euint256.unwrap(result), msg.sender);
|
|
36
|
+
return result;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
function testSubScalar(euint256 a, uint256 b) external returns (euint256) {
|
|
40
|
+
euint256 result = inco.eSub(a, inco.asEuint256(b));
|
|
41
|
+
inco.allow(euint256.unwrap(result), address(this));
|
|
42
|
+
inco.allow(euint256.unwrap(result), msg.sender);
|
|
43
|
+
return result;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
function testMul(euint256 a, euint256 b) external returns (euint256) {
|
|
47
|
+
euint256 result = inco.eMul(a, b);
|
|
48
|
+
inco.allow(euint256.unwrap(result), address(this));
|
|
49
|
+
inco.allow(euint256.unwrap(result), msg.sender);
|
|
50
|
+
return result;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
function testMulScalar(euint256 a, uint256 b) external returns (euint256) {
|
|
54
|
+
euint256 result = inco.eMul(a, inco.asEuint256(b));
|
|
55
|
+
inco.allow(euint256.unwrap(result), address(this));
|
|
56
|
+
inco.allow(euint256.unwrap(result), msg.sender);
|
|
57
|
+
return result;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
function testDiv(euint256 a, euint256 b) external returns (euint256) {
|
|
61
|
+
euint256 result = inco.eDiv(a, b);
|
|
62
|
+
inco.allow(euint256.unwrap(result), address(this));
|
|
63
|
+
inco.allow(euint256.unwrap(result), msg.sender);
|
|
64
|
+
return result;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
function testDivScalar(euint256 a, uint256 b) external returns (euint256) {
|
|
68
|
+
euint256 result = inco.eDiv(a, inco.asEuint256(b));
|
|
69
|
+
inco.allow(euint256.unwrap(result), address(this));
|
|
70
|
+
inco.allow(euint256.unwrap(result), msg.sender);
|
|
71
|
+
return result;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
function testRem(euint256 a, euint256 b) external returns (euint256) {
|
|
75
|
+
euint256 result = inco.eRem(a, b);
|
|
76
|
+
inco.allow(euint256.unwrap(result), address(this));
|
|
77
|
+
inco.allow(euint256.unwrap(result), msg.sender);
|
|
78
|
+
return result;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
function testRemScalar(euint256 a, uint256 b) external returns (euint256) {
|
|
82
|
+
euint256 result = inco.eRem(a, inco.asEuint256(b));
|
|
83
|
+
inco.allow(euint256.unwrap(result), address(this));
|
|
84
|
+
inco.allow(euint256.unwrap(result), msg.sender);
|
|
85
|
+
return result;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
// ============ BITWISE OPERATIONS ============
|
|
89
|
+
|
|
90
|
+
function testAnd(euint256 a, euint256 b) external returns (euint256) {
|
|
91
|
+
euint256 result = euint256.wrap(inco.eBitAnd(euint256.unwrap(a), euint256.unwrap(b)));
|
|
92
|
+
inco.allow(euint256.unwrap(result), address(this));
|
|
93
|
+
inco.allow(euint256.unwrap(result), msg.sender);
|
|
94
|
+
return result;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
function testAndScalar(euint256 a, uint256 b) external returns (euint256) {
|
|
98
|
+
euint256 result = euint256.wrap(inco.eBitAnd(euint256.unwrap(a), euint256.unwrap(inco.asEuint256(b))));
|
|
99
|
+
inco.allow(euint256.unwrap(result), address(this));
|
|
100
|
+
inco.allow(euint256.unwrap(result), msg.sender);
|
|
101
|
+
return result;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
function testAndBool(ebool a, ebool b) external returns (ebool) {
|
|
105
|
+
ebool result = ebool.wrap(inco.eBitAnd(ebool.unwrap(a), ebool.unwrap(b)));
|
|
106
|
+
inco.allow(ebool.unwrap(result), address(this));
|
|
107
|
+
inco.allow(ebool.unwrap(result), msg.sender);
|
|
108
|
+
return result;
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
function testAndBoolScalar(ebool a, bool b) external returns (ebool) {
|
|
112
|
+
ebool result = ebool.wrap(inco.eBitAnd(ebool.unwrap(a), ebool.unwrap(inco.asEbool(b))));
|
|
113
|
+
inco.allow(ebool.unwrap(result), address(this));
|
|
114
|
+
inco.allow(ebool.unwrap(result), msg.sender);
|
|
115
|
+
return result;
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
function testOr(euint256 a, euint256 b) external returns (euint256) {
|
|
119
|
+
euint256 result = euint256.wrap(inco.eBitOr(euint256.unwrap(a), euint256.unwrap(b)));
|
|
120
|
+
inco.allow(euint256.unwrap(result), address(this));
|
|
121
|
+
inco.allow(euint256.unwrap(result), msg.sender);
|
|
122
|
+
return result;
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
function testOrScalar(euint256 a, uint256 b) external returns (euint256) {
|
|
126
|
+
euint256 result = euint256.wrap(inco.eBitOr(euint256.unwrap(a), euint256.unwrap(inco.asEuint256(b))));
|
|
127
|
+
inco.allow(euint256.unwrap(result), address(this));
|
|
128
|
+
inco.allow(euint256.unwrap(result), msg.sender);
|
|
129
|
+
return result;
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
function testOrBool(ebool a, ebool b) external returns (ebool) {
|
|
133
|
+
ebool result = ebool.wrap(inco.eBitOr(ebool.unwrap(a), ebool.unwrap(b)));
|
|
134
|
+
inco.allow(ebool.unwrap(result), address(this));
|
|
135
|
+
inco.allow(ebool.unwrap(result), msg.sender);
|
|
136
|
+
return result;
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
function testOrBoolScalar(ebool a, bool b) external returns (ebool) {
|
|
140
|
+
ebool result = ebool.wrap(inco.eBitOr(ebool.unwrap(a), ebool.unwrap(inco.asEbool(b))));
|
|
141
|
+
inco.allow(ebool.unwrap(result), address(this));
|
|
142
|
+
inco.allow(ebool.unwrap(result), msg.sender);
|
|
143
|
+
return result;
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
function testXor(euint256 a, euint256 b) external returns (euint256) {
|
|
147
|
+
euint256 result = euint256.wrap(inco.eBitXor(euint256.unwrap(a), euint256.unwrap(b)));
|
|
148
|
+
inco.allow(euint256.unwrap(result), address(this));
|
|
149
|
+
inco.allow(euint256.unwrap(result), msg.sender);
|
|
150
|
+
return result;
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
function testXorScalar(euint256 a, uint256 b) external returns (euint256) {
|
|
154
|
+
euint256 result = euint256.wrap(inco.eBitXor(euint256.unwrap(a), euint256.unwrap(inco.asEuint256(b))));
|
|
155
|
+
inco.allow(euint256.unwrap(result), address(this));
|
|
156
|
+
inco.allow(euint256.unwrap(result), msg.sender);
|
|
157
|
+
return result;
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
function testXorBool(ebool a, ebool b) external returns (ebool) {
|
|
161
|
+
ebool result = ebool.wrap(inco.eBitXor(ebool.unwrap(a), ebool.unwrap(b)));
|
|
162
|
+
inco.allow(ebool.unwrap(result), address(this));
|
|
163
|
+
inco.allow(ebool.unwrap(result), msg.sender);
|
|
164
|
+
return result;
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
function testXorBoolScalar(ebool a, bool b) external returns (ebool) {
|
|
168
|
+
ebool result = ebool.wrap(inco.eBitXor(ebool.unwrap(a), ebool.unwrap(inco.asEbool(b))));
|
|
169
|
+
inco.allow(ebool.unwrap(result), address(this));
|
|
170
|
+
inco.allow(ebool.unwrap(result), msg.sender);
|
|
171
|
+
return result;
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
function testShl(euint256 a, euint256 b) external returns (euint256) {
|
|
175
|
+
euint256 result = inco.eShl(a, b);
|
|
176
|
+
inco.allow(euint256.unwrap(result), address(this));
|
|
177
|
+
inco.allow(euint256.unwrap(result), msg.sender);
|
|
178
|
+
return result;
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
function testShlScalar(euint256 a, uint256 b) external returns (euint256) {
|
|
182
|
+
euint256 result = inco.eShl(a, inco.asEuint256(b));
|
|
183
|
+
inco.allow(euint256.unwrap(result), address(this));
|
|
184
|
+
inco.allow(euint256.unwrap(result), msg.sender);
|
|
185
|
+
return result;
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
function testShr(euint256 a, euint256 b) external returns (euint256) {
|
|
189
|
+
euint256 result = inco.eShr(a, b);
|
|
190
|
+
inco.allow(euint256.unwrap(result), address(this));
|
|
191
|
+
inco.allow(euint256.unwrap(result), msg.sender);
|
|
192
|
+
return result;
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
function testShrScalar(euint256 a, uint256 b) external returns (euint256) {
|
|
196
|
+
euint256 result = inco.eShr(a, inco.asEuint256(b));
|
|
197
|
+
inco.allow(euint256.unwrap(result), address(this));
|
|
198
|
+
inco.allow(euint256.unwrap(result), msg.sender);
|
|
199
|
+
return result;
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
function testRotl(euint256 a, euint256 b) external returns (euint256) {
|
|
203
|
+
euint256 result = inco.eRotl(a, b);
|
|
204
|
+
inco.allow(euint256.unwrap(result), address(this));
|
|
205
|
+
inco.allow(euint256.unwrap(result), msg.sender);
|
|
206
|
+
return result;
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
function testRotlScalar(euint256 a, uint256 b) external returns (euint256) {
|
|
210
|
+
euint256 result = inco.eRotl(a, inco.asEuint256(b));
|
|
211
|
+
inco.allow(euint256.unwrap(result), address(this));
|
|
212
|
+
inco.allow(euint256.unwrap(result), msg.sender);
|
|
213
|
+
return result;
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
function testRotr(euint256 a, euint256 b) external returns (euint256) {
|
|
217
|
+
euint256 result = inco.eRotr(a, b);
|
|
218
|
+
inco.allow(euint256.unwrap(result), address(this));
|
|
219
|
+
inco.allow(euint256.unwrap(result), msg.sender);
|
|
220
|
+
return result;
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
function testRotrScalar(euint256 a, uint256 b) external returns (euint256) {
|
|
224
|
+
euint256 result = inco.eRotr(a, inco.asEuint256(b));
|
|
225
|
+
inco.allow(euint256.unwrap(result), address(this));
|
|
226
|
+
inco.allow(euint256.unwrap(result), msg.sender);
|
|
227
|
+
return result;
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
// ============ COMPARISON OPERATIONS ============
|
|
231
|
+
|
|
232
|
+
function testEq(euint256 a, euint256 b) external returns (ebool) {
|
|
233
|
+
ebool result = inco.eEq(euint256.unwrap(a), euint256.unwrap(b));
|
|
234
|
+
inco.allow(ebool.unwrap(result), address(this));
|
|
235
|
+
inco.allow(ebool.unwrap(result), msg.sender);
|
|
236
|
+
return result;
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
function testEqScalar(euint256 a, uint256 b) external returns (ebool) {
|
|
240
|
+
ebool result = inco.eEq(euint256.unwrap(a), euint256.unwrap(inco.asEuint256(b)));
|
|
241
|
+
inco.allow(ebool.unwrap(result), address(this));
|
|
242
|
+
inco.allow(ebool.unwrap(result), msg.sender);
|
|
243
|
+
return result;
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
function testEqAddress(eaddress a, eaddress b) external returns (ebool) {
|
|
247
|
+
ebool result = inco.eEq(eaddress.unwrap(a), eaddress.unwrap(b));
|
|
248
|
+
inco.allow(ebool.unwrap(result), address(this));
|
|
249
|
+
inco.allow(ebool.unwrap(result), msg.sender);
|
|
250
|
+
return result;
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
function testEqAddressScalar(eaddress a, address b) external returns (ebool) {
|
|
254
|
+
ebool result = inco.eEq(eaddress.unwrap(a), eaddress.unwrap(inco.asEaddress(b)));
|
|
255
|
+
inco.allow(ebool.unwrap(result), address(this));
|
|
256
|
+
inco.allow(ebool.unwrap(result), msg.sender);
|
|
257
|
+
return result;
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
function testNe(euint256 a, euint256 b) external returns (ebool) {
|
|
261
|
+
ebool result = inco.eNe(euint256.unwrap(a), euint256.unwrap(b));
|
|
262
|
+
inco.allow(ebool.unwrap(result), address(this));
|
|
263
|
+
inco.allow(ebool.unwrap(result), msg.sender);
|
|
264
|
+
return result;
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
function testNeScalar(euint256 a, uint256 b) external returns (ebool) {
|
|
268
|
+
ebool result = inco.eNe(euint256.unwrap(a), euint256.unwrap(inco.asEuint256(b)));
|
|
269
|
+
inco.allow(ebool.unwrap(result), address(this));
|
|
270
|
+
inco.allow(ebool.unwrap(result), msg.sender);
|
|
271
|
+
return result;
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
function testNeAddress(eaddress a, eaddress b) external returns (ebool) {
|
|
275
|
+
ebool result = inco.eNe(eaddress.unwrap(a), eaddress.unwrap(b));
|
|
276
|
+
inco.allow(ebool.unwrap(result), address(this));
|
|
277
|
+
inco.allow(ebool.unwrap(result), msg.sender);
|
|
278
|
+
return result;
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
function testNeAddressScalar(eaddress a, address b) external returns (ebool) {
|
|
282
|
+
ebool result = inco.eNe(eaddress.unwrap(a), eaddress.unwrap(inco.asEaddress(b)));
|
|
283
|
+
inco.allow(ebool.unwrap(result), address(this));
|
|
284
|
+
inco.allow(ebool.unwrap(result), msg.sender);
|
|
285
|
+
return result;
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
function testGe(euint256 a, euint256 b) external returns (ebool) {
|
|
289
|
+
ebool result = inco.eGe(a, b);
|
|
290
|
+
inco.allow(ebool.unwrap(result), address(this));
|
|
291
|
+
inco.allow(ebool.unwrap(result), msg.sender);
|
|
292
|
+
return result;
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
function testGeScalar(euint256 a, uint256 b) external returns (ebool) {
|
|
296
|
+
ebool result = inco.eGe(a, inco.asEuint256(b));
|
|
297
|
+
inco.allow(ebool.unwrap(result), address(this));
|
|
298
|
+
inco.allow(ebool.unwrap(result), msg.sender);
|
|
299
|
+
return result;
|
|
300
|
+
}
|
|
301
|
+
|
|
302
|
+
function testGt(euint256 a, euint256 b) external returns (ebool) {
|
|
303
|
+
ebool result = inco.eGt(a, b);
|
|
304
|
+
inco.allow(ebool.unwrap(result), address(this));
|
|
305
|
+
inco.allow(ebool.unwrap(result), msg.sender);
|
|
306
|
+
return result;
|
|
307
|
+
}
|
|
308
|
+
|
|
309
|
+
function testGtScalar(euint256 a, uint256 b) external returns (ebool) {
|
|
310
|
+
ebool result = inco.eGt(a, inco.asEuint256(b));
|
|
311
|
+
inco.allow(ebool.unwrap(result), address(this));
|
|
312
|
+
inco.allow(ebool.unwrap(result), msg.sender);
|
|
313
|
+
return result;
|
|
314
|
+
}
|
|
315
|
+
|
|
316
|
+
function testLe(euint256 a, euint256 b) external returns (ebool) {
|
|
317
|
+
ebool result = inco.eLe(a, b);
|
|
318
|
+
inco.allow(ebool.unwrap(result), address(this));
|
|
319
|
+
inco.allow(ebool.unwrap(result), msg.sender);
|
|
320
|
+
return result;
|
|
321
|
+
}
|
|
322
|
+
|
|
323
|
+
function testLeScalar(euint256 a, uint256 b) external returns (ebool) {
|
|
324
|
+
ebool result = inco.eLe(a, inco.asEuint256(b));
|
|
325
|
+
inco.allow(ebool.unwrap(result), address(this));
|
|
326
|
+
inco.allow(ebool.unwrap(result), msg.sender);
|
|
327
|
+
return result;
|
|
328
|
+
}
|
|
329
|
+
|
|
330
|
+
function testLt(euint256 a, euint256 b) external returns (ebool) {
|
|
331
|
+
ebool result = inco.eLt(a, b);
|
|
332
|
+
inco.allow(ebool.unwrap(result), address(this));
|
|
333
|
+
inco.allow(ebool.unwrap(result), msg.sender);
|
|
334
|
+
return result;
|
|
335
|
+
}
|
|
336
|
+
|
|
337
|
+
function testLtScalar(euint256 a, uint256 b) external returns (ebool) {
|
|
338
|
+
ebool result = inco.eLt(a, inco.asEuint256(b));
|
|
339
|
+
inco.allow(ebool.unwrap(result), address(this));
|
|
340
|
+
inco.allow(ebool.unwrap(result), msg.sender);
|
|
341
|
+
return result;
|
|
342
|
+
}
|
|
343
|
+
|
|
344
|
+
function testMin(euint256 a, euint256 b) external returns (euint256) {
|
|
345
|
+
euint256 result = inco.eMin(a, b);
|
|
346
|
+
inco.allow(euint256.unwrap(result), address(this));
|
|
347
|
+
inco.allow(euint256.unwrap(result), msg.sender);
|
|
348
|
+
return result;
|
|
349
|
+
}
|
|
350
|
+
|
|
351
|
+
function testMinScalar(euint256 a, uint256 b) external returns (euint256) {
|
|
352
|
+
euint256 result = inco.eMin(a, inco.asEuint256(b));
|
|
353
|
+
inco.allow(euint256.unwrap(result), address(this));
|
|
354
|
+
inco.allow(euint256.unwrap(result), msg.sender);
|
|
355
|
+
return result;
|
|
356
|
+
}
|
|
357
|
+
|
|
358
|
+
function testMax(euint256 a, euint256 b) external returns (euint256) {
|
|
359
|
+
euint256 result = inco.eMax(a, b);
|
|
360
|
+
inco.allow(euint256.unwrap(result), address(this));
|
|
361
|
+
inco.allow(euint256.unwrap(result), msg.sender);
|
|
362
|
+
return result;
|
|
363
|
+
}
|
|
364
|
+
|
|
365
|
+
function testMaxScalar(euint256 a, uint256 b) external returns (euint256) {
|
|
366
|
+
euint256 result = inco.eMax(a, inco.asEuint256(b));
|
|
367
|
+
inco.allow(euint256.unwrap(result), address(this));
|
|
368
|
+
inco.allow(euint256.unwrap(result), msg.sender);
|
|
369
|
+
return result;
|
|
370
|
+
}
|
|
371
|
+
|
|
372
|
+
// ============ LOGICAL OPERATIONS ============
|
|
373
|
+
|
|
374
|
+
function testNot(ebool a) external returns (ebool) {
|
|
375
|
+
ebool result = inco.eNot(a);
|
|
376
|
+
inco.allow(ebool.unwrap(result), address(this));
|
|
377
|
+
inco.allow(ebool.unwrap(result), msg.sender);
|
|
378
|
+
return result;
|
|
379
|
+
}
|
|
380
|
+
|
|
381
|
+
// ============ RANDOM NUMBER GENERATION ============
|
|
382
|
+
|
|
383
|
+
function testRand() external payable returns (euint256) {
|
|
384
|
+
euint256 result = euint256.wrap(inco.eRand{value: getFee()}(ETypes.Uint256));
|
|
385
|
+
inco.allow(euint256.unwrap(result), address(this));
|
|
386
|
+
inco.allow(euint256.unwrap(result), msg.sender);
|
|
387
|
+
return result;
|
|
388
|
+
}
|
|
389
|
+
|
|
390
|
+
function testRandBounded(uint256 upperBound) external payable returns (euint256) {
|
|
391
|
+
euint256 result = euint256.wrap(
|
|
392
|
+
inco.eRandBounded{value: getFee()}(euint256.unwrap(inco.asEuint256(upperBound)), ETypes.Uint256)
|
|
393
|
+
);
|
|
394
|
+
inco.allow(euint256.unwrap(result), address(this));
|
|
395
|
+
inco.allow(euint256.unwrap(result), msg.sender);
|
|
396
|
+
return result;
|
|
397
|
+
}
|
|
398
|
+
|
|
399
|
+
function testRandBoundedEncrypted(euint256 upperBound) external payable returns (euint256) {
|
|
400
|
+
euint256 result = euint256.wrap(inco.eRandBounded{value: getFee()}(euint256.unwrap(upperBound), ETypes.Uint256));
|
|
401
|
+
inco.allow(euint256.unwrap(result), address(this));
|
|
402
|
+
inco.allow(euint256.unwrap(result), msg.sender);
|
|
403
|
+
return result;
|
|
404
|
+
}
|
|
405
|
+
|
|
406
|
+
// ============ ENCRYPTED INPUT CREATION ============
|
|
407
|
+
|
|
408
|
+
function testNewEuint256(bytes memory ciphertext, address user) external payable returns (euint256) {
|
|
409
|
+
euint256 encryptedUint256 = inco.newEuint256{value: getFee()}(ciphertext, user);
|
|
410
|
+
inco.allow(euint256.unwrap(encryptedUint256), address(this));
|
|
411
|
+
inco.allow(euint256.unwrap(encryptedUint256), user);
|
|
412
|
+
return encryptedUint256;
|
|
413
|
+
}
|
|
414
|
+
|
|
415
|
+
function testNewEbool(bytes memory ciphertext, address user) external payable returns (ebool) {
|
|
416
|
+
ebool encryptedBool = inco.newEbool{value: getFee()}(ciphertext, user);
|
|
417
|
+
inco.allow(ebool.unwrap(encryptedBool), address(this));
|
|
418
|
+
inco.allow(ebool.unwrap(encryptedBool), user);
|
|
419
|
+
return encryptedBool;
|
|
420
|
+
}
|
|
421
|
+
|
|
422
|
+
function testNewEaddress(bytes memory ciphertext, address user) external payable returns (eaddress) {
|
|
423
|
+
eaddress encryptedAddress = inco.newEaddress{value: getFee()}(ciphertext, user);
|
|
424
|
+
inco.allow(eaddress.unwrap(encryptedAddress), address(this));
|
|
425
|
+
inco.allow(eaddress.unwrap(encryptedAddress), user);
|
|
426
|
+
return encryptedAddress;
|
|
427
|
+
}
|
|
428
|
+
|
|
429
|
+
}
|
|
@@ -5,92 +5,65 @@ import {TEELifecycle} from "../../lightning-parts/TEELifecycle.sol";
|
|
|
5
5
|
import {BootstrapResult, AddNodeResult} from "../../lightning-parts/TEELifecycle.types.sol";
|
|
6
6
|
import {MockRemoteAttestation} from "../FakeIncoInfra/MockRemoteAttestation.sol";
|
|
7
7
|
import {FakeQuoteVerifier} from "../FakeIncoInfra/FakeQuoteVerifier.sol";
|
|
8
|
-
import {Test} from "forge-std/Test.sol";
|
|
9
8
|
|
|
10
|
-
contract TEELifecycleMockTest is
|
|
9
|
+
contract TEELifecycleMockTest is MockRemoteAttestation, TEELifecycle {
|
|
10
|
+
|
|
11
11
|
// Constants for testing
|
|
12
|
-
bytes testNetworkPubkey =
|
|
12
|
+
bytes testNetworkPubkey =
|
|
13
|
+
hex"04ff5c6dd72ad7583288b84ee2598e081fe0bc6ef543c342e925a5dfcff9afb2444d25454d7d5dcfadc9ed99477c245efa93caf58d7f58143300d81cc948e7bdf5";
|
|
13
14
|
// See DEFAULT_MRTD in attestation/src/remote_attestation.rs
|
|
14
|
-
bytes testMrtd =
|
|
15
|
+
bytes testMrtd =
|
|
16
|
+
hex"010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101";
|
|
15
17
|
// See DEFAULT_MR_AGGREGATED in attestation/src/remote_attestation.rs to
|
|
16
18
|
// see the calculation of the default value.
|
|
17
19
|
bytes32 testMrAggregated = hex"c3a67bac251d4946d7b17481d39631676042fe3afab06e70c22105ad8383c19f";
|
|
18
20
|
|
|
19
21
|
function setUp() public {
|
|
20
|
-
|
|
22
|
+
getTeeLifecycleStorage().quoteVerifier = new FakeQuoteVerifier();
|
|
21
23
|
}
|
|
22
24
|
|
|
23
25
|
function testSuccessfulBootstrap() public {
|
|
24
|
-
(
|
|
25
|
-
|
|
26
|
-
,
|
|
27
|
-
,
|
|
28
|
-
bytes memory quote,
|
|
29
|
-
bytes memory signature,
|
|
30
|
-
bytes32 mrAggregated
|
|
31
|
-
) = successfulBootstrapResult();
|
|
26
|
+
(BootstrapResult memory bootstrapResult,,, bytes memory quote, bytes memory signature, bytes32 mrAggregated) =
|
|
27
|
+
successfulBootstrapResult();
|
|
32
28
|
vm.startPrank(this.owner());
|
|
33
|
-
this.
|
|
29
|
+
this.approveNewTeeVersion(mrAggregated);
|
|
34
30
|
this.verifyBootstrapResult(bootstrapResult, quote, signature);
|
|
35
31
|
assertTrue(this.isBootstrapComplete(), "Bootstrap should be complete");
|
|
36
32
|
vm.stopPrank();
|
|
37
33
|
}
|
|
38
34
|
|
|
39
35
|
function testInvalidMrtd() public {
|
|
40
|
-
bytes
|
|
41
|
-
|
|
36
|
+
bytes memory badMrtd =
|
|
37
|
+
hex"1234567890abcdef1234567890abcdef1234567890abcdef1234567890abcdef1234567890abcdef1234567890abcdef";
|
|
42
38
|
|
|
43
|
-
(
|
|
44
|
-
|
|
45
|
-
,
|
|
46
|
-
address bootstrapPartyAddress,
|
|
47
|
-
bytes memory quote,
|
|
48
|
-
bytes memory signature,
|
|
49
|
-
bytes32 mrAggregated
|
|
50
|
-
) = successfulBootstrapResult();
|
|
39
|
+
(BootstrapResult memory bootstrapResult, bytes memory quote, bytes memory signature, bytes32 mrAggregated) =
|
|
40
|
+
successfulBootstrapResult(this);
|
|
51
41
|
|
|
52
|
-
quote = createQuote(badMrtd,
|
|
42
|
+
quote = createQuote(badMrtd, teeEOA); // Replace with bad MRTD
|
|
53
43
|
vm.startPrank(this.owner());
|
|
54
|
-
this.
|
|
44
|
+
this.approveNewTeeVersion(mrAggregated);
|
|
55
45
|
vm.expectRevert(TEELifecycle.InvalidReportMrAggregated.selector);
|
|
56
46
|
this.verifyBootstrapResult(bootstrapResult, quote, signature);
|
|
57
47
|
vm.stopPrank();
|
|
58
48
|
}
|
|
59
49
|
|
|
60
50
|
function testInvalidSignature() public {
|
|
61
|
-
(
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
bytes memory quote,
|
|
66
|
-
,
|
|
67
|
-
bytes32 mrAggregated
|
|
68
|
-
) = successfulBootstrapResult();
|
|
69
|
-
(uint256 bootstrapPartyFakePrivkey, ) = getLabeledKeyPair(
|
|
70
|
-
"bootstrapPartyFake"
|
|
71
|
-
);
|
|
72
|
-
bytes memory signatureInvalid = signBootstrapResult(
|
|
73
|
-
bootstrapResult,
|
|
74
|
-
bootstrapPartyFakePrivkey
|
|
75
|
-
);
|
|
51
|
+
(BootstrapResult memory bootstrapResult,,, bytes memory quote,, bytes32 mrAggregated) =
|
|
52
|
+
successfulBootstrapResult();
|
|
53
|
+
(uint256 bootstrapPartyFakePrivkey,) = getLabeledKeyPair("bootstrapPartyFake");
|
|
54
|
+
bytes memory signatureInvalid = signBootstrapResult(bootstrapResult, bootstrapPartyFakePrivkey);
|
|
76
55
|
vm.startPrank(this.owner());
|
|
77
|
-
this.
|
|
56
|
+
this.approveNewTeeVersion(mrAggregated);
|
|
78
57
|
vm.expectRevert(TEELifecycle.InvalidEIP712Signature.selector);
|
|
79
58
|
this.verifyBootstrapResult(bootstrapResult, quote, signatureInvalid);
|
|
80
59
|
vm.stopPrank();
|
|
81
60
|
}
|
|
82
61
|
|
|
83
62
|
function testBootstrapAlreadyComplete() public {
|
|
84
|
-
(
|
|
85
|
-
|
|
86
|
-
,
|
|
87
|
-
,
|
|
88
|
-
bytes memory quote,
|
|
89
|
-
bytes memory signature,
|
|
90
|
-
bytes32 mrAggregated
|
|
91
|
-
) = successfulBootstrapResult();
|
|
63
|
+
(BootstrapResult memory bootstrapResult,,, bytes memory quote, bytes memory signature, bytes32 mrAggregated) =
|
|
64
|
+
successfulBootstrapResult();
|
|
92
65
|
vm.startPrank(this.owner());
|
|
93
|
-
this.
|
|
66
|
+
this.approveNewTeeVersion(mrAggregated);
|
|
94
67
|
this.verifyBootstrapResult(bootstrapResult, quote, signature);
|
|
95
68
|
vm.expectRevert(TEELifecycle.BootstrapAlreadyCompleted.selector);
|
|
96
69
|
this.verifyBootstrapResult(bootstrapResult, quote, signature);
|
|
@@ -98,77 +71,57 @@ contract TEELifecycleMockTest is Test, MockRemoteAttestation, TEELifecycle {
|
|
|
98
71
|
}
|
|
99
72
|
|
|
100
73
|
function testAddNodeBootstrapNotComplete() public {
|
|
101
|
-
bytes
|
|
102
|
-
|
|
74
|
+
bytes memory mrtd =
|
|
75
|
+
hex"2a90c8fa38672cafd791d994beb6836b99383b2563736858632284f0f760a6446efd1e7ec457cf08b629ea630f7b4525";
|
|
103
76
|
(, address newCoval) = getLabeledKeyPair("newCoval");
|
|
104
77
|
bytes memory quote = createQuote(mrtd, newCoval);
|
|
105
78
|
vm.startPrank(this.owner());
|
|
106
79
|
vm.expectRevert(TEELifecycle.BootstrapNotComplete.selector);
|
|
107
|
-
this.verifyAddNodeResult(testMrAggregated, AddNodeResult({
|
|
80
|
+
this.verifyAddNodeResult(testMrAggregated, AddNodeResult({networkPubkey: hex"00"}), quote, hex"");
|
|
108
81
|
vm.stopPrank();
|
|
109
82
|
}
|
|
110
83
|
|
|
111
84
|
function testAddNodeInvalidMrtd() public {
|
|
112
|
-
(
|
|
113
|
-
|
|
114
|
-
,
|
|
115
|
-
,
|
|
116
|
-
bytes memory quote,
|
|
117
|
-
bytes memory signature,
|
|
118
|
-
bytes32 mrAggregated
|
|
119
|
-
) = successfulBootstrapResult();
|
|
85
|
+
(BootstrapResult memory bootstrapResult,,, bytes memory quote, bytes memory signature, bytes32 mrAggregated) =
|
|
86
|
+
successfulBootstrapResult();
|
|
120
87
|
vm.startPrank(this.owner());
|
|
121
|
-
this.
|
|
88
|
+
this.approveNewTeeVersion(mrAggregated);
|
|
122
89
|
this.verifyBootstrapResult(bootstrapResult, quote, signature);
|
|
123
|
-
bytes
|
|
124
|
-
|
|
90
|
+
bytes memory badMrtd =
|
|
91
|
+
hex"1234567890abcdef1234567890abcdef1234567890abcdef1234567890abcdef1234567890abcdef1234567890abcdef";
|
|
125
92
|
(, address newCoval) = getLabeledKeyPair("newCoval");
|
|
126
93
|
bytes memory badQuote = createQuote(badMrtd, newCoval);
|
|
127
94
|
vm.expectRevert(TEELifecycle.InvalidReportMrAggregated.selector);
|
|
128
|
-
this.verifyAddNodeResult(mrAggregated, AddNodeResult({
|
|
95
|
+
this.verifyAddNodeResult(mrAggregated, AddNodeResult({networkPubkey: testNetworkPubkey}), badQuote, signature);
|
|
129
96
|
vm.stopPrank();
|
|
130
97
|
}
|
|
131
98
|
|
|
132
99
|
function testAddNodeInvalidNetworkPubkey() public {
|
|
133
|
-
(
|
|
134
|
-
|
|
135
|
-
,
|
|
136
|
-
,
|
|
137
|
-
bytes memory quote,
|
|
138
|
-
bytes memory signature,
|
|
139
|
-
bytes32 mrAggregated
|
|
140
|
-
) = successfulBootstrapResult();
|
|
100
|
+
(BootstrapResult memory bootstrapResult,,, bytes memory quote, bytes memory signature, bytes32 mrAggregated) =
|
|
101
|
+
successfulBootstrapResult();
|
|
141
102
|
vm.startPrank(this.owner());
|
|
142
|
-
this.
|
|
103
|
+
this.approveNewTeeVersion(mrAggregated);
|
|
143
104
|
this.verifyBootstrapResult(bootstrapResult, quote, signature);
|
|
144
105
|
vm.expectRevert(TEELifecycle.InvalidNetworkPubkey.selector);
|
|
145
|
-
this.verifyAddNodeResult(testMrAggregated, AddNodeResult({
|
|
106
|
+
this.verifyAddNodeResult(testMrAggregated, AddNodeResult({networkPubkey: hex"00"}), quote, signature);
|
|
146
107
|
vm.stopPrank();
|
|
147
108
|
}
|
|
148
109
|
|
|
149
110
|
function testAddNodeInvalidSignature() public {
|
|
150
|
-
(
|
|
151
|
-
|
|
152
|
-
,
|
|
153
|
-
,
|
|
154
|
-
bytes memory quote,
|
|
155
|
-
bytes memory signature,
|
|
156
|
-
bytes32 mrAggregated
|
|
157
|
-
) = successfulBootstrapResult();
|
|
111
|
+
(BootstrapResult memory bootstrapResult,,, bytes memory quote, bytes memory signature, bytes32 mrAggregated) =
|
|
112
|
+
successfulBootstrapResult();
|
|
158
113
|
vm.startPrank(this.owner());
|
|
159
|
-
this.
|
|
114
|
+
this.approveNewTeeVersion(mrAggregated);
|
|
160
115
|
this.verifyBootstrapResult(bootstrapResult, quote, signature);
|
|
161
116
|
|
|
162
|
-
(uint256 maliciousNewNodePrivkey,) = getLabeledKeyPair(
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
bytes memory badSignature = signAddNodeResult(
|
|
166
|
-
AddNodeResult({network_pubkey: testNetworkPubkey}),
|
|
167
|
-
maliciousNewNodePrivkey
|
|
168
|
-
);
|
|
117
|
+
(uint256 maliciousNewNodePrivkey,) = getLabeledKeyPair("maliciousNewNode");
|
|
118
|
+
bytes memory badSignature =
|
|
119
|
+
signAddNodeResult(AddNodeResult({networkPubkey: testNetworkPubkey}), maliciousNewNodePrivkey);
|
|
169
120
|
|
|
170
121
|
vm.expectRevert(TEELifecycle.InvalidEIP712Signature.selector);
|
|
171
|
-
this.verifyAddNodeResult(
|
|
122
|
+
this.verifyAddNodeResult(
|
|
123
|
+
testMrAggregated, AddNodeResult({networkPubkey: testNetworkPubkey}), quote, badSignature
|
|
124
|
+
);
|
|
172
125
|
vm.stopPrank();
|
|
173
126
|
}
|
|
174
127
|
|
|
@@ -184,9 +137,7 @@ contract TEELifecycleMockTest is Test, MockRemoteAttestation, TEELifecycle {
|
|
|
184
137
|
bytes32 mrAggregated
|
|
185
138
|
)
|
|
186
139
|
{
|
|
187
|
-
(bootstrapPartyPrivkey, bootstrapPartyAddress) = getLabeledKeyPair(
|
|
188
|
-
"bootstrapParty"
|
|
189
|
-
);
|
|
140
|
+
(bootstrapPartyPrivkey, bootstrapPartyAddress) = getLabeledKeyPair("bootstrapParty");
|
|
190
141
|
mrAggregated = testMrAggregated;
|
|
191
142
|
bootstrapResult = BootstrapResult({ecies_pubkey: testNetworkPubkey});
|
|
192
143
|
|
|
@@ -195,20 +146,23 @@ contract TEELifecycleMockTest is Test, MockRemoteAttestation, TEELifecycle {
|
|
|
195
146
|
}
|
|
196
147
|
|
|
197
148
|
// Helper function to sign the bootstrap result
|
|
198
|
-
function signBootstrapResult(
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
149
|
+
function signBootstrapResult(BootstrapResult memory bootstrapResult, uint256 privateKey)
|
|
150
|
+
internal
|
|
151
|
+
view
|
|
152
|
+
returns (bytes memory)
|
|
153
|
+
{
|
|
202
154
|
bytes32 bootstrapResultDigest = bootstrapResultDigest(bootstrapResult);
|
|
203
155
|
return getSignatureForDigest(bootstrapResultDigest, privateKey);
|
|
204
156
|
}
|
|
205
157
|
|
|
206
158
|
// Helper function to sign the add node result
|
|
207
|
-
function signAddNodeResult(
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
159
|
+
function signAddNodeResult(AddNodeResult memory addNodeResult, uint256 privateKey)
|
|
160
|
+
internal
|
|
161
|
+
view
|
|
162
|
+
returns (bytes memory)
|
|
163
|
+
{
|
|
211
164
|
bytes32 addNodeResultDigest = addNodeResultDigest(addNodeResult);
|
|
212
165
|
return getSignatureForDigest(addNodeResultDigest, privateKey);
|
|
213
166
|
}
|
|
167
|
+
|
|
214
168
|
}
|