From 7fb012844a7418b0d37f00860f05ec8e8faf5cb1 Mon Sep 17 00:00:00 2001 From: Makoto Inoue <2630+makoto@users.noreply.github.com> Date: Wed, 29 Nov 2023 14:51:27 +0000 Subject: [PATCH] Remove offset from getTarget --- crosschain-resolver/README.md | 2 +- crosschain-resolver/contracts/ITargetResolver.sol | 6 +----- crosschain-resolver/contracts/L1Resolver.sol | 13 +++++++++---- crosschain-resolver/scripts/getaddr.ts | 4 ++-- crosschain-resolver/test/testResolver.ts | 10 +++++----- 5 files changed, 18 insertions(+), 17 deletions(-) diff --git a/crosschain-resolver/README.md b/crosschain-resolver/README.md index 0d5e3113..0d3bdcbb 100644 --- a/crosschain-resolver/README.md +++ b/crosschain-resolver/README.md @@ -214,7 +214,7 @@ Once done, set addrss of the subname from the operator, wait 10~20 min, then que Go to [Base L1 resolver](https://goerli.etherscan.io/address/0x052D7E10D55Ae12b4F62cdE18dBb7E938efa230D#readContract) ``` -[node, target] = l1resolver.getTarget(encodedname, 0) +[node, target] = l1resolver.getTarget(encodedname) ``` #### Step 2: Deploy the registrar contract diff --git a/crosschain-resolver/contracts/ITargetResolver.sol b/crosschain-resolver/contracts/ITargetResolver.sol index 3268a640..b7f0b797 100644 --- a/crosschain-resolver/contracts/ITargetResolver.sol +++ b/crosschain-resolver/contracts/ITargetResolver.sol @@ -2,11 +2,7 @@ pragma solidity ^0.8.17; interface ITargetResolver{ - function setTarget( - bytes32 node, address target - ) external; - function getTarget( - bytes memory name,uint256 offset + bytes memory name ) external view returns (bytes32 node, address target); } diff --git a/crosschain-resolver/contracts/L1Resolver.sol b/crosschain-resolver/contracts/L1Resolver.sol index 6b7a54b7..00f95b29 100644 --- a/crosschain-resolver/contracts/L1Resolver.sol +++ b/crosschain-resolver/contracts/L1Resolver.sol @@ -73,19 +73,24 @@ contract L1Resolver is EVMFetchTarget { /** * @dev Returns the L2 target address that can answer queries for `name`. * @param name DNS encoded ENS name to query - * @param offset The offset of the label to query recursively. * @return node The node of the name * @return target The L2 resolver address to verify against. */ function getTarget( + bytes memory name + ) public view returns (bytes32 node, address target) { + return _getTarget(name, 0); + } + + function _getTarget( bytes memory name, uint256 offset - ) public view returns (bytes32 node, address target) { + ) private view returns (bytes32 node, address target) { uint256 len = name.readUint8(offset); node = bytes32(0); if (len > 0) { bytes32 label = name.keccak(offset + 1, len); - (node, target) = getTarget( + (node, target) = _getTarget( name, offset + len + 1 ); @@ -112,7 +117,7 @@ contract L1Resolver is EVMFetchTarget { * @return result result of the call */ function resolve(bytes calldata name, bytes calldata data) external view returns (bytes memory result) { - (, address target) = getTarget(name, 0); + (, address target) = _getTarget(name, 0); bytes4 selector = bytes4(data); if (selector == IAddrResolver.addr.selector) { diff --git a/crosschain-resolver/scripts/getaddr.ts b/crosschain-resolver/scripts/getaddr.ts index a018ba65..fd0008d6 100644 --- a/crosschain-resolver/scripts/getaddr.ts +++ b/crosschain-resolver/scripts/getaddr.ts @@ -1,7 +1,7 @@ import packet from 'dns-packet'; const encodeName = (name) => '0x' + packet.name.encode(name).toString('hex') const l1abi = [ - "function getTarget(bytes,uint256) view returns (bytes32, address)", + "function getTarget(bytes) view returns (bytes32, address)", "function addr(bytes32) view returns (address)", "function resolve(bytes,bytes) view returns (bytes)", ] @@ -32,7 +32,7 @@ export const main = async () => { } console.log({ENS_NAME, resolver, encodedname, node}) const l1resolver = new ethers.Contract(resolver.address, l1abi, l1provider); - const target = await l1resolver.getTarget(encodedname, 0) + const target = await l1resolver.getTarget(encodedname) const l2resolverAddress = target[1] console.log('Target is set to ' + l2resolverAddress); const l2resolver = new ethers.Contract(l2resolverAddress, l2abi, l2provider); diff --git a/crosschain-resolver/test/testResolver.ts b/crosschain-resolver/test/testResolver.ts index 67dc43fc..ff811351 100644 --- a/crosschain-resolver/test/testResolver.ts +++ b/crosschain-resolver/test/testResolver.ts @@ -159,13 +159,13 @@ describe('Crosschain Resolver', () => { }catch(e){ } - const result = await target.getTarget(incorrectname, 0) + const result = await target.getTarget(incorrectname) expect(result[1]).to.equal(EMPTY_ADDRESS); }) it("should allow owner to set target", async() => { await target.setTarget(node, signerAddress) - const result = await target.getTarget(encodeName(name), 0) + const result = await target.getTarget(encodeName(name)) expect(result[1]).to.equal(signerAddress); }) @@ -174,7 +174,7 @@ describe('Crosschain Resolver', () => { const encodedsubname = encodeName(subname) const subnode = ethers.namehash(subname) await target.setTarget(node, signerAddress) - const result = await target.getTarget(encodedsubname, 0) + const result = await target.getTarget(encodedsubname) expect(result[0]).to.equal(subnode); expect(result[1]).to.equal(signerAddress); }) @@ -193,7 +193,7 @@ describe('Crosschain Resolver', () => { const wrappedtnode = ethers.namehash(`${label}.eth`) await target.setTarget(wrappedtnode, resolverAddress) const encodedname = encodeName(`${label}.eth`) - const result = await target.getTarget(encodedname, 0) + const result = await target.getTarget(encodedname) expect(result[1]).to.equal(resolverAddress); }) @@ -292,7 +292,7 @@ describe('Crosschain Resolver', () => { }) it("should support interface", async() => { - expect(await target.supportsInterface('0x6c4787ef')).to.equal(true) // ITargetResolver + expect(await target.supportsInterface('0x15f64386')).to.equal(true) // ITargetResolver expect(await target.supportsInterface('0x9061b923')).to.equal(true) // IExtendedResolver }) }); \ No newline at end of file