@inco/lightning 0.8.0-devnet-7 → 0.8.0-devnet-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.
- package/manifest.yaml +22 -0
- package/package.json +1 -1
- package/src/CreateXHelper.sol +1 -1
- package/src/IncoLightning.sol +20 -7
- package/src/IncoVerifier.sol +1 -1
- package/src/Lib.devnet.sol +1 -1
- package/src/Lib.sol +1 -1
- package/src/interfaces/IIncoLightning.sol +4 -0
- 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_devnet_v5_203964628.sol +942 -0
- package/src/lightning-parts/AccessControl/AdvancedAccessControl.sol +4 -0
- package/src/lightning-parts/AccessControl/test/TestAdvancedAccessControl.t.sol +15 -0
- package/src/lightning-parts/EncryptedInput.sol +60 -5
- package/src/lightning-parts/TEELifecycle.sol +37 -29
- package/src/lightning-parts/TEELifecycle.types.sol +1 -1
- package/src/lightning-parts/interfaces/IEncryptedInput.sol +6 -0
- package/src/lightning-parts/interfaces/ITEELifecycle.sol +1 -1
- package/src/lightning-parts/primitives/HandleGeneration.sol +2 -2
- package/src/lightning-parts/primitives/test/SignatureVerifier.t.sol +1 -1
- package/src/lightning-parts/test/HandleMetadata.t.sol +59 -9
- package/src/pasted-dependencies/ICreateX.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/test/FakeIncoInfra/FakeIncoInfraBase.sol +3 -3
- package/src/test/FakeIncoInfra/MockRemoteAttestation.sol +2 -1
- package/src/test/TEELifecycle/TEELifecycleMockTest.t.sol +82 -57
- package/src/test/TestDeploy.t.sol +28 -0
- package/src/test/TestUpgrade.t.sol +1 -1
- 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
|
|
@@ -449,4 +395,83 @@ contract TEELifecycleMockTest is MockRemoteAttestation, TEELifecycle {
|
|
|
449
395
|
);
|
|
450
396
|
}
|
|
451
397
|
|
|
398
|
+
// ============ Tests for reset() ============
|
|
399
|
+
|
|
400
|
+
function testReset_OnlyOwner() public {
|
|
401
|
+
address nonOwner = address(0x1234);
|
|
402
|
+
vm.startPrank(nonOwner);
|
|
403
|
+
vm.expectRevert();
|
|
404
|
+
this.reset();
|
|
405
|
+
vm.stopPrank();
|
|
406
|
+
}
|
|
407
|
+
|
|
408
|
+
function testReset_WithMultipleSigners() public {
|
|
409
|
+
// Complete bootstrap with first signer
|
|
410
|
+
(
|
|
411
|
+
BootstrapResult memory bootstrapResult,,
|
|
412
|
+
address bootstrapPartyAddress,
|
|
413
|
+
bytes memory quote,
|
|
414
|
+
bytes memory signature,
|
|
415
|
+
bytes32 mrAggregated
|
|
416
|
+
) = successfulBootstrapResult();
|
|
417
|
+
|
|
418
|
+
vm.startPrank(this.owner());
|
|
419
|
+
this.approveNewTeeVersion(mrAggregated);
|
|
420
|
+
this.verifyBootstrapResult(bootstrapResult, quote, signature);
|
|
421
|
+
|
|
422
|
+
// Add a second node
|
|
423
|
+
(uint256 newNodePrivkey, address newNodeAddress) = getLabeledKeyPair("newNode");
|
|
424
|
+
AddNodeResult memory addNodeResult = AddNodeResult({networkPubkey: testNetworkPubkey});
|
|
425
|
+
bytes memory addNodeSignature = signAddNodeResult(addNodeResult, newNodePrivkey);
|
|
426
|
+
bytes memory addNodeQuote = createQuote(testMrtd, newNodeAddress);
|
|
427
|
+
this.verifyAddNodeResult(mrAggregated, addNodeResult, addNodeQuote, addNodeSignature);
|
|
428
|
+
|
|
429
|
+
// Verify state before reset
|
|
430
|
+
assertTrue(this.isBootstrapComplete(), "Bootstrap should be complete before reset");
|
|
431
|
+
assertEq(this.networkPubkey(), testNetworkPubkey, "Network pubkey should be set before reset");
|
|
432
|
+
assertEq(this.approvedTeeVersions(0), mrAggregated, "Approved TEE version should exist before reset");
|
|
433
|
+
assertEq(this.getSignersCount(), 2, "Should have 2 signers before reset");
|
|
434
|
+
assertTrue(this.isSigner(bootstrapPartyAddress), "First signer should exist");
|
|
435
|
+
assertTrue(this.isSigner(newNodeAddress), "Second signer should exist");
|
|
436
|
+
|
|
437
|
+
// Call reset
|
|
438
|
+
this.reset();
|
|
439
|
+
|
|
440
|
+
// Verify all state has been cleared
|
|
441
|
+
assertFalse(this.isBootstrapComplete(), "Bootstrap should not be complete after reset");
|
|
442
|
+
assertEq(this.networkPubkey().length, 0, "Network pubkey should be empty after reset");
|
|
443
|
+
assertEq(this.getSignersCount(), 0, "Should have 0 signers after reset");
|
|
444
|
+
assertFalse(this.isSigner(bootstrapPartyAddress), "First signer should be removed");
|
|
445
|
+
assertFalse(this.isSigner(newNodeAddress), "Second signer should be removed");
|
|
446
|
+
assertEq(this.getThreshold(), 0, "Threshold should be 0 after reset");
|
|
447
|
+
|
|
448
|
+
// Verify approved TEE versions array is empty
|
|
449
|
+
vm.expectRevert(TEELifecycle.IndexOutOfBounds.selector);
|
|
450
|
+
this.approvedTeeVersions(0);
|
|
451
|
+
|
|
452
|
+
vm.stopPrank();
|
|
453
|
+
}
|
|
454
|
+
|
|
455
|
+
function testReset_AllowsNewBootstrap() public {
|
|
456
|
+
// Complete bootstrap
|
|
457
|
+
(BootstrapResult memory bootstrapResult,,, bytes memory quote, bytes memory signature, bytes32 mrAggregated) =
|
|
458
|
+
successfulBootstrapResult();
|
|
459
|
+
|
|
460
|
+
vm.startPrank(this.owner());
|
|
461
|
+
this.approveNewTeeVersion(mrAggregated);
|
|
462
|
+
this.verifyBootstrapResult(bootstrapResult, quote, signature);
|
|
463
|
+
assertTrue(this.isBootstrapComplete(), "Bootstrap should be complete");
|
|
464
|
+
|
|
465
|
+
// Reset the contract
|
|
466
|
+
this.reset();
|
|
467
|
+
assertFalse(this.isBootstrapComplete(), "Bootstrap should not be complete after reset");
|
|
468
|
+
|
|
469
|
+
// Should be able to bootstrap again
|
|
470
|
+
this.approveNewTeeVersion(mrAggregated);
|
|
471
|
+
this.verifyBootstrapResult(bootstrapResult, quote, signature);
|
|
472
|
+
assertTrue(this.isBootstrapComplete(), "Should be able to bootstrap again after reset");
|
|
473
|
+
|
|
474
|
+
vm.stopPrank();
|
|
475
|
+
}
|
|
476
|
+
|
|
452
477
|
}
|
|
@@ -5,6 +5,7 @@ import {Test} 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";
|
|
10
11
|
|
|
@@ -26,6 +27,7 @@ contract TestDeploy is Test, IncoTest {
|
|
|
26
27
|
vm.expectEmit(false, false, true, false, address(inco));
|
|
27
28
|
emit TrivialEncryption.TrivialEncrypt(bytes32(uint256(1)), bytes32(uint256(1)), ETypes.Bool, 0);
|
|
28
29
|
inco.asEbool(true);
|
|
30
|
+
assertTrue(inco.isAcceptedVersion(2));
|
|
29
31
|
}
|
|
30
32
|
|
|
31
33
|
function testUpgrade() public {
|
|
@@ -35,4 +37,30 @@ contract TestDeploy is Test, IncoTest {
|
|
|
35
37
|
assertEq(ReturnTwo(address(inco)).getTwo(), 2);
|
|
36
38
|
}
|
|
37
39
|
|
|
40
|
+
function testAddAcceptedVersion() public {
|
|
41
|
+
assertFalse(inco.isAcceptedVersion(42));
|
|
42
|
+
vm.prank(owner);
|
|
43
|
+
inco.addAcceptedVersion(42);
|
|
44
|
+
assertTrue(inco.isAcceptedVersion(42));
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
function testAddAcceptedVersionNotOwner() public {
|
|
48
|
+
vm.expectRevert(abi.encodeWithSelector(OwnableUpgradeable.OwnableUnauthorizedAccount.selector, alice));
|
|
49
|
+
vm.prank(alice);
|
|
50
|
+
inco.addAcceptedVersion(42);
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
function testRemoveAcceptedVersion() public {
|
|
54
|
+
assertFalse(inco.isAcceptedVersion(42));
|
|
55
|
+
vm.prank(owner);
|
|
56
|
+
inco.removeAcceptedVersion(42); // removing a non-existent version should be no-op
|
|
57
|
+
assertFalse(inco.isAcceptedVersion(42));
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
function testRemoveAcceptedVersionNotOwner() public {
|
|
61
|
+
vm.expectRevert(abi.encodeWithSelector(OwnableUpgradeable.OwnableUnauthorizedAccount.selector, alice));
|
|
62
|
+
vm.prank(alice);
|
|
63
|
+
inco.removeAcceptedVersion(42);
|
|
64
|
+
}
|
|
65
|
+
|
|
38
66
|
}
|
|
@@ -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 =
|
|
10
|
+
uint8 constant MAJOR_VERSION = 5;
|
|
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
|