Skip to content

Commit

Permalink
forge fmt
Browse files Browse the repository at this point in the history
  • Loading branch information
Chomtana committed Jan 11, 2025
1 parent 0331fd9 commit 859828b
Show file tree
Hide file tree
Showing 9 changed files with 71 additions and 133 deletions.
4 changes: 4 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"editor.formatOnSave": true,
"solidity.formatter": "forge"
}
6 changes: 3 additions & 3 deletions script/Counter.s.sol
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.13;

import {Script, console} from "forge-std/Script.sol";
import {Counter} from "../src/Counter.sol";
import { Script, console } from "forge-std/Script.sol";
import { Counter } from "../src/Counter.sol";

contract CounterScript is Script {
Counter public counter;

function setUp() public {}
function setUp() public { }

function run() public {
vm.startBroadcast();
Expand Down
56 changes: 18 additions & 38 deletions src/DomainImplementation.sol
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ pragma solidity ^0.8.17;

import "./interfaces/IDomain.sol";
import "./lib/DNSEncoder.sol";
import {ClonesWithImmutableArgs} from "clones-with-immutable-args/ClonesWithImmutableArgs.sol";
import { ClonesWithImmutableArgs } from "clones-with-immutable-args/ClonesWithImmutableArgs.sol";

/// @title DomainImplementation
/// @notice Implementation contract for domain management with immutable args
Expand Down Expand Up @@ -36,15 +36,10 @@ abstract contract DomainImplementation is IDomain {
bool isParentOwnerDelegated = false;
address parentAddr = parent();
if (parentAddr != address(0)) {
isParentOwnerDelegated =
DomainImplementation(parentAddr).subdomainOwnerDelegation() &&
owner == msg.sender;
isParentOwnerDelegated = DomainImplementation(parentAddr).subdomainOwnerDelegation() && owner == msg.sender;
}

return
msg.sender == parentAddr ||
authorizedDelegates[msg.sender] ||
isParentOwnerDelegated;
return msg.sender == parentAddr || authorizedDelegates[msg.sender] || isParentOwnerDelegated;
}

modifier onlyAuthorized() {
Expand All @@ -68,10 +63,7 @@ abstract contract DomainImplementation is IDomain {

/// @notice Adds a new authorized delegate
/// @param delegate Address to authorize
function addAuthorizedDelegate(
address delegate,
bool authorized
) external onlyAuthorized {
function addAuthorizedDelegate(address delegate, bool authorized) external onlyAuthorized {
authorizedDelegates[delegate] = authorized;
emit DelegateAuthorized(delegate, authorized);
}
Expand All @@ -85,10 +77,11 @@ abstract contract DomainImplementation is IDomain {
/// @notice Registers a new subdomain
/// @param label The label for the subdomain
/// @param subdomainOwner The owner of the new subdomain
function registerSubdomain(
string calldata label,
address subdomainOwner
) external onlyAuthorized returns (address) {
function registerSubdomain(string calldata label, address subdomainOwner)
external
onlyAuthorized
returns (address)
{
bytes memory labelBytes = bytes(label);
if (!DNSEncoder.isValidLabel(labelBytes)) revert InvalidLabel();
if (subdomains[label] != address(0)) revert SubdomainAlreadyExists();
Expand Down Expand Up @@ -119,10 +112,11 @@ abstract contract DomainImplementation is IDomain {
/// @param reverseDnsEncoded The reverse DNS encoded name of the subdomain path
/// @param data The calldata to pass to the final subdomain
/// @return bytes The return data from the call
function callSubdomain(
bytes calldata reverseDnsEncoded,
bytes calldata data
) external onlyAuthorized returns (bytes memory) {
function callSubdomain(bytes calldata reverseDnsEncoded, bytes calldata data)
external
onlyAuthorized
returns (bytes memory)
{
// If no more labels, execute the call on this contract
if (reverseDnsEncoded.length == 1 && reverseDnsEncoded[0] == 0) {
(bool success, bytes memory returnData) = address(this).call(data);
Expand All @@ -134,9 +128,7 @@ abstract contract DomainImplementation is IDomain {
uint8 labelLength = uint8(reverseDnsEncoded[0]);

// Extract the label
string memory currentLabel = string(
reverseDnsEncoded[1:labelLength + 1]
);
string memory currentLabel = string(reverseDnsEncoded[1:labelLength + 1]);

// Get the subdomain address
address subdomainAddr = subdomains[currentLabel];
Expand All @@ -146,11 +138,7 @@ abstract contract DomainImplementation is IDomain {
bytes calldata remainingLabels = reverseDnsEncoded[labelLength + 1:];

// Recursively call the subdomain
return
DomainImplementation(subdomainAddr).callSubdomain(
remainingLabels,
data
);
return DomainImplementation(subdomainAddr).callSubdomain(remainingLabels, data);
}

/// @notice Gets the implementation contract address
Expand Down Expand Up @@ -194,12 +182,7 @@ abstract contract DomainImplementation is IDomain {
bytes memory labelBytes = bytes(domainLabel);

// Combine this label with parent's encoded name
return
abi.encodePacked(
bytes1(uint8(labelBytes.length)),
labelBytes,
parentEncoded
);
return abi.encodePacked(bytes1(uint8(labelBytes.length)), labelBytes, parentEncoded);
}

/// @notice Gets all subdomain names
Expand All @@ -224,10 +207,7 @@ abstract contract DomainImplementation is IDomain {
return arg;
}

function _getArgBytes(
uint256 offset,
uint256 length
) internal pure returns (bytes memory) {
function _getArgBytes(uint256 offset, uint256 length) internal pure returns (bytes memory) {
bytes memory arg = new bytes(length);
assembly {
calldatacopy(add(arg, 0x20), offset, length)
Expand Down
77 changes: 29 additions & 48 deletions src/SingularResolver.sol
Original file line number Diff line number Diff line change
Expand Up @@ -9,36 +9,27 @@ import "./interfaces/ISingularResolverAuthorizer.sol";
/// @dev Implements the IResolver interface with authorization checks
contract SingularResolver is IResolver {
mapping(address => mapping(bytes32 => address)) private addresses;
mapping(address => mapping(bytes32 => mapping(string => string)))
private texts;
mapping(address => mapping(bytes32 => mapping(string => string))) private texts;
mapping(address => mapping(bytes32 => bytes)) private contenthashes;
mapping(address => mapping(bytes32 => mapping(bytes => mapping(uint16 => bytes))))
private dnsRecords;
mapping(address => mapping(bytes32 => mapping(bytes => mapping(uint16 => bytes)))) private dnsRecords;
mapping(address => mapping(bytes32 => bytes)) private zonehashes;

/// @notice Ensures that only authorized addresses can modify records
/// @param authorizer The authorizer contract to check permissions
/// @param node The node being modified
modifier onlyAuthorized(
ISingularResolverAuthorizer authorizer,
bytes32 node
) {
require(
authorizer.isResolverAuthorized(node, msg.sender, msg.data),
"SingularResolver: Not authorized"
);
modifier onlyAuthorized(ISingularResolverAuthorizer authorizer, bytes32 node) {
require(authorizer.isResolverAuthorized(node, msg.sender, msg.data), "SingularResolver: Not authorized");
_;
}

/// @notice Sets the address associated with a node
/// @param authorizer The authorizer contract
/// @param node The node to update
/// @param addr The address to set
function setAddr(
ISingularResolverAuthorizer authorizer,
bytes32 node,
address addr
) external onlyAuthorized(authorizer, node) {
function setAddr(ISingularResolverAuthorizer authorizer, bytes32 node, address addr)
external
onlyAuthorized(authorizer, node)
{
addresses[address(authorizer)][node] = addr;
emit AddrChanged(node, addr);
}
Expand All @@ -47,35 +38,27 @@ contract SingularResolver is IResolver {
return addresses[msg.sender][node];
}

function setText(
ISingularResolverAuthorizer authorizer,
bytes32 node,
string calldata key,
string calldata value
) external onlyAuthorized(authorizer, node) {
function setText(ISingularResolverAuthorizer authorizer, bytes32 node, string calldata key, string calldata value)
external
onlyAuthorized(authorizer, node)
{
texts[address(authorizer)][node][key] = value;
emit TextChanged(node, key, value);
}

function text(
bytes32 node,
string calldata key
) external view override returns (string memory) {
function text(bytes32 node, string calldata key) external view override returns (string memory) {
return texts[msg.sender][node][key];
}

function setContenthash(
ISingularResolverAuthorizer authorizer,
bytes32 node,
bytes calldata hash
) external onlyAuthorized(authorizer, node) {
function setContenthash(ISingularResolverAuthorizer authorizer, bytes32 node, bytes calldata hash)
external
onlyAuthorized(authorizer, node)
{
contenthashes[address(authorizer)][node] = hash;
emit ContenthashChanged(node, hash);
}

function contenthash(
bytes32 node
) external view override returns (bytes memory) {
function contenthash(bytes32 node) external view override returns (bytes memory) {
return contenthashes[msg.sender][node];
}

Expand All @@ -90,26 +73,24 @@ contract SingularResolver is IResolver {
emit DNSRecordChanged(node, name, resource, record);
}

function dnsRecord(
bytes32 node,
bytes calldata name,
uint16 resource
) external view override returns (bytes memory) {
function dnsRecord(bytes32 node, bytes calldata name, uint16 resource)
external
view
override
returns (bytes memory)
{
return dnsRecords[msg.sender][node][name][resource];
}

function setDNSZonehash(
ISingularResolverAuthorizer authorizer,
bytes32 node,
bytes calldata hash
) external onlyAuthorized(authorizer, node) {
function setDNSZonehash(ISingularResolverAuthorizer authorizer, bytes32 node, bytes calldata hash)
external
onlyAuthorized(authorizer, node)
{
zonehashes[address(authorizer)][node] = hash;
emit DNSZonehashChanged(node, hash);
}

function dnsZonehash(
bytes32 node
) external view override returns (bytes memory) {
function dnsZonehash(bytes32 node) external view override returns (bytes memory) {
return zonehashes[msg.sender][node];
}
}
10 changes: 2 additions & 8 deletions src/interfaces/IDomain.sol
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,7 @@ pragma solidity ^0.8.17;

interface IDomain {
/// @notice Emitted when domain ownership is transferred
event OwnershipTransferred(
address indexed previousOwner,
address indexed newOwner
);
event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);

/// @notice Emitted when a subdomain is recorded
event SubdomainRecorded(string indexed name, address indexed proxyAddress);
Expand All @@ -22,10 +19,7 @@ interface IDomain {
/// @param label The label for the subdomain
/// @param subdomainOwner The owner of the new subdomain
/// @return The address of the new subdomain contract
function registerSubdomain(
string calldata label,
address subdomainOwner
) external returns (address);
function registerSubdomain(string calldata label, address subdomainOwner) external returns (address);

/// @notice Gets the current owner of the domain
function owner() external view returns (address);
Expand Down
18 changes: 3 additions & 15 deletions src/interfaces/IResolver.sol
Original file line number Diff line number Diff line change
Expand Up @@ -5,28 +5,16 @@ interface IResolver {
event AddrChanged(bytes32 indexed node, address addr);
event TextChanged(bytes32 indexed node, string indexed key, string value);
event ContenthashChanged(bytes32 indexed node, bytes contenthash);
event DNSRecordChanged(
bytes32 indexed node,
bytes name,
uint16 resource,
bytes record
);
event DNSRecordChanged(bytes32 indexed node, bytes name, uint16 resource, bytes record);
event DNSZonehashChanged(bytes32 indexed node, bytes zonehash);

function addr(bytes32 node) external view returns (address);

function text(
bytes32 node,
string calldata key
) external view returns (string memory);
function text(bytes32 node, string calldata key) external view returns (string memory);

function contenthash(bytes32 node) external view returns (bytes memory);

function dnsRecord(
bytes32 node,
bytes calldata name,
uint16 resource
) external view returns (bytes memory);
function dnsRecord(bytes32 node, bytes calldata name, uint16 resource) external view returns (bytes memory);

function dnsZonehash(bytes32 node) external view returns (bytes memory);
}
6 changes: 1 addition & 5 deletions src/interfaces/ISingularResolverAuthorizer.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,5 @@
pragma solidity ^0.8.17;

interface ISingularResolverAuthorizer {
function isResolverAuthorized(
bytes32 node,
address caller,
bytes calldata data
) external view returns (bool);
function isResolverAuthorized(bytes32 node, address caller, bytes calldata data) external view returns (bool);
}
23 changes: 9 additions & 14 deletions src/lib/DNSEncoder.sol
Original file line number Diff line number Diff line change
Expand Up @@ -68,10 +68,7 @@ library DNSEncoder {
/// @param label The new label to prepend
/// @param name The existing encoded name
/// @return bytes The concatenated name in DNS wire format
function concatenateName(
bytes memory label,
bytes memory name
) internal pure returns (bytes memory) {
function concatenateName(bytes memory label, bytes memory name) internal pure returns (bytes memory) {
if (!isValidLabel(label)) revert InvalidLabel();
if (!isValidDomain(name)) revert InvalidDomain();

Expand All @@ -84,9 +81,7 @@ library DNSEncoder {
/// @notice Encodes a domain name from an array of labels
/// @param labels Array of labels in reverse order (TLD first)
/// @return bytes The encoded domain name in DNS wire format
function encodeName(
string[] memory labels
) internal pure returns (bytes memory) {
function encodeName(string[] memory labels) internal pure returns (bytes memory) {
bytes memory result = abi.encodePacked(ZERO_LENGTH);

for (uint256 i = 0; i < labels.length; i++) {
Expand All @@ -102,9 +97,7 @@ library DNSEncoder {
/// @notice Decodes a DNS wire format name into its labels
/// @param name The encoded domain name
/// @return labels Array of decoded labels
function decodeName(
bytes memory name
) internal pure returns (string[] memory labels) {
function decodeName(bytes memory name) internal pure returns (string[] memory labels) {
if (!isValidDomain(name)) revert InvalidDomain();

// Count labels first
Expand Down Expand Up @@ -143,9 +136,11 @@ library DNSEncoder {
function _isValidLabelChar(bytes1 ch) private pure returns (bool) {
// Letters, digits, and hyphens only
// ASCII: 0-9, A-Z, a-z, -
return ((ch >= 0x30 && ch <= 0x39) || // 0-9
(ch >= 0x41 && ch <= 0x5A) || // A-Z
(ch >= 0x61 && ch <= 0x7A) || // a-z
ch == 0x2D); // hyphen
return (
(ch >= 0x30 && ch <= 0x39) // 0-9
|| (ch >= 0x41 && ch <= 0x5A) // A-Z
|| (ch >= 0x61 && ch <= 0x7A) // a-z
|| ch == 0x2D
); // hyphen
}
}
Loading

0 comments on commit 859828b

Please sign in to comment.