@inco/lightning 0.2.14 → 0.2.16

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.
@@ -44,6 +44,18 @@ contract FakeIncoInfraBase is TestUtils, KVStore {
44
44
  value = abi.decode(ciphertext, (uint256));
45
45
  }
46
46
 
47
+ function fakePrepareEuint160Ciphertext(
48
+ uint160 value
49
+ ) internal pure returns (bytes memory ciphertext) {
50
+ ciphertext = abi.encode(value);
51
+ }
52
+
53
+ function fakeDecryptEuint160Ciphertext(
54
+ bytes memory ciphertext
55
+ ) internal pure returns (uint160 value) {
56
+ value = abi.decode(ciphertext, (uint160));
57
+ }
58
+
47
59
  function fakePrepareEboolCiphertext(
48
60
  bool value
49
61
  ) internal pure returns (bytes memory ciphertext) {
@@ -2,7 +2,7 @@
2
2
  pragma solidity ^0.8;
3
3
 
4
4
  import {HandleMetadata} from "../../lightning-parts/primitives/HandleMetadata.sol";
5
- import {ETypes, euint256, ebool} from "../../Types.sol";
5
+ import {ETypes, euint256, ebool, eaddress} from "../../Types.sol";
6
6
  import {asBool} from "@inco/shared/src/TypeUtils.sol";
7
7
 
8
8
  /// @notice key-value store, knows the value behind each handle
@@ -29,6 +29,12 @@ contract KVStore is HandleMetadata {
29
29
  return asBool(get(handle));
30
30
  }
31
31
 
32
+ function getAddressValue(eaddress input) internal view returns (address) {
33
+ bytes32 handle = eaddress.unwrap(input);
34
+ checkType(handle, ETypes.AddressOrUint160OrBytes20);
35
+ return address(uint160(uint256(get(handle))));
36
+ }
37
+
32
38
  function checkType(bytes32 handle, ETypes requiredType) private pure {
33
39
  assert(typeOf(handle) == requiredType);
34
40
  }
@@ -89,6 +89,8 @@ contract MockOpHandler is FakeIncoInfraBase, FakeComputeServer {
89
89
  set(result, bytes32(fakeDecryptEuint256Ciphertext(ciphertext)));
90
90
  } else if (inputType == ETypes.Bool) {
91
91
  set(result, asBytes32(fakeDecryptEboolCiphertext(ciphertext)));
92
+ } else if (inputType == ETypes.AddressOrUint160OrBytes20) {
93
+ set(result, bytes32(uint256(fakeDecryptEuint160Ciphertext(ciphertext))));
92
94
  } else {
93
95
  revert UnsupportedTypeInput(inputType);
94
96
  }
@@ -124,7 +126,7 @@ contract MockOpHandler is FakeIncoInfraBase, FakeComputeServer {
124
126
 
125
127
  function handleECast(bytes32 handle, uint8 toType, bytes32 result) private {
126
128
  ETypes _toType = ETypes(toType);
127
- if (_toType == ETypes.Bool || _toType == ETypes.Uint256) {
129
+ if (_toType == ETypes.Bool || _toType == ETypes.Uint256 || _toType == ETypes.AddressOrUint160OrBytes20) {
128
130
  set(result, get(handle));
129
131
  } else {
130
132
  revert UnsupportedTypeInput(ETypes(toType));
@@ -2,7 +2,7 @@
2
2
  pragma solidity ^0.8;
3
3
 
4
4
  import {IncoTest} from "./IncoTest.sol";
5
- import {e, euint256, ebool} from "../Lib.sol";
5
+ import {e, euint256, ebool, eaddress} from "../Lib.sol";
6
6
  import {SenderNotAllowedForHandle} from "../Types.sol";
7
7
 
8
8
  contract TakesEInput {
@@ -41,6 +41,8 @@ contract TestFakeInfra is IncoTest {
41
41
  using e for ebool;
42
42
  using e for uint256;
43
43
  using e for bool;
44
+ using e for address;
45
+ using e for eaddress;
44
46
 
45
47
  function testTrivialEncrypt() public {
46
48
  euint256 a = e.asEuint256(3);
@@ -50,6 +52,9 @@ contract TestFakeInfra is IncoTest {
50
52
  ebool b = e.asEbool(true);
51
53
  processAllOperations();
52
54
  assertEq(getBoolValue(b), true);
55
+ eaddress c = e.asEaddress(address(0xdeadbeef));
56
+ processAllOperations();
57
+ assertEq(getAddressValue(c), address(0xdeadbeef));
53
58
  }
54
59
 
55
60
  function testEAdd() public {
@@ -10,4 +10,4 @@ pragma solidity ^0.8;
10
10
  string constant CONTRACT_NAME = "incoLightning";
11
11
  uint8 constant MAJOR_VERSION = 0;
12
12
  uint8 constant MINOR_VERSION = 2;
13
- uint8 constant PATCH_VERSION = 0;
13
+ uint8 constant PATCH_VERSION = 1;
@@ -1,389 +0,0 @@
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.sol";
9
- import { ebool, euint256, ETypes } from "../Types.sol";
10
-
11
- IncoLightning constant inco = IncoLightning(0x5Db4068769783837bFFc070A703B29f44Ba16f98);
12
- address constant deployedBy = 0x8202D2D747784Cb7D48868E44C42C4bf162a70BC;
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
-
42
- function add(euint256 a, uint256 b) internal returns (euint256) {
43
- return inco.eAdd(s(a), asEuint256(b));
44
- }
45
-
46
- function add(uint256 a, euint256 b) internal returns (euint256) {
47
- return inco.eAdd(asEuint256(a), s(b));
48
- }
49
-
50
- function sub(euint256 a, euint256 b) internal returns (euint256) {
51
- return inco.eSub(s(a), s(b));
52
- }
53
-
54
- function sub(euint256 a, uint256 b) internal returns (euint256) {
55
- return inco.eSub(s(a), asEuint256(b));
56
- }
57
-
58
- function sub(uint256 a, euint256 b) internal returns (euint256) {
59
- return inco.eSub(asEuint256(a), s(b));
60
- }
61
-
62
- function mul(euint256 a, euint256 b) internal returns (euint256) {
63
- return inco.eMul(s(a), s(b));
64
- }
65
-
66
- function mul(euint256 a, uint256 b) internal returns (euint256) {
67
- return inco.eMul(s(a), asEuint256(b));
68
- }
69
-
70
- function mul(uint256 a, euint256 b) internal returns (euint256) {
71
- return inco.eMul(asEuint256(a), s(b));
72
- }
73
-
74
- function div(euint256 a, euint256 b) internal returns (euint256) {
75
- return inco.eDiv(s(a), s(b));
76
- }
77
-
78
- function div(euint256 a, uint256 b) internal returns (euint256) {
79
- return inco.eDiv(s(a), asEuint256(b));
80
- }
81
-
82
- function div(uint256 a, euint256 b) internal returns (euint256) {
83
- return inco.eDiv(asEuint256(a), s(b));
84
- }
85
-
86
- function rem(euint256 a, euint256 b) internal returns (euint256) {
87
- return inco.eRem(s(a), s(b));
88
- }
89
-
90
- function rem(euint256 a, uint256 b) internal returns (euint256) {
91
- return inco.eRem(s(a), asEuint256(b));
92
- }
93
-
94
- function rem(uint256 a, euint256 b) internal returns (euint256) {
95
- return inco.eRem(asEuint256(a), s(b));
96
- }
97
-
98
- function and(euint256 a, euint256 b) internal returns (euint256) {
99
- return euint256.wrap(inco.eBitAnd(euint256.unwrap(s(a)), euint256.unwrap(s(b))));
100
- }
101
-
102
- function and(euint256 a, uint256 b) internal returns (euint256) {
103
- return euint256.wrap(inco.eBitAnd(euint256.unwrap(s(a)), euint256.unwrap(asEuint256(b))));
104
- }
105
-
106
- function and(uint256 a, euint256 b) internal returns (euint256) {
107
- return euint256.wrap(inco.eBitAnd(euint256.unwrap(asEuint256(a)), euint256.unwrap(s(b))));
108
- }
109
-
110
- function and(ebool a, ebool b) internal returns (ebool) {
111
- return ebool.wrap(inco.eBitAnd(ebool.unwrap(s(a)), ebool.unwrap(s(b))));
112
- }
113
-
114
- function and(ebool a, bool b) internal returns (ebool) {
115
- return ebool.wrap(inco.eBitAnd(ebool.unwrap(s(a)), ebool.unwrap(asEbool(b))));
116
- }
117
-
118
- function and(bool a, ebool b) internal returns (ebool) {
119
- return ebool.wrap(inco.eBitAnd(ebool.unwrap(asEbool(a)), ebool.unwrap(s(b))));
120
- }
121
-
122
- function or(euint256 a, euint256 b) internal returns (euint256) {
123
- return euint256.wrap(inco.eBitOr(euint256.unwrap(s(a)), euint256.unwrap(s(b))));
124
- }
125
-
126
- function or(euint256 a, uint256 b) internal returns (euint256) {
127
- return euint256.wrap(inco.eBitOr(euint256.unwrap(s(a)), euint256.unwrap(asEuint256(b))));
128
- }
129
-
130
- function or(uint256 a, euint256 b) internal returns (euint256) {
131
- return euint256.wrap(inco.eBitOr(euint256.unwrap(asEuint256(a)), euint256.unwrap(s(b))));
132
- }
133
-
134
- function or(ebool a, ebool b) internal returns (ebool) {
135
- return ebool.wrap(inco.eBitOr(ebool.unwrap(s(a)), ebool.unwrap(s(b))));
136
- }
137
-
138
- function or(ebool a, bool b) internal returns (ebool) {
139
- return ebool.wrap(inco.eBitOr(ebool.unwrap(s(a)), ebool.unwrap(asEbool(b))));
140
- }
141
-
142
- function or(bool a, ebool b) internal returns (ebool) {
143
- return ebool.wrap(inco.eBitOr(ebool.unwrap(asEbool(a)), ebool.unwrap(s(b))));
144
- }
145
-
146
- function xor(euint256 a, euint256 b) internal returns (euint256) {
147
- return euint256.wrap(inco.eBitXor(euint256.unwrap(s(a)), euint256.unwrap(s(b))));
148
- }
149
-
150
- function xor(euint256 a, uint256 b) internal returns (euint256) {
151
- return euint256.wrap(inco.eBitXor(euint256.unwrap(s(a)), euint256.unwrap(asEuint256(b))));
152
- }
153
-
154
- function xor(uint256 a, euint256 b) internal returns (euint256) {
155
- return euint256.wrap(inco.eBitXor(euint256.unwrap(asEuint256(a)), euint256.unwrap(s(b))));
156
- }
157
-
158
- function xor(ebool a, ebool b) internal returns (ebool) {
159
- return ebool.wrap(inco.eBitXor(ebool.unwrap(s(a)), ebool.unwrap(s(b))));
160
- }
161
-
162
- function xor(ebool a, bool b) internal returns (ebool) {
163
- return ebool.wrap(inco.eBitXor(ebool.unwrap(s(a)), ebool.unwrap(asEbool(b))));
164
- }
165
-
166
- function xor(bool a, ebool b) internal returns (ebool) {
167
- return ebool.wrap(inco.eBitXor(ebool.unwrap(asEbool(a)), ebool.unwrap(s(b))));
168
- }
169
-
170
- function shl(euint256 a, euint256 b) internal returns (euint256) {
171
- return inco.eShl(s(a), s(b));
172
- }
173
-
174
- function shl(euint256 a, uint256 b) internal returns (euint256) {
175
- return inco.eShl(s(a), asEuint256(b));
176
- }
177
-
178
- function shl(uint256 a, euint256 b) internal returns (euint256) {
179
- return inco.eShl(asEuint256(a), s(b));
180
- }
181
-
182
- function shr(euint256 a, euint256 b) internal returns (euint256) {
183
- return inco.eShr(s(a), s(b));
184
- }
185
-
186
- function shr(euint256 a, uint256 b) internal returns (euint256) {
187
- return inco.eShr(s(a), asEuint256(b));
188
- }
189
-
190
- function shr(uint256 a, euint256 b) internal returns (euint256) {
191
- return inco.eShr(asEuint256(a), s(b));
192
- }
193
-
194
- function rotl(euint256 a, euint256 b) internal returns (euint256) {
195
- return inco.eRotl(s(a), s(b));
196
- }
197
-
198
- function rotl(euint256 a, uint256 b) internal returns (euint256) {
199
- return inco.eRotl(s(a), asEuint256(b));
200
- }
201
-
202
- function rotl(uint256 a, euint256 b) internal returns (euint256) {
203
- return inco.eRotl(asEuint256(a), s(b));
204
- }
205
-
206
- function rotr(euint256 a, euint256 b) internal returns (euint256) {
207
- return inco.eRotr(s(a), s(b));
208
- }
209
-
210
- function rotr(euint256 a, uint256 b) internal returns (euint256) {
211
- return inco.eRotr(s(a), asEuint256(b));
212
- }
213
-
214
- function rotr(uint256 a, euint256 b) internal returns (euint256) {
215
- return inco.eRotr(asEuint256(a), s(b));
216
- }
217
-
218
- function eq(euint256 a, euint256 b) internal returns (ebool) {
219
- return inco.eEq(s(a), s(b));
220
- }
221
-
222
- function eq(euint256 a, uint256 b) internal returns (ebool) {
223
- return inco.eEq(s(a), asEuint256(b));
224
- }
225
-
226
- function eq(uint256 a, euint256 b) internal returns (ebool) {
227
- return inco.eEq(asEuint256(a), s(b));
228
- }
229
-
230
- function ne(euint256 a, euint256 b) internal returns (ebool) {
231
- return inco.eNe(s(a), s(b));
232
- }
233
-
234
- function ne(euint256 a, uint256 b) internal returns (ebool) {
235
- return inco.eNe(s(a), asEuint256(b));
236
- }
237
-
238
- function ne(uint256 a, euint256 b) internal returns (ebool) {
239
- return inco.eNe(asEuint256(a), s(b));
240
- }
241
-
242
- function ge(euint256 a, euint256 b) internal returns (ebool) {
243
- return inco.eGe(s(a), s(b));
244
- }
245
-
246
- function ge(euint256 a, uint256 b) internal returns (ebool) {
247
- return inco.eGe(s(a), asEuint256(b));
248
- }
249
-
250
- function ge(uint256 a, euint256 b) internal returns (ebool) {
251
- return inco.eGe(asEuint256(a), s(b));
252
- }
253
-
254
- function gt(euint256 a, euint256 b) internal returns (ebool) {
255
- return inco.eGt(s(a), s(b));
256
- }
257
-
258
- function gt(euint256 a, uint256 b) internal returns (ebool) {
259
- return inco.eGt(s(a), asEuint256(b));
260
- }
261
-
262
- function gt(uint256 a, euint256 b) internal returns (ebool) {
263
- return inco.eGt(asEuint256(a), s(b));
264
- }
265
-
266
- function le(euint256 a, euint256 b) internal returns (ebool) {
267
- return inco.eLe(s(a), s(b));
268
- }
269
-
270
- function le(euint256 a, uint256 b) internal returns (ebool) {
271
- return inco.eLe(s(a), asEuint256(b));
272
- }
273
-
274
- function le(uint256 a, euint256 b) internal returns (ebool) {
275
- return inco.eLe(asEuint256(a), s(b));
276
- }
277
-
278
- function lt(euint256 a, euint256 b) internal returns (ebool) {
279
- return inco.eLt(s(a), s(b));
280
- }
281
-
282
- function lt(euint256 a, uint256 b) internal returns (ebool) {
283
- return inco.eLt(s(a), asEuint256(b));
284
- }
285
-
286
- function lt(uint256 a, euint256 b) internal returns (ebool) {
287
- return inco.eLt(asEuint256(a), s(b));
288
- }
289
-
290
- function min(euint256 a, euint256 b) internal returns (euint256) {
291
- return inco.eMin(s(a), s(b));
292
- }
293
-
294
- function min(euint256 a, uint256 b) internal returns (euint256) {
295
- return inco.eMin(s(a), asEuint256(b));
296
- }
297
-
298
- function min(uint256 a, euint256 b) internal returns (euint256) {
299
- return inco.eMin(asEuint256(a), s(b));
300
- }
301
-
302
- function max(euint256 a, euint256 b) internal returns (euint256) {
303
- return inco.eMax(s(a), s(b));
304
- }
305
-
306
- function max(euint256 a, uint256 b) internal returns (euint256) {
307
- return inco.eMax(s(a), asEuint256(b));
308
- }
309
-
310
- function max(uint256 a, euint256 b) internal returns (euint256) {
311
- return inco.eMax(asEuint256(a), s(b));
312
- }
313
-
314
- function not(ebool a) internal returns (ebool) {
315
- return inco.eNot(s(a));
316
- }
317
-
318
- function rand() internal returns (euint256) {
319
- return euint256.wrap(inco.eRand(ETypes.Uint256));
320
- }
321
-
322
- function randBounded(uint256 upperBound) internal returns (euint256) {
323
- return euint256.wrap(inco.eRandBounded(euint256.unwrap(asEuint256(upperBound)), ETypes.Uint256));
324
- }
325
-
326
- function randBounded(euint256 upperBound) internal returns (euint256) {
327
- return euint256.wrap(inco.eRandBounded(euint256.unwrap(s(upperBound)), ETypes.Uint256));
328
- }
329
-
330
- function asEuint256(uint256 a) internal returns (euint256) {
331
- return inco.asEuint256(a);
332
- }
333
-
334
- function asEbool(bool a) internal returns (ebool) {
335
- return inco.asEbool(a);
336
- }
337
-
338
- function asEbool(euint256 a) internal returns (ebool) {
339
- return ebool.wrap(inco.eCast(euint256.unwrap(a), ETypes.Bool));
340
- }
341
-
342
- function asEuint256(ebool a) internal returns (euint256) {
343
- return euint256.wrap(inco.eCast(ebool.unwrap(a), ETypes.Uint256));
344
- }
345
-
346
- function newEuint256(bytes memory ciphertext, address user) internal returns (euint256) {
347
- return inco.newEuint256(ciphertext, user);
348
- }
349
-
350
- function newEbool(bytes memory ciphertext, address user) internal returns (ebool) {
351
- return inco.newEbool(ciphertext, user);
352
- }
353
-
354
- function allow(euint256 a, address to) internal {
355
- inco.allow(euint256.unwrap(a), to);
356
- }
357
-
358
- function allow(ebool a, address to) internal {
359
- inco.allow(ebool.unwrap(a), to);
360
- }
361
-
362
- function allowThis(euint256 a) internal {
363
- allow(a, address(this));
364
- }
365
-
366
- function allowThis(ebool a) internal {
367
- allow(a, address(this));
368
- }
369
-
370
- function isAllowed(address user, euint256 a) internal view returns (bool) {
371
- return inco.isAllowed(euint256.unwrap(a), user);
372
- }
373
-
374
- function select(ebool control, euint256 ifTrue, euint256 ifFalse) internal returns (euint256) {
375
- return euint256.wrap(inco.eIfThenElse(s(control), euint256.unwrap(s(ifTrue)), euint256.unwrap(s(ifFalse))));
376
- }
377
-
378
- function select(ebool control, ebool ifTrue, ebool ifFalse) internal returns (ebool) {
379
- return ebool.wrap(inco.eIfThenElse(s(control), ebool.unwrap(s(ifTrue)), ebool.unwrap(s(ifFalse))));
380
- }
381
-
382
- function requestDecryption(euint256 a, bytes4 callbackSelector, bytes memory callbackData) internal returns (uint256 requestId) {
383
- requestId = inco.requestDecryption(callbackSelector, block.timestamp + defaultDecryptionDelayLimit, euint256.unwrap(s(a)), callbackData);
384
- }
385
-
386
- function requestDecryption(ebool a, bytes4 callbackSelector, bytes memory callbackData) internal returns (uint256 requestId) {
387
- requestId = inco.requestDecryption(callbackSelector, block.timestamp + defaultDecryptionDelayLimit, ebool.unwrap(s(a)), callbackData);
388
- }
389
- }