@inco/lightning 0.6.8 → 0.6.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/README.md +29 -2
- package/manifest.yaml +0 -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.template.sol +40 -159
- package/src/Types.sol +233 -97
- package/src/interfaces/IIncoLightning.sol +2 -0
- package/src/interfaces/IIncoVerifier.sol +7 -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_devnet_v1_887305889.sol +5 -3
- package/src/libs/incoLightning_testnet_v1_938327937.sol +5 -3
- package/src/lightning-parts/AccessControl/AdvancedAccessControl.sol +41 -75
- 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 +42 -83
- 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 +93 -440
- package/src/lightning-parts/Fee.sol +3 -1
- package/src/lightning-parts/TEELifecycle.sol +95 -225
- 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 +146 -419
- package/src/pasted-dependencies/ICreateX.sol +58 -102
- package/src/periphery/SessionVerifier.sol +5 -7
- 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 +14 -13
- package/src/test/AddTwo.sol +9 -7
- package/src/test/FakeIncoInfra/FakeComputeServer.sol +11 -53
- package/src/test/FakeIncoInfra/FakeDecryptionAttester.sol +35 -118
- 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 +44 -21
- package/src/test/IncoTest.sol +15 -9
- package/src/test/OpsTest.sol +429 -0
- package/src/test/TEELifecycle/TEELifecycleMockTest.t.sol +58 -104
- package/src/test/TestAddTwo.t.sol +4 -3
- package/src/test/TestDeploy.t.sol +5 -6
- package/src/test/TestExtractDataOfEventTooLarge.t.sol +7 -14
- 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 +1 -1
- package/src/version/Version.sol +48 -51
- package/src/version/interfaces/IVersion.sol +6 -0
|
@@ -7,18 +7,13 @@ import {ITEELifecycle} from "../lightning-parts/interfaces/ITEELifecycle.sol";
|
|
|
7
7
|
import {IQuoteVerifier} from "./automata-interfaces/IQuoteVerifier.sol";
|
|
8
8
|
import {ISignatureVerifier} from "../lightning-parts/primitives/interfaces/ISignatureVerifier.sol";
|
|
9
9
|
|
|
10
|
-
interface IIncoVerifier is
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
{
|
|
16
|
-
function initialize(
|
|
17
|
-
address owner,
|
|
18
|
-
string memory name,
|
|
19
|
-
string memory version,
|
|
20
|
-
IQuoteVerifier quoteVerifier
|
|
21
|
-
) external;
|
|
10
|
+
interface IIncoVerifier is IAdvancedAccessControl, IDecryptionAttester, ITEELifecycle, ISignatureVerifier {
|
|
11
|
+
|
|
12
|
+
function initialize(address owner, string memory name, string memory version, IQuoteVerifier quoteVerifier)
|
|
13
|
+
external;
|
|
14
|
+
// forge-lint: disable-next-line(mixed-case-function)
|
|
22
15
|
function getEIP712Name() external view returns (string memory);
|
|
16
|
+
// forge-lint: disable-next-line(mixed-case-function)
|
|
23
17
|
function getEIP712Version() external view returns (string memory);
|
|
18
|
+
|
|
24
19
|
}
|
|
@@ -5,6 +5,7 @@ pragma solidity ^0.8.0;
|
|
|
5
5
|
* @notice Converts a little-endian encoded bytes to a big-endian uint256 integer
|
|
6
6
|
*/
|
|
7
7
|
library BELE {
|
|
8
|
+
|
|
8
9
|
function leBytesToBeUint(bytes memory encoded) internal pure returns (uint256 decoded) {
|
|
9
10
|
for (uint256 i = 0; i < encoded.length; i++) {
|
|
10
11
|
uint256 digits = uint256(uint8(bytes1(encoded[i])));
|
|
@@ -17,4 +18,5 @@ library BELE {
|
|
|
17
18
|
decoded += acc;
|
|
18
19
|
}
|
|
19
20
|
}
|
|
21
|
+
|
|
20
22
|
}
|
|
@@ -5,24 +5,22 @@ import {EnclaveIdentityJsonObj, IdentityObj} from "./Types.sol";
|
|
|
5
5
|
|
|
6
6
|
// only the functions we need have been included here
|
|
7
7
|
interface IEnclaveIdentityHelper {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
)
|
|
8
|
+
|
|
9
|
+
function parseIdentityString(string calldata identityStr)
|
|
11
10
|
external
|
|
12
11
|
pure
|
|
13
12
|
returns (IdentityObj memory identity, string memory identityTcbString);
|
|
13
|
+
|
|
14
14
|
}
|
|
15
15
|
|
|
16
16
|
// only the functions we need have been included here
|
|
17
17
|
interface IAutomataEnclaveIdentityDao {
|
|
18
|
-
function upsertEnclaveIdentity(
|
|
19
|
-
uint256 id,
|
|
20
|
-
uint256 version,
|
|
21
|
-
EnclaveIdentityJsonObj calldata enclaveIdentityObj
|
|
22
|
-
) external returns (bytes32 attestationId);
|
|
23
18
|
|
|
24
|
-
function
|
|
19
|
+
function upsertEnclaveIdentity(uint256 id, uint256 version, EnclaveIdentityJsonObj calldata enclaveIdentityObj)
|
|
25
20
|
external
|
|
26
|
-
|
|
27
|
-
|
|
21
|
+
returns (bytes32 attestationId);
|
|
22
|
+
|
|
23
|
+
// forge-lint: disable-next-line(mixed-case-function)
|
|
24
|
+
function EnclaveIdentityLib() external view returns (IEnclaveIdentityHelper);
|
|
25
|
+
|
|
28
26
|
}
|
|
@@ -4,7 +4,7 @@ pragma solidity ^0.8;
|
|
|
4
4
|
import {TcbInfoJsonObj} from "./Types.sol";
|
|
5
5
|
|
|
6
6
|
interface IFmspcTcbDao {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
7
|
+
|
|
8
|
+
function upsertFmspcTcb(TcbInfoJsonObj calldata tcbInfoObj) external returns (bytes32 attestationId);
|
|
9
|
+
|
|
10
10
|
}
|
|
@@ -1,18 +1,7 @@
|
|
|
1
1
|
//SPDX-License-Identifier: MIT
|
|
2
2
|
pragma solidity >=0.8.0;
|
|
3
3
|
|
|
4
|
-
import {
|
|
5
|
-
EnclaveIdentityJsonObj,
|
|
6
|
-
IdentityObj,
|
|
7
|
-
EnclaveId,
|
|
8
|
-
CA,
|
|
9
|
-
TcbInfoJsonObj,
|
|
10
|
-
TCBLevelsObj,
|
|
11
|
-
TcbInfoBasic,
|
|
12
|
-
TcbId,
|
|
13
|
-
TDXModule,
|
|
14
|
-
TDXModuleIdentity
|
|
15
|
-
} from "./Types.sol";
|
|
4
|
+
import {IdentityObj, EnclaveId, CA, TcbLevelsObj, TcbId, TdxModule, TdxModuleIdentity} from "./Types.sol";
|
|
16
5
|
|
|
17
6
|
/**
|
|
18
7
|
* @title PCCS Router Interface
|
|
@@ -20,6 +9,7 @@ import {
|
|
|
20
9
|
* to fetch collaterals from the On Chain PCCS
|
|
21
10
|
*/
|
|
22
11
|
interface IPCCSRouter {
|
|
12
|
+
|
|
23
13
|
function qeIdDaoAddr() external view returns (address);
|
|
24
14
|
|
|
25
15
|
function fmspcTcbDaoAddr() external view returns (address);
|
|
@@ -34,37 +24,18 @@ interface IPCCSRouter {
|
|
|
34
24
|
|
|
35
25
|
function fmspcTcbHelperAddr() external view returns (address);
|
|
36
26
|
|
|
37
|
-
function getQeIdentity(
|
|
38
|
-
EnclaveId id,
|
|
39
|
-
uint256 quoteVersion
|
|
40
|
-
) external view returns (IdentityObj memory);
|
|
27
|
+
function getQeIdentity(EnclaveId id, uint256 quoteVersion) external view returns (IdentityObj memory);
|
|
41
28
|
|
|
42
|
-
function getQeIdentityContentHash(
|
|
43
|
-
EnclaveId id,
|
|
44
|
-
uint256 version
|
|
45
|
-
) external view returns (bytes32);
|
|
29
|
+
function getQeIdentityContentHash(EnclaveId id, uint256 version) external view returns (bytes32);
|
|
46
30
|
|
|
47
|
-
function getFmspcTcbV2(
|
|
48
|
-
bytes6 fmspc
|
|
49
|
-
) external view returns (TCBLevelsObj[] memory);
|
|
31
|
+
function getFmspcTcbV2(bytes6 fmspc) external view returns (TcbLevelsObj[] memory);
|
|
50
32
|
|
|
51
|
-
function getFmspcTcbV3(
|
|
52
|
-
TcbId id,
|
|
53
|
-
bytes6 fmspc
|
|
54
|
-
)
|
|
33
|
+
function getFmspcTcbV3(TcbId id, bytes6 fmspc)
|
|
55
34
|
external
|
|
56
35
|
view
|
|
57
|
-
returns (
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
TDXModuleIdentity[] memory
|
|
61
|
-
);
|
|
62
|
-
|
|
63
|
-
function getFmspcTcbContentHash(
|
|
64
|
-
TcbId id,
|
|
65
|
-
bytes6 fmspc,
|
|
66
|
-
uint32 version
|
|
67
|
-
) external view returns (bytes32);
|
|
36
|
+
returns (TcbLevelsObj[] memory, TdxModule memory, TdxModuleIdentity[] memory);
|
|
37
|
+
|
|
38
|
+
function getFmspcTcbContentHash(TcbId id, bytes6 fmspc, uint32 version) external view returns (bytes32);
|
|
68
39
|
|
|
69
40
|
function getPckCert(
|
|
70
41
|
string calldata qeid,
|
|
@@ -82,13 +53,8 @@ interface IPCCSRouter {
|
|
|
82
53
|
function getCrlHash(CA ca) external view returns (bytes32);
|
|
83
54
|
|
|
84
55
|
// *withTimestamp() methods to check collateral expiration status based on the provided timestamp
|
|
85
|
-
function getCertHashWithTimestamp(
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
function getCrlHashWithTimestamp(
|
|
91
|
-
CA ca,
|
|
92
|
-
uint64 timestamp
|
|
93
|
-
) external view returns (bytes32);
|
|
56
|
+
function getCertHashWithTimestamp(CA ca, uint64 timestamp) external view returns (bytes32);
|
|
57
|
+
|
|
58
|
+
function getCrlHashWithTimestamp(CA ca, uint64 timestamp) external view returns (bytes32);
|
|
59
|
+
|
|
94
60
|
}
|
|
@@ -6,5 +6,7 @@ import {IPCCSRouter} from "./IPCCSRouter.sol";
|
|
|
6
6
|
/// @dev we declare this interface because the one exported from the automata-dcap-attestation package is missing some
|
|
7
7
|
/// external functions.
|
|
8
8
|
interface IPCCSRouterExtended is IPCCSRouter {
|
|
9
|
+
|
|
9
10
|
function setAuthorized(address caller, bool authorized) external;
|
|
11
|
+
|
|
10
12
|
}
|
|
@@ -4,15 +4,10 @@ pragma solidity ^0.8.0;
|
|
|
4
4
|
import {CA} from "./Types.sol";
|
|
5
5
|
|
|
6
6
|
interface IPcsDao {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
function
|
|
12
|
-
|
|
13
|
-
bytes calldata crl
|
|
14
|
-
) external returns (bytes32 attestationId);
|
|
15
|
-
function upsertRootCACrl(
|
|
16
|
-
bytes calldata rootcacrl
|
|
17
|
-
) external returns (bytes32 attestationId);
|
|
7
|
+
|
|
8
|
+
function upsertPcsCertificates(CA ca, bytes calldata cert) external returns (bytes32 attestationId);
|
|
9
|
+
function upsertPckCrl(CA ca, bytes calldata crl) external returns (bytes32 attestationId);
|
|
10
|
+
// forge-lint: disable-next-line(mixed-case-function)
|
|
11
|
+
function upsertRootCACrl(bytes calldata rootcacrl) external returns (bytes32 attestationId);
|
|
12
|
+
|
|
18
13
|
}
|
|
@@ -9,6 +9,7 @@ import {Header} from "./Types.sol";
|
|
|
9
9
|
* @notice Provides the interface to implement version-specific verifiers
|
|
10
10
|
*/
|
|
11
11
|
interface IQuoteVerifier {
|
|
12
|
+
|
|
12
13
|
/**
|
|
13
14
|
* @dev this method must be immutable
|
|
14
15
|
* @return an instance of the PCCSRouter interface
|
|
@@ -20,15 +21,11 @@ interface IQuoteVerifier {
|
|
|
20
21
|
*/
|
|
21
22
|
function quoteVersion() external view returns (uint16);
|
|
22
23
|
|
|
23
|
-
function verifyQuote(
|
|
24
|
-
Header calldata,
|
|
25
|
-
bytes calldata
|
|
26
|
-
) external view returns (bool, bytes memory);
|
|
24
|
+
function verifyQuote(Header calldata, bytes calldata) external view returns (bool, bytes memory);
|
|
27
25
|
|
|
28
26
|
/**
|
|
29
27
|
* @notice additional check on the public output obtained from the ZK Program execution
|
|
30
28
|
*/
|
|
31
|
-
function verifyZkOutput(
|
|
32
|
-
|
|
33
|
-
) external view returns (bool, bytes memory);
|
|
29
|
+
function verifyZkOutput(bytes calldata) external view returns (bool, bytes memory);
|
|
30
|
+
|
|
34
31
|
}
|
|
@@ -41,7 +41,7 @@ struct TcbInfoBasic {
|
|
|
41
41
|
bytes2 pceid;
|
|
42
42
|
}
|
|
43
43
|
|
|
44
|
-
struct
|
|
44
|
+
struct TcbLevelsObj {
|
|
45
45
|
uint16 pcesvn;
|
|
46
46
|
uint8[] sgxComponentCpuSvns;
|
|
47
47
|
uint8[] tdxComponentCpuSvns;
|
|
@@ -50,21 +50,21 @@ struct TCBLevelsObj {
|
|
|
50
50
|
string[] advisoryIDs;
|
|
51
51
|
}
|
|
52
52
|
|
|
53
|
-
struct
|
|
53
|
+
struct TdxModule {
|
|
54
54
|
bytes mrsigner; // 48 bytes
|
|
55
55
|
bytes8 attributes;
|
|
56
56
|
bytes8 attributesMask;
|
|
57
57
|
}
|
|
58
58
|
|
|
59
|
-
struct
|
|
59
|
+
struct TdxModuleIdentity {
|
|
60
60
|
string id;
|
|
61
61
|
bytes8 attributes;
|
|
62
62
|
bytes8 attributesMask;
|
|
63
63
|
bytes mrsigner; // 48 bytes
|
|
64
|
-
|
|
64
|
+
TdxModuleTcbLevelsObj[] tcbLevels;
|
|
65
65
|
}
|
|
66
66
|
|
|
67
|
-
struct
|
|
67
|
+
struct TdxModuleTcbLevelsObj {
|
|
68
68
|
uint8 isvsvn;
|
|
69
69
|
uint64 tcbDateTimestamp;
|
|
70
70
|
TCBStatus status;
|
|
@@ -154,12 +154,13 @@ struct Header {
|
|
|
154
154
|
* @dev Section A.3.2 of Intel V4 TDX DCAP API Library Documentation
|
|
155
155
|
* @dev https://github.com/intel/SGX-TDX-DCAP-QuoteVerificationLibrary/blob/7e5b2a13ca5472de8d97dd7d7024c2ea5af9a6ba/Src/AttestationLibrary/src/QuoteVerification/QuoteStructures.h#L82-L103
|
|
156
156
|
*/
|
|
157
|
-
struct
|
|
157
|
+
struct Td10ReportBody {
|
|
158
158
|
bytes16 teeTcbSvn;
|
|
159
159
|
bytes mrSeam; // 48 bytes
|
|
160
160
|
bytes mrsignerSeam; // 48 bytes
|
|
161
161
|
bytes8 seamAttributes;
|
|
162
162
|
bytes8 tdAttributes;
|
|
163
|
+
// forge-lint: disable-next-line(mixed-case-variable)
|
|
163
164
|
bytes8 xFAM;
|
|
164
165
|
bytes mrTd; // 48 bytes
|
|
165
166
|
bytes mrConfigId; // 48 bytes
|
|
@@ -5,8 +5,8 @@
|
|
|
5
5
|
/// SPDX-License-Identifier: No License
|
|
6
6
|
pragma solidity ^0.8;
|
|
7
7
|
|
|
8
|
-
import {
|
|
9
|
-
import {
|
|
8
|
+
import {IncoLightning} from "../IncoLightning.sol";
|
|
9
|
+
import {ebool, euint256, eaddress, ETypes} from "../Types.sol";
|
|
10
10
|
|
|
11
11
|
IncoLightning constant inco = IncoLightning(0x7b98b0482099611B0ebEA0F98f81FF555406794A);
|
|
12
12
|
address constant deployedBy = 0x8202D2D747784Cb7D48868E44C42C4bf162a70BC;
|
|
@@ -16,6 +16,7 @@ function typeOf(bytes32 handle) pure returns (ETypes) {
|
|
|
16
16
|
}
|
|
17
17
|
|
|
18
18
|
library e {
|
|
19
|
+
|
|
19
20
|
function sanitize(euint256 a) internal returns (euint256) {
|
|
20
21
|
if (euint256.unwrap(a) == bytes32(0)) {
|
|
21
22
|
return asEuint256(0);
|
|
@@ -448,4 +449,5 @@ library e {
|
|
|
448
449
|
function select(ebool control, eaddress ifTrue, eaddress ifFalse) internal returns (eaddress) {
|
|
449
450
|
return eaddress.wrap(inco.eIfThenElse(s(control), eaddress.unwrap(s(ifTrue)), eaddress.unwrap(s(ifFalse))));
|
|
450
451
|
}
|
|
451
|
-
|
|
452
|
+
|
|
453
|
+
}
|
|
@@ -5,8 +5,8 @@
|
|
|
5
5
|
/// SPDX-License-Identifier: No License
|
|
6
6
|
pragma solidity ^0.8;
|
|
7
7
|
|
|
8
|
-
import {
|
|
9
|
-
import {
|
|
8
|
+
import {IncoLightning} from "../IncoLightning.sol";
|
|
9
|
+
import {ebool, euint256, eaddress, ETypes} from "../Types.sol";
|
|
10
10
|
|
|
11
11
|
IncoLightning constant inco = IncoLightning(0xFb0Bd1a97DD2ECA4c7560b2a35d56474593f3Bab);
|
|
12
12
|
address constant deployedBy = 0x1804c8AB1F12E6bbf3894d4083f33e07309d1f38;
|
|
@@ -16,6 +16,7 @@ function typeOf(bytes32 handle) pure returns (ETypes) {
|
|
|
16
16
|
}
|
|
17
17
|
|
|
18
18
|
library e {
|
|
19
|
+
|
|
19
20
|
function sanitize(euint256 a) internal returns (euint256) {
|
|
20
21
|
if (euint256.unwrap(a) == bytes32(0)) {
|
|
21
22
|
return asEuint256(0);
|
|
@@ -448,4 +449,5 @@ library e {
|
|
|
448
449
|
function select(ebool control, eaddress ifTrue, eaddress ifFalse) internal returns (eaddress) {
|
|
449
450
|
return eaddress.wrap(inco.eIfThenElse(s(control), eaddress.unwrap(s(ifTrue)), eaddress.unwrap(s(ifFalse))));
|
|
450
451
|
}
|
|
451
|
-
|
|
452
|
+
|
|
453
|
+
}
|
|
@@ -11,43 +11,42 @@ import {IBaseAccessControlList} from "./interfaces/IBaseAccessControlList.sol";
|
|
|
11
11
|
import {LightningAddressGetter} from "../primitives/LightningAddressGetter.sol";
|
|
12
12
|
|
|
13
13
|
abstract contract AdvancedAccessControlStorage {
|
|
14
|
-
|
|
14
|
+
|
|
15
|
+
struct AacStorage {
|
|
15
16
|
mapping(address => bytes32) activeVouchersSessionNonce; // initial session nonce is 0
|
|
16
17
|
}
|
|
17
18
|
|
|
18
|
-
bytes32 private constant
|
|
19
|
-
keccak256("inco.storage.AdvancedAccessControl");
|
|
19
|
+
bytes32 private constant AAC_STORAGE_LOCATION = keccak256("inco.storage.AdvancedAccessControl");
|
|
20
20
|
|
|
21
|
-
function
|
|
22
|
-
bytes32 loc =
|
|
21
|
+
function getAacStorage() internal pure returns (AacStorage storage $) {
|
|
22
|
+
bytes32 loc = AAC_STORAGE_LOCATION;
|
|
23
23
|
assembly {
|
|
24
24
|
$.slot := loc
|
|
25
25
|
}
|
|
26
26
|
}
|
|
27
|
+
|
|
27
28
|
}
|
|
28
|
-
|
|
29
|
+
|
|
29
30
|
abstract contract VoucherEip712Checker is IVoucherEip712Checker, EIP712Upgradeable {
|
|
30
|
-
bytes32 constant AllowanceVoucherStructHash =
|
|
31
|
-
keccak256(
|
|
32
|
-
"AllowanceVoucher(bytes32 sessionNonce,address verifyingContract,bytes4 callFunction,bytes sharerArgData)"
|
|
33
|
-
);
|
|
34
31
|
|
|
35
|
-
|
|
36
|
-
AllowanceVoucher
|
|
37
|
-
)
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
)
|
|
32
|
+
bytes32 constant ALLOWANCE_VOUCHER_STRUCT_HASH = keccak256(
|
|
33
|
+
"AllowanceVoucher(bytes32 sessionNonce,address verifyingContract,bytes4 callFunction,bytes sharerArgData)"
|
|
34
|
+
);
|
|
35
|
+
|
|
36
|
+
function allowanceVoucherDigest(AllowanceVoucher memory voucher) public view returns (bytes32) {
|
|
37
|
+
return _hashTypedDataV4(
|
|
38
|
+
keccak256(
|
|
39
|
+
abi.encode(
|
|
40
|
+
ALLOWANCE_VOUCHER_STRUCT_HASH,
|
|
41
|
+
voucher.sessionNonce,
|
|
42
|
+
voucher.verifyingContract,
|
|
43
|
+
voucher.callFunction,
|
|
44
|
+
keccak256(voucher.sharerArgData)
|
|
48
45
|
)
|
|
49
|
-
)
|
|
46
|
+
)
|
|
47
|
+
);
|
|
50
48
|
}
|
|
49
|
+
|
|
51
50
|
}
|
|
52
51
|
|
|
53
52
|
abstract contract AdvancedAccessControl is
|
|
@@ -56,78 +55,45 @@ abstract contract AdvancedAccessControl is
|
|
|
56
55
|
VoucherEip712Checker,
|
|
57
56
|
LightningAddressGetter
|
|
58
57
|
{
|
|
58
|
+
|
|
59
59
|
using SignatureChecker for address;
|
|
60
60
|
|
|
61
|
-
error InvalidVoucherSignature(
|
|
62
|
-
|
|
63
|
-
bytes32 digest,
|
|
64
|
-
bytes signature
|
|
65
|
-
);
|
|
66
|
-
error InvalidVoucherSessionNonce(
|
|
67
|
-
bytes32 providedSessionNonce,
|
|
68
|
-
bytes32 activeSessionNonce
|
|
69
|
-
);
|
|
61
|
+
error InvalidVoucherSignature(address signer, bytes32 digest, bytes signature);
|
|
62
|
+
error InvalidVoucherSessionNonce(bytes32 providedSessionNonce, bytes32 activeSessionNonce);
|
|
70
63
|
|
|
71
64
|
/// @dev meant to for simulation, can't be a view function as it calls other contracts
|
|
72
65
|
/// @dev returns true if the account is allowed to access the handle, false or reverts otherwise
|
|
73
|
-
function isAllowedWithProof(
|
|
74
|
-
bytes32 handle,
|
|
75
|
-
address account,
|
|
76
|
-
AllowanceProof memory proof
|
|
77
|
-
) public returns (bool) {
|
|
66
|
+
function isAllowedWithProof(bytes32 handle, address account, AllowanceProof memory proof) public returns (bool) {
|
|
78
67
|
require(
|
|
79
68
|
IBaseAccessControlList(incoLightningAddress).isAllowed(handle, proof.sharer),
|
|
80
69
|
SharerNotAllowedForHandle(handle, proof.sharer)
|
|
81
70
|
);
|
|
82
71
|
bytes32 voucherDigest = allowanceVoucherDigest(proof.voucher);
|
|
83
72
|
require(
|
|
84
|
-
proof.sharer.isValidSignatureNow(
|
|
85
|
-
|
|
86
|
-
proof.voucherSignature
|
|
87
|
-
),
|
|
88
|
-
InvalidVoucherSignature(
|
|
89
|
-
proof.sharer,
|
|
90
|
-
voucherDigest,
|
|
91
|
-
proof.voucherSignature
|
|
92
|
-
)
|
|
73
|
+
proof.sharer.isValidSignatureNow(voucherDigest, proof.voucherSignature),
|
|
74
|
+
InvalidVoucherSignature(proof.sharer, voucherDigest, proof.voucherSignature)
|
|
93
75
|
);
|
|
94
|
-
bytes32 sharerActiveVouchersSessionNonce = getActiveVouchersSessionNonce(
|
|
95
|
-
proof.sharer
|
|
96
|
-
);
|
|
76
|
+
bytes32 sharerActiveVouchersSessionNonce = getActiveVouchersSessionNonce(proof.sharer);
|
|
97
77
|
require(
|
|
98
78
|
proof.voucher.sessionNonce == sharerActiveVouchersSessionNonce,
|
|
99
|
-
InvalidVoucherSessionNonce(
|
|
100
|
-
|
|
101
|
-
|
|
79
|
+
InvalidVoucherSessionNonce(proof.voucher.sessionNonce, sharerActiveVouchersSessionNonce)
|
|
80
|
+
);
|
|
81
|
+
(bool success, bytes memory result) = proof.voucher.verifyingContract.call(
|
|
82
|
+
abi.encodeWithSelector(
|
|
83
|
+
proof.voucher.callFunction, handle, account, proof.voucher.sharerArgData, proof.requesterArgData
|
|
102
84
|
)
|
|
103
85
|
);
|
|
104
|
-
(
|
|
105
|
-
.voucher
|
|
106
|
-
.verifyingContract
|
|
107
|
-
.call(
|
|
108
|
-
abi.encodeWithSelector(
|
|
109
|
-
proof.voucher.callFunction,
|
|
110
|
-
handle,
|
|
111
|
-
account,
|
|
112
|
-
proof.voucher.sharerArgData,
|
|
113
|
-
proof.requesterArgData
|
|
114
|
-
)
|
|
115
|
-
);
|
|
116
|
-
return (success &&
|
|
117
|
-
result.length >= 32 &&
|
|
118
|
-
abi.decode(result, (bytes32)) == ALLOWANCE_GRANTED_MAGIC_VALUE);
|
|
86
|
+
return (success && result.length >= 32 && abi.decode(result, (bytes32)) == ALLOWANCE_GRANTED_MAGIC_VALUE);
|
|
119
87
|
}
|
|
120
88
|
|
|
121
|
-
function getActiveVouchersSessionNonce(
|
|
122
|
-
|
|
123
|
-
) public view returns (bytes32) {
|
|
124
|
-
return getAACStorage().activeVouchersSessionNonce[account];
|
|
89
|
+
function getActiveVouchersSessionNonce(address account) public view returns (bytes32) {
|
|
90
|
+
return getAacStorage().activeVouchersSessionNonce[account];
|
|
125
91
|
}
|
|
126
92
|
|
|
127
93
|
/// @notice invalidates all previously signed vouchers
|
|
128
94
|
function updateActiveVouchersSessionNonce() external {
|
|
129
|
-
|
|
130
|
-
abi.encodePacked(msg.sender, block.prevrandao)
|
|
131
|
-
);
|
|
95
|
+
getAacStorage().activeVouchersSessionNonce[msg.sender] =
|
|
96
|
+
keccak256(abi.encodePacked(msg.sender, block.prevrandao));
|
|
132
97
|
}
|
|
98
|
+
|
|
133
99
|
}
|
|
@@ -8,55 +8,46 @@ import {VerifierAddressGetter} from "../primitives/VerifierAddressGetter.sol";
|
|
|
8
8
|
import {AllowanceProof} from "../AccessControl/AdvancedAccessControl.types.sol";
|
|
9
9
|
|
|
10
10
|
contract AccessControlListStorage {
|
|
11
|
-
|
|
11
|
+
|
|
12
|
+
struct AclStorage {
|
|
12
13
|
mapping(bytes32 handle => mapping(address account => bool isAllowed)) persistedAllowedPairs;
|
|
13
14
|
mapping(bytes32 handle => bool isAllowed) persistedAllowedForDecryption;
|
|
14
15
|
}
|
|
15
16
|
|
|
16
|
-
bytes32 private constant
|
|
17
|
+
bytes32 private constant ACL_STORAGE_LOCATION = keccak256("inco.storage.ACL");
|
|
17
18
|
|
|
18
|
-
function
|
|
19
|
-
bytes32 loc =
|
|
19
|
+
function getAclStorage() internal pure returns (AclStorage storage $) {
|
|
20
|
+
bytes32 loc = ACL_STORAGE_LOCATION;
|
|
20
21
|
assembly {
|
|
21
22
|
$.slot := loc
|
|
22
23
|
}
|
|
23
24
|
}
|
|
25
|
+
|
|
24
26
|
}
|
|
25
27
|
|
|
26
|
-
abstract contract BaseAccessControlList is
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
28
|
+
abstract contract BaseAccessControlList is
|
|
29
|
+
IBaseAccessControlList,
|
|
30
|
+
AccessControlListStorage,
|
|
31
|
+
VerifierAddressGetter,
|
|
32
|
+
EventCounter
|
|
33
|
+
{
|
|
34
|
+
|
|
35
|
+
error ProofVerificationFailed(address verifyingContract, bytes4 callFunction, bytes argData);
|
|
32
36
|
|
|
33
|
-
event Allow(
|
|
34
|
-
bytes32 handle,
|
|
35
|
-
address account,
|
|
36
|
-
uint256 eventId
|
|
37
|
-
);
|
|
37
|
+
event Allow(bytes32 handle, address account, uint256 eventId);
|
|
38
38
|
|
|
39
|
-
event Reveal(
|
|
40
|
-
bytes32 handle,
|
|
41
|
-
uint256 eventId
|
|
42
|
-
);
|
|
39
|
+
event Reveal(bytes32 handle, uint256 eventId);
|
|
43
40
|
|
|
44
41
|
/// @dev persistent
|
|
45
42
|
function allow(bytes32 handle, address account) public {
|
|
46
|
-
require(
|
|
47
|
-
isAllowed(handle, msg.sender),
|
|
48
|
-
SenderNotAllowedForHandle(handle, msg.sender)
|
|
49
|
-
);
|
|
43
|
+
require(isAllowed(handle, msg.sender), SenderNotAllowedForHandle(handle, msg.sender));
|
|
50
44
|
allowInternal(handle, account);
|
|
51
45
|
}
|
|
52
46
|
|
|
53
47
|
/// @dev Permanently allows public decryption/reencryption access to anyone for the given handle.
|
|
54
48
|
function reveal(bytes32 handle) public {
|
|
55
|
-
require(
|
|
56
|
-
|
|
57
|
-
SenderNotAllowedForHandle(handle, msg.sender)
|
|
58
|
-
);
|
|
59
|
-
ACLStorage storage $ = getACLStorage();
|
|
49
|
+
require(isAllowed(handle, msg.sender), SenderNotAllowedForHandle(handle, msg.sender));
|
|
50
|
+
AclStorage storage $ = getAclStorage();
|
|
60
51
|
$.persistedAllowedForDecryption[handle] = true;
|
|
61
52
|
uint256 id = getNextEventId();
|
|
62
53
|
emit Reveal(handle, id);
|
|
@@ -65,7 +56,7 @@ abstract contract BaseAccessControlList is IBaseAccessControlList, AccessControl
|
|
|
65
56
|
|
|
66
57
|
/// @dev persistent
|
|
67
58
|
function allowInternal(bytes32 handle, address account) internal {
|
|
68
|
-
|
|
59
|
+
AclStorage storage $ = getAclStorage();
|
|
69
60
|
$.persistedAllowedPairs[handle][account] = true;
|
|
70
61
|
uint256 id = getNextEventId();
|
|
71
62
|
emit Allow(handle, account, id);
|
|
@@ -74,10 +65,7 @@ abstract contract BaseAccessControlList is IBaseAccessControlList, AccessControl
|
|
|
74
65
|
|
|
75
66
|
// todo current transient allowance is unsafe, make storage account bound + how to clean between UserOps
|
|
76
67
|
function allowTransient(bytes32 handle, address account) public {
|
|
77
|
-
require(
|
|
78
|
-
isAllowed(handle, msg.sender),
|
|
79
|
-
SenderNotAllowedForHandle(handle, msg.sender)
|
|
80
|
-
);
|
|
68
|
+
require(isAllowed(handle, msg.sender), SenderNotAllowedForHandle(handle, msg.sender));
|
|
81
69
|
allowTransientInternal(handle, account);
|
|
82
70
|
}
|
|
83
71
|
|
|
@@ -93,10 +81,7 @@ abstract contract BaseAccessControlList is IBaseAccessControlList, AccessControl
|
|
|
93
81
|
}
|
|
94
82
|
}
|
|
95
83
|
|
|
96
|
-
function allowedTransient(
|
|
97
|
-
bytes32 handle,
|
|
98
|
-
address account
|
|
99
|
-
) public view returns (bool) {
|
|
84
|
+
function allowedTransient(bytes32 handle, address account) public view returns (bool) {
|
|
100
85
|
bool isAllowedTransient;
|
|
101
86
|
bytes32 key = keccak256(abi.encodePacked(handle, account));
|
|
102
87
|
assembly {
|
|
@@ -110,11 +95,7 @@ abstract contract BaseAccessControlList is IBaseAccessControlList, AccessControl
|
|
|
110
95
|
let length := tload(0)
|
|
111
96
|
tstore(0, 0)
|
|
112
97
|
let lengthPlusOne := add(length, 1)
|
|
113
|
-
for {
|
|
114
|
-
let i := 1
|
|
115
|
-
} lt(i, lengthPlusOne) {
|
|
116
|
-
i := add(i, 1)
|
|
117
|
-
} {
|
|
98
|
+
for { let i := 1 } lt(i, lengthPlusOne) { i := add(i, 1) } {
|
|
118
99
|
let handle := tload(i)
|
|
119
100
|
tstore(i, 0)
|
|
120
101
|
tstore(handle, 0)
|
|
@@ -126,36 +107,24 @@ abstract contract BaseAccessControlList is IBaseAccessControlList, AccessControl
|
|
|
126
107
|
require(
|
|
127
108
|
incoVerifier.isAllowedWithProof(handle, msg.sender, proof),
|
|
128
109
|
ProofVerificationFailed(
|
|
129
|
-
proof.voucher.verifyingContract,
|
|
130
|
-
proof.voucher.callFunction,
|
|
131
|
-
proof.voucher.sharerArgData
|
|
110
|
+
proof.voucher.verifyingContract, proof.voucher.callFunction, proof.voucher.sharerArgData
|
|
132
111
|
)
|
|
133
112
|
);
|
|
134
113
|
allowInternal(handle, msg.sender);
|
|
135
114
|
}
|
|
136
115
|
|
|
137
|
-
function persistAllowed(
|
|
138
|
-
|
|
139
|
-
address account
|
|
140
|
-
) public view returns (bool) {
|
|
141
|
-
ACLStorage storage $ = getACLStorage();
|
|
116
|
+
function persistAllowed(bytes32 handle, address account) public view returns (bool) {
|
|
117
|
+
AclStorage storage $ = getAclStorage();
|
|
142
118
|
return $.persistedAllowedPairs[handle][account];
|
|
143
119
|
}
|
|
144
120
|
|
|
145
|
-
function isAllowed(
|
|
146
|
-
|
|
147
|
-
address account
|
|
148
|
-
) public view returns (bool) {
|
|
149
|
-
return
|
|
150
|
-
allowedTransient(handle, account) ||
|
|
151
|
-
persistAllowed(handle, account) ||
|
|
152
|
-
isRevealed(handle);
|
|
121
|
+
function isAllowed(bytes32 handle, address account) public view returns (bool) {
|
|
122
|
+
return allowedTransient(handle, account) || persistAllowed(handle, account) || isRevealed(handle);
|
|
153
123
|
}
|
|
154
124
|
|
|
155
|
-
function isRevealed(
|
|
156
|
-
|
|
157
|
-
) public view returns (bool) {
|
|
158
|
-
ACLStorage storage $ = getACLStorage();
|
|
125
|
+
function isRevealed(bytes32 handle) public view returns (bool) {
|
|
126
|
+
AclStorage storage $ = getAclStorage();
|
|
159
127
|
return $.persistedAllowedForDecryption[handle];
|
|
160
128
|
}
|
|
129
|
+
|
|
161
130
|
}
|