Skip to content

Commit

Permalink
Use explicit public suffix list
Browse files Browse the repository at this point in the history
  • Loading branch information
Arachnid committed Jan 17, 2024
1 parent 03b4775 commit 3d2f538
Show file tree
Hide file tree
Showing 5 changed files with 70 additions and 6 deletions.
18 changes: 18 additions & 0 deletions contracts/dnsregistrar/MappingPublicSuffixList.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
pragma solidity ^0.8.4;

import "../dnssec-oracle/BytesUtils.sol";
import "./PublicSuffixList.sol";

/**
* @dev A public suffix list that treats all TLDs as public suffixes.
*/
contract TLDPublicSuffixList is PublicSuffixList {
using BytesUtils for bytes;

function isPublicSuffix(
bytes calldata name
) external view override returns (bool) {
uint256 labellen = name.readUint8(0);
return labellen > 0 && name.readUint8(labellen + 1) == 0;
}
}
3 changes: 3 additions & 0 deletions contracts/dnsregistrar/SimplePublicSuffixList.sol
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,12 @@ import "./PublicSuffixList.sol";
contract SimplePublicSuffixList is PublicSuffixList, Ownable {
mapping(bytes => bool) suffixes;

event SuffixAdded(bytes suffix);

function addPublicSuffixes(bytes[] memory names) public onlyOwner {
for (uint256 i = 0; i < names.length; i++) {
suffixes[names[i]] = true;
emit SuffixAdded(names[i]);
}
}

Expand Down
46 changes: 46 additions & 0 deletions deploy/dnsregistrar/05_deploy_public_suffix_list.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import { ethers } from 'hardhat'
import { DeployFunction } from 'hardhat-deploy/types'
import { HardhatRuntimeEnvironment } from 'hardhat/types'

const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) {
const { getNamedAccounts, deployments } = hre
const { deploy } = deployments
const { deployer, owner } = await getNamedAccounts()

await deploy('SimplePublicSuffixList', {
from: deployer,
args: [],
log: true,
})
const publicSuffixList = await ethers.getContract('SimplePublicSuffixList')

const suffixList = await (
await fetch('https://publicsuffix.org/list/public_suffix_list.dat')
).text()
let suffixes = suffixList
.split('\n')
.filter((suffix) => !suffix.startsWith('//') && suffix.trim() != '')
// Right now we're only going to support top-level, non-idna suffixes
suffixes = suffixes.filter((suffix) => suffix.match(/^[a-z0-9]+$/))
const promises = []
for (let i = 0; i < suffixes.length; i += 100) {
const batch = suffixes
.slice(i, i + 100)
.map((suffix) => ethers.utils.toUtf8Bytes(suffix))
promises.push(publicSuffixList.addPublicSuffixes(batch))
}
console.log(
`Waiting on ${promises.length} suffix-setting transactions to complete...`,
)
await Promise.all(promises)

if (owner !== undefined && owner !== deployer) {
console.log('Transferring ownership to owner account')
await publicSuffixList.transferOwnership(owner)
}
}

func.tags = ['SimplePublicSuffixList']
func.dependencies = []

export default func
8 changes: 2 additions & 6 deletions deploy/dnsregistrar/10_deploy_dnsregistrar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,7 @@ const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) {
const oldregistrar = await hre.deployments.getOrNull('DNSRegistrar')
const root = await ethers.getContract('Root')

const publicSuffixList = await deploy('TLDPublicSuffixList', {
from: deployer,
args: [],
log: true,
})
const publicSuffixList = await ethers.getContract('SimplePublicSuffixList')

const tx = await deploy('DNSRegistrar', {
from: deployer,
Expand All @@ -34,7 +30,7 @@ const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) {

if (
owner !== undefined &&
(await root.owner().toLowerCase()) === owner.toLowerCase()
(await root.owner()).toLowerCase() === owner.toLowerCase()
) {
const tx2 = await root
.connect(await ethers.getSigner(owner))
Expand Down
1 change: 1 addition & 0 deletions hardhat.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ const config: HardhatUserConfig = {
},
owner: {
default: 1,
1: '0xFe89cc7aBB2C4183683ab71653C4cdc9B02D44b7',
},
},
external: {
Expand Down

0 comments on commit 3d2f538

Please sign in to comment.