@inco/lightning 0.6.8 → 0.7.0
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/CHANGELOG.md +6 -0
- package/README.md +29 -2
- package/manifest.yaml +35 -42
- package/package.json +5 -2
- package/src/CreateXHelper.sol +3 -1
- package/src/DeployUtils.sol +36 -71
- package/src/Errors.sol +1 -1
- package/src/IIncoLightning.sol +2 -0
- package/src/IncoLightning.sol +5 -17
- package/src/IncoVerifier.sol +12 -18
- package/src/Lib.alphanet.sol +1 -1
- package/src/Lib.sol +1 -1
- package/src/Lib.template.sol +35 -153
- package/src/Types.sol +231 -97
- package/src/interfaces/IIncoLightning.sol +2 -0
- package/src/interfaces/IIncoVerifier.sol +6 -12
- package/src/interfaces/automata-interfaces/BELE.sol +2 -0
- package/src/interfaces/automata-interfaces/IAutomataEnclaveIdentityDao.sol +9 -11
- package/src/interfaces/automata-interfaces/IFmspcTcbDao.sol +3 -3
- package/src/interfaces/automata-interfaces/IPCCSRouter.sol +13 -47
- package/src/interfaces/automata-interfaces/IPCCSRouterExtended.sol +2 -0
- package/src/interfaces/automata-interfaces/IPcsDao.sol +6 -11
- package/src/interfaces/automata-interfaces/IQuoteVerifier.sol +4 -7
- package/src/interfaces/automata-interfaces/Types.sol +7 -6
- package/src/libs/incoLightning_alphanet_v2_976644394.sol +478 -0
- package/src/libs/incoLightning_devnet_v1_887305889.sol +5 -3
- package/src/libs/incoLightning_testnet_v1_938327937.sol +5 -3
- package/src/lightning-parts/AccessControl/AdvancedAccessControl.sol +39 -72
- package/src/lightning-parts/AccessControl/BaseAccessControlList.sol +31 -62
- package/src/lightning-parts/AccessControl/interfaces/IAdvancedAccessControl.sol +8 -15
- package/src/lightning-parts/AccessControl/interfaces/IBaseAccessControlList.sol +5 -12
- package/src/lightning-parts/AccessControl/test/TestAdvancedAccessControl.t.sol +44 -84
- package/src/lightning-parts/AccessControl/test/TestBaseAccessControl.t.sol +2 -0
- package/src/lightning-parts/DecryptionAttester.sol +14 -28
- package/src/lightning-parts/EncryptedInput.sol +23 -52
- package/src/lightning-parts/EncryptedOperations.sol +96 -438
- package/src/lightning-parts/Fee.sol +3 -1
- package/src/lightning-parts/TEELifecycle.sol +94 -223
- package/src/lightning-parts/TEELifecycle.types.sol +4 -3
- package/src/lightning-parts/TrivialEncryption.sol +6 -20
- package/src/lightning-parts/interfaces/IDecryptionAttester.sol +7 -2
- package/src/lightning-parts/interfaces/IEncryptedInput.sol +5 -12
- package/src/lightning-parts/interfaces/IEncryptedOperations.sol +17 -61
- package/src/lightning-parts/interfaces/ITEELifecycle.sol +7 -11
- package/src/lightning-parts/interfaces/ITrivialEncryption.sol +2 -0
- package/src/lightning-parts/primitives/EventCounter.sol +7 -8
- package/src/lightning-parts/primitives/HandleGeneration.sol +20 -32
- package/src/lightning-parts/primitives/HandleMetadata.sol +7 -17
- package/src/lightning-parts/primitives/LightningAddressGetter.sol +3 -0
- package/src/lightning-parts/primitives/SignatureVerifier.sol +91 -27
- package/src/lightning-parts/primitives/VerifierAddressGetter.sol +3 -0
- package/src/lightning-parts/primitives/interfaces/IEventCounter.sol +2 -0
- package/src/lightning-parts/primitives/interfaces/IHandleGeneration.sol +10 -2
- package/src/lightning-parts/primitives/interfaces/ISignatureVerifier.sol +4 -2
- package/src/lightning-parts/primitives/interfaces/IVerifierAddressGetter.sol +2 -0
- package/src/lightning-parts/primitives/test/SignatureVerifier.t.sol +838 -0
- package/src/lightning-parts/test/Fee.t.sol +6 -6
- package/src/lightning-parts/test/HandleMetadata.t.sol +21 -76
- package/src/lightning-parts/test/InputsFee.t.sol +7 -28
- package/src/lightning-parts/test/TestDecryptionAttestationInSynchronousFlow.t.sol +16 -48
- package/src/pasted-dependencies/CreateX.sol +154 -455
- package/src/pasted-dependencies/ICreateX.sol +55 -102
- package/src/periphery/SessionVerifier.sol +10 -8
- package/src/shared/IOwnable.sol +3 -0
- package/src/shared/IUUPSUpgradable.sol +5 -1
- package/src/shared/JsonUtils.sol +3 -5
- package/src/shared/TestUtils.sol +15 -13
- package/src/test/AddTwo.sol +9 -7
- package/src/test/FakeIncoInfra/FakeComputeServer.sol +11 -53
- package/src/test/FakeIncoInfra/FakeDecryptionAttester.sol +35 -119
- package/src/test/FakeIncoInfra/FakeIncoInfraBase.sol +31 -48
- package/src/test/FakeIncoInfra/FakeQuoteVerifier.sol +4 -7
- package/src/test/FakeIncoInfra/KVStore.sol +2 -0
- package/src/test/FakeIncoInfra/MockOpHandler.sol +9 -31
- package/src/test/FakeIncoInfra/MockRemoteAttestation.sol +50 -21
- package/src/test/IncoTest.sol +22 -9
- package/src/test/OpsTest.sol +438 -0
- package/src/test/TEELifecycle/TEELifecycleMockTest.t.sol +57 -104
- package/src/test/TestAddTwo.t.sol +4 -3
- package/src/test/TestDeploy.t.sol +5 -6
- package/src/test/TestExtractDataOfEventTooLarge.t.sol +7 -9
- package/src/test/TestFakeInfra.t.sol +15 -38
- package/src/test/TestUpgrade.t.sol +40 -135
- package/src/test/TestVersion.t.sol +6 -5
- package/src/version/IncoLightningConfig.sol +2 -2
- package/src/version/Version.sol +46 -48
- package/src/version/interfaces/IVersion.sol +6 -0
|
@@ -5,92 +5,64 @@ import {TEELifecycle} from "../../lightning-parts/TEELifecycle.sol";
|
|
|
5
5
|
import {BootstrapResult, AddNodeResult} from "../../lightning-parts/TEELifecycle.types.sol";
|
|
6
6
|
import {MockRemoteAttestation} from "../FakeIncoInfra/MockRemoteAttestation.sol";
|
|
7
7
|
import {FakeQuoteVerifier} from "../FakeIncoInfra/FakeQuoteVerifier.sol";
|
|
8
|
-
import {Test} from "forge-std/Test.sol";
|
|
9
8
|
|
|
10
|
-
contract TEELifecycleMockTest is
|
|
9
|
+
contract TEELifecycleMockTest is MockRemoteAttestation, TEELifecycle {
|
|
10
|
+
|
|
11
11
|
// Constants for testing
|
|
12
|
-
bytes testNetworkPubkey = hex"
|
|
12
|
+
bytes testNetworkPubkey = hex"02516bda9e68a1c3dce74dc1b6ed7d91a91d51c1e1933947f06331cef59631e9eb";
|
|
13
13
|
// See DEFAULT_MRTD in attestation/src/remote_attestation.rs
|
|
14
|
-
bytes testMrtd =
|
|
14
|
+
bytes testMrtd =
|
|
15
|
+
hex"010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101";
|
|
15
16
|
// See DEFAULT_MR_AGGREGATED in attestation/src/remote_attestation.rs to
|
|
16
17
|
// see the calculation of the default value.
|
|
17
18
|
bytes32 testMrAggregated = hex"c3a67bac251d4946d7b17481d39631676042fe3afab06e70c22105ad8383c19f";
|
|
18
19
|
|
|
19
20
|
function setUp() public {
|
|
20
|
-
|
|
21
|
+
getTeeLifecycleStorage().quoteVerifier = new FakeQuoteVerifier();
|
|
21
22
|
}
|
|
22
23
|
|
|
23
24
|
function testSuccessfulBootstrap() public {
|
|
24
|
-
(
|
|
25
|
-
|
|
26
|
-
,
|
|
27
|
-
,
|
|
28
|
-
bytes memory quote,
|
|
29
|
-
bytes memory signature,
|
|
30
|
-
bytes32 mrAggregated
|
|
31
|
-
) = successfulBootstrapResult();
|
|
25
|
+
(BootstrapResult memory bootstrapResult,,, bytes memory quote, bytes memory signature, bytes32 mrAggregated) =
|
|
26
|
+
successfulBootstrapResult();
|
|
32
27
|
vm.startPrank(this.owner());
|
|
33
|
-
this.
|
|
28
|
+
this.approveNewTeeVersion(mrAggregated);
|
|
34
29
|
this.verifyBootstrapResult(bootstrapResult, quote, signature);
|
|
35
30
|
assertTrue(this.isBootstrapComplete(), "Bootstrap should be complete");
|
|
36
31
|
vm.stopPrank();
|
|
37
32
|
}
|
|
38
33
|
|
|
39
34
|
function testInvalidMrtd() public {
|
|
40
|
-
bytes
|
|
41
|
-
|
|
35
|
+
bytes memory badMrtd =
|
|
36
|
+
hex"1234567890abcdef1234567890abcdef1234567890abcdef1234567890abcdef1234567890abcdef1234567890abcdef";
|
|
42
37
|
|
|
43
|
-
(
|
|
44
|
-
|
|
45
|
-
,
|
|
46
|
-
address bootstrapPartyAddress,
|
|
47
|
-
bytes memory quote,
|
|
48
|
-
bytes memory signature,
|
|
49
|
-
bytes32 mrAggregated
|
|
50
|
-
) = successfulBootstrapResult();
|
|
38
|
+
(BootstrapResult memory bootstrapResult, bytes memory quote, bytes memory signature, bytes32 mrAggregated) =
|
|
39
|
+
successfulBootstrapResult(this, testNetworkPubkey, teeEOA, teePrivKey);
|
|
51
40
|
|
|
52
|
-
quote = createQuote(badMrtd,
|
|
41
|
+
quote = createQuote(badMrtd, teeEOA); // Replace with bad MRTD
|
|
53
42
|
vm.startPrank(this.owner());
|
|
54
|
-
this.
|
|
43
|
+
this.approveNewTeeVersion(mrAggregated);
|
|
55
44
|
vm.expectRevert(TEELifecycle.InvalidReportMrAggregated.selector);
|
|
56
45
|
this.verifyBootstrapResult(bootstrapResult, quote, signature);
|
|
57
46
|
vm.stopPrank();
|
|
58
47
|
}
|
|
59
48
|
|
|
60
49
|
function testInvalidSignature() public {
|
|
61
|
-
(
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
bytes memory quote,
|
|
66
|
-
,
|
|
67
|
-
bytes32 mrAggregated
|
|
68
|
-
) = successfulBootstrapResult();
|
|
69
|
-
(uint256 bootstrapPartyFakePrivkey, ) = getLabeledKeyPair(
|
|
70
|
-
"bootstrapPartyFake"
|
|
71
|
-
);
|
|
72
|
-
bytes memory signatureInvalid = signBootstrapResult(
|
|
73
|
-
bootstrapResult,
|
|
74
|
-
bootstrapPartyFakePrivkey
|
|
75
|
-
);
|
|
50
|
+
(BootstrapResult memory bootstrapResult,,, bytes memory quote,, bytes32 mrAggregated) =
|
|
51
|
+
successfulBootstrapResult();
|
|
52
|
+
(uint256 bootstrapPartyFakePrivkey,) = getLabeledKeyPair("bootstrapPartyFake");
|
|
53
|
+
bytes memory signatureInvalid = signBootstrapResult(bootstrapResult, bootstrapPartyFakePrivkey);
|
|
76
54
|
vm.startPrank(this.owner());
|
|
77
|
-
this.
|
|
55
|
+
this.approveNewTeeVersion(mrAggregated);
|
|
78
56
|
vm.expectRevert(TEELifecycle.InvalidEIP712Signature.selector);
|
|
79
57
|
this.verifyBootstrapResult(bootstrapResult, quote, signatureInvalid);
|
|
80
58
|
vm.stopPrank();
|
|
81
59
|
}
|
|
82
60
|
|
|
83
61
|
function testBootstrapAlreadyComplete() public {
|
|
84
|
-
(
|
|
85
|
-
|
|
86
|
-
,
|
|
87
|
-
,
|
|
88
|
-
bytes memory quote,
|
|
89
|
-
bytes memory signature,
|
|
90
|
-
bytes32 mrAggregated
|
|
91
|
-
) = successfulBootstrapResult();
|
|
62
|
+
(BootstrapResult memory bootstrapResult,,, bytes memory quote, bytes memory signature, bytes32 mrAggregated) =
|
|
63
|
+
successfulBootstrapResult();
|
|
92
64
|
vm.startPrank(this.owner());
|
|
93
|
-
this.
|
|
65
|
+
this.approveNewTeeVersion(mrAggregated);
|
|
94
66
|
this.verifyBootstrapResult(bootstrapResult, quote, signature);
|
|
95
67
|
vm.expectRevert(TEELifecycle.BootstrapAlreadyCompleted.selector);
|
|
96
68
|
this.verifyBootstrapResult(bootstrapResult, quote, signature);
|
|
@@ -98,77 +70,57 @@ contract TEELifecycleMockTest is Test, MockRemoteAttestation, TEELifecycle {
|
|
|
98
70
|
}
|
|
99
71
|
|
|
100
72
|
function testAddNodeBootstrapNotComplete() public {
|
|
101
|
-
bytes
|
|
102
|
-
|
|
73
|
+
bytes memory mrtd =
|
|
74
|
+
hex"2a90c8fa38672cafd791d994beb6836b99383b2563736858632284f0f760a6446efd1e7ec457cf08b629ea630f7b4525";
|
|
103
75
|
(, address newCoval) = getLabeledKeyPair("newCoval");
|
|
104
76
|
bytes memory quote = createQuote(mrtd, newCoval);
|
|
105
77
|
vm.startPrank(this.owner());
|
|
106
78
|
vm.expectRevert(TEELifecycle.BootstrapNotComplete.selector);
|
|
107
|
-
this.verifyAddNodeResult(testMrAggregated, AddNodeResult({
|
|
79
|
+
this.verifyAddNodeResult(testMrAggregated, AddNodeResult({networkPubkey: hex"00"}), quote, hex"");
|
|
108
80
|
vm.stopPrank();
|
|
109
81
|
}
|
|
110
82
|
|
|
111
83
|
function testAddNodeInvalidMrtd() public {
|
|
112
|
-
(
|
|
113
|
-
|
|
114
|
-
,
|
|
115
|
-
,
|
|
116
|
-
bytes memory quote,
|
|
117
|
-
bytes memory signature,
|
|
118
|
-
bytes32 mrAggregated
|
|
119
|
-
) = successfulBootstrapResult();
|
|
84
|
+
(BootstrapResult memory bootstrapResult,,, bytes memory quote, bytes memory signature, bytes32 mrAggregated) =
|
|
85
|
+
successfulBootstrapResult();
|
|
120
86
|
vm.startPrank(this.owner());
|
|
121
|
-
this.
|
|
87
|
+
this.approveNewTeeVersion(mrAggregated);
|
|
122
88
|
this.verifyBootstrapResult(bootstrapResult, quote, signature);
|
|
123
|
-
bytes
|
|
124
|
-
|
|
89
|
+
bytes memory badMrtd =
|
|
90
|
+
hex"1234567890abcdef1234567890abcdef1234567890abcdef1234567890abcdef1234567890abcdef1234567890abcdef";
|
|
125
91
|
(, address newCoval) = getLabeledKeyPair("newCoval");
|
|
126
92
|
bytes memory badQuote = createQuote(badMrtd, newCoval);
|
|
127
93
|
vm.expectRevert(TEELifecycle.InvalidReportMrAggregated.selector);
|
|
128
|
-
this.verifyAddNodeResult(mrAggregated, AddNodeResult({
|
|
94
|
+
this.verifyAddNodeResult(mrAggregated, AddNodeResult({networkPubkey: testNetworkPubkey}), badQuote, signature);
|
|
129
95
|
vm.stopPrank();
|
|
130
96
|
}
|
|
131
97
|
|
|
132
98
|
function testAddNodeInvalidNetworkPubkey() public {
|
|
133
|
-
(
|
|
134
|
-
|
|
135
|
-
,
|
|
136
|
-
,
|
|
137
|
-
bytes memory quote,
|
|
138
|
-
bytes memory signature,
|
|
139
|
-
bytes32 mrAggregated
|
|
140
|
-
) = successfulBootstrapResult();
|
|
99
|
+
(BootstrapResult memory bootstrapResult,,, bytes memory quote, bytes memory signature, bytes32 mrAggregated) =
|
|
100
|
+
successfulBootstrapResult();
|
|
141
101
|
vm.startPrank(this.owner());
|
|
142
|
-
this.
|
|
102
|
+
this.approveNewTeeVersion(mrAggregated);
|
|
143
103
|
this.verifyBootstrapResult(bootstrapResult, quote, signature);
|
|
144
104
|
vm.expectRevert(TEELifecycle.InvalidNetworkPubkey.selector);
|
|
145
|
-
this.verifyAddNodeResult(testMrAggregated, AddNodeResult({
|
|
105
|
+
this.verifyAddNodeResult(testMrAggregated, AddNodeResult({networkPubkey: hex"00"}), quote, signature);
|
|
146
106
|
vm.stopPrank();
|
|
147
107
|
}
|
|
148
108
|
|
|
149
109
|
function testAddNodeInvalidSignature() public {
|
|
150
|
-
(
|
|
151
|
-
|
|
152
|
-
,
|
|
153
|
-
,
|
|
154
|
-
bytes memory quote,
|
|
155
|
-
bytes memory signature,
|
|
156
|
-
bytes32 mrAggregated
|
|
157
|
-
) = successfulBootstrapResult();
|
|
110
|
+
(BootstrapResult memory bootstrapResult,,, bytes memory quote, bytes memory signature, bytes32 mrAggregated) =
|
|
111
|
+
successfulBootstrapResult();
|
|
158
112
|
vm.startPrank(this.owner());
|
|
159
|
-
this.
|
|
113
|
+
this.approveNewTeeVersion(mrAggregated);
|
|
160
114
|
this.verifyBootstrapResult(bootstrapResult, quote, signature);
|
|
161
115
|
|
|
162
|
-
(uint256 maliciousNewNodePrivkey,) = getLabeledKeyPair(
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
bytes memory badSignature = signAddNodeResult(
|
|
166
|
-
AddNodeResult({network_pubkey: testNetworkPubkey}),
|
|
167
|
-
maliciousNewNodePrivkey
|
|
168
|
-
);
|
|
116
|
+
(uint256 maliciousNewNodePrivkey,) = getLabeledKeyPair("maliciousNewNode");
|
|
117
|
+
bytes memory badSignature =
|
|
118
|
+
signAddNodeResult(AddNodeResult({networkPubkey: testNetworkPubkey}), maliciousNewNodePrivkey);
|
|
169
119
|
|
|
170
120
|
vm.expectRevert(TEELifecycle.InvalidEIP712Signature.selector);
|
|
171
|
-
this.verifyAddNodeResult(
|
|
121
|
+
this.verifyAddNodeResult(
|
|
122
|
+
testMrAggregated, AddNodeResult({networkPubkey: testNetworkPubkey}), quote, badSignature
|
|
123
|
+
);
|
|
172
124
|
vm.stopPrank();
|
|
173
125
|
}
|
|
174
126
|
|
|
@@ -184,9 +136,7 @@ contract TEELifecycleMockTest is Test, MockRemoteAttestation, TEELifecycle {
|
|
|
184
136
|
bytes32 mrAggregated
|
|
185
137
|
)
|
|
186
138
|
{
|
|
187
|
-
(bootstrapPartyPrivkey, bootstrapPartyAddress) = getLabeledKeyPair(
|
|
188
|
-
"bootstrapParty"
|
|
189
|
-
);
|
|
139
|
+
(bootstrapPartyPrivkey, bootstrapPartyAddress) = getLabeledKeyPair("bootstrapParty");
|
|
190
140
|
mrAggregated = testMrAggregated;
|
|
191
141
|
bootstrapResult = BootstrapResult({ecies_pubkey: testNetworkPubkey});
|
|
192
142
|
|
|
@@ -195,20 +145,23 @@ contract TEELifecycleMockTest is Test, MockRemoteAttestation, TEELifecycle {
|
|
|
195
145
|
}
|
|
196
146
|
|
|
197
147
|
// Helper function to sign the bootstrap result
|
|
198
|
-
function signBootstrapResult(
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
148
|
+
function signBootstrapResult(BootstrapResult memory bootstrapResult, uint256 privateKey)
|
|
149
|
+
internal
|
|
150
|
+
view
|
|
151
|
+
returns (bytes memory)
|
|
152
|
+
{
|
|
202
153
|
bytes32 bootstrapResultDigest = bootstrapResultDigest(bootstrapResult);
|
|
203
154
|
return getSignatureForDigest(bootstrapResultDigest, privateKey);
|
|
204
155
|
}
|
|
205
156
|
|
|
206
157
|
// Helper function to sign the add node result
|
|
207
|
-
function signAddNodeResult(
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
158
|
+
function signAddNodeResult(AddNodeResult memory addNodeResult, uint256 privateKey)
|
|
159
|
+
internal
|
|
160
|
+
view
|
|
161
|
+
returns (bytes memory)
|
|
162
|
+
{
|
|
211
163
|
bytes32 addNodeResultDigest = addNodeResultDigest(addNodeResult);
|
|
212
164
|
return getSignatureForDigest(addNodeResultDigest, privateKey);
|
|
213
165
|
}
|
|
166
|
+
|
|
214
167
|
}
|
|
@@ -7,6 +7,7 @@ import {IncoTest} from "./IncoTest.sol";
|
|
|
7
7
|
import {AddTwo} from "./AddTwo.sol";
|
|
8
8
|
|
|
9
9
|
contract TestAddTwo is IncoTest {
|
|
10
|
+
|
|
10
11
|
AddTwo addTwo;
|
|
11
12
|
|
|
12
13
|
function setUp() public override {
|
|
@@ -25,9 +26,8 @@ contract TestAddTwo is IncoTest {
|
|
|
25
26
|
}
|
|
26
27
|
|
|
27
28
|
function testAddTwoEoaAndPublicReveal() public {
|
|
28
|
-
(euint256 result, euint256 revealedResult) =
|
|
29
|
-
fakePrepareEuint256Ciphertext(3, address(this), address(addTwo))
|
|
30
|
-
);
|
|
29
|
+
(euint256 result, euint256 revealedResult) =
|
|
30
|
+
addTwo.addTwoEoa(fakePrepareEuint256Ciphertext(3, address(this), address(addTwo)));
|
|
31
31
|
processAllOperations();
|
|
32
32
|
assertEq(getUint256Value(result), 5);
|
|
33
33
|
assertEq(getUint256Value(revealedResult), 5);
|
|
@@ -41,4 +41,5 @@ contract TestAddTwo is IncoTest {
|
|
|
41
41
|
assertEq(getBoolValue(trueVal), true);
|
|
42
42
|
assertTrue(inco.isAllowed(ebool.unwrap(trueVal), bob));
|
|
43
43
|
}
|
|
44
|
+
|
|
44
45
|
}
|
|
@@ -9,24 +9,22 @@ import {inco} from "../Lib.sol";
|
|
|
9
9
|
import {IncoTest} from "./IncoTest.sol";
|
|
10
10
|
|
|
11
11
|
contract ReturnTwo is UUPSUpgradeable {
|
|
12
|
+
|
|
12
13
|
function getTwo() external pure returns (uint256) {
|
|
13
14
|
return 2;
|
|
14
15
|
}
|
|
15
16
|
|
|
16
17
|
function _authorizeUpgrade(address) internal override {}
|
|
18
|
+
|
|
17
19
|
}
|
|
18
20
|
|
|
19
21
|
contract TestDeploy is Test, IncoTest {
|
|
22
|
+
|
|
20
23
|
// todo test that inco gets deployed at the predicted address
|
|
21
24
|
|
|
22
25
|
function testDeployedCorrectly() public {
|
|
23
26
|
vm.expectEmit(false, false, true, false, address(inco));
|
|
24
|
-
emit TrivialEncryption.TrivialEncrypt(
|
|
25
|
-
bytes32(uint256(1)),
|
|
26
|
-
bytes32(uint256(1)),
|
|
27
|
-
ETypes.Bool,
|
|
28
|
-
0
|
|
29
|
-
);
|
|
27
|
+
emit TrivialEncryption.TrivialEncrypt(bytes32(uint256(1)), bytes32(uint256(1)), ETypes.Bool, 0);
|
|
30
28
|
inco.asEbool(true);
|
|
31
29
|
}
|
|
32
30
|
|
|
@@ -36,4 +34,5 @@ contract TestDeploy is Test, IncoTest {
|
|
|
36
34
|
inco.upgradeToAndCall(address(newImplem), "");
|
|
37
35
|
assertEq(ReturnTwo(address(inco)).getTwo(), 2);
|
|
38
36
|
}
|
|
37
|
+
|
|
39
38
|
}
|
|
@@ -3,8 +3,8 @@ pragma solidity ^0.8;
|
|
|
3
3
|
|
|
4
4
|
import {Test, Vm, console} from "forge-std/Test.sol";
|
|
5
5
|
|
|
6
|
-
event EventTooLarge(
|
|
7
|
-
bytes32 control,
|
|
6
|
+
event EventTooLarge( // can't index >3 fields
|
|
7
|
+
bytes32 control,
|
|
8
8
|
bytes32 indexed ifTrue,
|
|
9
9
|
bytes32 indexed ifFalse,
|
|
10
10
|
bytes32 indexed result,
|
|
@@ -12,18 +12,15 @@ event EventTooLarge(
|
|
|
12
12
|
);
|
|
13
13
|
|
|
14
14
|
contract Emitter {
|
|
15
|
+
|
|
15
16
|
function emitEventTooLarge() external {
|
|
16
|
-
emit EventTooLarge(
|
|
17
|
-
bytes32(uint256(1)),
|
|
18
|
-
bytes32(uint256(2)),
|
|
19
|
-
bytes32(uint256(3)),
|
|
20
|
-
bytes32(uint256(4)),
|
|
21
|
-
5
|
|
22
|
-
);
|
|
17
|
+
emit EventTooLarge(bytes32(uint256(1)), bytes32(uint256(2)), bytes32(uint256(3)), bytes32(uint256(4)), 5);
|
|
23
18
|
}
|
|
19
|
+
|
|
24
20
|
}
|
|
25
21
|
|
|
26
22
|
contract TestExtractDataOfEventTooLarge is Test {
|
|
23
|
+
|
|
27
24
|
function testEmit() public {
|
|
28
25
|
Emitter emitter = new Emitter();
|
|
29
26
|
vm.recordLogs();
|
|
@@ -40,4 +37,5 @@ contract TestExtractDataOfEventTooLarge is Test {
|
|
|
40
37
|
assertEq(first32Bytes, bytes32(uint256(1)));
|
|
41
38
|
assertEq(second32Bytes, bytes32(uint256(5)));
|
|
42
39
|
}
|
|
40
|
+
|
|
43
41
|
}
|
|
@@ -5,13 +5,10 @@ import {IncoTest} from "./IncoTest.sol";
|
|
|
5
5
|
import {e, euint256, ebool, eaddress, inco} from "../Lib.sol";
|
|
6
6
|
import {SenderNotAllowedForHandle} from "../Types.sol";
|
|
7
7
|
import {TEELifecycle} from "../lightning-parts/TEELifecycle.sol";
|
|
8
|
-
import {
|
|
9
|
-
import {
|
|
10
|
-
TD10ReportBody,
|
|
11
|
-
MINIMUM_QUOTE_LENGTH
|
|
12
|
-
} from "../interfaces/automata-interfaces/Types.sol";
|
|
8
|
+
import {Td10ReportBody, MINIMUM_QUOTE_LENGTH} from "../interfaces/automata-interfaces/Types.sol";
|
|
13
9
|
|
|
14
10
|
contract TakesEInput is IncoTest {
|
|
11
|
+
|
|
15
12
|
using e for bytes;
|
|
16
13
|
using e for euint256;
|
|
17
14
|
|
|
@@ -27,10 +24,12 @@ contract TakesEInput is IncoTest {
|
|
|
27
24
|
function setB(bytes memory boolEInput) external {
|
|
28
25
|
b = boolEInput.newEbool(msg.sender);
|
|
29
26
|
}
|
|
27
|
+
|
|
30
28
|
}
|
|
31
29
|
|
|
32
30
|
// its meta: this is testing correct behavior of our testing infrastructure
|
|
33
|
-
contract TestFakeInfra is IncoTest
|
|
31
|
+
contract TestFakeInfra is IncoTest {
|
|
32
|
+
|
|
34
33
|
using e for euint256;
|
|
35
34
|
using e for ebool;
|
|
36
35
|
using e for uint256;
|
|
@@ -153,10 +152,7 @@ contract TestFakeInfra is IncoTest, MockRemoteAttestation {
|
|
|
153
152
|
euint256 b = e.asEuint256(4);
|
|
154
153
|
euint256 c = a.rotr(b);
|
|
155
154
|
processAllOperations();
|
|
156
|
-
assertEq(
|
|
157
|
-
getUint256Value(c),
|
|
158
|
-
72370055773322622139731865630429942408293740416025352524660990004945706024960
|
|
159
|
-
);
|
|
155
|
+
assertEq(getUint256Value(c), 72370055773322622139731865630429942408293740416025352524660990004945706024960);
|
|
160
156
|
}
|
|
161
157
|
|
|
162
158
|
function testEEq() public {
|
|
@@ -272,17 +268,9 @@ contract TestFakeInfra is IncoTest, MockRemoteAttestation {
|
|
|
272
268
|
TakesEInput inputContract = new TakesEInput();
|
|
273
269
|
vm.deal(address(inputContract), 1 ether);
|
|
274
270
|
address self = address(this);
|
|
275
|
-
bytes memory ciphertext = fakePrepareEuint256Ciphertext(
|
|
276
|
-
12,
|
|
277
|
-
self,
|
|
278
|
-
address(inputContract)
|
|
279
|
-
);
|
|
271
|
+
bytes memory ciphertext = fakePrepareEuint256Ciphertext(12, self, address(inputContract));
|
|
280
272
|
inputContract.setA(ciphertext);
|
|
281
|
-
inputContract.setB(
|
|
282
|
-
fakePrepareEboolCiphertext(true,
|
|
283
|
-
self,
|
|
284
|
-
address(inputContract)
|
|
285
|
-
));
|
|
273
|
+
inputContract.setB(fakePrepareEboolCiphertext(true, self, address(inputContract)));
|
|
286
274
|
processAllOperations();
|
|
287
275
|
assertEq(getUint256Value(inputContract.a()), 12);
|
|
288
276
|
assertEq(getBoolValue(inputContract.b()), true);
|
|
@@ -291,35 +279,24 @@ contract TestFakeInfra is IncoTest, MockRemoteAttestation {
|
|
|
291
279
|
function testUninitializedHandleIsDisallowed() public {
|
|
292
280
|
bytes32 randomHandle = keccak256("random handle");
|
|
293
281
|
euint256 a = e.asEuint256(12);
|
|
294
|
-
vm.expectRevert(
|
|
295
|
-
abi.encodeWithSelector(
|
|
296
|
-
SenderNotAllowedForHandle.selector,
|
|
297
|
-
randomHandle,
|
|
298
|
-
address(this)
|
|
299
|
-
)
|
|
300
|
-
);
|
|
282
|
+
vm.expectRevert(abi.encodeWithSelector(SenderNotAllowedForHandle.selector, randomHandle, address(this)));
|
|
301
283
|
a.add(euint256.wrap(randomHandle));
|
|
302
284
|
}
|
|
303
285
|
|
|
304
286
|
function testCreateQuote() public view {
|
|
305
|
-
bytes
|
|
306
|
-
|
|
287
|
+
bytes memory mrtd =
|
|
288
|
+
hex"1234567890abcdef1234567890abcdef1234567890abcdef1234567890abcdef1234567890abcdef1234567890abcdef";
|
|
307
289
|
address signer = address(0x1234567890123456789012345678901234567890);
|
|
308
290
|
bytes memory quote = createQuote(mrtd, signer);
|
|
309
291
|
TEELifecycle lifecycle = TEELifecycle(address(inco.incoVerifier()));
|
|
310
|
-
|
|
311
|
-
(address reportDataSigner, bytes32 reportMrAggregated) = lifecycle
|
|
312
|
-
.parseReport(tdReport);
|
|
292
|
+
Td10ReportBody memory tdReport = lifecycle.parseTd10ReportBody(quote);
|
|
293
|
+
(address reportDataSigner, bytes32 reportMrAggregated) = lifecycle.parseReport(tdReport);
|
|
313
294
|
assertEq(reportDataSigner, signer);
|
|
314
295
|
assertEq(
|
|
315
296
|
reportMrAggregated,
|
|
316
|
-
lifecycle.computeMrAggregated(
|
|
317
|
-
tdReport.mrTd,
|
|
318
|
-
tdReport.rtMr0,
|
|
319
|
-
tdReport.rtMr1,
|
|
320
|
-
tdReport.rtMr2
|
|
321
|
-
)
|
|
297
|
+
lifecycle.computeMrAggregated(tdReport.mrTd, tdReport.rtMr0, tdReport.rtMr1, tdReport.rtMr2)
|
|
322
298
|
);
|
|
323
299
|
assertEq(quote.length, MINIMUM_QUOTE_LENGTH);
|
|
324
300
|
}
|
|
301
|
+
|
|
325
302
|
}
|