// SPDX-License-Identifier: MITpragmasolidity >=0.8.4;import"./IABIResolver.sol";
import"../ResolverBase.sol";
abstractcontractABIResolverisIABIResolver, ResolverBase{
mapping(uint64=>mapping(bytes32=>mapping(uint256=>bytes))) versionable_abis;
/**
* Sets the ABI associated with an ENS node.
* Nodes may have one ABI of each content type. To remove an ABI, set it to
* the empty string.
* @param node The node to update.
* @param contentType The content type of the ABI
* @param data The ABI data.
*/functionsetABI(bytes32 node,
uint256 contentType,
bytescalldata data
) externalvirtualauthorised(node) {
// Content types must be powers of 2require(((contentType -1) & contentType) ==0);
versionable_abis[recordVersions[node]][node][contentType] = data;
emit ABIChanged(node, contentType);
}
/**
* Returns the ABI associated with an ENS node.
* Defined in EIP205.
* @param node The ENS node to query
* @param contentTypes A bitwise OR of the ABI formats accepted by the caller.
* @return contentType The content type of the return value
* @return data The ABI data
*/functionABI(bytes32 node,
uint256 contentTypes
) externalviewvirtualoverridereturns (uint256, bytesmemory) {
mapping(uint256=>bytes) storage abiset = versionable_abis[
recordVersions[node]
][node];
for (
uint256 contentType =1;
contentType <= contentTypes;
contentType <<=1
) {
if (
(contentType & contentTypes) !=0&&
abiset[contentType].length>0
) {
return (contentType, abiset[contentType]);
}
}
return (0, bytes(""));
}
functionsupportsInterface(bytes4 interfaceID
) publicviewvirtualoverridereturns (bool) {
return
interfaceID ==type(IABIResolver).interfaceId||super.supportsInterface(interfaceID);
}
}
Contract Source Code
File 2 of 37: AddrResolver.sol
// SPDX-License-Identifier: MITpragmasolidity >=0.8.4;import"../ResolverBase.sol";
import"./IAddrResolver.sol";
import"./IAddressResolver.sol";
abstractcontractAddrResolverisIAddrResolver,
IAddressResolver,
ResolverBase{
uint256privateconstant COIN_TYPE_ETH =60;
mapping(uint64=>mapping(bytes32=>mapping(uint256=>bytes))) versionable_addresses;
/**
* Sets the address associated with an ENS node.
* May only be called by the owner of that node in the ENS registry.
* @param node The node to update.
* @param a The address to set.
*/functionsetAddr(bytes32 node,
address a
) externalvirtualauthorised(node) {
setAddr(node, COIN_TYPE_ETH, addressToBytes(a));
}
/**
* Returns the address associated with an ENS node.
* @param node The ENS node to query.
* @return The associated address.
*/functionaddr(bytes32 node
) publicviewvirtualoverridereturns (addresspayable) {
bytesmemory a = addr(node, COIN_TYPE_ETH);
if (a.length==0) {
returnpayable(0);
}
return bytesToAddress(a);
}
functionsetAddr(bytes32 node,
uint256 coinType,
bytesmemory a
) publicvirtualauthorised(node) {
emit AddressChanged(node, coinType, a);
if (coinType == COIN_TYPE_ETH) {
emit AddrChanged(node, bytesToAddress(a));
}
versionable_addresses[recordVersions[node]][node][coinType] = a;
}
functionaddr(bytes32 node,
uint256 coinType
) publicviewvirtualoverridereturns (bytesmemory) {
return versionable_addresses[recordVersions[node]][node][coinType];
}
functionsupportsInterface(bytes4 interfaceID
) publicviewvirtualoverridereturns (bool) {
return
interfaceID ==type(IAddrResolver).interfaceId||
interfaceID ==type(IAddressResolver).interfaceId||super.supportsInterface(interfaceID);
}
functionbytesToAddress(bytesmemory b
) internalpurereturns (addresspayable a) {
require(b.length==20);
assembly {
a :=div(mload(add(b, 32)), exp(256, 12))
}
}
functionaddressToBytes(address a) internalpurereturns (bytesmemory b) {
b =newbytes(20);
assembly {
mstore(add(b, 32), mul(a, exp(256, 12)))
}
}
}
Contract Source Code
File 3 of 37: Buffer.sol
// SPDX-License-Identifier: BSD-2-Clausepragmasolidity ^0.8.4;/**
* @dev A library for working with mutable byte buffers in Solidity.
*
* Byte buffers are mutable and expandable, and provide a variety of primitives
* for appending to them. At any time you can fetch a bytes object containing the
* current contents of the buffer. The bytes object should not be stored between
* operations, as it may change due to resizing of the buffer.
*/libraryBuffer{
/**
* @dev Represents a mutable buffer. Buffers have a current value (buf) and
* a capacity. The capacity may be longer than the current value, in
* which case it can be extended without the need to allocate more memory.
*/structbuffer {
bytes buf;
uint capacity;
}
/**
* @dev Initializes a buffer with an initial capacity.
* @param buf The buffer to initialize.
* @param capacity The number of bytes of space to allocate the buffer.
* @return The buffer, for chaining.
*/functioninit(buffer memory buf, uint capacity) internalpurereturns(buffer memory) {
if (capacity %32!=0) {
capacity +=32- (capacity %32);
}
// Allocate space for the buffer data
buf.capacity = capacity;
assembly {
let ptr :=mload(0x40)
mstore(buf, ptr)
mstore(ptr, 0)
let fpm :=add(32, add(ptr, capacity))
iflt(fpm, ptr) {
revert(0, 0)
}
mstore(0x40, fpm)
}
return buf;
}
/**
* @dev Initializes a new buffer from an existing bytes object.
* Changes to the buffer may mutate the original value.
* @param b The bytes object to initialize the buffer with.
* @return A new buffer.
*/functionfromBytes(bytesmemory b) internalpurereturns(buffer memory) {
buffer memory buf;
buf.buf = b;
buf.capacity = b.length;
return buf;
}
functionresize(buffer memory buf, uint capacity) privatepure{
bytesmemory oldbuf = buf.buf;
init(buf, capacity);
append(buf, oldbuf);
}
/**
* @dev Sets buffer length to 0.
* @param buf The buffer to truncate.
* @return The original buffer, for chaining..
*/functiontruncate(buffer memory buf) internalpurereturns (buffer memory) {
assembly {
let bufptr :=mload(buf)
mstore(bufptr, 0)
}
return buf;
}
/**
* @dev Appends len bytes of a byte string to a buffer. Resizes if doing so would exceed
* the capacity of the buffer.
* @param buf The buffer to append to.
* @param data The data to append.
* @param len The number of bytes to copy.
* @return The original buffer, for chaining.
*/functionappend(buffer memory buf, bytesmemory data, uint len) internalpurereturns(buffer memory) {
require(len <= data.length);
uint off = buf.buf.length;
uint newCapacity = off + len;
if (newCapacity > buf.capacity) {
resize(buf, newCapacity *2);
}
uint dest;
uint src;
assembly {
// Memory address of the buffer datalet bufptr :=mload(buf)
// Length of existing buffer datalet buflen :=mload(bufptr)
// Start address = buffer address + offset + sizeof(buffer length)
dest :=add(add(bufptr, 32), off)
// Update buffer length if we're extending itifgt(newCapacity, buflen) {
mstore(bufptr, newCapacity)
}
src :=add(data, 32)
}
// Copy word-length chunks while possiblefor (; len >=32; len -=32) {
assembly {
mstore(dest, mload(src))
}
dest +=32;
src +=32;
}
// Copy remaining bytesunchecked {
uint mask = (256** (32- len)) -1;
assembly {
let srcpart :=and(mload(src), not(mask))
let destpart :=and(mload(dest), mask)
mstore(dest, or(destpart, srcpart))
}
}
return buf;
}
/**
* @dev Appends a byte string to a buffer. Resizes if doing so would exceed
* the capacity of the buffer.
* @param buf The buffer to append to.
* @param data The data to append.
* @return The original buffer, for chaining.
*/functionappend(buffer memory buf, bytesmemory data) internalpurereturns (buffer memory) {
return append(buf, data, data.length);
}
/**
* @dev Appends a byte to the buffer. Resizes if doing so would exceed the
* capacity of the buffer.
* @param buf The buffer to append to.
* @param data The data to append.
* @return The original buffer, for chaining.
*/functionappendUint8(buffer memory buf, uint8 data) internalpurereturns(buffer memory) {
uint off = buf.buf.length;
uint offPlusOne = off +1;
if (off >= buf.capacity) {
resize(buf, offPlusOne *2);
}
assembly {
// Memory address of the buffer datalet bufptr :=mload(buf)
// Address = buffer address + sizeof(buffer length) + offlet dest :=add(add(bufptr, off), 32)
mstore8(dest, data)
// Update buffer length if we extended itifgt(offPlusOne, mload(bufptr)) {
mstore(bufptr, offPlusOne)
}
}
return buf;
}
/**
* @dev Appends len bytes of bytes32 to a buffer. Resizes if doing so would
* exceed the capacity of the buffer.
* @param buf The buffer to append to.
* @param data The data to append.
* @param len The number of bytes to write (left-aligned).
* @return The original buffer, for chaining.
*/functionappend(buffer memory buf, bytes32 data, uint len) privatepurereturns(buffer memory) {
uint off = buf.buf.length;
uint newCapacity = len + off;
if (newCapacity > buf.capacity) {
resize(buf, newCapacity *2);
}
unchecked {
uint mask = (256** len) -1;
// Right-align data
data = data >> (8* (32- len));
assembly {
// Memory address of the buffer datalet bufptr :=mload(buf)
// Address = buffer address + sizeof(buffer length) + newCapacitylet dest :=add(bufptr, newCapacity)
mstore(dest, or(and(mload(dest), not(mask)), data))
// Update buffer length if we extended itifgt(newCapacity, mload(bufptr)) {
mstore(bufptr, newCapacity)
}
}
}
return buf;
}
/**
* @dev Appends a bytes20 to the buffer. Resizes if doing so would exceed
* the capacity of the buffer.
* @param buf The buffer to append to.
* @param data The data to append.
* @return The original buffer, for chhaining.
*/functionappendBytes20(buffer memory buf, bytes20 data) internalpurereturns (buffer memory) {
return append(buf, bytes32(data), 20);
}
/**
* @dev Appends a bytes32 to the buffer. Resizes if doing so would exceed
* the capacity of the buffer.
* @param buf The buffer to append to.
* @param data The data to append.
* @return The original buffer, for chaining.
*/functionappendBytes32(buffer memory buf, bytes32 data) internalpurereturns (buffer memory) {
return append(buf, data, 32);
}
/**
* @dev Appends a byte to the end of the buffer. Resizes if doing so would
* exceed the capacity of the buffer.
* @param buf The buffer to append to.
* @param data The data to append.
* @param len The number of bytes to write (right-aligned).
* @return The original buffer.
*/functionappendInt(buffer memory buf, uint data, uint len) internalpurereturns(buffer memory) {
uint off = buf.buf.length;
uint newCapacity = len + off;
if (newCapacity > buf.capacity) {
resize(buf, newCapacity *2);
}
uint mask = (256** len) -1;
assembly {
// Memory address of the buffer datalet bufptr :=mload(buf)
// Address = buffer address + sizeof(buffer length) + newCapacitylet dest :=add(bufptr, newCapacity)
mstore(dest, or(and(mload(dest), not(mask)), data))
// Update buffer length if we extended itifgt(newCapacity, mload(bufptr)) {
mstore(bufptr, newCapacity)
}
}
return buf;
}
}
Contract Source Code
File 4 of 37: BytesUtils.sol
pragmasolidity ^0.8.4;libraryBytesUtils{
errorOffsetOutOfBoundsError(uint256 offset, uint256 length);
/*
* @dev Returns the keccak-256 hash of a byte range.
* @param self The byte string to hash.
* @param offset The position to start hashing at.
* @param len The number of bytes to hash.
* @return The hash of the byte range.
*/functionkeccak(bytesmemoryself,
uint256 offset,
uint256 len
) internalpurereturns (bytes32 ret) {
require(offset + len <=self.length);
assembly {
ret :=keccak256(add(add(self, 32), offset), len)
}
}
/*
* @dev Returns a positive number if `other` comes lexicographically after
* `self`, a negative number if it comes before, or zero if the
* contents of the two bytes are equal.
* @param self The first bytes to compare.
* @param other The second bytes to compare.
* @return The result of the comparison.
*/functioncompare(bytesmemoryself,
bytesmemory other
) internalpurereturns (int256) {
return compare(self, 0, self.length, other, 0, other.length);
}
/*
* @dev Returns a positive number if `other` comes lexicographically after
* `self`, a negative number if it comes before, or zero if the
* contents of the two bytes are equal. Comparison is done per-rune,
* on unicode codepoints.
* @param self The first bytes to compare.
* @param offset The offset of self.
* @param len The length of self.
* @param other The second bytes to compare.
* @param otheroffset The offset of the other string.
* @param otherlen The length of the other string.
* @return The result of the comparison.
*/functioncompare(bytesmemoryself,
uint256 offset,
uint256 len,
bytesmemory other,
uint256 otheroffset,
uint256 otherlen
) internalpurereturns (int256) {
if (offset + len >self.length) {
revert OffsetOutOfBoundsError(offset + len, self.length);
}
if (otheroffset + otherlen > other.length) {
revert OffsetOutOfBoundsError(otheroffset + otherlen, other.length);
}
uint256 shortest = len;
if (otherlen < len) shortest = otherlen;
uint256 selfptr;
uint256 otherptr;
assembly {
selfptr :=add(self, add(offset, 32))
otherptr :=add(other, add(otheroffset, 32))
}
for (uint256 idx =0; idx < shortest; idx +=32) {
uint256 a;
uint256 b;
assembly {
a :=mload(selfptr)
b :=mload(otherptr)
}
if (a != b) {
// Mask out irrelevant bytes and check againuint256 mask;
if (shortest - idx >=32) {
mask =type(uint256).max;
} else {
mask =~(2** (8* (idx +32- shortest)) -1);
}
int256 diff =int256(a & mask) -int256(b & mask);
if (diff !=0) return diff;
}
selfptr +=32;
otherptr +=32;
}
returnint256(len) -int256(otherlen);
}
/*
* @dev Returns true if the two byte ranges are equal.
* @param self The first byte range to compare.
* @param offset The offset into the first byte range.
* @param other The second byte range to compare.
* @param otherOffset The offset into the second byte range.
* @param len The number of bytes to compare
* @return True if the byte ranges are equal, false otherwise.
*/functionequals(bytesmemoryself,
uint256 offset,
bytesmemory other,
uint256 otherOffset,
uint256 len
) internalpurereturns (bool) {
return keccak(self, offset, len) == keccak(other, otherOffset, len);
}
/*
* @dev Returns true if the two byte ranges are equal with offsets.
* @param self The first byte range to compare.
* @param offset The offset into the first byte range.
* @param other The second byte range to compare.
* @param otherOffset The offset into the second byte range.
* @return True if the byte ranges are equal, false otherwise.
*/functionequals(bytesmemoryself,
uint256 offset,
bytesmemory other,
uint256 otherOffset
) internalpurereturns (bool) {
return
keccak(self, offset, self.length- offset) ==
keccak(other, otherOffset, other.length- otherOffset);
}
/*
* @dev Compares a range of 'self' to all of 'other' and returns True iff
* they are equal.
* @param self The first byte range to compare.
* @param offset The offset into the first byte range.
* @param other The second byte range to compare.
* @return True if the byte ranges are equal, false otherwise.
*/functionequals(bytesmemoryself,
uint256 offset,
bytesmemory other
) internalpurereturns (bool) {
returnself.length== offset + other.length&&
equals(self, offset, other, 0, other.length);
}
/*
* @dev Returns true if the two byte ranges are equal.
* @param self The first byte range to compare.
* @param other The second byte range to compare.
* @return True if the byte ranges are equal, false otherwise.
*/functionequals(bytesmemoryself,
bytesmemory other
) internalpurereturns (bool) {
returnself.length== other.length&&
equals(self, 0, other, 0, self.length);
}
/*
* @dev Returns the 8-bit number at the specified index of self.
* @param self The byte string.
* @param idx The index into the bytes
* @return The specified 8 bits of the string, interpreted as an integer.
*/functionreadUint8(bytesmemoryself,
uint256 idx
) internalpurereturns (uint8 ret) {
returnuint8(self[idx]);
}
/*
* @dev Returns the 16-bit number at the specified index of self.
* @param self The byte string.
* @param idx The index into the bytes
* @return The specified 16 bits of the string, interpreted as an integer.
*/functionreadUint16(bytesmemoryself,
uint256 idx
) internalpurereturns (uint16 ret) {
require(idx +2<=self.length);
assembly {
ret :=and(mload(add(add(self, 2), idx)), 0xFFFF)
}
}
/*
* @dev Returns the 32-bit number at the specified index of self.
* @param self The byte string.
* @param idx The index into the bytes
* @return The specified 32 bits of the string, interpreted as an integer.
*/functionreadUint32(bytesmemoryself,
uint256 idx
) internalpurereturns (uint32 ret) {
require(idx +4<=self.length);
assembly {
ret :=and(mload(add(add(self, 4), idx)), 0xFFFFFFFF)
}
}
/*
* @dev Returns the 32 byte value at the specified index of self.
* @param self The byte string.
* @param idx The index into the bytes
* @return The specified 32 bytes of the string.
*/functionreadBytes32(bytesmemoryself,
uint256 idx
) internalpurereturns (bytes32 ret) {
require(idx +32<=self.length);
assembly {
ret :=mload(add(add(self, 32), idx))
}
}
/*
* @dev Returns the 32 byte value at the specified index of self.
* @param self The byte string.
* @param idx The index into the bytes
* @return The specified 32 bytes of the string.
*/functionreadBytes20(bytesmemoryself,
uint256 idx
) internalpurereturns (bytes20 ret) {
require(idx +20<=self.length);
assembly {
ret :=and(
mload(add(add(self, 32), idx)),
0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF000000000000000000000000
)
}
}
/*
* @dev Returns the n byte value at the specified index of self.
* @param self The byte string.
* @param idx The index into the bytes.
* @param len The number of bytes.
* @return The specified 32 bytes of the string.
*/functionreadBytesN(bytesmemoryself,
uint256 idx,
uint256 len
) internalpurereturns (bytes32 ret) {
require(len <=32);
require(idx + len <=self.length);
assembly {
let mask :=not(sub(exp(256, sub(32, len)), 1))
ret :=and(mload(add(add(self, 32), idx)), mask)
}
}
functionmemcpy(uint256 dest, uint256 src, uint256 len) privatepure{
// Copy word-length chunks while possiblefor (; len >=32; len -=32) {
assembly {
mstore(dest, mload(src))
}
dest +=32;
src +=32;
}
// Copy remaining bytesunchecked {
uint256 mask = (256** (32- len)) -1;
assembly {
let srcpart :=and(mload(src), not(mask))
let destpart :=and(mload(dest), mask)
mstore(dest, or(destpart, srcpart))
}
}
}
/*
* @dev Copies a substring into a new byte string.
* @param self The byte string to copy from.
* @param offset The offset to start copying at.
* @param len The number of bytes to copy.
*/functionsubstring(bytesmemoryself,
uint256 offset,
uint256 len
) internalpurereturns (bytesmemory) {
require(offset + len <=self.length);
bytesmemory ret =newbytes(len);
uint256 dest;
uint256 src;
assembly {
dest :=add(ret, 32)
src :=add(add(self, 32), offset)
}
memcpy(dest, src, len);
return ret;
}
// Maps characters from 0x30 to 0x7A to their base32 values.// 0xFF represents invalid characters in that range.bytesconstant base32HexTable =hex"00010203040506070809FFFFFFFFFFFFFF0A0B0C0D0E0F101112131415161718191A1B1C1D1E1FFFFFFFFFFFFFFFFFFFFF0A0B0C0D0E0F101112131415161718191A1B1C1D1E1F";
/**
* @dev Decodes unpadded base32 data of up to one word in length.
* @param self The data to decode.
* @param off Offset into the string to start at.
* @param len Number of characters to decode.
* @return The decoded data, left aligned.
*/functionbase32HexDecodeWord(bytesmemoryself,
uint256 off,
uint256 len
) internalpurereturns (bytes32) {
require(len <=52);
uint256 ret =0;
uint8 decoded;
for (uint256 i =0; i < len; i++) {
bytes1 char =self[off + i];
require(char >=0x30&& char <=0x7A);
decoded =uint8(base32HexTable[uint256(uint8(char)) -0x30]);
require(decoded <=0x20);
if (i == len -1) {
break;
}
ret = (ret <<5) | decoded;
}
uint256 bitlen = len *5;
if (len %8==0) {
// Multiple of 8 characters, no padding
ret = (ret <<5) | decoded;
} elseif (len %8==2) {
// Two extra characters - 1 byte
ret = (ret <<3) | (decoded >>2);
bitlen -=2;
} elseif (len %8==4) {
// Four extra characters - 2 bytes
ret = (ret <<1) | (decoded >>4);
bitlen -=4;
} elseif (len %8==5) {
// Five extra characters - 3 bytes
ret = (ret <<4) | (decoded >>1);
bitlen -=1;
} elseif (len %8==7) {
// Seven extra characters - 4 bytes
ret = (ret <<2) | (decoded >>3);
bitlen -=3;
} else {
revert();
}
returnbytes32(ret << (256- bitlen));
}
/**
* @dev Finds the first occurrence of the byte `needle` in `self`.
* @param self The string to search
* @param off The offset to start searching at
* @param len The number of bytes to search
* @param needle The byte to search for
* @return The offset of `needle` in `self`, or 2**256-1 if it was not found.
*/functionfind(bytesmemoryself,
uint256 off,
uint256 len,
bytes1 needle
) internalpurereturns (uint256) {
for (uint256 idx = off; idx < off + len; idx++) {
if (self[idx] == needle) {
return idx;
}
}
returntype(uint256).max;
}
}
Contract Source Code
File 5 of 37: ContentHashResolver.sol
// SPDX-License-Identifier: MITpragmasolidity >=0.8.4;import"../ResolverBase.sol";
import"./IContentHashResolver.sol";
abstractcontractContentHashResolverisIContentHashResolver, ResolverBase{
mapping(uint64=>mapping(bytes32=>bytes)) versionable_hashes;
/**
* Sets the contenthash associated with an ENS node.
* May only be called by the owner of that node in the ENS registry.
* @param node The node to update.
* @param hash The contenthash to set
*/functionsetContenthash(bytes32 node,
bytescalldata hash
) externalvirtualauthorised(node) {
versionable_hashes[recordVersions[node]][node] = hash;
emit ContenthashChanged(node, hash);
}
/**
* Returns the contenthash associated with an ENS node.
* @param node The ENS node to query.
* @return The associated contenthash.
*/functioncontenthash(bytes32 node
) externalviewvirtualoverridereturns (bytesmemory) {
return versionable_hashes[recordVersions[node]][node];
}
functionsupportsInterface(bytes4 interfaceID
) publicviewvirtualoverridereturns (bool) {
return
interfaceID ==type(IContentHashResolver).interfaceId||super.supportsInterface(interfaceID);
}
}
Contract Source Code
File 6 of 37: DNSResolver.sol
// SPDX-License-Identifier: MITpragmasolidity >=0.8.4;import"../ResolverBase.sol";
import"../../dnssec-oracle/RRUtils.sol";
import"./IDNSRecordResolver.sol";
import"./IDNSZoneResolver.sol";
abstractcontractDNSResolverisIDNSRecordResolver,
IDNSZoneResolver,
ResolverBase{
usingRRUtilsfor*;
usingBytesUtilsforbytes;
// Zone hashes for the domains.// A zone hash is an EIP-1577 content hash in binary format that should point to a// resource containing a single zonefile.// node => contenthashmapping(uint64=>mapping(bytes32=>bytes)) private versionable_zonehashes;
// The records themselves. Stored as binary RRSETs// node => version => name => resource => datamapping(uint64=>mapping(bytes32=>mapping(bytes32=>mapping(uint16=>bytes))))
private versionable_records;
// Count of number of entries for a given name. Required for DNS resolvers// when resolving wildcards.// node => version => name => number of recordsmapping(uint64=>mapping(bytes32=>mapping(bytes32=>uint16)))
private versionable_nameEntriesCount;
/**
* Set one or more DNS records. Records are supplied in wire-format.
* Records with the same node/name/resource must be supplied one after the
* other to ensure the data is updated correctly. For example, if the data
* was supplied:
* a.example.com IN A 1.2.3.4
* a.example.com IN A 5.6.7.8
* www.example.com IN CNAME a.example.com.
* then this would store the two A records for a.example.com correctly as a
* single RRSET, however if the data was supplied:
* a.example.com IN A 1.2.3.4
* www.example.com IN CNAME a.example.com.
* a.example.com IN A 5.6.7.8
* then this would store the first A record, the CNAME, then the second A
* record which would overwrite the first.
*
* @param node the namehash of the node for which to set the records
* @param data the DNS wire format records to set
*/functionsetDNSRecords(bytes32 node,
bytescalldata data
) externalvirtualauthorised(node) {
uint16 resource =0;
uint256 offset =0;
bytesmemory name;
bytesmemory value;
bytes32 nameHash;
uint64 version = recordVersions[node];
// Iterate over the data to add the resource recordsfor (
RRUtils.RRIterator memory iter = data.iterateRRs(0);
!iter.done();
iter.next()
) {
if (resource ==0) {
resource = iter.dnstype;
name = iter.name();
nameHash =keccak256(abi.encodePacked(name));
value =bytes(iter.rdata());
} else {
bytesmemory newName = iter.name();
if (resource != iter.dnstype ||!name.equals(newName)) {
setDNSRRSet(
node,
name,
resource,
data,
offset,
iter.offset - offset,
value.length==0,
version
);
resource = iter.dnstype;
offset = iter.offset;
name = newName;
nameHash =keccak256(name);
value =bytes(iter.rdata());
}
}
}
if (name.length>0) {
setDNSRRSet(
node,
name,
resource,
data,
offset,
data.length- offset,
value.length==0,
version
);
}
}
/**
* Obtain a DNS record.
* @param node the namehash of the node for which to fetch the record
* @param name the keccak-256 hash of the fully-qualified name for which to fetch the record
* @param resource the ID of the resource as per https://en.wikipedia.org/wiki/List_of_DNS_record_types
* @return the DNS record in wire format if present, otherwise empty
*/functiondnsRecord(bytes32 node,
bytes32 name,
uint16 resource
) publicviewvirtualoverridereturns (bytesmemory) {
return versionable_records[recordVersions[node]][node][name][resource];
}
/**
* Check if a given node has records.
* @param node the namehash of the node for which to check the records
* @param name the namehash of the node for which to check the records
*/functionhasDNSRecords(bytes32 node,
bytes32 name
) publicviewvirtualreturns (bool) {
return (versionable_nameEntriesCount[recordVersions[node]][node][
name
] !=0);
}
/**
* setZonehash sets the hash for the zone.
* May only be called by the owner of that node in the ENS registry.
* @param node The node to update.
* @param hash The zonehash to set
*/functionsetZonehash(bytes32 node,
bytescalldata hash
) externalvirtualauthorised(node) {
uint64 currentRecordVersion = recordVersions[node];
bytesmemory oldhash = versionable_zonehashes[currentRecordVersion][
node
];
versionable_zonehashes[currentRecordVersion][node] = hash;
emit DNSZonehashChanged(node, oldhash, hash);
}
/**
* zonehash obtains the hash for the zone.
* @param node The ENS node to query.
* @return The associated contenthash.
*/functionzonehash(bytes32 node
) externalviewvirtualoverridereturns (bytesmemory) {
return versionable_zonehashes[recordVersions[node]][node];
}
functionsupportsInterface(bytes4 interfaceID
) publicviewvirtualoverridereturns (bool) {
return
interfaceID ==type(IDNSRecordResolver).interfaceId||
interfaceID ==type(IDNSZoneResolver).interfaceId||super.supportsInterface(interfaceID);
}
functionsetDNSRRSet(bytes32 node,
bytesmemory name,
uint16 resource,
bytesmemory data,
uint256 offset,
uint256 size,
bool deleteRecord,
uint64 version
) private{
bytes32 nameHash =keccak256(name);
bytesmemory rrData = data.substring(offset, size);
if (deleteRecord) {
if (
versionable_records[version][node][nameHash][resource].length!=0
) {
versionable_nameEntriesCount[version][node][nameHash]--;
}
delete (versionable_records[version][node][nameHash][resource]);
emit DNSRecordDeleted(node, name, resource);
} else {
if (
versionable_records[version][node][nameHash][resource].length==0
) {
versionable_nameEntriesCount[version][node][nameHash]++;
}
versionable_records[version][node][nameHash][resource] = rrData;
emit DNSRecordChanged(node, name, resource, rrData);
}
}
}
Contract Source Code
File 7 of 37: ENS.sol
pragmasolidity >=0.8.4;interfaceENS{
// Logged when the owner of a node assigns a new owner to a subnode.eventNewOwner(bytes32indexed node, bytes32indexed label, address owner);
// Logged when the owner of a node transfers ownership to a new account.eventTransfer(bytes32indexed node, address owner);
// Logged when the resolver for a node changes.eventNewResolver(bytes32indexed node, address resolver);
// Logged when the TTL of a node changeseventNewTTL(bytes32indexed node, uint64 ttl);
// Logged when an operator is added or removed.eventApprovalForAll(addressindexed owner,
addressindexed operator,
bool approved
);
functionsetRecord(bytes32 node,
address owner,
address resolver,
uint64 ttl
) external;
functionsetSubnodeRecord(bytes32 node,
bytes32 label,
address owner,
address resolver,
uint64 ttl
) external;
functionsetSubnodeOwner(bytes32 node,
bytes32 label,
address owner
) externalreturns (bytes32);
functionsetResolver(bytes32 node, address resolver) external;
functionsetOwner(bytes32 node, address owner) external;
functionsetTTL(bytes32 node, uint64 ttl) external;
functionsetApprovalForAll(address operator, bool approved) external;
functionowner(bytes32 node) externalviewreturns (address);
functionresolver(bytes32 node) externalviewreturns (address);
functionttl(bytes32 node) externalviewreturns (uint64);
functionrecordExists(bytes32 node) externalviewreturns (bool);
functionisApprovedForAll(address owner,
address operator
) externalviewreturns (bool);
}
Contract Source Code
File 8 of 37: ERC165.sol
// SPDX-License-Identifier: MIT// OpenZeppelin Contracts v4.4.1 (utils/introspection/ERC165.sol)pragmasolidity ^0.8.0;import"./IERC165.sol";
/**
* @dev Implementation of the {IERC165} interface.
*
* Contracts that want to implement ERC165 should inherit from this contract and override {supportsInterface} to check
* for the additional interface id that will be supported. For example:
*
* ```solidity
* function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) {
* return interfaceId == type(MyInterface).interfaceId || super.supportsInterface(interfaceId);
* }
* ```
*
* Alternatively, {ERC165Storage} provides an easier to use but more expensive implementation.
*/abstractcontractERC165isIERC165{
/**
* @dev See {IERC165-supportsInterface}.
*/functionsupportsInterface(bytes4 interfaceId) publicviewvirtualoverridereturns (bool) {
return interfaceId ==type(IERC165).interfaceId;
}
}
Contract Source Code
File 9 of 37: IABIResolver.sol
// SPDX-License-Identifier: MITpragmasolidity >=0.8.4;interfaceIABIResolver{
eventABIChanged(bytes32indexed node, uint256indexed contentType);
/**
* Returns the ABI associated with an ENS node.
* Defined in EIP205.
* @param node The ENS node to query
* @param contentTypes A bitwise OR of the ABI formats accepted by the caller.
* @return contentType The content type of the return value
* @return data The ABI data
*/functionABI(bytes32 node,
uint256 contentTypes
) externalviewreturns (uint256, bytesmemory);
}
Contract Source Code
File 10 of 37: IAddrResolver.sol
// SPDX-License-Identifier: MITpragmasolidity >=0.8.4;/**
* Interface for the legacy (ETH-only) addr function.
*/interfaceIAddrResolver{
eventAddrChanged(bytes32indexed node, address a);
/**
* Returns the address associated with an ENS node.
* @param node The ENS node to query.
* @return The associated address.
*/functionaddr(bytes32 node) externalviewreturns (addresspayable);
}
Contract Source Code
File 11 of 37: IAddressResolver.sol
// SPDX-License-Identifier: MITpragmasolidity >=0.8.4;/**
* Interface for the new (multicoin) addr function.
*/interfaceIAddressResolver{
eventAddressChanged(bytes32indexed node,
uint256 coinType,
bytes newAddress
);
functionaddr(bytes32 node,
uint256 coinType
) externalviewreturns (bytesmemory);
}
Contract Source Code
File 12 of 37: IBaseRegistrar.sol
import"../registry/ENS.sol";
import"./IBaseRegistrar.sol";
import"@openzeppelin/contracts/token/ERC721/IERC721.sol";
interfaceIBaseRegistrarisIERC721{
eventControllerAdded(addressindexed controller);
eventControllerRemoved(addressindexed controller);
eventNameMigrated(uint256indexed id,
addressindexed owner,
uint256 expires
);
eventNameRegistered(uint256indexed id,
addressindexed owner,
uint256 expires
);
eventNameRenewed(uint256indexed id, uint256 expires);
// Authorises a controller, who can register and renew domains.functionaddController(address controller) external;
// Revoke controller permission for an address.functionremoveController(address controller) external;
// Set the resolver for the TLD this registrar manages.functionsetResolver(address resolver) external;
// Returns the expiration timestamp of the specified label hash.functionnameExpires(uint256 id) externalviewreturns (uint256);
// Returns true iff the specified name is available for registration.functionavailable(uint256 id) externalviewreturns (bool);
/**
* @dev Register a name.
*/functionregister(uint256 id,
address owner,
uint256 duration
) externalreturns (uint256);
functionrenew(uint256 id, uint256 duration) externalreturns (uint256);
/**
* @dev Reclaim ownership of a name in ENS, if you own it in the registrar.
*/functionreclaim(uint256 id, address owner) external;
}
Contract Source Code
File 13 of 37: IContentHashResolver.sol
// SPDX-License-Identifier: MITpragmasolidity >=0.8.4;interfaceIContentHashResolver{
eventContenthashChanged(bytes32indexed node, bytes hash);
/**
* Returns the contenthash associated with an ENS node.
* @param node The ENS node to query.
* @return The associated contenthash.
*/functioncontenthash(bytes32 node) externalviewreturns (bytesmemory);
}
Contract Source Code
File 14 of 37: IDNSRecordResolver.sol
// SPDX-License-Identifier: MITpragmasolidity >=0.8.4;interfaceIDNSRecordResolver{
// DNSRecordChanged is emitted whenever a given node/name/resource's RRSET is updated.eventDNSRecordChanged(bytes32indexed node,
bytes name,
uint16 resource,
bytes record
);
// DNSRecordDeleted is emitted whenever a given node/name/resource's RRSET is deleted.eventDNSRecordDeleted(bytes32indexed node, bytes name, uint16 resource);
/**
* Obtain a DNS record.
* @param node the namehash of the node for which to fetch the record
* @param name the keccak-256 hash of the fully-qualified name for which to fetch the record
* @param resource the ID of the resource as per https://en.wikipedia.org/wiki/List_of_DNS_record_types
* @return the DNS record in wire format if present, otherwise empty
*/functiondnsRecord(bytes32 node,
bytes32 name,
uint16 resource
) externalviewreturns (bytesmemory);
}
Contract Source Code
File 15 of 37: IDNSZoneResolver.sol
// SPDX-License-Identifier: MITpragmasolidity >=0.8.4;interfaceIDNSZoneResolver{
// DNSZonehashChanged is emitted whenever a given node's zone hash is updated.eventDNSZonehashChanged(bytes32indexed node,
bytes lastzonehash,
bytes zonehash
);
/**
* zonehash obtains the hash for the zone.
* @param node The ENS node to query.
* @return The associated contenthash.
*/functionzonehash(bytes32 node) externalviewreturns (bytesmemory);
}
Contract Source Code
File 16 of 37: IERC1155.sol
// SPDX-License-Identifier: MIT// OpenZeppelin Contracts (last updated v4.7.0) (token/ERC1155/IERC1155.sol)pragmasolidity ^0.8.0;import"../../utils/introspection/IERC165.sol";
/**
* @dev Required interface of an ERC1155 compliant contract, as defined in the
* https://eips.ethereum.org/EIPS/eip-1155[EIP].
*
* _Available since v3.1._
*/interfaceIERC1155isIERC165{
/**
* @dev Emitted when `value` tokens of token type `id` are transferred from `from` to `to` by `operator`.
*/eventTransferSingle(addressindexed operator, addressindexedfrom, addressindexed to, uint256 id, uint256 value);
/**
* @dev Equivalent to multiple {TransferSingle} events, where `operator`, `from` and `to` are the same for all
* transfers.
*/eventTransferBatch(addressindexed operator,
addressindexedfrom,
addressindexed to,
uint256[] ids,
uint256[] values
);
/**
* @dev Emitted when `account` grants or revokes permission to `operator` to transfer their tokens, according to
* `approved`.
*/eventApprovalForAll(addressindexed account, addressindexed operator, bool approved);
/**
* @dev Emitted when the URI for token type `id` changes to `value`, if it is a non-programmatic URI.
*
* If an {URI} event was emitted for `id`, the standard
* https://eips.ethereum.org/EIPS/eip-1155#metadata-extensions[guarantees] that `value` will equal the value
* returned by {IERC1155MetadataURI-uri}.
*/eventURI(string value, uint256indexed id);
/**
* @dev Returns the amount of tokens of token type `id` owned by `account`.
*
* Requirements:
*
* - `account` cannot be the zero address.
*/functionbalanceOf(address account, uint256 id) externalviewreturns (uint256);
/**
* @dev xref:ROOT:erc1155.adoc#batch-operations[Batched] version of {balanceOf}.
*
* Requirements:
*
* - `accounts` and `ids` must have the same length.
*/functionbalanceOfBatch(address[] calldata accounts, uint256[] calldata ids)
externalviewreturns (uint256[] memory);
/**
* @dev Grants or revokes permission to `operator` to transfer the caller's tokens, according to `approved`,
*
* Emits an {ApprovalForAll} event.
*
* Requirements:
*
* - `operator` cannot be the caller.
*/functionsetApprovalForAll(address operator, bool approved) external;
/**
* @dev Returns true if `operator` is approved to transfer ``account``'s tokens.
*
* See {setApprovalForAll}.
*/functionisApprovedForAll(address account, address operator) externalviewreturns (bool);
/**
* @dev Transfers `amount` tokens of token type `id` from `from` to `to`.
*
* Emits a {TransferSingle} event.
*
* Requirements:
*
* - `to` cannot be the zero address.
* - If the caller is not `from`, it must have been approved to spend ``from``'s tokens via {setApprovalForAll}.
* - `from` must have a balance of tokens of type `id` of at least `amount`.
* - If `to` refers to a smart contract, it must implement {IERC1155Receiver-onERC1155Received} and return the
* acceptance magic value.
*/functionsafeTransferFrom(addressfrom,
address to,
uint256 id,
uint256 amount,
bytescalldata data
) external;
/**
* @dev xref:ROOT:erc1155.adoc#batch-operations[Batched] version of {safeTransferFrom}.
*
* Emits a {TransferBatch} event.
*
* Requirements:
*
* - `ids` and `amounts` must have the same length.
* - If `to` refers to a smart contract, it must implement {IERC1155Receiver-onERC1155BatchReceived} and return the
* acceptance magic value.
*/functionsafeBatchTransferFrom(addressfrom,
address to,
uint256[] calldata ids,
uint256[] calldata amounts,
bytescalldata data
) external;
}
Contract Source Code
File 17 of 37: IERC165.sol
// SPDX-License-Identifier: MIT// OpenZeppelin Contracts v4.4.1 (utils/introspection/IERC165.sol)pragmasolidity ^0.8.0;/**
* @dev Interface of the ERC165 standard, as defined in the
* https://eips.ethereum.org/EIPS/eip-165[EIP].
*
* Implementers can declare support of contract interfaces, which can then be
* queried by others ({ERC165Checker}).
*
* For an implementation, see {ERC165}.
*/interfaceIERC165{
/**
* @dev Returns true if this contract implements the interface defined by
* `interfaceId`. See the corresponding
* https://eips.ethereum.org/EIPS/eip-165#how-interfaces-are-identified[EIP section]
* to learn more about how these ids are created.
*
* This function call must use less than 30 000 gas.
*/functionsupportsInterface(bytes4 interfaceId) externalviewreturns (bool);
}
Contract Source Code
File 18 of 37: IERC721.sol
// SPDX-License-Identifier: MIT// OpenZeppelin Contracts (last updated v4.8.0) (token/ERC721/IERC721.sol)pragmasolidity ^0.8.0;import"../../utils/introspection/IERC165.sol";
/**
* @dev Required interface of an ERC721 compliant contract.
*/interfaceIERC721isIERC165{
/**
* @dev Emitted when `tokenId` token is transferred from `from` to `to`.
*/eventTransfer(addressindexedfrom, addressindexed to, uint256indexed tokenId);
/**
* @dev Emitted when `owner` enables `approved` to manage the `tokenId` token.
*/eventApproval(addressindexed owner, addressindexed approved, uint256indexed tokenId);
/**
* @dev Emitted when `owner` enables or disables (`approved`) `operator` to manage all of its assets.
*/eventApprovalForAll(addressindexed owner, addressindexed operator, bool approved);
/**
* @dev Returns the number of tokens in ``owner``'s account.
*/functionbalanceOf(address owner) externalviewreturns (uint256 balance);
/**
* @dev Returns the owner of the `tokenId` token.
*
* Requirements:
*
* - `tokenId` must exist.
*/functionownerOf(uint256 tokenId) externalviewreturns (address owner);
/**
* @dev Safely transfers `tokenId` token from `from` to `to`.
*
* Requirements:
*
* - `from` cannot be the zero address.
* - `to` cannot be the zero address.
* - `tokenId` token must exist and be owned by `from`.
* - If the caller is not `from`, it must be approved to move this token by either {approve} or {setApprovalForAll}.
* - If `to` refers to a smart contract, it must implement {IERC721Receiver-onERC721Received}, which is called upon a safe transfer.
*
* Emits a {Transfer} event.
*/functionsafeTransferFrom(addressfrom,
address to,
uint256 tokenId,
bytescalldata data
) external;
/**
* @dev Safely transfers `tokenId` token from `from` to `to`, checking first that contract recipients
* are aware of the ERC721 protocol to prevent tokens from being forever locked.
*
* Requirements:
*
* - `from` cannot be the zero address.
* - `to` cannot be the zero address.
* - `tokenId` token must exist and be owned by `from`.
* - If the caller is not `from`, it must have been allowed to move this token by either {approve} or {setApprovalForAll}.
* - If `to` refers to a smart contract, it must implement {IERC721Receiver-onERC721Received}, which is called upon a safe transfer.
*
* Emits a {Transfer} event.
*/functionsafeTransferFrom(addressfrom,
address to,
uint256 tokenId
) external;
/**
* @dev Transfers `tokenId` token from `from` to `to`.
*
* WARNING: Note that the caller is responsible to confirm that the recipient is capable of receiving ERC721
* or else they may be permanently lost. Usage of {safeTransferFrom} prevents loss, though the caller must
* understand this adds an external call which potentially creates a reentrancy vulnerability.
*
* Requirements:
*
* - `from` cannot be the zero address.
* - `to` cannot be the zero address.
* - `tokenId` token must be owned by `from`.
* - If the caller is not `from`, it must be approved to move this token by either {approve} or {setApprovalForAll}.
*
* Emits a {Transfer} event.
*/functiontransferFrom(addressfrom,
address to,
uint256 tokenId
) external;
/**
* @dev Gives permission to `to` to transfer `tokenId` token to another account.
* The approval is cleared when the token is transferred.
*
* Only a single account can be approved at a time, so approving the zero address clears previous approvals.
*
* Requirements:
*
* - The caller must own the token or be an approved operator.
* - `tokenId` must exist.
*
* Emits an {Approval} event.
*/functionapprove(address to, uint256 tokenId) external;
/**
* @dev Approve or remove `operator` as an operator for the caller.
* Operators can call {transferFrom} or {safeTransferFrom} for any token owned by the caller.
*
* Requirements:
*
* - The `operator` cannot be the caller.
*
* Emits an {ApprovalForAll} event.
*/functionsetApprovalForAll(address operator, bool _approved) external;
/**
* @dev Returns the account approved for `tokenId` token.
*
* Requirements:
*
* - `tokenId` must exist.
*/functiongetApproved(uint256 tokenId) externalviewreturns (address operator);
/**
* @dev Returns if the `operator` is allowed to manage all of the assets of `owner`.
*
* See {setApprovalForAll}
*/functionisApprovedForAll(address owner, address operator) externalviewreturns (bool);
}
Contract Source Code
File 19 of 37: IInterfaceResolver.sol
// SPDX-License-Identifier: MITpragmasolidity >=0.8.4;interfaceIInterfaceResolver{
eventInterfaceChanged(bytes32indexed node,
bytes4indexed interfaceID,
address implementer
);
/**
* Returns the address of a contract that implements the specified interface for this name.
* If an implementer has not been set for this interfaceID and name, the resolver will query
* the contract at `addr()`. If `addr()` is set, a contract exists at that address, and that
* contract implements EIP165 and returns `true` for the specified interfaceID, its address
* will be returned.
* @param node The ENS node to query.
* @param interfaceID The EIP 165 interface ID to check for.
* @return The address that implements this interface, or 0 if the interface is unsupported.
*/functioninterfaceImplementer(bytes32 node,
bytes4 interfaceID
) externalviewreturns (address);
}
// SPDX-License-Identifier: MITpragmasolidity >=0.8.4;interfaceINameResolver{
eventNameChanged(bytes32indexed node, string name);
/**
* Returns the name associated with an ENS node, for reverse records.
* Defined in EIP181.
* @param node The ENS node to query.
* @return The associated name.
*/functionname(bytes32 node) externalviewreturns (stringmemory);
}
// SPDX-License-Identifier: MITpragmasolidity >=0.8.4;interfaceIPubkeyResolver{
eventPubkeyChanged(bytes32indexed node, bytes32 x, bytes32 y);
/**
* Returns the SECP256k1 public key associated with an ENS node.
* Defined in EIP 619.
* @param node The ENS node to query
* @return x The X coordinate of the curve point for the public key.
* @return y The Y coordinate of the curve point for the public key.
*/functionpubkey(bytes32 node) externalviewreturns (bytes32 x, bytes32 y);
}
// SPDX-License-Identifier: MITpragmasolidity >=0.8.4;interfaceITextResolver{
eventTextChanged(bytes32indexed node,
stringindexed indexedKey,
string key,
string value
);
/**
* Returns the text data associated with an ENS node and key.
* @param node The ENS node to query.
* @param key The text data key to query.
* @return The associated text data.
*/functiontext(bytes32 node,
stringcalldata key
) externalviewreturns (stringmemory);
}
// SPDX-License-Identifier: MITpragmasolidity >=0.8.4;import"@openzeppelin/contracts/utils/introspection/IERC165.sol";
import"../ResolverBase.sol";
import"./AddrResolver.sol";
import"./IInterfaceResolver.sol";
abstractcontractInterfaceResolverisIInterfaceResolver, AddrResolver{
mapping(uint64=>mapping(bytes32=>mapping(bytes4=>address))) versionable_interfaces;
/**
* Sets an interface associated with a name.
* Setting the address to 0 restores the default behaviour of querying the contract at `addr()` for interface support.
* @param node The node to update.
* @param interfaceID The EIP 165 interface ID.
* @param implementer The address of a contract that implements this interface for this node.
*/functionsetInterface(bytes32 node,
bytes4 interfaceID,
address implementer
) externalvirtualauthorised(node) {
versionable_interfaces[recordVersions[node]][node][
interfaceID
] = implementer;
emit InterfaceChanged(node, interfaceID, implementer);
}
/**
* Returns the address of a contract that implements the specified interface for this name.
* If an implementer has not been set for this interfaceID and name, the resolver will query
* the contract at `addr()`. If `addr()` is set, a contract exists at that address, and that
* contract implements EIP165 and returns `true` for the specified interfaceID, its address
* will be returned.
* @param node The ENS node to query.
* @param interfaceID The EIP 165 interface ID to check for.
* @return The address that implements this interface, or 0 if the interface is unsupported.
*/functioninterfaceImplementer(bytes32 node,
bytes4 interfaceID
) externalviewvirtualoverridereturns (address) {
address implementer = versionable_interfaces[recordVersions[node]][
node
][interfaceID];
if (implementer !=address(0)) {
return implementer;
}
address a = addr(node);
if (a ==address(0)) {
returnaddress(0);
}
(bool success, bytesmemory returnData) = a.staticcall(
abi.encodeWithSignature(
"supportsInterface(bytes4)",
type(IERC165).interfaceId
)
);
if (!success || returnData.length<32|| returnData[31] ==0) {
// EIP 165 not supported by targetreturnaddress(0);
}
(success, returnData) = a.staticcall(
abi.encodeWithSignature("supportsInterface(bytes4)", interfaceID)
);
if (!success || returnData.length<32|| returnData[31] ==0) {
// Specified interface not supported by targetreturnaddress(0);
}
return a;
}
functionsupportsInterface(bytes4 interfaceID
) publicviewvirtualoverridereturns (bool) {
return
interfaceID ==type(IInterfaceResolver).interfaceId||super.supportsInterface(interfaceID);
}
}
Contract Source Code
File 30 of 37: Multicallable.sol
// SPDX-License-Identifier: MITpragmasolidity ^0.8.4;import"./IMulticallable.sol";
import"@openzeppelin/contracts/utils/introspection/ERC165.sol";
abstractcontractMulticallableisIMulticallable, ERC165{
function_multicall(bytes32 nodehash,
bytes[] calldata data
) internalreturns (bytes[] memory results) {
results =newbytes[](data.length);
for (uint256 i =0; i < data.length; i++) {
if (nodehash !=bytes32(0)) {
bytes32 txNamehash =bytes32(data[i][4:36]);
require(
txNamehash == nodehash,
"multicall: All records must have a matching namehash"
);
}
(bool success, bytesmemory result) =address(this).delegatecall(
data[i]
);
require(success);
results[i] = result;
}
return results;
}
// This function provides an extra security check when called// from priviledged contracts (such as EthRegistrarController)// that can set records on behalf of the node ownersfunctionmulticallWithNodeCheck(bytes32 nodehash,
bytes[] calldata data
) externalreturns (bytes[] memory results) {
return _multicall(nodehash, data);
}
functionmulticall(bytes[] calldata data
) publicoverridereturns (bytes[] memory results) {
return _multicall(bytes32(0), data);
}
functionsupportsInterface(bytes4 interfaceID
) publicviewvirtualoverridereturns (bool) {
return
interfaceID ==type(IMulticallable).interfaceId||super.supportsInterface(interfaceID);
}
}
Contract Source Code
File 31 of 37: NameResolver.sol
// SPDX-License-Identifier: MITpragmasolidity >=0.8.4;import"../ResolverBase.sol";
import"./INameResolver.sol";
abstractcontractNameResolverisINameResolver, ResolverBase{
mapping(uint64=>mapping(bytes32=>string)) versionable_names;
/**
* Sets the name associated with an ENS node, for reverse records.
* May only be called by the owner of that node in the ENS registry.
* @param node The node to update.
*/functionsetName(bytes32 node,
stringcalldata newName
) externalvirtualauthorised(node) {
versionable_names[recordVersions[node]][node] = newName;
emit NameChanged(node, newName);
}
/**
* Returns the name associated with an ENS node, for reverse records.
* Defined in EIP181.
* @param node The ENS node to query.
* @return The associated name.
*/functionname(bytes32 node
) externalviewvirtualoverridereturns (stringmemory) {
return versionable_names[recordVersions[node]][node];
}
functionsupportsInterface(bytes4 interfaceID
) publicviewvirtualoverridereturns (bool) {
return
interfaceID ==type(INameResolver).interfaceId||super.supportsInterface(interfaceID);
}
}
Contract Source Code
File 32 of 37: PubkeyResolver.sol
// SPDX-License-Identifier: MITpragmasolidity >=0.8.4;import"../ResolverBase.sol";
import"./IPubkeyResolver.sol";
abstractcontractPubkeyResolverisIPubkeyResolver, ResolverBase{
structPublicKey {
bytes32 x;
bytes32 y;
}
mapping(uint64=>mapping(bytes32=> PublicKey)) versionable_pubkeys;
/**
* Sets the SECP256k1 public key associated with an ENS node.
* @param node The ENS node to query
* @param x the X coordinate of the curve point for the public key.
* @param y the Y coordinate of the curve point for the public key.
*/functionsetPubkey(bytes32 node,
bytes32 x,
bytes32 y
) externalvirtualauthorised(node) {
versionable_pubkeys[recordVersions[node]][node] = PublicKey(x, y);
emit PubkeyChanged(node, x, y);
}
/**
* Returns the SECP256k1 public key associated with an ENS node.
* Defined in EIP 619.
* @param node The ENS node to query
* @return x The X coordinate of the curve point for the public key.
* @return y The Y coordinate of the curve point for the public key.
*/functionpubkey(bytes32 node
) externalviewvirtualoverridereturns (bytes32 x, bytes32 y) {
uint64 currentRecordVersion = recordVersions[node];
return (
versionable_pubkeys[currentRecordVersion][node].x,
versionable_pubkeys[currentRecordVersion][node].y
);
}
functionsupportsInterface(bytes4 interfaceID
) publicviewvirtualoverridereturns (bool) {
return
interfaceID ==type(IPubkeyResolver).interfaceId||super.supportsInterface(interfaceID);
}
}
Contract Source Code
File 33 of 37: PublicResolver.sol
//SPDX-License-Identifier: MITpragmasolidity >=0.8.17 <0.9.0;import"../registry/ENS.sol";
import"./profiles/ABIResolver.sol";
import"./profiles/AddrResolver.sol";
import"./profiles/ContentHashResolver.sol";
import"./profiles/DNSResolver.sol";
import"./profiles/InterfaceResolver.sol";
import"./profiles/NameResolver.sol";
import"./profiles/PubkeyResolver.sol";
import"./profiles/TextResolver.sol";
import"./Multicallable.sol";
import {ReverseClaimer} from"../reverseRegistrar/ReverseClaimer.sol";
import {INameWrapper} from"../wrapper/INameWrapper.sol";
/**
* A simple resolver anyone can use; only allows the owner of a node to set its
* address.
*/contractPublicResolverisMulticallable,
ABIResolver,
AddrResolver,
ContentHashResolver,
DNSResolver,
InterfaceResolver,
NameResolver,
PubkeyResolver,
TextResolver,
ReverseClaimer{
ENS immutable ens;
INameWrapper immutable nameWrapper;
addressimmutable trustedETHController;
addressimmutable trustedReverseRegistrar;
/**
* A mapping of operators. An address that is authorised for an address
* may make any changes to the name that the owner could, but may not update
* the set of authorisations.
* (owner, operator) => approved
*/mapping(address=>mapping(address=>bool)) private _operatorApprovals;
/**
* A mapping of delegates. A delegate that is authorised by an owner
* for a name may make changes to the name's resolver, but may not update
* the set of token approvals.
* (owner, name, delegate) => approved
*/mapping(address=>mapping(bytes32=>mapping(address=>bool)))
private _tokenApprovals;
// Logged when an operator is added or removed.eventApprovalForAll(addressindexed owner,
addressindexed operator,
bool approved
);
// Logged when a delegate is approved or an approval is revoked.eventApproved(address owner,
bytes32indexed node,
addressindexed delegate,
boolindexed approved
);
constructor(
ENS _ens,
INameWrapper wrapperAddress,
address _trustedETHController,
address _trustedReverseRegistrar
) ReverseClaimer(_ens, msg.sender) {
ens = _ens;
nameWrapper = wrapperAddress;
trustedETHController = _trustedETHController;
trustedReverseRegistrar = _trustedReverseRegistrar;
}
/**
* @dev See {IERC1155-setApprovalForAll}.
*/functionsetApprovalForAll(address operator, bool approved) external{
require(
msg.sender!= operator,
"ERC1155: setting approval status for self"
);
_operatorApprovals[msg.sender][operator] = approved;
emit ApprovalForAll(msg.sender, operator, approved);
}
/**
* @dev See {IERC1155-isApprovedForAll}.
*/functionisApprovedForAll(address account,
address operator
) publicviewreturns (bool) {
return _operatorApprovals[account][operator];
}
/**
* @dev Approve a delegate to be able to updated records on a node.
*/functionapprove(bytes32 node, address delegate, bool approved) external{
require(msg.sender!= delegate, "Setting delegate status for self");
_tokenApprovals[msg.sender][node][delegate] = approved;
emit Approved(msg.sender, node, delegate, approved);
}
/**
* @dev Check to see if the delegate has been approved by the owner for the node.
*/functionisApprovedFor(address owner,
bytes32 node,
address delegate
) publicviewreturns (bool) {
return _tokenApprovals[owner][node][delegate];
}
functionisAuthorised(bytes32 node) internalviewoverridereturns (bool) {
if (
msg.sender== trustedETHController ||msg.sender== trustedReverseRegistrar
) {
returntrue;
}
address owner = ens.owner(node);
if (owner ==address(nameWrapper)) {
owner = nameWrapper.ownerOf(uint256(node));
}
return
owner ==msg.sender||
isApprovedForAll(owner, msg.sender) ||
isApprovedFor(owner, node, msg.sender);
}
functionsupportsInterface(bytes4 interfaceID
)
publicviewoverride(
Multicallable,
ABIResolver,
AddrResolver,
ContentHashResolver,
DNSResolver,
InterfaceResolver,
NameResolver,
PubkeyResolver,
TextResolver
)
returns (bool)
{
returnsuper.supportsInterface(interfaceID);
}
}
Contract Source Code
File 34 of 37: RRUtils.sol
pragmasolidity ^0.8.4;import"./BytesUtils.sol";
import"@ensdomains/buffer/contracts/Buffer.sol";
/**
* @dev RRUtils is a library that provides utilities for parsing DNS resource records.
*/libraryRRUtils{
usingBytesUtilsfor*;
usingBufferfor*;
/**
* @dev Returns the number of bytes in the DNS name at 'offset' in 'self'.
* @param self The byte array to read a name from.
* @param offset The offset to start reading at.
* @return The length of the DNS name at 'offset', in bytes.
*/functionnameLength(bytesmemoryself,
uint256 offset
) internalpurereturns (uint256) {
uint256 idx = offset;
while (true) {
assert(idx <self.length);
uint256 labelLen =self.readUint8(idx);
idx += labelLen +1;
if (labelLen ==0) {
break;
}
}
return idx - offset;
}
/**
* @dev Returns a DNS format name at the specified offset of self.
* @param self The byte array to read a name from.
* @param offset The offset to start reading at.
* @return ret The name.
*/functionreadName(bytesmemoryself,
uint256 offset
) internalpurereturns (bytesmemory ret) {
uint256 len = nameLength(self, offset);
returnself.substring(offset, len);
}
/**
* @dev Returns the number of labels in the DNS name at 'offset' in 'self'.
* @param self The byte array to read a name from.
* @param offset The offset to start reading at.
* @return The number of labels in the DNS name at 'offset', in bytes.
*/functionlabelCount(bytesmemoryself,
uint256 offset
) internalpurereturns (uint256) {
uint256 count =0;
while (true) {
assert(offset <self.length);
uint256 labelLen =self.readUint8(offset);
offset += labelLen +1;
if (labelLen ==0) {
break;
}
count +=1;
}
return count;
}
uint256constant RRSIG_TYPE =0;
uint256constant RRSIG_ALGORITHM =2;
uint256constant RRSIG_LABELS =3;
uint256constant RRSIG_TTL =4;
uint256constant RRSIG_EXPIRATION =8;
uint256constant RRSIG_INCEPTION =12;
uint256constant RRSIG_KEY_TAG =16;
uint256constant RRSIG_SIGNER_NAME =18;
structSignedSet {
uint16 typeCovered;
uint8 algorithm;
uint8 labels;
uint32 ttl;
uint32 expiration;
uint32 inception;
uint16 keytag;
bytes signerName;
bytes data;
bytes name;
}
functionreadSignedSet(bytesmemory data
) internalpurereturns (SignedSet memoryself) {
self.typeCovered = data.readUint16(RRSIG_TYPE);
self.algorithm = data.readUint8(RRSIG_ALGORITHM);
self.labels = data.readUint8(RRSIG_LABELS);
self.ttl = data.readUint32(RRSIG_TTL);
self.expiration = data.readUint32(RRSIG_EXPIRATION);
self.inception = data.readUint32(RRSIG_INCEPTION);
self.keytag = data.readUint16(RRSIG_KEY_TAG);
self.signerName = readName(data, RRSIG_SIGNER_NAME);
self.data = data.substring(
RRSIG_SIGNER_NAME +self.signerName.length,
data.length- RRSIG_SIGNER_NAME -self.signerName.length
);
}
functionrrs(
SignedSet memory rrset
) internalpurereturns (RRIterator memory) {
return iterateRRs(rrset.data, 0);
}
/**
* @dev An iterator over resource records.
*/structRRIterator {
bytes data;
uint256 offset;
uint16 dnstype;
uint16 class;
uint32 ttl;
uint256 rdataOffset;
uint256 nextOffset;
}
/**
* @dev Begins iterating over resource records.
* @param self The byte string to read from.
* @param offset The offset to start reading at.
* @return ret An iterator object.
*/functioniterateRRs(bytesmemoryself,
uint256 offset
) internalpurereturns (RRIterator memory ret) {
ret.data =self;
ret.nextOffset = offset;
next(ret);
}
/**
* @dev Returns true iff there are more RRs to iterate.
* @param iter The iterator to check.
* @return True iff the iterator has finished.
*/functiondone(RRIterator memory iter) internalpurereturns (bool) {
return iter.offset >= iter.data.length;
}
/**
* @dev Moves the iterator to the next resource record.
* @param iter The iterator to advance.
*/functionnext(RRIterator memory iter) internalpure{
iter.offset = iter.nextOffset;
if (iter.offset >= iter.data.length) {
return;
}
// Skip the nameuint256 off = iter.offset + nameLength(iter.data, iter.offset);
// Read type, class, and ttl
iter.dnstype = iter.data.readUint16(off);
off +=2;
iter.class = iter.data.readUint16(off);
off +=2;
iter.ttl = iter.data.readUint32(off);
off +=4;
// Read the rdatauint256 rdataLength = iter.data.readUint16(off);
off +=2;
iter.rdataOffset = off;
iter.nextOffset = off + rdataLength;
}
/**
* @dev Returns the name of the current record.
* @param iter The iterator.
* @return A new bytes object containing the owner name from the RR.
*/functionname(RRIterator memory iter) internalpurereturns (bytesmemory) {
return
iter.data.substring(
iter.offset,
nameLength(iter.data, iter.offset)
);
}
/**
* @dev Returns the rdata portion of the current record.
* @param iter The iterator.
* @return A new bytes object containing the RR's RDATA.
*/functionrdata(
RRIterator memory iter
) internalpurereturns (bytesmemory) {
return
iter.data.substring(
iter.rdataOffset,
iter.nextOffset - iter.rdataOffset
);
}
uint256constant DNSKEY_FLAGS =0;
uint256constant DNSKEY_PROTOCOL =2;
uint256constant DNSKEY_ALGORITHM =3;
uint256constant DNSKEY_PUBKEY =4;
structDNSKEY {
uint16 flags;
uint8 protocol;
uint8 algorithm;
bytes publicKey;
}
functionreadDNSKEY(bytesmemory data,
uint256 offset,
uint256 length
) internalpurereturns (DNSKEY memoryself) {
self.flags = data.readUint16(offset + DNSKEY_FLAGS);
self.protocol = data.readUint8(offset + DNSKEY_PROTOCOL);
self.algorithm = data.readUint8(offset + DNSKEY_ALGORITHM);
self.publicKey = data.substring(
offset + DNSKEY_PUBKEY,
length - DNSKEY_PUBKEY
);
}
uint256constant DS_KEY_TAG =0;
uint256constant DS_ALGORITHM =2;
uint256constant DS_DIGEST_TYPE =3;
uint256constant DS_DIGEST =4;
structDS {
uint16 keytag;
uint8 algorithm;
uint8 digestType;
bytes digest;
}
functionreadDS(bytesmemory data,
uint256 offset,
uint256 length
) internalpurereturns (DS memoryself) {
self.keytag = data.readUint16(offset + DS_KEY_TAG);
self.algorithm = data.readUint8(offset + DS_ALGORITHM);
self.digestType = data.readUint8(offset + DS_DIGEST_TYPE);
self.digest = data.substring(offset + DS_DIGEST, length - DS_DIGEST);
}
functionisSubdomainOf(bytesmemoryself,
bytesmemory other
) internalpurereturns (bool) {
uint256 off =0;
uint256 counts = labelCount(self, 0);
uint256 othercounts = labelCount(other, 0);
while (counts > othercounts) {
off = progress(self, off);
counts--;
}
returnself.equals(off, other, 0);
}
functioncompareNames(bytesmemoryself,
bytesmemory other
) internalpurereturns (int256) {
if (self.equals(other)) {
return0;
}
uint256 off;
uint256 otheroff;
uint256 prevoff;
uint256 otherprevoff;
uint256 counts = labelCount(self, 0);
uint256 othercounts = labelCount(other, 0);
// Keep removing labels from the front of the name until both names are equal lengthwhile (counts > othercounts) {
prevoff = off;
off = progress(self, off);
counts--;
}
while (othercounts > counts) {
otherprevoff = otheroff;
otheroff = progress(other, otheroff);
othercounts--;
}
// Compare the last nonequal labels to each otherwhile (counts >0&&!self.equals(off, other, otheroff)) {
prevoff = off;
off = progress(self, off);
otherprevoff = otheroff;
otheroff = progress(other, otheroff);
counts -=1;
}
if (off ==0) {
return-1;
}
if (otheroff ==0) {
return1;
}
returnself.compare(
prevoff +1,
self.readUint8(prevoff),
other,
otherprevoff +1,
other.readUint8(otherprevoff)
);
}
/**
* @dev Compares two serial numbers using RFC1982 serial number math.
*/functionserialNumberGte(uint32 i1,
uint32 i2
) internalpurereturns (bool) {
unchecked {
returnint32(i1) -int32(i2) >=0;
}
}
functionprogress(bytesmemory body,
uint256 off
) internalpurereturns (uint256) {
return off +1+ body.readUint8(off);
}
/**
* @dev Computes the keytag for a chunk of data.
* @param data The data to compute a keytag for.
* @return The computed key tag.
*/functioncomputeKeytag(bytesmemory data) internalpurereturns (uint16) {
/* This function probably deserves some explanation.
* The DNSSEC keytag function is a checksum that relies on summing up individual bytes
* from the input string, with some mild bitshifting. Here's a Naive solidity implementation:
*
* function computeKeytag(bytes memory data) internal pure returns (uint16) {
* uint ac;
* for (uint i = 0; i < data.length; i++) {
* ac += i & 1 == 0 ? uint16(data.readUint8(i)) << 8 : data.readUint8(i);
* }
* return uint16(ac + (ac >> 16));
* }
*
* The EVM, with its 256 bit words, is exceedingly inefficient at doing byte-by-byte operations;
* the code above, on reasonable length inputs, consumes over 100k gas. But we can make the EVM's
* large words work in our favour.
*
* The code below works by treating the input as a series of 256 bit words. It first masks out
* even and odd bytes from each input word, adding them to two separate accumulators `ac1` and `ac2`.
* The bytes are separated by empty bytes, so as long as no individual sum exceeds 2^16-1, we're
* effectively summing 16 different numbers with each EVM ADD opcode.
*
* Once it's added up all the inputs, it has to add all the 16 bit values in `ac1` and `ac2` together.
* It does this using the same trick - mask out every other value, shift to align them, add them together.
* After the first addition on both accumulators, there's enough room to add the two accumulators together,
* and the remaining sums can be done just on ac1.
*/unchecked {
require(data.length<=8192, "Long keys not permitted");
uint256 ac1;
uint256 ac2;
for (uint256 i =0; i < data.length+31; i +=32) {
uint256 word;
assembly {
word :=mload(add(add(data, 32), i))
}
if (i +32> data.length) {
uint256 unused =256- (data.length- i) *8;
word = (word >> unused) << unused;
}
ac1 +=
(word &0xFF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00) >>8;
ac2 += (word &0x00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF);
}
ac1 =
(ac1 &0x0000FFFF0000FFFF0000FFFF0000FFFF0000FFFF0000FFFF0000FFFF0000FFFF) +
((ac1 &0xFFFF0000FFFF0000FFFF0000FFFF0000FFFF0000FFFF0000FFFF0000FFFF0000) >>16);
ac2 =
(ac2 &0x0000FFFF0000FFFF0000FFFF0000FFFF0000FFFF0000FFFF0000FFFF0000FFFF) +
((ac2 &0xFFFF0000FFFF0000FFFF0000FFFF0000FFFF0000FFFF0000FFFF0000FFFF0000) >>16);
ac1 = (ac1 <<8) + ac2;
ac1 =
(ac1 &0x00000000FFFFFFFF00000000FFFFFFFF00000000FFFFFFFF00000000FFFFFFFF) +
((ac1 &0xFFFFFFFF00000000FFFFFFFF00000000FFFFFFFF00000000FFFFFFFF00000000) >>32);
ac1 =
(ac1 &0x0000000000000000FFFFFFFFFFFFFFFF0000000000000000FFFFFFFFFFFFFFFF) +
((ac1 &0xFFFFFFFFFFFFFFFF0000000000000000FFFFFFFFFFFFFFFF0000000000000000) >>64);
ac1 =
(ac1 &0x00000000000000000000000000000000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF) +
(ac1 >>128);
ac1 += (ac1 >>16) &0xFFFF;
returnuint16(ac1);
}
}
}
Contract Source Code
File 35 of 37: ResolverBase.sol
// SPDX-License-Identifier: MITpragmasolidity >=0.8.4;import"@openzeppelin/contracts/utils/introspection/ERC165.sol";
import"./profiles/IVersionableResolver.sol";
abstractcontractResolverBaseisERC165, IVersionableResolver{
mapping(bytes32=>uint64) public recordVersions;
functionisAuthorised(bytes32 node) internalviewvirtualreturns (bool);
modifierauthorised(bytes32 node) {
require(isAuthorised(node));
_;
}
/**
* Increments the record version associated with an ENS node.
* May only be called by the owner of that node in the ENS registry.
* @param node The node to update.
*/functionclearRecords(bytes32 node) publicvirtualauthorised(node) {
recordVersions[node]++;
emit VersionChanged(node, recordVersions[node]);
}
functionsupportsInterface(bytes4 interfaceID
) publicviewvirtualoverridereturns (bool) {
return
interfaceID ==type(IVersionableResolver).interfaceId||super.supportsInterface(interfaceID);
}
}
// SPDX-License-Identifier: MITpragmasolidity >=0.8.4;import"../ResolverBase.sol";
import"./ITextResolver.sol";
abstractcontractTextResolverisITextResolver, ResolverBase{
mapping(uint64=>mapping(bytes32=>mapping(string=>string))) versionable_texts;
/**
* Sets the text data associated with an ENS node and key.
* May only be called by the owner of that node in the ENS registry.
* @param node The node to update.
* @param key The key to set.
* @param value The text data value to set.
*/functionsetText(bytes32 node,
stringcalldata key,
stringcalldata value
) externalvirtualauthorised(node) {
versionable_texts[recordVersions[node]][node][key] = value;
emit TextChanged(node, key, key, value);
}
/**
* Returns the text data associated with an ENS node and key.
* @param node The ENS node to query.
* @param key The text data key to query.
* @return The associated text data.
*/functiontext(bytes32 node,
stringcalldata key
) externalviewvirtualoverridereturns (stringmemory) {
return versionable_texts[recordVersions[node]][node][key];
}
functionsupportsInterface(bytes4 interfaceID
) publicviewvirtualoverridereturns (bool) {
return
interfaceID ==type(ITextResolver).interfaceId||super.supportsInterface(interfaceID);
}
}