From a9b7db1d43c13c79062e657e7520a2ad7263561e Mon Sep 17 00:00:00 2001 From: garyghayrat Date: Tue, 30 Jan 2024 12:43:21 -0500 Subject: [PATCH] Add standalone type hash definition and remove `regitrant` from it --- src/ERC6538Registry.sol | 12 +++++------- test/ERC6538Registry.t.sol | 20 ++++++++------------ 2 files changed, 13 insertions(+), 19 deletions(-) diff --git a/src/ERC6538Registry.sol b/src/ERC6538Registry.sol index e72d1ef..b42926f 100644 --- a/src/ERC6538Registry.sol +++ b/src/ERC6538Registry.sol @@ -17,6 +17,10 @@ contract ERC6538Registry { /// @dev `nonce` will be incremented after each valid `registerKeysOnBehalf` call. mapping(address user => uint256) public nonceOf; + /// @notice The EIP-712 type hash used in `registerKeysOnBehalf`. + bytes32 public constant ERC6538REGISTRY_ENTRY_TYPE_HASH = + keccak256("Erc6538RegistryEntry(uint256 schemeId,bytes stealthMetaAddress,uint256 nonce)"); + /// @dev The chain ID where this contract is initially deployed. uint256 internal immutable INITIAL_CHAIN_ID; @@ -76,13 +80,7 @@ contract ERC6538Registry { DOMAIN_SEPARATOR(), keccak256( abi.encode( - keccak256( - "RegisterKeysOnBehalf(address registrant,uint256 schemeId,bytes stealthMetaAddress,uint256 nonce)" - ), - registrant, - schemeId, - stealthMetaAddress, - nonceOf[registrant]++ + ERC6538REGISTRY_ENTRY_TYPE_HASH, schemeId, stealthMetaAddress, nonceOf[registrant]++ ) ) ) diff --git a/test/ERC6538Registry.t.sol b/test/ERC6538Registry.t.sol index ccbc76d..b3591a1 100644 --- a/test/ERC6538Registry.t.sol +++ b/test/ERC6538Registry.t.sol @@ -66,7 +66,7 @@ contract RegisterKeysOnBehalf_Address is ERC6538RegistryTest { ) external { (address alice, uint256 alicePk) = makeAddrAndKey(name); SigUtils.RegistrantInfo memory registrantInfo = - SigUtils.RegistrantInfo(alice, schemeId, stealthMetaAddress, 0 /* nonce */ ); + SigUtils.RegistrantInfo(schemeId, stealthMetaAddress, 0 /* nonce */ ); bytes32 hash = sigUtils.getTypedDataHash(registrantInfo); (uint8 v, bytes32 r, bytes32 s) = vm.sign(alicePk, hash); bytes memory signature = abi.encodePacked(r, s, v); @@ -88,7 +88,7 @@ contract RegisterKeysOnBehalf_Address is ERC6538RegistryTest { address registrant = address(erc1271MockContract); SigUtils.RegistrantInfo memory registrantInfo = - SigUtils.RegistrantInfo(registrant, schemeId, stealthMetaAddress, 0 /* nonce */ ); + SigUtils.RegistrantInfo(schemeId, stealthMetaAddress, 0 /* nonce */ ); bytes32 hash = sigUtils.getTypedDataHash(registrantInfo); (uint8 v, bytes32 r, bytes32 s) = vm.sign(alicePk, hash); bytes memory signature = abi.encodePacked(r, s, v); @@ -109,7 +109,7 @@ contract RegisterKeysOnBehalf_Address is ERC6538RegistryTest { for (uint256 nonce = 0; nonce < numOfUpdates; nonce++) { SigUtils.RegistrantInfo memory registrantInfo = - SigUtils.RegistrantInfo(alice, schemeId, stealthMetaAddress, nonce); + SigUtils.RegistrantInfo(schemeId, stealthMetaAddress, nonce); bytes32 hash = sigUtils.getTypedDataHash(registrantInfo); (uint8 v, bytes32 r, bytes32 s) = vm.sign(alicePk, hash); bytes memory signature = abi.encodePacked(r, s, v); @@ -126,9 +126,9 @@ contract RegisterKeysOnBehalf_Address is ERC6538RegistryTest { uint256 schemeId, bytes memory stealthMetaAddress ) external { - (address alice, uint256 alicePk) = makeAddrAndKey(name); + ( /*address alice */ , uint256 alicePk) = makeAddrAndKey(name); SigUtils.RegistrantInfo memory registrantInfo = - SigUtils.RegistrantInfo(alice, schemeId, stealthMetaAddress, 0 /* nonce */ ); + SigUtils.RegistrantInfo(schemeId, stealthMetaAddress, 0 /* nonce */ ); bytes32 hash = sigUtils.getTypedDataHash(registrantInfo); (uint8 v, bytes32 r, bytes32 s) = vm.sign(alicePk, hash); bytes memory signature = abi.encodePacked(r, s, v); @@ -150,7 +150,7 @@ contract RegisterKeysOnBehalf_Address is ERC6538RegistryTest { address registrant = address(erc1271MockContract); SigUtils.RegistrantInfo memory registrantInfo = - SigUtils.RegistrantInfo(registrant, schemeId, stealthMetaAddress, 0 /* nonce */ ); + SigUtils.RegistrantInfo(schemeId, stealthMetaAddress, 0 /* nonce */ ); bytes32 hash = sigUtils.getTypedDataHash(registrantInfo); (uint8 v, bytes32 r, bytes32 s) = vm.sign(alicePk, hash); bytes memory signature = abi.encodePacked(r, s, v); @@ -168,7 +168,7 @@ contract RegisterKeysOnBehalf_Address is ERC6538RegistryTest { vm.assume(nonce != 0); (address alice, uint256 alicePk) = makeAddrAndKey(name); SigUtils.RegistrantInfo memory registrantInfo = - SigUtils.RegistrantInfo(alice, schemeId, stealthMetaAddress, nonce); + SigUtils.RegistrantInfo(schemeId, stealthMetaAddress, nonce); bytes32 hash = sigUtils.getTypedDataHash(registrantInfo); (uint8 v, bytes32 r, bytes32 s) = vm.sign(alicePk, hash); bytes memory signature = abi.encodePacked(r, s, v); @@ -302,7 +302,6 @@ contract SigUtils { } struct RegistrantInfo { - address registrant; uint256 schemeId; bytes stealthMetaAddress; uint256 nonce; @@ -312,10 +311,7 @@ contract SigUtils { function getStructHash(RegistrantInfo memory _info) internal pure returns (bytes32) { return keccak256( abi.encode( - keccak256( - "RegisterKeysOnBehalf(address registrant,uint256 schemeId,bytes stealthMetaAddress,uint256 nonce)" - ), - _info.registrant, + keccak256("Erc6538RegistryEntry(uint256 schemeId,bytes stealthMetaAddress,uint256 nonce)"), _info.schemeId, _info.stealthMetaAddress, _info.nonce