Skip to content

Commit

Permalink
remove usage of eth-ens-namehash
Browse files Browse the repository at this point in the history
  • Loading branch information
talentlessguy committed Jun 13, 2024
1 parent e24d592 commit 45254ab
Show file tree
Hide file tree
Showing 27 changed files with 152 additions and 187 deletions.
Binary file modified bun.lockb
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import namehash from 'eth-ens-namehash'
import { ethers } from 'hardhat'
import { DeployFunction } from 'hardhat-deploy/types'
import { HardhatRuntimeEnvironment } from 'hardhat/types'
import { keccak256 } from 'js-sha3'
import { namehash } from 'viem/ens'

const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) {
const { getNamedAccounts, deployments, network } = hre
Expand All @@ -17,7 +17,7 @@ const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) {

const deployArgs = {
from: deployer,
args: [registry.address, namehash.hash('eth')],
args: [registry.address, namehash('eth')],
log: true,
}

Expand Down
1 change: 0 additions & 1 deletion deploy/ethregistrar/00_setup_base_registrar.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import namehash from 'eth-ens-namehash'
import { ethers } from 'hardhat'
import { DeployFunction } from 'hardhat-deploy/types'
import { HardhatRuntimeEnvironment } from 'hardhat/types'
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -79,5 +79,6 @@
"homepage": "https://github.com/ensdomains/ens-contracts#readme",
"volta": {
"node": "16.20.2"
}
},
"packageManager": "yarn@1.22.22+sha1.ac34549e6aa8e7ead463a7407e1c7390f61a6610"
}
4 changes: 1 addition & 3 deletions tasks/seed.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
import fs from 'fs'

import { namehash } from 'viem/ens'
import * as envfile from 'envfile'
import n from 'eth-ens-namehash'
import { task } from 'hardhat/config'

const namehash = n.hash
const labelhash = (utils: any, label: string) =>
utils.keccak256(utils.toUtf8Bytes(label))

Expand Down
32 changes: 16 additions & 16 deletions test/dnsregistrar/TestDNSRegistrar.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ const SimplePublixSuffixList = artifacts.require('./SimplePublicSuffixList.sol')
const DNSRegistrarContract = artifacts.require('./DNSRegistrar.sol')
const PublicResolver = artifacts.require('./PublicResolver.sol')
const DNSSECImpl = artifacts.require('./DNSSECImpl')
const namehash = require('eth-ens-namehash')
const { namehash } = require('viem/ens')
const utils = require('./Helpers/Utils')
const { exceptions } = require('@ensdomains/test-utils')
const { assert } = require('chai')
Expand Down Expand Up @@ -61,7 +61,7 @@ contract('DNSRegistrar', function (accounts) {
const ReverseRegistrar = await deploy('ReverseRegistrar', ens.address)
await ens.setSubnodeOwner(EMPTY_BYTES32, labelhash('reverse'), accounts[0])
await ens.setSubnodeOwner(
namehash.hash('reverse'),
namehash('reverse'),
labelhash('addr'),
ReverseRegistrar.address,
)
Expand Down Expand Up @@ -100,7 +100,7 @@ contract('DNSRegistrar', function (accounts) {
from: accounts[1],
})

assert.equal(await ens.owner(namehash.hash('foo.test')), accounts[0])
assert.equal(await ens.owner(namehash('foo.test')), accounts[0])
})

it('allows claims on names that are not TLDs', async function () {
Expand All @@ -111,7 +111,7 @@ contract('DNSRegistrar', function (accounts) {

await registrar.proveAndClaim(utils.hexEncodeName('foo.co.nz'), proof)

assert.equal(await ens.owner(namehash.hash('foo.co.nz')), accounts[0])
assert.equal(await ens.owner(namehash('foo.co.nz')), accounts[0])
})

it('allows anyone to update a DNSSEC referenced name', async function () {
Expand All @@ -126,7 +126,7 @@ contract('DNSRegistrar', function (accounts) {

await registrar.proveAndClaim(utils.hexEncodeName('foo.test'), proof)

assert.equal(await ens.owner(namehash.hash('foo.test')), accounts[1])
assert.equal(await ens.owner(namehash('foo.test')), accounts[1])
})

it('rejects proofs with earlier inceptions', async function () {
Expand Down Expand Up @@ -173,8 +173,8 @@ contract('DNSRegistrar', function (accounts) {
ZERO_ADDRESS,
)

assert.equal(await ens.owner(namehash.hash('foo.test')), accounts[0])
assert.equal(await ens.resolver(namehash.hash('foo.test')), accounts[1])
assert.equal(await ens.owner(namehash('foo.test')), accounts[0])
assert.equal(await ens.resolver(namehash('foo.test')), accounts[1])
})

it('does not allow anyone else to claim and set a resolver', async () => {
Expand Down Expand Up @@ -214,7 +214,7 @@ contract('DNSRegistrar', function (accounts) {
accounts[0],
)

assert.equal(await resolver.addr(namehash.hash('foo.test')), accounts[0])
assert.equal(await resolver.addr(namehash('foo.test')), accounts[0])
})

it('forbids setting an address if the resolver is not also set', async () => {
Expand Down Expand Up @@ -309,22 +309,22 @@ contract('DNSRegistrar', function (accounts) {

// This is the expected use case.
// Using the proof for `alice.test`, can claim `alice.test`
assert.equal(await ens.owner(namehash.hash('alice.test')), ZERO_ADDRESS)
assert.equal(await ens.owner(namehash('alice.test')), ZERO_ADDRESS)
await registrar.proveAndClaim(
utils.hexEncodeName('alice.test'),
proofForAliceDotTest,
)
assert.equal(await ens.owner(namehash.hash('alice.test')), alice)
assert.equal(await ens.owner(namehash('alice.test')), alice)

// Now using the same proof for `alice.test`, alice can also claim `foo.test`. Without a proof involving `foo.test`
assert.equal(await ens.owner(namehash.hash('foo.test')), ZERO_ADDRESS)
assert.equal(await ens.owner(namehash('foo.test')), ZERO_ADDRESS)
await expect(
registrar.proveAndClaim(
utils.hexEncodeName('foo.test'),
proofForAliceDotTest,
),
).to.be.revertedWith('NoOwnerRecordFound')
assert.equal(await ens.owner(namehash.hash('foo.test')), ZERO_ADDRESS)
assert.equal(await ens.owner(namehash('foo.test')), ZERO_ADDRESS)
})

it('cannot takeover claimed DNS domains using unrelated proof', async function () {
Expand All @@ -338,12 +338,12 @@ contract('DNSRegistrar', function (accounts) {
]

// Alice claims her domain
assert.equal(await ens.owner(namehash.hash('alice.test')), ZERO_ADDRESS)
assert.equal(await ens.owner(namehash('alice.test')), ZERO_ADDRESS)
await registrar.proveAndClaim(
utils.hexEncodeName('alice.test'),
proofForAliceDotTest,
)
assert.equal(await ens.owner(namehash.hash('alice.test')), alice)
assert.equal(await ens.owner(namehash('alice.test')), alice)

// Build sample proof for a DNS record with name `bob.test` that bob owns
const proofForBobDotTest = [
Expand All @@ -352,13 +352,13 @@ contract('DNSRegistrar', function (accounts) {
]

// Bob claims alice's domain
assert.equal(await ens.owner(namehash.hash('alice.test')), alice)
assert.equal(await ens.owner(namehash('alice.test')), alice)
await expect(
registrar.proveAndClaim(
utils.hexEncodeName('alice.test'),
proofForBobDotTest,
),
).to.be.revertedWith('NoOwnerRecordFound')
assert.equal(await ens.owner(namehash.hash('alice.test')), alice)
assert.equal(await ens.owner(namehash('alice.test')), alice)
})
})
53 changes: 25 additions & 28 deletions test/dnsregistrar/TestOffchainDNSResolver.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ const DummyNonCCIPAwareResolver = artifacts.require(
'./DummyNonCCIPAwareResolver.sol',
)
const DNSSECImpl = artifacts.require('./DNSSECImpl')
const namehash = require('eth-ens-namehash')
const { namehash } = require('viem/ens')
const utils = require('./Helpers/Utils')
const { expect } = require('chai')
const { rootKeys, hexEncodeSignedSet } = require('../utils/dnsutils.js')
Expand Down Expand Up @@ -111,7 +111,7 @@ contract('OffchainDNSResolver', function (accounts) {
const DNSGatewayInterface = new ethers.utils.Interface(IDNSGateway.abi)
const dnsName = utils.hexEncodeName('test.test')
const callData = pr.contract.methods['addr(bytes32)'](
namehash.hash('test.test'),
namehash('test.test'),
).encodeABI()
await expect(
offchainDNSResolver.resolve(dnsName, callData),
Expand Down Expand Up @@ -167,10 +167,10 @@ contract('OffchainDNSResolver', function (accounts) {
it('handles calls to resolveCallback() with valid DNS TXT records containing an address', async function () {
const name = 'test.test'
const testAddress = '0xfefeFEFeFEFEFEFEFeFefefefefeFEfEfefefEfe'
await ownedResolver.setAddr(namehash.hash(name), testAddress)
await ownedResolver.setAddr(namehash(name), testAddress)
const pr = await PublicResolver.at(offchainDNSResolver.address)
const callData = pr.contract.methods['addr(bytes32)'](
namehash.hash(name),
namehash(name),
).encodeABI()
const result = await doDNSResolveCallback(
name,
Expand All @@ -185,10 +185,10 @@ contract('OffchainDNSResolver', function (accounts) {
it('handles calls to resolveCallback() with extra data and a legacy resolver', async function () {
const name = 'test.test'
const testAddress = '0xfefeFEFeFEFEFEFEFeFefefefefeFEfEfefefEfe'
await ownedResolver.setAddr(namehash.hash(name), testAddress)
await ownedResolver.setAddr(namehash(name), testAddress)
const pr = await PublicResolver.at(offchainDNSResolver.address)
const callData = pr.contract.methods['addr(bytes32)'](
namehash.hash(name),
namehash(name),
).encodeABI()
const result = await doDNSResolveCallback(
name,
Expand All @@ -204,25 +204,22 @@ contract('OffchainDNSResolver', function (accounts) {
// Configure dnsresolver.eth to resolve to the ownedResolver so we can use it in the test
await root.setSubnodeOwner(ethers.utils.id('eth'), accounts[0])
await ens.setSubnodeOwner(
namehash.hash('eth'),
namehash('eth'),
ethers.utils.id('dnsresolver'),
accounts[0],
)
await ens.setResolver(
namehash.hash('dnsresolver.eth'),
ownedResolver.address,
)
await ens.setResolver(namehash('dnsresolver.eth'), ownedResolver.address)
await ownedResolver.setAddr(
namehash.hash('dnsresolver.eth'),
namehash('dnsresolver.eth'),
ownedResolver.address,
)

const name = 'test.test'
const testAddress = '0xfefeFEFeFEFEFEFEFeFefefefefeFEfEfefefEfe'
await ownedResolver.setAddr(namehash.hash(name), testAddress)
await ownedResolver.setAddr(namehash(name), testAddress)
const pr = await PublicResolver.at(offchainDNSResolver.address)
const callData = pr.contract.methods['addr(bytes32)'](
namehash.hash(name),
namehash(name),
).encodeABI()
const result = await doDNSResolveCallback(
name,
Expand All @@ -237,10 +234,10 @@ contract('OffchainDNSResolver', function (accounts) {
it('rejects calls to resolveCallback() with an invalid TXT record', async function () {
const name = 'test.test'
const testAddress = '0xfefeFEFeFEFEFEFEFeFefefefefeFEfEfefefEfe'
await ownedResolver.setAddr(namehash.hash(name), testAddress)
await ownedResolver.setAddr(namehash(name), testAddress)
const pr = await PublicResolver.at(offchainDNSResolver.address)
const callData = pr.contract.methods['addr(bytes32)'](
namehash.hash(name),
namehash(name),
).encodeABI()
await expect(
doDNSResolveCallback(name, ['nonsense'], callData),
Expand All @@ -250,10 +247,10 @@ contract('OffchainDNSResolver', function (accounts) {
it('handles calls to resolveCallback() where the valid TXT record is not the first', async function () {
const name = 'test.test'
const testAddress = '0xfefeFEFeFEFEFEFEFeFefefefefeFEfEfefefEfe'
await ownedResolver.setAddr(namehash.hash(name), testAddress)
await ownedResolver.setAddr(namehash(name), testAddress)
const pr = await PublicResolver.at(offchainDNSResolver.address)
const callData = pr.contract.methods['addr(bytes32)'](
namehash.hash(name),
namehash(name),
).encodeABI()
const result = await doDNSResolveCallback(
name,
Expand All @@ -268,10 +265,10 @@ contract('OffchainDNSResolver', function (accounts) {
it('respects the first record with a valid resolver', async function () {
const name = 'test.test'
const testAddress = '0xfefeFEFeFEFEFEFEFeFefefefefeFEfEfefefEfe'
await ownedResolver.setAddr(namehash.hash(name), testAddress)
await ownedResolver.setAddr(namehash(name), testAddress)
const pr = await PublicResolver.at(offchainDNSResolver.address)
const callData = pr.contract.methods['addr(bytes32)'](
namehash.hash(name),
namehash(name),
).encodeABI()
const result = await doDNSResolveCallback(
name,
Expand All @@ -288,7 +285,7 @@ contract('OffchainDNSResolver', function (accounts) {
const resolver = await DummyExtendedDNSSECResolver.new()
const pr = await PublicResolver.at(resolver.address)
const callData = pr.contract.methods['text'](
namehash.hash(name),
namehash(name),
'test',
).encodeABI()
const result = await doDNSResolveCallback(
Expand All @@ -307,7 +304,7 @@ contract('OffchainDNSResolver', function (accounts) {
const resolver = await ExtendedDNSResolver.new()
const pr = await PublicResolver.at(resolver.address)
const callData = pr.contract.methods['addr(bytes32)'](
namehash.hash(name),
namehash(name),
).encodeABI()
const result = await doDNSResolveCallback(
name,
Expand All @@ -324,7 +321,7 @@ contract('OffchainDNSResolver', function (accounts) {
const resolver = await ExtendedDNSResolver.new()
const pr = await PublicResolver.at(resolver.address)
const callData = pr.contract.methods['addr(bytes32,uint256)'](
namehash.hash(name),
namehash(name),
COIN_TYPE_ETH,
).encodeABI()
const result = await doDNSResolveCallback(
Expand All @@ -342,7 +339,7 @@ contract('OffchainDNSResolver', function (accounts) {
const resolver = await ExtendedDNSResolver.new()
const pr = await PublicResolver.at(resolver.address)
const callData = pr.contract.methods['addr(bytes32,uint256)'](
namehash.hash(name),
namehash(name),
COIN_TYPE_BTC,
).encodeABI()
const result = await doDNSResolveCallback(
Expand All @@ -359,7 +356,7 @@ contract('OffchainDNSResolver', function (accounts) {
const resolver = await ExtendedDNSResolver.new()
const pr = await PublicResolver.at(resolver.address)
const callData = pr.contract.methods['addr(bytes32)'](
namehash.hash(name),
namehash(name),
).encodeABI()
await expect(
doDNSResolveCallback(
Expand All @@ -374,7 +371,7 @@ contract('OffchainDNSResolver', function (accounts) {
const name = 'test.test'
const resolver = await DummyLegacyTextResolver.new()
const callData = resolver.contract.methods['text'](
namehash.hash(name),
namehash(name),
'test',
).encodeABI()
const result = await doDNSResolveCallback(
Expand All @@ -392,7 +389,7 @@ contract('OffchainDNSResolver', function (accounts) {
const pr = await PublicResolver.at(offchainDNSResolver.address)
const dnsName = utils.hexEncodeName('test.test')
const callData = pr.contract.methods['addr(bytes32)'](
namehash.hash(name),
namehash(name),
).encodeABI()

const extraData = ethers.utils.defaultAbiCoder.encode(
Expand Down Expand Up @@ -443,7 +440,7 @@ contract('OffchainDNSResolver', function (accounts) {
const name = 'test.test'
const pr = await PublicResolver.at(offchainDNSResolver.address)
const callData = pr.contract.methods['addr(bytes32)'](
namehash.hash(name),
namehash(name),
).encodeABI()
await expect(
doDNSResolveCallback(name, [`ENS1 ${dummyResolver.address}`], callData),
Expand Down
6 changes: 3 additions & 3 deletions test/dnsregistrar/TestUniversalResolverWithDNS.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const { solidity } = require('ethereum-waffle')
const { use, expect } = require('chai')
const namehash = require('eth-ens-namehash')
const { namehash } = require('viem/ens')
const sha3 = require('web3-utils').sha3
const { ethers } = require('hardhat')
const { dns } = require('../test-utils')
Expand Down Expand Up @@ -122,7 +122,7 @@ contract('UniversalResolver', function (accounts) {
})

beforeEach(async () => {
node = namehash.hash('eth')
node = namehash('eth')
ens = await deploy('ENSRegistry')
root = await deploy('Root', ens.address)
dnssec = await deploy('DNSSECImpl', encodeAnchors(anchors))
Expand Down Expand Up @@ -182,7 +182,7 @@ contract('UniversalResolver', function (accounts) {
it('should revert OffchainLookup via universalResolver + offchainDNSresolver', async () => {
const addrCallData = PublicResolver.interface.encodeFunctionData(
'addr(bytes32)',
[namehash.hash('test.test')],
[namehash('test.test')],
)

const IDNSGatewayAbi = [
Expand Down
Loading

0 comments on commit 45254ab

Please sign in to comment.