From 488e50d2f2e99f1e01955f94c7afb0e6e4640327 Mon Sep 17 00:00:00 2001 From: brenzi-agent <346870783+brenzi-agent@users.noreply.github.com> Date: Fri, 27 Nov 2026 10:22:29 +0000 Subject: [PATCH 1/8] ci: run the SimpleX tests on pushes of ab/one-step-claim --- .github/workflows/simplex.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/simplex.yml b/.github/workflows/simplex.yml index 2c881f09..04e6beae 100644 --- a/.github/workflows/simplex.yml +++ b/.github/workflows/simplex.yml @@ -2,7 +2,7 @@ name: SimpleX tests on: push: - branches: [simplex] + branches: [simplex, ab/one-step-claim] pull_request: branches: [simplex] From 2b6a44bdc0b4eea52139f1a68189db39b00510ea Mon Sep 17 00:00:00 2001 From: brenzi-agent <346870783+brenzi-agent@users.noreply.github.com> Date: Fri, 27 Nov 2026 10:25:07 +0000 Subject: [PATCH 2/8] test: the recipient accepts the terms and claims in one transaction --- contracts/mocks/ReentrantClaimer.sol | 54 +++ test/simplex/TestClaimUnderTerms.test.ts | 505 +++++++++++++++++++++++ 2 files changed, 559 insertions(+) create mode 100644 contracts/mocks/ReentrantClaimer.sol create mode 100644 test/simplex/TestClaimUnderTerms.test.ts diff --git a/contracts/mocks/ReentrantClaimer.sol b/contracts/mocks/ReentrantClaimer.sol new file mode 100644 index 00000000..ffd71f7d --- /dev/null +++ b/contracts/mocks/ReentrantClaimer.sol @@ -0,0 +1,54 @@ +//SPDX-License-Identifier: MIT +pragma solidity ~0.8.26; + +interface IClaimUnderTerms { + function approve(address to, uint256 tokenId) external; + + function claimUnderTerms( + address from, + uint256 tokenId, + uint256 offer, + bytes32 acceptedTermsHash + ) external; +} + +contract ReentrantClaimer { + IClaimUnderTerms public immutable registrar; + uint256 public reentries; + + constructor(IClaimUnderTerms registrar_) { + registrar = registrar_; + } + + function offer(address to, uint256 tokenId) external { + registrar.approve(to, tokenId); + } + + function claim( + address from, + uint256 tokenId, + uint256 offerNumber, + bytes32 termsHash + ) external { + registrar.claimUnderTerms(from, tokenId, offerNumber, termsHash); + } + + function onERC721Received( + address, + address from, + uint256 tokenId, + bytes calldata + ) external returns (bytes4) { + _reenter(from, tokenId); + return this.onERC721Received.selector; + } + + fallback() external { + _reenter(address(0), 0); + } + + function _reenter(address from, uint256 tokenId) private { + ++reentries; + registrar.claimUnderTerms(from, tokenId, 0, bytes32(0)); + } +} diff --git a/test/simplex/TestClaimUnderTerms.test.ts b/test/simplex/TestClaimUnderTerms.test.ts new file mode 100644 index 00000000..dc0ce832 --- /dev/null +++ b/test/simplex/TestClaimUnderTerms.test.ts @@ -0,0 +1,505 @@ +import hre from 'hardhat' +import { + getAddress, + keccak256, + labelhash, + parseEventLogs, + toHex, + zeroAddress, + zeroHash, +} from 'viem' +import { describe, expect, it } from 'vitest' + +import { + AMPLE_ALLOWANCE, + commitUnderGeneralTerms, + COMMUNITY_TERMS, + deployNamesV2, + GENERAL_TERMS, + MIN_REGISTRATION, + node, + registration, + signRegistration, + termsLink, + YEAR_PRICE_USD, +} from './fixtures/namesV2.js' +import { DAY } from '../fixtures/constants.js' + +const GRACE_PERIOD = 90n * DAY + +const connection = await hre.network.connect() +const publicClient = await connection.viem.getPublicClient() +const testClient = await connection.viem.getTestClient() +const [ + ownerClient, + guardianClient, + registrarClient, + aliceClient, + bobClient, + carolClient, +] = await connection.viem.getWalletClients() +const owner = ownerClient.account +const guardian = guardianClient.account +const registrar = registrarClient.account +const alice = aliceClient.account +const bob = bobClient.account +const carol = carolClient.account +type Account = typeof alice + +const KINDS = [ + { + title: 'general terms', + label: 'plainname', + terms: GENERAL_TERMS, + other: COMMUNITY_TERMS, + commit: 'commitUnderGeneralTerms', + acceptForClaim: 'acceptGeneralTermsForClaim', + setTerms: 'setGeneralTerms', + accepted: 'GeneralTermsAccepted', + }, + { + title: 'community terms', + label: 'community', + terms: COMMUNITY_TERMS, + other: GENERAL_TERMS, + commit: 'commitUnderCommunityTerms', + acceptForClaim: 'acceptCommunityTermsForClaim', + setTerms: 'setCommunityTerms', + accepted: 'CommunityTermsAccepted', + }, +] as const +type Kind = (typeof KINDS)[number] +const [GENERAL, COMMUNITY] = KINDS + +const id = (label: string) => BigInt(labelhash(label)) + +async function fixture() { + const f = await deployNamesV2(connection, { + owner: owner.address, + beneficiary: guardian.address, + }) + await f.sponsor.write.setRegistrarAllowance( + [registrar.address, AMPLE_ALLOWANCE], + { account: guardian }, + ) + await f.controller.write.setPublicSalesOpen([true], { account: owner }) + await f.namePolicy.write.addCommunityNames([[COMMUNITY.label]], { + account: guardian, + }) + for (const k of KINDS) { + const reg = registration(k.label, alice.address) + const namePolicy: any = f.namePolicy + await namePolicy.write[k.commit]( + [await f.controller.read.makeCommitment([reg]), k.terms], + { account: alice }, + ) + await f.controller.write.register([reg], { + account: alice, + value: 2n * YEAR_PRICE_USD, + }) + } + return f +} +const load = () => connection.networkHelpers.loadFixture(fixture) +type Fixture = Awaited> + +async function offerToBob(f: Fixture, label: string) { + await f.baseRegistrar.write.approve([bob.address, id(label)], { + account: alice, + }) + return f.baseRegistrar.read.offers([id(label)]) +} + +const claim = ( + f: Fixture, + label: string, + { + from = alice.address, + offer, + terms, + account = bob, + }: { + from?: `0x${string}` + offer: bigint + terms: `0x${string}` + account?: Account + }, +) => + f.baseRegistrar.write.claimUnderTerms([from, id(label), offer, terms], { + account, + }) + +const logsOf = async (hash: `0x${string}`) => + (await publicClient.waitForTransactionReceipt({ hash })).logs.map( + ({ address, topics, data }) => ({ address, topics, data }), + ) + +const acceptances = async (f: Fixture, k: Kind, hash: `0x${string}`) => + parseEventLogs({ + abi: f.namePolicy.abi, + eventName: k.accepted, + logs: (await publicClient.waitForTransactionReceipt({ hash })).logs, + }).map(({ args }) => [args.name, args.holder, args.termsHash]) + +const stateAfterClaim = (f: Fixture, label: string, offer: bigint) => + Promise.all([ + f.baseRegistrar.read.ownerOf([id(label)]), + f.baseRegistrar.read.getApproved([id(label)]), + f.baseRegistrar.read.offers([id(label)]), + f.baseRegistrar.read.balanceOf([alice.address]), + f.baseRegistrar.read.balanceOf([bob.address]), + f.baseRegistrar.read.nonces([bob.address]), + f.ens.read.owner([node(label)]), + f.namePolicy.read.acceptedClaimTerms([ + id(label), + alice.address, + bob.address, + offer, + ]), + f.namePolicy.read.nonces([bob.address]), + ]) + +describe('claimUnderTerms', () => { + for (const k of KINDS) { + describe(k.title, () => { + it('one transaction of the recipient leaves the state and the events of the acceptance and the claim', async () => { + const twoStep = await load() + const offer = await offerToBob(twoStep, k.label) + const namePolicy: any = twoStep.namePolicy + const accept = await namePolicy.write[k.acceptForClaim]( + [id(k.label), alice.address, offer, k.terms], + { account: bob }, + ) + const take = await twoStep.baseRegistrar.write.transferFrom( + [alice.address, bob.address, id(k.label)], + { account: bob }, + ) + const twoStepLogs = [...(await logsOf(accept)), ...(await logsOf(take))] + const twoStepState = await stateAfterClaim(twoStep, k.label, offer) + + const oneStep = await load() + expect(await offerToBob(oneStep, k.label)).toBe(offer) + const claimed = await claim(oneStep, k.label, { offer, terms: k.terms }) + + expect(await logsOf(claimed)).toEqual(twoStepLogs) + expect(await stateAfterClaim(oneStep, k.label, offer)).toEqual( + twoStepState, + ) + expect(await acceptances(oneStep, k, claimed)).toEqual([ + [k.label, getAddress(bob.address), k.terms], + ]) + expect(await oneStep.baseRegistrar.read.ownerOf([id(k.label)])).toBe( + getAddress(bob.address), + ) + expect(await oneStep.ens.read.owner([node(k.label)])).toBe( + getAddress(bob.address), + ) + }) + + it('reverts TermsNotAccepted for the other terms, for none and for terms replaced since the offer, and the name stays', async () => { + const f = await load() + const offer = await offerToBob(f, k.label) + for (const terms of [k.other, zeroHash]) { + await expect( + claim(f, k.label, { offer, terms }), + ).toBeRevertedWithCustomErrorFrom(f.namePolicy, 'TermsNotAccepted') + } + const next = termsLink('next.md', '4') + const namePolicy: any = f.namePolicy + await namePolicy.write[k.setTerms]([next], { account: owner }) + await expect( + claim(f, k.label, { offer, terms: k.terms }), + ).toBeRevertedWithCustomErrorFrom(f.namePolicy, 'TermsNotAccepted') + expect(await f.baseRegistrar.read.ownerOf([id(k.label)])).toBe( + getAddress(alice.address), + ) + await claim(f, k.label, { offer, terms: keccak256(toHex(next)) }) + expect(await f.baseRegistrar.read.ownerOf([id(k.label)])).toBe( + getAddress(bob.address), + ) + }) + }) + } + + it('a name removed from the community names between the offer and the claim is claimed under the general terms', async () => { + const f = await load() + const offer = await offerToBob(f, COMMUNITY.label) + await f.namePolicy.write.removeCommunityNames([[COMMUNITY.label]], { + account: owner, + }) + await expect( + claim(f, COMMUNITY.label, { offer, terms: COMMUNITY_TERMS }), + ).toBeRevertedWithCustomErrorFrom(f.namePolicy, 'TermsNotAccepted') + const claimed = await claim(f, COMMUNITY.label, { + offer, + terms: GENERAL_TERMS, + }) + expect(await acceptances(f, GENERAL, claimed)).toEqual([ + [COMMUNITY.label, getAddress(bob.address), GENERAL_TERMS], + ]) + }) + + it('only the approved recipient of the open offer claims', async () => { + const f = await load() + const label = GENERAL.label + const terms = GENERAL_TERMS + await expect( + claim(f, label, { offer: 0n, terms }), + ).toBeRevertedWithCustomError('NotOffered') + + await f.baseRegistrar.write.setApprovalForAll([bob.address, true], { + account: alice, + }) + await expect( + claim(f, label, { offer: 0n, terms }), + ).toBeRevertedWithCustomError('NotOffered') + + await f.baseRegistrar.write.approve([carol.address, id(label)], { + account: alice, + }) + const toCarol = await f.baseRegistrar.read.offers([id(label)]) + for (const account of [bob, alice]) { + await expect( + claim(f, label, { offer: toCarol, terms, account }), + ).toBeRevertedWithCustomError('NotOffered') + } + + const first = await offerToBob(f, label) + await f.baseRegistrar.write.approve([zeroAddress, id(label)], { + account: alice, + }) + await expect( + claim(f, label, { offer: first, terms }), + ).toBeRevertedWithCustomError('NotOffered') + + const second = await offerToBob(f, label) + await expect( + claim(f, label, { offer: first, terms }), + ).toBeRevertedWithCustomError('NotOffered') + await claim(f, label, { offer: second, terms }) + expect(await f.baseRegistrar.read.ownerOf([id(label)])).toBe( + getAddress(bob.address), + ) + }) + + it('an offer replaced in the same block before the claim is not claimed', async () => { + const f = await load() + const label = GENERAL.label + const offer = await offerToBob(f, label) + const first = { maxPriorityFeePerGas: 2_000_000_000n } + await testClient.setAutomine(false) + try { + const withdrawn = await f.baseRegistrar.write.approve( + [zeroAddress, id(label)], + { account: alice, ...first }, + ) + const offeredAgain = await f.baseRegistrar.write.approve( + [bob.address, id(label)], + { account: alice, ...first }, + ) + const claimed = await f.baseRegistrar.write.claimUnderTerms( + [alice.address, id(label), offer, GENERAL_TERMS], + { account: bob, gas: 1_000_000n, maxPriorityFeePerGas: 1n }, + ) + await testClient.mine({ blocks: 1 }) + const [withdrawal, reoffer, claimReceipt] = await Promise.all( + [withdrawn, offeredAgain, claimed].map((hash) => + publicClient.getTransactionReceipt({ hash }), + ), + ) + expect( + [withdrawal, reoffer, claimReceipt].map( + ({ blockNumber, transactionIndex, status }) => [ + blockNumber, + transactionIndex, + status, + ], + ), + ).toEqual([ + [withdrawal.blockNumber, 0, 'success'], + [withdrawal.blockNumber, 1, 'success'], + [withdrawal.blockNumber, 2, 'reverted'], + ]) + } finally { + await testClient.setAutomine(true) + } + expect(await f.baseRegistrar.read.ownerOf([id(label)])).toBe( + getAddress(alice.address), + ) + await expect( + claim(f, label, { offer, terms: GENERAL_TERMS }), + ).toBeRevertedWithCustomError('NotOffered') + await claim(f, label, { + offer: await f.baseRegistrar.read.offers([id(label)]), + terms: GENERAL_TERMS, + }) + }) + + it('a claim naming another holder reverts NotNameOwner, and only the registrar records an acceptance for a claim', async () => { + const f = await load() + const label = GENERAL.label + const offer = await offerToBob(f, label) + await expect( + claim(f, label, { from: carol.address, offer, terms: GENERAL_TERMS }), + ).toBeRevertedWithCustomError('NotNameOwner') + for (const account of [alice, bob]) { + await expect( + f.namePolicy.write.acceptTermsForClaim( + [id(label), alice.address, offer, GENERAL_TERMS, bob.address], + { account }, + ), + ).toBeRevertedWithCustomError('NotRegistrar') + } + }) + + it('a lapsed name in its grace period, and a name registered again, are not claimed', async () => { + const f = await load() + const label = GENERAL.label + const offer = await offerToBob(f, label) + await connection.networkHelpers.time.increase(MIN_REGISTRATION + 1n) + await expect( + claim(f, label, { offer, terms: GENERAL_TERMS }), + ).toBeRevertedWithoutReason() + + await connection.networkHelpers.time.increase(GRACE_PERIOD) + const reg = registration(label, carol.address) + await commitUnderGeneralTerms(connection, f.controller, reg, { + account: carol, + }) + await f.controller.write.register([reg], { + account: carol, + value: 2n * YEAR_PRICE_USD, + }) + await expect( + claim(f, label, { offer, terms: GENERAL_TERMS }), + ).toBeRevertedWithCustomError('NotNameOwner') + await expect( + claim(f, label, { from: carol.address, offer, terms: GENERAL_TERMS }), + ).toBeRevertedWithCustomError('NotOffered') + }) + + it('a name in its dispute period is claimed in one transaction', async () => { + const f = await load() + const label = 'disputedname' + const reg = registration(label, alice.address) + await commitUnderGeneralTerms(connection, f.controller, reg, { + account: alice, + }) + await f.sponsor.write.registerWithCredit( + await signRegistration(connection, f.sponsor, reg), + { account: registrar }, + ) + const until = await f.baseRegistrar.read.disputeUntil([id(label)]) + const offer = await offerToBob(f, label) + const claimed = await claim(f, label, { offer, terms: GENERAL_TERMS }) + const { blockNumber } = await publicClient.waitForTransactionReceipt({ + hash: claimed, + }) + expect( + (await publicClient.getBlock({ blockNumber })).timestamp, + ).toBeLessThan(until) + expect(await f.baseRegistrar.read.ownerOf([id(label)])).toBe( + getAddress(bob.address), + ) + expect(await f.baseRegistrar.read.disputeUntil([id(label)])).toBe(until) + }) + + it('the claim calls no code of the holder or the recipient', async () => { + const f = await load() + const label = GENERAL.label + const holder = await connection.viem.deployContract('ReentrantClaimer', [ + f.baseRegistrar.address, + ]) + await f.baseRegistrar.write.approve([holder.address, id(label)], { + account: alice, + }) + await holder.write.claim( + [ + alice.address, + id(label), + await f.baseRegistrar.read.offers([id(label)]), + GENERAL_TERMS, + ], + { account: carol }, + ) + expect(await f.baseRegistrar.read.ownerOf([id(label)])).toBe( + getAddress(holder.address), + ) + + await holder.write.offer([bob.address, id(label)], { account: carol }) + await claim(f, label, { + from: holder.address, + offer: await f.baseRegistrar.read.offers([id(label)]), + terms: GENERAL_TERMS, + }) + expect(await f.baseRegistrar.read.ownerOf([id(label)])).toBe( + getAddress(bob.address), + ) + expect(await holder.read.reentries()).toBe(0n) + }) + + it("with the registrar's policy pointer at the policy implementation the claim reverts NotProxy, and at zero it reverts while transferFrom moves the name", async () => { + const f = await load() + const label = GENERAL.label + const offer = await offerToBob(f, label) + await f.baseRegistrar.write.setNamePolicy( + [f.namePolicyImplementation.address], + { account: owner }, + ) + await expect( + claim(f, label, { offer, terms: GENERAL_TERMS }), + ).toBeRevertedWithCustomErrorFrom(f.namePolicy, 'NotProxy') + + await f.baseRegistrar.write.setNamePolicy([zeroAddress], { + account: owner, + }) + await expect( + claim(f, label, { offer, terms: GENERAL_TERMS }), + ).toBeRevertedWithoutReason() + await f.baseRegistrar.write.transferFrom( + [alice.address, bob.address, id(label)], + { account: bob }, + ) + expect(await f.baseRegistrar.read.ownerOf([id(label)])).toBe( + getAddress(bob.address), + ) + }) + + it('gas of the one-step claim against the acceptance and the claim', async () => { + const gasUsed = async (hash: Promise<`0x${string}`>) => + (await publicClient.waitForTransactionReceipt({ hash: await hash })) + .gasUsed + const rows: Record> = {} + for (const k of KINDS) { + const twoStep = await load() + const offer = await offerToBob(twoStep, k.label) + const namePolicy: any = twoStep.namePolicy + const accept = await gasUsed( + namePolicy.write[k.acceptForClaim]( + [id(k.label), alice.address, offer, k.terms], + { account: bob }, + ), + ) + const transferFrom = await gasUsed( + twoStep.baseRegistrar.write.transferFrom( + [alice.address, bob.address, id(k.label)], + { account: bob }, + ), + ) + const oneStep = await load() + await offerToBob(oneStep, k.label) + const claimUnderTerms = await gasUsed( + claim(oneStep, k.label, { offer, terms: k.terms }), + ) + rows[k.title] = { + [k.acceptForClaim]: Number(accept), + transferFrom: Number(transferFrom), + twoTransactions: Number(accept + transferFrom), + claimUnderTerms: Number(claimUnderTerms), + saved: Number(accept + transferFrom - claimUnderTerms), + } + expect(claimUnderTerms).toBeLessThan(accept + transferFrom) + } + console.table(rows) + }) +}) From 6baded6c893acefed5a32b03d7993e2acc44387d Mon Sep 17 00:00:00 2001 From: brenzi-agent <346870783+brenzi-agent@users.noreply.github.com> Date: Fri, 27 Nov 2026 10:26:27 +0000 Subject: [PATCH 3/8] registrar, SimplexNamePolicy: claim under the terms in one transaction --- .../BaseRegistrarImplementation.sol | 19 +++++++++++++++++++ contracts/simplex/INamePolicy.sol | 8 ++++++++ contracts/simplex/SimplexNamePolicy.sol | 11 +++++++++++ docs/upgrades.md | 2 +- 4 files changed, 39 insertions(+), 1 deletion(-) diff --git a/contracts/ethregistrar/BaseRegistrarImplementation.sol b/contracts/ethregistrar/BaseRegistrarImplementation.sol index c7eb16c9..b2444a83 100644 --- a/contracts/ethregistrar/BaseRegistrarImplementation.sol +++ b/contracts/ethregistrar/BaseRegistrarImplementation.sol @@ -567,6 +567,25 @@ contract BaseRegistrarImplementation is _transfer(from, to, tokenId); } + function claimUnderTerms( + address from, + uint256 tokenId, + uint256 offer, + bytes32 acceptedTermsHash + ) external { + if (ownerOf(tokenId) != from) revert NotNameOwner(); + if (getApproved(tokenId) != msg.sender || offer != offers[tokenId]) + revert NotOffered(); + INamePolicy(namePolicy).acceptTermsForClaim( + tokenId, + from, + offer, + acceptedTermsHash, + msg.sender + ); + _transfer(from, msg.sender, tokenId); + } + /// @dev Auto-reclaim: an NFT transfer re-points the 2LD's ENS registry node /// to the new holder, so the registry "manager" always tracks the token /// — no separate reclaim, and the previous owner can no longer manage diff --git a/contracts/simplex/INamePolicy.sol b/contracts/simplex/INamePolicy.sol index bd366557..ab5c8c23 100644 --- a/contracts/simplex/INamePolicy.sol +++ b/contracts/simplex/INamePolicy.sol @@ -13,6 +13,14 @@ interface INamePolicy { function communityNames(bytes32 labelhash) external view returns (bool); + function acceptTermsForClaim( + uint256 tokenId, + address from, + uint256 offer, + bytes32 acceptedTermsHash, + address recipient + ) external; + function consumeTransfer( uint256 tokenId, address from, diff --git a/contracts/simplex/SimplexNamePolicy.sol b/contracts/simplex/SimplexNamePolicy.sol index 4c70fa58..2f3b127a 100644 --- a/contracts/simplex/SimplexNamePolicy.sol +++ b/contracts/simplex/SimplexNamePolicy.sol @@ -398,6 +398,17 @@ contract SimplexNamePolicy is INamePolicy { _acceptForClaim(tokenId, from, offer, acceptedTermsHash, communityTermsHash, recipient); } + function acceptTermsForClaim( + uint256 tokenId, + address from, + uint256 offer, + bytes32 acceptedTermsHash, + address recipient + ) external { + if (msg.sender != address(registrar)) revert NotRegistrar(); + acceptedClaimTerms[tokenId][from][recipient][offer] = acceptedTermsHash; + } + function acceptGeneralTermsForRenewal( uint256 tokenId, uint256 expires, diff --git a/docs/upgrades.md b/docs/upgrades.md index 4aa3ece3..f9ce3264 100644 --- a/docs/upgrades.md +++ b/docs/upgrades.md @@ -231,7 +231,7 @@ declaration order, so reordering them swaps the two lists; keep them unchanged | `SimplexResolver` | `SimplexNamePolicy` | `clearRecords` | | `SimplexResolver` | `UniversalResolver` | `supportsInterface` and the resolver functions requested through it | | `SimplexNamePolicy` | `SimplexController` | `controller`, `isReserved`, `communityNames`, `consumeRegistration` | -| `SimplexNamePolicy` | `BaseRegistrarImplementation` | `registrar`, `consumeTransfer` | +| `SimplexNamePolicy` | `BaseRegistrarImplementation` | `registrar`, `acceptTermsForClaim`, `consumeTransfer` | `SimplexSponsor` and `UniversalResolver` are called only from outside the stack. `registerSponsored` and `renewSponsored` of `SimplexController` revert From 52a95acc8f91a0c8e3e6c82a16833b9520560b0d Mon Sep 17 00:00:00 2001 From: brenzi-agent <346870783+brenzi-agent@users.noreply.github.com> Date: Fri, 27 Nov 2026 11:06:21 +0000 Subject: [PATCH 4/8] ci: drop the push trigger of ab/one-step-claim --- .github/workflows/simplex.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/simplex.yml b/.github/workflows/simplex.yml index 04e6beae..2c881f09 100644 --- a/.github/workflows/simplex.yml +++ b/.github/workflows/simplex.yml @@ -2,7 +2,7 @@ name: SimpleX tests on: push: - branches: [simplex, ab/one-step-claim] + branches: [simplex] pull_request: branches: [simplex] From 4de2f09e352c19f01ec25b271bbd7d4f22e37ca6 Mon Sep 17 00:00:00 2001 From: brenzi-agent <346870783+brenzi-agent@users.noreply.github.com> Date: Fri, 27 Nov 2026 11:06:36 +0000 Subject: [PATCH 5/8] SimplexNamePolicy: name the registrar's claim hook recordClaimTerms --- contracts/ethregistrar/BaseRegistrarImplementation.sol | 2 +- contracts/simplex/INamePolicy.sol | 2 +- contracts/simplex/SimplexNamePolicy.sol | 2 +- docs/upgrades.md | 2 +- test/simplex/TestClaimUnderTerms.test.ts | 4 ++-- 5 files changed, 6 insertions(+), 6 deletions(-) diff --git a/contracts/ethregistrar/BaseRegistrarImplementation.sol b/contracts/ethregistrar/BaseRegistrarImplementation.sol index b2444a83..904fd9ce 100644 --- a/contracts/ethregistrar/BaseRegistrarImplementation.sol +++ b/contracts/ethregistrar/BaseRegistrarImplementation.sol @@ -576,7 +576,7 @@ contract BaseRegistrarImplementation is if (ownerOf(tokenId) != from) revert NotNameOwner(); if (getApproved(tokenId) != msg.sender || offer != offers[tokenId]) revert NotOffered(); - INamePolicy(namePolicy).acceptTermsForClaim( + INamePolicy(namePolicy).recordClaimTerms( tokenId, from, offer, diff --git a/contracts/simplex/INamePolicy.sol b/contracts/simplex/INamePolicy.sol index ab5c8c23..27590494 100644 --- a/contracts/simplex/INamePolicy.sol +++ b/contracts/simplex/INamePolicy.sol @@ -13,7 +13,7 @@ interface INamePolicy { function communityNames(bytes32 labelhash) external view returns (bool); - function acceptTermsForClaim( + function recordClaimTerms( uint256 tokenId, address from, uint256 offer, diff --git a/contracts/simplex/SimplexNamePolicy.sol b/contracts/simplex/SimplexNamePolicy.sol index 2f3b127a..fa8ad90b 100644 --- a/contracts/simplex/SimplexNamePolicy.sol +++ b/contracts/simplex/SimplexNamePolicy.sol @@ -398,7 +398,7 @@ contract SimplexNamePolicy is INamePolicy { _acceptForClaim(tokenId, from, offer, acceptedTermsHash, communityTermsHash, recipient); } - function acceptTermsForClaim( + function recordClaimTerms( uint256 tokenId, address from, uint256 offer, diff --git a/docs/upgrades.md b/docs/upgrades.md index f9ce3264..53e33117 100644 --- a/docs/upgrades.md +++ b/docs/upgrades.md @@ -231,7 +231,7 @@ declaration order, so reordering them swaps the two lists; keep them unchanged | `SimplexResolver` | `SimplexNamePolicy` | `clearRecords` | | `SimplexResolver` | `UniversalResolver` | `supportsInterface` and the resolver functions requested through it | | `SimplexNamePolicy` | `SimplexController` | `controller`, `isReserved`, `communityNames`, `consumeRegistration` | -| `SimplexNamePolicy` | `BaseRegistrarImplementation` | `registrar`, `acceptTermsForClaim`, `consumeTransfer` | +| `SimplexNamePolicy` | `BaseRegistrarImplementation` | `registrar`, `recordClaimTerms`, `consumeTransfer` | `SimplexSponsor` and `UniversalResolver` are called only from outside the stack. `registerSponsored` and `renewSponsored` of `SimplexController` revert diff --git a/test/simplex/TestClaimUnderTerms.test.ts b/test/simplex/TestClaimUnderTerms.test.ts index dc0ce832..f3b23c84 100644 --- a/test/simplex/TestClaimUnderTerms.test.ts +++ b/test/simplex/TestClaimUnderTerms.test.ts @@ -335,7 +335,7 @@ describe('claimUnderTerms', () => { }) }) - it('a claim naming another holder reverts NotNameOwner, and only the registrar records an acceptance for a claim', async () => { + it('a claim naming another holder reverts NotNameOwner, and only the registrar records claim terms', async () => { const f = await load() const label = GENERAL.label const offer = await offerToBob(f, label) @@ -344,7 +344,7 @@ describe('claimUnderTerms', () => { ).toBeRevertedWithCustomError('NotNameOwner') for (const account of [alice, bob]) { await expect( - f.namePolicy.write.acceptTermsForClaim( + f.namePolicy.write.recordClaimTerms( [id(label), alice.address, offer, GENERAL_TERMS, bob.address], { account }, ), From a06bcd63f15b32ac3e775e491022e2cc5037cc6d Mon Sep 17 00:00:00 2001 From: brenzi-agent <346870783+brenzi-agent@users.noreply.github.com> Date: Fri, 27 Nov 2026 11:06:36 +0000 Subject: [PATCH 6/8] test: claim with a policy lacking recordClaimTerms, and re-entry --- contracts/mocks/ReentrantClaimer.sol | 10 ++------- contracts/mocks/TransferOnlyNamePolicy.sol | 18 +++++++++++++++ test/simplex/TestClaimUnderTerms.test.ts | 26 +++++++++++++--------- 3 files changed, 36 insertions(+), 18 deletions(-) create mode 100644 contracts/mocks/TransferOnlyNamePolicy.sol diff --git a/contracts/mocks/ReentrantClaimer.sol b/contracts/mocks/ReentrantClaimer.sol index ffd71f7d..359f83ec 100644 --- a/contracts/mocks/ReentrantClaimer.sol +++ b/contracts/mocks/ReentrantClaimer.sol @@ -14,7 +14,6 @@ interface IClaimUnderTerms { contract ReentrantClaimer { IClaimUnderTerms public immutable registrar; - uint256 public reentries; constructor(IClaimUnderTerms registrar_) { registrar = registrar_; @@ -39,16 +38,11 @@ contract ReentrantClaimer { uint256 tokenId, bytes calldata ) external returns (bytes4) { - _reenter(from, tokenId); + registrar.claimUnderTerms(from, tokenId, 0, bytes32(0)); return this.onERC721Received.selector; } fallback() external { - _reenter(address(0), 0); - } - - function _reenter(address from, uint256 tokenId) private { - ++reentries; - registrar.claimUnderTerms(from, tokenId, 0, bytes32(0)); + registrar.claimUnderTerms(address(0), 0, 0, bytes32(0)); } } diff --git a/contracts/mocks/TransferOnlyNamePolicy.sol b/contracts/mocks/TransferOnlyNamePolicy.sol new file mode 100644 index 00000000..0a5b045f --- /dev/null +++ b/contracts/mocks/TransferOnlyNamePolicy.sol @@ -0,0 +1,18 @@ +//SPDX-License-Identifier: MIT +pragma solidity ~0.8.26; + +contract TransferOnlyNamePolicy { + address public immutable registrar; + + constructor(address registrar_) { + registrar = registrar_; + } + + function consumeTransfer( + uint256, + address, + address, + uint256, + string calldata + ) external pure {} +} diff --git a/test/simplex/TestClaimUnderTerms.test.ts b/test/simplex/TestClaimUnderTerms.test.ts index f3b23c84..a924fe6e 100644 --- a/test/simplex/TestClaimUnderTerms.test.ts +++ b/test/simplex/TestClaimUnderTerms.test.ts @@ -286,16 +286,16 @@ describe('claimUnderTerms', () => { const f = await load() const label = GENERAL.label const offer = await offerToBob(f, label) - const first = { maxPriorityFeePerGas: 2_000_000_000n } + const higherTip = { maxPriorityFeePerGas: 2_000_000_000n } await testClient.setAutomine(false) try { const withdrawn = await f.baseRegistrar.write.approve( [zeroAddress, id(label)], - { account: alice, ...first }, + { account: alice, ...higherTip }, ) const offeredAgain = await f.baseRegistrar.write.approve( [bob.address, id(label)], - { account: alice, ...first }, + { account: alice, ...higherTip }, ) const claimed = await f.baseRegistrar.write.claimUnderTerms( [alice.address, id(label), offer, GENERAL_TERMS], @@ -404,7 +404,7 @@ describe('claimUnderTerms', () => { expect(await f.baseRegistrar.read.disputeUntil([id(label)])).toBe(until) }) - it('the claim calls no code of the holder or the recipient', async () => { + it('a holder and a recipient that re-enter claimUnderTerms from any call into them both claim', async () => { const f = await load() const label = GENERAL.label const holder = await connection.viem.deployContract('ReentrantClaimer', [ @@ -435,10 +435,9 @@ describe('claimUnderTerms', () => { expect(await f.baseRegistrar.read.ownerOf([id(label)])).toBe( getAddress(bob.address), ) - expect(await holder.read.reentries()).toBe(0n) }) - it("with the registrar's policy pointer at the policy implementation the claim reverts NotProxy, and at zero it reverts while transferFrom moves the name", async () => { + it("with the registrar's policy pointer at the policy implementation the claim reverts NotProxy, and at a policy without recordClaimTerms or at zero it reverts while transferFrom moves the name", async () => { const f = await load() const label = GENERAL.label const offer = await offerToBob(f, label) @@ -450,12 +449,19 @@ describe('claimUnderTerms', () => { claim(f, label, { offer, terms: GENERAL_TERMS }), ).toBeRevertedWithCustomErrorFrom(f.namePolicy, 'NotProxy') - await f.baseRegistrar.write.setNamePolicy([zeroAddress], { + const transferOnly = await connection.viem.deployContract( + 'TransferOnlyNamePolicy', + [f.baseRegistrar.address], + ) + for (const pointer of [transferOnly.address, zeroAddress]) { + await f.baseRegistrar.write.setNamePolicy([pointer], { account: owner }) + await expect( + claim(f, label, { offer, terms: GENERAL_TERMS }), + ).toBeRevertedWithoutReason() + } + await f.baseRegistrar.write.setNamePolicy([transferOnly.address], { account: owner, }) - await expect( - claim(f, label, { offer, terms: GENERAL_TERMS }), - ).toBeRevertedWithoutReason() await f.baseRegistrar.write.transferFrom( [alice.address, bob.address, id(label)], { account: bob }, From 580b2a80ce981325c5ea4d52a493e6f18004227e Mon Sep 17 00:00:00 2001 From: brenzi-agent <346870783+brenzi-agent@users.noreply.github.com> Date: Fri, 27 Nov 2026 11:31:17 +0000 Subject: [PATCH 7/8] test: name the re-entry test by what it asserts --- test/simplex/TestClaimUnderTerms.test.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/simplex/TestClaimUnderTerms.test.ts b/test/simplex/TestClaimUnderTerms.test.ts index a924fe6e..86cbcadb 100644 --- a/test/simplex/TestClaimUnderTerms.test.ts +++ b/test/simplex/TestClaimUnderTerms.test.ts @@ -404,7 +404,7 @@ describe('claimUnderTerms', () => { expect(await f.baseRegistrar.read.disputeUntil([id(label)])).toBe(until) }) - it('a holder and a recipient that re-enter claimUnderTerms from any call into them both claim', async () => { + it('the claim calls no code of the holder or the recipient', async () => { const f = await load() const label = GENERAL.label const holder = await connection.viem.deployContract('ReentrantClaimer', [ From cc024cc37c9595d0a63af48c10c1cb55a50c43d0 Mon Sep 17 00:00:00 2001 From: brenzi-agent <346870783+brenzi-agent@users.noreply.github.com> Date: Fri, 27 Nov 2026 11:57:32 +0000 Subject: [PATCH 8/8] test: name the pointer test by the transfer it makes --- test/simplex/TestClaimUnderTerms.test.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/simplex/TestClaimUnderTerms.test.ts b/test/simplex/TestClaimUnderTerms.test.ts index 86cbcadb..af0168c4 100644 --- a/test/simplex/TestClaimUnderTerms.test.ts +++ b/test/simplex/TestClaimUnderTerms.test.ts @@ -437,7 +437,7 @@ describe('claimUnderTerms', () => { ) }) - it("with the registrar's policy pointer at the policy implementation the claim reverts NotProxy, and at a policy without recordClaimTerms or at zero it reverts while transferFrom moves the name", async () => { + it("with the registrar's policy pointer at the policy implementation the claim reverts NotProxy, at a policy without recordClaimTerms or at zero it reverts, and transferFrom moves the name through that policy", async () => { const f = await load() const label = GENERAL.label const offer = await offerToBob(f, label)