@inco/lightning 0.9.0-devnet-test-10 → 0.10.0-devnet-1
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/manifest.yaml +150 -0
- package/package.json +8 -8
- package/src/CreateXHelper.sol +1 -1
- package/src/DeployUtils.sol +22 -28
- package/src/IncoLightning.sol +27 -18
- package/src/IncoVerifier.sol +1 -1
- package/src/Lib.alphanet.sol +294 -13
- package/src/Lib.demonet.sol +294 -13
- package/src/Lib.devnet.sol +294 -13
- package/src/Lib.sol +294 -13
- package/src/Lib.template.sol +357 -13
- package/src/Lib.testnet.sol +294 -13
- package/src/Types.sol +44 -0
- package/src/interfaces/IIncoLightning.sol +8 -12
- package/src/interfaces/automata-interfaces/BELE.sol +1 -1
- package/src/interfaces/automata-interfaces/IPCCSRouter.sol +1 -1
- package/src/interfaces/automata-interfaces/IPcsDao.sol +1 -1
- package/src/interfaces/automata-interfaces/IQuoteVerifier.sol +1 -1
- package/src/interfaces/automata-interfaces/Types.sol +1 -1
- package/src/libs/incoLightning_alphanet_v0_297966649.sol +294 -13
- package/src/libs/incoLightning_alphanet_v1_725458969.sol +294 -13
- package/src/libs/incoLightning_alphanet_v2_976644394.sol +294 -13
- package/src/libs/incoLightning_demonet_v0_863421733.sol +294 -13
- package/src/libs/incoLightning_demonet_v2_467437523.sol +294 -13
- package/src/libs/incoLightning_devnet_v0_340846814.sol +294 -13
- package/src/libs/incoLightning_devnet_v10_266391127.sol +1223 -0
- package/src/libs/incoLightning_devnet_v1_904635675.sol +294 -13
- package/src/libs/incoLightning_devnet_v2_295237520.sol +294 -13
- package/src/libs/incoLightning_devnet_v3_976859633.sol +294 -13
- package/src/libs/incoLightning_devnet_v4_409204766.sol +294 -13
- package/src/libs/incoLightning_devnet_v5_203964628.sol +1223 -0
- package/src/libs/incoLightning_devnet_v6_281949651.sol +1223 -0
- package/src/libs/incoLightning_devnet_v7_24560427.sol +1223 -0
- package/src/libs/incoLightning_devnet_v8_985328058.sol +1223 -0
- package/src/libs/incoLightning_devnet_v9_269218568.sol +1223 -0
- package/src/libs/incoLightning_testnet_v0_183408998.sol +294 -13
- package/src/libs/incoLightning_testnet_v2_889158349.sol +294 -13
- package/src/lightning-parts/AccessControl/AdvancedAccessControl.sol +8 -3
- package/src/lightning-parts/AccessControl/BaseAccessControlList.sol +0 -16
- package/src/lightning-parts/AccessControl/interfaces/IAdvancedAccessControl.sol +1 -1
- package/src/lightning-parts/AccessControl/interfaces/IBaseAccessControlList.sol +3 -2
- package/src/lightning-parts/AccessControl/test/TestAdvancedAccessControl.t.sol +18 -1
- package/src/lightning-parts/AccessControl/test/TestBaseAccessControl.t.sol +0 -43
- package/src/lightning-parts/DecryptionAttester.sol +124 -2
- package/src/lightning-parts/DecryptionAttester.types.sol +20 -0
- package/src/lightning-parts/EList.sol +397 -0
- package/src/lightning-parts/EncryptedInput.sol +78 -8
- package/src/lightning-parts/EncryptedOperations.sol +40 -34
- package/src/lightning-parts/Fee.sol +29 -0
- package/src/lightning-parts/TEELifecycle.sol +38 -30
- package/src/lightning-parts/TEELifecycle.types.sol +1 -1
- package/src/lightning-parts/TrivialEncryption.sol +1 -2
- package/src/lightning-parts/interfaces/IDecryptionAttester.sol +16 -1
- package/src/lightning-parts/interfaces/IEList.sol +38 -0
- package/src/lightning-parts/interfaces/IEncryptedInput.sol +9 -1
- package/src/lightning-parts/interfaces/IEncryptedOperations.sol +3 -2
- package/src/lightning-parts/interfaces/ITEELifecycle.sol +1 -1
- package/src/lightning-parts/interfaces/ITrivialEncryption.sol +3 -1
- package/src/lightning-parts/primitives/EListHandleGeneration.sol +66 -0
- package/src/lightning-parts/primitives/EListHandleMetadata.sol +67 -0
- package/src/lightning-parts/primitives/HandleGeneration.sol +31 -8
- package/src/lightning-parts/primitives/HandleMetadata.sol +10 -3
- package/src/lightning-parts/primitives/interfaces/IEListHandleMetadata.sol +8 -0
- package/src/lightning-parts/primitives/test/SignatureVerifier.t.sol +1 -1
- package/src/lightning-parts/test/Elist.t.sol +218 -0
- package/src/lightning-parts/test/HandleMetadata.t.sol +66 -23
- package/src/lightning-parts/test/TestDecryptionAttestationInSynchronousFlow.t.sol +41 -13
- package/src/misc/ABIHelper.sol +15 -0
- package/src/pasted-dependencies/ICreateX.sol +1 -1
- package/src/periphery/IncoUtils.sol +1 -1
- package/src/periphery/SessionVerifier.sol +4 -4
- package/src/shared/IOwnable.sol +1 -1
- package/src/shared/IUUPSUpgradable.sol +1 -1
- package/src/shared/TestUtils.sol +8 -1
- package/src/test/EListTester.sol +171 -0
- package/src/test/FakeIncoInfra/FakeComputeServer.sol +2 -2
- package/src/test/FakeIncoInfra/FakeIncoInfraBase.sol +3 -3
- package/src/test/FakeIncoInfra/MockOpHandler.sol +7 -9
- package/src/test/FakeIncoInfra/MockRemoteAttestation.sol +2 -1
- package/src/test/FakeIncoInfra/getOpForSelector.sol +0 -2
- package/src/test/IncoTest.sol +17 -5
- package/src/test/OpsTest.sol +3 -2
- package/src/test/TEELifecycle/TEELifecycleMockTest.t.sol +85 -57
- package/src/test/TestDeploy.t.sol +73 -1
- package/src/test/TestFakeInfra.t.sol +32 -6
- package/src/test/TestLib.t.sol +986 -19
- package/src/test/TestReceive.t.sol +42 -0
- package/src/test/TestUpgrade.t.sol +34 -63
- package/src/version/IncoLightningConfig.sol +1 -1
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
// SPDX-License-Identifier: UNLICENSED
|
|
2
|
-
pragma solidity ^0.8
|
|
2
|
+
pragma solidity ^0.8;
|
|
3
3
|
|
|
4
4
|
import {TEELifecycle} from "../../lightning-parts/TEELifecycle.sol";
|
|
5
5
|
import {BootstrapResult, AddNodeResult, UpgradeResult} from "../../lightning-parts/TEELifecycle.types.sol";
|
|
@@ -24,7 +24,8 @@ contract TEELifecycleMockTest is MockRemoteAttestation, TEELifecycle {
|
|
|
24
24
|
hex"010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101";
|
|
25
25
|
// See DEFAULT_MR_AGGREGATED in attestation/src/remote_attestation.rs to
|
|
26
26
|
// see the calculation of the default value.
|
|
27
|
-
|
|
27
|
+
// Note: This uses abi.encode (not encodePacked) to avoid hash collision vulnerabilities.
|
|
28
|
+
bytes32 testMrAggregated = hex"3d48a1faa8620d86ae037f4fd6746987733d085314b3cd5d5d074ade8bab6ebd";
|
|
28
29
|
|
|
29
30
|
function setUp() public {
|
|
30
31
|
getTeeLifecycleStorage().quoteVerifier = new FakeQuoteVerifier();
|
|
@@ -133,61 +134,6 @@ contract TEELifecycleMockTest is MockRemoteAttestation, TEELifecycle {
|
|
|
133
134
|
vm.stopPrank();
|
|
134
135
|
}
|
|
135
136
|
|
|
136
|
-
function testRemoveApprovedTeeVersionPreservesOrder() public {
|
|
137
|
-
bytes32 mrAggregated1 = hex"1111111111111111111111111111111111111111111111111111111111111111";
|
|
138
|
-
bytes32 mrAggregated2 = hex"2222222222222222222222222222222222222222222222222222222222222222";
|
|
139
|
-
bytes32 mrAggregated3 = hex"3333333333333333333333333333333333333333333333333333333333333333";
|
|
140
|
-
|
|
141
|
-
vm.startPrank(this.owner());
|
|
142
|
-
|
|
143
|
-
// Add three versions
|
|
144
|
-
this.approveNewTeeVersion(mrAggregated1);
|
|
145
|
-
this.approveNewTeeVersion(mrAggregated2);
|
|
146
|
-
this.approveNewTeeVersion(mrAggregated3);
|
|
147
|
-
|
|
148
|
-
// Verify all exist in order
|
|
149
|
-
assertEq(this.approvedTeeVersions(0), mrAggregated1);
|
|
150
|
-
assertEq(this.approvedTeeVersions(1), mrAggregated2);
|
|
151
|
-
assertEq(this.approvedTeeVersions(2), mrAggregated3);
|
|
152
|
-
|
|
153
|
-
// Remove the middle one (mrAggregated2)
|
|
154
|
-
this.removeApprovedTeeVersion(mrAggregated2);
|
|
155
|
-
|
|
156
|
-
// Verify insertion order is preserved: mrAggregated1 stays at 0, mrAggregated3 shifts to 1
|
|
157
|
-
assertEq(this.approvedTeeVersions(0), mrAggregated1);
|
|
158
|
-
assertEq(this.approvedTeeVersions(1), mrAggregated3);
|
|
159
|
-
|
|
160
|
-
// Verify index 2 is now out of bounds
|
|
161
|
-
vm.expectRevert(TEELifecycle.IndexOutOfBounds.selector);
|
|
162
|
-
this.approvedTeeVersions(2);
|
|
163
|
-
|
|
164
|
-
vm.stopPrank();
|
|
165
|
-
}
|
|
166
|
-
|
|
167
|
-
function testRemoveApprovedTeeVersionNotFound() public {
|
|
168
|
-
bytes32 nonExistentMrAggregated = hex"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa";
|
|
169
|
-
|
|
170
|
-
vm.startPrank(this.owner());
|
|
171
|
-
vm.expectRevert(TEELifecycle.TEEVersionNotFound.selector);
|
|
172
|
-
this.removeApprovedTeeVersion(nonExistentMrAggregated);
|
|
173
|
-
vm.stopPrank();
|
|
174
|
-
}
|
|
175
|
-
|
|
176
|
-
function testRemoveApprovedTeeVersionOnlyOwner() public {
|
|
177
|
-
bytes32 mrAggregated = hex"1111111111111111111111111111111111111111111111111111111111111111";
|
|
178
|
-
|
|
179
|
-
vm.startPrank(this.owner());
|
|
180
|
-
this.approveNewTeeVersion(mrAggregated);
|
|
181
|
-
vm.stopPrank();
|
|
182
|
-
|
|
183
|
-
// Try to remove as non-owner
|
|
184
|
-
address nonOwner = address(0x1234);
|
|
185
|
-
vm.startPrank(nonOwner);
|
|
186
|
-
vm.expectRevert();
|
|
187
|
-
this.removeApprovedTeeVersion(mrAggregated);
|
|
188
|
-
vm.stopPrank();
|
|
189
|
-
}
|
|
190
|
-
|
|
191
137
|
// Helper function to create a successful bootstrap result
|
|
192
138
|
function successfulBootstrapResult()
|
|
193
139
|
internal
|
|
@@ -310,6 +256,7 @@ contract TEELifecycleMockTest is MockRemoteAttestation, TEELifecycle {
|
|
|
310
256
|
|
|
311
257
|
function testVerifyUpgradeResult_BootstrapNotComplete() public {
|
|
312
258
|
UpgradeResult memory upgradeResult = UpgradeResult({networkPubkey: testNetworkPubkey});
|
|
259
|
+
vm.prank(this.owner());
|
|
313
260
|
vm.expectRevert(TEELifecycle.BootstrapNotComplete.selector);
|
|
314
261
|
this.verifyUpgradeResult(testMrAggregated, upgradeResult, hex"", hex"");
|
|
315
262
|
}
|
|
@@ -325,6 +272,7 @@ contract TEELifecycleMockTest is MockRemoteAttestation, TEELifecycle {
|
|
|
325
272
|
|
|
326
273
|
// Try upgrade with wrong network pubkey
|
|
327
274
|
UpgradeResult memory upgradeResult = UpgradeResult({networkPubkey: hex"deadbeef"});
|
|
275
|
+
vm.prank(this.owner());
|
|
328
276
|
vm.expectRevert(TEELifecycle.InvalidNetworkPubkey.selector);
|
|
329
277
|
this.verifyUpgradeResult(mrAggregated, upgradeResult, quote, signature);
|
|
330
278
|
}
|
|
@@ -341,6 +289,7 @@ contract TEELifecycleMockTest is MockRemoteAttestation, TEELifecycle {
|
|
|
341
289
|
// Try upgrade with unapproved MR_AGGREGATED
|
|
342
290
|
bytes32 unapprovedMr = bytes32(uint256(1234));
|
|
343
291
|
UpgradeResult memory upgradeResult = UpgradeResult({networkPubkey: testNetworkPubkey});
|
|
292
|
+
vm.prank(this.owner());
|
|
344
293
|
vm.expectRevert(TEELifecycle.TEEVersionNotFound.selector);
|
|
345
294
|
this.verifyUpgradeResult(unapprovedMr, upgradeResult, quote, signature);
|
|
346
295
|
}
|
|
@@ -449,4 +398,83 @@ contract TEELifecycleMockTest is MockRemoteAttestation, TEELifecycle {
|
|
|
449
398
|
);
|
|
450
399
|
}
|
|
451
400
|
|
|
401
|
+
// ============ Tests for reset() ============
|
|
402
|
+
|
|
403
|
+
function testReset_OnlyOwner() public {
|
|
404
|
+
address nonOwner = address(0x1234);
|
|
405
|
+
vm.startPrank(nonOwner);
|
|
406
|
+
vm.expectRevert();
|
|
407
|
+
this.reset();
|
|
408
|
+
vm.stopPrank();
|
|
409
|
+
}
|
|
410
|
+
|
|
411
|
+
function testReset_WithMultipleSigners() public {
|
|
412
|
+
// Complete bootstrap with first signer
|
|
413
|
+
(
|
|
414
|
+
BootstrapResult memory bootstrapResult,,
|
|
415
|
+
address bootstrapPartyAddress,
|
|
416
|
+
bytes memory quote,
|
|
417
|
+
bytes memory signature,
|
|
418
|
+
bytes32 mrAggregated
|
|
419
|
+
) = successfulBootstrapResult();
|
|
420
|
+
|
|
421
|
+
vm.startPrank(this.owner());
|
|
422
|
+
this.approveNewTeeVersion(mrAggregated);
|
|
423
|
+
this.verifyBootstrapResult(bootstrapResult, quote, signature);
|
|
424
|
+
|
|
425
|
+
// Add a second node
|
|
426
|
+
(uint256 newNodePrivkey, address newNodeAddress) = getLabeledKeyPair("newNode");
|
|
427
|
+
AddNodeResult memory addNodeResult = AddNodeResult({networkPubkey: testNetworkPubkey});
|
|
428
|
+
bytes memory addNodeSignature = signAddNodeResult(addNodeResult, newNodePrivkey);
|
|
429
|
+
bytes memory addNodeQuote = createQuote(testMrtd, newNodeAddress);
|
|
430
|
+
this.verifyAddNodeResult(mrAggregated, addNodeResult, addNodeQuote, addNodeSignature);
|
|
431
|
+
|
|
432
|
+
// Verify state before reset
|
|
433
|
+
assertTrue(this.isBootstrapComplete(), "Bootstrap should be complete before reset");
|
|
434
|
+
assertEq(this.networkPubkey(), testNetworkPubkey, "Network pubkey should be set before reset");
|
|
435
|
+
assertEq(this.approvedTeeVersions(0), mrAggregated, "Approved TEE version should exist before reset");
|
|
436
|
+
assertEq(this.getSignersCount(), 2, "Should have 2 signers before reset");
|
|
437
|
+
assertTrue(this.isSigner(bootstrapPartyAddress), "First signer should exist");
|
|
438
|
+
assertTrue(this.isSigner(newNodeAddress), "Second signer should exist");
|
|
439
|
+
|
|
440
|
+
// Call reset
|
|
441
|
+
this.reset();
|
|
442
|
+
|
|
443
|
+
// Verify all state has been cleared
|
|
444
|
+
assertFalse(this.isBootstrapComplete(), "Bootstrap should not be complete after reset");
|
|
445
|
+
assertEq(this.networkPubkey().length, 0, "Network pubkey should be empty after reset");
|
|
446
|
+
assertEq(this.getSignersCount(), 0, "Should have 0 signers after reset");
|
|
447
|
+
assertFalse(this.isSigner(bootstrapPartyAddress), "First signer should be removed");
|
|
448
|
+
assertFalse(this.isSigner(newNodeAddress), "Second signer should be removed");
|
|
449
|
+
assertEq(this.getThreshold(), 0, "Threshold should be 0 after reset");
|
|
450
|
+
|
|
451
|
+
// Verify approved TEE versions array is empty
|
|
452
|
+
vm.expectRevert(TEELifecycle.IndexOutOfBounds.selector);
|
|
453
|
+
this.approvedTeeVersions(0);
|
|
454
|
+
|
|
455
|
+
vm.stopPrank();
|
|
456
|
+
}
|
|
457
|
+
|
|
458
|
+
function testReset_AllowsNewBootstrap() public {
|
|
459
|
+
// Complete bootstrap
|
|
460
|
+
(BootstrapResult memory bootstrapResult,,, bytes memory quote, bytes memory signature, bytes32 mrAggregated) =
|
|
461
|
+
successfulBootstrapResult();
|
|
462
|
+
|
|
463
|
+
vm.startPrank(this.owner());
|
|
464
|
+
this.approveNewTeeVersion(mrAggregated);
|
|
465
|
+
this.verifyBootstrapResult(bootstrapResult, quote, signature);
|
|
466
|
+
assertTrue(this.isBootstrapComplete(), "Bootstrap should be complete");
|
|
467
|
+
|
|
468
|
+
// Reset the contract
|
|
469
|
+
this.reset();
|
|
470
|
+
assertFalse(this.isBootstrapComplete(), "Bootstrap should not be complete after reset");
|
|
471
|
+
|
|
472
|
+
// Should be able to bootstrap again
|
|
473
|
+
this.approveNewTeeVersion(mrAggregated);
|
|
474
|
+
this.verifyBootstrapResult(bootstrapResult, quote, signature);
|
|
475
|
+
assertTrue(this.isBootstrapComplete(), "Should be able to bootstrap again after reset");
|
|
476
|
+
|
|
477
|
+
vm.stopPrank();
|
|
478
|
+
}
|
|
479
|
+
|
|
452
480
|
}
|
|
@@ -1,12 +1,14 @@
|
|
|
1
1
|
// SPDX-License-Identifier: No License
|
|
2
2
|
pragma solidity ^0.8;
|
|
3
3
|
|
|
4
|
-
import {Test} from "forge-std/Test.sol";
|
|
4
|
+
import {Test, Vm} from "forge-std/Test.sol";
|
|
5
5
|
import {TrivialEncryption} from "../lightning-parts/TrivialEncryption.sol";
|
|
6
6
|
import {ETypes} from "../Types.sol";
|
|
7
7
|
import {UUPSUpgradeable} from "@openzeppelin/contracts/proxy/utils/UUPSUpgradeable.sol";
|
|
8
|
+
import {OwnableUpgradeable} from "@openzeppelin/contracts-upgradeable/access/OwnableUpgradeable.sol";
|
|
8
9
|
import {inco} from "../Lib.sol";
|
|
9
10
|
import {IncoTest} from "./IncoTest.sol";
|
|
11
|
+
import {IEncryptedInput} from "../lightning-parts/interfaces/IEncryptedInput.sol";
|
|
10
12
|
|
|
11
13
|
contract ReturnTwo is UUPSUpgradeable {
|
|
12
14
|
|
|
@@ -26,6 +28,7 @@ contract TestDeploy is Test, IncoTest {
|
|
|
26
28
|
vm.expectEmit(false, false, true, false, address(inco));
|
|
27
29
|
emit TrivialEncryption.TrivialEncrypt(bytes32(uint256(1)), bytes32(uint256(1)), ETypes.Bool, 0);
|
|
28
30
|
inco.asEbool(true);
|
|
31
|
+
assertTrue(inco.isAcceptedVersion(2));
|
|
29
32
|
}
|
|
30
33
|
|
|
31
34
|
function testUpgrade() public {
|
|
@@ -35,4 +38,73 @@ contract TestDeploy is Test, IncoTest {
|
|
|
35
38
|
assertEq(ReturnTwo(address(inco)).getTwo(), 2);
|
|
36
39
|
}
|
|
37
40
|
|
|
41
|
+
function testAddAcceptedVersion() public {
|
|
42
|
+
assertFalse(inco.isAcceptedVersion(42));
|
|
43
|
+
vm.prank(owner);
|
|
44
|
+
inco.addAcceptedVersion(42);
|
|
45
|
+
assertTrue(inco.isAcceptedVersion(42));
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
function testAddAcceptedVersion_EmitsVersionAccepted() public {
|
|
49
|
+
vm.recordLogs();
|
|
50
|
+
vm.prank(owner);
|
|
51
|
+
inco.addAcceptedVersion(42);
|
|
52
|
+
|
|
53
|
+
Vm.Log[] memory logs = vm.getRecordedLogs();
|
|
54
|
+
bytes32 expectedTopic0 = keccak256("VersionAccepted(uint16)");
|
|
55
|
+
bool found = false;
|
|
56
|
+
for (uint256 i = 0; i < logs.length; i++) {
|
|
57
|
+
if (logs[i].topics[0] == expectedTopic0) {
|
|
58
|
+
found = true;
|
|
59
|
+
// version is indexed: must appear in topics[1], not in data
|
|
60
|
+
assertEq(logs[i].topics[1], bytes32(uint256(42)), "version should be an indexed topic");
|
|
61
|
+
assertEq(logs[i].data.length, 0, "data should be empty since version is indexed");
|
|
62
|
+
break;
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
assertTrue(found, "VersionAccepted event was not emitted");
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
function testAddAcceptedVersionNotOwner() public {
|
|
69
|
+
vm.expectRevert(abi.encodeWithSelector(OwnableUpgradeable.OwnableUnauthorizedAccount.selector, alice));
|
|
70
|
+
vm.prank(alice);
|
|
71
|
+
inco.addAcceptedVersion(42);
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
function testRemoveAcceptedVersion() public {
|
|
75
|
+
assertFalse(inco.isAcceptedVersion(42));
|
|
76
|
+
vm.prank(owner);
|
|
77
|
+
inco.removeAcceptedVersion(42); // removing a non-existent version should be no-op
|
|
78
|
+
assertFalse(inco.isAcceptedVersion(42));
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
function testRemoveAcceptedVersion_EmitsVersionRemoved() public {
|
|
82
|
+
vm.prank(owner);
|
|
83
|
+
inco.addAcceptedVersion(42);
|
|
84
|
+
|
|
85
|
+
vm.recordLogs();
|
|
86
|
+
vm.prank(owner);
|
|
87
|
+
inco.removeAcceptedVersion(42);
|
|
88
|
+
|
|
89
|
+
Vm.Log[] memory logs = vm.getRecordedLogs();
|
|
90
|
+
bytes32 expectedTopic0 = keccak256("VersionRemoved(uint16)");
|
|
91
|
+
bool found = false;
|
|
92
|
+
for (uint256 i = 0; i < logs.length; i++) {
|
|
93
|
+
if (logs[i].topics[0] == expectedTopic0) {
|
|
94
|
+
found = true;
|
|
95
|
+
// version is indexed: must appear in topics[1], not in data
|
|
96
|
+
assertEq(logs[i].topics[1], bytes32(uint256(42)), "version should be an indexed topic");
|
|
97
|
+
assertEq(logs[i].data.length, 0, "data should be empty since version is indexed");
|
|
98
|
+
break;
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
assertTrue(found, "VersionRemoved event was not emitted");
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
function testRemoveAcceptedVersionNotOwner() public {
|
|
105
|
+
vm.expectRevert(abi.encodeWithSelector(OwnableUpgradeable.OwnableUnauthorizedAccount.selector, alice));
|
|
106
|
+
vm.prank(alice);
|
|
107
|
+
inco.removeAcceptedVersion(42);
|
|
108
|
+
}
|
|
109
|
+
|
|
38
110
|
}
|
|
@@ -3,7 +3,7 @@ pragma solidity ^0.8;
|
|
|
3
3
|
|
|
4
4
|
import {IncoTest} from "./IncoTest.sol";
|
|
5
5
|
import {e, euint256, ebool, eaddress, inco} from "../Lib.sol";
|
|
6
|
-
import {SenderNotAllowedForHandle} from "../Types.sol";
|
|
6
|
+
import {SenderNotAllowedForHandle, UnsupportedType, ETypes, UnexpectedType, typeToBitMask} from "../Types.sol";
|
|
7
7
|
import {TEELifecycle} from "../lightning-parts/TEELifecycle.sol";
|
|
8
8
|
import {Td10ReportBody, MINIMUM_QUOTE_LENGTH} from "../interfaces/automata-interfaces/Types.sol";
|
|
9
9
|
|
|
@@ -96,6 +96,14 @@ contract TestFakeInfra is IncoTest {
|
|
|
96
96
|
assertEq(getUint256Value(c), 2);
|
|
97
97
|
}
|
|
98
98
|
|
|
99
|
+
function testEDiv_DivisionByZeroReturnsMaxUint256() public {
|
|
100
|
+
euint256 a = e.asEuint256(10);
|
|
101
|
+
euint256 zero = e.asEuint256(0);
|
|
102
|
+
euint256 c = a.div(zero);
|
|
103
|
+
processAllOperations();
|
|
104
|
+
assertEq(getUint256Value(c), type(uint256).max);
|
|
105
|
+
}
|
|
106
|
+
|
|
99
107
|
function testERem() public {
|
|
100
108
|
euint256 a = e.asEuint256(10);
|
|
101
109
|
euint256 b = e.asEuint256(4);
|
|
@@ -104,6 +112,14 @@ contract TestFakeInfra is IncoTest {
|
|
|
104
112
|
assertEq(getUint256Value(c), 2);
|
|
105
113
|
}
|
|
106
114
|
|
|
115
|
+
function testERem_RemainderByZeroReturnsLhs() public {
|
|
116
|
+
euint256 a = e.asEuint256(10);
|
|
117
|
+
euint256 zero = e.asEuint256(0);
|
|
118
|
+
euint256 c = a.rem(zero);
|
|
119
|
+
processAllOperations();
|
|
120
|
+
assertEq(getUint256Value(c), 10);
|
|
121
|
+
}
|
|
122
|
+
|
|
107
123
|
function testEAnd() public {
|
|
108
124
|
euint256 a = e.asEuint256(10);
|
|
109
125
|
euint256 b = e.asEuint256(4);
|
|
@@ -514,11 +530,10 @@ contract TestFakeInfra is IncoTest {
|
|
|
514
530
|
assertEq(getUint256Value(resB), 4);
|
|
515
531
|
}
|
|
516
532
|
|
|
517
|
-
function
|
|
533
|
+
function testECastToEBoolRevert() public {
|
|
518
534
|
euint256 a = e.asEuint256(1);
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
assertEq(getBoolValue(b), true);
|
|
535
|
+
vm.expectRevert(abi.encodeWithSelector(UnsupportedType.selector, ETypes.Bool));
|
|
536
|
+
inco.eCast(euint256.unwrap(a), ETypes.Bool);
|
|
522
537
|
}
|
|
523
538
|
|
|
524
539
|
function testECastToFromEBool() public {
|
|
@@ -557,7 +572,7 @@ contract TestFakeInfra is IncoTest {
|
|
|
557
572
|
function testECastAllowed() public {
|
|
558
573
|
bytes32 invalidHandle = keccak256("invalid handle");
|
|
559
574
|
vm.expectRevert(abi.encodeWithSelector(SenderNotAllowedForHandle.selector, invalidHandle, address(this)));
|
|
560
|
-
|
|
575
|
+
ebool.wrap(invalidHandle).asEuint256();
|
|
561
576
|
}
|
|
562
577
|
|
|
563
578
|
function testUninitializedHandleIsDisallowed_Add_Lhs() public {
|
|
@@ -1104,4 +1119,15 @@ contract TestFakeInfra is IncoTest {
|
|
|
1104
1119
|
assertEq(quote.length, MINIMUM_QUOTE_LENGTH);
|
|
1105
1120
|
}
|
|
1106
1121
|
|
|
1122
|
+
function testRandBoundedUpperBoundLargerThanRandType() public {
|
|
1123
|
+
euint256 upperBound = e.asEuint256(type(uint256).max);
|
|
1124
|
+
uint256 fee = inco.getFee();
|
|
1125
|
+
vm.expectRevert(
|
|
1126
|
+
abi.encodeWithSelector(
|
|
1127
|
+
UnexpectedType.selector, ETypes.Uint256, typeToBitMask(ETypes.AddressOrUint160OrBytes20)
|
|
1128
|
+
)
|
|
1129
|
+
);
|
|
1130
|
+
inco.eRandBounded{value: fee}(euint256.unwrap(upperBound), ETypes.AddressOrUint160OrBytes20);
|
|
1131
|
+
}
|
|
1132
|
+
|
|
1107
1133
|
}
|