Skip to content
Verified contractExactMIT

OnFiberResolver

Address0xab521efcbead77cfe669d7554609a8b5257e4074
Balance

0 ETH

 

Transactions

1

 

Compiler

solc 0.8.30

 

Same code

Only this contract

 

Details

Compiler
solc 0.8.30+commit.73712a01
Language
solidity
Optimization
Yes, 200 runs
EVM version
cancun
License
MIT
Match
Exactcreation code: yes, runtime code: yes
Verified on Sourcify
Created in block
26,350,019
Creation transaction
0x72a56888d3…889e33cd22

src/OnFiberResolver.sol

// SPDX-License-Identifier: MIT
pragma solidity ^0.8.24;

/// @notice ENSIP-10 wildcard resolver for *.onfiber.eth, answered offchain through ERC-3668.
/// @dev The contract cannot check that an address belongs to a name: a trusted signer can point any
/// name at any address until the owner removes it. Answers expire so removal takes effect quickly.
contract OnFiberResolver {
    error OffchainLookup(
        address sender, string[] urls, bytes callData, bytes4 callbackFunction, bytes extraData
    );
    error NotOwner();
    error NotPendingOwner();
    error InvalidAddress();
    error NoUrls();
    error AnswerExpired();
    error InvalidSignature();
    error UntrustedSigner();

    event SignerUpdated(address indexed signer, bool trusted);
    event UrlsUpdated(string[] urls);
    event OwnershipTransferStarted(address indexed owner, address indexed pendingOwner);
    event OwnershipTransferred(address indexed previousOwner, address indexed owner);

    bytes4 private constant ERC165_INTERFACE_ID = 0x01ffc9a7;
    bytes4 private constant ENSIP10_INTERFACE_ID = 0x9061b923;
    // Half the secp256k1 order: higher s values are the malleable twin of a valid signature.
    uint256 private constant MAX_SIGNATURE_S =
        0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF5D576E7357A4501DDFE92F46681B20A0;

    address public owner;
    address public pendingOwner;
    mapping(address signer => bool trusted) public signers;
    string[] private gatewayUrls;

    modifier onlyOwner() {
        if (msg.sender != owner) revert NotOwner();
        _;
    }

    /// @param initialOwner Account that manages signers and gateway urls.
    /// @param initialSigner Key the gateway signs answers with.
    /// @param initialUrls Gateway urls without {data}, so clients POST and names stay out of url logs.
    constructor(address initialOwner, address initialSigner, string[] memory initialUrls) {
        if (initialOwner == address(0)) revert InvalidAddress();
        owner = initialOwner;
        emit OwnershipTransferred(address(0), initialOwner);
        _setSigner(initialSigner, true);
        _setUrls(initialUrls);
    }

    /// @notice Sends every lookup to the gateway; the signed answer returns through resolveWithProof.
    function resolve(bytes calldata, bytes calldata) external view returns (bytes memory) {
        revert OffchainLookup(
            address(this), gatewayUrls, msg.data, this.resolveWithProof.selector, msg.data
        );
    }

    /// @notice Returns a gateway answer once its expiry and signature check out.
    /// @param response abi.encode(bytes result, uint64 expires, bytes signature).
    /// @param extraData The original resolve calldata, which binds the answer to that one question.
    function resolveWithProof(bytes calldata response, bytes calldata extraData)
        external
        view
        returns (bytes memory)
    {
        (bytes memory result, uint64 expires, bytes memory signature) =
            abi.decode(response, (bytes, uint64, bytes));
        if (expires < block.timestamp) revert AnswerExpired();

        bytes32 answerHash = keccak256(
            abi.encodePacked(
                hex"1900", address(this), expires, keccak256(extraData), keccak256(result)
            )
        );
        if (!signers[_recover(answerHash, signature)]) revert UntrustedSigner();
        return result;
    }

    function supportsInterface(bytes4 interfaceId) external pure returns (bool) {
        return interfaceId == ERC165_INTERFACE_ID || interfaceId == ENSIP10_INTERFACE_ID;
    }

    function urls() external view returns (string[] memory) {
        return gatewayUrls;
    }

    function setSigner(address signer, bool trusted) external onlyOwner {
        _setSigner(signer, trusted);
    }

    function setUrls(string[] calldata newUrls) external onlyOwner {
        _setUrls(newUrls);
    }

    /// @notice Starts a two-step handover so a mistyped address cannot strand signer rotation.
    function transferOwnership(address newOwner) external onlyOwner {
        pendingOwner = newOwner;
        emit OwnershipTransferStarted(owner, newOwner);
    }

    function acceptOwnership() external {
        if (msg.sender != pendingOwner) revert NotPendingOwner();
        emit OwnershipTransferred(owner, msg.sender);
        owner = msg.sender;
        pendingOwner = address(0);
    }

    function _setSigner(address signer, bool trusted) private {
        if (signer == address(0)) revert InvalidAddress();
        signers[signer] = trusted;
        emit SignerUpdated(signer, trusted);
    }

    function _setUrls(string[] memory newUrls) private {
        if (newUrls.length == 0) revert NoUrls();
        gatewayUrls = newUrls;
        emit UrlsUpdated(newUrls);
    }

    function _recover(bytes32 digest, bytes memory signature) private pure returns (address) {
        if (signature.length != 65) revert InvalidSignature();
        bytes32 r;
        bytes32 s;
        uint8 v;
        assembly ("memory-safe") {
            r := mload(add(signature, 0x20))
            s := mload(add(signature, 0x40))
            v := byte(0, mload(add(signature, 0x60)))
        }
        if (uint256(s) > MAX_SIGNATURE_S || (v != 27 && v != 28)) revert InvalidSignature();
        address signer = ecrecover(digest, v, r, s);
        if (signer == address(0)) revert InvalidSignature();
        return signer;
    }
}
Compiler settingsShow
{
  "viaIR": false,
  "metadata": {
    "appendCBOR": true,
    "bytecodeHash": "ipfs",
    "useLiteralContent": false
  },
  "optimizer": {
    "runs": 200,
    "enabled": true
  },
  "evmVersion": "cancun"
}

Source code and metadata: Sourcify.

The source code belongs to the authors of the contract.