diff --git a/contracts/dnsregistrar/MappingPublicSuffixList.sol b/contracts/dnsregistrar/MappingPublicSuffixList.sol new file mode 100644 index 00000000..86bcd341 --- /dev/null +++ b/contracts/dnsregistrar/MappingPublicSuffixList.sol @@ -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; + } +} diff --git a/contracts/dnsregistrar/SimplePublicSuffixList.sol b/contracts/dnsregistrar/SimplePublicSuffixList.sol index 2a3a9635..1d6b8aa5 100644 --- a/contracts/dnsregistrar/SimplePublicSuffixList.sol +++ b/contracts/dnsregistrar/SimplePublicSuffixList.sol @@ -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]); } } diff --git a/deploy/dnsregistrar/05_deploy_public_suffix_list.ts b/deploy/dnsregistrar/05_deploy_public_suffix_list.ts new file mode 100644 index 00000000..e92b0f09 --- /dev/null +++ b/deploy/dnsregistrar/05_deploy_public_suffix_list.ts @@ -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 diff --git a/deploy/dnsregistrar/10_deploy_dnsregistrar.ts b/deploy/dnsregistrar/10_deploy_dnsregistrar.ts index 9bfa5840..d7c8ed21 100644 --- a/deploy/dnsregistrar/10_deploy_dnsregistrar.ts +++ b/deploy/dnsregistrar/10_deploy_dnsregistrar.ts @@ -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, @@ -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)) diff --git a/hardhat.config.ts b/hardhat.config.ts index 900f3541..a3a9c0b4 100644 --- a/hardhat.config.ts +++ b/hardhat.config.ts @@ -127,6 +127,7 @@ const config: HardhatUserConfig = { }, owner: { default: 1, + 1: '0xFe89cc7aBB2C4183683ab71653C4cdc9B02D44b7', }, }, external: {