Skip to content

Commit

Permalink
Merge pull request #304 from ensdomains/deploy-dnssec-registrar
Browse files Browse the repository at this point in the history
Deploy dnssec registrar
  • Loading branch information
mdtanrikulu committed Jan 23, 2024
2 parents 5cb8128 + 322c326 commit 02c9e6b
Show file tree
Hide file tree
Showing 37 changed files with 3,243 additions and 780 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ yarn pub

### Cherry-picked release flow

Certain changes can be released in isolation via cherry-picking, although ideally we would always release from `staging`.
Certain changes can be released in isolation via cherry-picking, although ideally we would always release from `staging`.

1. Create a new branch from `mainnet`.
2. Cherry-pick from `staging` into new branch.
Expand Down
148 changes: 85 additions & 63 deletions contracts/dnsregistrar/OffchainDNSResolver.sol
Original file line number Diff line number Diff line change
Expand Up @@ -61,23 +61,36 @@ contract OffchainDNSResolver is IExtendedResolver, IERC165 {
bytes calldata name,
bytes calldata data
) external view returns (bytes memory) {
return
callWithOffchainLookupPropagation(
msg.sender,
name,
data,
abi.encodeCall(IExtendedResolver.resolve, (name, data))
);
revertWithDefaultOffchainLookup(name, data);
}

function resolveCallback(
bytes calldata response,
bytes calldata extraData
) external view returns (bytes memory) {
(bytes memory name, bytes memory query) = abi.decode(
(bytes memory name, bytes memory query, bytes4 selector) = abi.decode(
extraData,
(bytes, bytes)
(bytes, bytes, bytes4)
);

if (selector != bytes4(0)) {
(bytes memory targetData, address targetResolver) = abi.decode(
query,
(bytes, address)
);
return
callWithOffchainLookupPropagation(
targetResolver,
name,
query,
abi.encodeWithSelector(
selector,
response,
abi.encode(targetData, address(this))
)
);
}

DNSSEC.RRSetWithSignature[] memory rrsets = abi.decode(
response,
(DNSSEC.RRSetWithSignature[])
Expand Down Expand Up @@ -251,64 +264,73 @@ contract OffchainDNSResolver is IExtendedResolver, IERC165 {
bytes memory innerdata,
bytes memory data
) internal view returns (bytes memory) {
if (target.isContract()) {
bool result = LowLevelCallUtils.functionStaticCall(
address(target),
data
);
uint256 size = LowLevelCallUtils.returnDataSize();
if (result) {
bytes memory returnData = LowLevelCallUtils.readReturnData(
0,
size
if (!target.isContract()) {
revertWithDefaultOffchainLookup(name, innerdata);
}

bool result = LowLevelCallUtils.functionStaticCall(
address(target),
data
);
uint256 size = LowLevelCallUtils.returnDataSize();
if (result) {
bytes memory returnData = LowLevelCallUtils.readReturnData(0, size);
return abi.decode(returnData, (bytes));
}
// Failure
if (size >= 4) {
bytes memory errorId = LowLevelCallUtils.readReturnData(0, 4);
if (bytes4(errorId) == OffchainLookup.selector) {
// Offchain lookup. Decode the revert message and create our own that nests it.
bytes memory revertData = LowLevelCallUtils.readReturnData(
4,
size - 4
);
return abi.decode(returnData, (bytes));
handleOffchainLookupError(revertData, target, name);
}
// Failure
if (size >= 4) {
bytes memory errorId = LowLevelCallUtils.readReturnData(0, 4);
if (bytes4(errorId) == OffchainLookup.selector) {
// Offchain lookup. Decode the revert message and create our own that nests it.
bytes memory revertData = LowLevelCallUtils.readReturnData(
4,
size - 4
);
(
address sender,
string[] memory urls,
bytes memory callData,
bytes4 innerCallbackFunction,
bytes memory extraData
) = abi.decode(
revertData,
(address, string[], bytes, bytes4, bytes)
);
}
LowLevelCallUtils.propagateRevert();
}

if (sender != target) {
revert InvalidOperation();
}
function revertWithDefaultOffchainLookup(
bytes memory name,
bytes memory data
) internal view {
string[] memory urls = new string[](1);
urls[0] = gatewayURL;

revert OffchainLookup(
address(this),
urls,
callData,
OffchainDNSResolver.resolveCallback.selector,
abi.encode(sender, innerCallbackFunction, extraData)
);
}
}
LowLevelCallUtils.propagateRevert();
} else {
string[] memory urls = new string[](1);
urls[0] = gatewayURL;

revert OffchainLookup(
address(this),
urls,
abi.encodeCall(IDNSGateway.resolve, (name, TYPE_TXT)),
OffchainDNSResolver.resolveCallback.selector,
abi.encode(name, innerdata)
);
revert OffchainLookup(
address(this),
urls,
abi.encodeCall(IDNSGateway.resolve, (name, TYPE_TXT)),
OffchainDNSResolver.resolveCallback.selector,
abi.encode(name, data, bytes4(0))
);
}

function handleOffchainLookupError(
bytes memory returnData,
address target,
bytes memory name
) internal view {
(
address sender,
string[] memory urls,
bytes memory callData,
bytes4 innerCallbackFunction,
bytes memory extraData
) = abi.decode(returnData, (address, string[], bytes, bytes4, bytes));

if (sender != target) {
revert InvalidOperation();
}

revert OffchainLookup(
address(this),
urls,
callData,
OffchainDNSResolver.resolveCallback.selector,
abi.encode(name, extraData, innerCallbackFunction)
);
}
}
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
2 changes: 0 additions & 2 deletions contracts/ethregistrar/IETHRegistrarController.sol
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,6 @@ interface IETHRegistrarController {

function commit(bytes32) external;

function commitments(bytes32) external view returns (uint256);

function register(
string calldata,
address,
Expand Down
49 changes: 49 additions & 0 deletions deploy/dnsregistrar/05_deploy_public_suffix_list.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import { ethers } from 'hardhat'
import packet from 'dns-packet'
import { DeployFunction } from 'hardhat-deploy/types'
import { HardhatRuntimeEnvironment } from 'hardhat/types'

function encodeName(name: string) {
return '0x' + packet.name.encode(name).toString('hex')
}

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 txes = []
for (let i = 0; i < suffixes.length; i += 100) {
const batch = suffixes.slice(i, i + 100).map((suffix) => encodeName(suffix))
txes.push(await publicSuffixList.addPublicSuffixes(batch))
}
console.log(
`Waiting on ${txes.length} suffix-setting transactions to complete...`,
)
await Promise.all(txes.map((tx) => tx.wait()))

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

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

export default func
25 changes: 15 additions & 10 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 @@ -32,11 +28,20 @@ const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) {
})
console.log(`Deployed DNSRegistrar to ${tx.address}`)

const tx2 = await root
.connect(await ethers.getSigner(owner))
.setController(tx.address, true)
console.log(`Set DNSRegistrar as controller of Root (${tx2.hash})`)
await tx2.wait()
if (
owner !== undefined &&
(await root.owner()).toLowerCase() === owner.toLowerCase()
) {
const tx2 = await root
.connect(await ethers.getSigner(owner))
.setController(tx.address, true)
console.log(`Set DNSRegistrar as controller of Root (${tx2.hash})`)
await tx2.wait()
} else {
console.log(
`${owner} is not the owner of the root; you will need to call setController('${tx.address}', true) manually`,
)
}
}

func.tags = ['DNSRegistrar']
Expand Down
2 changes: 1 addition & 1 deletion deploy/dnsregistrar/20_set_tlds.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1284,7 +1284,7 @@ const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) {
}
}

func.tags = ['DNSRegistrar']
func.tags = ['registrar-tlds']
func.dependencies = ['registry', 'dnssec-oracle']
func.runAtTheEnd = true

Expand Down
3 changes: 0 additions & 3 deletions deploy/registry/00_deploy_registry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,11 @@ const ZERO_HASH =
'0x0000000000000000000000000000000000000000000000000000000000000000'

const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) {
console.log('starting')
const { getNamedAccounts, deployments, network } = hre
const { deploy, run } = deployments
const { deployer, owner } = await getNamedAccounts()

if (network.tags.legacy) {
console.log(deployer)
console.log(owner)
const contract = await deploy('LegacyENSRegistry', {
from: owner,
args: [],
Expand Down
1 change: 0 additions & 1 deletion deploy/resolvers/00_deploy_extended_dns_resolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) {
})
}

func.id = 'extended-dns-resolver'
func.tags = ['resolvers', 'ExtendedDNSResolver']

export default func
3 changes: 2 additions & 1 deletion deployments/mainnet/.migrations.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"ens": 1626404011,
"root": 1580387832
"root": 1580387832,
"setupRoot": 1580387832
}
Loading

0 comments on commit 02c9e6b

Please sign in to comment.