Skip to content

Commit

Permalink
Merge pull request #325 from ensdomains/staging
Browse files Browse the repository at this point in the history
Sync staging with mainnet
  • Loading branch information
LeonmanRolls authored Feb 16, 2024
2 parents 6d7b4c9 + fac78e2 commit 4aecdb3
Show file tree
Hide file tree
Showing 88 changed files with 21,611 additions and 1,904 deletions.
22 changes: 16 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -177,11 +177,20 @@ yarn pub
6. Have the tagged commit audited if necessary
7. If changes are required, make the changes and then once ready for review create another GitHub release with an incremented RC value `v1.2.3-RC0` -> `v.1.2.3-RC1`. Repeat as necessary.
8. Deploy to testnet. Open a pull request to merge the deploy artifacts into
the `feature` branch. Get someone to review and approve the deployment and then merge. You now MUST merge this branch into `staging` branch.
9. Create GitHub release of the form `v1.2.3-testnet` from the commit that has the new deployment artifacts.
the `feature` branch. Create GitHub release of the form `v1.2.3-testnet` from the commit that has the new deployment artifacts.
9. Get someone to review and approve the deployment and then merge. You now MUST merge this branch into `staging` branch.
10. If any further changes are needed, you can either make them on the existing feature branch that is in sync or create a new branch, and follow steps 1 -> 9. Repeat as necessary.
11. Make Deployment to mainnet from `staging`. Commit build artifacts. You now MUST merge this branch into `main`.
12. Create GitHub release of the form `v1.2.3-mainnet` from the commit that has the new deployment artifacts.
11. Make a deployment to ethereum mainnet from `staging`. Create a GitHub release of the form `v1.2.3` from the commit that has the new deployment artifacts.
12. Open a PR to merge into `main`. Have it reviewed and merged.

### Cherry-picked release flow

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.
3. Deploy to ethereum mainnet, tag the commit that has deployment artifacts and create a release.
4. Merge into `mainnet`.

### Emergency release process

Expand All @@ -191,7 +200,8 @@ yarn pub

### Notes

- `staging` branch and `main` branch should start off in sync
- Deployed code should always match source code in mainnet releases. This may not be the case for `staging`.
- `staging` branch and `main` branch should start in sync
- `staging` is intended to be a practice `main`. Only code that is intended to be released to `main` can be merged to `staging`. Consequently:
- Feature branches will be long-lived
- Feature branches must be kept in sync with `staging`
Expand All @@ -200,4 +210,4 @@ yarn pub
- It is preferable to not edit the same file on different feature branches.
- Code on `staging` and `main` will always be a subset of what is deployed, as smart contracts cannot be undeployed.
- Release candidates, `staging` and `main` branch are subject to our bug bounty
- Releases follow semantic versioning and should contain a description of changes with developers being the intended audience
- Releases follow semantic versioning and releases should contain a description of changes with developers being the intended audience
142 changes: 126 additions & 16 deletions contracts/dnsregistrar/OffchainDNSResolver.sol
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ import "../dnssec-oracle/RRUtils.sol";
import "../registry/ENSRegistry.sol";
import "../utils/HexUtils.sol";

import {Address} from "@openzeppelin/contracts/utils/Address.sol";
import {LowLevelCallUtils} from "../utils/LowLevelCallUtils.sol";

error InvalidOperation();
error OffchainLookup(
address sender,
string[] urls,
Expand All @@ -29,8 +33,9 @@ interface IDNSGateway {
uint16 constant CLASS_INET = 1;
uint16 constant TYPE_TXT = 16;

contract OffchainDNSResolver is IExtendedResolver {
contract OffchainDNSResolver is IExtendedResolver, IERC165 {
using RRUtils for *;
using Address for address;
using BytesUtils for bytes;
using HexUtils for bytes;

Expand All @@ -46,30 +51,46 @@ contract OffchainDNSResolver is IExtendedResolver {
gatewayURL = _gatewayURL;
}

function supportsInterface(
bytes4 interfaceId
) external pure override returns (bool) {
return interfaceId == type(IExtendedResolver).interfaceId;
}

function resolve(
bytes calldata name,
bytes calldata data
) external view returns (bytes memory) {
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, 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 @@ -106,17 +127,30 @@ contract OffchainDNSResolver is IExtendedResolver {
)
) {
return
IExtendedDNSResolver(dnsresolver).resolve(
callWithOffchainLookupPropagation(
dnsresolver,
name,
query,
context
abi.encodeCall(
IExtendedDNSResolver.resolve,
(name, query, context)
)
);
} else if (
IERC165(dnsresolver).supportsInterface(
IExtendedResolver.resolve.selector
)
) {
return IExtendedResolver(dnsresolver).resolve(name, query);
return
callWithOffchainLookupPropagation(
dnsresolver,
name,
query,
abi.encodeCall(
IExtendedResolver.resolve,
(name, query)
)
);
} else {
(bool ok, bytes memory ret) = address(dnsresolver)
.staticcall(query);
Expand Down Expand Up @@ -223,4 +257,80 @@ contract OffchainDNSResolver is IExtendedResolver {
abi.encodePacked(parentNode, name.keccak(idx, separator - idx))
);
}

function callWithOffchainLookupPropagation(
address target,
bytes memory name,
bytes memory innerdata,
bytes memory data
) internal view returns (bytes memory) {
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
);
handleOffchainLookupError(revertData, target, name);
}
}
LowLevelCallUtils.propagateRevert();
}

function revertWithDefaultOffchainLookup(
bytes memory name,
bytes memory data
) internal view {
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, 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)
);
}
}
6 changes: 4 additions & 2 deletions contracts/dnsregistrar/RecordParser.sol
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,13 @@ library RecordParser {
" "
);
if (terminator == type(uint256).max) {
terminator = input.length;
terminator = len + offset;
nextOffset = terminator;
} else {
nextOffset = terminator + 1;
}

key = input.substring(offset, separator - offset);
value = input.substring(separator + 1, terminator - separator - 1);
nextOffset = terminator + 1;
}
}
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
37 changes: 37 additions & 0 deletions contracts/dnsregistrar/mocks/DummyNonCCIPAwareResolver.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.4;

import "@openzeppelin/contracts/utils/introspection/ERC165.sol";
import "../OffchainDNSResolver.sol";
import "../../resolvers/profiles/IExtendedResolver.sol";

contract DummyNonCCIPAwareResolver is IExtendedResolver, ERC165 {
OffchainDNSResolver dnsResolver;

constructor(OffchainDNSResolver _dnsResolver) {
dnsResolver = _dnsResolver;
}

function supportsInterface(
bytes4 interfaceId
) public view virtual override returns (bool) {
return
interfaceId == type(IExtendedResolver).interfaceId ||
super.supportsInterface(interfaceId);
}

function resolve(
bytes calldata /* name */,
bytes calldata data
) external view returns (bytes memory) {
string[] memory urls = new string[](1);
urls[0] = "https://example.com/";
revert OffchainLookup(
address(dnsResolver),
urls,
data,
OffchainDNSResolver.resolveCallback.selector,
data
);
}
}
47 changes: 47 additions & 0 deletions contracts/dnsregistrar/mocks/DummyParser.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
pragma solidity ^0.8.4;

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

contract DummyParser {
using BytesUtils for bytes;

// parse data in format: name;key1=value1 key2=value2;url
function parseData(
bytes memory data,
uint256 kvCount
)
external
pure
returns (
string memory name,
string[] memory keys,
string[] memory values,
string memory url
)
{
uint256 len = data.length;
// retrieve name
uint256 sep1 = data.find(0, len, ";");
name = string(data.substring(0, sep1));

// retrieve url
uint256 sep2 = data.find(sep1 + 1, len - sep1, ";");
url = string(data.substring(sep2 + 1, len - sep2 - 1));

keys = new string[](kvCount);
values = new string[](kvCount);
// retrieve keys and values
uint256 offset = sep1 + 1;
for (uint256 i; i < kvCount && offset < len; i++) {
(
bytes memory key,
bytes memory val,
uint256 nextOffset
) = RecordParser.readKeyValue(data, offset, sep2 - offset);
keys[i] = string(key);
values[i] = string(val);
offset = nextOffset;
}
}
}
47 changes: 47 additions & 0 deletions contracts/resolvers/profiles/ExtendedDNSResolver.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.4;

import "@openzeppelin/contracts/utils/introspection/IERC165.sol";
import "../../resolvers/profiles/IExtendedDNSResolver.sol";
import "../../resolvers/profiles/IAddressResolver.sol";
import "../../resolvers/profiles/IAddrResolver.sol";
import "../../utils/HexUtils.sol";

contract ExtendedDNSResolver is IExtendedDNSResolver, IERC165 {
using HexUtils for *;

uint256 private constant COIN_TYPE_ETH = 60;

error NotImplemented();
error InvalidAddressFormat();

function supportsInterface(
bytes4 interfaceId
) external view virtual override returns (bool) {
return interfaceId == type(IExtendedDNSResolver).interfaceId;
}

function resolve(
bytes calldata /* name */,
bytes calldata data,
bytes calldata context
) external pure override returns (bytes memory) {
bytes4 selector = bytes4(data);
if (
selector == IAddrResolver.addr.selector ||
selector == IAddressResolver.addr.selector
) {
if (selector == IAddressResolver.addr.selector) {
(, uint256 coinType) = abi.decode(data[4:], (bytes32, uint256));
if (coinType != COIN_TYPE_ETH) return abi.encode("");
}
(address record, bool valid) = context.hexToAddress(
2,
context.length
);
if (!valid) revert InvalidAddressFormat();
return abi.encode(record);
}
revert NotImplemented();
}
}
Loading

0 comments on commit 4aecdb3

Please sign in to comment.