-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #17 from datachainlab/multiple-operators
Multiple operators support Signed-off-by: Jun Kimura <jun.kimura@datachain.jp>
- Loading branch information
Showing
85 changed files
with
2,369 additions
and
660 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
// SPDX-License-Identifier: Apache-2.0 | ||
pragma solidity ^0.8.12; | ||
|
||
interface ILCPClientErrors { | ||
error LCPClientRootCACertAlreadyInitialized(); | ||
error LCPClientClientStateInvalidLatestHeight(); | ||
error LCPClientClientStateFrozen(); | ||
error LCPClientClientStateInvalidKeyExpiration(); | ||
error LCPClientClientStateInvalidMrenclaveLength(); | ||
error LCPClientClientStateUnexpectedMrenclave(); | ||
error LCPClientClientStateEmptyOperators(); | ||
error LCPClientClientStateInvalidOperatorAddress(); | ||
error LCPClientClientStateInvalidOperatorAddressLength(); | ||
error LCPClientClientStateInvalidOperatorsNonce(); | ||
error LCPClientClientStateUnexpectedOperatorsNonce(uint64 expectedNonce); | ||
|
||
error LCPClientOperatorsInvalidOrder(address prevOperator, address nextOperator); | ||
error LCPClientClientStateInvalidOperatorsThreshold(); | ||
|
||
error LCPClientConsensusStateInvalidTimestamp(); | ||
error LCPClientConsensusStateInvalidStateId(); | ||
|
||
error LCPClientClientStateNotFound(); | ||
error LCPClientConsensusStateNotFound(); | ||
error LCPClientUnknownProxyMessageHeader(); | ||
error LCPClientUnknownProtoTypeUrl(); | ||
|
||
error LCPClientMembershipVerificationInvalidHeight(); | ||
error LCPClientMembershipVerificationInvalidPrefix(); | ||
error LCPClientMembershipVerificationInvalidPath(); | ||
error LCPClientMembershipVerificationInvalidValue(); | ||
error LCPClientMembershipVerificationInvalidStateId(); | ||
|
||
error LCPClientUpdateStateEmittedStatesMustNotEmpty(); | ||
error LCPClientUpdateStatePrevStateIdMustNotEmpty(); | ||
error LCPClientUpdateStateUnexpectedPrevStateId(); | ||
|
||
error LCPClientMisbehaviourPrevStatesMustNotEmpty(); | ||
|
||
error LCPClientEnclaveKeyNotExist(); | ||
error LCPClientEnclaveKeyExpired(); | ||
error LCPClientEnclaveKeyUnexpectedOperator(address expected, address actual); | ||
error LCPClientEnclaveKeyUnexpectedExpiredAt(); | ||
|
||
error LCPClientOperatorSignaturesInsufficient(uint256 success); | ||
|
||
error LCPClientIASRootCertExpired(); | ||
error LCPClientIASCertExpired(); | ||
|
||
error LCPClientAVRInvalidSignature(); | ||
error LCPClientAVRAlreadyExpired(); | ||
|
||
error LCPClientInvalidSignaturesLength(); | ||
|
||
error LCPClientAVRUnexpectedOperator(address actual, address expected); | ||
|
||
error LCPClientUpdateOperatorsPermissionless(); | ||
error LCPClientUpdateOperatorsSignatureUnexpectedOperator(address actual, address expected); | ||
} |
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
// SPDX-License-Identifier: Apache-2.0 | ||
pragma solidity ^0.8.12; | ||
|
||
library LCPOperator { | ||
type ChainType is uint16; | ||
|
||
bytes32 internal constant TYPEHASH_DOMAIN_SEPARATOR = | ||
keccak256("EIP712Domain(string name,string version,uint256 chainId,address verifyingContract,bytes32 salt)"); | ||
bytes32 internal constant TYPEHASH_REGISTER_ENCLAVE_KEY = keccak256("RegisterEnclaveKey(string avr)"); | ||
bytes32 internal constant TYPEHASH_UPDATE_OPERATORS = keccak256( | ||
"UpdateOperators(string clientId,uint64 nonce,address[] newOperators,uint64 thresholdNumerator,uint64 thresholdDenominator)" | ||
); | ||
|
||
bytes32 internal constant DOMAIN_SEPARATOR_NAME = keccak256("LCPClient"); | ||
bytes32 internal constant DOMAIN_SEPARATOR_VERSION = keccak256("1"); | ||
|
||
// domainSeparator(0, address(0)) | ||
bytes32 internal constant DOMAIN_SEPARATOR_REGISTER_ENCLAVE_KEY = | ||
0xe33d217bff42bc015bf037be8386bf5055ec6019e58e8c5e89b5c74b8225fa6a; | ||
ChainType internal constant CHAIN_TYPE_EVM = ChainType.wrap(1); | ||
// chainTypeSalt(CHAIN_TYPE_EVM, hex"") | ||
bytes32 internal constant CHAIN_TYPE_EVM_SALT = keccak256(abi.encodePacked(CHAIN_TYPE_EVM, hex"")); | ||
|
||
function chainTypeSalt(ChainType chainType, bytes memory args) internal pure returns (bytes32) { | ||
return keccak256(abi.encodePacked(chainType, args)); | ||
} | ||
|
||
function domainSeparator(uint256 chainId, address verifyingContract) internal pure returns (bytes32) { | ||
return keccak256( | ||
abi.encode( | ||
TYPEHASH_DOMAIN_SEPARATOR, | ||
DOMAIN_SEPARATOR_NAME, | ||
DOMAIN_SEPARATOR_VERSION, | ||
chainId, | ||
verifyingContract, | ||
CHAIN_TYPE_EVM_SALT | ||
) | ||
); | ||
} | ||
|
||
function computeEIP712RegisterEnclaveKey(bytes calldata avr) internal pure returns (bytes memory) { | ||
return abi.encodePacked( | ||
hex"1901", | ||
DOMAIN_SEPARATOR_REGISTER_ENCLAVE_KEY, | ||
keccak256(abi.encode(TYPEHASH_REGISTER_ENCLAVE_KEY, keccak256(avr))) | ||
); | ||
} | ||
|
||
function computeEIP712UpdateOperators( | ||
string calldata clientId, | ||
uint64 nonce, | ||
address[] memory newOperators, | ||
uint64 thresholdNumerator, | ||
uint64 thresholdDenominator | ||
) internal view returns (bytes memory) { | ||
return computeEIP712UpdateOperators( | ||
block.chainid, address(this), clientId, nonce, newOperators, thresholdNumerator, thresholdDenominator | ||
); | ||
} | ||
|
||
function computeEIP712UpdateOperators( | ||
uint256 chainId, | ||
address verifyingContract, | ||
string calldata clientId, | ||
uint64 nonce, | ||
address[] memory newOperators, | ||
uint64 thresholdNumerator, | ||
uint64 thresholdDenominator | ||
) internal pure returns (bytes memory) { | ||
return abi.encodePacked( | ||
hex"1901", | ||
domainSeparator(chainId, verifyingContract), | ||
keccak256( | ||
abi.encode( | ||
TYPEHASH_UPDATE_OPERATORS, | ||
keccak256(bytes(clientId)), | ||
nonce, | ||
keccak256(abi.encodePacked(newOperators)), | ||
thresholdNumerator, | ||
thresholdDenominator | ||
) | ||
) | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.