diff --git a/packages/client/src/index.ts b/packages/client/src/index.ts index ea7ba5cdd..ab44b5783 100644 --- a/packages/client/src/index.ts +++ b/packages/client/src/index.ts @@ -43,6 +43,7 @@ const provider = new ethers.providers.JsonRpcProvider(l1_provider_url, { const name = program.args[0]; console.log("name", name); const resolverFound = await provider.getResolver(name); + console.log("resolverFound address", resolverFound?.address); const node = namehash.hash(name); console.log("node", node); diff --git a/packages/contracts/contracts/l1/LineaResolverStub.sol b/packages/contracts/contracts/l1/LineaResolverStub.sol index 083f09297..ac368bb1a 100644 --- a/packages/contracts/contracts/l1/LineaResolverStub.sol +++ b/packages/contracts/contracts/l1/LineaResolverStub.sol @@ -6,16 +6,14 @@ import { Lib_SecureMerkleTrie } from "@eth-optimism/contracts/libraries/trie/Lib import { Lib_RLPReader } from "@eth-optimism/contracts/libraries/rlp/Lib_RLPReader.sol"; import { Lib_BytesUtils } from "@eth-optimism/contracts/libraries/utils/Lib_BytesUtils.sol"; +import "hardhat/console.sol"; + struct L2StateProof { - uint64 nodeIndex; bytes32 blockHash; - bytes sendRoot; bytes encodedBlockArray; bytes stateTrieWitness; bytes32 stateRoot; bytes storageTrieWitness; - bytes node; - bytes result; } interface IResolverService { @@ -84,7 +82,7 @@ contract LineaResolverStub is IExtendedResolver, SupportsInterface { gateways, callData, LineaResolverStub.resolveWithProof.selector, - abi.encode(name) + data ); } @@ -95,6 +93,15 @@ contract LineaResolverStub is IExtendedResolver, SupportsInterface { bytes calldata response, bytes calldata extraData ) external view returns (bytes memory) { + // We only resolve if the addr(bytes32) is called otherwise we simply return an empty response + bytes4 signature = bytes4(extraData[0:4]); + if (signature != bytes4(0x3b3b57de)) { + return abi.encode(""); + } + + // This is the hash name of the domain name + bytes32 node = abi.decode(extraData[4:], (bytes32)); + L2StateProof memory proof = abi.decode(response, (L2StateProof)); // bytes32 node = abi.decode(extraData, (bytes32)); // step 2: check blockHash against encoded block array @@ -102,11 +109,12 @@ contract LineaResolverStub is IExtendedResolver, SupportsInterface { proof.blockHash == keccak256(proof.encodedBlockArray), "blockHash encodedBlockArray mismatch" ); + // step 3: check storage value from derived value // Here the node used should be in extra data but we need to find a way // to convert extra data to an ens hashname in solidity, in the meantime we use // the node sent by the gateway - bytes32 slot = keccak256(abi.encodePacked(proof.node, uint256(1))); + bytes32 slot = keccak256(abi.encodePacked(node, uint256(1))); bytes32 value = getStorageValue( l2resolver, slot, @@ -115,12 +123,7 @@ contract LineaResolverStub is IExtendedResolver, SupportsInterface { proof.storageTrieWitness ); - require( - keccak256(proof.result) == keccak256(abi.encode(value)), - "LineaResolverStub: value different from expected result" - ); - - return proof.result; + return abi.encode(value); } function getl2Resolver() external view returns (address) { diff --git a/packages/gateway/src/index.ts b/packages/gateway/src/index.ts index 73a71dd13..364b95be0 100644 --- a/packages/gateway/src/index.ts +++ b/packages/gateway/src/index.ts @@ -1,14 +1,10 @@ import { Server } from "@chainlink/ccip-read-server"; import { Command } from "commander"; -import { ethers, BytesLike } from "ethers"; +import { ethers } from "ethers"; import { Result } from "ethers/lib/utils"; const IResolverAbi = require("../../contracts/artifacts/contracts/l1/LineaResolverStub.sol/IResolverService.json") .abi; -const IResolverL2Abi = require("../../contracts/artifacts/contracts/l2/LineaResolver.sol/LineaResolver.json") - .abi; -import { abi as Resolver_abi } from "@ensdomains/ens-contracts/artifacts/contracts/resolvers/Resolver.sol/Resolver.json"; -const Resolver = new ethers.utils.Interface(Resolver_abi); const rollupAbi = require("../abi/rollup.json"); const { BigNumber } = ethers; const program = new Command(); @@ -59,9 +55,9 @@ server.add(IResolverAbi, [ console.log("name", name); const node = ethers.utils.namehash(name); console.log("node", node); - const addrSlot = ethers.utils.keccak256(node + "00".repeat(31) + "01"); if (debug) { + const addrSlot = ethers.utils.keccak256(node + "00".repeat(31) + "01"); const to = request?.to; console.log(1, { node, @@ -88,7 +84,6 @@ server.add(IResolverAbi, [ } const lastBlockFinalized = await rollup.lastFinalizedBatchHeight(); - const stateRootHash = await rollup.stateRootHash(); const blockNumber = lastBlockFinalized.toNumber(); console.log(`Last block number finalized on L2 : ${blockNumber}`); const block = await l2provider.getBlock(blockNumber); @@ -130,19 +125,12 @@ server.add(IResolverAbi, [ (proof.storageProof as any[]).filter((x) => x.key === slot)[0].proof ); - // Result that will returned to the client after verification of the proof - const { result } = await getResult(name, data); - const finalProof = { - nodeIndex: blockNumber, blockHash, - sendRoot: stateRootHash, encodedBlockArray, stateTrieWitness: accountProof, stateRoot, storageTrieWitness: storageProof, - node, - result, }; console.log(7, { finalProof }); return [finalProof]; @@ -163,32 +151,3 @@ function decodeDnsName(dnsname: Buffer) { } return labels.join("."); } - -async function getResult( - name: string, - data: string -): Promise<{ result: BytesLike }> { - // Parse the data nested inside the second argument to `resolve` - const { signature, args } = Resolver.parseTransaction({ data }); - console.log("signature", signature); - - if (ethers.utils.nameprep(name) !== name) { - throw new Error("Name must be normalised"); - } - - if (ethers.utils.namehash(name) !== args[0]) { - throw new Error("Name does not match namehash"); - } - - const resolverL2 = await new ethers.Contract( - l2_resolver_address, - IResolverL2Abi, - l2provider - ); - const node = ethers.utils.namehash(name); - const result = await resolverL2.addr(node); - - return { - result: Resolver.encodeFunctionResult(signature, [result]), - }; -}