@inco/lightning 0.4.0 → 0.5.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (110) hide show
  1. package/CHANGELOG.md +4 -0
  2. package/README.md +2 -0
  3. package/manifest.yaml +23 -0
  4. package/package.json +2 -5
  5. package/src/DeployUtils.sol +113 -77
  6. package/src/IIncoLightning.sol +16 -9
  7. package/src/IncoLightning.sol +18 -9
  8. package/src/IncoVerifier.sol +47 -0
  9. package/src/Lib.alphanet.sol +2 -15
  10. package/src/Lib.demonet.sol +2 -15
  11. package/src/Lib.devnet.sol +3 -16
  12. package/src/Lib.sol +3 -16
  13. package/src/Lib.template.sol +3 -44
  14. package/src/Lib.testnet.sol +2 -15
  15. package/src/Types.sol +7 -0
  16. package/src/interfaces/IIncoLightning.sol +20 -0
  17. package/src/interfaces/IIncoVerifier.sol +24 -0
  18. package/src/interfaces/automata-interfaces/BELE.sol +20 -0
  19. package/src/interfaces/automata-interfaces/IAutomataEnclaveIdentityDao.sol +28 -0
  20. package/src/interfaces/automata-interfaces/IFmspcTcbDao.sol +10 -0
  21. package/src/interfaces/automata-interfaces/IPCCSRouter.sol +94 -0
  22. package/src/interfaces/automata-interfaces/IPCCSRouterExtended.sol +10 -0
  23. package/src/interfaces/automata-interfaces/IPcsDao.sol +18 -0
  24. package/src/interfaces/automata-interfaces/IQuoteVerifier.sol +34 -0
  25. package/src/interfaces/automata-interfaces/Types.sol +193 -0
  26. package/src/libs/incoLightning_alphanet_v0_297966649.sol +2 -15
  27. package/src/libs/incoLightning_demonet_v0_863421733.sol +2 -15
  28. package/src/libs/incoLightning_devnet_v0_340846814.sol +2 -15
  29. package/src/libs/incoLightning_devnet_v1_887305889.sol +451 -0
  30. package/src/libs/incoLightning_testnet_v0_183408998.sol +2 -15
  31. package/src/libs/incoLightning_testnet_v1_938327937.sol +451 -0
  32. package/src/lightning-parts/AccessControl/AdvancedAccessControl.sol +133 -0
  33. package/src/lightning-parts/AccessControl/AdvancedAccessControl.types.sol +18 -0
  34. package/src/lightning-parts/AccessControl/BaseAccessControlList.sol +22 -2
  35. package/src/lightning-parts/AccessControl/interfaces/IAdvancedAccessControl.sol +25 -0
  36. package/src/lightning-parts/AccessControl/interfaces/IBaseAccessControlList.sol +24 -0
  37. package/src/lightning-parts/AccessControl/test/TestAdvancedAccessControl.t.sol +234 -0
  38. package/src/lightning-parts/AccessControl/test/TestBaseAccessControl.t.sol +4 -3
  39. package/src/lightning-parts/DecryptionAttester.sol +45 -0
  40. package/src/lightning-parts/DecryptionAttester.types.sol +7 -0
  41. package/src/lightning-parts/EncryptedInput.sol +8 -13
  42. package/src/lightning-parts/EncryptedOperations.sol +2 -2
  43. package/src/lightning-parts/TEELifecycle.sol +180 -88
  44. package/src/lightning-parts/TrivialEncryption.sol +8 -10
  45. package/src/lightning-parts/interfaces/IDecryptionAttester.sol +9 -0
  46. package/src/lightning-parts/interfaces/IEncryptedInput.sol +19 -0
  47. package/src/lightning-parts/interfaces/IEncryptedOperations.sol +31 -0
  48. package/src/lightning-parts/interfaces/ITEELifecycle.sol +26 -0
  49. package/src/lightning-parts/interfaces/ITrivialEncryption.sol +10 -0
  50. package/src/lightning-parts/primitives/EventCounter.sol +2 -2
  51. package/src/lightning-parts/primitives/HandleGeneration.sol +8 -3
  52. package/src/lightning-parts/primitives/HandleMetadata.sol +1 -1
  53. package/src/lightning-parts/primitives/LightningAddressGetter.sol +10 -0
  54. package/src/lightning-parts/primitives/SignatureVerifier.sol +2 -9
  55. package/src/lightning-parts/primitives/VerifierAddressGetter.sol +13 -0
  56. package/src/lightning-parts/primitives/{EventCounter.gen.sol → interfaces/IEventCounter.sol} +2 -2
  57. package/src/lightning-parts/primitives/interfaces/IHandleGeneration.sol +41 -0
  58. package/src/lightning-parts/primitives/interfaces/ISignatureVerifier.sol +9 -0
  59. package/src/lightning-parts/primitives/interfaces/IVerifierAddressGetter.sol +8 -0
  60. package/src/lightning-parts/test/HandleMetadata.t.sol +25 -6
  61. package/src/lightning-parts/test/TestDecryptionAttestationInSynchronousFlow.t.sol +78 -0
  62. package/src/periphery/SessionVerifier.sol +63 -0
  63. package/src/test/AddTwo.sol +18 -33
  64. package/src/test/FakeIncoInfra/FakeDecryptionAttester.sol +198 -0
  65. package/src/test/FakeIncoInfra/FakeIncoInfraBase.sol +0 -15
  66. package/src/test/FakeIncoInfra/FakeQuoteVerifier.sol +10 -6
  67. package/src/test/FakeIncoInfra/MockOpHandler.sol +0 -7
  68. package/src/test/FakeIncoInfra/MockRemoteAttestation.sol +19 -7
  69. package/src/test/FakeIncoInfra/getOpForSelector.sol +0 -3
  70. package/src/test/IncoTest.sol +12 -11
  71. package/src/test/TEELifecycle/TEELifecycleMockTest.t.sol +98 -77
  72. package/src/test/TestAddTwo.t.sol +16 -9
  73. package/src/test/TestFakeInfra.t.sol +10 -27
  74. package/src/test/TestUpgrade.t.sol +11 -4
  75. package/src/test/TestVersion.t.sol +0 -7
  76. package/src/version/IncoLightningConfig.sol +5 -4
  77. package/src/version/SessionVerifierConfig.sol +8 -0
  78. package/src/version/Version.sol +7 -9
  79. package/src/version/interfaces/IVersion.sol +8 -0
  80. package/src/DeployTEE.sol +0 -153
  81. package/src/IncoLightning.gen.sol +0 -15
  82. package/src/lightning-parts/AccessControl/BaseAccessControlList.gen.sol +0 -24
  83. package/src/lightning-parts/DecryptionHandler.gen.sol +0 -54
  84. package/src/lightning-parts/DecryptionHandler.sol +0 -307
  85. package/src/lightning-parts/DecryptionHandler.types.sol +0 -34
  86. package/src/lightning-parts/EncryptedInput.gen.sol +0 -16
  87. package/src/lightning-parts/EncryptedOperations.gen.sol +0 -59
  88. package/src/lightning-parts/TEELifecycle.gen.sol +0 -58
  89. package/src/lightning-parts/TrivialEncryption.gen.sol +0 -15
  90. package/src/lightning-parts/primitives/HandleGeneration.gen.sol +0 -19
  91. package/src/lightning-parts/primitives/HandleMetadata.gen.sol +0 -4
  92. package/src/lightning-parts/primitives/SignatureVerifier.gen.sol +0 -16
  93. package/src/test/FibonacciDecrypt.sol +0 -49
  94. package/src/test/TEELifecycle/TEELifecycleHWTest.t.sol +0 -119
  95. package/src/test/TEELifecycle/addnode_data/eoa.txt +0 -1
  96. package/src/test/TEELifecycle/addnode_data/quote.bin +0 -0
  97. package/src/test/TEELifecycle/bootstrap_data/ecies_pubkey.bin +0 -1
  98. package/src/test/TEELifecycle/bootstrap_data/eip712_signature.bin +0 -1
  99. package/src/test/TEELifecycle/bootstrap_data/eoa.txt +0 -1
  100. package/src/test/TEELifecycle/bootstrap_data/qe_identity +0 -1
  101. package/src/test/TEELifecycle/bootstrap_data/qe_identity_signature.bin +0 -1
  102. package/src/test/TEELifecycle/bootstrap_data/quote.bin +0 -0
  103. package/src/test/TEELifecycle/bootstrap_data/tcb_info +0 -1
  104. package/src/test/TEELifecycle/bootstrap_data/tcb_info_signature.bin +0 -1
  105. package/src/test/TEELifecycle/test_cert/AttestationReportSigningCA.crl +0 -0
  106. package/src/test/TEELifecycle/test_cert/Intel_SGX_Attestation_RootCA.cer +0 -0
  107. package/src/test/TEELifecycle/test_cert/Intel_SGX_PCK_CRL.crl +0 -0
  108. package/src/test/TEELifecycle/test_cert/Intel_SGX_PCK_PlatformCA.cer +0 -0
  109. package/src/test/TEELifecycle/test_cert/Intel_SGX_TCB_Signing.cer +0 -0
  110. package/src/version/Version.gen.sol +0 -14
@@ -0,0 +1,451 @@
1
+ // AUTOGENERATED FILE. DO NOT EDIT.
2
+ // This file was generated by the IncoLightning library generator.
3
+ // The original template is located at Lib.template.sol
4
+
5
+ /// SPDX-License-Identifier: No License
6
+ pragma solidity ^0.8;
7
+
8
+ import { IncoLightning } from "../IncoLightning.sol";
9
+ import { ebool, euint256, eaddress, ETypes } from "../Types.sol";
10
+
11
+ IncoLightning constant inco = IncoLightning(0xFb0Bd1a97DD2ECA4c7560b2a35d56474593f3Bab);
12
+ address constant deployedBy = 0x1804c8AB1F12E6bbf3894d4083f33e07309d1f38;
13
+
14
+ function typeOf(bytes32 handle) pure returns (ETypes) {
15
+ return ETypes(uint8(uint256(handle) >> 8));
16
+ }
17
+
18
+ library e {
19
+ function sanitize(euint256 a) internal returns (euint256) {
20
+ if (euint256.unwrap(a) == bytes32(0)) {
21
+ return asEuint256(0);
22
+ }
23
+ return a;
24
+ }
25
+
26
+ function sanitize(ebool a) internal returns (ebool) {
27
+ if (ebool.unwrap(a) == bytes32(0)) {
28
+ return asEbool(false);
29
+ }
30
+ return a;
31
+ }
32
+
33
+ function sanitize(eaddress a) internal returns (eaddress) {
34
+ if (eaddress.unwrap(a) == bytes32(0)) {
35
+ return asEaddress(address(0));
36
+ }
37
+ return a;
38
+ }
39
+
40
+ function s(euint256 a) internal returns (euint256) {
41
+ return sanitize(a);
42
+ }
43
+
44
+ function s(ebool a) internal returns (ebool) {
45
+ return sanitize(a);
46
+ }
47
+
48
+ function s(eaddress a) internal returns (eaddress) {
49
+ return sanitize(a);
50
+ }
51
+
52
+ function add(euint256 a, euint256 b) internal returns (euint256) {
53
+ return inco.eAdd(s(a), s(b));
54
+ }
55
+
56
+ function add(euint256 a, uint256 b) internal returns (euint256) {
57
+ return inco.eAdd(s(a), asEuint256(b));
58
+ }
59
+
60
+ function add(uint256 a, euint256 b) internal returns (euint256) {
61
+ return inco.eAdd(asEuint256(a), s(b));
62
+ }
63
+
64
+ function sub(euint256 a, euint256 b) internal returns (euint256) {
65
+ return inco.eSub(s(a), s(b));
66
+ }
67
+
68
+ function sub(euint256 a, uint256 b) internal returns (euint256) {
69
+ return inco.eSub(s(a), asEuint256(b));
70
+ }
71
+
72
+ function sub(uint256 a, euint256 b) internal returns (euint256) {
73
+ return inco.eSub(asEuint256(a), s(b));
74
+ }
75
+
76
+ function mul(euint256 a, euint256 b) internal returns (euint256) {
77
+ return inco.eMul(s(a), s(b));
78
+ }
79
+
80
+ function mul(euint256 a, uint256 b) internal returns (euint256) {
81
+ return inco.eMul(s(a), asEuint256(b));
82
+ }
83
+
84
+ function mul(uint256 a, euint256 b) internal returns (euint256) {
85
+ return inco.eMul(asEuint256(a), s(b));
86
+ }
87
+
88
+ function div(euint256 a, euint256 b) internal returns (euint256) {
89
+ return inco.eDiv(s(a), s(b));
90
+ }
91
+
92
+ function div(euint256 a, uint256 b) internal returns (euint256) {
93
+ return inco.eDiv(s(a), asEuint256(b));
94
+ }
95
+
96
+ function div(uint256 a, euint256 b) internal returns (euint256) {
97
+ return inco.eDiv(asEuint256(a), s(b));
98
+ }
99
+
100
+ function rem(euint256 a, euint256 b) internal returns (euint256) {
101
+ return inco.eRem(s(a), s(b));
102
+ }
103
+
104
+ function rem(euint256 a, uint256 b) internal returns (euint256) {
105
+ return inco.eRem(s(a), asEuint256(b));
106
+ }
107
+
108
+ function rem(uint256 a, euint256 b) internal returns (euint256) {
109
+ return inco.eRem(asEuint256(a), s(b));
110
+ }
111
+
112
+ function and(euint256 a, euint256 b) internal returns (euint256) {
113
+ return euint256.wrap(inco.eBitAnd(euint256.unwrap(s(a)), euint256.unwrap(s(b))));
114
+ }
115
+
116
+ function and(euint256 a, uint256 b) internal returns (euint256) {
117
+ return euint256.wrap(inco.eBitAnd(euint256.unwrap(s(a)), euint256.unwrap(asEuint256(b))));
118
+ }
119
+
120
+ function and(uint256 a, euint256 b) internal returns (euint256) {
121
+ return euint256.wrap(inco.eBitAnd(euint256.unwrap(asEuint256(a)), euint256.unwrap(s(b))));
122
+ }
123
+
124
+ function and(ebool a, ebool b) internal returns (ebool) {
125
+ return ebool.wrap(inco.eBitAnd(ebool.unwrap(s(a)), ebool.unwrap(s(b))));
126
+ }
127
+
128
+ function and(ebool a, bool b) internal returns (ebool) {
129
+ return ebool.wrap(inco.eBitAnd(ebool.unwrap(s(a)), ebool.unwrap(asEbool(b))));
130
+ }
131
+
132
+ function and(bool a, ebool b) internal returns (ebool) {
133
+ return ebool.wrap(inco.eBitAnd(ebool.unwrap(asEbool(a)), ebool.unwrap(s(b))));
134
+ }
135
+
136
+ function or(euint256 a, euint256 b) internal returns (euint256) {
137
+ return euint256.wrap(inco.eBitOr(euint256.unwrap(s(a)), euint256.unwrap(s(b))));
138
+ }
139
+
140
+ function or(euint256 a, uint256 b) internal returns (euint256) {
141
+ return euint256.wrap(inco.eBitOr(euint256.unwrap(s(a)), euint256.unwrap(asEuint256(b))));
142
+ }
143
+
144
+ function or(uint256 a, euint256 b) internal returns (euint256) {
145
+ return euint256.wrap(inco.eBitOr(euint256.unwrap(asEuint256(a)), euint256.unwrap(s(b))));
146
+ }
147
+
148
+ function or(ebool a, ebool b) internal returns (ebool) {
149
+ return ebool.wrap(inco.eBitOr(ebool.unwrap(s(a)), ebool.unwrap(s(b))));
150
+ }
151
+
152
+ function or(ebool a, bool b) internal returns (ebool) {
153
+ return ebool.wrap(inco.eBitOr(ebool.unwrap(s(a)), ebool.unwrap(asEbool(b))));
154
+ }
155
+
156
+ function or(bool a, ebool b) internal returns (ebool) {
157
+ return ebool.wrap(inco.eBitOr(ebool.unwrap(asEbool(a)), ebool.unwrap(s(b))));
158
+ }
159
+
160
+ function xor(euint256 a, euint256 b) internal returns (euint256) {
161
+ return euint256.wrap(inco.eBitXor(euint256.unwrap(s(a)), euint256.unwrap(s(b))));
162
+ }
163
+
164
+ function xor(euint256 a, uint256 b) internal returns (euint256) {
165
+ return euint256.wrap(inco.eBitXor(euint256.unwrap(s(a)), euint256.unwrap(asEuint256(b))));
166
+ }
167
+
168
+ function xor(uint256 a, euint256 b) internal returns (euint256) {
169
+ return euint256.wrap(inco.eBitXor(euint256.unwrap(asEuint256(a)), euint256.unwrap(s(b))));
170
+ }
171
+
172
+ function xor(ebool a, ebool b) internal returns (ebool) {
173
+ return ebool.wrap(inco.eBitXor(ebool.unwrap(s(a)), ebool.unwrap(s(b))));
174
+ }
175
+
176
+ function xor(ebool a, bool b) internal returns (ebool) {
177
+ return ebool.wrap(inco.eBitXor(ebool.unwrap(s(a)), ebool.unwrap(asEbool(b))));
178
+ }
179
+
180
+ function xor(bool a, ebool b) internal returns (ebool) {
181
+ return ebool.wrap(inco.eBitXor(ebool.unwrap(asEbool(a)), ebool.unwrap(s(b))));
182
+ }
183
+
184
+ function shl(euint256 a, euint256 b) internal returns (euint256) {
185
+ return inco.eShl(s(a), s(b));
186
+ }
187
+
188
+ function shl(euint256 a, uint256 b) internal returns (euint256) {
189
+ return inco.eShl(s(a), asEuint256(b));
190
+ }
191
+
192
+ function shl(uint256 a, euint256 b) internal returns (euint256) {
193
+ return inco.eShl(asEuint256(a), s(b));
194
+ }
195
+
196
+ function shr(euint256 a, euint256 b) internal returns (euint256) {
197
+ return inco.eShr(s(a), s(b));
198
+ }
199
+
200
+ function shr(euint256 a, uint256 b) internal returns (euint256) {
201
+ return inco.eShr(s(a), asEuint256(b));
202
+ }
203
+
204
+ function shr(uint256 a, euint256 b) internal returns (euint256) {
205
+ return inco.eShr(asEuint256(a), s(b));
206
+ }
207
+
208
+ function rotl(euint256 a, euint256 b) internal returns (euint256) {
209
+ return inco.eRotl(s(a), s(b));
210
+ }
211
+
212
+ function rotl(euint256 a, uint256 b) internal returns (euint256) {
213
+ return inco.eRotl(s(a), asEuint256(b));
214
+ }
215
+
216
+ function rotl(uint256 a, euint256 b) internal returns (euint256) {
217
+ return inco.eRotl(asEuint256(a), s(b));
218
+ }
219
+
220
+ function rotr(euint256 a, euint256 b) internal returns (euint256) {
221
+ return inco.eRotr(s(a), s(b));
222
+ }
223
+
224
+ function rotr(euint256 a, uint256 b) internal returns (euint256) {
225
+ return inco.eRotr(s(a), asEuint256(b));
226
+ }
227
+
228
+ function rotr(uint256 a, euint256 b) internal returns (euint256) {
229
+ return inco.eRotr(asEuint256(a), s(b));
230
+ }
231
+
232
+ function eq(euint256 a, euint256 b) internal returns (ebool) {
233
+ return inco.eEq(euint256.unwrap(s(a)), euint256.unwrap(s(b)));
234
+ }
235
+
236
+ function eq(euint256 a, uint256 b) internal returns (ebool) {
237
+ return inco.eEq(euint256.unwrap(s(a)), euint256.unwrap(asEuint256(b)));
238
+ }
239
+
240
+ function eq(uint256 a, euint256 b) internal returns (ebool) {
241
+ return inco.eEq(euint256.unwrap(asEuint256(a)), euint256.unwrap(s(b)));
242
+ }
243
+
244
+ function eq(eaddress a, address b) internal returns (ebool) {
245
+ return inco.eEq(eaddress.unwrap(s(a)), eaddress.unwrap(asEaddress(b)));
246
+ }
247
+
248
+ function eq(eaddress a, eaddress b) internal returns (ebool) {
249
+ return inco.eEq(eaddress.unwrap(s(a)), eaddress.unwrap(s(b)));
250
+ }
251
+
252
+ function eq(address a, eaddress b) internal returns (ebool) {
253
+ return inco.eEq(eaddress.unwrap(asEaddress(a)), eaddress.unwrap(s(b)));
254
+ }
255
+
256
+ function ne(euint256 a, euint256 b) internal returns (ebool) {
257
+ return inco.eNe(euint256.unwrap(s(a)), euint256.unwrap(s(b)));
258
+ }
259
+
260
+ function ne(euint256 a, uint256 b) internal returns (ebool) {
261
+ return inco.eNe(euint256.unwrap(s(a)), euint256.unwrap(asEuint256(b)));
262
+ }
263
+
264
+ function ne(uint256 a, euint256 b) internal returns (ebool) {
265
+ return inco.eNe(euint256.unwrap(asEuint256(a)), euint256.unwrap(s(b)));
266
+ }
267
+
268
+ function ne(eaddress a, eaddress b) internal returns (ebool) {
269
+ return inco.eNe(eaddress.unwrap(s(a)), eaddress.unwrap(s(b)));
270
+ }
271
+
272
+ function ne(eaddress a, address b) internal returns (ebool) {
273
+ return inco.eNe(eaddress.unwrap(s(a)), eaddress.unwrap(asEaddress(b)));
274
+ }
275
+
276
+ function ne(address a, eaddress b) internal returns (ebool) {
277
+ return inco.eNe(eaddress.unwrap(asEaddress(a)), eaddress.unwrap(s(b)));
278
+ }
279
+
280
+ function ge(euint256 a, euint256 b) internal returns (ebool) {
281
+ return inco.eGe(s(a), s(b));
282
+ }
283
+
284
+ function ge(euint256 a, uint256 b) internal returns (ebool) {
285
+ return inco.eGe(s(a), asEuint256(b));
286
+ }
287
+
288
+ function ge(uint256 a, euint256 b) internal returns (ebool) {
289
+ return inco.eGe(asEuint256(a), s(b));
290
+ }
291
+
292
+ function gt(euint256 a, euint256 b) internal returns (ebool) {
293
+ return inco.eGt(s(a), s(b));
294
+ }
295
+
296
+ function gt(euint256 a, uint256 b) internal returns (ebool) {
297
+ return inco.eGt(s(a), asEuint256(b));
298
+ }
299
+
300
+ function gt(uint256 a, euint256 b) internal returns (ebool) {
301
+ return inco.eGt(asEuint256(a), s(b));
302
+ }
303
+
304
+ function le(euint256 a, euint256 b) internal returns (ebool) {
305
+ return inco.eLe(s(a), s(b));
306
+ }
307
+
308
+ function le(euint256 a, uint256 b) internal returns (ebool) {
309
+ return inco.eLe(s(a), asEuint256(b));
310
+ }
311
+
312
+ function le(uint256 a, euint256 b) internal returns (ebool) {
313
+ return inco.eLe(asEuint256(a), s(b));
314
+ }
315
+
316
+ function lt(euint256 a, euint256 b) internal returns (ebool) {
317
+ return inco.eLt(s(a), s(b));
318
+ }
319
+
320
+ function lt(euint256 a, uint256 b) internal returns (ebool) {
321
+ return inco.eLt(s(a), asEuint256(b));
322
+ }
323
+
324
+ function lt(uint256 a, euint256 b) internal returns (ebool) {
325
+ return inco.eLt(asEuint256(a), s(b));
326
+ }
327
+
328
+ function min(euint256 a, euint256 b) internal returns (euint256) {
329
+ return inco.eMin(s(a), s(b));
330
+ }
331
+
332
+ function min(euint256 a, uint256 b) internal returns (euint256) {
333
+ return inco.eMin(s(a), asEuint256(b));
334
+ }
335
+
336
+ function min(uint256 a, euint256 b) internal returns (euint256) {
337
+ return inco.eMin(asEuint256(a), s(b));
338
+ }
339
+
340
+ function max(euint256 a, euint256 b) internal returns (euint256) {
341
+ return inco.eMax(s(a), s(b));
342
+ }
343
+
344
+ function max(euint256 a, uint256 b) internal returns (euint256) {
345
+ return inco.eMax(s(a), asEuint256(b));
346
+ }
347
+
348
+ function max(uint256 a, euint256 b) internal returns (euint256) {
349
+ return inco.eMax(asEuint256(a), s(b));
350
+ }
351
+
352
+ function not(ebool a) internal returns (ebool) {
353
+ return inco.eNot(s(a));
354
+ }
355
+
356
+ function rand() internal returns (euint256) {
357
+ return euint256.wrap(inco.eRand(ETypes.Uint256));
358
+ }
359
+
360
+ function randBounded(uint256 upperBound) internal returns (euint256) {
361
+ return euint256.wrap(inco.eRandBounded(euint256.unwrap(asEuint256(upperBound)), ETypes.Uint256));
362
+ }
363
+
364
+ function randBounded(euint256 upperBound) internal returns (euint256) {
365
+ return euint256.wrap(inco.eRandBounded(euint256.unwrap(s(upperBound)), ETypes.Uint256));
366
+ }
367
+
368
+ function asEuint256(uint256 a) internal returns (euint256) {
369
+ return inco.asEuint256(a);
370
+ }
371
+
372
+ function asEbool(bool a) internal returns (ebool) {
373
+ return inco.asEbool(a);
374
+ }
375
+
376
+ function asEaddress(address a) internal returns (eaddress) {
377
+ return inco.asEaddress(a);
378
+ }
379
+
380
+ function asEbool(euint256 a) internal returns (ebool) {
381
+ return ebool.wrap(inco.eCast(euint256.unwrap(a), ETypes.Bool));
382
+ }
383
+
384
+ function asEuint256(ebool a) internal returns (euint256) {
385
+ return euint256.wrap(inco.eCast(ebool.unwrap(a), ETypes.Uint256));
386
+ }
387
+
388
+ function newEuint256(bytes memory ciphertext, address user) internal returns (euint256) {
389
+ return inco.newEuint256(ciphertext, user);
390
+ }
391
+
392
+ function newEbool(bytes memory ciphertext, address user) internal returns (ebool) {
393
+ return inco.newEbool(ciphertext, user);
394
+ }
395
+
396
+ function newEaddress(bytes memory ciphertext, address user) internal returns (eaddress) {
397
+ return inco.newEaddress(ciphertext, user);
398
+ }
399
+
400
+ function allow(euint256 a, address to) internal {
401
+ inco.allow(euint256.unwrap(a), to);
402
+ }
403
+
404
+ function allow(ebool a, address to) internal {
405
+ inco.allow(ebool.unwrap(a), to);
406
+ }
407
+
408
+ function allow(eaddress a, address to) internal {
409
+ inco.allow(eaddress.unwrap(a), to);
410
+ }
411
+
412
+ function reveal(euint256 a) internal {
413
+ inco.reveal(euint256.unwrap(a));
414
+ }
415
+
416
+ function reveal(ebool a) internal {
417
+ inco.reveal(ebool.unwrap(a));
418
+ }
419
+
420
+ function reveal(eaddress a) internal {
421
+ inco.reveal(eaddress.unwrap(a));
422
+ }
423
+
424
+ function allowThis(euint256 a) internal {
425
+ allow(a, address(this));
426
+ }
427
+
428
+ function allowThis(ebool a) internal {
429
+ allow(a, address(this));
430
+ }
431
+
432
+ function allowThis(eaddress a) internal {
433
+ allow(a, address(this));
434
+ }
435
+
436
+ function isAllowed(address user, euint256 a) internal view returns (bool) {
437
+ return inco.isAllowed(euint256.unwrap(a), user);
438
+ }
439
+
440
+ function select(ebool control, euint256 ifTrue, euint256 ifFalse) internal returns (euint256) {
441
+ return euint256.wrap(inco.eIfThenElse(s(control), euint256.unwrap(s(ifTrue)), euint256.unwrap(s(ifFalse))));
442
+ }
443
+
444
+ function select(ebool control, ebool ifTrue, ebool ifFalse) internal returns (ebool) {
445
+ return ebool.wrap(inco.eIfThenElse(s(control), ebool.unwrap(s(ifTrue)), ebool.unwrap(s(ifFalse))));
446
+ }
447
+
448
+ function select(ebool control, eaddress ifTrue, eaddress ifFalse) internal returns (eaddress) {
449
+ return eaddress.wrap(inco.eIfThenElse(s(control), eaddress.unwrap(s(ifTrue)), eaddress.unwrap(s(ifFalse))));
450
+ }
451
+ }
@@ -0,0 +1,133 @@
1
+ // SPDX-License-Identifier: No License
2
+ pragma solidity ^0.8;
3
+
4
+ import {AllowanceVoucher, AllowanceProof} from "./AdvancedAccessControl.types.sol";
5
+ import {ALLOWANCE_GRANTED_MAGIC_VALUE} from "../../Types.sol";
6
+ import {EIP712Upgradeable} from "@openzeppelin/contracts-upgradeable/utils/cryptography/EIP712Upgradeable.sol";
7
+ import {IAdvancedAccessControl, IVoucherEip712Checker} from "./interfaces/IAdvancedAccessControl.sol";
8
+ import {SharerNotAllowedForHandle} from "../../Types.sol";
9
+ import {SignatureChecker} from "@openzeppelin/contracts/utils/cryptography/SignatureChecker.sol";
10
+ import {IBaseAccessControlList} from "./interfaces/IBaseAccessControlList.sol";
11
+ import {LightningAddressGetter} from "../primitives/LightningAddressGetter.sol";
12
+
13
+ abstract contract AdvancedAccessControlStorage {
14
+ struct AACStorage {
15
+ mapping(address => bytes32) activeVouchersSessionNonce; // initial session nonce is 0
16
+ }
17
+
18
+ bytes32 private constant AACStorageLocation =
19
+ keccak256("inco.storage.AdvancedAccessControl");
20
+
21
+ function getAACStorage() internal pure returns (AACStorage storage $) {
22
+ bytes32 loc = AACStorageLocation;
23
+ assembly {
24
+ $.slot := loc
25
+ }
26
+ }
27
+ }
28
+
29
+ abstract contract VoucherEip712Checker is IVoucherEip712Checker, EIP712Upgradeable {
30
+ bytes32 constant AllowanceVoucherStructHash =
31
+ keccak256(
32
+ "AllowanceVoucher(bytes32 sessionNonce,address verifyingContract,bytes4 callFunction,bytes sharerArgData)"
33
+ );
34
+
35
+ function allowanceVoucherDigest(
36
+ AllowanceVoucher memory voucher
37
+ ) public view returns (bytes32) {
38
+ return
39
+ _hashTypedDataV4(
40
+ keccak256(
41
+ abi.encode(
42
+ AllowanceVoucherStructHash,
43
+ voucher.sessionNonce,
44
+ voucher.verifyingContract,
45
+ voucher.callFunction,
46
+ keccak256(voucher.sharerArgData)
47
+ )
48
+ )
49
+ );
50
+ }
51
+ }
52
+
53
+ abstract contract AdvancedAccessControl is
54
+ IAdvancedAccessControl,
55
+ AdvancedAccessControlStorage,
56
+ VoucherEip712Checker,
57
+ LightningAddressGetter
58
+ {
59
+ using SignatureChecker for address;
60
+
61
+ error InvalidVoucherSignature(
62
+ address signer,
63
+ bytes32 digest,
64
+ bytes signature
65
+ );
66
+ error InvalidVoucherSessionNonce(
67
+ bytes32 providedSessionNonce,
68
+ bytes32 activeSessionNonce
69
+ );
70
+
71
+ /// @dev meant to for simulation, can't be a view function as it calls other contracts
72
+ /// @dev returns true if the account is allowed to access the handle, false or reverts otherwise
73
+ function isAllowedWithProof(
74
+ bytes32 handle,
75
+ address account,
76
+ AllowanceProof memory proof
77
+ ) public returns (bool) {
78
+ require(
79
+ IBaseAccessControlList(incoLightningAddress).isAllowed(handle, proof.sharer),
80
+ SharerNotAllowedForHandle(handle, proof.sharer)
81
+ );
82
+ bytes32 voucherDigest = allowanceVoucherDigest(proof.voucher);
83
+ require(
84
+ proof.sharer.isValidSignatureNow(
85
+ voucherDigest,
86
+ proof.voucherSignature
87
+ ),
88
+ InvalidVoucherSignature(
89
+ proof.sharer,
90
+ voucherDigest,
91
+ proof.voucherSignature
92
+ )
93
+ );
94
+ bytes32 sharerActiveVouchersSessionNonce = getActiveVouchersSessionNonce(
95
+ proof.sharer
96
+ );
97
+ require(
98
+ proof.voucher.sessionNonce == sharerActiveVouchersSessionNonce,
99
+ InvalidVoucherSessionNonce(
100
+ proof.voucher.sessionNonce,
101
+ sharerActiveVouchersSessionNonce
102
+ )
103
+ );
104
+ (bool success, bytes memory result) = proof
105
+ .voucher
106
+ .verifyingContract
107
+ .call(
108
+ abi.encodeWithSelector(
109
+ proof.voucher.callFunction,
110
+ handle,
111
+ account,
112
+ proof.voucher.sharerArgData,
113
+ proof.requesterArgData
114
+ )
115
+ );
116
+ return (success &&
117
+ result.length >= 32 &&
118
+ abi.decode(result, (bytes32)) == ALLOWANCE_GRANTED_MAGIC_VALUE);
119
+ }
120
+
121
+ function getActiveVouchersSessionNonce(
122
+ address account
123
+ ) public view returns (bytes32) {
124
+ return getAACStorage().activeVouchersSessionNonce[account];
125
+ }
126
+
127
+ /// @notice invalidates all previously signed vouchers
128
+ function updateActiveVouchersSessionNonce() external {
129
+ getAACStorage().activeVouchersSessionNonce[msg.sender] = keccak256(
130
+ abi.encodePacked(msg.sender, block.prevrandao)
131
+ );
132
+ }
133
+ }
@@ -0,0 +1,18 @@
1
+ // SPDX-License-Identifier: No License
2
+ pragma solidity ^0.8;
3
+
4
+ // can be for arbitrary handles to arbitrary accounts
5
+ // signed by the account sharing its read access
6
+ struct AllowanceVoucher {
7
+ bytes32 sessionNonce;
8
+ address verifyingContract;
9
+ bytes4 callFunction;
10
+ bytes sharerArgData;
11
+ }
12
+
13
+ struct AllowanceProof {
14
+ address sharer;
15
+ AllowanceVoucher voucher;
16
+ bytes voucherSignature;
17
+ bytes requesterArgData;
18
+ }
@@ -2,7 +2,9 @@
2
2
  pragma solidity ^0.8;
3
3
 
4
4
  import {SenderNotAllowedForHandle} from "../../Types.sol";
5
- import {IBaseAccessControlListGen} from "./BaseAccessControlList.gen.sol";
5
+ import {IBaseAccessControlList} from "./interfaces/IBaseAccessControlList.sol";
6
+ import {VerifierAddressGetter} from "../primitives/VerifierAddressGetter.sol";
7
+ import {AllowanceProof} from "../AccessControl/AdvancedAccessControl.types.sol";
6
8
 
7
9
  contract AccessControlListStorage {
8
10
  struct ACLStorage {
@@ -21,7 +23,13 @@ contract AccessControlListStorage {
21
23
  }
22
24
 
23
25
  // todo should add allowance events ?
24
- contract BaseAccessControlList is IBaseAccessControlListGen, AccessControlListStorage {
26
+ abstract contract BaseAccessControlList is IBaseAccessControlList, AccessControlListStorage, VerifierAddressGetter {
27
+ error ProofVerificationFailed(
28
+ address verifyingContract,
29
+ bytes4 callFunction,
30
+ bytes argData
31
+ );
32
+
25
33
  /// @dev persistent
26
34
  function allow(bytes32 handle, address account) public {
27
35
  require(
@@ -98,6 +106,18 @@ contract BaseAccessControlList is IBaseAccessControlListGen, AccessControlListSt
98
106
  }
99
107
  }
100
108
 
109
+ function claimHandle(bytes32 handle, AllowanceProof memory proof) public {
110
+ require(
111
+ incoVerifier.isAllowedWithProof(handle, msg.sender, proof),
112
+ ProofVerificationFailed(
113
+ proof.voucher.verifyingContract,
114
+ proof.voucher.callFunction,
115
+ proof.voucher.sharerArgData
116
+ )
117
+ );
118
+ allowInternal(handle, msg.sender);
119
+ }
120
+
101
121
  function persistAllowed(
102
122
  bytes32 handle,
103
123
  address account
@@ -0,0 +1,25 @@
1
+ // SPDX-License-Identifier: No License
2
+ pragma solidity ^0.8;
3
+
4
+ import {
5
+ AllowanceProof,
6
+ AllowanceVoucher
7
+ } from "../AdvancedAccessControl.types.sol";
8
+
9
+ interface IVoucherEip712Checker {
10
+ function allowanceVoucherDigest(
11
+ AllowanceVoucher memory voucher
12
+ ) external view returns (bytes32);
13
+ }
14
+
15
+ interface IAdvancedAccessControl is IVoucherEip712Checker {
16
+ function isAllowedWithProof(
17
+ bytes32 handle,
18
+ address account,
19
+ AllowanceProof memory proof
20
+ ) external returns (bool);
21
+ function getActiveVouchersSessionNonce(
22
+ address account
23
+ ) external view returns (bytes32);
24
+ function updateActiveVouchersSessionNonce() external;
25
+ }
@@ -0,0 +1,24 @@
1
+ // SPDX-License-Identifier: No License
2
+ pragma solidity ^0.8;
3
+
4
+ import {IVerifierAddressGetter} from "../../primitives/interfaces/IVerifierAddressGetter.sol";
5
+ import {AllowanceProof} from "../AdvancedAccessControl.types.sol";
6
+
7
+ interface IBaseAccessControlList is IVerifierAddressGetter {
8
+ function allow(bytes32 handle, address account) external;
9
+ function allowTransient(bytes32 handle, address account) external;
10
+ function allowedTransient(
11
+ bytes32 handle,
12
+ address account
13
+ ) external view returns (bool);
14
+ function cleanTransientStorage() external;
15
+ function persistAllowed(
16
+ bytes32 handle,
17
+ address account
18
+ ) external view returns (bool);
19
+ function isAllowed(
20
+ bytes32 handle,
21
+ address account
22
+ ) external view returns (bool);
23
+ function claimHandle(bytes32 handle, AllowanceProof memory proof) external;
24
+ }