@inco/lightning 0.6.8 → 0.6.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (83) hide show
  1. package/README.md +29 -2
  2. package/manifest.yaml +0 -42
  3. package/package.json +5 -2
  4. package/src/CreateXHelper.sol +3 -1
  5. package/src/DeployUtils.sol +36 -71
  6. package/src/Errors.sol +1 -1
  7. package/src/IIncoLightning.sol +2 -0
  8. package/src/IncoLightning.sol +5 -17
  9. package/src/IncoVerifier.sol +12 -18
  10. package/src/Lib.template.sol +40 -159
  11. package/src/Types.sol +233 -97
  12. package/src/interfaces/IIncoLightning.sol +2 -0
  13. package/src/interfaces/IIncoVerifier.sol +7 -12
  14. package/src/interfaces/automata-interfaces/BELE.sol +2 -0
  15. package/src/interfaces/automata-interfaces/IAutomataEnclaveIdentityDao.sol +9 -11
  16. package/src/interfaces/automata-interfaces/IFmspcTcbDao.sol +3 -3
  17. package/src/interfaces/automata-interfaces/IPCCSRouter.sol +13 -47
  18. package/src/interfaces/automata-interfaces/IPCCSRouterExtended.sol +2 -0
  19. package/src/interfaces/automata-interfaces/IPcsDao.sol +6 -11
  20. package/src/interfaces/automata-interfaces/IQuoteVerifier.sol +4 -7
  21. package/src/interfaces/automata-interfaces/Types.sol +7 -6
  22. package/src/libs/incoLightning_devnet_v1_887305889.sol +5 -3
  23. package/src/libs/incoLightning_testnet_v1_938327937.sol +5 -3
  24. package/src/lightning-parts/AccessControl/AdvancedAccessControl.sol +41 -75
  25. package/src/lightning-parts/AccessControl/BaseAccessControlList.sol +31 -62
  26. package/src/lightning-parts/AccessControl/interfaces/IAdvancedAccessControl.sol +8 -15
  27. package/src/lightning-parts/AccessControl/interfaces/IBaseAccessControlList.sol +5 -12
  28. package/src/lightning-parts/AccessControl/test/TestAdvancedAccessControl.t.sol +42 -83
  29. package/src/lightning-parts/AccessControl/test/TestBaseAccessControl.t.sol +2 -0
  30. package/src/lightning-parts/DecryptionAttester.sol +14 -28
  31. package/src/lightning-parts/EncryptedInput.sol +23 -52
  32. package/src/lightning-parts/EncryptedOperations.sol +93 -440
  33. package/src/lightning-parts/Fee.sol +3 -1
  34. package/src/lightning-parts/TEELifecycle.sol +95 -225
  35. package/src/lightning-parts/TEELifecycle.types.sol +4 -3
  36. package/src/lightning-parts/TrivialEncryption.sol +6 -20
  37. package/src/lightning-parts/interfaces/IDecryptionAttester.sol +7 -2
  38. package/src/lightning-parts/interfaces/IEncryptedInput.sol +5 -12
  39. package/src/lightning-parts/interfaces/IEncryptedOperations.sol +17 -61
  40. package/src/lightning-parts/interfaces/ITEELifecycle.sol +7 -11
  41. package/src/lightning-parts/interfaces/ITrivialEncryption.sol +2 -0
  42. package/src/lightning-parts/primitives/EventCounter.sol +7 -8
  43. package/src/lightning-parts/primitives/HandleGeneration.sol +20 -32
  44. package/src/lightning-parts/primitives/HandleMetadata.sol +7 -17
  45. package/src/lightning-parts/primitives/LightningAddressGetter.sol +3 -0
  46. package/src/lightning-parts/primitives/SignatureVerifier.sol +91 -27
  47. package/src/lightning-parts/primitives/VerifierAddressGetter.sol +3 -0
  48. package/src/lightning-parts/primitives/interfaces/IEventCounter.sol +2 -0
  49. package/src/lightning-parts/primitives/interfaces/IHandleGeneration.sol +10 -2
  50. package/src/lightning-parts/primitives/interfaces/ISignatureVerifier.sol +4 -2
  51. package/src/lightning-parts/primitives/interfaces/IVerifierAddressGetter.sol +2 -0
  52. package/src/lightning-parts/primitives/test/SignatureVerifier.t.sol +838 -0
  53. package/src/lightning-parts/test/Fee.t.sol +6 -6
  54. package/src/lightning-parts/test/HandleMetadata.t.sol +21 -76
  55. package/src/lightning-parts/test/InputsFee.t.sol +7 -28
  56. package/src/lightning-parts/test/TestDecryptionAttestationInSynchronousFlow.t.sol +16 -48
  57. package/src/pasted-dependencies/CreateX.sol +146 -419
  58. package/src/pasted-dependencies/ICreateX.sol +58 -102
  59. package/src/periphery/SessionVerifier.sol +5 -7
  60. package/src/shared/IOwnable.sol +3 -0
  61. package/src/shared/IUUPSUpgradable.sol +5 -1
  62. package/src/shared/JsonUtils.sol +3 -5
  63. package/src/shared/TestUtils.sol +14 -13
  64. package/src/test/AddTwo.sol +9 -7
  65. package/src/test/FakeIncoInfra/FakeComputeServer.sol +11 -53
  66. package/src/test/FakeIncoInfra/FakeDecryptionAttester.sol +35 -118
  67. package/src/test/FakeIncoInfra/FakeIncoInfraBase.sol +31 -48
  68. package/src/test/FakeIncoInfra/FakeQuoteVerifier.sol +4 -7
  69. package/src/test/FakeIncoInfra/KVStore.sol +2 -0
  70. package/src/test/FakeIncoInfra/MockOpHandler.sol +9 -31
  71. package/src/test/FakeIncoInfra/MockRemoteAttestation.sol +44 -21
  72. package/src/test/IncoTest.sol +15 -9
  73. package/src/test/OpsTest.sol +429 -0
  74. package/src/test/TEELifecycle/TEELifecycleMockTest.t.sol +58 -104
  75. package/src/test/TestAddTwo.t.sol +4 -3
  76. package/src/test/TestDeploy.t.sol +5 -6
  77. package/src/test/TestExtractDataOfEventTooLarge.t.sol +7 -14
  78. package/src/test/TestFakeInfra.t.sol +15 -38
  79. package/src/test/TestUpgrade.t.sol +40 -135
  80. package/src/test/TestVersion.t.sol +6 -5
  81. package/src/version/IncoLightningConfig.sol +1 -1
  82. package/src/version/Version.sol +48 -51
  83. package/src/version/interfaces/IVersion.sol +6 -0
@@ -7,173 +7,48 @@ import {HandleGeneration} from "./primitives/HandleGeneration.sol";
7
7
  import {IEncryptedOperations} from "./interfaces/IEncryptedOperations.sol";
8
8
  import {Fee} from "./Fee.sol";
9
9
 
10
- abstract contract EncryptedOperations is
11
- IEncryptedOperations,
12
- BaseAccessControlList,
13
- HandleGeneration,
14
- Fee
15
- {
10
+ abstract contract EncryptedOperations is IEncryptedOperations, BaseAccessControlList, HandleGeneration, Fee {
11
+
16
12
  error UnexpectedType(ETypes actual, bytes32 expectedTypes);
17
13
  error UnsupportedType(ETypes actual);
18
14
 
19
15
  uint256 internal randCounter;
20
-
21
- bytes32 constant EBOOL = bytes32(1 << uint256(ETypes.Bool));
22
- bytes32 constant EUINT160 = bytes32(1 << uint256(ETypes.AddressOrUint160OrBytes20));
23
- bytes32 constant EUINT256 = bytes32(1 << uint256(ETypes.Uint256));
24
-
25
- bytes32 constant SUPPORTED_TYPES_MASK =
26
- EBOOL |
27
- EUINT160 |
28
- EUINT256;
29
-
30
- event EAdd(
31
- euint256 indexed lhs,
32
- euint256 indexed rhs,
33
- euint256 indexed result,
34
- uint256 eventId
35
- );
36
- event ESub(
37
- euint256 indexed lhs,
38
- euint256 indexed rhs,
39
- euint256 indexed result,
40
- uint256 eventId
41
- );
42
- event EMul(
43
- euint256 indexed lhs,
44
- euint256 indexed rhs,
45
- euint256 indexed result,
46
- uint256 eventId
47
- );
48
- event EDiv(
49
- euint256 indexed lhs,
50
- euint256 indexed rhs,
51
- euint256 indexed result,
52
- uint256 eventId
53
- );
54
- event ERem(
55
- euint256 indexed lhs,
56
- euint256 indexed rhs,
57
- euint256 indexed result,
58
- uint256 eventId
59
- );
60
- event EBitAnd(
61
- bytes32 indexed lhs,
62
- bytes32 indexed rhs,
63
- bytes32 indexed result,
64
- uint256 eventId
65
- );
66
- event EBitOr(
67
- bytes32 indexed lhs,
68
- bytes32 indexed rhs,
69
- bytes32 indexed result,
70
- uint256 eventId
71
- );
72
- event EBitXor(
73
- bytes32 indexed lhs,
74
- bytes32 indexed rhs,
75
- bytes32 indexed result,
76
- uint256 eventId
77
- );
78
- event EShl(
79
- euint256 indexed lhs,
80
- euint256 indexed rhs,
81
- euint256 indexed result,
82
- uint256 eventId
83
- );
84
- event EShr(
85
- euint256 indexed lhs,
86
- euint256 indexed rhs,
87
- euint256 indexed result,
88
- uint256 eventId
89
- );
90
- event ERotl(
91
- euint256 indexed lhs,
92
- euint256 indexed rhs,
93
- euint256 indexed result,
94
- uint256 eventId
95
- );
96
- event ERotr(
97
- euint256 indexed lhs,
98
- euint256 indexed rhs,
99
- euint256 indexed result,
100
- uint256 eventId
101
- );
102
- event EEq(
103
- bytes32 indexed lhs,
104
- bytes32 indexed rhs,
105
- ebool indexed result,
106
- uint256 eventId
107
- );
108
- event ENe(
109
- bytes32 indexed lhs,
110
- bytes32 indexed rhs,
111
- ebool indexed result,
112
- uint256 eventId
113
- );
114
- event EGe(
115
- euint256 indexed lhs,
116
- euint256 indexed rhs,
117
- ebool indexed result,
118
- uint256 eventId
119
- );
120
- event EGt(
121
- euint256 indexed lhs,
122
- euint256 indexed rhs,
123
- ebool indexed result,
124
- uint256 eventId
125
- );
126
- event ELe(
127
- euint256 indexed lhs,
128
- euint256 indexed rhs,
129
- ebool indexed result,
130
- uint256 eventId
131
- );
132
- event ELt(
133
- euint256 indexed lhs,
134
- euint256 indexed rhs,
135
- ebool indexed result,
136
- uint256 eventId
137
- );
138
- event EMin(
139
- euint256 indexed lhs,
140
- euint256 indexed rhs,
141
- euint256 indexed result,
142
- uint256 eventId
143
- );
144
- event EMax(
145
- euint256 indexed lhs,
146
- euint256 indexed rhs,
147
- euint256 indexed result,
148
- uint256 eventId
149
- );
150
- event ERand(
151
- uint256 indexed counter,
152
- ETypes randType,
153
- bytes32 indexed result,
154
- uint256 eventId
155
- );
16
+ uint256 internal constant ONE = 1;
17
+
18
+ bytes32 constant EBOOL = bytes32(ONE << uint256(ETypes.Bool));
19
+ bytes32 constant EUINT160 = bytes32(ONE << uint256(ETypes.AddressOrUint160OrBytes20));
20
+ bytes32 constant EUINT256 = bytes32(ONE << uint256(ETypes.Uint256));
21
+
22
+ bytes32 constant SUPPORTED_TYPES_MASK = EBOOL | EUINT160 | EUINT256;
23
+
24
+ event EAdd(euint256 indexed lhs, euint256 indexed rhs, euint256 indexed result, uint256 eventId);
25
+ event ESub(euint256 indexed lhs, euint256 indexed rhs, euint256 indexed result, uint256 eventId);
26
+ event EMul(euint256 indexed lhs, euint256 indexed rhs, euint256 indexed result, uint256 eventId);
27
+ event EDiv(euint256 indexed lhs, euint256 indexed rhs, euint256 indexed result, uint256 eventId);
28
+ event ERem(euint256 indexed lhs, euint256 indexed rhs, euint256 indexed result, uint256 eventId);
29
+ event EBitAnd(bytes32 indexed lhs, bytes32 indexed rhs, bytes32 indexed result, uint256 eventId);
30
+ event EBitOr(bytes32 indexed lhs, bytes32 indexed rhs, bytes32 indexed result, uint256 eventId);
31
+ event EBitXor(bytes32 indexed lhs, bytes32 indexed rhs, bytes32 indexed result, uint256 eventId);
32
+ event EShl(euint256 indexed lhs, euint256 indexed rhs, euint256 indexed result, uint256 eventId);
33
+ event EShr(euint256 indexed lhs, euint256 indexed rhs, euint256 indexed result, uint256 eventId);
34
+ event ERotl(euint256 indexed lhs, euint256 indexed rhs, euint256 indexed result, uint256 eventId);
35
+ event ERotr(euint256 indexed lhs, euint256 indexed rhs, euint256 indexed result, uint256 eventId);
36
+ event EEq(bytes32 indexed lhs, bytes32 indexed rhs, ebool indexed result, uint256 eventId);
37
+ event ENe(bytes32 indexed lhs, bytes32 indexed rhs, ebool indexed result, uint256 eventId);
38
+ event EGe(euint256 indexed lhs, euint256 indexed rhs, ebool indexed result, uint256 eventId);
39
+ event EGt(euint256 indexed lhs, euint256 indexed rhs, ebool indexed result, uint256 eventId);
40
+ event ELe(euint256 indexed lhs, euint256 indexed rhs, ebool indexed result, uint256 eventId);
41
+ event ELt(euint256 indexed lhs, euint256 indexed rhs, ebool indexed result, uint256 eventId);
42
+ event EMin(euint256 indexed lhs, euint256 indexed rhs, euint256 indexed result, uint256 eventId);
43
+ event EMax(euint256 indexed lhs, euint256 indexed rhs, euint256 indexed result, uint256 eventId);
44
+ event ERand(uint256 indexed counter, ETypes randType, bytes32 indexed result, uint256 eventId);
156
45
  event ERandBounded(
157
- uint256 indexed counter,
158
- ETypes randType,
159
- bytes32 indexed upperBound,
160
- bytes32 indexed result,
161
- uint256 eventId
162
- );
163
- event EIfThenElse(
164
- ebool control, // can't index >3 fields
165
- bytes32 indexed ifTrue,
166
- bytes32 indexed ifFalse,
167
- bytes32 indexed result,
168
- uint256 eventId
46
+ uint256 indexed counter, ETypes randType, bytes32 indexed upperBound, bytes32 indexed result, uint256 eventId
169
47
  );
48
+ event EIfThenElse( // can't index >3 fields
49
+ ebool control, bytes32 indexed ifTrue, bytes32 indexed ifFalse, bytes32 indexed result, uint256 eventId);
170
50
  event ENot(ebool indexed operand, ebool indexed result, uint256 eventId);
171
- event ECast(
172
- bytes32 indexed ct,
173
- uint8 indexed toType,
174
- bytes32 indexed result,
175
- uint256 eventId
176
- );
51
+ event ECast(bytes32 indexed ct, uint8 indexed toType, bytes32 indexed result, uint256 eventId);
177
52
 
178
53
  modifier checked(euint256 lhs, euint256 rhs) {
179
54
  checkInput(euint256.unwrap(lhs), typeToBitMask(ETypes.Uint256));
@@ -186,123 +61,65 @@ abstract contract EncryptedOperations is
186
61
  _;
187
62
  }
188
63
 
189
-
190
64
  function checkInput(bytes32 input, bytes32 requiredTypes) internal view {
191
- require(
192
- isAllowed(input, msg.sender),
193
- SenderNotAllowedForHandle(input, msg.sender)
194
- );
65
+ require(isAllowed(input, msg.sender), SenderNotAllowedForHandle(input, msg.sender));
195
66
  require(requiredTypes & typeToBitMask(typeOf(input)) != 0, UnexpectedType(typeOf(input), requiredTypes));
196
67
  }
197
68
 
198
- function createResultHandle(
199
- EOps op,
200
- ETypes returnType,
201
- bytes memory packedInputs
202
- ) internal returns (bytes32 result) {
69
+ function createResultHandle(EOps op, ETypes returnType, bytes memory packedInputs)
70
+ internal
71
+ returns (bytes32 result)
72
+ {
203
73
  result = getOpResultHandle(op, returnType, packedInputs);
204
74
  allowTransientInternal(result, msg.sender);
205
75
  }
206
76
 
207
- function eAdd(
208
- euint256 lhs,
209
- euint256 rhs
210
- ) external checked(lhs, rhs) returns (euint256 result) {
77
+ function eAdd(euint256 lhs, euint256 rhs) external checked(lhs, rhs) returns (euint256 result) {
211
78
  result = euint256.wrap(
212
- createResultHandle(
213
- EOps.Add,
214
- ETypes.Uint256,
215
- abi.encodePacked(
216
- euint256.unwrap(lhs),
217
- euint256.unwrap(rhs)
218
- )
219
- )
79
+ createResultHandle(EOps.Add, ETypes.Uint256, abi.encodePacked(euint256.unwrap(lhs), euint256.unwrap(rhs)))
220
80
  );
221
81
  uint256 id = getNextEventId();
222
82
  emit EAdd(lhs, rhs, result, id);
223
83
  setDigest(abi.encodePacked(result, id));
224
84
  }
225
85
 
226
- function eSub(
227
- euint256 lhs,
228
- euint256 rhs
229
- ) external checked(lhs, rhs) returns (euint256 result) {
86
+ function eSub(euint256 lhs, euint256 rhs) external checked(lhs, rhs) returns (euint256 result) {
230
87
  result = euint256.wrap(
231
- createResultHandle(
232
- EOps.Sub,
233
- ETypes.Uint256,
234
- abi.encodePacked(
235
- euint256.unwrap(lhs),
236
- euint256.unwrap(rhs)
237
- )
238
- )
88
+ createResultHandle(EOps.Sub, ETypes.Uint256, abi.encodePacked(euint256.unwrap(lhs), euint256.unwrap(rhs)))
239
89
  );
240
90
  uint256 id = getNextEventId();
241
91
  emit ESub(lhs, rhs, result, id);
242
92
  setDigest(abi.encodePacked(result, id));
243
93
  }
244
94
 
245
- function eMul(
246
- euint256 lhs,
247
- euint256 rhs
248
- ) external checked(lhs, rhs) returns (euint256 result) {
95
+ function eMul(euint256 lhs, euint256 rhs) external checked(lhs, rhs) returns (euint256 result) {
249
96
  result = euint256.wrap(
250
- createResultHandle(
251
- EOps.Mul,
252
- ETypes.Uint256,
253
- abi.encodePacked(
254
- euint256.unwrap(lhs),
255
- euint256.unwrap(rhs)
256
- )
257
- )
97
+ createResultHandle(EOps.Mul, ETypes.Uint256, abi.encodePacked(euint256.unwrap(lhs), euint256.unwrap(rhs)))
258
98
  );
259
99
  uint256 id = getNextEventId();
260
100
  emit EMul(lhs, rhs, result, id);
261
101
  setDigest(abi.encodePacked(result, id));
262
- }
102
+ }
263
103
 
264
- function eDiv(
265
- euint256 lhs,
266
- euint256 rhs
267
- ) external checked(lhs, rhs) returns (euint256 result) {
104
+ function eDiv(euint256 lhs, euint256 rhs) external checked(lhs, rhs) returns (euint256 result) {
268
105
  result = euint256.wrap(
269
- createResultHandle(
270
- EOps.Div,
271
- ETypes.Uint256,
272
- abi.encodePacked(
273
- euint256.unwrap(lhs),
274
- euint256.unwrap(rhs)
275
- )
276
- )
106
+ createResultHandle(EOps.Div, ETypes.Uint256, abi.encodePacked(euint256.unwrap(lhs), euint256.unwrap(rhs)))
277
107
  );
278
108
  uint256 id = getNextEventId();
279
109
  emit EDiv(lhs, rhs, result, id);
280
110
  setDigest(abi.encodePacked(result, id));
281
111
  }
282
112
 
283
- function eRem(
284
- euint256 lhs,
285
- euint256 rhs
286
- ) external virtual checked(lhs, rhs) returns (euint256 result) {
113
+ function eRem(euint256 lhs, euint256 rhs) external virtual checked(lhs, rhs) returns (euint256 result) {
287
114
  result = euint256.wrap(
288
- createResultHandle(
289
- EOps.Rem,
290
- ETypes.Uint256,
291
- abi.encodePacked(
292
- euint256.unwrap(lhs),
293
- euint256.unwrap(rhs)
294
- )
295
- )
115
+ createResultHandle(EOps.Rem, ETypes.Uint256, abi.encodePacked(euint256.unwrap(lhs), euint256.unwrap(rhs)))
296
116
  );
297
117
  uint256 id = getNextEventId();
298
118
  emit ERem(lhs, rhs, result, id);
299
119
  setDigest(abi.encodePacked(result, id));
300
120
  }
301
121
 
302
- function eBitAnd(
303
- bytes32 lhs,
304
- bytes32 rhs
305
- ) external returns (bytes32 result) {
122
+ function eBitAnd(bytes32 lhs, bytes32 rhs) external returns (bytes32 result) {
306
123
  ETypes lhsType = typeOf(lhs);
307
124
  ETypes rhsType = typeOf(rhs);
308
125
  checkInput(lhs, typeToBitMask(lhsType));
@@ -314,10 +131,7 @@ abstract contract EncryptedOperations is
314
131
  setDigest(abi.encodePacked(result, id));
315
132
  }
316
133
 
317
- function eBitOr(
318
- bytes32 lhs,
319
- bytes32 rhs
320
- ) external returns (bytes32 result) {
134
+ function eBitOr(bytes32 lhs, bytes32 rhs) external returns (bytes32 result) {
321
135
  ETypes lhsType = typeOf(lhs);
322
136
  ETypes rhsType = typeOf(rhs);
323
137
  checkInput(lhs, typeToBitMask(lhsType));
@@ -329,10 +143,7 @@ abstract contract EncryptedOperations is
329
143
  setDigest(abi.encodePacked(result, id));
330
144
  }
331
145
 
332
- function eBitXor(
333
- bytes32 lhs,
334
- bytes32 rhs
335
- ) external returns (bytes32 result) {
146
+ function eBitXor(bytes32 lhs, bytes32 rhs) external returns (bytes32 result) {
336
147
  ETypes lhsType = typeOf(lhs);
337
148
  ETypes rhsType = typeOf(rhs);
338
149
  checkInput(lhs, typeToBitMask(lhsType));
@@ -344,234 +155,110 @@ abstract contract EncryptedOperations is
344
155
  setDigest(abi.encodePacked(result, id));
345
156
  }
346
157
 
347
- function eShl(
348
- euint256 lhs,
349
- euint256 rhs
350
- ) external checked(lhs, rhs) returns (euint256 result) {
158
+ function eShl(euint256 lhs, euint256 rhs) external checked(lhs, rhs) returns (euint256 result) {
351
159
  result = euint256.wrap(
352
- createResultHandle(
353
- EOps.Shl,
354
- ETypes.Uint256,
355
- abi.encodePacked(
356
- euint256.unwrap(lhs),
357
- euint256.unwrap(rhs)
358
- )
359
- )
160
+ createResultHandle(EOps.Shl, ETypes.Uint256, abi.encodePacked(euint256.unwrap(lhs), euint256.unwrap(rhs)))
360
161
  );
361
162
  uint256 id = getNextEventId();
362
163
  emit EShl(lhs, rhs, result, id);
363
164
  setDigest(abi.encodePacked(result, id));
364
165
  }
365
166
 
366
- function eShr(
367
- euint256 lhs,
368
- euint256 rhs
369
- ) external checked(lhs, rhs) returns (euint256 result) {
167
+ function eShr(euint256 lhs, euint256 rhs) external checked(lhs, rhs) returns (euint256 result) {
370
168
  result = euint256.wrap(
371
- createResultHandle(
372
- EOps.Shr,
373
- ETypes.Uint256,
374
- abi.encodePacked(
375
- euint256.unwrap(lhs),
376
- euint256.unwrap(rhs)
377
- )
378
- )
169
+ createResultHandle(EOps.Shr, ETypes.Uint256, abi.encodePacked(euint256.unwrap(lhs), euint256.unwrap(rhs)))
379
170
  );
380
171
  uint256 id = getNextEventId();
381
172
  emit EShr(lhs, rhs, result, id);
382
173
  setDigest(abi.encodePacked(result, id));
383
174
  }
384
175
 
385
- function eRotl(
386
- euint256 lhs,
387
- euint256 rhs
388
- ) external checked(lhs, rhs) returns (euint256 result) {
176
+ function eRotl(euint256 lhs, euint256 rhs) external checked(lhs, rhs) returns (euint256 result) {
389
177
  result = euint256.wrap(
390
- createResultHandle(
391
- EOps.Rotl,
392
- ETypes.Uint256,
393
- abi.encodePacked(
394
- euint256.unwrap(lhs),
395
- euint256.unwrap(rhs)
396
- )
397
- )
178
+ createResultHandle(EOps.Rotl, ETypes.Uint256, abi.encodePacked(euint256.unwrap(lhs), euint256.unwrap(rhs)))
398
179
  );
399
180
  uint256 id = getNextEventId();
400
181
  emit ERotl(lhs, rhs, result, id);
401
182
  setDigest(abi.encodePacked(result, id));
402
183
  }
403
184
 
404
- function eRotr(
405
- euint256 lhs,
406
- euint256 rhs
407
- ) external checked(lhs, rhs) returns (euint256 result) {
185
+ function eRotr(euint256 lhs, euint256 rhs) external checked(lhs, rhs) returns (euint256 result) {
408
186
  result = euint256.wrap(
409
- createResultHandle(
410
- EOps.Rotr,
411
- ETypes.Uint256,
412
- abi.encodePacked(
413
- euint256.unwrap(lhs),
414
- euint256.unwrap(rhs)
415
- )
416
- )
187
+ createResultHandle(EOps.Rotr, ETypes.Uint256, abi.encodePacked(euint256.unwrap(lhs), euint256.unwrap(rhs)))
417
188
  );
418
189
  uint256 id = getNextEventId();
419
190
  emit ERotr(lhs, rhs, result, id);
420
191
  setDigest(abi.encodePacked(result, id));
421
192
  }
422
193
 
423
- function eEq(
424
- bytes32 lhs,
425
- bytes32 rhs
426
- ) external returns (ebool result) {
194
+ function eEq(bytes32 lhs, bytes32 rhs) external returns (ebool result) {
427
195
  checkInput(lhs, SUPPORTED_TYPES_MASK);
428
196
  checkInput(rhs, SUPPORTED_TYPES_MASK);
429
197
 
430
- result = ebool.wrap(
431
- createResultHandle(
432
- EOps.Eq,
433
- ETypes.Bool,
434
- abi.encodePacked(
435
- lhs,
436
- rhs
437
- )
438
- )
439
- );
198
+ result = ebool.wrap(createResultHandle(EOps.Eq, ETypes.Bool, abi.encodePacked(lhs, rhs)));
440
199
  uint256 id = getNextEventId();
441
200
  emit EEq(lhs, rhs, result, id);
442
201
  setDigest(abi.encodePacked(result, id));
443
202
  }
444
203
 
445
- function eNe(
446
- bytes32 lhs,
447
- bytes32 rhs
448
- ) external returns (ebool result) {
204
+ function eNe(bytes32 lhs, bytes32 rhs) external returns (ebool result) {
449
205
  checkInput(lhs, SUPPORTED_TYPES_MASK);
450
206
  checkInput(rhs, SUPPORTED_TYPES_MASK);
451
207
 
452
- result = ebool.wrap(
453
- createResultHandle(
454
- EOps.Ne,
455
- ETypes.Bool,
456
- abi.encodePacked(
457
- lhs,
458
- rhs
459
- )
460
- )
461
- );
208
+ result = ebool.wrap(createResultHandle(EOps.Ne, ETypes.Bool, abi.encodePacked(lhs, rhs)));
462
209
  uint256 id = getNextEventId();
463
210
  emit ENe(lhs, rhs, result, id);
464
211
  setDigest(abi.encodePacked(result, id));
465
212
  }
466
213
 
467
- function eGe(
468
- euint256 lhs,
469
- euint256 rhs
470
- ) external checked(lhs, rhs) returns (ebool result) {
214
+ function eGe(euint256 lhs, euint256 rhs) external checked(lhs, rhs) returns (ebool result) {
471
215
  result = ebool.wrap(
472
- createResultHandle(
473
- EOps.Ge,
474
- ETypes.Bool,
475
- abi.encodePacked(
476
- euint256.unwrap(lhs),
477
- euint256.unwrap(rhs)
478
- )
479
- )
216
+ createResultHandle(EOps.Ge, ETypes.Bool, abi.encodePacked(euint256.unwrap(lhs), euint256.unwrap(rhs)))
480
217
  );
481
218
  uint256 id = getNextEventId();
482
219
  emit EGe(lhs, rhs, result, id);
483
220
  setDigest(abi.encodePacked(result, id));
484
221
  }
485
222
 
486
- function eGt(
487
- euint256 lhs,
488
- euint256 rhs
489
- ) external checked(lhs, rhs) returns (ebool result) {
223
+ function eGt(euint256 lhs, euint256 rhs) external checked(lhs, rhs) returns (ebool result) {
490
224
  result = ebool.wrap(
491
- createResultHandle(
492
- EOps.Gt,
493
- ETypes.Bool,
494
- abi.encodePacked(
495
- euint256.unwrap(lhs),
496
- euint256.unwrap(rhs)
497
- )
498
- )
225
+ createResultHandle(EOps.Gt, ETypes.Bool, abi.encodePacked(euint256.unwrap(lhs), euint256.unwrap(rhs)))
499
226
  );
500
227
  uint256 id = getNextEventId();
501
228
  emit EGt(lhs, rhs, result, id);
502
229
  setDigest(abi.encodePacked(result, id));
503
230
  }
504
231
 
505
- function eLe(
506
- euint256 lhs,
507
- euint256 rhs
508
- ) external checked(lhs, rhs) returns (ebool result) {
232
+ function eLe(euint256 lhs, euint256 rhs) external checked(lhs, rhs) returns (ebool result) {
509
233
  result = ebool.wrap(
510
- createResultHandle(
511
- EOps.Le,
512
- ETypes.Bool,
513
- abi.encodePacked(
514
- euint256.unwrap(lhs),
515
- euint256.unwrap(rhs)
516
- )
517
- )
234
+ createResultHandle(EOps.Le, ETypes.Bool, abi.encodePacked(euint256.unwrap(lhs), euint256.unwrap(rhs)))
518
235
  );
519
236
  uint256 id = getNextEventId();
520
237
  emit ELe(lhs, rhs, result, id);
521
238
  setDigest(abi.encodePacked(result, id));
522
239
  }
523
240
 
524
- function eLt(
525
- euint256 lhs,
526
- euint256 rhs
527
- ) external checked(lhs, rhs) returns (ebool result) {
241
+ function eLt(euint256 lhs, euint256 rhs) external checked(lhs, rhs) returns (ebool result) {
528
242
  result = ebool.wrap(
529
- createResultHandle(
530
- EOps.Lt,
531
- ETypes.Bool,
532
- abi.encodePacked(
533
- euint256.unwrap(lhs),
534
- euint256.unwrap(rhs)
535
- )
536
- )
243
+ createResultHandle(EOps.Lt, ETypes.Bool, abi.encodePacked(euint256.unwrap(lhs), euint256.unwrap(rhs)))
537
244
  );
538
245
  uint256 id = getNextEventId();
539
246
  emit ELt(lhs, rhs, result, id);
540
247
  setDigest(abi.encodePacked(result, id));
541
248
  }
542
249
 
543
- function eMin(
544
- euint256 lhs,
545
- euint256 rhs
546
- ) external checked(lhs, rhs) returns (euint256 result) {
250
+ function eMin(euint256 lhs, euint256 rhs) external checked(lhs, rhs) returns (euint256 result) {
547
251
  result = euint256.wrap(
548
- createResultHandle(
549
- EOps.Min,
550
- ETypes.Uint256,
551
- abi.encodePacked(
552
- euint256.unwrap(lhs),
553
- euint256.unwrap(rhs)
554
- )
555
- )
252
+ createResultHandle(EOps.Min, ETypes.Uint256, abi.encodePacked(euint256.unwrap(lhs), euint256.unwrap(rhs)))
556
253
  );
557
254
  uint256 id = getNextEventId();
558
255
  emit EMin(lhs, rhs, result, id);
559
256
  setDigest(abi.encodePacked(result, id));
560
257
  }
561
258
 
562
- function eMax(
563
- euint256 lhs,
564
- euint256 rhs
565
- ) external checked(lhs, rhs) returns (euint256 result) {
259
+ function eMax(euint256 lhs, euint256 rhs) external checked(lhs, rhs) returns (euint256 result) {
566
260
  result = euint256.wrap(
567
- createResultHandle(
568
- EOps.Max,
569
- ETypes.Uint256,
570
- abi.encodePacked(
571
- euint256.unwrap(lhs),
572
- euint256.unwrap(rhs)
573
- )
574
- )
261
+ createResultHandle(EOps.Max, ETypes.Uint256, abi.encodePacked(euint256.unwrap(lhs), euint256.unwrap(rhs)))
575
262
  );
576
263
  uint256 id = getNextEventId();
577
264
  emit EMax(lhs, rhs, result, id);
@@ -580,18 +267,13 @@ abstract contract EncryptedOperations is
580
267
 
581
268
  function eNot(ebool operand) external returns (ebool result) {
582
269
  checkInput(ebool.unwrap(operand), typeToBitMask(ETypes.Bool));
583
- result = ebool.wrap(
584
- createResultHandle(EOps.Not, ETypes.Bool, abi.encodePacked(ebool.unwrap(operand)))
585
- );
270
+ result = ebool.wrap(createResultHandle(EOps.Not, ETypes.Bool, abi.encodePacked(ebool.unwrap(operand))));
586
271
  uint256 id = getNextEventId();
587
272
  emit ENot(operand, result, id);
588
273
  setDigest(abi.encodePacked(result, id));
589
274
  }
590
275
 
591
- function eCast(
592
- bytes32 ct,
593
- ETypes toType
594
- ) external returns (bytes32 result) {
276
+ function eCast(bytes32 ct, ETypes toType) external returns (bytes32 result) {
595
277
  bytes32 baseHandle = keccak256(abi.encodePacked(EOps.Cast, ct));
596
278
  result = embedTypeVersion(baseHandle, toType);
597
279
  allowTransientInternal(result, msg.sender);
@@ -600,56 +282,29 @@ abstract contract EncryptedOperations is
600
282
  setDigest(abi.encodePacked(result, id));
601
283
  }
602
284
 
603
- function eRand(
604
- ETypes randType
605
- ) external paying payable returns (bytes32 result) {
285
+ function eRand(ETypes randType) external payable paying returns (bytes32 result) {
606
286
  require(isTypeSupported(randType), UnsupportedType(randType));
607
287
  randCounter++;
608
- result = createResultHandle(
609
- EOps.Rand,
610
- randType,
611
- abi.encodePacked(bytes32(randCounter))
612
- );
288
+ result = createResultHandle(EOps.Rand, randType, abi.encodePacked(bytes32(randCounter)));
613
289
  uint256 id = getNextEventId();
614
290
  emit ERand(randCounter, randType, result, id);
615
291
  setDigest(abi.encodePacked(result, id));
616
292
  }
617
293
 
618
- function eRandBounded(
619
- bytes32 upperBound,
620
- ETypes randType
621
- ) external paying payable returns (bytes32 result) {
294
+ function eRandBounded(bytes32 upperBound, ETypes randType) external payable paying returns (bytes32 result) {
622
295
  require(isTypeSupported(randType), UnsupportedType(randType));
623
296
  checkInput(upperBound, typeToBitMask(ETypes.Uint256));
624
297
  randCounter++;
625
- result = createResultHandle(
626
- EOps.RandBounded,
627
- randType,
628
- abi.encodePacked(
629
- bytes32(randCounter),
630
- upperBound
631
- )
632
- );
298
+ result = createResultHandle(EOps.RandBounded, randType, abi.encodePacked(bytes32(randCounter), upperBound));
633
299
  uint256 id = getNextEventId();
634
300
  emit ERandBounded(randCounter, randType, upperBound, result, id);
635
301
  setDigest(abi.encodePacked(result, id));
636
302
  }
637
303
 
638
304
  // todo add support in testing framework
639
- function eIfThenElse(
640
- ebool control,
641
- bytes32 ifTrue,
642
- bytes32 ifFalse
643
- ) external returns (bytes32 result) {
305
+ function eIfThenElse(ebool control, bytes32 ifTrue, bytes32 ifFalse) external returns (bytes32 result) {
644
306
  ETypes returnType = checkEIfThenElseInputs(control, ifTrue, ifFalse);
645
- bytes32 baseHandle = keccak256(
646
- abi.encodePacked(
647
- EOps.IfThenElse,
648
- ebool.unwrap(control),
649
- ifTrue,
650
- ifFalse
651
- )
652
- );
307
+ bytes32 baseHandle = keccak256(abi.encodePacked(EOps.IfThenElse, ebool.unwrap(control), ifTrue, ifFalse));
653
308
  result = embedTypeVersion(baseHandle, returnType);
654
309
  allowTransientInternal(result, msg.sender);
655
310
  uint256 id = getNextEventId();
@@ -657,21 +312,19 @@ abstract contract EncryptedOperations is
657
312
  setDigest(abi.encodePacked(result, id));
658
313
  }
659
314
 
660
- function checkEIfThenElseInputs(
661
- ebool control,
662
- bytes32 ifTrue,
663
- bytes32 ifFalse
664
- ) internal view returns (ETypes ifTrueType) {
315
+ function checkEIfThenElseInputs(ebool control, bytes32 ifTrue, bytes32 ifFalse)
316
+ internal
317
+ view
318
+ returns (ETypes ifTrueType)
319
+ {
665
320
  checkInput(ebool.unwrap(control), typeToBitMask(ETypes.Bool));
666
321
  ifTrueType = typeOf(ifTrue);
667
322
  require(
668
323
  ifTrueType == ETypes.Uint256 || ifTrueType == ETypes.Bool || ifTrueType == ETypes.AddressOrUint160OrBytes20,
669
324
  UnsupportedType(ifTrueType)
670
325
  );
671
- require(
672
- isAllowed(ifTrue, msg.sender),
673
- SenderNotAllowedForHandle(ifTrue, msg.sender)
674
- );
326
+ require(isAllowed(ifTrue, msg.sender), SenderNotAllowedForHandle(ifTrue, msg.sender));
675
327
  checkInput(ifFalse, typeToBitMask(ifTrueType));
676
328
  }
329
+
677
330
  }