Repository navigation
Fix v1 random offset, multiConfigure and transfer validation bugs - #196
Merged
Merged
Conversation
There was a problem hiding this comment.
🟢 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
multiConfigurearrays, 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
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
force-pushed
the
ryan/v1-contract-fixes
branch
from
November 6, 2026 23:04
c066697 to
fa76a44
Compare
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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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 (
ERC721SeaDropRandomOffsetand the upgradeable variant)tokenURIshifts each token's metadata byrandomOffset + 1, modulo the max supply. The old code drewrandomOffsetfrom 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.tokenURIis unchanged, so already-revealed collections keep their mapping.NotFullyMinted.BatchMetadataUpdate(startTokenId, lastTokenId). The token advertises 4906, andv2's extension already emitted it.setMaxSupplynow revertsAlreadyRevealed()after the reveal, which also blocks it throughmultiConfigure. Raising it after the reveal reshuffled revealed metadata. To allow the override, the basesetMaxSupplygoes fromexternaltopublic virtual. The ABI is the same.2. Upgradeable random offset init.
__ERC721SeaDropRandomOffset_initdidn'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.
multiConfigurelength 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()returnedisViewFunction = false. ButITransferValidator721.validateTransferis declaredview, the token calls it with STATICCALL, and Limit Break's ERC721C convention returnstrue. It now returnstrue.SeaDrop.solis untouched.Verification
forge test:Ran 32 test suites: 256 tests passed, 0 failed, 0 skipped, up from 239 onmain.forge fmt --check,forge lint --deny warningsandbiome ci .pass. Both random offset contracts are at 100% coverage.setMaxSupplylock reads the existingrevealedflag.forge inspect storageLayoutand every diamondLayoutare unchanged.ERC721SeaDropRandomOffsetERC721SeaDropRandomOffsetUpgradeableERC721SeaDropUpgradeableOwner 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:
ERC721SeaDropCloneFactory.createClonesalts withblockhash(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.ERC721SeaDropSoulbound, andERC721SeaDropPausablewhile paused, block burns as well as transfers.SeaDrop.soldoesn't checkminFeeBps <= maxFeeBpsin signed-mint validation params. Changing it would mean redeploying the canonicalSeaDropat0x00005EA00Ac477B1030CE78506496e8C2dE24bf5.🤖 Generated with Claude Code