@inco/lightning 0.6.8 → 0.7.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/CHANGELOG.md +6 -0
- package/README.md +29 -2
- package/manifest.yaml +35 -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.alphanet.sol +1 -1
- package/src/Lib.sol +1 -1
- package/src/Lib.template.sol +35 -153
- package/src/Types.sol +231 -97
- package/src/interfaces/IIncoLightning.sol +2 -0
- package/src/interfaces/IIncoVerifier.sol +6 -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_alphanet_v2_976644394.sol +478 -0
- 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 +39 -72
- 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 +44 -84
- 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 +96 -438
- package/src/lightning-parts/Fee.sol +3 -1
- package/src/lightning-parts/TEELifecycle.sol +94 -223
- 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 +154 -455
- package/src/pasted-dependencies/ICreateX.sol +55 -102
- package/src/periphery/SessionVerifier.sol +10 -8
- 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 +15 -13
- package/src/test/AddTwo.sol +9 -7
- package/src/test/FakeIncoInfra/FakeComputeServer.sol +11 -53
- package/src/test/FakeIncoInfra/FakeDecryptionAttester.sol +35 -119
- 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 +50 -21
- package/src/test/IncoTest.sol +22 -9
- package/src/test/OpsTest.sol +438 -0
- package/src/test/TEELifecycle/TEELifecycleMockTest.t.sol +57 -104
- package/src/test/TestAddTwo.t.sol +4 -3
- package/src/test/TestDeploy.t.sol +5 -6
- package/src/test/TestExtractDataOfEventTooLarge.t.sol +7 -9
- 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 +2 -2
- package/src/version/Version.sol +46 -48
- package/src/version/interfaces/IVersion.sol +6 -0
|
@@ -0,0 +1,478 @@
|
|
|
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(0xc0d693DeEF0A91CE39208676b6da09B822abd199);
|
|
12
|
+
address constant deployedBy = 0x8202D2D747784Cb7D48868E44C42C4bf162a70BC;
|
|
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
|
+
/// @dev costs the inco fee
|
|
357
|
+
function rand() internal returns (euint256) {
|
|
358
|
+
return euint256.wrap(inco.eRand{value: inco.getFee()}(ETypes.Uint256));
|
|
359
|
+
}
|
|
360
|
+
|
|
361
|
+
/// @dev costs the inco fee
|
|
362
|
+
function randBounded(uint256 upperBound) internal returns (euint256) {
|
|
363
|
+
return euint256.wrap(inco.eRandBounded{value: inco.getFee()}(euint256.unwrap(asEuint256(upperBound)), ETypes.Uint256));
|
|
364
|
+
}
|
|
365
|
+
|
|
366
|
+
/// @dev costs the inco fee
|
|
367
|
+
function randBounded(euint256 upperBound) internal returns (euint256) {
|
|
368
|
+
return euint256.wrap(inco.eRandBounded{value: inco.getFee()}(euint256.unwrap(s(upperBound)), ETypes.Uint256));
|
|
369
|
+
}
|
|
370
|
+
|
|
371
|
+
function asEuint256(uint256 a) internal returns (euint256) {
|
|
372
|
+
return inco.asEuint256(a);
|
|
373
|
+
}
|
|
374
|
+
|
|
375
|
+
function asEbool(bool a) internal returns (ebool) {
|
|
376
|
+
return inco.asEbool(a);
|
|
377
|
+
}
|
|
378
|
+
|
|
379
|
+
function asEaddress(address a) internal returns (eaddress) {
|
|
380
|
+
return inco.asEaddress(a);
|
|
381
|
+
}
|
|
382
|
+
|
|
383
|
+
function asEbool(euint256 a) internal returns (ebool) {
|
|
384
|
+
return ebool.wrap(inco.eCast(euint256.unwrap(a), ETypes.Bool));
|
|
385
|
+
}
|
|
386
|
+
|
|
387
|
+
function asEuint256(ebool a) internal returns (euint256) {
|
|
388
|
+
return euint256.wrap(inco.eCast(ebool.unwrap(a), ETypes.Uint256));
|
|
389
|
+
}
|
|
390
|
+
|
|
391
|
+
/// @notice Creates a new encrypted uint256 assuming msg.sender is the user
|
|
392
|
+
/// @dev costs the inco fee
|
|
393
|
+
function newEuint256(bytes memory ciphertext) internal returns (euint256) {
|
|
394
|
+
return newEuint256(ciphertext, msg.sender);
|
|
395
|
+
}
|
|
396
|
+
|
|
397
|
+
/// @notice Creates a new encrypted uint256 for the given user.
|
|
398
|
+
/// @dev costs the inco fee
|
|
399
|
+
function newEuint256(bytes memory ciphertext, address user) internal returns (euint256) {
|
|
400
|
+
return inco.newEuint256{value: inco.getFee()}(ciphertext, user);
|
|
401
|
+
}
|
|
402
|
+
|
|
403
|
+
/// @notice Creates a new encrypted bool assuming msg.sender is the user
|
|
404
|
+
/// @dev costs the inco fee
|
|
405
|
+
function newEbool(bytes memory ciphertext) internal returns (ebool) {
|
|
406
|
+
return newEbool(ciphertext, msg.sender);
|
|
407
|
+
}
|
|
408
|
+
|
|
409
|
+
/// @notice Creates a new encrypted bool for the given user.
|
|
410
|
+
/// @dev costs the inco fee
|
|
411
|
+
function newEbool(bytes memory ciphertext, address user) internal returns (ebool) {
|
|
412
|
+
return inco.newEbool{value: inco.getFee()}(ciphertext, user);
|
|
413
|
+
}
|
|
414
|
+
|
|
415
|
+
/// @notice Creates a new encrypted address assuming msg.sender is the user
|
|
416
|
+
/// @dev costs the inco fee
|
|
417
|
+
function newEaddress(bytes memory ciphertext) internal returns (eaddress) {
|
|
418
|
+
return newEaddress(ciphertext, msg.sender);
|
|
419
|
+
}
|
|
420
|
+
|
|
421
|
+
/// @notice Creates a new encrypted address for the given user.
|
|
422
|
+
/// @dev costs the inco fee
|
|
423
|
+
function newEaddress(bytes memory ciphertext, address user) internal returns (eaddress) {
|
|
424
|
+
return inco.newEaddress{value: inco.getFee()}(ciphertext, user);
|
|
425
|
+
}
|
|
426
|
+
|
|
427
|
+
function allow(euint256 a, address to) internal {
|
|
428
|
+
inco.allow(euint256.unwrap(a), to);
|
|
429
|
+
}
|
|
430
|
+
|
|
431
|
+
function allow(ebool a, address to) internal {
|
|
432
|
+
inco.allow(ebool.unwrap(a), to);
|
|
433
|
+
}
|
|
434
|
+
|
|
435
|
+
function allow(eaddress a, address to) internal {
|
|
436
|
+
inco.allow(eaddress.unwrap(a), to);
|
|
437
|
+
}
|
|
438
|
+
|
|
439
|
+
function reveal(euint256 a) internal {
|
|
440
|
+
inco.reveal(euint256.unwrap(a));
|
|
441
|
+
}
|
|
442
|
+
|
|
443
|
+
function reveal(ebool a) internal {
|
|
444
|
+
inco.reveal(ebool.unwrap(a));
|
|
445
|
+
}
|
|
446
|
+
|
|
447
|
+
function reveal(eaddress a) internal {
|
|
448
|
+
inco.reveal(eaddress.unwrap(a));
|
|
449
|
+
}
|
|
450
|
+
|
|
451
|
+
function allowThis(euint256 a) internal {
|
|
452
|
+
allow(a, address(this));
|
|
453
|
+
}
|
|
454
|
+
|
|
455
|
+
function allowThis(ebool a) internal {
|
|
456
|
+
allow(a, address(this));
|
|
457
|
+
}
|
|
458
|
+
|
|
459
|
+
function allowThis(eaddress a) internal {
|
|
460
|
+
allow(a, address(this));
|
|
461
|
+
}
|
|
462
|
+
|
|
463
|
+
function isAllowed(address user, euint256 a) internal view returns (bool) {
|
|
464
|
+
return inco.isAllowed(euint256.unwrap(a), user);
|
|
465
|
+
}
|
|
466
|
+
|
|
467
|
+
function select(ebool control, euint256 ifTrue, euint256 ifFalse) internal returns (euint256) {
|
|
468
|
+
return euint256.wrap(inco.eIfThenElse(s(control), euint256.unwrap(s(ifTrue)), euint256.unwrap(s(ifFalse))));
|
|
469
|
+
}
|
|
470
|
+
|
|
471
|
+
function select(ebool control, ebool ifTrue, ebool ifFalse) internal returns (ebool) {
|
|
472
|
+
return ebool.wrap(inco.eIfThenElse(s(control), ebool.unwrap(s(ifTrue)), ebool.unwrap(s(ifFalse))));
|
|
473
|
+
}
|
|
474
|
+
|
|
475
|
+
function select(ebool control, eaddress ifTrue, eaddress ifFalse) internal returns (eaddress) {
|
|
476
|
+
return eaddress.wrap(inco.eIfThenElse(s(control), eaddress.unwrap(s(ifTrue)), eaddress.unwrap(s(ifFalse))));
|
|
477
|
+
}
|
|
478
|
+
}
|
|
@@ -5,8 +5,8 @@
|
|
|
5
5
|
/// SPDX-License-Identifier: No License
|
|
6
6
|
pragma solidity ^0.8;
|
|
7
7
|
|
|
8
|
-
import {
|
|
9
|
-
import {
|
|
8
|
+
import {IncoLightning} from "../IncoLightning.sol";
|
|
9
|
+
import {ebool, euint256, eaddress, ETypes} from "../Types.sol";
|
|
10
10
|
|
|
11
11
|
IncoLightning constant inco = IncoLightning(0x7b98b0482099611B0ebEA0F98f81FF555406794A);
|
|
12
12
|
address constant deployedBy = 0x8202D2D747784Cb7D48868E44C42C4bf162a70BC;
|
|
@@ -16,6 +16,7 @@ function typeOf(bytes32 handle) pure returns (ETypes) {
|
|
|
16
16
|
}
|
|
17
17
|
|
|
18
18
|
library e {
|
|
19
|
+
|
|
19
20
|
function sanitize(euint256 a) internal returns (euint256) {
|
|
20
21
|
if (euint256.unwrap(a) == bytes32(0)) {
|
|
21
22
|
return asEuint256(0);
|
|
@@ -448,4 +449,5 @@ library e {
|
|
|
448
449
|
function select(ebool control, eaddress ifTrue, eaddress ifFalse) internal returns (eaddress) {
|
|
449
450
|
return eaddress.wrap(inco.eIfThenElse(s(control), eaddress.unwrap(s(ifTrue)), eaddress.unwrap(s(ifFalse))));
|
|
450
451
|
}
|
|
451
|
-
|
|
452
|
+
|
|
453
|
+
}
|
|
@@ -5,8 +5,8 @@
|
|
|
5
5
|
/// SPDX-License-Identifier: No License
|
|
6
6
|
pragma solidity ^0.8;
|
|
7
7
|
|
|
8
|
-
import {
|
|
9
|
-
import {
|
|
8
|
+
import {IncoLightning} from "../IncoLightning.sol";
|
|
9
|
+
import {ebool, euint256, eaddress, ETypes} from "../Types.sol";
|
|
10
10
|
|
|
11
11
|
IncoLightning constant inco = IncoLightning(0xFb0Bd1a97DD2ECA4c7560b2a35d56474593f3Bab);
|
|
12
12
|
address constant deployedBy = 0x1804c8AB1F12E6bbf3894d4083f33e07309d1f38;
|
|
@@ -16,6 +16,7 @@ function typeOf(bytes32 handle) pure returns (ETypes) {
|
|
|
16
16
|
}
|
|
17
17
|
|
|
18
18
|
library e {
|
|
19
|
+
|
|
19
20
|
function sanitize(euint256 a) internal returns (euint256) {
|
|
20
21
|
if (euint256.unwrap(a) == bytes32(0)) {
|
|
21
22
|
return asEuint256(0);
|
|
@@ -448,4 +449,5 @@ library e {
|
|
|
448
449
|
function select(ebool control, eaddress ifTrue, eaddress ifFalse) internal returns (eaddress) {
|
|
449
450
|
return eaddress.wrap(inco.eIfThenElse(s(control), eaddress.unwrap(s(ifTrue)), eaddress.unwrap(s(ifFalse))));
|
|
450
451
|
}
|
|
451
|
-
|
|
452
|
+
|
|
453
|
+
}
|
|
@@ -11,43 +11,42 @@ import {IBaseAccessControlList} from "./interfaces/IBaseAccessControlList.sol";
|
|
|
11
11
|
import {LightningAddressGetter} from "../primitives/LightningAddressGetter.sol";
|
|
12
12
|
|
|
13
13
|
abstract contract AdvancedAccessControlStorage {
|
|
14
|
-
|
|
14
|
+
|
|
15
|
+
struct AacStorage {
|
|
15
16
|
mapping(address => bytes32) activeVouchersSessionNonce; // initial session nonce is 0
|
|
16
17
|
}
|
|
17
18
|
|
|
18
|
-
bytes32 private constant
|
|
19
|
-
keccak256("inco.storage.AdvancedAccessControl");
|
|
19
|
+
bytes32 private constant AAC_STORAGE_LOCATION = keccak256("inco.storage.AdvancedAccessControl");
|
|
20
20
|
|
|
21
|
-
function
|
|
22
|
-
bytes32 loc =
|
|
21
|
+
function getAacStorage() internal pure returns (AacStorage storage $) {
|
|
22
|
+
bytes32 loc = AAC_STORAGE_LOCATION;
|
|
23
23
|
assembly {
|
|
24
24
|
$.slot := loc
|
|
25
25
|
}
|
|
26
26
|
}
|
|
27
|
+
|
|
27
28
|
}
|
|
28
|
-
|
|
29
|
+
|
|
29
30
|
abstract contract VoucherEip712Checker is IVoucherEip712Checker, EIP712Upgradeable {
|
|
30
|
-
bytes32 constant AllowanceVoucherStructHash =
|
|
31
|
-
keccak256(
|
|
32
|
-
"AllowanceVoucher(bytes32 sessionNonce,address verifyingContract,bytes4 callFunction,bytes sharerArgData)"
|
|
33
|
-
);
|
|
34
31
|
|
|
35
|
-
|
|
36
|
-
AllowanceVoucher
|
|
37
|
-
)
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
)
|
|
32
|
+
bytes32 constant ALLOWANCE_VOUCHER_STRUCT_HASH = keccak256(
|
|
33
|
+
"AllowanceVoucher(bytes32 sessionNonce,address verifyingContract,bytes4 callFunction,bytes sharerArgData)"
|
|
34
|
+
);
|
|
35
|
+
|
|
36
|
+
function allowanceVoucherDigest(AllowanceVoucher memory voucher) public view returns (bytes32) {
|
|
37
|
+
return _hashTypedDataV4(
|
|
38
|
+
keccak256(
|
|
39
|
+
abi.encode(
|
|
40
|
+
ALLOWANCE_VOUCHER_STRUCT_HASH,
|
|
41
|
+
voucher.sessionNonce,
|
|
42
|
+
voucher.verifyingContract,
|
|
43
|
+
voucher.callFunction,
|
|
44
|
+
keccak256(voucher.sharerArgData)
|
|
48
45
|
)
|
|
49
|
-
)
|
|
46
|
+
)
|
|
47
|
+
);
|
|
50
48
|
}
|
|
49
|
+
|
|
51
50
|
}
|
|
52
51
|
|
|
53
52
|
abstract contract AdvancedAccessControl is
|
|
@@ -56,78 +55,46 @@ abstract contract AdvancedAccessControl is
|
|
|
56
55
|
VoucherEip712Checker,
|
|
57
56
|
LightningAddressGetter
|
|
58
57
|
{
|
|
58
|
+
|
|
59
59
|
using SignatureChecker for address;
|
|
60
60
|
|
|
61
|
-
error InvalidVoucherSignature(
|
|
62
|
-
|
|
63
|
-
bytes32 digest,
|
|
64
|
-
bytes signature
|
|
65
|
-
);
|
|
66
|
-
error InvalidVoucherSessionNonce(
|
|
67
|
-
bytes32 providedSessionNonce,
|
|
68
|
-
bytes32 activeSessionNonce
|
|
69
|
-
);
|
|
61
|
+
error InvalidVoucherSignature(address signer, bytes32 digest, bytes signature);
|
|
62
|
+
error InvalidVoucherSessionNonce(bytes32 providedSessionNonce, bytes32 activeSessionNonce);
|
|
70
63
|
|
|
71
64
|
/// @dev meant to for simulation, can't be a view function as it calls other contracts
|
|
72
65
|
/// @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) {
|
|
66
|
+
function isAllowedWithProof(bytes32 handle, address account, AllowanceProof memory proof) public returns (bool) {
|
|
78
67
|
require(
|
|
79
68
|
IBaseAccessControlList(incoLightningAddress).isAllowed(handle, proof.sharer),
|
|
80
69
|
SharerNotAllowedForHandle(handle, proof.sharer)
|
|
81
70
|
);
|
|
82
71
|
bytes32 voucherDigest = allowanceVoucherDigest(proof.voucher);
|
|
83
72
|
require(
|
|
84
|
-
proof.sharer.isValidSignatureNow(
|
|
85
|
-
|
|
86
|
-
proof.voucherSignature
|
|
87
|
-
),
|
|
88
|
-
InvalidVoucherSignature(
|
|
89
|
-
proof.sharer,
|
|
90
|
-
voucherDigest,
|
|
91
|
-
proof.voucherSignature
|
|
92
|
-
)
|
|
73
|
+
proof.sharer.isValidSignatureNow(voucherDigest, proof.voucherSignature),
|
|
74
|
+
InvalidVoucherSignature(proof.sharer, voucherDigest, proof.voucherSignature)
|
|
93
75
|
);
|
|
94
|
-
bytes32 sharerActiveVouchersSessionNonce = getActiveVouchersSessionNonce(
|
|
95
|
-
proof.sharer
|
|
96
|
-
);
|
|
76
|
+
bytes32 sharerActiveVouchersSessionNonce = getActiveVouchersSessionNonce(proof.sharer);
|
|
97
77
|
require(
|
|
98
78
|
proof.voucher.sessionNonce == sharerActiveVouchersSessionNonce,
|
|
99
|
-
InvalidVoucherSessionNonce(
|
|
100
|
-
proof.voucher.sessionNonce,
|
|
101
|
-
sharerActiveVouchersSessionNonce
|
|
102
|
-
)
|
|
79
|
+
InvalidVoucherSessionNonce(proof.voucher.sessionNonce, sharerActiveVouchersSessionNonce)
|
|
103
80
|
);
|
|
104
|
-
(bool success, bytes memory result) = proof
|
|
105
|
-
.voucher
|
|
106
|
-
.verifyingContract
|
|
81
|
+
(bool success, bytes memory result) = proof.voucher.verifyingContract
|
|
107
82
|
.call(
|
|
108
83
|
abi.encodeWithSelector(
|
|
109
|
-
proof.voucher.callFunction,
|
|
110
|
-
handle,
|
|
111
|
-
account,
|
|
112
|
-
proof.voucher.sharerArgData,
|
|
113
|
-
proof.requesterArgData
|
|
84
|
+
proof.voucher.callFunction, handle, account, proof.voucher.sharerArgData, proof.requesterArgData
|
|
114
85
|
)
|
|
115
86
|
);
|
|
116
|
-
return (success &&
|
|
117
|
-
result.length >= 32 &&
|
|
118
|
-
abi.decode(result, (bytes32)) == ALLOWANCE_GRANTED_MAGIC_VALUE);
|
|
87
|
+
return (success && result.length >= 32 && abi.decode(result, (bytes32)) == ALLOWANCE_GRANTED_MAGIC_VALUE);
|
|
119
88
|
}
|
|
120
89
|
|
|
121
|
-
function getActiveVouchersSessionNonce(
|
|
122
|
-
|
|
123
|
-
) public view returns (bytes32) {
|
|
124
|
-
return getAACStorage().activeVouchersSessionNonce[account];
|
|
90
|
+
function getActiveVouchersSessionNonce(address account) public view returns (bytes32) {
|
|
91
|
+
return getAacStorage().activeVouchersSessionNonce[account];
|
|
125
92
|
}
|
|
126
93
|
|
|
127
94
|
/// @notice invalidates all previously signed vouchers
|
|
128
95
|
function updateActiveVouchersSessionNonce() external {
|
|
129
|
-
|
|
130
|
-
abi.encodePacked(msg.sender, block.prevrandao)
|
|
131
|
-
);
|
|
96
|
+
getAacStorage().activeVouchersSessionNonce[msg.sender] =
|
|
97
|
+
keccak256(abi.encodePacked(msg.sender, block.prevrandao));
|
|
132
98
|
}
|
|
99
|
+
|
|
133
100
|
}
|