@inco/lightning 0.5.2 → 0.5.3
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 +9 -9
- package/package.json +1 -2
- package/src/DeployUtils.sol +10 -19
- package/src/Lib.devnet.sol +1 -1
- package/src/Lib.sol +1 -1
- package/src/Types.sol +3 -1
- package/src/libs/incoLightning_devnet_v1_904635675.sol +451 -0
- package/src/lightning-parts/AccessControl/BaseAccessControlList.sol +12 -4
- package/src/lightning-parts/EncryptedInput.sol +1 -1
- package/src/lightning-parts/EncryptedOperations.sol +1 -1
- package/src/lightning-parts/TEELifecycle.sol +40 -23
- package/src/lightning-parts/TEELifecycle.types.sol +2 -2
- package/src/lightning-parts/TrivialEncryption.sol +1 -1
- package/src/lightning-parts/interfaces/ITEELifecycle.sol +2 -2
- package/src/test/FakeIncoInfra/MockRemoteAttestation.sol +6 -0
- package/src/test/FakeIncoInfra/getOpForSelector.sol +3 -0
- package/src/test/IncoTest.sol +1 -0
- package/src/test/TEELifecycle/TEELifecycleMockTest.t.sol +20 -25
- package/src/test/TestFakeInfra.t.sol +2 -3
- package/src/version/IncoLightningConfig.sol +3 -1
- package/src/test/TEELifecycle/README.md +0 -53
package/manifest.yaml
CHANGED
|
@@ -1,25 +1,25 @@
|
|
|
1
|
-
|
|
1
|
+
incoLightning_devnet_v1_904635675:
|
|
2
2
|
executor:
|
|
3
|
-
name:
|
|
3
|
+
name: incoLightning_devnet_v1_904635675
|
|
4
4
|
majorVersion: 1
|
|
5
5
|
deployer: "0x8202D2D747784Cb7D48868E44C42C4bf162a70BC"
|
|
6
6
|
pepper: devnet
|
|
7
|
-
executorAddress: "
|
|
8
|
-
salt: "
|
|
7
|
+
executorAddress: "0x3473820DcAa71Af8157b93C7f2bf1c676A2A39A6"
|
|
8
|
+
salt: "0x8202d2d747784cb7d48868e44c42c4bf162a70bc007d63c0fdca6698ac7cc51b"
|
|
9
9
|
deployments:
|
|
10
|
-
- name:
|
|
10
|
+
- name: incoLightningPreview_1_0_0__904635675
|
|
11
11
|
chainId: "9746"
|
|
12
12
|
chainName: Plasma Testnet
|
|
13
13
|
version:
|
|
14
14
|
major: 1
|
|
15
15
|
minor: 0
|
|
16
16
|
patch: 0
|
|
17
|
-
shortSalt: "
|
|
17
|
+
shortSalt: "904635675"
|
|
18
18
|
decryptSigner: "0x138AcbDC1FA02b955949d8Da09E546Ea7748710f"
|
|
19
19
|
eciesPublicKey: "0x038a582d29083c2f3fefe024bf4dd9ab913ab8973716977da5f01106e0b84095b1"
|
|
20
|
-
blockNumber: "
|
|
21
|
-
deployDate: 2025-09-
|
|
22
|
-
commit: v0.5.
|
|
20
|
+
blockNumber: "3344310"
|
|
21
|
+
deployDate: 2025-09-29T11:14:02.599Z
|
|
22
|
+
commit: v0.5.1-5-g4135c790-dirty
|
|
23
23
|
active: true
|
|
24
24
|
incoLightning_testnet_v0_183408998:
|
|
25
25
|
executor:
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@inco/lightning",
|
|
3
|
-
"version": "0.5.
|
|
3
|
+
"version": "0.5.3",
|
|
4
4
|
"repository": "https://github.com/Inco-fhevm/inco-monorepo",
|
|
5
5
|
"files": [
|
|
6
6
|
"src/",
|
|
@@ -21,7 +21,6 @@
|
|
|
21
21
|
"@safe-global/safe-smart-account": "https://github.com/safe-global/safe-smart-account.git#v1.5.0",
|
|
22
22
|
"ds-test": "https://github.com/dapphub/ds-test",
|
|
23
23
|
"forge-std": "https://github.com/foundry-rs/forge-std",
|
|
24
|
-
"solady": "https://github.com/Vectorized/solady.git#v0.1.24",
|
|
25
24
|
"tsx": "^4.19.3"
|
|
26
25
|
},
|
|
27
26
|
"devDependencies": {
|
package/src/DeployUtils.sol
CHANGED
|
@@ -6,15 +6,15 @@ import {Script} from "forge-std/Script.sol";
|
|
|
6
6
|
import {IIncoLightning} from "./interfaces/IIncoLightning.sol";
|
|
7
7
|
import {Vm} from "forge-std/Vm.sol";
|
|
8
8
|
import {
|
|
9
|
-
CreateX,
|
|
10
|
-
createXAddress,
|
|
11
|
-
createXDeployer
|
|
9
|
+
CreateX,
|
|
10
|
+
createXAddress,
|
|
11
|
+
createXDeployer
|
|
12
12
|
} from "./pasted-dependencies/CreateX.sol";
|
|
13
13
|
import {ERC1967Proxy} from "@openzeppelin/contracts/proxy/ERC1967/ERC1967Proxy.sol";
|
|
14
14
|
import {
|
|
15
|
-
CONTRACT_NAME,
|
|
16
|
-
MAJOR_VERSION,
|
|
17
|
-
VERIFIER_NAME
|
|
15
|
+
CONTRACT_NAME,
|
|
16
|
+
MAJOR_VERSION,
|
|
17
|
+
VERIFIER_NAME
|
|
18
18
|
} from "./version/IncoLightningConfig.sol";
|
|
19
19
|
import {IncoVerifier} from "./IncoVerifier.sol";
|
|
20
20
|
import {IIncoVerifier} from "./interfaces/IIncoVerifier.sol";
|
|
@@ -51,22 +51,13 @@ contract DeployUtils is Script {
|
|
|
51
51
|
string memory pepper
|
|
52
52
|
) internal pure returns (bytes32) {
|
|
53
53
|
return
|
|
54
|
-
|
|
54
|
+
bytes32(
|
|
55
55
|
abi.encodePacked(
|
|
56
56
|
deployer,
|
|
57
57
|
crossChainDeployAuthorizedFlag,
|
|
58
58
|
bytes11(
|
|
59
59
|
keccak256(
|
|
60
|
-
abi.encodePacked(
|
|
61
|
-
name,
|
|
62
|
-
majorVersionNumber,
|
|
63
|
-
// "ghost" minor and patch versions are passed in the salt for retro compatibility
|
|
64
|
-
// of the deployment address
|
|
65
|
-
// todo #1037 remove permanently fake minor and patch versions from the salt
|
|
66
|
-
uint8(1),
|
|
67
|
-
uint8(29),
|
|
68
|
-
pepper
|
|
69
|
-
)
|
|
60
|
+
abi.encodePacked(name, majorVersionNumber, pepper)
|
|
70
61
|
)
|
|
71
62
|
)
|
|
72
63
|
)
|
|
@@ -91,8 +82,8 @@ contract DeployUtils is Script {
|
|
|
91
82
|
string memory pepper,
|
|
92
83
|
IQuoteVerifier quoteVerifier
|
|
93
84
|
)
|
|
94
|
-
|
|
95
|
-
|
|
85
|
+
internal
|
|
86
|
+
returns (IIncoLightning lightningProxy, IIncoVerifier verifierProxy)
|
|
96
87
|
{
|
|
97
88
|
(bytes32 lightningSalt, bytes32 verifierSalt) = getIncoSalts(
|
|
98
89
|
deployer,
|
package/src/Lib.devnet.sol
CHANGED
|
@@ -8,7 +8,7 @@ pragma solidity ^0.8;
|
|
|
8
8
|
import { IncoLightning } from "./IncoLightning.sol";
|
|
9
9
|
import { ebool, euint256, eaddress, ETypes } from "./Types.sol";
|
|
10
10
|
|
|
11
|
-
IncoLightning constant inco = IncoLightning(
|
|
11
|
+
IncoLightning constant inco = IncoLightning(0x3473820DcAa71Af8157b93C7f2bf1c676A2A39A6);
|
|
12
12
|
address constant deployedBy = 0x8202D2D747784Cb7D48868E44C42C4bf162a70BC;
|
|
13
13
|
|
|
14
14
|
function typeOf(bytes32 handle) pure returns (ETypes) {
|
package/src/Lib.sol
CHANGED
|
@@ -8,7 +8,7 @@ pragma solidity ^0.8;
|
|
|
8
8
|
import { IncoLightning } from "./IncoLightning.sol";
|
|
9
9
|
import { ebool, euint256, eaddress, ETypes } from "./Types.sol";
|
|
10
10
|
|
|
11
|
-
IncoLightning constant inco = IncoLightning(
|
|
11
|
+
IncoLightning constant inco = IncoLightning(0x3473820DcAa71Af8157b93C7f2bf1c676A2A39A6);
|
|
12
12
|
address constant deployedBy = 0x8202D2D747784Cb7D48868E44C42C4bf162a70BC;
|
|
13
13
|
|
|
14
14
|
function typeOf(bytes32 handle) pure returns (ETypes) {
|
package/src/Types.sol
CHANGED
|
@@ -36,7 +36,9 @@ pragma solidity ^0.8;
|
|
|
36
36
|
DecryptionRequested, // 28
|
|
37
37
|
RequestFulfilled, // 29
|
|
38
38
|
EOP30, EOP31, EOP32, EOP33, EOP34, EOP35, EOP36, EOP37, EOP38, EOP39,
|
|
39
|
-
|
|
39
|
+
// Pseudo-operation for an ACL (persistent) allow
|
|
40
|
+
Allow, // 40
|
|
41
|
+
EOP41, EOP42, EOP43, EOP44, EOP45, EOP46, EOP47, EOP48, EOP49,
|
|
40
42
|
EOP50, EOP51, EOP52, EOP53, EOP54, EOP55, EOP56, EOP57, EOP58, EOP59,
|
|
41
43
|
EOP60, EOP61, EOP62, EOP63, EOP64, EOP65, EOP66, EOP67, EOP68, EOP69,
|
|
42
44
|
EOP70, EOP71, EOP72, EOP73, EOP74, EOP75, EOP76, EOP77, EOP78, EOP79,
|
|
@@ -0,0 +1,451 @@
|
|
|
1
|
+
// AUTOGENERATED FILE. DO NOT EDIT.
|
|
2
|
+
// This file was generated by the IncoLightning library generator.
|
|
3
|
+
// The original template is located at Lib.template.sol
|
|
4
|
+
|
|
5
|
+
/// SPDX-License-Identifier: No License
|
|
6
|
+
pragma solidity ^0.8;
|
|
7
|
+
|
|
8
|
+
import { IncoLightning } from "../IncoLightning.sol";
|
|
9
|
+
import { ebool, euint256, eaddress, ETypes } from "../Types.sol";
|
|
10
|
+
|
|
11
|
+
IncoLightning constant inco = IncoLightning(0x3473820DcAa71Af8157b93C7f2bf1c676A2A39A6);
|
|
12
|
+
address constant deployedBy = 0x8202D2D747784Cb7D48868E44C42C4bf162a70BC;
|
|
13
|
+
|
|
14
|
+
function typeOf(bytes32 handle) pure returns (ETypes) {
|
|
15
|
+
return ETypes(uint8(uint256(handle) >> 8));
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
library e {
|
|
19
|
+
function sanitize(euint256 a) internal returns (euint256) {
|
|
20
|
+
if (euint256.unwrap(a) == bytes32(0)) {
|
|
21
|
+
return asEuint256(0);
|
|
22
|
+
}
|
|
23
|
+
return a;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
function sanitize(ebool a) internal returns (ebool) {
|
|
27
|
+
if (ebool.unwrap(a) == bytes32(0)) {
|
|
28
|
+
return asEbool(false);
|
|
29
|
+
}
|
|
30
|
+
return a;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
function sanitize(eaddress a) internal returns (eaddress) {
|
|
34
|
+
if (eaddress.unwrap(a) == bytes32(0)) {
|
|
35
|
+
return asEaddress(address(0));
|
|
36
|
+
}
|
|
37
|
+
return a;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
function s(euint256 a) internal returns (euint256) {
|
|
41
|
+
return sanitize(a);
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
function s(ebool a) internal returns (ebool) {
|
|
45
|
+
return sanitize(a);
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
function s(eaddress a) internal returns (eaddress) {
|
|
49
|
+
return sanitize(a);
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
function add(euint256 a, euint256 b) internal returns (euint256) {
|
|
53
|
+
return inco.eAdd(s(a), s(b));
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
function add(euint256 a, uint256 b) internal returns (euint256) {
|
|
57
|
+
return inco.eAdd(s(a), asEuint256(b));
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
function add(uint256 a, euint256 b) internal returns (euint256) {
|
|
61
|
+
return inco.eAdd(asEuint256(a), s(b));
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
function sub(euint256 a, euint256 b) internal returns (euint256) {
|
|
65
|
+
return inco.eSub(s(a), s(b));
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
function sub(euint256 a, uint256 b) internal returns (euint256) {
|
|
69
|
+
return inco.eSub(s(a), asEuint256(b));
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
function sub(uint256 a, euint256 b) internal returns (euint256) {
|
|
73
|
+
return inco.eSub(asEuint256(a), s(b));
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
function mul(euint256 a, euint256 b) internal returns (euint256) {
|
|
77
|
+
return inco.eMul(s(a), s(b));
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
function mul(euint256 a, uint256 b) internal returns (euint256) {
|
|
81
|
+
return inco.eMul(s(a), asEuint256(b));
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
function mul(uint256 a, euint256 b) internal returns (euint256) {
|
|
85
|
+
return inco.eMul(asEuint256(a), s(b));
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
function div(euint256 a, euint256 b) internal returns (euint256) {
|
|
89
|
+
return inco.eDiv(s(a), s(b));
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
function div(euint256 a, uint256 b) internal returns (euint256) {
|
|
93
|
+
return inco.eDiv(s(a), asEuint256(b));
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
function div(uint256 a, euint256 b) internal returns (euint256) {
|
|
97
|
+
return inco.eDiv(asEuint256(a), s(b));
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
function rem(euint256 a, euint256 b) internal returns (euint256) {
|
|
101
|
+
return inco.eRem(s(a), s(b));
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
function rem(euint256 a, uint256 b) internal returns (euint256) {
|
|
105
|
+
return inco.eRem(s(a), asEuint256(b));
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
function rem(uint256 a, euint256 b) internal returns (euint256) {
|
|
109
|
+
return inco.eRem(asEuint256(a), s(b));
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
function and(euint256 a, euint256 b) internal returns (euint256) {
|
|
113
|
+
return euint256.wrap(inco.eBitAnd(euint256.unwrap(s(a)), euint256.unwrap(s(b))));
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
function and(euint256 a, uint256 b) internal returns (euint256) {
|
|
117
|
+
return euint256.wrap(inco.eBitAnd(euint256.unwrap(s(a)), euint256.unwrap(asEuint256(b))));
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
function and(uint256 a, euint256 b) internal returns (euint256) {
|
|
121
|
+
return euint256.wrap(inco.eBitAnd(euint256.unwrap(asEuint256(a)), euint256.unwrap(s(b))));
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
function and(ebool a, ebool b) internal returns (ebool) {
|
|
125
|
+
return ebool.wrap(inco.eBitAnd(ebool.unwrap(s(a)), ebool.unwrap(s(b))));
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
function and(ebool a, bool b) internal returns (ebool) {
|
|
129
|
+
return ebool.wrap(inco.eBitAnd(ebool.unwrap(s(a)), ebool.unwrap(asEbool(b))));
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
function and(bool a, ebool b) internal returns (ebool) {
|
|
133
|
+
return ebool.wrap(inco.eBitAnd(ebool.unwrap(asEbool(a)), ebool.unwrap(s(b))));
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
function or(euint256 a, euint256 b) internal returns (euint256) {
|
|
137
|
+
return euint256.wrap(inco.eBitOr(euint256.unwrap(s(a)), euint256.unwrap(s(b))));
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
function or(euint256 a, uint256 b) internal returns (euint256) {
|
|
141
|
+
return euint256.wrap(inco.eBitOr(euint256.unwrap(s(a)), euint256.unwrap(asEuint256(b))));
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
function or(uint256 a, euint256 b) internal returns (euint256) {
|
|
145
|
+
return euint256.wrap(inco.eBitOr(euint256.unwrap(asEuint256(a)), euint256.unwrap(s(b))));
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
function or(ebool a, ebool b) internal returns (ebool) {
|
|
149
|
+
return ebool.wrap(inco.eBitOr(ebool.unwrap(s(a)), ebool.unwrap(s(b))));
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
function or(ebool a, bool b) internal returns (ebool) {
|
|
153
|
+
return ebool.wrap(inco.eBitOr(ebool.unwrap(s(a)), ebool.unwrap(asEbool(b))));
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
function or(bool a, ebool b) internal returns (ebool) {
|
|
157
|
+
return ebool.wrap(inco.eBitOr(ebool.unwrap(asEbool(a)), ebool.unwrap(s(b))));
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
function xor(euint256 a, euint256 b) internal returns (euint256) {
|
|
161
|
+
return euint256.wrap(inco.eBitXor(euint256.unwrap(s(a)), euint256.unwrap(s(b))));
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
function xor(euint256 a, uint256 b) internal returns (euint256) {
|
|
165
|
+
return euint256.wrap(inco.eBitXor(euint256.unwrap(s(a)), euint256.unwrap(asEuint256(b))));
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
function xor(uint256 a, euint256 b) internal returns (euint256) {
|
|
169
|
+
return euint256.wrap(inco.eBitXor(euint256.unwrap(asEuint256(a)), euint256.unwrap(s(b))));
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
function xor(ebool a, ebool b) internal returns (ebool) {
|
|
173
|
+
return ebool.wrap(inco.eBitXor(ebool.unwrap(s(a)), ebool.unwrap(s(b))));
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
function xor(ebool a, bool b) internal returns (ebool) {
|
|
177
|
+
return ebool.wrap(inco.eBitXor(ebool.unwrap(s(a)), ebool.unwrap(asEbool(b))));
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
function xor(bool a, ebool b) internal returns (ebool) {
|
|
181
|
+
return ebool.wrap(inco.eBitXor(ebool.unwrap(asEbool(a)), ebool.unwrap(s(b))));
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
function shl(euint256 a, euint256 b) internal returns (euint256) {
|
|
185
|
+
return inco.eShl(s(a), s(b));
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
function shl(euint256 a, uint256 b) internal returns (euint256) {
|
|
189
|
+
return inco.eShl(s(a), asEuint256(b));
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
function shl(uint256 a, euint256 b) internal returns (euint256) {
|
|
193
|
+
return inco.eShl(asEuint256(a), s(b));
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
function shr(euint256 a, euint256 b) internal returns (euint256) {
|
|
197
|
+
return inco.eShr(s(a), s(b));
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
function shr(euint256 a, uint256 b) internal returns (euint256) {
|
|
201
|
+
return inco.eShr(s(a), asEuint256(b));
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
function shr(uint256 a, euint256 b) internal returns (euint256) {
|
|
205
|
+
return inco.eShr(asEuint256(a), s(b));
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
function rotl(euint256 a, euint256 b) internal returns (euint256) {
|
|
209
|
+
return inco.eRotl(s(a), s(b));
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
function rotl(euint256 a, uint256 b) internal returns (euint256) {
|
|
213
|
+
return inco.eRotl(s(a), asEuint256(b));
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
function rotl(uint256 a, euint256 b) internal returns (euint256) {
|
|
217
|
+
return inco.eRotl(asEuint256(a), s(b));
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
function rotr(euint256 a, euint256 b) internal returns (euint256) {
|
|
221
|
+
return inco.eRotr(s(a), s(b));
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
function rotr(euint256 a, uint256 b) internal returns (euint256) {
|
|
225
|
+
return inco.eRotr(s(a), asEuint256(b));
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
function rotr(uint256 a, euint256 b) internal returns (euint256) {
|
|
229
|
+
return inco.eRotr(asEuint256(a), s(b));
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
function eq(euint256 a, euint256 b) internal returns (ebool) {
|
|
233
|
+
return inco.eEq(euint256.unwrap(s(a)), euint256.unwrap(s(b)));
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
function eq(euint256 a, uint256 b) internal returns (ebool) {
|
|
237
|
+
return inco.eEq(euint256.unwrap(s(a)), euint256.unwrap(asEuint256(b)));
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
function eq(uint256 a, euint256 b) internal returns (ebool) {
|
|
241
|
+
return inco.eEq(euint256.unwrap(asEuint256(a)), euint256.unwrap(s(b)));
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
function eq(eaddress a, address b) internal returns (ebool) {
|
|
245
|
+
return inco.eEq(eaddress.unwrap(s(a)), eaddress.unwrap(asEaddress(b)));
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
function eq(eaddress a, eaddress b) internal returns (ebool) {
|
|
249
|
+
return inco.eEq(eaddress.unwrap(s(a)), eaddress.unwrap(s(b)));
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
function eq(address a, eaddress b) internal returns (ebool) {
|
|
253
|
+
return inco.eEq(eaddress.unwrap(asEaddress(a)), eaddress.unwrap(s(b)));
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
function ne(euint256 a, euint256 b) internal returns (ebool) {
|
|
257
|
+
return inco.eNe(euint256.unwrap(s(a)), euint256.unwrap(s(b)));
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
function ne(euint256 a, uint256 b) internal returns (ebool) {
|
|
261
|
+
return inco.eNe(euint256.unwrap(s(a)), euint256.unwrap(asEuint256(b)));
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
function ne(uint256 a, euint256 b) internal returns (ebool) {
|
|
265
|
+
return inco.eNe(euint256.unwrap(asEuint256(a)), euint256.unwrap(s(b)));
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
function ne(eaddress a, eaddress b) internal returns (ebool) {
|
|
269
|
+
return inco.eNe(eaddress.unwrap(s(a)), eaddress.unwrap(s(b)));
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
function ne(eaddress a, address b) internal returns (ebool) {
|
|
273
|
+
return inco.eNe(eaddress.unwrap(s(a)), eaddress.unwrap(asEaddress(b)));
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
function ne(address a, eaddress b) internal returns (ebool) {
|
|
277
|
+
return inco.eNe(eaddress.unwrap(asEaddress(a)), eaddress.unwrap(s(b)));
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
function ge(euint256 a, euint256 b) internal returns (ebool) {
|
|
281
|
+
return inco.eGe(s(a), s(b));
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
function ge(euint256 a, uint256 b) internal returns (ebool) {
|
|
285
|
+
return inco.eGe(s(a), asEuint256(b));
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
function ge(uint256 a, euint256 b) internal returns (ebool) {
|
|
289
|
+
return inco.eGe(asEuint256(a), s(b));
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
function gt(euint256 a, euint256 b) internal returns (ebool) {
|
|
293
|
+
return inco.eGt(s(a), s(b));
|
|
294
|
+
}
|
|
295
|
+
|
|
296
|
+
function gt(euint256 a, uint256 b) internal returns (ebool) {
|
|
297
|
+
return inco.eGt(s(a), asEuint256(b));
|
|
298
|
+
}
|
|
299
|
+
|
|
300
|
+
function gt(uint256 a, euint256 b) internal returns (ebool) {
|
|
301
|
+
return inco.eGt(asEuint256(a), s(b));
|
|
302
|
+
}
|
|
303
|
+
|
|
304
|
+
function le(euint256 a, euint256 b) internal returns (ebool) {
|
|
305
|
+
return inco.eLe(s(a), s(b));
|
|
306
|
+
}
|
|
307
|
+
|
|
308
|
+
function le(euint256 a, uint256 b) internal returns (ebool) {
|
|
309
|
+
return inco.eLe(s(a), asEuint256(b));
|
|
310
|
+
}
|
|
311
|
+
|
|
312
|
+
function le(uint256 a, euint256 b) internal returns (ebool) {
|
|
313
|
+
return inco.eLe(asEuint256(a), s(b));
|
|
314
|
+
}
|
|
315
|
+
|
|
316
|
+
function lt(euint256 a, euint256 b) internal returns (ebool) {
|
|
317
|
+
return inco.eLt(s(a), s(b));
|
|
318
|
+
}
|
|
319
|
+
|
|
320
|
+
function lt(euint256 a, uint256 b) internal returns (ebool) {
|
|
321
|
+
return inco.eLt(s(a), asEuint256(b));
|
|
322
|
+
}
|
|
323
|
+
|
|
324
|
+
function lt(uint256 a, euint256 b) internal returns (ebool) {
|
|
325
|
+
return inco.eLt(asEuint256(a), s(b));
|
|
326
|
+
}
|
|
327
|
+
|
|
328
|
+
function min(euint256 a, euint256 b) internal returns (euint256) {
|
|
329
|
+
return inco.eMin(s(a), s(b));
|
|
330
|
+
}
|
|
331
|
+
|
|
332
|
+
function min(euint256 a, uint256 b) internal returns (euint256) {
|
|
333
|
+
return inco.eMin(s(a), asEuint256(b));
|
|
334
|
+
}
|
|
335
|
+
|
|
336
|
+
function min(uint256 a, euint256 b) internal returns (euint256) {
|
|
337
|
+
return inco.eMin(asEuint256(a), s(b));
|
|
338
|
+
}
|
|
339
|
+
|
|
340
|
+
function max(euint256 a, euint256 b) internal returns (euint256) {
|
|
341
|
+
return inco.eMax(s(a), s(b));
|
|
342
|
+
}
|
|
343
|
+
|
|
344
|
+
function max(euint256 a, uint256 b) internal returns (euint256) {
|
|
345
|
+
return inco.eMax(s(a), asEuint256(b));
|
|
346
|
+
}
|
|
347
|
+
|
|
348
|
+
function max(uint256 a, euint256 b) internal returns (euint256) {
|
|
349
|
+
return inco.eMax(asEuint256(a), s(b));
|
|
350
|
+
}
|
|
351
|
+
|
|
352
|
+
function not(ebool a) internal returns (ebool) {
|
|
353
|
+
return inco.eNot(s(a));
|
|
354
|
+
}
|
|
355
|
+
|
|
356
|
+
function rand() internal returns (euint256) {
|
|
357
|
+
return euint256.wrap(inco.eRand(ETypes.Uint256));
|
|
358
|
+
}
|
|
359
|
+
|
|
360
|
+
function randBounded(uint256 upperBound) internal returns (euint256) {
|
|
361
|
+
return euint256.wrap(inco.eRandBounded(euint256.unwrap(asEuint256(upperBound)), ETypes.Uint256));
|
|
362
|
+
}
|
|
363
|
+
|
|
364
|
+
function randBounded(euint256 upperBound) internal returns (euint256) {
|
|
365
|
+
return euint256.wrap(inco.eRandBounded(euint256.unwrap(s(upperBound)), ETypes.Uint256));
|
|
366
|
+
}
|
|
367
|
+
|
|
368
|
+
function asEuint256(uint256 a) internal returns (euint256) {
|
|
369
|
+
return inco.asEuint256(a);
|
|
370
|
+
}
|
|
371
|
+
|
|
372
|
+
function asEbool(bool a) internal returns (ebool) {
|
|
373
|
+
return inco.asEbool(a);
|
|
374
|
+
}
|
|
375
|
+
|
|
376
|
+
function asEaddress(address a) internal returns (eaddress) {
|
|
377
|
+
return inco.asEaddress(a);
|
|
378
|
+
}
|
|
379
|
+
|
|
380
|
+
function asEbool(euint256 a) internal returns (ebool) {
|
|
381
|
+
return ebool.wrap(inco.eCast(euint256.unwrap(a), ETypes.Bool));
|
|
382
|
+
}
|
|
383
|
+
|
|
384
|
+
function asEuint256(ebool a) internal returns (euint256) {
|
|
385
|
+
return euint256.wrap(inco.eCast(ebool.unwrap(a), ETypes.Uint256));
|
|
386
|
+
}
|
|
387
|
+
|
|
388
|
+
function newEuint256(bytes memory ciphertext, address user) internal returns (euint256) {
|
|
389
|
+
return inco.newEuint256(ciphertext, user);
|
|
390
|
+
}
|
|
391
|
+
|
|
392
|
+
function newEbool(bytes memory ciphertext, address user) internal returns (ebool) {
|
|
393
|
+
return inco.newEbool(ciphertext, user);
|
|
394
|
+
}
|
|
395
|
+
|
|
396
|
+
function newEaddress(bytes memory ciphertext, address user) internal returns (eaddress) {
|
|
397
|
+
return inco.newEaddress(ciphertext, user);
|
|
398
|
+
}
|
|
399
|
+
|
|
400
|
+
function allow(euint256 a, address to) internal {
|
|
401
|
+
inco.allow(euint256.unwrap(a), to);
|
|
402
|
+
}
|
|
403
|
+
|
|
404
|
+
function allow(ebool a, address to) internal {
|
|
405
|
+
inco.allow(ebool.unwrap(a), to);
|
|
406
|
+
}
|
|
407
|
+
|
|
408
|
+
function allow(eaddress a, address to) internal {
|
|
409
|
+
inco.allow(eaddress.unwrap(a), to);
|
|
410
|
+
}
|
|
411
|
+
|
|
412
|
+
function reveal(euint256 a) internal {
|
|
413
|
+
inco.reveal(euint256.unwrap(a));
|
|
414
|
+
}
|
|
415
|
+
|
|
416
|
+
function reveal(ebool a) internal {
|
|
417
|
+
inco.reveal(ebool.unwrap(a));
|
|
418
|
+
}
|
|
419
|
+
|
|
420
|
+
function reveal(eaddress a) internal {
|
|
421
|
+
inco.reveal(eaddress.unwrap(a));
|
|
422
|
+
}
|
|
423
|
+
|
|
424
|
+
function allowThis(euint256 a) internal {
|
|
425
|
+
allow(a, address(this));
|
|
426
|
+
}
|
|
427
|
+
|
|
428
|
+
function allowThis(ebool a) internal {
|
|
429
|
+
allow(a, address(this));
|
|
430
|
+
}
|
|
431
|
+
|
|
432
|
+
function allowThis(eaddress a) internal {
|
|
433
|
+
allow(a, address(this));
|
|
434
|
+
}
|
|
435
|
+
|
|
436
|
+
function isAllowed(address user, euint256 a) internal view returns (bool) {
|
|
437
|
+
return inco.isAllowed(euint256.unwrap(a), user);
|
|
438
|
+
}
|
|
439
|
+
|
|
440
|
+
function select(ebool control, euint256 ifTrue, euint256 ifFalse) internal returns (euint256) {
|
|
441
|
+
return euint256.wrap(inco.eIfThenElse(s(control), euint256.unwrap(s(ifTrue)), euint256.unwrap(s(ifFalse))));
|
|
442
|
+
}
|
|
443
|
+
|
|
444
|
+
function select(ebool control, ebool ifTrue, ebool ifFalse) internal returns (ebool) {
|
|
445
|
+
return ebool.wrap(inco.eIfThenElse(s(control), ebool.unwrap(s(ifTrue)), ebool.unwrap(s(ifFalse))));
|
|
446
|
+
}
|
|
447
|
+
|
|
448
|
+
function select(ebool control, eaddress ifTrue, eaddress ifFalse) internal returns (eaddress) {
|
|
449
|
+
return eaddress.wrap(inco.eIfThenElse(s(control), eaddress.unwrap(s(ifTrue)), eaddress.unwrap(s(ifFalse))));
|
|
450
|
+
}
|
|
451
|
+
}
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
// SPDX-License-Identifier: No License
|
|
2
2
|
pragma solidity ^0.8;
|
|
3
3
|
|
|
4
|
-
import {SenderNotAllowedForHandle} from "../../Types.sol";
|
|
4
|
+
import {EOps, SenderNotAllowedForHandle} from "../../Types.sol";
|
|
5
5
|
import {IBaseAccessControlList} from "./interfaces/IBaseAccessControlList.sol";
|
|
6
|
+
import {EventCounter} from "../primitives/EventCounter.sol";
|
|
6
7
|
import {VerifierAddressGetter} from "../primitives/VerifierAddressGetter.sol";
|
|
7
8
|
import {AllowanceProof} from "../AccessControl/AdvancedAccessControl.types.sol";
|
|
8
9
|
|
|
@@ -22,13 +23,18 @@ contract AccessControlListStorage {
|
|
|
22
23
|
}
|
|
23
24
|
}
|
|
24
25
|
|
|
25
|
-
|
|
26
|
-
abstract contract BaseAccessControlList is IBaseAccessControlList, AccessControlListStorage, VerifierAddressGetter {
|
|
26
|
+
abstract contract BaseAccessControlList is IBaseAccessControlList, AccessControlListStorage, VerifierAddressGetter, EventCounter {
|
|
27
27
|
error ProofVerificationFailed(
|
|
28
28
|
address verifyingContract,
|
|
29
29
|
bytes4 callFunction,
|
|
30
30
|
bytes argData
|
|
31
31
|
);
|
|
32
|
+
|
|
33
|
+
event EAllow(
|
|
34
|
+
bytes32 handle,
|
|
35
|
+
address account,
|
|
36
|
+
uint256 eventId
|
|
37
|
+
);
|
|
32
38
|
|
|
33
39
|
/// @dev persistent
|
|
34
40
|
function allow(bytes32 handle, address account) public {
|
|
@@ -53,7 +59,9 @@ abstract contract BaseAccessControlList is IBaseAccessControlList, AccessControl
|
|
|
53
59
|
function allowInternal(bytes32 handle, address account) internal {
|
|
54
60
|
ACLStorage storage $ = getACLStorage();
|
|
55
61
|
$.persistedAllowedPairs[handle][account] = true;
|
|
56
|
-
|
|
62
|
+
uint256 id = getNextEventId();
|
|
63
|
+
emit EAllow(handle, account, id);
|
|
64
|
+
setDigest(abi.encodePacked(EOps.Allow, handle, account, id));
|
|
57
65
|
}
|
|
58
66
|
|
|
59
67
|
// todo current transient allowance is unsafe, make storage account bound + how to clean between UserOps
|
|
@@ -9,8 +9,8 @@ import {IEncryptedOperations} from "./interfaces/IEncryptedOperations.sol";
|
|
|
9
9
|
|
|
10
10
|
abstract contract EncryptedOperations is
|
|
11
11
|
IEncryptedOperations,
|
|
12
|
-
BaseAccessControlList,
|
|
13
12
|
EventCounter,
|
|
13
|
+
BaseAccessControlList,
|
|
14
14
|
HandleGeneration
|
|
15
15
|
{
|
|
16
16
|
error UnexpectedType(ETypes actual, bytes32 expectedTypes);
|
|
@@ -36,12 +36,9 @@ abstract contract TEELifecycle is
|
|
|
36
36
|
/// @notice TEEVersionHistory must have exactly one version, please call approveNewTEEVersion first
|
|
37
37
|
error TEEVersionHistoryInconsistent();
|
|
38
38
|
error TEEVersionHistoryStatusIsNotPending();
|
|
39
|
-
error
|
|
39
|
+
error InvalidReportMrAggregated();
|
|
40
40
|
error InvalidBootstrapDataSignature();
|
|
41
|
-
/// @notice MRTD must be exactly 48 bytes
|
|
42
|
-
error MrtdInvalidLength();
|
|
43
41
|
error EOASignerAlreadyInitialized();
|
|
44
|
-
error InvalidMrtdReport();
|
|
45
42
|
error InvalidReportDataSigner();
|
|
46
43
|
|
|
47
44
|
event QuoteVerifierUpdated(uint16 indexed version);
|
|
@@ -120,7 +117,7 @@ abstract contract TEELifecycle is
|
|
|
120
117
|
bytes calldata signature
|
|
121
118
|
) public onlyOwner {
|
|
122
119
|
// Make sure the bootstrap is not already complete, and that the contract owner
|
|
123
|
-
// has already submitted the pending TEE
|
|
120
|
+
// has already submitted the pending TEE MR_AGGREGATED.
|
|
124
121
|
require(!isBootstrapComplete(), BootstrapAlreadyCompleted());
|
|
125
122
|
require(TEEVersionHistory.length == 1, TEEVersionHistoryInconsistent());
|
|
126
123
|
require(
|
|
@@ -132,15 +129,15 @@ abstract contract TEELifecycle is
|
|
|
132
129
|
(bool success, bytes memory output) = _verifyAndAttestOnChain(quote);
|
|
133
130
|
require(success, string(output));
|
|
134
131
|
|
|
135
|
-
|
|
132
|
+
bytes32 v0MrAggregated = TEEVersionHistory[0].mrAggregated;
|
|
136
133
|
|
|
137
134
|
TD10ReportBody memory tdReport = parseTD10ReportBody(quote);
|
|
138
|
-
(address reportDataSigner,
|
|
135
|
+
(address reportDataSigner, bytes32 reportMrAggregated) = parseReport(
|
|
139
136
|
tdReport
|
|
140
137
|
);
|
|
141
138
|
require(
|
|
142
|
-
|
|
143
|
-
|
|
139
|
+
reportMrAggregated == v0MrAggregated,
|
|
140
|
+
InvalidReportMrAggregated()
|
|
144
141
|
);
|
|
145
142
|
address recoveredAddress = ECDSA.recover(
|
|
146
143
|
_bootstrapResultDigest,
|
|
@@ -161,14 +158,12 @@ abstract contract TEELifecycle is
|
|
|
161
158
|
|
|
162
159
|
/**
|
|
163
160
|
* @notice Approves a new TEE version and updates the TEEVersionHistory
|
|
164
|
-
* @param
|
|
161
|
+
* @param newMrAggregated - The MR_AGGREGATED bytes of the new TEE version
|
|
165
162
|
* @dev This function increments the version number automatically based on the current history
|
|
166
163
|
*/
|
|
167
|
-
function approveNewTEEVersion(
|
|
168
|
-
require(newMRTD.length == 48, MrtdInvalidLength());
|
|
169
|
-
|
|
164
|
+
function approveNewTEEVersion(bytes32 newMrAggregated) public onlyOwner {
|
|
170
165
|
TEEVersionHistory.push(
|
|
171
|
-
TEEVersion({
|
|
166
|
+
TEEVersion({mrAggregated: newMrAggregated, status: TEEVersionStatus.PENDING})
|
|
172
167
|
);
|
|
173
168
|
|
|
174
169
|
emit TEEVersionUpdated(TEEVersionHistory[TEEVersionHistory.length - 1]);
|
|
@@ -176,7 +171,7 @@ abstract contract TEELifecycle is
|
|
|
176
171
|
|
|
177
172
|
/**
|
|
178
173
|
* @notice Adds a new covalidator to the contract state
|
|
179
|
-
* @param quote - The quote from the new covalidator that contains the current
|
|
174
|
+
* @param quote - The quote from the new covalidator that contains the current MR_AGGREGATED and the eoa address of the new party in the report data
|
|
180
175
|
*/
|
|
181
176
|
function addNewCovalidator(bytes calldata quote) public onlyOwner {
|
|
182
177
|
require(isBootstrapComplete(), BootstrapNotComplete());
|
|
@@ -184,15 +179,15 @@ abstract contract TEELifecycle is
|
|
|
184
179
|
(bool success, bytes memory output) = _verifyAndAttestOnChain(quote);
|
|
185
180
|
require(success, string(output));
|
|
186
181
|
TD10ReportBody memory tdReport = parseTD10ReportBody(quote);
|
|
187
|
-
(address reportDataSigner,
|
|
182
|
+
(address reportDataSigner, bytes32 reportMrAggregated) = parseReport(
|
|
188
183
|
tdReport
|
|
189
184
|
);
|
|
190
185
|
require(!EOASigners[reportDataSigner], EOASignerAlreadyInitialized());
|
|
191
186
|
|
|
192
187
|
require(
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
188
|
+
reportMrAggregated ==
|
|
189
|
+
TEEVersionHistory[TEEVersionHistory.length - 1].mrAggregated,
|
|
190
|
+
InvalidReportMrAggregated()
|
|
196
191
|
);
|
|
197
192
|
require(reportDataSigner != address(0), InvalidReportDataSigner());
|
|
198
193
|
emit NewCovalidatorAdded(reportDataSigner, quote);
|
|
@@ -320,15 +315,37 @@ abstract contract TEELifecycle is
|
|
|
320
315
|
}
|
|
321
316
|
|
|
322
317
|
/**
|
|
323
|
-
* @notice Parses the TD10 report to extract the report data and
|
|
318
|
+
* @notice Parses the TD10 report to extract the report data and MR_AGGREGATED
|
|
324
319
|
* @param tdReport - The TD10 report body
|
|
325
320
|
* @return reportDataSigner - The signing address of the report data signer
|
|
326
|
-
* @return
|
|
321
|
+
* @return reportMrAggregated - The MR_AGGREGATED bytes from the report
|
|
327
322
|
*/
|
|
328
323
|
function parseReport(
|
|
329
324
|
TD10ReportBody memory tdReport
|
|
330
|
-
) public pure returns (address,
|
|
331
|
-
return (
|
|
325
|
+
) public pure returns (address, bytes32) {
|
|
326
|
+
return (
|
|
327
|
+
address(bytes20(tdReport.reportData)),
|
|
328
|
+
computeMrAggregated(tdReport.mrTd, tdReport.rtMr0, tdReport.rtMr1, tdReport.rtMr2)
|
|
329
|
+
);
|
|
330
|
+
}
|
|
331
|
+
|
|
332
|
+
/**
|
|
333
|
+
* @notice Computes the MR_AGGREGATED from the TD10 report body. It is defined as:
|
|
334
|
+
* KECCAK256(mrTd ++ rtMr0 ++ rtMr1 ++ rtMr2 ++ rtMr3)
|
|
335
|
+
* @param mrTd - The MR_TD bytes
|
|
336
|
+
* @param rtMr0 - The RTMR0 bytes
|
|
337
|
+
* @param rtMr1 - The RTMR1 bytes
|
|
338
|
+
* @param rtMr2 - The RTMR2 bytes
|
|
339
|
+
* @return mrAggregated - The MR_AGGREGATED bytes32
|
|
340
|
+
*/
|
|
341
|
+
function computeMrAggregated(
|
|
342
|
+
bytes memory mrTd,
|
|
343
|
+
bytes memory rtMr0,
|
|
344
|
+
bytes memory rtMr1,
|
|
345
|
+
bytes memory rtMr2
|
|
346
|
+
) public pure returns (bytes32) {
|
|
347
|
+
bytes memory message = abi.encodePacked(mrTd, rtMr0, rtMr1, rtMr2);
|
|
348
|
+
return keccak256(message);
|
|
332
349
|
}
|
|
333
350
|
|
|
334
351
|
function bootstrapResultDigest(
|
|
@@ -12,10 +12,10 @@ enum TEEVersionStatus {
|
|
|
12
12
|
|
|
13
13
|
/**
|
|
14
14
|
* @notice A struct representing a TEE version. The actual version number is the index in the TEEVersionHistory array.
|
|
15
|
-
* @param
|
|
15
|
+
* @param mrAggregated - The MR_AGGREGATED of the TEE version
|
|
16
16
|
* @param status - The status of the TEE version
|
|
17
17
|
*/
|
|
18
18
|
struct TEEVersion {
|
|
19
|
-
|
|
19
|
+
bytes32 mrAggregated;
|
|
20
20
|
TEEVersionStatus status;
|
|
21
21
|
}
|
|
@@ -11,14 +11,14 @@ interface ITEELifecycle {
|
|
|
11
11
|
bytes calldata quote,
|
|
12
12
|
bytes calldata signature
|
|
13
13
|
) external;
|
|
14
|
-
function approveNewTEEVersion(
|
|
14
|
+
function approveNewTEEVersion(bytes32 newMrAggregated) external;
|
|
15
15
|
function addNewCovalidator(bytes calldata quote) external;
|
|
16
16
|
function parseTD10ReportBody(
|
|
17
17
|
bytes calldata rawQuote
|
|
18
18
|
) external pure returns (TD10ReportBody memory report);
|
|
19
19
|
function parseReport(
|
|
20
20
|
TD10ReportBody memory tdReport
|
|
21
|
-
) external pure returns (address,
|
|
21
|
+
) external pure returns (address, bytes32);
|
|
22
22
|
function bootstrapResultDigest(
|
|
23
23
|
BootstrapResult memory bootstrapResult
|
|
24
24
|
) external view returns (bytes32);
|
|
@@ -9,6 +9,12 @@ import {
|
|
|
9
9
|
} from "../../interfaces/automata-interfaces/Types.sol";
|
|
10
10
|
|
|
11
11
|
contract MockRemoteAttestation is TestUtils {
|
|
12
|
+
/**
|
|
13
|
+
* @notice Creates a mock quote for the given MRTD and signer
|
|
14
|
+
* The RTMR0, RTMR1, RTMR2 are set to zeros
|
|
15
|
+
* @dev This function is the same as the non-TDX version of
|
|
16
|
+
* get_tdx_quote in attestation/src/remote_attestation.rs
|
|
17
|
+
*/
|
|
12
18
|
function createQuote(
|
|
13
19
|
bytes memory mrtd,
|
|
14
20
|
address signer
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
// SPDX-License-Identifier: No License
|
|
2
2
|
pragma solidity ^0.8;
|
|
3
3
|
|
|
4
|
+
import {BaseAccessControlList} from "../../lightning-parts/AccessControl/BaseAccessControlList.sol";
|
|
4
5
|
import {EncryptedOperations} from "../../lightning-parts/EncryptedOperations.sol";
|
|
5
6
|
import {TrivialEncryption} from "../../lightning-parts/TrivialEncryption.sol";
|
|
6
7
|
import {EncryptedInput} from "../../lightning-parts/EncryptedInput.sol";
|
|
@@ -62,6 +63,8 @@ function getOpForSelector(bytes32 opEventSelector) pure returns (EOps) {
|
|
|
62
63
|
return EOps.Rand;
|
|
63
64
|
} else if (opEventSelector == EncryptedOperations.ERandBounded.selector) {
|
|
64
65
|
return EOps.RandBounded;
|
|
66
|
+
} else if (opEventSelector == BaseAccessControlList.EAllow.selector) {
|
|
67
|
+
return EOps.Allow;
|
|
65
68
|
} else {
|
|
66
69
|
revert("getOpForSelector: Unsupported selector");
|
|
67
70
|
}
|
package/src/test/IncoTest.sol
CHANGED
|
@@ -32,6 +32,7 @@ contract IncoTest is MockOpHandler, DeployUtils, FakeDecryptionAttester {
|
|
|
32
32
|
(IIncoLightning proxy, ) = deployIncoLightningUsingConfig({
|
|
33
33
|
deployer: testDeployer,
|
|
34
34
|
// The highest precedent deployment
|
|
35
|
+
// We select the pepper that will be used that will be generated in the lib.sol (usually "testnet"), but currently "devnet" has higher major version
|
|
35
36
|
pepper: "devnet",
|
|
36
37
|
quoteVerifier: new FakeQuoteVerifier()
|
|
37
38
|
});
|
|
@@ -19,10 +19,10 @@ contract TEELifecycleMockTest is Test, MockRemoteAttestation, TEELifecycle {
|
|
|
19
19
|
,
|
|
20
20
|
bytes memory quote,
|
|
21
21
|
bytes memory signature,
|
|
22
|
-
|
|
22
|
+
bytes32 mrAggregated
|
|
23
23
|
) = successfulBootstrapResult();
|
|
24
24
|
vm.startPrank(this.owner());
|
|
25
|
-
this.approveNewTEEVersion(
|
|
25
|
+
this.approveNewTEEVersion(mrAggregated);
|
|
26
26
|
this.verifyBootstrapResult(bootstrapResult, quote, signature);
|
|
27
27
|
assertTrue(this.isBootstrapComplete(), "Bootstrap should be complete");
|
|
28
28
|
vm.stopPrank();
|
|
@@ -38,13 +38,13 @@ contract TEELifecycleMockTest is Test, MockRemoteAttestation, TEELifecycle {
|
|
|
38
38
|
address bootstrapPartyAddress,
|
|
39
39
|
bytes memory quote,
|
|
40
40
|
bytes memory signature,
|
|
41
|
-
|
|
41
|
+
bytes32 mrAggregated
|
|
42
42
|
) = successfulBootstrapResult();
|
|
43
43
|
|
|
44
44
|
quote = createQuote(badMrtd, bootstrapPartyAddress); // Replace with bad MRTD
|
|
45
45
|
vm.startPrank(this.owner());
|
|
46
|
-
this.approveNewTEEVersion(
|
|
47
|
-
vm.expectRevert(TEELifecycle.
|
|
46
|
+
this.approveNewTEEVersion(mrAggregated);
|
|
47
|
+
vm.expectRevert(TEELifecycle.InvalidReportMrAggregated.selector);
|
|
48
48
|
this.verifyBootstrapResult(bootstrapResult, quote, signature);
|
|
49
49
|
vm.stopPrank();
|
|
50
50
|
}
|
|
@@ -56,7 +56,7 @@ contract TEELifecycleMockTest is Test, MockRemoteAttestation, TEELifecycle {
|
|
|
56
56
|
,
|
|
57
57
|
bytes memory quote,
|
|
58
58
|
,
|
|
59
|
-
|
|
59
|
+
bytes32 mrAggregated
|
|
60
60
|
) = successfulBootstrapResult();
|
|
61
61
|
(uint256 bootstrapPartyFakePrivkey, ) = getLabeledKeyPair(
|
|
62
62
|
"bootstrapPartyFake"
|
|
@@ -66,7 +66,7 @@ contract TEELifecycleMockTest is Test, MockRemoteAttestation, TEELifecycle {
|
|
|
66
66
|
bootstrapPartyFakePrivkey
|
|
67
67
|
);
|
|
68
68
|
vm.startPrank(this.owner());
|
|
69
|
-
this.approveNewTEEVersion(
|
|
69
|
+
this.approveNewTEEVersion(mrAggregated);
|
|
70
70
|
vm.expectRevert(TEELifecycle.InvalidBootstrapDataSignature.selector);
|
|
71
71
|
this.verifyBootstrapResult(bootstrapResult, quote, signatureInvalid);
|
|
72
72
|
vm.stopPrank();
|
|
@@ -79,29 +79,21 @@ contract TEELifecycleMockTest is Test, MockRemoteAttestation, TEELifecycle {
|
|
|
79
79
|
,
|
|
80
80
|
bytes memory quote,
|
|
81
81
|
bytes memory signature,
|
|
82
|
-
|
|
82
|
+
bytes32 mrAggregated
|
|
83
83
|
) = successfulBootstrapResult();
|
|
84
84
|
vm.startPrank(this.owner());
|
|
85
|
-
this.approveNewTEEVersion(
|
|
85
|
+
this.approveNewTEEVersion(mrAggregated);
|
|
86
86
|
this.verifyBootstrapResult(bootstrapResult, quote, signature);
|
|
87
87
|
vm.expectRevert(TEELifecycle.BootstrapAlreadyCompleted.selector);
|
|
88
88
|
this.verifyBootstrapResult(bootstrapResult, quote, signature);
|
|
89
89
|
vm.stopPrank();
|
|
90
90
|
}
|
|
91
91
|
|
|
92
|
-
function testApproveNewTEEInvalidMrtd() public {
|
|
93
|
-
bytes memory mrtd = hex"deadbeef";
|
|
94
|
-
vm.startPrank(this.owner());
|
|
95
|
-
vm.expectRevert(TEELifecycle.MrtdInvalidLength.selector);
|
|
96
|
-
this.approveNewTEEVersion(mrtd);
|
|
97
|
-
vm.stopPrank();
|
|
98
|
-
}
|
|
99
|
-
|
|
100
92
|
function testBootstrapNotCompleteNewCoval() public {
|
|
101
93
|
bytes
|
|
102
|
-
memory
|
|
94
|
+
memory mrAggregated = hex"2a90c8fa38672cafd791d994beb6836b99383b2563736858632284f0f760a6446efd1e7ec457cf08b629ea630f7b4525";
|
|
103
95
|
(, address newCoval) = getLabeledKeyPair("newCoval");
|
|
104
|
-
bytes memory quote = createQuote(
|
|
96
|
+
bytes memory quote = createQuote(mrAggregated, newCoval);
|
|
105
97
|
vm.startPrank(this.owner());
|
|
106
98
|
vm.expectRevert(TEELifecycle.BootstrapNotComplete.selector);
|
|
107
99
|
this.addNewCovalidator(quote);
|
|
@@ -115,17 +107,17 @@ contract TEELifecycleMockTest is Test, MockRemoteAttestation, TEELifecycle {
|
|
|
115
107
|
,
|
|
116
108
|
bytes memory quote,
|
|
117
109
|
bytes memory signature,
|
|
118
|
-
|
|
110
|
+
bytes32 mrAggregated
|
|
119
111
|
) = successfulBootstrapResult();
|
|
120
112
|
vm.startPrank(this.owner());
|
|
121
|
-
this.approveNewTEEVersion(
|
|
113
|
+
this.approveNewTEEVersion(mrAggregated);
|
|
122
114
|
this.verifyBootstrapResult(bootstrapResult, quote, signature);
|
|
123
115
|
bytes
|
|
124
116
|
memory badMrtd = hex"1234567890abcdef1234567890abcdef1234567890abcdef1234567890abcdef1234567890abcdef1234567890abcdef";
|
|
125
117
|
(, address newCoval) = getLabeledKeyPair("newCoval");
|
|
126
118
|
bytes memory quoteNew = createQuote(badMrtd, newCoval);
|
|
127
119
|
|
|
128
|
-
vm.expectRevert(TEELifecycle.
|
|
120
|
+
vm.expectRevert(TEELifecycle.InvalidReportMrAggregated.selector);
|
|
129
121
|
this.addNewCovalidator(quoteNew);
|
|
130
122
|
vm.stopPrank();
|
|
131
123
|
}
|
|
@@ -139,7 +131,7 @@ contract TEELifecycleMockTest is Test, MockRemoteAttestation, TEELifecycle {
|
|
|
139
131
|
address bootstrapPartyAddress,
|
|
140
132
|
bytes memory quote,
|
|
141
133
|
bytes memory signature,
|
|
142
|
-
|
|
134
|
+
bytes32 mrAggregated
|
|
143
135
|
)
|
|
144
136
|
{
|
|
145
137
|
(bootstrapPartyPrivkey, bootstrapPartyAddress) = getLabeledKeyPair(
|
|
@@ -147,8 +139,11 @@ contract TEELifecycleMockTest is Test, MockRemoteAttestation, TEELifecycle {
|
|
|
147
139
|
);
|
|
148
140
|
bytes
|
|
149
141
|
memory eciesPubkey = hex"04ff5c6dd72ad7583288b84ee2598e081fe0bc6ef543c342e925a5dfcff9afb2444d25454d7d5dcfadc9ed99477c245efa93caf58d7f58143300d81cc948e7bdf5";
|
|
150
|
-
|
|
151
|
-
|
|
142
|
+
// See DEFAULT_MRTD in attestation/src/remote_attestation.rs
|
|
143
|
+
bytes memory mrtd = hex"010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101";
|
|
144
|
+
// See DEFAULT_MR_AGGREGATED in attestation/src/remote_attestation.rs to
|
|
145
|
+
// see the calculation of the default value.
|
|
146
|
+
mrAggregated = hex"c3a67bac251d4946d7b17481d39631676042fe3afab06e70c22105ad8383c19f";
|
|
152
147
|
bootstrapResult = BootstrapResult({ecies_pubkey: eciesPubkey});
|
|
153
148
|
|
|
154
149
|
quote = createQuote(mrtd, bootstrapPartyAddress);
|
|
@@ -297,10 +297,9 @@ contract TestFakeInfra is IncoTest, MockRemoteAttestation {
|
|
|
297
297
|
bytes memory quote = createQuote(mrtd, signer);
|
|
298
298
|
TEELifecycle lifecycle = TEELifecycle(address(inco.incoVerifier()));
|
|
299
299
|
TD10ReportBody memory tdReport = lifecycle.parseTD10ReportBody(quote);
|
|
300
|
-
(address reportDataSigner,
|
|
301
|
-
.parseReport(tdReport);
|
|
300
|
+
(address reportDataSigner, bytes32 reportMrAggregated) = lifecycle.parseReport(tdReport);
|
|
302
301
|
assertEq(reportDataSigner, signer);
|
|
303
|
-
assertEq(
|
|
302
|
+
assertEq(reportMrAggregated, lifecycle.computeMrAggregated(tdReport.mrTd, tdReport.rtMr0, tdReport.rtMr1, tdReport.rtMr2));
|
|
304
303
|
assertEq(quote.length, MINIMUM_QUOTE_LENGTH);
|
|
305
304
|
}
|
|
306
305
|
}
|
|
@@ -9,6 +9,8 @@ pragma solidity ^0.8;
|
|
|
9
9
|
string constant CONTRACT_NAME = "incoLightning";
|
|
10
10
|
uint8 constant MAJOR_VERSION = 1;
|
|
11
11
|
uint8 constant MINOR_VERSION = 0;
|
|
12
|
-
|
|
12
|
+
// whenever a new major version is deployed, we need to pump this up
|
|
13
|
+
// otherwise make test_upgrade will fail
|
|
14
|
+
uint8 constant PATCH_VERSION = 1;
|
|
13
15
|
|
|
14
16
|
string constant VERIFIER_NAME = "incoVerifier";
|
|
@@ -1,53 +0,0 @@
|
|
|
1
|
-
# TEE Lifecycle Test
|
|
2
|
-
|
|
3
|
-
## TEELifecycle HW Test
|
|
4
|
-
|
|
5
|
-
This test data was generated using Adrian's V0 TDX VM running in GCP. The data
|
|
6
|
-
was returned collected using the `agent-lib` tool.
|
|
7
|
-
|
|
8
|
-
* To generate new test data: for `test_LifecycleBootstrap`
|
|
9
|
-
|
|
10
|
-
```bash
|
|
11
|
-
cd agent-lib
|
|
12
|
-
|
|
13
|
-
cargo run --features hw -- start-bootstrap \
|
|
14
|
-
--expected-mrtd 0x409c0cd3e63d9ea54d817cf851983a220131262664ac8cd02cc6a2e19fd291d2fdd0cc035d7789b982a43a92a4424c99 \
|
|
15
|
-
--tee-lifecycle-grpc-url http://34.91.236.235:4321 \
|
|
16
|
-
--output-dir ../contracts/lightning/src/test/TEELifecycle/bootstrap_data
|
|
17
|
-
```
|
|
18
|
-
|
|
19
|
-
* To generate new test data for `test_LifecycleNewEOA`
|
|
20
|
-
|
|
21
|
-
```bash
|
|
22
|
-
cd agent-lib
|
|
23
|
-
|
|
24
|
-
# TODO: change this to add-node endpoint after https://github.com/Inco-fhevm/inco-monorepo/issues/889
|
|
25
|
-
cargo run --features hw -- start-bootstrap \
|
|
26
|
-
--expected-mrtd 0x409c0cd3e63d9ea54d817cf851983a220131262664ac8cd02cc6a2e19fd291d2fdd0cc035d7789b982a43a92a4424c99 \
|
|
27
|
-
--tee-lifecycle-grpc-url http://34.91.236.235:4321 \
|
|
28
|
-
--output-dir ../contracts/lightning/src/test/TEELifecycle/addnode_data
|
|
29
|
-
|
|
30
|
-
# Delete the unused output data since it is not used
|
|
31
|
-
# to add a node
|
|
32
|
-
rm ../contracts/lightning/src/test/TEELifecycle/addnode_data/ecies_pubkey.bin
|
|
33
|
-
rm ../contracts/lightning/src/test/TEELifecycle/addnode_data/eip712_signature.bin
|
|
34
|
-
rm ../contracts/lightning/src/test/TEELifecycle/addnode_data/qe_identity
|
|
35
|
-
rm ../contracts/lightning/src/test/TEELifecycle/addnode_data/qe_identity_signature.bin
|
|
36
|
-
rm ../contracts/lightning/src/test/TEELifecycle/addnode_data/tcb_info
|
|
37
|
-
rm ../contracts/lightning/src/test/TEELifecycle/addnode_data/tcb_info_signature.bin
|
|
38
|
-
```
|
|
39
|
-
|
|
40
|
-
* To generate the Intel root certificates
|
|
41
|
-
|
|
42
|
-
```bash
|
|
43
|
-
cd contracts/lightning/src/test/TEELifecycle/test_cert
|
|
44
|
-
python3 -m pip install -r ../../../../../lightning-deployment/script/tee/requirements.txt
|
|
45
|
-
python3 ../../../../../lightning-deployment/script/tee/get_ca_certs.py
|
|
46
|
-
```
|
|
47
|
-
|
|
48
|
-
* Hard code the block timestamp to the current time to ensure that there is no certificate out of date errors
|
|
49
|
-
by setting `uint256 collateral_timestamp =` in [TEELifecycleHWTest.t](TEELifecycleHWTest.t.sol#24) to the output of:
|
|
50
|
-
|
|
51
|
-
```bash
|
|
52
|
-
echo $(date +%s)
|
|
53
|
-
```
|