Skip to content

Commit

Permalink
Store chainId directly
Browse files Browse the repository at this point in the history
  • Loading branch information
makoto committed Apr 3, 2024
1 parent fbbc60c commit 7f6b0d7
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 17 deletions.
14 changes: 5 additions & 9 deletions crosschain-resolver/contracts/L1Resolver.sol
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ contract L1Resolver is EVMFetchTarget, ITargetResolver, IMetadataResolver, IExte
uint256 constant VERSIONABLE_HASHES_SLOT = 3;
uint256 constant VERSIONABLE_TEXTS_SLOT = 10;
string public graphqlUrl;
uint256 public l2ResolverCoinType;
uint256 public l2ChainId;

event TargetSet(bytes name, address target);
function isAuthorised(bytes32 node) internal view returns (bool) {
Expand Down Expand Up @@ -61,14 +61,14 @@ contract L1Resolver is EVMFetchTarget, ITargetResolver, IMetadataResolver, IExte
* @param _ens The ENS registry address
* @param _nameWrapper The ENS name wrapper address
* @param _graphqlUrl The offchain/l2 graphql endpoint url
* @param _l2ResolverCoinType The chainId at which the resolver resolves data from. 0 if storageLocation is offChain
* @param _l2ChainId The chainId at which the resolver resolves data from
*/
constructor(
IEVMVerifier _verifier,
ENS _ens,
INameWrapper _nameWrapper,
string memory _graphqlUrl,
uint256 _l2ResolverCoinType
uint256 _l2ChainId
){
require(address(_nameWrapper) != address(0), "Name Wrapper address must be set");
require(address(_verifier) != address(0), "Verifier address must be set");
Expand All @@ -77,7 +77,7 @@ contract L1Resolver is EVMFetchTarget, ITargetResolver, IMetadataResolver, IExte
ens = _ens;
nameWrapper = _nameWrapper;
graphqlUrl = _graphqlUrl;
l2ResolverCoinType = _l2ResolverCoinType;
l2ChainId = _l2ChainId;
}

/**
Expand Down Expand Up @@ -283,13 +283,9 @@ contract L1Resolver is EVMFetchTarget, ITargetResolver, IMetadataResolver, IExte
super.supportsInterface(interfaceId);
}

function convertCoinTypeToEVMChainId(uint256 coinType) private pure returns (uint256) {
return (0x7fffffff & coinType) >> 0;
}

function _writeDeferral(address target) internal view {
revert StorageHandledByL2(
convertCoinTypeToEVMChainId(l2ResolverCoinType),
l2ChainId,
target
);
}
Expand Down
5 changes: 2 additions & 3 deletions crosschain-resolver/deploy_l1/10_l1resolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,11 @@ const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) {
const CHAIN_NAME = process.env.CHAIN_NAME

if(!['Op', 'Base', 'Arb'].includes(CHAIN_NAME)) throw ('Set $CHAIN_NAME to Op, Base, or Arb')
const L2_COINTYPE = convertEVMChainIdToCoinType(parseInt(L2_CHAIN_ID))
console.log({VERIFIER_ADDRESS,ENS_ADDRESS, WRAPPER_ADDRESS,L2_GRAPHQL_URL,L2_COINTYPE})
console.log({VERIFIER_ADDRESS,ENS_ADDRESS, WRAPPER_ADDRESS,L2_GRAPHQL_URL,L2_CHAIN_ID})
await deploy(`${CHAIN_NAME}L1Resolver`, {
from: deployer,
contract: 'L1Resolver',
args: [VERIFIER_ADDRESS,ENS_ADDRESS,WRAPPER_ADDRESS,L2_GRAPHQL_URL,L2_COINTYPE],
args: [VERIFIER_ADDRESS,ENS_ADDRESS,WRAPPER_ADDRESS,L2_GRAPHQL_URL,parseInt(L2_CHAIN_ID)],
log: true,
});
};
Expand Down
9 changes: 4 additions & 5 deletions crosschain-resolver/test/testResolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,12 @@ import { ethers } from 'hardhat';
import { EthereumProvider } from 'hardhat/types';
import request from 'supertest';
import packet from 'dns-packet';
import {convertEVMChainIdToCoinType} from '@ensdomains/address-encoder'
import { L2ChainID } from '@eth-optimism/sdk';
const labelhash = (label) => ethers.keccak256(ethers.toUtf8Bytes(label))
const encodeName = (name) => '0x' + packet.name.encode(name).toString('hex')

const l2graphqlUrl = 'http://graphql'
const l2ResolverChainId = 420
const l2ResolverCoinType = convertEVMChainIdToCoinType(l2ResolverChainId) // Optimism Goerli
const chainId = L2ChainID.OPTIMISM_SEPOLIA

const name = 'foo.eth'
const node = ethers.namehash(name)
Expand Down Expand Up @@ -155,7 +154,7 @@ describe('Crosschain Resolver', () => {
signer
);
const verifierAddress = await verifier.getAddress()
target = await testL1Factory.deploy(verifierAddress, ensAddress, wrapperAddress, l2graphqlUrl, l2ResolverCoinType);
target = await testL1Factory.deploy(verifierAddress, ensAddress, wrapperAddress, l2graphqlUrl, chainId);

// Mine an empty block so we have something to prove against
await provider.send('evm_mine', []);
Expand Down Expand Up @@ -328,7 +327,7 @@ describe('Crosschain Resolver', () => {
const calldata = i.encodeFunctionData("setAddr", [node, EMPTY_ADDRESS])
await expect(target.resolveDeferral(encodedname, calldata)).to.be
.revertedWithCustomError(target, 'StorageHandledByL2')
.withArgs(l2ResolverChainId, resolverAddress)
.withArgs(chainId, resolverAddress)
});
});

Expand Down

0 comments on commit 7f6b0d7

Please sign in to comment.