Verified contractPartialMIT
NWBulkRegistrar
Address0xe887aab539ab3f54f7b5db29cbdec1378eb307fa
- Balance
0 ETH
- Transactions
754
- Compiler
solc 0.8.26
- Same code
Only this contract
Details
- Compiler
- solc 0.8.26+commit.8a97fa7a
- Language
- solidity
- Optimization
- Yes, 200 runs
- EVM version
- cancun
- Via IR
- yes
- License
- MIT
- Match
- Partialcreation code: yes, runtime code: yes
- Verified on Sourcify
- Created in block
- 25,652,329
- Creation transaction
- 0xc48794b5b5…8d6c8428e9
src/NWBulkRegistrar.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.26;
interface IPriceOracle {
struct Price {
uint256 base;
uint256 premium;
}
}
/// @notice The NameHash UnwrappedEthRegistrarController (referral controller).
/// Mainnet: 0x59e16fccd424cc24e280be16e11bcd56fb0ce547
/// Sepolia: 0xfb3ce5d01e0f33f41dbb39035db9745962f1f968
interface IUnwrappedEthRegistrarController {
struct Registration {
string label;
address owner;
uint256 duration;
bytes32 secret;
address resolver;
bytes[] data;
uint8 reverseRecord;
bytes32 referrer;
}
function rentPrice(string memory label, uint256 duration)
external
view
returns (IPriceOracle.Price memory price);
function makeCommitment(Registration memory registration) external pure returns (bytes32);
function commit(bytes32 commitment) external;
function register(Registration memory registration) external payable;
function available(string memory label) external view returns (bool);
}
interface IENS {
function owner(bytes32 node) external view returns (address);
}
interface IReverseRegistrar {
function setName(string memory name) external returns (bytes32);
}
/**
* NWBulkRegistrar — Bulk-register direct .eth subnames in one transaction
* with ENS Referral Program attribution + an optional immutable interface fee.
*
* Wraps NameHash's UnwrappedEthRegistrarController (the referral-aware ENS
* controller). Lets a user commit to N names in 1 tx and register all N in
* 1 tx — total 2 signatures, instead of the 1 + N signatures the controller
* forces when called directly.
*
* ── DESIGN INVARIANTS ──────────────────────────────────────────────
*
* 1. ALL config is IMMUTABLE: CONTROLLER, REFERRER, FEE_RECEIVER, FEE_BPS.
* There are no setters. To change anything, deploy a new contract.
*
* 2. No owner, no admin, no pause, no upgrade proxy, no delegatecall,
* no selfdestruct.
*
* 3. REFERRER is baked in at deploy. Every multiRegister call credits
* this address per the ENS Referral Program. Callers cannot redirect
* the referral credit elsewhere — that's the whole point of this
* contract being single-tenant.
*
* 4. The interface fee is FIXED at deploy. multiRegister takes no fee
* parameter — every call pays FEE_BPS to FEE_RECEIVER. Fee is computed
* on `totalForwarded` — the explicit sum sent to CONTROLLER inside the
* register loop, NOT the balance delta. This closes a fee-bypass vector
* where a malicious user-supplied resolver could force-send ETH into
* the wrapper during the controller's resolver callback (e.g. via
* selfdestruct), inflating address(this).balance and shrinking a
* balance-based fee. Forced ETH still gets refunded to msg.sender (or
* stranded if injected pre-call) so the attacker gains nothing.
*
* 5. Per-name failure reverts the batch (no try/catch). Frontend should
* pre-flight `available()` checks before submitting.
*
* 6. Exact-price forwarding to register(): we read rentPrice() in the
* same tx as the register call, so no oracle drift can occur and the
* controller never tries to refund. Defense-in-depth: receive() ONLY
* accepts ETH from CONTROLLER (in case of a controller-side rounding
* refund); direct sends from anyone else revert.
*
* 7. Refund of the user's overpayment goes back to msg.sender — reverts
* on failure so funds can never strand from a normal call.
*
* 8. Single secret per batch (Grails pattern). Each commitment is still
* unique because it includes the label; the secret only needs to be
* unique per (label, owner, duration, ...) tuple to prevent
* front-running, and a per-batch fresh-random secret achieves that.
*
* ── BLAST RADIUS ───────────────────────────────────────────────────
*
* User principal flows through this contract twice:
* • multiCommit: zero ETH movement (commit() is non-payable).
* • multiRegister: msg.value forwarded per name to CONTROLLER → leftover
* refunded to msg.sender.
*
* Worst-case outcomes:
* • Per-name register reverts → entire batch reverts; commit slot stays
* reserved for ~24h, user retries with fewer names.
* • A bug in fee math could overcharge the user — capped at MAX_FEE_BPS (10%).
* • CONTROLLER going down would brick this contract — but it's the
* NameHash referral-program controller, live and audited.
*/
contract NWBulkRegistrar {
/// @notice The NameHash UnwrappedEthRegistrarController. Source of truth
/// for pricing AND target for both commit() and register() forwarding.
IUnwrappedEthRegistrarController public immutable CONTROLLER;
/// @notice 32-byte referrer ID per ENS Referral Program spec
/// (12 zero bytes + 20-byte referrer address). Hardcoded at deploy.
bytes32 public immutable REFERRER;
/// @notice Immutable destination for the optional interface fee.
/// address(0) permanently disables the fee even if FEE_BPS > 0
/// (constructor enforces the inverse: if FEE_BPS > 0, FEE_RECEIVER must be set).
address public immutable FEE_RECEIVER;
/// @notice Interface fee in basis points. Immutable at deploy. 100 = 1%, 0 = no fee.
uint256 public immutable FEE_BPS;
/// @notice Hard cap on the interface fee, in basis points (10%).
uint256 public constant MAX_FEE_BPS = 1000;
/// @dev Reentrancy guard. 1 = not entered, 2 = entered. Initialized to 1 so
/// first-call SSTORE is warm (cheaper). Defends against a malicious or
/// callback-capable FEE_RECEIVER reentering multiRegister during the fee
/// transfer to drain a pending refund.
uint256 private _entered = 1;
/// @notice Emitted once per batch when a non-zero fee is paid.
event FeePaid(address indexed payer, uint256 ensSpent, uint256 fee);
/// @notice Emitted at deploy with the immutable config — useful for
/// off-chain indexers verifying contract setup without ABI calls.
event Configured(address indexed controller, bytes32 referrer, address feeReceiver, uint256 feeBps);
error ArrayLengthMismatch();
error EmptyBatch();
error FeeTooHigh();
error TransferFailed();
error ZeroAddress();
error FeeReceiverRequired();
error DirectEthNotAccepted();
error ReentrancyDetected();
error InsufficientValue();
modifier nonReentrant() {
if (_entered == 2) revert ReentrancyDetected();
_entered = 2;
_;
_entered = 1;
}
constructor(
IUnwrappedEthRegistrarController _controller,
bytes32 _referrer,
address _feeReceiver,
uint256 _feeBps,
IENS _ens,
string memory _ensName
) {
if (address(_controller) == address(0)) revert ZeroAddress();
if (_feeBps > MAX_FEE_BPS) revert FeeTooHigh();
if (_feeBps > 0 && _feeReceiver == address(0)) revert FeeReceiverRequired();
CONTROLLER = _controller;
REFERRER = _referrer;
FEE_RECEIVER = _feeReceiver;
FEE_BPS = _feeBps;
emit Configured(address(_controller), _referrer, _feeReceiver, _feeBps);
// Self-claim our reverse ENS record and set the name. The ReverseRegistrar
// address is fetched from the ENS registry (network-agnostic). namehash
// of "addr.reverse" is the same on every ENS deployment.
if (address(_ens) != address(0) && bytes(_ensName).length > 0) {
address rr = _ens.owner(0x91d1777781884d03a6757a803996e38de2a42967fb37eeaca72729271025a9e2);
// slither-disable-next-line unused-return
IReverseRegistrar(rr).setName(_ensName);
}
}
// ─── View functions ─────────────────────────────────────────
/// @notice Per-name availability check via the controller.
function available(string[] calldata labels) external view returns (bool[] memory results) {
uint256 length = labels.length;
results = new bool[](length);
for (uint256 i = 0; i < length;) {
results[i] = CONTROLLER.available(labels[i]);
unchecked {
++i;
}
}
}
/// @notice Sum of `base + premium` across the batch. Does NOT include
/// the interface fee — use `bulkQuote()` for the full cost the user must send.
function bulkRentPrice(string[] calldata labels, uint256[] calldata durations)
external
view
returns (uint256 total)
{
return _sumPrices(labels, durations);
}
/// @notice Full quote: ENS protocol cost, interface fee, and grand total.
/// Send `total` (or slightly above for safety buffer) as the `value` to multiRegister.
function bulkQuote(string[] calldata labels, uint256[] calldata durations)
external
view
returns (uint256 ensCost, uint256 fee, uint256 total)
{
ensCost = _sumPrices(labels, durations);
fee = (ensCost * FEE_BPS) / 10000;
total = ensCost + fee;
}
/// @dev Internal price summation. `unchecked` is safe: ENS prices are bounded
/// (max ~0.1 ETH per name pre-premium), batch size is gas-bounded, so total
/// can never approach uint256 overflow. Saves real gas in the loop.
function _sumPrices(string[] calldata labels, uint256[] calldata durations)
internal
view
returns (uint256 total)
{
uint256 length = labels.length;
if (length != durations.length) revert ArrayLengthMismatch();
for (uint256 i = 0; i < length;) {
IPriceOracle.Price memory price = CONTROLLER.rentPrice(labels[i], durations[i]);
unchecked {
total += price.base + price.premium;
++i;
}
}
}
/// @notice Compute commitment hashes for the batch via the controller's
/// makeCommitment view function. Returned array is byte-identical to what
/// multiRegister will compute internally — pass it to multiCommit.
/// @dev `reverseRecord` is deliberately omitted: the upstream controller
/// sets reverse records for `msg.sender`, which through this wrapper would
/// be the wrapper itself (not the registrant). To set their primary name,
/// the user must call the ReverseRegistrar directly after registration.
function makeCommitments(
string[] calldata labels,
address owner,
uint256[] calldata durations,
bytes32 secret,
address resolver,
bytes[][] calldata data
) external view returns (bytes32[] memory commitments) {
uint256 length = labels.length;
if (length != durations.length || length != data.length) revert ArrayLengthMismatch();
IUnwrappedEthRegistrarController.Registration memory reg;
reg.owner = owner;
reg.secret = secret;
reg.resolver = resolver;
reg.reverseRecord = 0;
reg.referrer = REFERRER;
commitments = new bytes32[](length);
for (uint256 i = 0; i < length;) {
reg.label = labels[i];
reg.duration = durations[i];
reg.data = data[i];
commitments[i] = CONTROLLER.makeCommitment(reg);
unchecked {
++i;
}
}
}
// ─── State-changing functions ───────────────────────────────
/// @notice Submit an array of pre-computed commitment hashes in a single tx.
/// commit() is non-payable on the controller, so no value is required.
/// @dev `nonReentrant` is overkill for this function (no ETH movement, no
/// external callbacks back into us), but applied for symmetry and
/// defense-in-depth in case future controller upgrades change behavior.
function multiCommit(bytes32[] calldata commitments) external nonReentrant {
uint256 length = commitments.length;
if (length == 0) revert EmptyBatch();
for (uint256 i = 0; i < length;) {
CONTROLLER.commit(commitments[i]);
unchecked {
++i;
}
}
}
/// @notice Bulk register direct .eth subnames in a single tx. All names
/// share the same secret, owner, and resolver; durations and resolver-init
/// data[] are per-name. `reverseRecord` is hardcoded to 0 — see makeCommitments.
/// @param labels .eth subname labels (no ".eth" suffix).
/// @param owner Address that will own all registered names.
/// @param durations Per-name registration duration in seconds.
/// @param secret Single random secret used for all commitments + registers.
/// @param resolver Resolver address all names will point to (typically PublicResolver 3).
/// @param data Per-name resolver-init multicall payload (e.g. setAddr).
/// Pass `[[]]` to skip record initialisation.
/// @dev Sends EXACT price.base + price.premium per name, read in-tx, so no
/// controller-side refund is triggered. Fee is computed against the
/// ACCUMULATED amount we forwarded to the controller (`totalForwarded`),
/// NOT against `address(this).balance` delta — this matters because a
/// malicious user-supplied resolver could force-send ETH into this
/// contract during the controller's resolver callback (e.g. via
/// `selfdestruct`), bypassing our receive() guard. Using totalForwarded
/// makes the fee resistant to this. Any forced ETH simply gets included
/// in the refund back to msg.sender.
function multiRegister(
string[] calldata labels,
address owner,
uint256[] calldata durations,
bytes32 secret,
address resolver,
bytes[][] calldata data
) external payable nonReentrant {
uint256 length = labels.length;
if (length == 0) revert EmptyBatch();
if (length != durations.length || length != data.length) revert ArrayLengthMismatch();
// baseline excluding this call's incoming ETH — used for refund accounting
uint256 balanceBefore = address(this).balance - msg.value;
uint256 totalForwarded = _runRegisterLoop(labels, owner, durations, secret, resolver, data);
_settleAfterBatch(balanceBefore, totalForwarded);
}
/// @dev Extracted to avoid stack-too-deep in multiRegister. Reads price
/// in-tx and forwards EXACT cost to the controller so no refund is triggered.
/// Reverts the whole batch on insufficient value or per-name failure.
/// Builds the Registration struct ONCE in memory and mutates label/duration/data
/// per iteration — keeps stack pressure low without ABI changes.
/// Returns the SUM of cost forwarded — the only safe basis for the interface
/// fee, immune to forced-ETH inflation of address(this).balance.
function _runRegisterLoop(
string[] calldata labels,
address owner,
uint256[] calldata durations,
bytes32 secret,
address resolver,
bytes[][] calldata data
) internal returns (uint256 totalForwarded) {
IUnwrappedEthRegistrarController.Registration memory reg;
reg.owner = owner;
reg.secret = secret;
reg.resolver = resolver;
reg.reverseRecord = 0; // see makeCommitments docstring
reg.referrer = REFERRER;
uint256 length = labels.length;
for (uint256 i = 0; i < length;) {
reg.label = labels[i];
reg.duration = durations[i];
reg.data = data[i];
IPriceOracle.Price memory price = CONTROLLER.rentPrice(labels[i], durations[i]);
uint256 cost = price.base + price.premium;
CONTROLLER.register{value: cost}(reg);
unchecked {
totalForwarded += cost;
++i;
}
}
}
/// @dev Take fee (if configured) on the explicit totalForwarded — NOT on
/// balance delta — then refund any leftover ETH to msg.sender. Using the
/// explicit sum closes a fee-bypass vector where a malicious user-supplied
/// resolver force-sends ETH during the controller's resolver callback,
/// inflating address(this).balance and shrinking a balance-based fee
/// computation. The forced ETH is still returned to msg.sender via the
/// refund (so attackers gain nothing by force-sending).
function _settleAfterBatch(uint256 balanceBefore, uint256 totalForwarded) internal {
if (totalForwarded > msg.value) revert InsufficientValue();
if (FEE_BPS > 0 && FEE_RECEIVER != address(0)) {
uint256 fee = (totalForwarded * FEE_BPS) / 10000;
if (fee > 0) {
// The fee must be funded by msg.value, never by ETH already in
// the contract (forced sends / controller refunds). Checking
// against msg.value also surfaces underpayment as
// InsufficientValue instead of an opaque TransferFailed from
// the fee call below.
if (totalForwarded + fee > msg.value) revert InsufficientValue();
emit FeePaid(msg.sender, totalForwarded, fee);
(bool feeSent,) = FEE_RECEIVER.call{value: fee}("");
if (!feeSent) revert TransferFailed();
}
}
// Refund leftover ETH to msg.sender. Reverts on failure so funds can
// never strand here from a normal call. Includes any ETH force-sent
// into us during the loop (controller refund or attacker selfdestruct).
// slither-disable-next-line arbitrary-send-eth
uint256 remaining = address(this).balance - balanceBefore;
if (remaining > 0) {
(bool refundSent,) = msg.sender.call{value: remaining}("");
if (!refundSent) revert TransferFailed();
}
}
/// @notice Only accept ETH from CONTROLLER (refund of any rounding excess).
/// Direct ETH sends from anyone else are rejected so users cannot
/// accidentally strand funds in the contract.
receive() external payable {
if (msg.sender != address(CONTROLLER)) revert DirectEthNotAccepted();
}
}
Compiler settingsShow
{
"viaIR": true,
"metadata": {
"appendCBOR": false,
"bytecodeHash": "none",
"useLiteralContent": false
},
"optimizer": {
"runs": 200,
"enabled": true
},
"evmVersion": "cancun",
"remappings": [
"@openzeppelin/contracts/=lib/openzeppelin-contracts/contracts/",
"@ensdomains/ens-contracts/=lib/ens-contracts/",
"forge-std/=lib/forge-std/src/",
"ens-contracts/=lib/ens-contracts/contracts/",
"erc4626-tests/=lib/openzeppelin-contracts/lib/erc4626-tests/",
"halmos-cheatcodes/=lib/openzeppelin-contracts/lib/halmos-cheatcodes/src/",
"openzeppelin-contracts/=lib/openzeppelin-contracts/"
]
}Source code and metadata: Sourcify.
The source code belongs to the authors of the contract.