Skip to content

Fix v1 random offset, multiConfigure and transfer validation bugs - #196

Merged
ryanio merged 3 commits into
mainfrom
ryan/v1-contract-fixes
Nov 6, 2026
Merged

ryanio merged 3 commits into
mainfrom
ryan/v1-contract-fixes

Conversation

@ryanio

@ryanio ryanio commented Nov 6, 2026 •

Copy link
Copy Markdown
Collaborator

Motivation

Porting the v1 Hardhat suite to Forge in #193 turned up contract bugs, and #194 exposed one more in the upgradeable random offset. This fixes them in the regular, clone and upgradeable variants. #194 has merged, and this is rebased onto main.

Solution

Each fix has tests that fail on the old code, run against both the regular and upgradeable variants.

1. Random offset range (ERC721SeaDropRandomOffset and the upgradeable variant)

  • tokenURI shifts each token's metadata by randomOffset + 1, modulo the max supply. The old code drew randomOffset from 1 to N−1. That made N−1 the identity shift, leaving every token on its own metadata, and N=2 always landed there. It now draws from 0 to N−2, so the shift is uniform over the N−1 shifts that move every token.
  • tokenURI is unchanged, so already-revealed collections keep their mapping.
  • A max supply of 1 divided by zero. It now reveals with offset 0. A max supply of 0 underflowed; it now reverts NotFullyMinted.
  • The reveal now emits ERC-4906's BatchMetadataUpdate(startTokenId, lastTokenId). The token advertises 4906, and v2's extension already emitted it.
  • setMaxSupply now reverts AlreadyRevealed() after the reveal, which also blocks it through multiConfigure. Raising it after the reveal reshuffled revealed metadata. To allow the override, the base setMaxSupply goes from external to public virtual. The ABI is the same.

2. Upgradeable random offset init. __ERC721SeaDropRandomOffset_init didn't run its parents' initializers. That left no name, symbol or owner, and a zero reentrancy lock, so every mint reverted. It now runs the full parent init.

3. multiConfigure length checks (ERC721SeaDrop, ERC721SeaDropCloneable, ERC721SeaDropUpgradeable). The checks that allowed tokens pair with token-gated stages, and signers with validation params, only ran when the stages or params were non-empty. Tokens or signers passed alone were silently dropped. Both pairs are now checked up front.

4. Transfer validation view flag (regular, clone and upgradeable). getTransferValidationFunction() returned isViewFunction = false. But ITransferValidator721.validateTransfer is declared view, the token calls it with STATICCALL, and Limit Break's ERC721C convention returns true. It now returns true.

SeaDrop.sol is untouched.

Verification

  • forge test: Ran 32 test suites: 256 tests passed, 0 failed, 0 skipped, up from 239 on main. forge fmt --check, forge lint --deny warnings and biome ci . pass. Both random offset contracts are at 100% coverage.
  • Upgradeable storage. The upgradeable changes add no storage. The setMaxSupply lock reads the existing revealed flag. forge inspect storageLayout and every diamond Layout are unchanged.
  • Upgrade from old bytecode. A throwaway test upgraded a proxy built from the original bytecode. It kept all state, including a revealed offset mapping, and the new lock applied after the upgrade.
  • Runtime sizes, all under EIP-170:
Contract Before After Headroom
ERC721SeaDropRandomOffset 20,069 20,211 4,365
ERC721SeaDropRandomOffsetUpgradeable 23,346 23,419 1,157
ERC721SeaDropUpgradeable 22,892 22,894 1,682

Owner decision needed

These are pre-existing findings from the same pass, left alone because fixing them changes addresses or behavior that integrators may rely on:

  • Clone salt. ERC721SeaDropCloneFactory.createClone salts with blockhash(block.number), which is always 0 inside the current block. So the salt doesn't separate clones across chains, and anyone can front-run a salt. Fixing it changes the clone addresses the factory produces.
  • Burns are blocked. ERC721SeaDropSoulbound, and ERC721SeaDropPausable while paused, block burns as well as transfers.
  • Fee bounds. SeaDrop.sol doesn't check minFeeBps <= maxFeeBps in signed-mint validation params. Changing it would mean redeploying the canonical SeaDrop at 0x00005EA00Ac477B1030CE78506496e8C2dE24bf5.

🤖 Generated with Claude Code

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

No active review issues are reported for the token-contract fixes across regular, cloneable, and upgradeable variants.

No open issues 🎉

What changed in this PR

Fixes v1 token-contract bugs identified during the Foundry migration and upgradeable consolidation in #193 and #194. Changes cover regular, cloneable, and upgradeable variants without modifying SeaDrop.sol.

Changes:

  • Corrects random-offset reveals, handles zero/one-token supplies, emits metadata updates, and locks max supply after reveal.
  • Repairs upgradeable parent initialization, validates paired multiConfigure arrays, and corrects transfer-validation view flags.
  • Adds regression tests for the fixes across applicable contract variants.
File Description
test/​foundry/​upgradeable/​ERC721SeaDropUpgradeable.t.sol Tests random-offset parent initialization and minting.
test/​foundry/​ERC721TransferValidator.t.sol Expects the corrected view flag.
test/​foundry/​ERC721SeaDropRandomOffset.t.sol Tests offset ranges, edge cases, reveal events, and supply locking.
test/​foundry/​ERC721SeaDropCloneFactory.t.sol Tests clone array validation and view flags.
test/​foundry/​ERC721SeaDropAdmin.t.sol Tests rejection of unpaired configuration arrays.
src/​upgradeable/​extensions/​ERC721SeaDropRandomOffsetUpgradeable.sol Fixes initialization, reveal behavior, and post-reveal supply locking.
src/​upgradeable/​extensions/​ERC721SeaDropRandomOffsetStorage.sol Updates offset-range documentation only.
src/​upgradeable/​ERC721SeaDropUpgradeable.sol Validates paired arrays before configuration.
src/​upgradeable/​ERC721ContractMetadataUpgradeable.sol Enables supply overrides and corrects the view flag.
src/​extensions/​ERC721SeaDropRandomOffset.sol Corrects reveals, emits metadata updates, and locks supply.
src/​ERC721SeaDrop.sol Validates paired arrays before configuration.
src/​ERC721ContractMetadata.sol Enables supply overrides and corrects the view flag.
src/​clones/​ERC721SeaDropCloneable.sol Validates paired arrays before clone configuration.
src/​clones/​ERC721ContractMetadataCloneable.sol Corrects the transfer-validation view flag.

Review effort: Balanced

Base automatically changed from ryan/upgradeable-into-src to main November 6, 2026 23:02
ryanio and others added 3 commits November 6, 2026 15:04
Random offset (regular and upgradeable): tokenURI shifts metadata ids
by randomOffset + 1, so the old offset, (random % (maxSupply - 1)) + 1,
could be maxSupply - 1 and leave every token on its own metadata. With
two tokens it always did. It now draws from [0, maxSupply - 2], uniform
over the shifts that move every token. maxSupply 1 reveals with offset
0 instead of dividing by zero, and maxSupply 0 reverts NotFullyMinted
instead of underflowing. tokenURI is unchanged, so collections already
revealed keep their mapping.

__ERC721SeaDropRandomOffset_init ran only __ERC721SeaDrop_init_unchained,
leaving a token initialized through it with no name, symbol, or owner
and a zero reentrancy lock. It now runs __ERC721SeaDrop_init.

multiConfigure (regular, clone, upgradeable) checked the token gated
and signer array lengths only when stages or params were non-empty, so
tokens or signers passed alone were dropped. It now checks both pairs
up front and reverts with TokenGatedMismatch or SignersMismatch.

getTransferValidationFunction (regular, clone, upgradeable) returned
isViewFunction = false, but ITransferValidator721.validateTransfer is
view and the token calls it with STATICCALL. It now returns true.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
setRandomOffset moves every token's metadata, and the token advertises
ERC-4906, so it now emits BatchMetadataUpdate over all minted tokens, in
both the regular and upgradeable extensions.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
tokenURI maps tokens modulo the max supply, so raising it after the
reveal reshuffled the revealed tokens. setMaxSupply is now public
virtual, and both random offset extensions override it to revert with
AlreadyRevealed after the reveal, which also covers multiConfigure.
The upgradeable override reads the existing revealed flag, so the
storage layout is unchanged.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@ryanio
ryanio force-pushed the ryan/v1-contract-fixes branch from c066697 to fa76a44 Compare November 6, 2026 23:04
@ryanio
ryanio merged commit 691f015 into main Nov 6, 2026
7 checks passed
@ryanio
ryanio deleted the ryan/v1-contract-fixes branch November 6, 2026 23:18
ryanio added a commit that referenced this pull request Nov 8, 2026
…#217)

## Motivation

An audit of this round's `main` changes turned up two low-severity
problems worth fixing before the new clone factory ships. Both predate
this round.

`renounceOwnership`, from utility-contracts' `TwoStepOwnable`, leaves
`potentialOwner` set. If an owner nominates someone with
`transferOwnership` and then renounces, the nominee can still call
`acceptOwnership` and take back a contract that looks renounced. On
`ERC721SeaDropLockable` the nominee could then call `lockPermanently`,
even though ERC-8451 consumers read `owner() == address(0)` as "nobody
can change the lock".

`ERC721SeaDropCloneFactory.createClone` derived the clone salt as
`keccak256(abi.encodePacked(salt, blockhash(block.number)))`. The
blockhash of the current block is always 0, so a clone's address depends
only on the salt the caller passes. Anyone who copies the salt from a
pending `createClone` transaction gets a clone at that address, owned by
them, and the original call reverts. os2-core picks random salts and
learns clone addresses from ingestion, so the impact is griefing. #196
left this for an owner decision because fixing it moves clone addresses,
but a new factory moves them anyway.

## Solution

- `ERC721ContractMetadata`, `ERC721ContractMetadataCloneable` and
`ERC721ContractMetadataUpgradeable` override `renounceOwnership` to call
`cancelOwnershipTransfer()` before renouncing. It emits
`PotentialOwnerUpdated(address(0))`, and other callers still get
`OnlyOwner`. `ERC721SeaDropLockable` still checks for a temporary lock
after the renounce.
- `createClone` now uses `keccak256(abi.encode(msg.sender, salt))`.
Nothing in os2-core or os2-web predicts clone addresses. os2-core only
encodes the `createClone` call, in
`CreatorStudioDeployContractHelper.kt`.

## Deployment impact

- Deployed contracts don't change. Lockables that partners deployed from
the deploy page, which pins 0d3fbf3, keep the old renounce behavior. The
page picks up the fix once its `seadrop` submodule moves to a commit
that includes this one.
- The clone implementation's runtime code hash becomes
`0x6182dc72499ec18621a76368261d1fd2ec9c111e6aa402821bd22e5eec141e34`
(Foundry 1.9.0). That's the value os2-core has to pin for the new
factory. The factory's init code also changes, so mine its CREATE2 salt
against the new init code hash.
- The storage layout and ABI don't change. `ERC721SeaDrop`'s runtime
code grows by 12 bytes, to 19,450.

## Testing

- `testRenounceOwnership_cancelsPendingTransfer` and
`testRenounceOwnership_onlyOwner` run against the regular token and,
through `SharedTests`, the upgradeable token.
- `testCloneRenounceOwnership_cancelsPendingTransfer` and
`testCreateClone_saltIsBoundToCaller` cover the clone and the factory.
- `testRenounceOwnershipCancelsPendingTransfer` covers
`ERC721SeaDropLockable`.
- Every new test fails against the previous code.
- `forge test`: 299 passed, 0 failed. `forge fmt --check` and `forge
lint --deny warnings` pass with Foundry 1.9.0.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants