Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 33 additions & 2 deletions contracts/ethregistrar/BaseRegistrarImplementation.sol
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ interface ISubnameHook {
/// @dev INVARIANT (ERC721Enumerable): enumeration (`totalSupply`,
/// `tokenByIndex`, `balanceOf`, `tokenOfOwnerByIndex`) is maintained on
/// transfer/mint/burn, NOT on expiry — a name is only burned when it is
/// re-registered after its grace period. So enumeration includes
/// re-registered after its grace period or its unregistration.
/// So enumeration includes
/// expired-but-unburned names and can disagree with the grace-period
/// `ownerOf` (which reverts once expired). Readers MUST filter by
/// `nameExpires(id) > block.timestamp` to get the live set.
Expand Down Expand Up @@ -60,9 +61,13 @@ contract BaseRegistrarImplementation is
event MaxLabelLengthChanged(uint256 maxLabelLength);
event SubnameHookChanged(address indexed hook);
event NamePolicyChanged(address indexed namePolicy);
event NameUnregistered(uint256 indexed id);

error LabelTooLong(uint256 length, uint256 max);
error NamePolicyMismatch();
error DisputePeriodOver(uint256 id);
error DisputePeriodNotOver(uint256 id);
error DisputeUntilMismatch(uint256 named, uint256 current);

/// v2.1.3 version of _isApprovedOrOwner which calls ownerOf(tokenId) and takes grace period into consideration instead of ERC721.ownerOf(tokenId);
/// https://github.com/OpenZeppelin/openzeppelin-contracts/blob/v2.1.3/contracts/token/ERC721/ERC721.sol#L187
Expand Down Expand Up @@ -164,14 +169,18 @@ contract BaseRegistrarImplementation is
function registerWithLabel(
string calldata label,
address owner,
uint256 duration
uint256 duration,
uint256 disputePeriod
) external returns (uint256) {
if (maxLabelLength != 0 && bytes(label).length > maxLabelLength)
revert LabelTooLong(bytes(label).length, maxLabelLength);
uint256 id = uint256(keccak256(bytes(label)));
if (bytes(labelOf[id]).length == 0) {
labelOf[id] = label;
}
disputeUntil[id] = disputePeriod == 0
? 0
: block.timestamp + disputePeriod;
return _register(id, owner, duration);
}

Expand Down Expand Up @@ -223,6 +232,7 @@ contract BaseRegistrarImplementation is
uint256 id,
uint256 duration
) external override live onlyController returns (uint256) {
if (block.timestamp < disputeUntil[id]) revert DisputePeriodNotOver(id);
require(expiries[id] + GRACE_PERIOD >= block.timestamp); // Name must be registered here or in grace period
require(
expiries[id] + duration + GRACE_PERIOD > duration + GRACE_PERIOD
Expand All @@ -239,6 +249,25 @@ contract BaseRegistrarImplementation is
return expiries[id];
}

function unregister(
uint256 id,
uint256 until
) external live onlyController {
if (disputeUntil[id] != until)
revert DisputeUntilMismatch(until, disputeUntil[id]);
if (block.timestamp >= disputeUntil[id]) revert DisputePeriodOver(id);
delete disputeUntil[id];
expiries[id] = 0;
ens.setSubnodeRecord(baseNode, bytes32(id), address(0), address(0), 0);
if (subnameHook != address(0)) {
ISubnameHook(subnameHook).onExpiryChanged(
keccak256(abi.encodePacked(baseNode, bytes32(id))),
0
);
}
emit NameUnregistered(id);
}

/// @dev Reclaim ownership of a name in ENS, if you own it in the registrar.
function reclaim(uint256 id, address owner) external override live {
require(_isApprovedOrOwner(msg.sender, id));
Expand Down Expand Up @@ -343,6 +372,8 @@ contract BaseRegistrarImplementation is
/// `approve`, so a claim signature is valid for one offer and no later one.
mapping(uint256 => uint256) public offers;

mapping(uint256 => uint256) public disputeUntil;

/// @dev ERC-5564 `Announcement`, verbatim in name, parameter list and
/// indexing, so any indexer that knows the standard decodes ours by
/// topic without special-casing. It carries the sender's ephemeral
Expand Down
30 changes: 24 additions & 6 deletions contracts/simplex/SimplexController.sol
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ contract SimplexController is
uint256 public constant MIN_RENEWAL_DURATION = 365 days;
uint256 public constant MAX_REGISTRATION_DURATION = MAX_REGISTRATION;
uint256 public constant MAX_SPONSORED_REGISTRATION_DURATION = MAX_SPONSORED_REGISTRATION;
uint256 public constant MIN_DISPUTE_DAYS = 14;
uint256 public constant MAX_DISPUTE_DAYS = 120;

// Manual reentrancy guard (see `_reentrancyStatus` + `nonReentrant`).
// Implemented by hand rather than inheriting ReentrancyGuardUpgradeable so
Expand Down Expand Up @@ -124,6 +126,7 @@ contract SimplexController is
error PublicSalesClosed();
error OwnerMustBeCaller();
error NotSponsor();
error DisputeDaysOutOfRange(uint256 disputeDays);

event NameRegistered(
string label,
Expand Down Expand Up @@ -424,7 +427,7 @@ contract SimplexController is
uint256 totalPrice = price.base + price.premium;
if (msg.value < totalPrice) revert InsufficientValue();

_registerCore(registration, labelhash, price);
_registerCore(registration, labelhash, price, 0);

if (msg.value > totalPrice) {
(bool ok, ) = payable(msg.sender).call{value: msg.value - totalPrice}("");
Expand All @@ -436,27 +439,31 @@ contract SimplexController is
/// The fee would have gone to the controller and been withdrawn back
/// to the same treasury, so it is removed rather than performed.
function registerSponsored(
Registration calldata registration
Registration calldata registration,
uint256 disputeDays
) external onlySponsor nonReentrant {
bytes32 labelhash = keccak256(bytes(registration.label));
if (registration.duration > _sponsoredHorizon(labelhash))
revert DurationTooLong(registration.duration);
if (disputeDays < MIN_DISPUTE_DAYS || disputeDays > MAX_DISPUTE_DAYS)
revert DisputeDaysOutOfRange(disputeDays);
_checkSimplexGates(registration.label, false);

// Zero cost in the event, and no `_rentPrice` call: nothing is paid on
// this path, so the wei figure would be a quote rather than a payment —
// and reading it would couple the sponsored flow to the ETH/USD feed,
// which is the one dependency this path exists without. What was
// actually consumed is in the sponsor's `RegistrarAllowanceSpent`, in attoUSD.
_registerCore(registration, labelhash, IPriceOracle.Price(0, 0));
_registerCore(registration, labelhash, IPriceOracle.Price(0, 0), disputeDays * 1 days);
}

/// @dev Everything both registration paths share: availability, the
/// commit/reveal window, the mint and the records.
function _registerCore(
Registration calldata registration,
bytes32 labelhash,
IPriceOracle.Price memory price
IPriceOracle.Price memory price,
uint256 disputePeriod
) private returns (uint256 expires) {
if (!_available(registration.label, labelhash))
revert NameNotAvailable(registration.label);
Expand Down Expand Up @@ -500,13 +507,15 @@ contract SimplexController is
expires = base.registerWithLabel(
registration.label,
registration.owner,
registration.duration
registration.duration,
disputePeriod
);
} else {
expires = base.registerWithLabel(
registration.label,
address(this),
registration.duration
registration.duration,
disputePeriod
);

ens.setRecord(
Expand Down Expand Up @@ -592,6 +601,15 @@ contract SimplexController is
emit NameRenewed(label, labelhash, cost, expires, referrer);
}

function unregister(string calldata label, uint256 until) external onlyOwnerOrBeneficiary {
bytes32 labelhash = keccak256(bytes(label));
bytes32 node = keccak256(abi.encodePacked(tldNode, labelhash));
_retireStaleRecords(node);
address resolver = defaultResolver;
if (resolver != address(0)) IClearableResolver(resolver).clearRecords(node);
base.unregister(uint256(labelhash), until);
}

/// @notice Pays the beneficiary, never `owner()`, so revenue is independent of
/// the admin key. Permissionless to call.
function withdraw() public nonReentrant {
Expand Down
2 changes: 1 addition & 1 deletion contracts/simplex/SimplexNamePolicy.sol
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ contract SimplexNamePolicy is INamePolicy {
emit ReservedNameRemoved(label);

bytes32 namehash = keccak256(abi.encodePacked(_tldNode, labelhash));
registrar.registerWithLabel(label, address(this), duration);
registrar.registerWithLabel(label, address(this), duration, 0);
_retireStaleRecords(namehash);
address resolver = controller.defaultResolver();
if (resolver != address(0))
Expand Down
11 changes: 7 additions & 4 deletions contracts/simplex/SimplexSponsor.sol
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ contract SimplexSponsor {
bytes32 private constant _EIP712_VERSION = keccak256("1");
bytes32 public constant REGISTER_TYPEHASH =
keccak256(
"RegisterName(string label,address owner,uint256 duration,address resolver,bytes[] data,uint256 nonce,uint256 deadline)"
"RegisterName(string label,address owner,uint256 duration,address resolver,bytes[] data,uint256 disputeDays,uint256 nonce,uint256 deadline)"
);

SimplexController public immutable controller;
Expand Down Expand Up @@ -67,22 +67,23 @@ contract SimplexSponsor {
/// @notice Register with no value attached, spending the name's list price
/// from the caller's allowance.
/// @param sig The owner's EIP-712 `RegisterName` signature, which covers the
/// label, the duration, the resolver and `data`, not the secret or referrer.
/// label, the duration, the resolver, `data` and `disputeDays`, not the secret or referrer.
/// Not checked when the owner is the caller.
function registerWithCredit(
IETHRegistrarController.Registration calldata registration,
uint256 disputeDays,
uint256 nonce,
uint256 deadline,
bytes calldata sig
) external {
if (registration.owner != msg.sender)
_consumeIntent(registration, nonce, deadline, sig);
_consumeIntent(registration, disputeDays, nonce, deadline, sig);
IPriceOracle.Price memory usd = controller.rentPriceUSD(
registration.label,
registration.duration
);
_spendAllowance(usd.base + usd.premium);
controller.registerSponsored(registration);
controller.registerSponsored(registration, disputeDays);
}

/// @notice Renew with no value attached, spending the name's list price
Expand Down Expand Up @@ -130,6 +131,7 @@ contract SimplexSponsor {
/// @dev Verify the owner's signature, then spend the nonce.
function _consumeIntent(
IETHRegistrarController.Registration calldata registration,
uint256 disputeDays,
uint256 nonce,
uint256 deadline,
bytes calldata sig
Expand All @@ -153,6 +155,7 @@ contract SimplexSponsor {
registration.duration,
registration.resolver,
keccak256(abi.encodePacked(dataHashes)),
disputeDays,
nonce,
deadline
)
Expand Down
3 changes: 2 additions & 1 deletion contracts/simplex/SubnameRegistrar.sol
Original file line number Diff line number Diff line change
Expand Up @@ -402,7 +402,8 @@ contract SubnameRegistrar is ISubnameRegistrar {
}

/// @notice Called by BaseRegistrar whenever 2LD `node`'s expiry moves
/// (registration or renewal), so subname authority can follow the
/// (registration, renewal or unregistration), so subname
/// authority can follow the
/// registration rather than the registry record it outlives.
function onExpiryChanged(bytes32 node, uint256 expiry) external {
if (msg.sender != baseRegistrar) revert NotBaseRegistrar();
Expand Down
2 changes: 1 addition & 1 deletion docs/upgrades.md
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ declaration order, so reordering them swaps the two lists; keep them unchanged
| `ENSRegistry` | `SimplexResolver` | `owner` |
| `ENSRegistry` | `Root` | `setSubnodeOwner`, `setResolver` |
| `ENSRegistry` | `UniversalResolver` | `resolver` |
| `BaseRegistrarImplementation` | `SimplexController` | `available`, `nameExpires`, `registerWithLabel`, `renew`, `transferFrom` |
| `BaseRegistrarImplementation` | `SimplexController` | `available`, `nameExpires`, `registerWithLabel`, `renew`, `transferFrom`, `unregister` |
| `BaseRegistrarImplementation` | `SimplexNamePolicy` | `available`, `registerWithLabel`, `transferFrom` |
| `SimplexController` | `SimplexNamePolicy` | `owner`, `beneficiary`, `defaultResolver`, `wasDefaultResolver`, `commitments`, `maxCommitmentAge`, `commit`; `ens` and `tldNode` in its constructor |
| `SimplexController` | `SimplexSponsor` | `beneficiary`, `rentPriceUSD`, `registerSponsored`, `renewSponsored` |
Expand Down
10 changes: 5 additions & 5 deletions test/ethregistrar/TestBaseRegistrar.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ const loadFixture = async () => connection.networkHelpers.loadFixture(fixture)
async function fixtureWithRegistration() {
const existing = await loadFixture()
await existing.baseRegistrar.write.registerWithLabel(
['newname', registrantAccount.address, 86400n],
['newname', registrantAccount.address, 86400n, 0n],
{
account: controllerAccount,
},
Expand All @@ -47,7 +47,7 @@ describe('BaseRegistrar', () => {
const { ensRegistry, baseRegistrar } = await loadFixture()

const hash = await baseRegistrar.write.registerWithLabel(
['newname', registrantAccount.address, 86400n],
['newname', registrantAccount.address, 86400n, 0n],
{
account: controllerAccount,
},
Expand Down Expand Up @@ -87,7 +87,7 @@ describe('BaseRegistrar', () => {

await expect(
baseRegistrar.write.registerWithLabel(
['foo', otherAccount.address, 86400n],
['foo', otherAccount.address, 86400n, 0n],
{
account: otherAccount,
},
Expand All @@ -110,7 +110,7 @@ describe('BaseRegistrar', () => {

await expect(
baseRegistrar.write.registerWithLabel(
['newname', registrantAccount.address, 86400n],
['newname', registrantAccount.address, 86400n, 0n],
{
account: controllerAccount,
},
Expand Down Expand Up @@ -255,7 +255,7 @@ describe('BaseRegistrar', () => {
).toBeRevertedWithoutReason()

await baseRegistrar.write.registerWithLabel(
['newname', otherAccount.address, 86400n],
['newname', otherAccount.address, 86400n, 0n],
{
account: controllerAccount,
},
Expand Down
1 change: 1 addition & 0 deletions test/simplex/TestApproveClaimWithSig.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ async function fixture() {
'alicechat',
aliceAccount.address,
DURATION,
0n,
])
return { ensRegistry, baseRegistrar }
}
Expand Down
Loading