Skip to content

Commit

Permalink
Fix typeHash usage
Browse files Browse the repository at this point in the history
  • Loading branch information
garyghayrat committed Jan 25, 2024
1 parent 7cfeddc commit d8140ae
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 10 deletions.
22 changes: 16 additions & 6 deletions src/ERC6538Registry.sol
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,6 @@ contract ERC6538Registry {
/// @dev `nonce` will be incremented after each valid `registerKeysOnBehalf` call.
mapping(address user => uint256) public nonceOf;

/// @dev EIP-712 Type hash used in `registerKeysOnBehalf`.
bytes32 public constant TYPE_HASH =
keccak256("EIP712Domain(string name,string version,uint256 chainId,address registryContract)");

/// @dev The chain ID where this contract is initially deployed.
uint256 internal immutable INITIAL_CHAIN_ID;

Expand Down Expand Up @@ -76,7 +72,15 @@ contract ERC6538Registry {
"\x19\x01",
DOMAIN_SEPARATOR(),
keccak256(
abi.encode(TYPE_HASH, registrant, schemeId, stealthMetaAddress, nonceOf[registrant]++)
abi.encode(
keccak256(
"RegisterKeysOnBehalf(address registrant,uint256 schemeId,bytes stealthMetaAddress,uint256 nonce)"
),
registrant,
schemeId,
stealthMetaAddress,
nonceOf[registrant]++
)
)
)
);
Expand Down Expand Up @@ -126,7 +130,13 @@ contract ERC6538Registry {
function _computeDomainSeparator() internal view returns (bytes32) {
return keccak256(
abi.encode(
TYPE_HASH, keccak256("ERC6538Registry"), keccak256("1.0"), block.chainid, address(this)
keccak256(
"EIP712Domain(string name,string version,uint256 chainId,address registryContract)"
),
keccak256("ERC6538Registry"),
keccak256("1.0"),
block.chainid,
address(this)
)
);
}
Expand Down
13 changes: 9 additions & 4 deletions test/ERC6538Registry.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -299,9 +299,6 @@ contract SigUtils {
DOMAIN_SEPARATOR = _DOMAIN_SEPARATOR;
}

bytes32 public constant TYPEHASH =
keccak256("EIP712Domain(string name,string version,uint256 chainId,address registryContract)");

struct RegistrantInfo {
address registrant;
uint256 schemeId;
Expand All @@ -312,7 +309,15 @@ contract SigUtils {
// computes the hash
function getStructHash(RegistrantInfo memory _info) internal pure returns (bytes32) {
return keccak256(
abi.encode(TYPEHASH, _info.registrant, _info.schemeId, _info.stealthMetaAddress, _info.nonce)
abi.encode(
keccak256(
"RegisterKeysOnBehalf(address registrant,uint256 schemeId,bytes stealthMetaAddress,uint256 nonce)"
),
_info.registrant,
_info.schemeId,
_info.stealthMetaAddress,
_info.nonce
)
);
}

Expand Down

0 comments on commit d8140ae

Please sign in to comment.