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.

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!#
- 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!
- 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!
- 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!
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(orreceive) unconditionallyreverts (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 toWETH) and isolatetransferFrom(non-callback!) fallback paths when settlement finality is required!
ERC-721 Transfer & Mint Security Comparison Matrix#
| Solidity Transfer Function | Invokes 0x150b7a02 Callback? | Reentrancy Risk | Receiver Revert DoS Risk | Correct Protocol Usage |
|---|---|---|---|---|
_mint(to, id) / transferFrom | No (Zero external call) | Zero | Zero | Forced liquidations & auction clears |
_safeMint(to, id) + No CEI | Yes (if to.code.length > 0) | CRITICAL DRAIN | High in batch loops | NEVER DEPLOY |
_safeMint + CEI + EIP-1153 Guard | Yes | Blocked (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-only | Low-gas multi-mint drops (Azuki) |
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!
- 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
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-reentrancyRegulatory Directory Cross-Reference
Referenced Institutions & Regulatory Registries
Top Regulated Institutions in This Coverage Slice
Primary Tier-1 Supervisory Registries
Related Erc721 Erc1155 Eip712 Permit Security & Institutional Briefings
Explore Erc721 Erc1155 Eip712 Permit Security Hub (20) →Erc721 Erc1155 Eip712 Permit Security
EIP-712 Typed Signatures, Permit2 Allowances, NFT Royalties & Proxy Timelocks: 2026 Security GuideErc721 Erc1155 Eip712 Permit Security
Blind-Signing Deprecation (eth_sign), Pre-Sign Transaction Simulation & EIP-7730 Clear SigningErc721 Erc1155 Eip712 Permit Security
ERC-1155 Batch Transfer Security: Mandatory Receiver Hooks, Array Mismatches & Gas-Bomb DoSErc721 Erc1155 Eip712 Permit Security
CREATE2 Metamorphic Contracts, Cancun EIP-6780 SELFDESTRUCT & Bytecode Provenance AuditsErc721 Erc1155 Eip712 Permit Security
EIP-7201 Namespaced Storage Layouts: Eliminating __gap Fragility in Upgradeable ProxiesErc721 Erc1155 Eip712 Permit Security
EIP-712 Domain Separator Engineering: Dynamic chainId Caching & Cross-Fork Replay DefenseErc721 Erc1155 Eip712 Permit Security
Uniswap Permit2 Security Audit: AllowanceTransfer vs SignatureTransfer & Witness PhishingErc721 Erc1155 Eip712 Permit Security
EIP-2612 ERC-20 Permit Audits: ecrecover Zero-Address, s-Malleability & Griefing FrontrunsCross Chain Bridge Validator Exploits
Solidity Fixed-Point Precision Audits: WAD/RAY Scaling, mulDiv Overflow & Rounding ExploitsCross Chain Bridge Validator Exploits
Cross-Chain Message Replay, Chain Reorgs & Finality Depth Engineering (safe vs finalized)Cross Chain Bridge Validator Exploits
Bug Bounty Escrows, Immunefi Vaults & SEAL Whitehat Safe Harbor On-Chain Rescue ProtocolsCross Chain Bridge Validator Exploits
Restaked Bridge & Oracle AVSs (EigenLayer / Symbiotic): Slashing Math & Corruptible-Majority Bounds
NFTVenue Ledger Data, Benchmarks & Contributor Records
CC BY 4.0 Open Data
Open Institutional Datasets (CSV / JSON) →
Download desk-compiled quantitative series & schemas.
2026 Reference Matrix
2026 Institutional Benchmarks & Thresholds →
Statutory capital, clearing, margin & rate conventions.
Editorial Records
Authors & Review Records →
View named contributors where those records are available.
Complete Index
Master Research & Dossier Archive →
Browse all published briefings by topic pillar & date.
