# ERC-1155 Batch Transfer Security: Hooks & Gas-Bomb DoS

> Audit EIP-1155 safeBatchTransferFrom: mandatory onERC1155BatchReceived (0xbc197c81) return-bomb/gas griefing, duplicate-ID balance bugs, and marketplace sweeps.

Canonical: https://nftvenueledger.com/protocols/erc1155-batch-transfer-hook-gas-stipend-dos-marketplace
Last updated: 2026-11-14T19:48:24.508Z

**Publication:** NFTVenue Ledger
**Category:** Erc721 Erc1155 Eip712 Permit Security
**Published:** 2026-11-13T18:35:25.915Z
**Author:** Dr. Devon Kurosawa, PhD (PhD in Distributed Systems & Cryptographic Protocol Verification)
**Reviewer:** Not recorded

## Answer-first summary

Unlike ERC-721, EIP-1155 omits non-callback transfers entirely—making mandatory onERC1155Received and onERC1155BatchReceived hooks prime vectors for return-bomb and batch-sweep DoS.

## Key takeaways

- Unlike ERC-721, EIP-1155 provides zero non-callback transfer function—every single and batch transfer to a contract address invokes 0xf23a6e61 or 0xbc197c81.
- Custom safeBatchTransferFrom implementations must never pre-cache _balances before looping—passing duplicate token IDs (e.g., [42, 42]) and from == to inflates supply instantly.
- High-level Solidity try/catch forwards 63/64 gas and copies unbounded returndata, enabling toxic listings to Return-Bomb multi-item marketplace floor sweepers.
- Inline assembly hooks capping subcall gas and bounding output buffer size to 32 bytes (0x20) neutralize both gas-stipend and quadratic memory-expansion DoS.

## Related financial entities

- **Checks-Effects-Interactions (CEI) Security Pattern** (CEI-SEC) — product: Foundational programming design pattern in smart contract development preventing reentrancy attacks by executing internal state updates before external calls.
- **ERC-2981 NFT Royalty Standard** (ERC-2981) — product: Universal Ethereum standard allowing contracts to signal a royalty payout amount and receiver address upon token sales.
- **Seaport Marketplace Protocol Standard** (SEAPORT) — product: Open-source, highly optimized marketplace contract suite for efficiently buying and selling fungible and non-fungible tokens.

## Analysis

Gaming inventories, fractionalized RWA tranches, and open-edition art collections across our [marketplaces directory](/marketplaces)—such as [Basepaint](/marketplaces/basepaint), [Avarik Saga](/marketplaces/avarik-saga), [Art Blocks X Bright Moments](/marketplaces/art-blocks-x-bright-moments), and [Async Blueprints](/marketplaces/async-blueprints)—overwhelmingly prefer **EIP-1155 Multi-Token Contracts** because transferring 50 distinct items in one `safeBatchTransferFrom(from, to, ids, values, data)` call saves up to `80%` gas over 50 separate ERC-721 transfers.

Yet as detailed in our [EIP-712, Permit2 & proxy security master guide](/protocols/eip712-permit2-erc721-royalty-proxy-timelock-security-2026), EIP-1155 contains two architectural surprises that repeatedly break NFT aggregators, lending liquidators, and custom token implementations: **(1) EIP-1155 has NO `transferFrom` without callbacks—every single transfer triggers `0xf23a6e61` or `0xbc197c81` on contract recipients**, and **(2) custom `safeBatchTransferFrom` loops frequently introduce fatal Duplicate-ID Balance Overwrite Bugs**!

## Fatal Bug #1: Caching Balances Across Duplicate `ids` in `safeBatchTransferFrom`!

Watch how custom gas-optimized ERC-1155 implementations get drained for infinite tokens in 1 transaction when developers rewrite OpenZeppelin's `safeBatchTransferFrom` loop carelessly:
- Suppose an attacker calls `safeBatchTransferFrom(attacker, attacker, [42, 42], [100, 100], "")` passing **the exact same `id = 42` twice** inside `ids`!
- If a developer reads `uint256 fromBal_i = _balances[42][from]; uint256 toBal_i = _balances[42][to];` into memory arrays *before* the update loop (or caches `toBal` when `from == to`!), iteration 1 writes `_balances[42] = 100`, and iteration 2 adds `+100` onto stale `toBal_i` (or skips subtracting twice)—**doubling the attacker's token balance out of thin air on every call**!
- **Mandatory Audit Invariant**: Inside every `for (uint256 i = 0; i < ids.length; ++i)` iteration, read and write storage `_balances[id][from] -= value` and `_balances[id][to] += value` **sequentially per element**, never caching across array indices, and strictly assert `ids.length == values.length`!

![ERC-1155 safeBatchTransferFrom CEI execution, memory return-bomb defense, and aggregator try-catch isolation](/api/figure?type=flow&title=Hardened%20ERC-1155%20Batch%20Settlement%20%26%20Aggregator%20Isolation&subtitle=Defeating%20duplicate-ID%20balance%20inflation%2C%20return-data%20memory%20bombs%2C%20and%20toxic-listing%20DoS&steps=1.%20Array%20%26%20CEI%20Update%3A%3AAssert%20ids.length%20%3D%3D%20values.length%3B%20update%20_balances%20sequentially%20FIRST!%7C2.%20Emit%20TransferBatch%3A%3AEmit%20canonical%20TransferBatch%20event%20BEFORE%20external%20receiver%20hook%7C3.%20Bounded%20Hook%20Call%3A%3AAssembly%20call%20capping%20gas%20%26%20copying%20ONLY%2032%20bytes%20returndata%20%28no%20bomb!%29%7C4.%20Sweeper%20Isolation%3A%3AMarketplace%20floor-sweeper%20wraps%20each%20item%20in%20gas-capped%20try-catch&metrics=SINGLE%20HOOK%20ID%3A%3A0xf23a6e61%3A%3AonERC1155Received%20magic%20selector%7CBATCH%20HOOK%20ID%3A%3A0xbc197c81%3A%3AonERC1155BatchReceived%20selector%7CRETURNDATA%20BOMB%3A%3AQuadratic%20Mem%20Gas%3A%3AHigh-level%20Solidity%20copies%20full%20bytes!%7CNO%20UNSAFE%20ESCAPE%3A%3A100%25%20Hooked%3A%3AUnlike%20ERC-721%2C%20no%20non-hook%20transfer!)

## Fatal Bug #2: Floor-Sweeper & Liquidation DoS (`Gas Bomb + Return Bomb`)

Because EIP-1155 provides **zero non-callback transfer function**, what happens when a borrower locks an ERC-1155 asset inside a lending protocol (`or lists the cheapest item on the floor against a 20-item aggregator sweep on Seaport`) via a smart-contract address whose `onERC1155Received` executes **`invalid`** or returns **`2,000,000 bytes` of junk memory (`Return-Data Bomb`)**?

1. **63/64 Gas Griefing**: High-level Solidity `to.onERC1155Received(...)` forwards `63/64` of the transaction's entire remaining gas (`EIP-150`). If a marketplace aggregator wraps 20 floor items inside `try seaport.fulfillOrder(...) {} catch {}` **without capping forwarded gas**, 1 malicious seller's contract burns `98.4%` of `gasleft`, causing the outer aggregator transaction to run out of gas and revert all 19 honest sales!
2. **Quadratic Memory Expansion ("Return Bomb")**: Even if you cap `call{gas: 100_000}(...)`, high-level Solidity `try ... catch (bytes memory reason)` automatically executes `RETURNDATACOPY` on the entire returned payload! An attacker uses `100k` gas inside the subcall to return a massive byte buffer that triggers **quadratic memory expansion gas in the parent contract**, blowing through the caller's remaining gas!

## ERC-721 vs ERC-1155 Security & Marketplace Settlement Matrix

| Security / Settlement Property | ERC-721 Single-Asset Standard | ERC-1155 Multi-Token Standard | Mandatory Marketplace / Vault Fix |
| :--- | :--- | :--- | :--- |
| Non-Callback Fallback Transfer? | **Yes** (`transferFrom` skips hook) | **NO!** Every transfer calls `0xf23a6e61` / `0xbc197c81` | Liquidations seize to **Liquidator**, never push to Borrower! |
| Duplicate Token IDs in Batch | Impossible (1 `tokenId` per call) | **Allowed** (`ids = [7, 7]`) | Never cache `_balances` in memory prior to loop! |
| Floor-Sweep Aggregator Poisoning | Seller ETH `receive` gas/return bomb | Seller ETH + Buyer/Seller 1155 hook bombs | Low-level Yul `call(capGas, ...)` with `0` returndata copy! |
| Partial-Fill Order Support | Indivisible (`amount == 1`) | Native fungible `values` (`Seaport PARTIAL`) | Enforce exact fraction divisibility ([Seaport math](/protocols/seaport-order-conduit-zones-bulk-merkle-cancellation-trees)) |

![Gas cost of transferring 25 NFTs across ERC-721 loop, ERC-1155 safeBatchTransferFrom, and Return-Bomb safe call](/api/figure?type=bars&title=25-Item%20Batch%20Settlement%20Gas%20%26%20Return-Bomb%20Protection&subtitle=L1%20gas%20units%20consumed%20across%20batch%20transfers%20and%20assembly%20gas-capped%20aggregator%20routers&steps=25x%20Separate%20ERC-721%3A%3A~740%2C000%20gas%20%2825%20external%20calls%20%2B%2025%20separate%20ownership%20SSTOREs%29%7CERC-1155%20Batch%20%28Same%20Collection%29%3A%3A~168%2C000%20gas%20%28-77%25%20gas!%201%20external%20call%20%2B%201%20batch%20hook%20check%29%7CNaive%20Solidity%20try%2Fcatch%20Sweep%3A%3AVULNERABLE%3A%201%20malicious%20listing%20burns%2063%2F64%20gas%20or%20Return-Bombs!%7CYul%20ExcessivelySafeCall%20Sweep%3A%3AIMMUNE%3A%20Caps%20per-item%20gas%20%2B%20copies%20max%20256B%20revert%20data!&metrics=BATCH%20GAS%20SAVING%3A%3A-72%25%20to%20-80%25%3A%3A1%20external%20call%20%2B%201%20TransferBatch%20log%7CSAFE%20COPY%20CAP%3A%3A%3C%3D%2032%20-%20256B%3A%3ABlocks%20quadratic%20memory%20expansion%7CCEI%20HOOK%20ORDER%3A%3ABalances%20-%3E%20Hook%3A%3AStrict%20EIP-1155%20spec%20requirement%7CSELF-TRANSFER%3A%3Afrom%20%3D%3D%20to%20Test%3A%3AMandatory%20Foundry%20fuzz%20invariant!)

## Quadratic EVM Memory Expansion ("Return Bomb") Cost Formula & Assembly Shield

Why does copying `M = 65,536 bytes` (`2,048` 32-byte words) of malicious `returndata` destroy a parent contract's gas budget? Because EVM memory cost scales **quadratically** as `floor(words^2 / 512) + 3 * words`:

```formula
1) EVM Quadratic Memory Expansion Cost (Exploited by Return-Data Bombs):
 Memory_Gas(W words) = 3 * W + floor( W^2 / 512 )
 Example: Child subcall uses MSTORE8 at offset 131,072 (W = 4,096 words = 128 KB) & RETURN(0, 131072):
 If parent executes high-level Solidity try/catch (auto-copies full 128 KB into parent memory):
 Parent_Copy_Cost = 3*(4,096) + (4,096^2 / 512) + Copy_Words_Cost = 12,288 + 32,768 + 12,288 = 57,344+ unexpected gas!
 At 512 KB (W = 16,384): Parent_Copy_Cost = 573,440 gas -> Instant Out-Of-Gas parent revert!

2) Bomb-Proof Inline Yul ERC-1155 Hook Verification:
 let success := call(hookGasCap, to, 0, ptr, calldataLen, 0x00, 0x20) // Pre-caps output write to EXACTLY 32 bytes at 0x00!
 let magicOk := and(success, and(gt(returndatasize, 0x1f), eq(mload(0x00), shl(224, 0xbc197c81))))
 // Zero RETURNDATACOPY of arbitrary buffers -> Return-Bomb cost = 0 gas!
```

## Auditing Immutable vs Secretly Mutable Bytecode Next

Even when an ERC-1155 or marketplace Conduit appears to have **zero proxy admin** on Etherscan, can a malicious deployer wipe its bytecode and redeploy a drainer **at the exact same Ethereum address**? Examine `CREATE2` + `SELFDESTRUCT` traps next in [CREATE2 metamorphic redeployment detection](/protocols/create2-metamorphic-contract-redeployment-rug-detection) and [ERC-721 callback reentrancy](/protocols/erc721-safetransferfrom-onerc721received-callback-reentrancy) inside our [EIP-712, Permit2 & Proxy Security hub](/topics/erc721-erc1155-eip712-permit-security).

## Frequently asked questions

### How does the duplicate-ID balance inflation bug happen in custom ERC-1155 contracts?

If a developer reads sender and receiver balances into memory arrays before the transfer loop, submitting safeBatchTransferFrom(me, me, [1, 1], [100, 100]) overwrites the updated balance with stale cached math and mints free tokens.

### Why can a borrower freeze an ERC-1155 liquidation if the vault pushes collateral back?

Because ERC-1155 lacks a non-callback transferFrom, pushing excess ERC-1155 tokens back to a borrower contract lets the borrower revert inside onERC1155Received; vaults must hold surpluses in pull-claim escrows.

### What is a Return-Data Bomb in NFT marketplace aggregators?

When an aggregator wraps external fills in Solidity try/catch (bytes memory reason), Solidity copies the entire revert buffer into memory; returning 256 KB–512 KB triggers quadratic memory gas costs that crash the entire sweep.

### How does EIP-1155 enforce Checks-Effects-Interactions inside the standard itself?

The EIP-1155 specification explicitly mandates updating state balances and emitting TransferSingle/TransferBatch events BEFORE calling onERC1155Received or onERC1155BatchReceived.


## Source URLs

- https://eips.ethereum.org/EIPS/eip-1155
- https://docs.openzeppelin.com/contracts/5.x/api/token/ERC1155
- https://github.com/nomad-xyz/ExcessivelySafeCall

## Citation

- APA: Dr. Devon Kurosawa, PhD. (2026). ERC-1155 Batch Transfer Security: Mandatory Receiver Hooks, Array Mismatches & Gas-Bomb DoS. NFTVenue Ledger. https://nftvenueledger.com/protocols/erc1155-batch-transfer-hook-gas-stipend-dos-marketplace
- Canonical article: [ERC-1155 Batch Transfer Security: Mandatory Receiver Hooks, Array Mismatches & Gas-Bomb DoS](https://nftvenueledger.com/protocols/erc1155-batch-transfer-hook-gas-stipend-dos-marketplace)
- Site research index: [NFTVenue Ledger](https://nftvenueledger.com/llms-full.txt)
