Skip to content

Commit

Permalink
Merge pull request #19 from datachainlab/fix-register-enclave-key-domain
Browse files Browse the repository at this point in the history
Fix `RegisterEnclaveKey`'s domain

Signed-off-by: Jun Kimura <[email protected]>
  • Loading branch information
bluele authored Jun 20, 2024
2 parents 074548f + 634fcf2 commit 6388e8f
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 5 deletions.
16 changes: 12 additions & 4 deletions contracts/LCPOperator.sol
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ library LCPOperator {
bytes32 internal constant DOMAIN_SEPARATOR_NAME = keccak256("LCPClient");
bytes32 internal constant DOMAIN_SEPARATOR_VERSION = keccak256("1");

// domainSeparator(0, address(0))
// domainSeparatorUniversal()
bytes32 internal constant DOMAIN_SEPARATOR_REGISTER_ENCLAVE_KEY =
0xe33d217bff42bc015bf037be8386bf5055ec6019e58e8c5e89b5c74b8225fa6a;
0x7fd21c2453e80741907e7ff11fd62ae1daa34c6fc0c2eced821f1c1d3fe88a4c;
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""));
Expand All @@ -25,7 +25,15 @@ library LCPOperator {
return keccak256(abi.encodePacked(chainType, args));
}

function domainSeparator(uint256 chainId, address verifyingContract) internal pure returns (bytes32) {
function domainSeparatorUniversal() internal pure returns (bytes32) {
return keccak256(
abi.encode(
TYPEHASH_DOMAIN_SEPARATOR, DOMAIN_SEPARATOR_NAME, DOMAIN_SEPARATOR_VERSION, 0, address(0), bytes32(0)
)
);
}

function domainSeparatorEVM(uint256 chainId, address verifyingContract) internal pure returns (bytes32) {
return keccak256(
abi.encode(
TYPEHASH_DOMAIN_SEPARATOR,
Expand Down Expand Up @@ -69,7 +77,7 @@ library LCPOperator {
) internal pure returns (bytes memory) {
return abi.encodePacked(
hex"1901",
domainSeparator(chainId, verifyingContract),
domainSeparatorEVM(chainId, verifyingContract),
keccak256(
abi.encode(
TYPEHASH_UPDATE_OPERATORS,
Expand Down
2 changes: 1 addition & 1 deletion test/LCPClientOperator.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ contract LCPClientOperatorTest is BasicTest {
}

function testPreComputationValues() public pure {
assertEq(LCPOperator.domainSeparator(0, address(0)), LCPOperator.DOMAIN_SEPARATOR_REGISTER_ENCLAVE_KEY);
assertEq(LCPOperator.domainSeparatorUniversal(), LCPOperator.DOMAIN_SEPARATOR_REGISTER_ENCLAVE_KEY);
assertEq(LCPOperator.chainTypeSalt(LCPOperator.CHAIN_TYPE_EVM, hex""), LCPOperator.CHAIN_TYPE_EVM_SALT);
}

Expand Down

0 comments on commit 6388e8f

Please sign in to comment.