Skip to content
NFTVenue Ledger
Directory

Erc721 Erc1155 Eip712 Permit Security

ERC-721 safeTransferFrom & onERC721Received Reentrancy: Max-Supply Bypass & Escrow Drains

OpenZeppelin _safeMint and safeTransferFrom hand execution control directly to untrusted receiver contracts via onERC721Received, causing classic CEI violations across NFT venues.

By Dr. Devon Kurosawa, PhDReview not recorded · Updated
ERC-721 safeTransferFrom & onERC721Received Reentrancy: Max-Supply Bypass & Escrow Drains — NFTVenue Ledger 2026 quantitative & supervisory data card
NFTVenue Ledger (EIP-712 Signatures, Permit2 Allowance Security, Royalties & Proxy Timelocks): Strict CEI ordering on _safeMint, EIP-1153 300-gas locks, and pull-settlement auctions.Source: NFTVenue Ledger Institutional Research DeskLicense: CC-BY-4.0

Ask junior Solidity developers to name an untrusted external call, and everyone spots msg.sender.call{value: eth}("")—yet dozens of audited NFT mints, lending escrows, and staking vaults got drained for millions (HypeBears, Revest Finance, Omni NFT lending, Sudoswap-fork forks) because developers treated _safeMint(to, tokenId) and safeTransferFrom(from, to, tokenId) as "trusted internal library helpers"! In reality, per EIP-721, whenever to.code.length > 0, _checkOnERC721Received makes an untrusted external CALL forwarding 63/64 of remaining gas to IERC721Receiver(to).onERC721Received(...)!

Anchored in our EIP-712, Permit2 & proxy security master guide, enforcing the Checks-Effects-Interactions (CEI) security pattern and Cancun EIP-1153 ReentrancyGuardTransient is mandatory across every NFT mint, auction, and collateral vault in our marketplaces directory (from Azuki and Basepunks to Based Punks and Beanz Officia).

Three Real-World onERC721Received Reentrancy Exploit Patterns!#

  1. Pattern A — Allowlist / Max-Per-Wallet Mint Cap Bypass (HypeBears Style):

require(!hasMinted[msg.sender]); _safeMint(msg.sender, nextId++); hasMinted[msg.sender] = true; Because hasMinted[msg.sender] = true sits after _safeMint, the attacker's onERC721Received callback re-invokes mint 100 times in a recursive loop while hasMinted[msg.sender] is still false—minting out the entire collection in 1 transaction!

  1. Pattern B — for-Loop Batch Mint Same-Token-ID Overwrite / Supply Under-Count:

If a contract caches uint256 id = totalSupply in a local stack variable before a loop calling _safeMint, reentering inside onERC721Received reads the stale totalSupply storage variable before the outer frame writes totalSupply += qty!

  1. Pattern C — NFT Lending / Escrow Collateral Double-Withdraw (Omni Style):

A borrower repays debt or liquidates a sub-position, triggering collateralNFT.safeTransferFrom(vault, borrower, id) before updating userCollateralCount[borrower]-- or health factor. Inside onERC721Received, the borrower's contract still registers healthy collateral and borrows the entire WETH lending pool with zero backing!

onERC721Received recursive callback attack vs Checks-Effects-Interactions + EIP-1153 TSTORE defense
onERC721Received recursive callback attack vs Checks-Effects-Interactions + EIP-1153 TSTORE defenseVerified Exhibit

Push vs Pull Settlement: What Happens When onERC721Received Intentionally Reverts?#

Reentrancy isn't the only weapon inside onERC721Received! Suppose an English NFT auction contract settles bids by automatically calling nft.safeTransferFrom(escrow, winningBidder, id) or refunding outbid bidder A via prevBidder.call{value: prevBid}("") when bidder B bids higher:

  • A malicious bidder deploys a contract whose onERC721Received (or receive) unconditionally reverts (or burns 50,000,000 gas in an infinite loop!)!
  • Suddenly, nobody can outbid the attacker, or the seller can never finalize the auction to collect ETH (Permanent Auction Griefing DoS)!
  • Mandatory Pull-Over-Push Pattern: English auctions and Seaport-style clearinghouses credit unsuccessful bids to an internal claimable pendingWithdrawals[bidder] mapping (or wrap to WETH) and isolate transferFrom (non-callback!) fallback paths when settlement finality is required!

ERC-721 Transfer & Mint Security Comparison Matrix#

Solidity Transfer FunctionInvokes 0x150b7a02 Callback?Reentrancy RiskReceiver Revert DoS RiskCorrect Protocol Usage
_mint(to, id) / transferFromNo (Zero external call)ZeroZeroForced liquidations & auction clears
_safeMint(to, id) + No CEIYes (if to.code.length > 0)CRITICAL DRAINHigh in batch loopsNEVER DEPLOY
_safeMint + CEI + EIP-1153 GuardYesBlocked (0%)Self-only (Caller reverts own mint)Standard retail NFT drops
ERC-721A _safeMint(to, qty)Yes (per token, post-index update)Blocked on supply; add nonReentrant for custom mappings!Self-onlyLow-gas multi-mint drops (Azuki)
EVM gas overhead of reentrancy protection from OpenZeppelin SSTORE ReentrancyGuard to Cancun EIP-1153 TSTORE
EVM gas overhead of reentrancy protection from OpenZeppelin SSTORE ReentrancyGuard to Cancun EIP-1153 TSTOREVerified Exhibit

Cancun EIP-1153 ReentrancyGuardTransient Cost & Cross-Function Lock Invariant#

Why must nonReentrant be applied to every state-mutating AND price-reading view function sharing collateral state, rather than just mint alone? Because Cross-Function Reentrancy enters Function B (e.g., borrow or transfer ) from Function A's onERC721Received callback!

Formula or model from the articleNot independently verified
1) Cross-Function State Invariant Across Untrusted Callback Boundary:
  • Let I(S) denote protocol solvency & supply invariant (e.g., Minted[u] <= Cap && Debt[u] <= LTV * Collateral[u]).
  • REQUIRED BEFORE ANY safeTransferFrom / _safeMint / ETH call:
  • I(Sprecallback) == TRUE AND TransientLockSlot(tload(LOCK_SLOT)) == LOCKED (1)
  • 2) Cancun EIP-1153 Transient Guard Gas Savings:
  • Legacy SSTORE Guard (1 -> 2 -> 1): Glegacy = SLOADcold(2,100) + SSTOREdirty(2,900) + SSTOREreset(100) = 5,100 gas
  • EIP-1153 TSTORE Guard (0 -> 1 -> 0): Gtransient = TLOAD(100) + TSTORE(100) + TSTOREclear(100) = 300 gas (-94.1%!)
  • Worked Cross-Function Lending Audit:
  • Vault applies nonReentrantTransient to deposit, withdrawNFT, borrow, AND checks !reentrancyGuardEntered inside getAccountHealth
  • => Borrower's onERC721Received callback during withdrawNFT calls borrow -> Instant Revert ReentrancyGuardReentrantCall at 300 gas!

Extending Callback Defenses to ERC-1155 Batch Hooks#

While ERC-721 callbacks only trigger when the recipient is a contract, ERC-1155 unconditionally requires onERC1155Received / onERC1155BatchReceived on EVERY transfer (there is NO non-safe transferFrom in ERC-1155!)—creating acute gas-stipend DoS vectors on marketplaces examined next in ERC-1155 batch transfer gas-stipend DoS and setApprovalForAll blast radius inside our EIP-712, Permit2 & Proxy Security hub.

Frequently asked questions

Why did _safeMint cause so many max-supply NFT mint hacks?

Developers assumed _safeMint only wrote storage like _mint, overlooking that _safeMint invokes to.onERC721Received BEFORE returning—allowing a smart-contract minter to re-call mint recursively before hasMinted[msg.sender] updated.

Does Azuki ERC-721A prevent all _safeMint reentrancy bugs automatically?

ERC-721A updates _currentIndex and ownership state before invoking onERC721Received, protecting totalSupply; however, custom per-wallet allowlist mappings written in your wrapper mint function after _safeMint STILL require CEI or nonReentrant!

When should a smart contract use transferFrom instead of safeTransferFrom?

During forced protocol actions such as collateral liquidations or auction settlements where a malicious borrower/bidder contract could intentionally revert onERC721Received to block liquidation indefinitely.

How does EIP-1153 ReentrancyGuardTransient improve on classic ReentrancyGuard?

EIP-1153 uses transient memory-like TLOAD/TSTORE opcodes (100 gas each) that automatically wipe at transaction end, saving ~4,800 gas per call compared to warm storage SSTORE locks.

Publication record

Published
November 13, 2026
Updated
November 14, 2026
Author
Dr. Devon Kurosawa, PhD
Review
Review not recorded
Automated fact check
Passed in the stored pipeline record
Source URLs
3 recorded

AI assistance recorded: anthropic/claude-opus-4.6. This field does not establish human review or source verification.

Academic & Institutional Attribution

Cite This Research & Embed Live Data Card

Open Attribution License (CC BY 4.0)

Standard academic & institutional research paper citation format.

Dr. Devon Kurosawa, PhD. (2026, November 14). ERC-721 safeTransferFrom & onERC721Received Reentrancy: Max-Supply Bypass & Escrow Drains. NFTVenue Ledger. https://nftvenueledger.com/protocols/erc721-safetransferfrom-onerc721received-callback-reentrancy

Regulatory Directory Cross-Reference

Referenced Institutions & Regulatory Registries

Primary Tier-1 Supervisory Registries

Explore Erc721 Erc1155 Eip712 Permit Security Hub (20) →

NFTVenue Ledger Data, Benchmarks & Contributor Records

ERC-721 safeTransferFrom & onERC721Received Reentrancy Audit | NFTVenue Ledger