@inco/lightning 0.1.20
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 +39 -0
- package/README.md +69 -0
- package/dumps/incoLightning_0_1_23__547622051.dump.json +1 -0
- package/dumps/incoLightning_0_1_23__547622051.env +15 -0
- package/dumps/incoLightning_0_1_23__830342853.dump.json +1 -0
- package/dumps/incoLightning_0_1_23__830342853.env +15 -0
- package/dumps/incoLightning_0_1_24__266705097.dump.json +1 -0
- package/dumps/incoLightning_0_1_24__266705097.env +15 -0
- package/dumps/incoLightning_0_1_25__986372984.dump.json +1 -0
- package/dumps/incoLightning_0_1_25__986372984.env +15 -0
- package/foundry.toml +20 -0
- package/package.json +27 -0
- package/remappings.txt +4 -0
- package/src/DeployUtils.sol +109 -0
- package/src/IncoLightning.sol +45 -0
- package/src/Lib.sol +389 -0
- package/src/Lib.template.sol +464 -0
- package/src/Types.sol +74 -0
- package/src/libs/incoLightning_0_1_22__761766708.sol +389 -0
- package/src/libs/incoLightning_0_1_23__547622051.sol +389 -0
- package/src/libs/incoLightning_0_1_23__830342853.sol +389 -0
- package/src/libs/incoLightning_0_1_24__266705097.sol +389 -0
- package/src/libs/incoLightning_0_1_25__986372984.sol +389 -0
- package/src/lightning-parts/AccessControl/BaseAccessControlList.sol +105 -0
- package/src/lightning-parts/AccessControl/test/TestBaseAccessControl.t.sol +12 -0
- package/src/lightning-parts/DecryptionHandler.sol +164 -0
- package/src/lightning-parts/EncryptedInput.sol +61 -0
- package/src/lightning-parts/EncryptedOperations.sol +610 -0
- package/src/lightning-parts/TrivialEncryption.sol +43 -0
- package/src/lightning-parts/primitives/EventCounter.sol +32 -0
- package/src/lightning-parts/primitives/HandleGeneration.sol +107 -0
- package/src/lightning-parts/primitives/HandleMetadata.sol +38 -0
- package/src/lightning-parts/primitives/SignatureVerifier.sol +47 -0
- package/src/lightning-parts/test/HandleMetadata.t.sol +87 -0
- package/src/pasted-dependencies/CreateX.sol +1293 -0
- package/src/pasted-dependencies/ICreateX.sol +187 -0
- package/src/test/AddTwo.sol +48 -0
- package/src/test/FakeIncoInfra/FakeComputeServer.sol +137 -0
- package/src/test/FakeIncoInfra/FakeIncoInfraBase.sol +77 -0
- package/src/test/FakeIncoInfra/KVStore.sol +35 -0
- package/src/test/FakeIncoInfra/MockOpHandler.sol +140 -0
- package/src/test/FakeIncoInfra/getOpForSelector.sol +71 -0
- package/src/test/IncoTest.sol +48 -0
- package/src/test/TestAddTwo.t.sol +31 -0
- package/src/test/TestDeploy.t.sol +39 -0
- package/src/test/TestExtractDataOfEventTooLarge.t.sol +43 -0
- package/src/test/TestFakeInfra.t.sol +301 -0
- package/src/test/TestVersion.t.sol +36 -0
- package/src/version/IncoLightningConfig.sol +13 -0
- package/src/version/Version.sol +76 -0
|
@@ -0,0 +1,464 @@
|
|
|
1
|
+
// Edit this file to automatically alter generated libraries
|
|
2
|
+
// SPDX-License-Identifier: No License
|
|
3
|
+
pragma solidity ^0.8;
|
|
4
|
+
|
|
5
|
+
import "./IncoLightning.sol";
|
|
6
|
+
import {ebool, euint256, ETypes} from "./Types.sol";
|
|
7
|
+
|
|
8
|
+
IncoLightning constant inco = IncoLightning(
|
|
9
|
+
0x000000000000000000000000000000000000baBe
|
|
10
|
+
);
|
|
11
|
+
address constant deployedBy = 0x000000000000000000000000000000000000baBe;
|
|
12
|
+
|
|
13
|
+
uint256 constant defaultDecryptionDelayLimit = 2 hours;
|
|
14
|
+
|
|
15
|
+
library e {
|
|
16
|
+
function sanitize(euint256 a) internal returns (euint256) {
|
|
17
|
+
if (euint256.unwrap(a) == bytes32(0)) {
|
|
18
|
+
return asEuint256(0);
|
|
19
|
+
}
|
|
20
|
+
return a;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
function sanitize(ebool a) internal returns (ebool) {
|
|
24
|
+
if (ebool.unwrap(a) == bytes32(0)) {
|
|
25
|
+
return asEbool(false);
|
|
26
|
+
}
|
|
27
|
+
return a;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
function s(euint256 a) internal returns (euint256) {
|
|
31
|
+
return sanitize(a);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
function s(ebool a) internal returns (ebool) {
|
|
35
|
+
return sanitize(a);
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
function add(euint256 a, euint256 b) internal returns (euint256) {
|
|
39
|
+
return inco.eAdd(s(a), s(b));
|
|
40
|
+
}
|
|
41
|
+
function add(euint256 a, uint256 b) internal returns (euint256) {
|
|
42
|
+
return inco.eAdd(s(a), asEuint256(b));
|
|
43
|
+
}
|
|
44
|
+
function add(uint256 a, euint256 b) internal returns (euint256) {
|
|
45
|
+
return inco.eAdd(asEuint256(a), s(b));
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
function sub(euint256 a, euint256 b) internal returns (euint256) {
|
|
49
|
+
return inco.eSub(s(a), s(b));
|
|
50
|
+
}
|
|
51
|
+
function sub(euint256 a, uint256 b) internal returns (euint256) {
|
|
52
|
+
return inco.eSub(s(a), asEuint256(b));
|
|
53
|
+
}
|
|
54
|
+
function sub(uint256 a, euint256 b) internal returns (euint256) {
|
|
55
|
+
return inco.eSub(asEuint256(a), s(b));
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
function mul(euint256 a, euint256 b) internal returns (euint256) {
|
|
59
|
+
return inco.eMul(s(a), s(b));
|
|
60
|
+
}
|
|
61
|
+
function mul(euint256 a, uint256 b) internal returns (euint256) {
|
|
62
|
+
return inco.eMul(s(a), asEuint256(b));
|
|
63
|
+
}
|
|
64
|
+
function mul(uint256 a, euint256 b) internal returns (euint256) {
|
|
65
|
+
return inco.eMul(asEuint256(a), s(b));
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
function div(euint256 a, euint256 b) internal returns (euint256) {
|
|
69
|
+
return inco.eDiv(s(a), s(b));
|
|
70
|
+
}
|
|
71
|
+
function div(euint256 a, uint256 b) internal returns (euint256) {
|
|
72
|
+
return inco.eDiv(s(a), asEuint256(b));
|
|
73
|
+
}
|
|
74
|
+
function div(uint256 a, euint256 b) internal returns (euint256) {
|
|
75
|
+
return inco.eDiv(asEuint256(a), s(b));
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
function rem(euint256 a, euint256 b) internal returns (euint256) {
|
|
79
|
+
return inco.eRem(s(a), s(b));
|
|
80
|
+
}
|
|
81
|
+
function rem(euint256 a, uint256 b) internal returns (euint256) {
|
|
82
|
+
return inco.eRem(s(a), asEuint256(b));
|
|
83
|
+
}
|
|
84
|
+
function rem(uint256 a, euint256 b) internal returns (euint256) {
|
|
85
|
+
return inco.eRem(asEuint256(a), s(b));
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
function and(euint256 a, euint256 b) internal returns (euint256) {
|
|
89
|
+
return
|
|
90
|
+
euint256.wrap(
|
|
91
|
+
inco.eBitAnd(euint256.unwrap(s(a)), euint256.unwrap(s(b)))
|
|
92
|
+
);
|
|
93
|
+
}
|
|
94
|
+
function and(euint256 a, uint256 b) internal returns (euint256) {
|
|
95
|
+
return
|
|
96
|
+
euint256.wrap(
|
|
97
|
+
inco.eBitAnd(
|
|
98
|
+
euint256.unwrap(s(a)),
|
|
99
|
+
euint256.unwrap(asEuint256(b))
|
|
100
|
+
)
|
|
101
|
+
);
|
|
102
|
+
}
|
|
103
|
+
function and(uint256 a, euint256 b) internal returns (euint256) {
|
|
104
|
+
return
|
|
105
|
+
euint256.wrap(
|
|
106
|
+
inco.eBitAnd(
|
|
107
|
+
euint256.unwrap(asEuint256(a)),
|
|
108
|
+
euint256.unwrap(s(b))
|
|
109
|
+
)
|
|
110
|
+
);
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
function and(ebool a, ebool b) internal returns (ebool) {
|
|
114
|
+
return ebool.wrap(inco.eBitAnd(ebool.unwrap(s(a)), ebool.unwrap(s(b))));
|
|
115
|
+
}
|
|
116
|
+
function and(ebool a, bool b) internal returns (ebool) {
|
|
117
|
+
return
|
|
118
|
+
ebool.wrap(
|
|
119
|
+
inco.eBitAnd(ebool.unwrap(s(a)), ebool.unwrap(asEbool(b)))
|
|
120
|
+
);
|
|
121
|
+
}
|
|
122
|
+
function and(bool a, ebool b) internal returns (ebool) {
|
|
123
|
+
return
|
|
124
|
+
ebool.wrap(
|
|
125
|
+
inco.eBitAnd(ebool.unwrap(asEbool(a)), ebool.unwrap(s(b)))
|
|
126
|
+
);
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
function or(euint256 a, euint256 b) internal returns (euint256) {
|
|
130
|
+
return
|
|
131
|
+
euint256.wrap(
|
|
132
|
+
inco.eBitOr(euint256.unwrap(s(a)), euint256.unwrap(s(b)))
|
|
133
|
+
);
|
|
134
|
+
}
|
|
135
|
+
function or(euint256 a, uint256 b) internal returns (euint256) {
|
|
136
|
+
return
|
|
137
|
+
euint256.wrap(
|
|
138
|
+
inco.eBitOr(
|
|
139
|
+
euint256.unwrap(s(a)),
|
|
140
|
+
euint256.unwrap(asEuint256(b))
|
|
141
|
+
)
|
|
142
|
+
);
|
|
143
|
+
}
|
|
144
|
+
function or(uint256 a, euint256 b) internal returns (euint256) {
|
|
145
|
+
return
|
|
146
|
+
euint256.wrap(
|
|
147
|
+
inco.eBitOr(
|
|
148
|
+
euint256.unwrap(asEuint256(a)),
|
|
149
|
+
euint256.unwrap(s(b))
|
|
150
|
+
)
|
|
151
|
+
);
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
function or(ebool a, ebool b) internal returns (ebool) {
|
|
155
|
+
return ebool.wrap(inco.eBitOr(ebool.unwrap(s(a)), ebool.unwrap(s(b))));
|
|
156
|
+
}
|
|
157
|
+
function or(ebool a, bool b) internal returns (ebool) {
|
|
158
|
+
return
|
|
159
|
+
ebool.wrap(
|
|
160
|
+
inco.eBitOr(ebool.unwrap(s(a)), ebool.unwrap(asEbool(b)))
|
|
161
|
+
);
|
|
162
|
+
}
|
|
163
|
+
function or(bool a, ebool b) internal returns (ebool) {
|
|
164
|
+
return
|
|
165
|
+
ebool.wrap(
|
|
166
|
+
inco.eBitOr(ebool.unwrap(asEbool(a)), ebool.unwrap(s(b)))
|
|
167
|
+
);
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
function xor(euint256 a, euint256 b) internal returns (euint256) {
|
|
171
|
+
return
|
|
172
|
+
euint256.wrap(
|
|
173
|
+
inco.eBitXor(euint256.unwrap(s(a)), euint256.unwrap(s(b)))
|
|
174
|
+
);
|
|
175
|
+
}
|
|
176
|
+
function xor(euint256 a, uint256 b) internal returns (euint256) {
|
|
177
|
+
return
|
|
178
|
+
euint256.wrap(
|
|
179
|
+
inco.eBitXor(
|
|
180
|
+
euint256.unwrap(s(a)),
|
|
181
|
+
euint256.unwrap(asEuint256(b))
|
|
182
|
+
)
|
|
183
|
+
);
|
|
184
|
+
}
|
|
185
|
+
function xor(uint256 a, euint256 b) internal returns (euint256) {
|
|
186
|
+
return
|
|
187
|
+
euint256.wrap(
|
|
188
|
+
inco.eBitXor(
|
|
189
|
+
euint256.unwrap(asEuint256(a)),
|
|
190
|
+
euint256.unwrap(s(b))
|
|
191
|
+
)
|
|
192
|
+
);
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
function xor(ebool a, ebool b) internal returns (ebool) {
|
|
196
|
+
return ebool.wrap(inco.eBitXor(ebool.unwrap(s(a)), ebool.unwrap(s(b))));
|
|
197
|
+
}
|
|
198
|
+
function xor(ebool a, bool b) internal returns (ebool) {
|
|
199
|
+
return
|
|
200
|
+
ebool.wrap(
|
|
201
|
+
inco.eBitXor(ebool.unwrap(s(a)), ebool.unwrap(asEbool(b)))
|
|
202
|
+
);
|
|
203
|
+
}
|
|
204
|
+
function xor(bool a, ebool b) internal returns (ebool) {
|
|
205
|
+
return
|
|
206
|
+
ebool.wrap(
|
|
207
|
+
inco.eBitXor(ebool.unwrap(asEbool(a)), ebool.unwrap(s(b)))
|
|
208
|
+
);
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
function shl(euint256 a, euint256 b) internal returns (euint256) {
|
|
212
|
+
return inco.eShl(s(a), s(b));
|
|
213
|
+
}
|
|
214
|
+
function shl(euint256 a, uint256 b) internal returns (euint256) {
|
|
215
|
+
return inco.eShl(s(a), asEuint256(b));
|
|
216
|
+
}
|
|
217
|
+
function shl(uint256 a, euint256 b) internal returns (euint256) {
|
|
218
|
+
return inco.eShl(asEuint256(a), s(b));
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
function shr(euint256 a, euint256 b) internal returns (euint256) {
|
|
222
|
+
return inco.eShr(s(a), s(b));
|
|
223
|
+
}
|
|
224
|
+
function shr(euint256 a, uint256 b) internal returns (euint256) {
|
|
225
|
+
return inco.eShr(s(a), asEuint256(b));
|
|
226
|
+
}
|
|
227
|
+
function shr(uint256 a, euint256 b) internal returns (euint256) {
|
|
228
|
+
return inco.eShr(asEuint256(a), s(b));
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
function rotl(euint256 a, euint256 b) internal returns (euint256) {
|
|
232
|
+
return inco.eRotl(s(a), s(b));
|
|
233
|
+
}
|
|
234
|
+
function rotl(euint256 a, uint256 b) internal returns (euint256) {
|
|
235
|
+
return inco.eRotl(s(a), asEuint256(b));
|
|
236
|
+
}
|
|
237
|
+
function rotl(uint256 a, euint256 b) internal returns (euint256) {
|
|
238
|
+
return inco.eRotl(asEuint256(a), s(b));
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
function rotr(euint256 a, euint256 b) internal returns (euint256) {
|
|
242
|
+
return inco.eRotr(s(a), s(b));
|
|
243
|
+
}
|
|
244
|
+
function rotr(euint256 a, uint256 b) internal returns (euint256) {
|
|
245
|
+
return inco.eRotr(s(a), asEuint256(b));
|
|
246
|
+
}
|
|
247
|
+
function rotr(uint256 a, euint256 b) internal returns (euint256) {
|
|
248
|
+
return inco.eRotr(asEuint256(a), s(b));
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
function eq(euint256 a, euint256 b) internal returns (ebool) {
|
|
252
|
+
return inco.eEq(s(a), s(b));
|
|
253
|
+
}
|
|
254
|
+
function eq(euint256 a, uint256 b) internal returns (ebool) {
|
|
255
|
+
return inco.eEq(s(a), asEuint256(b));
|
|
256
|
+
}
|
|
257
|
+
function eq(uint256 a, euint256 b) internal returns (ebool) {
|
|
258
|
+
return inco.eEq(asEuint256(a), s(b));
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
function ne(euint256 a, euint256 b) internal returns (ebool) {
|
|
262
|
+
return inco.eNe(s(a), s(b));
|
|
263
|
+
}
|
|
264
|
+
function ne(euint256 a, uint256 b) internal returns (ebool) {
|
|
265
|
+
return inco.eNe(s(a), asEuint256(b));
|
|
266
|
+
}
|
|
267
|
+
function ne(uint256 a, euint256 b) internal returns (ebool) {
|
|
268
|
+
return inco.eNe(asEuint256(a), s(b));
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
function ge(euint256 a, euint256 b) internal returns (ebool) {
|
|
272
|
+
return inco.eGe(s(a), s(b));
|
|
273
|
+
}
|
|
274
|
+
function ge(euint256 a, uint256 b) internal returns (ebool) {
|
|
275
|
+
return inco.eGe(s(a), asEuint256(b));
|
|
276
|
+
}
|
|
277
|
+
function ge(uint256 a, euint256 b) internal returns (ebool) {
|
|
278
|
+
return inco.eGe(asEuint256(a), s(b));
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
function gt(euint256 a, euint256 b) internal returns (ebool) {
|
|
282
|
+
return inco.eGt(s(a), s(b));
|
|
283
|
+
}
|
|
284
|
+
function gt(euint256 a, uint256 b) internal returns (ebool) {
|
|
285
|
+
return inco.eGt(s(a), asEuint256(b));
|
|
286
|
+
}
|
|
287
|
+
function gt(uint256 a, euint256 b) internal returns (ebool) {
|
|
288
|
+
return inco.eGt(asEuint256(a), s(b));
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
function le(euint256 a, euint256 b) internal returns (ebool) {
|
|
292
|
+
return inco.eLe(s(a), s(b));
|
|
293
|
+
}
|
|
294
|
+
function le(euint256 a, uint256 b) internal returns (ebool) {
|
|
295
|
+
return inco.eLe(s(a), asEuint256(b));
|
|
296
|
+
}
|
|
297
|
+
function le(uint256 a, euint256 b) internal returns (ebool) {
|
|
298
|
+
return inco.eLe(asEuint256(a), s(b));
|
|
299
|
+
}
|
|
300
|
+
|
|
301
|
+
function lt(euint256 a, euint256 b) internal returns (ebool) {
|
|
302
|
+
return inco.eLt(s(a), s(b));
|
|
303
|
+
}
|
|
304
|
+
function lt(euint256 a, uint256 b) internal returns (ebool) {
|
|
305
|
+
return inco.eLt(s(a), asEuint256(b));
|
|
306
|
+
}
|
|
307
|
+
function lt(uint256 a, euint256 b) internal returns (ebool) {
|
|
308
|
+
return inco.eLt(asEuint256(a), s(b));
|
|
309
|
+
}
|
|
310
|
+
|
|
311
|
+
function min(euint256 a, euint256 b) internal returns (euint256) {
|
|
312
|
+
return inco.eMin(s(a), s(b));
|
|
313
|
+
}
|
|
314
|
+
function min(euint256 a, uint256 b) internal returns (euint256) {
|
|
315
|
+
return inco.eMin(s(a), asEuint256(b));
|
|
316
|
+
}
|
|
317
|
+
function min(uint256 a, euint256 b) internal returns (euint256) {
|
|
318
|
+
return inco.eMin(asEuint256(a), s(b));
|
|
319
|
+
}
|
|
320
|
+
|
|
321
|
+
function max(euint256 a, euint256 b) internal returns (euint256) {
|
|
322
|
+
return inco.eMax(s(a), s(b));
|
|
323
|
+
}
|
|
324
|
+
function max(euint256 a, uint256 b) internal returns (euint256) {
|
|
325
|
+
return inco.eMax(s(a), asEuint256(b));
|
|
326
|
+
}
|
|
327
|
+
function max(uint256 a, euint256 b) internal returns (euint256) {
|
|
328
|
+
return inco.eMax(asEuint256(a), s(b));
|
|
329
|
+
}
|
|
330
|
+
|
|
331
|
+
function not(ebool a) internal returns (ebool) {
|
|
332
|
+
return inco.eNot(s(a));
|
|
333
|
+
}
|
|
334
|
+
|
|
335
|
+
function rand() internal returns (euint256) {
|
|
336
|
+
return euint256.wrap(inco.eRand(ETypes.Uint256));
|
|
337
|
+
}
|
|
338
|
+
|
|
339
|
+
function randBounded(uint256 upperBound) internal returns (euint256) {
|
|
340
|
+
return
|
|
341
|
+
euint256.wrap(
|
|
342
|
+
inco.eRandBounded(
|
|
343
|
+
euint256.unwrap(asEuint256(upperBound)),
|
|
344
|
+
ETypes.Uint256
|
|
345
|
+
)
|
|
346
|
+
);
|
|
347
|
+
}
|
|
348
|
+
|
|
349
|
+
function randBounded(euint256 upperBound) internal returns (euint256) {
|
|
350
|
+
return
|
|
351
|
+
euint256.wrap(
|
|
352
|
+
inco.eRandBounded(
|
|
353
|
+
euint256.unwrap(s(upperBound)),
|
|
354
|
+
ETypes.Uint256
|
|
355
|
+
)
|
|
356
|
+
);
|
|
357
|
+
}
|
|
358
|
+
|
|
359
|
+
function asEuint256(uint256 a) internal returns (euint256) {
|
|
360
|
+
return inco.asEuint256(a);
|
|
361
|
+
}
|
|
362
|
+
|
|
363
|
+
function asEbool(bool a) internal returns (ebool) {
|
|
364
|
+
return inco.asEbool(a);
|
|
365
|
+
}
|
|
366
|
+
|
|
367
|
+
function asEbool(euint256 a) internal returns (ebool) {
|
|
368
|
+
return ebool.wrap(inco.eCast(euint256.unwrap(a), ETypes.Bool));
|
|
369
|
+
}
|
|
370
|
+
|
|
371
|
+
function asEuint256(ebool a) internal returns (euint256) {
|
|
372
|
+
return euint256.wrap(inco.eCast(ebool.unwrap(a), ETypes.Uint256));
|
|
373
|
+
}
|
|
374
|
+
|
|
375
|
+
function newEuint256(
|
|
376
|
+
bytes memory ciphertext,
|
|
377
|
+
address user
|
|
378
|
+
) internal returns (euint256) {
|
|
379
|
+
return inco.newEuint256(ciphertext, user);
|
|
380
|
+
}
|
|
381
|
+
|
|
382
|
+
function newEbool(
|
|
383
|
+
bytes memory ciphertext,
|
|
384
|
+
address user
|
|
385
|
+
) internal returns (ebool) {
|
|
386
|
+
return inco.newEbool(ciphertext, user);
|
|
387
|
+
}
|
|
388
|
+
|
|
389
|
+
function allow(euint256 a, address to) internal {
|
|
390
|
+
inco.allow(euint256.unwrap(a), to);
|
|
391
|
+
}
|
|
392
|
+
|
|
393
|
+
function allow(ebool a, address to) internal {
|
|
394
|
+
inco.allow(ebool.unwrap(a), to);
|
|
395
|
+
}
|
|
396
|
+
|
|
397
|
+
function allowThis(euint256 a) internal {
|
|
398
|
+
allow(a, address(this));
|
|
399
|
+
}
|
|
400
|
+
|
|
401
|
+
function allowThis(ebool a) internal {
|
|
402
|
+
allow(a, address(this));
|
|
403
|
+
}
|
|
404
|
+
|
|
405
|
+
function isAllowed(address user, euint256 a) internal view returns (bool) {
|
|
406
|
+
return inco.isAllowed(euint256.unwrap(a), user);
|
|
407
|
+
}
|
|
408
|
+
|
|
409
|
+
function select(
|
|
410
|
+
ebool control,
|
|
411
|
+
euint256 ifTrue,
|
|
412
|
+
euint256 ifFalse
|
|
413
|
+
) internal returns (euint256) {
|
|
414
|
+
return
|
|
415
|
+
euint256.wrap(
|
|
416
|
+
inco.eIfThenElse(
|
|
417
|
+
s(control),
|
|
418
|
+
euint256.unwrap(s(ifTrue)),
|
|
419
|
+
euint256.unwrap(s(ifFalse))
|
|
420
|
+
)
|
|
421
|
+
);
|
|
422
|
+
}
|
|
423
|
+
|
|
424
|
+
function select(
|
|
425
|
+
ebool control,
|
|
426
|
+
ebool ifTrue,
|
|
427
|
+
ebool ifFalse
|
|
428
|
+
) internal returns (ebool) {
|
|
429
|
+
return
|
|
430
|
+
ebool.wrap(
|
|
431
|
+
inco.eIfThenElse(
|
|
432
|
+
s(control),
|
|
433
|
+
ebool.unwrap(s(ifTrue)),
|
|
434
|
+
ebool.unwrap(s(ifFalse))
|
|
435
|
+
)
|
|
436
|
+
);
|
|
437
|
+
}
|
|
438
|
+
|
|
439
|
+
function requestDecryption(
|
|
440
|
+
euint256 a,
|
|
441
|
+
bytes4 callbackSelector,
|
|
442
|
+
bytes memory callbackData
|
|
443
|
+
) internal returns (uint256 requestId) {
|
|
444
|
+
requestId = inco.requestDecryption(
|
|
445
|
+
callbackSelector,
|
|
446
|
+
block.timestamp + defaultDecryptionDelayLimit,
|
|
447
|
+
euint256.unwrap(s(a)),
|
|
448
|
+
callbackData
|
|
449
|
+
);
|
|
450
|
+
}
|
|
451
|
+
|
|
452
|
+
function requestDecryption(
|
|
453
|
+
ebool a,
|
|
454
|
+
bytes4 callbackSelector,
|
|
455
|
+
bytes memory callbackData
|
|
456
|
+
) internal returns (uint256 requestId) {
|
|
457
|
+
requestId = inco.requestDecryption(
|
|
458
|
+
callbackSelector,
|
|
459
|
+
block.timestamp + defaultDecryptionDelayLimit,
|
|
460
|
+
ebool.unwrap(s(a)),
|
|
461
|
+
callbackData
|
|
462
|
+
);
|
|
463
|
+
}
|
|
464
|
+
}
|
package/src/Types.sol
ADDED
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
// SPDX-License-Identifier: No License
|
|
2
|
+
pragma solidity ^0.8;
|
|
3
|
+
|
|
4
|
+
// matches Zama's ids, cf contracts/inco-fhevm/dependencies/fhevm-0.0.1/contracts/contracts/TFHEExecutor.sol l97-124
|
|
5
|
+
// https://github.com/zama-ai/fhevm/blob/be14f85eb5b17ee868bfa66c2c6c5db61d67c89f/lib/TFHEExecutor.sol#L86
|
|
6
|
+
enum EOps {
|
|
7
|
+
Add, // 0
|
|
8
|
+
Sub, // 1
|
|
9
|
+
Mul, // 2
|
|
10
|
+
Div, // 3
|
|
11
|
+
Rem, // 4
|
|
12
|
+
BitAnd, // 5
|
|
13
|
+
BitOr, // 6
|
|
14
|
+
BitXor, // 7
|
|
15
|
+
Shl, // 8
|
|
16
|
+
Shr, // 9
|
|
17
|
+
Rotl, // 10
|
|
18
|
+
Rotr, // 11
|
|
19
|
+
Eq, // 12
|
|
20
|
+
Ne, // 13
|
|
21
|
+
Ge, // 14
|
|
22
|
+
Gt, // 15
|
|
23
|
+
Le, // 16
|
|
24
|
+
Lt, // 17
|
|
25
|
+
Min, // 18
|
|
26
|
+
Max, // 19
|
|
27
|
+
NegUNSUPPORTED, // 20
|
|
28
|
+
Not, // 21
|
|
29
|
+
NewInput, // 22
|
|
30
|
+
Cast, // 23
|
|
31
|
+
TrivialEncrypt, // 24
|
|
32
|
+
IfThenElse, // 25
|
|
33
|
+
Rand, // 26
|
|
34
|
+
RandBounded, // 27
|
|
35
|
+
DecryptionRequested // 28
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
type ebool is bytes32;
|
|
39
|
+
type euint256 is bytes32;
|
|
40
|
+
|
|
41
|
+
// matches Zama's ids, cf contracts/inco-fhevm/dependencies/fhevm-0.0.1/contracts/lib/TFHE.sol l24-35
|
|
42
|
+
// https://github.com/zama-ai/fhevm/blob/61c0b3593414082b2da6e591252ed3721fe922d7/lib/TFHE.sol#L26
|
|
43
|
+
enum ETypes {
|
|
44
|
+
Bool,
|
|
45
|
+
Uint4UNSUPPORTED,
|
|
46
|
+
Uint8UNSUPPORTED,
|
|
47
|
+
Uint16UNSUPPORTED,
|
|
48
|
+
Uint32UNSUPPORTED,
|
|
49
|
+
Uint64UNSUPPORTED,
|
|
50
|
+
Uint128UNSUPPORTED,
|
|
51
|
+
Uint160UNSUPPORTED,
|
|
52
|
+
Uint256,
|
|
53
|
+
Bytes64UNSUPPORTED,
|
|
54
|
+
Bytes128UNSUPPORTED,
|
|
55
|
+
Bytes256UNSUPPORTED
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
// check correctness of compute
|
|
59
|
+
// revert acl
|
|
60
|
+
|
|
61
|
+
/// Checks whether the given type is a valid numeric type or a boolean.
|
|
62
|
+
/// @param t the type to check
|
|
63
|
+
function isTypeSupported(ETypes t) pure returns (bool) {
|
|
64
|
+
return t == ETypes.Uint256 || t == ETypes.Bool;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
error SenderNotAllowedForHandle(bytes32 handle, address sender);
|
|
68
|
+
error SharerNotAllowedForHandle(bytes32 handle, address sharer);
|
|
69
|
+
|
|
70
|
+
string constant EVM_HOST_CHAIN_PREFIX = "evm/";
|
|
71
|
+
uint8 constant HANDLE_VERSION = 0;
|
|
72
|
+
|
|
73
|
+
// IncoLightning only supports single-valued ciphertexts so this is always 0
|
|
74
|
+
uint256 constant HANDLE_INDEX = 0;
|