Skip to content

Repository files navigation

L2Resolver

Minimal L2 Resolver system for ENS. It resolves ENS names to their corresponding EIP-7930-formatted chain identifiers (as bytes) and maps these EIP-7930 chain identifiers back to their primary ENS names. The system is implemented as a single contract that manages storage, authorization, and resolution logic.

Overview

setRecord():

  • given a domain set a chainID identifier
  • given a chainID identifier set a domain
  • caller must be owner of the ENS domain or approved by the owner in order to set records

chainName():

  • given a chainID identifier, returns the domain name

getRecord():

  • returns the domain for a given chainID identifier
  • returns the chainID identifier for a given domain

chainId():

  • given a domain, returns the chainID identifier

resolve():

  • implementation of ENSIP-10
  • resolves chainId and chainName selectors

supportsInterface():

  • returns true for IERC165 and IExtendedResolver

Examples

Set the record for the domain optimism.l2.eth:

  • node (ENS node, can be calculated using this tool): 0xcd14771f519e64452fe1d5a43016d25c86ef573ec499773443e29751c0dfcebc
  • key (as a string): chain.id.eip7930
  • value (as bytes, can be calculated in this way): 00010000010A00

Then setRecord() must be called with the parameters mentioned above. More information here

Set the reverse lookup for optimism.l2.eth:

  • node (constant, can be retrieved from the contract variable REVERSE_LOOKUP_NODE): 0xa1e7ae8efca73939b8018c7c06321689d70c6362862a1c900eb76c9e581e4ae8
  • key (as a string, calculated in this way): chain.id.eip79300x0a5a087e45046a1443319a227fbdfd0bfc6dfffc23c885a334649dc09b3d88e2
  • value (abi encoded domain, in this case abi.encode('optimism.l2.eth')): 0x0000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000f6f7074696d69736d2e6c322e6574680000000000000000000000000000000000

Then setRecord() must be called with the parameters mentioned above. More information here

Populate Script

To populate a file with the setRecords calldatas for the available chains in https://github.com/ethereum-lists/chains, run:

   cd populate-script
   yarn install
   yarn populate

The script will populate a file in populate-script/out/batches.json with the following format:

[
  {
    "chainIds": [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],
    "forwardCalldata": "0x57d...",
    "reverseCalldata": "0x57dcc7..."
  },
  //...
]

The file is separated in batches of max 10 chains. Each batch contains the setRecords calldata (forward and reverse) for the chains in the chainIds array.

Specification

The complete technical specification can be found here.

Setup

  1. Install Foundry by following the instructions from their repository.
  2. Copy the .env.example file to .env and fill in the variables.
  3. Install rust dependencies with cargo:
    1. cargo install lintspec
    2. cargo install bulloak
  4. Install the dependencies by running: yarn install. In case there is an error with the commands, run foundryup and try them again.

Build

The default way to build the code is suboptimal but fast, you can run it via:

yarn build

In order to build a more optimized code (via IR), run:

yarn build:optimized

Running tests

Unit tests should be isolated from any externalities, while Integration usually run in a fork of the blockchain. In this boilerplate you will find example of both.

In order to run both unit and integration tests, run:

yarn test

In order to just run unit tests, run:

yarn test:unit

In order to run unit tests and run way more fuzzing than usual (5x), run:

yarn test:unit:deep

In order to just run integration tests, run:

yarn test:integration

In order to start the Medusa fuzzing campaign (requires Medusa installed), run:

yarn test:fuzz

In order to just run the symbolic execution tests (requires Halmos installed), run:

yarn test:symbolic

In order to check your current code coverage, run:

yarn coverage

In order to create a new .t.sol file from a .tree bulloak file, run:

yarn test:bulloak:scaffold

In order to fix or add missing tests to a .t.sol file after changing a .tree bulloak file, run:

yarn test:bulloak:fix

Deploy & verify

1) Configure the .env variables and source them:

source .env

$MAINNET_DEPLOYER_NAME and $SEPOLIA_DEPLOYER_NAME are the names of the private keys in the keystore.

$ETHERSCAN_API_KEY is required for the deployment to be verified on Etherscan.

2) Import your private keys into Foundry's encrypted keystore:

cast wallet import $MAINNET_DEPLOYER_NAME --interactive

or

cast wallet import $SEPOLIA_DEPLOYER_NAME --interactive

3) Call the deploy script:

Sepolia

yarn deploy:sepolia

or

Mainnet

yarn deploy:mainnet

The deployments are stored in ./broadcast

See the Foundry Book for available options.

Licensing

The primary license for the L2Resolver is MIT, see LICENSE

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Used by

Contributors

Languages