Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix RegisterEnclaveKey's domain #19

Merged
merged 1 commit into from
Jun 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading