diff --git a/contracts/reverseRegistrar/L2ReverseRegistrar.sol b/contracts/reverseRegistrar/L2ReverseRegistrar.sol index 1c6f26a1..a065232a 100644 --- a/contracts/reverseRegistrar/L2ReverseRegistrar.sol +++ b/contracts/reverseRegistrar/L2ReverseRegistrar.sol @@ -70,8 +70,18 @@ contract L2ReverseRegistrar is uint256 inceptionDate, bytes memory signature ) internal view returns (bool) { + // Follow ERC191 version 0 https://eips.ethereum.org/EIPS/eip-191 bytes32 message = keccak256( - abi.encodePacked(hash, addr, owner, inceptionDate, chainId) + abi.encodePacked( + bytes1(0x19), + bytes1(0), + address(this), + hash, + addr, + owner, + inceptionDate, + chainId + ) ).toEthSignedMessageHash(); bytes32 node = _getNamehash(addr); diff --git a/contracts/reverseRegistrar/SignatureReverseResolver.sol b/contracts/reverseRegistrar/SignatureReverseResolver.sol index 65d108c2..8004cd81 100644 --- a/contracts/reverseRegistrar/SignatureReverseResolver.sol +++ b/contracts/reverseRegistrar/SignatureReverseResolver.sol @@ -57,8 +57,17 @@ contract SignatureReverseResolver is Ownable, ISignatureReverseResolver { uint256 inceptionDate, bytes memory signature ) internal view returns (bool) { + // Follow ERC191 version 0 https://eips.ethereum.org/EIPS/eip-191 bytes32 message = keccak256( - abi.encodePacked(hash, addr, inceptionDate, chainId) + abi.encodePacked( + bytes1(0x19), + bytes1(0), + address(this), + hash, + addr, + inceptionDate, + chainId + ) ).toEthSignedMessageHash(); bytes32 node = _getNamehash(addr); diff --git a/test/reverseRegistrar/TestL2ReverseRegistrar.js b/test/reverseRegistrar/TestL2ReverseRegistrar.js index 6132d8bd..f712287d 100644 --- a/test/reverseRegistrar/TestL2ReverseRegistrar.js +++ b/test/reverseRegistrar/TestL2ReverseRegistrar.js @@ -4,6 +4,12 @@ const { namehash } = require('../test-utils/ens') const keccak256 = ethers.utils.solidityKeccak256 +const geterc191 = (address) => { + return ['0x19', '0x00', address] +} + +const ERC191_TYPES = ['bytes1', 'bytes1', 'address'] + describe('L2ReverseRegistrar', function () { let L2ReverseRegistrar let L2ReverseRegistrarWithAccount2 @@ -104,8 +110,9 @@ describe('L2ReverseRegistrar', function () { signature = await signers[0].signMessage( ethers.utils.arrayify( keccak256( - ['bytes32', 'address', 'uint256', 'uint256'], + [...ERC191_TYPES, 'bytes32', 'address', 'uint256', 'uint256'], [ + ...geterc191(L2ReverseRegistrar.address), keccak256(['bytes4', 'string'], [funcId, name]), account, inceptionDate, @@ -149,8 +156,9 @@ describe('L2ReverseRegistrar', function () { const signature = await signers[0].signMessage( ethers.utils.arrayify( keccak256( - ['bytes32', 'address', 'uint256'], + [...ERC191_TYPES, 'bytes32', 'address', 'uint256'], [ + ...geterc191(L2ReverseRegistrarWithAccount2.address), keccak256(['bytes4', 'string'], [funcId, name]), account, inceptionDate, @@ -179,8 +187,9 @@ describe('L2ReverseRegistrar', function () { const signature = await signers[0].signMessage( ethers.utils.arrayify( keccak256( - ['bytes32', 'address', 'uint256', 'uint256'], + [...ERC191_TYPES, 'bytes32', 'address', 'uint256', 'uint256'], [ + ...geterc191(L2ReverseRegistrarWithAccount2.address), keccak256(['bytes4', 'string'], [funcId, 'hello.eth']), account, inceptionDate, @@ -204,8 +213,9 @@ describe('L2ReverseRegistrar', function () { const signature2 = await signers[0].signMessage( ethers.utils.arrayify( keccak256( - ['bytes32', 'address', 'uint256', 'uint256'], + [...ERC191_TYPES, 'bytes32', 'address', 'uint256', 'uint256'], [ + ...geterc191(L2ReverseRegistrarWithAccount2.address), keccak256(['bytes4', 'string'], [funcId, 'hello.eth']), account, inceptionDate2, @@ -244,8 +254,16 @@ describe('L2ReverseRegistrar', function () { signature = await signers[0].signMessage( ethers.utils.arrayify( keccak256( - ['bytes32', 'address', 'address', 'uint256', 'uint256'], [ + ...ERC191_TYPES, + 'bytes32', + 'address', + 'address', + 'uint256', + 'uint256', + ], + [ + ...geterc191(L2ReverseRegistrarWithAccount2.address), keccak256(['bytes4', 'string'], [funcId, name]), MockOwnable.address, MockSmartContractWallet.address, @@ -311,8 +329,9 @@ describe('L2ReverseRegistrar', function () { const signature = await signers[0].signMessage( ethers.utils.arrayify( keccak256( - ['bytes32', 'address', 'uint256', 'uint256'], + [...ERC191_TYPES, 'bytes32', 'address', 'uint256', 'uint256'], [ + ...geterc191(L2ReverseRegistrarWithAccount2.address), keccak256( ['bytes4', 'string', 'string'], [funcId, 'url', 'http://ens.domains'], @@ -353,8 +372,13 @@ describe('L2ReverseRegistrar', function () { ['bytes32', 'address', 'uint256'], [ keccak256( - ['bytes4', 'string', 'string'], - [funcId, 'url', 'http://ens.domains'], + [...ERC191_TYPES, 'bytes4', 'string', 'string'], + [ + ...geterc191(L2ReverseRegistrarWithAccount2.address), + funcId, + 'url', + 'http://ens.domains', + ], ), account, inceptionDate, @@ -384,8 +408,9 @@ describe('L2ReverseRegistrar', function () { const signature = await signers[0].signMessage( ethers.utils.arrayify( keccak256( - ['bytes32', 'address', 'uint256', 'uint256'], + [...ERC191_TYPES, 'bytes32', 'address', 'uint256', 'uint256'], [ + ...geterc191(L2ReverseRegistrarWithAccount2.address), keccak256( ['bytes4', 'string', 'string'], [funcId, 'url', 'http://ens.domains'], @@ -416,8 +441,9 @@ describe('L2ReverseRegistrar', function () { const signature2 = await signers[0].signMessage( ethers.utils.arrayify( keccak256( - ['bytes32', 'address', 'uint256', 'uint256'], + [...ERC191_TYPES, 'bytes32', 'address', 'uint256', 'uint256'], [ + ...geterc191(L2ReverseRegistrarWithAccount2.address), keccak256( ['bytes4', 'string', 'string'], [funcId, 'url', 'http://ens.domains'], @@ -455,8 +481,16 @@ describe('L2ReverseRegistrar', function () { const signature = await signers[0].signMessage( ethers.utils.arrayify( keccak256( - ['bytes32', 'address', 'address', 'uint256', 'uint256'], [ + ...ERC191_TYPES, + 'bytes32', + 'address', + 'address', + 'uint256', + 'uint256', + ], + [ + ...geterc191(L2ReverseRegistrarWithAccount2.address), keccak256( ['bytes4', 'string', 'string'], [funcId, 'url', 'http://ens.domains'], @@ -529,8 +563,9 @@ describe('L2ReverseRegistrar', function () { const signature1 = await signers[0].signMessage( ethers.utils.arrayify( keccak256( - ['bytes32', 'address', 'uint256', 'uint256'], + [...ERC191_TYPES, 'bytes32', 'address', 'uint256', 'uint256'], [ + ...geterc191(L2ReverseRegistrarWithAccount2.address), keccak256( ['bytes4', 'string', 'string'], [funcId1, 'url', 'http://ens.domains'], @@ -546,8 +581,9 @@ describe('L2ReverseRegistrar', function () { const signature2 = await signers[0].signMessage( ethers.utils.arrayify( keccak256( - ['bytes32', 'address', 'uint256', 'uint256'], + [...ERC191_TYPES, 'bytes32', 'address', 'uint256', 'uint256'], [ + ...geterc191(L2ReverseRegistrarWithAccount2.address), keccak256(['bytes4', 'string'], [funcId2, 'hello.eth']), account, inceptionDate + 1, @@ -612,8 +648,14 @@ describe('L2ReverseRegistrar', function () { const signature = await signers[0].signMessage( ethers.utils.arrayify( keccak256( - ['bytes32', 'address', 'uint256', 'uint256'], - [keccak256(['bytes4'], [funcId]), account, inceptionDate, chainId], + [...ERC191_TYPES, 'bytes32', 'address', 'uint256', 'uint256'], + [ + ...geterc191(L2ReverseRegistrarWithAccount2.address), + keccak256(['bytes4'], [funcId]), + account, + inceptionDate, + chainId, + ], ), ), ) @@ -646,8 +688,14 @@ describe('L2ReverseRegistrar', function () { const signature = await signers[0].signMessage( ethers.utils.arrayify( keccak256( - ['bytes32', 'address', 'uint256', 'uint256'], - [keccak256(['bytes4'], [funcId]), account, inceptionDate, chainId], + [...ERC191_TYPES, 'bytes32', 'address', 'uint256', 'uint256'], + [ + ...geterc191(L2ReverseRegistrarWithAccount2.address), + keccak256(['bytes4'], [funcId]), + account, + inceptionDate, + chainId, + ], ), ), )