@inco/lightning 0.9.0-devnet-test-10 → 0.10.0-devnet-2

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 (89) hide show
  1. package/manifest.yaml +150 -0
  2. package/package.json +8 -8
  3. package/src/CreateXHelper.sol +1 -1
  4. package/src/DeployUtils.sol +22 -28
  5. package/src/IncoLightning.sol +27 -18
  6. package/src/IncoVerifier.sol +1 -1
  7. package/src/Lib.alphanet.sol +294 -13
  8. package/src/Lib.demonet.sol +294 -13
  9. package/src/Lib.devnet.sol +294 -13
  10. package/src/Lib.sol +294 -13
  11. package/src/Lib.template.sol +357 -13
  12. package/src/Lib.testnet.sol +294 -13
  13. package/src/Types.sol +44 -0
  14. package/src/interfaces/IIncoLightning.sol +8 -12
  15. package/src/interfaces/automata-interfaces/BELE.sol +1 -1
  16. package/src/interfaces/automata-interfaces/IPCCSRouter.sol +1 -1
  17. package/src/interfaces/automata-interfaces/IPcsDao.sol +1 -1
  18. package/src/interfaces/automata-interfaces/IQuoteVerifier.sol +1 -1
  19. package/src/interfaces/automata-interfaces/Types.sol +1 -1
  20. package/src/libs/incoLightning_alphanet_v0_297966649.sol +294 -13
  21. package/src/libs/incoLightning_alphanet_v1_725458969.sol +294 -13
  22. package/src/libs/incoLightning_alphanet_v2_976644394.sol +294 -13
  23. package/src/libs/incoLightning_demonet_v0_863421733.sol +294 -13
  24. package/src/libs/incoLightning_demonet_v2_467437523.sol +294 -13
  25. package/src/libs/incoLightning_devnet_v0_340846814.sol +294 -13
  26. package/src/libs/incoLightning_devnet_v10_266391127.sol +1223 -0
  27. package/src/libs/incoLightning_devnet_v1_904635675.sol +294 -13
  28. package/src/libs/incoLightning_devnet_v2_295237520.sol +294 -13
  29. package/src/libs/incoLightning_devnet_v3_976859633.sol +294 -13
  30. package/src/libs/incoLightning_devnet_v4_409204766.sol +294 -13
  31. package/src/libs/incoLightning_devnet_v5_203964628.sol +1223 -0
  32. package/src/libs/incoLightning_devnet_v6_281949651.sol +1223 -0
  33. package/src/libs/incoLightning_devnet_v7_24560427.sol +1223 -0
  34. package/src/libs/incoLightning_devnet_v8_985328058.sol +1223 -0
  35. package/src/libs/incoLightning_devnet_v9_269218568.sol +1223 -0
  36. package/src/libs/incoLightning_testnet_v0_183408998.sol +294 -13
  37. package/src/libs/incoLightning_testnet_v2_889158349.sol +294 -13
  38. package/src/lightning-parts/AccessControl/AdvancedAccessControl.sol +8 -3
  39. package/src/lightning-parts/AccessControl/BaseAccessControlList.sol +0 -16
  40. package/src/lightning-parts/AccessControl/interfaces/IAdvancedAccessControl.sol +1 -1
  41. package/src/lightning-parts/AccessControl/interfaces/IBaseAccessControlList.sol +3 -2
  42. package/src/lightning-parts/AccessControl/test/TestAdvancedAccessControl.t.sol +18 -1
  43. package/src/lightning-parts/AccessControl/test/TestBaseAccessControl.t.sol +0 -43
  44. package/src/lightning-parts/DecryptionAttester.sol +124 -2
  45. package/src/lightning-parts/DecryptionAttester.types.sol +20 -0
  46. package/src/lightning-parts/EList.sol +397 -0
  47. package/src/lightning-parts/EncryptedInput.sol +78 -8
  48. package/src/lightning-parts/EncryptedOperations.sol +40 -34
  49. package/src/lightning-parts/Fee.sol +29 -0
  50. package/src/lightning-parts/TEELifecycle.sol +38 -30
  51. package/src/lightning-parts/TEELifecycle.types.sol +1 -1
  52. package/src/lightning-parts/TrivialEncryption.sol +1 -2
  53. package/src/lightning-parts/interfaces/IDecryptionAttester.sol +16 -1
  54. package/src/lightning-parts/interfaces/IEList.sol +38 -0
  55. package/src/lightning-parts/interfaces/IEncryptedInput.sol +9 -1
  56. package/src/lightning-parts/interfaces/IEncryptedOperations.sol +3 -2
  57. package/src/lightning-parts/interfaces/ITEELifecycle.sol +1 -1
  58. package/src/lightning-parts/interfaces/ITrivialEncryption.sol +3 -1
  59. package/src/lightning-parts/primitives/EListHandleGeneration.sol +66 -0
  60. package/src/lightning-parts/primitives/EListHandleMetadata.sol +67 -0
  61. package/src/lightning-parts/primitives/HandleGeneration.sol +31 -8
  62. package/src/lightning-parts/primitives/HandleMetadata.sol +10 -3
  63. package/src/lightning-parts/primitives/interfaces/IEListHandleMetadata.sol +8 -0
  64. package/src/lightning-parts/primitives/test/SignatureVerifier.t.sol +1 -1
  65. package/src/lightning-parts/test/Elist.t.sol +218 -0
  66. package/src/lightning-parts/test/HandleMetadata.t.sol +66 -23
  67. package/src/lightning-parts/test/TestDecryptionAttestationInSynchronousFlow.t.sol +41 -13
  68. package/src/misc/ABIHelper.sol +15 -0
  69. package/src/pasted-dependencies/ICreateX.sol +1 -1
  70. package/src/periphery/IncoUtils.sol +1 -1
  71. package/src/periphery/SessionVerifier.sol +4 -4
  72. package/src/shared/IOwnable.sol +1 -1
  73. package/src/shared/IUUPSUpgradable.sol +1 -1
  74. package/src/shared/TestUtils.sol +8 -1
  75. package/src/test/EListTester.sol +171 -0
  76. package/src/test/FakeIncoInfra/FakeComputeServer.sol +2 -2
  77. package/src/test/FakeIncoInfra/FakeIncoInfraBase.sol +3 -3
  78. package/src/test/FakeIncoInfra/MockOpHandler.sol +7 -9
  79. package/src/test/FakeIncoInfra/MockRemoteAttestation.sol +2 -1
  80. package/src/test/FakeIncoInfra/getOpForSelector.sol +0 -2
  81. package/src/test/IncoTest.sol +17 -5
  82. package/src/test/OpsTest.sol +3 -2
  83. package/src/test/TEELifecycle/TEELifecycleMockTest.t.sol +85 -57
  84. package/src/test/TestDeploy.t.sol +73 -1
  85. package/src/test/TestFakeInfra.t.sol +32 -6
  86. package/src/test/TestLib.t.sol +986 -19
  87. package/src/test/TestReceive.t.sol +42 -0
  88. package/src/test/TestUpgrade.t.sol +34 -63
  89. package/src/version/IncoLightningConfig.sol +1 -1
@@ -0,0 +1,42 @@
1
+ // SPDX-License-Identifier: No License
2
+ pragma solidity ^0.8;
3
+
4
+ import {inco} from "../Lib.sol";
5
+ import {IncoTest} from "./IncoTest.sol";
6
+ import {IIncoLightning} from "../interfaces/IIncoLightning.sol";
7
+
8
+ contract TestReceive is IncoTest {
9
+
10
+ function setUp() public override {
11
+ super.setUp();
12
+ }
13
+
14
+ function testReceive_Reverts() public {
15
+ uint256 sendAmount = 1 ether;
16
+ vm.deal(alice, sendAmount);
17
+ vm.prank(alice);
18
+ (bool success, bytes memory returnData) = address(inco).call{value: sendAmount}("");
19
+
20
+ assertFalse(success, "ETH transfer should revert");
21
+ bytes4 expectedSelector = IIncoLightning.EthInboundTransferUnsupported.selector;
22
+ bytes4 actualSelector;
23
+ assembly {
24
+ actualSelector := mload(add(returnData, 32))
25
+ }
26
+ assertEq(actualSelector, expectedSelector, "Should revert with EthInboundTransferUnsupported");
27
+ }
28
+
29
+ function testReceive_ZeroValue_Reverts() public {
30
+ vm.prank(alice);
31
+ (bool success, bytes memory returnData) = address(inco).call{value: 0}("");
32
+
33
+ assertFalse(success, "Zero value transfer should also revert");
34
+ bytes4 expectedSelector = IIncoLightning.EthInboundTransferUnsupported.selector;
35
+ bytes4 actualSelector;
36
+ assembly {
37
+ actualSelector := mload(add(returnData, 32))
38
+ }
39
+ assertEq(actualSelector, expectedSelector, "Should revert with EthInboundTransferUnsupported");
40
+ }
41
+
42
+ }
@@ -1,9 +1,8 @@
1
1
  // SPDX-License-Identifier: No License
2
- pragma solidity ^0.8.20;
2
+ pragma solidity ^0.8;
3
3
 
4
4
  import {Strings} from "@openzeppelin/contracts/utils/Strings.sol";
5
5
  import {Safe} from "safe-smart-account/Safe.sol";
6
- import {SafeProxyFactory} from "safe-smart-account/proxies/SafeProxyFactory.sol";
7
6
  import {Enum} from "safe-smart-account/libraries/Enum.sol";
8
7
  import {IOwnerManager} from "safe-smart-account/interfaces/IOwnerManager.sol";
9
8
  import {IncoTest} from "./IncoTest.sol";
@@ -49,36 +48,14 @@ contract TestUpgrade is IncoTest {
49
48
  IncoLightning private v1Impl;
50
49
  IncoLightningV2 private v2Impl;
51
50
 
52
- Safe private safe;
51
+ function safe() internal view returns (Safe) {
52
+ return Safe(payable(owner));
53
+ }
53
54
 
54
55
  function setUp() public override {
55
56
  super.setUp();
56
57
  incoProxyAddr = address(inco);
57
58
 
58
- Safe master = new Safe();
59
- SafeProxyFactory factory = new SafeProxyFactory();
60
-
61
- address[] memory owners = new address[](3);
62
- owners[0] = alice;
63
- owners[1] = bob;
64
- owners[2] = carol;
65
- uint256 threshold = 2;
66
- bytes memory setupData = abi.encodeWithSelector(
67
- Safe.setup.selector,
68
- owners,
69
- threshold,
70
- address(0),
71
- bytes(""),
72
- address(0),
73
- address(0),
74
- 0,
75
- payable(address(0))
76
- );
77
- safe = Safe(payable(factory.createProxyWithNonce(address(master), setupData, 0)));
78
-
79
- vm.prank(owner);
80
- inco.transferOwnership(address(safe));
81
-
82
59
  // Deploy V2
83
60
  bytes32 salt = getSalt("IncoLightningV2", 255, testDeployer, "testnet");
84
61
  v2Impl = new IncoLightningV2(salt);
@@ -99,14 +76,14 @@ contract TestUpgrade is IncoTest {
99
76
  // data to sign
100
77
  bytes memory data = abi.encodeWithSelector(IUUPS.upgradeToAndCall.selector, address(v2Impl), "");
101
78
  // prepare txhash
102
- bytes32 txHash = _txHash(safe, incoProxyAddr, 0, data);
79
+ bytes32 txHash = _txHash(safe(), incoProxyAddr, 0, data);
103
80
  // sign txHash
104
81
  bytes memory sigA = _sign(alicePrivKey, txHash);
105
82
  bytes memory sigB = _sign(bobPrivKey, txHash);
106
83
  // sort signatures (asc)
107
84
  bytes memory signatures = _packSortedTwo(sigA, alice, sigB, bob);
108
85
  // execute tx with sorted signatures
109
- _execSafe(safe, incoProxyAddr, 0, data, signatures);
86
+ _execSafe(safe(), incoProxyAddr, 0, data, signatures);
110
87
 
111
88
  address implAfter = address(uint160(uint256(vm.load(incoProxyAddr, IMPLEMENTATION_SLOT))));
112
89
  assertEq(implAfter, address(v2Impl));
@@ -117,75 +94,75 @@ contract TestUpgrade is IncoTest {
117
94
 
118
95
  function test_SafeSingleSignature_Fails() public {
119
96
  bytes memory data = abi.encodeWithSelector(IUUPS.upgradeToAndCall.selector, address(v2Impl), "");
120
- bytes32 txHash = _txHash(safe, incoProxyAddr, 0, data);
97
+ bytes32 txHash = _txHash(safe(), incoProxyAddr, 0, data);
121
98
  bytes memory sigA = _sign(alicePrivKey, txHash);
122
99
  vm.expectRevert();
123
- _execSafe(safe, incoProxyAddr, 0, data, sigA);
100
+ _execSafe(safe(), incoProxyAddr, 0, data, sigA);
124
101
  }
125
102
 
126
103
  function test_Safe_UnsortedSignatures_Fails() public {
127
104
  bytes memory data = abi.encodeWithSelector(IUUPS.upgradeToAndCall.selector, address(v2Impl), "");
128
- bytes32 txHash = _txHash(safe, incoProxyAddr, 0, data);
105
+ bytes32 txHash = _txHash(safe(), incoProxyAddr, 0, data);
129
106
  bytes memory sigA = _sign(alicePrivKey, txHash);
130
107
  bytes memory sigC = _sign(carolPrivKey, txHash);
131
108
  bytes memory signatures = bytes.concat(sigC, sigA); // unsorted
132
109
  vm.expectRevert();
133
- _execSafe(safe, incoProxyAddr, 0, data, signatures);
110
+ _execSafe(safe(), incoProxyAddr, 0, data, signatures);
134
111
  }
135
112
 
136
113
  function test_Safe_WrongSigner_Fails() public {
137
114
  bytes memory data = abi.encodeWithSelector(IUUPS.upgradeToAndCall.selector, address(v2Impl), "");
138
- bytes32 txHash = _txHash(safe, incoProxyAddr, 0, data);
115
+ bytes32 txHash = _txHash(safe(), incoProxyAddr, 0, data);
139
116
  bytes memory sigOwner = _sign(alicePrivKey, txHash);
140
117
  bytes memory sigAttacker = _sign(davePrivKey, txHash);
141
118
  bytes memory signatures = _packSortedTwo(sigOwner, alice, sigAttacker, dave); // dave not an owner
142
119
  vm.expectRevert();
143
- _execSafe(safe, incoProxyAddr, 0, data, signatures);
120
+ _execSafe(safe(), incoProxyAddr, 0, data, signatures);
144
121
  }
145
122
 
146
123
  function test_Safe_ReplayNonce_Fails() public {
147
124
  bytes memory data = abi.encodeWithSelector(IUUPS.upgradeToAndCall.selector, address(v2Impl), "");
148
- bytes32 txHash = _txHash(safe, incoProxyAddr, 0, data);
125
+ bytes32 txHash = _txHash(safe(), incoProxyAddr, 0, data);
149
126
  bytes memory sigA = _sign(alicePrivKey, txHash);
150
127
  bytes memory sigB = _sign(bobPrivKey, txHash);
151
128
  bytes memory signatures = _packSortedTwo(sigA, alice, sigB, bob);
152
- _execSafe(safe, incoProxyAddr, 0, data, signatures);
129
+ _execSafe(safe(), incoProxyAddr, 0, data, signatures);
153
130
 
154
131
  string memory versionAfter = inco.getVersion();
155
132
  assertEq(versionAfter, "255_255_255");
156
133
 
157
134
  vm.expectRevert();
158
- _execSafe(safe, incoProxyAddr, 0, data, signatures); // nonce advanced
135
+ _execSafe(safe(), incoProxyAddr, 0, data, signatures); // nonce advanced
159
136
  }
160
137
 
161
138
  function test_Safe_UpdateSigners_SwapOwner_ThenUpgrade() public {
162
139
  // swap bob -> eve (prevOwner = alice since owners were [alice, bob, carol])
163
140
  bytes memory change = abi.encodeWithSelector(IOwnerManager.swapOwner.selector, alice, bob, eve);
164
- bytes32 changeHash = _txHash(safe, address(safe), 0, change);
141
+ bytes32 changeHash = _txHash(safe(), address(safe()), 0, change);
165
142
  bytes memory changeSigA = _sign(alicePrivKey, changeHash);
166
143
  bytes memory changeSigC = _sign(carolPrivKey, changeHash);
167
144
  bytes memory changeSigs = _packSortedTwo(changeSigA, alice, changeSigC, carol);
168
- _execSafe(safe, address(safe), 0, change, changeSigs);
145
+ _execSafe(safe(), address(safe()), 0, change, changeSigs);
169
146
 
170
147
  // assertions on owners/threshold
171
- assertTrue(safe.isOwner(eve), "new owner not added");
172
- assertFalse(safe.isOwner(bob), "old owner not removed");
173
- assertEq(safe.getThreshold(), 2, "threshold changed unexpectedly");
148
+ assertTrue(safe().isOwner(eve), "new owner not added");
149
+ assertFalse(safe().isOwner(bob), "old owner not removed");
150
+ assertEq(safe().getThreshold(), 2, "threshold changed unexpectedly");
174
151
 
175
152
  // Attempt upgrade signed by removed owner should fail
176
153
  bytes memory upg = abi.encodeWithSelector(IUUPS.upgradeToAndCall.selector, address(v2Impl), "");
177
- bytes32 upgHash = _txHash(safe, incoProxyAddr, 0, upg);
154
+ bytes32 upgHash = _txHash(safe(), incoProxyAddr, 0, upg);
178
155
  bytes memory badSigA = _sign(alicePrivKey, upgHash);
179
156
  bytes memory badSigB = _sign(bobPrivKey, upgHash); // removed owner
180
157
  bytes memory badSigs = _packSortedTwo(badSigA, alice, badSigB, bob);
181
158
  vm.expectRevert();
182
- _execSafe(safe, incoProxyAddr, 0, upg, badSigs);
159
+ _execSafe(safe(), incoProxyAddr, 0, upg, badSigs);
183
160
 
184
161
  // Now sign with new owner (owner4) and succeed
185
162
  bytes memory goodSigA = _sign(alicePrivKey, upgHash);
186
163
  bytes memory goodSigE = _sign(evePrivKey, upgHash);
187
164
  bytes memory goodSigs = _packSortedTwo(goodSigA, alice, goodSigE, eve);
188
- _execSafe(safe, incoProxyAddr, 0, upg, goodSigs);
165
+ _execSafe(safe(), incoProxyAddr, 0, upg, goodSigs);
189
166
 
190
167
  address implAfter = address(uint160(uint256(vm.load(incoProxyAddr, IMPLEMENTATION_SLOT))));
191
168
  assertEq(implAfter, address(v2Impl));
@@ -195,7 +172,7 @@ contract TestUpgrade is IncoTest {
195
172
  }
196
173
 
197
174
  function test_Upgrade_NotBy_SafeWallet_Fails() public {
198
- vm.prank(owner);
175
+ vm.prank(alice);
199
176
  vm.expectRevert();
200
177
  inco.upgradeToAndCall(address(v2Impl), "");
201
178
  }
@@ -222,7 +199,7 @@ contract TestUpgrade is IncoTest {
222
199
  // Deploy a new IncoVerifier implementation
223
200
  IncoVerifier newImpl = new IncoVerifier(address(inco));
224
201
 
225
- // Upgrade by owner should succeed
202
+ // Upgrade by owner should succeed — owner is the Safe, so prank as Safe
226
203
  vm.prank(owner);
227
204
  verifier.upgradeToAndCall(address(newImpl), "");
228
205
  }
@@ -271,20 +248,12 @@ contract TestUpgrade is IncoTest {
271
248
  }
272
249
 
273
250
  function test_SessionVerifier_Initialize() public {
274
- SessionVerifier impl = new SessionVerifier("");
275
- ERC1967Proxy proxy = new ERC1967Proxy(address(impl), "");
276
- SessionVerifier verifier = SessionVerifier(address(proxy));
277
-
278
- verifier.initialize(alice);
251
+ SessionVerifier verifier = _deploySessionVerifierProxy(alice);
279
252
  assertEq(verifier.owner(), alice, "Owner should be alice after initialize");
280
253
  }
281
254
 
282
255
  function test_SessionVerifier_Upgrade_ByOwner_Succeeds() public {
283
- SessionVerifier impl = new SessionVerifier("");
284
- ERC1967Proxy proxy = new ERC1967Proxy(address(impl), "");
285
- SessionVerifier verifier = SessionVerifier(address(proxy));
286
-
287
- verifier.initialize(alice);
256
+ SessionVerifier verifier = _deploySessionVerifierProxy(alice);
288
257
 
289
258
  // Deploy new implementation
290
259
  SessionVerifier newImpl = new SessionVerifier("");
@@ -295,11 +264,7 @@ contract TestUpgrade is IncoTest {
295
264
  }
296
265
 
297
266
  function test_SessionVerifier_Upgrade_ByNonOwner_Fails() public {
298
- SessionVerifier impl = new SessionVerifier("");
299
- ERC1967Proxy proxy = new ERC1967Proxy(address(impl), "");
300
- SessionVerifier verifier = SessionVerifier(address(proxy));
301
-
302
- verifier.initialize(alice);
267
+ SessionVerifier verifier = _deploySessionVerifierProxy(alice);
303
268
 
304
269
  // Deploy new implementation
305
270
  SessionVerifier newImpl = new SessionVerifier("");
@@ -311,6 +276,12 @@ contract TestUpgrade is IncoTest {
311
276
  }
312
277
 
313
278
  // Helpers
279
+ function _deploySessionVerifierProxy(address proxyOwner) private returns (SessionVerifier) {
280
+ SessionVerifier impl = new SessionVerifier("");
281
+ ERC1967Proxy proxy = new ERC1967Proxy(address(impl), abi.encodeCall(SessionVerifier.initialize, (proxyOwner)));
282
+ return SessionVerifier(address(proxy));
283
+ }
284
+
314
285
  function _txHash(Safe _safe, address to, uint256 value, bytes memory data) internal view returns (bytes32) {
315
286
  return _safe.getTransactionHash(
316
287
  to, value, data, Enum.Operation.Call, 0, 0, 0, address(0), payable(address(0)), _safe.nonce()
@@ -7,7 +7,7 @@ pragma solidity ^0.8;
7
7
  // UPDATE the CHANGELOG on new versions
8
8
 
9
9
  string constant CONTRACT_NAME = "incoLightning";
10
- uint8 constant MAJOR_VERSION = 4;
10
+ uint8 constant MAJOR_VERSION = 10;
11
11
  uint8 constant MINOR_VERSION = 0;
12
12
  // whenever a new version is deployed, we need to pump this up
13
13
  // otherwise make test_upgrade will fail