# Checks-Effects-Interactions (CEI) & EIP-1153 Transient Locks

> Architect reentrancy-proof Solidity systems: strict CEI ordering, ERC-777/ERC-1363 hidden callbacks, global cross-contract locks, and EIP-1153 TLOAD/TSTORE.

Canonical: https://nftvenueledger.com/protocols/cei-checks-effects-interactions-reentrancyguard-transient
Last updated: 2026-11-14T19:39:49.572Z

**Publication:** NFTVenue Ledger
**Category:** Cross Chain Bridge Validator Exploits
**Published:** 2026-11-13T14:25:25.915Z
**Author:** Dr. Devon Kurosawa, PhD (PhD in Distributed Systems & Cryptographic Protocol Verification)
**Reviewer:** Not recorded

## Answer-first summary

Ten years after The DAO hack, multi-contract and hidden-hook reentrancy remain top DeFi killers—demanding strict CEI state ordering paired with shared EIP-1153 transient semaphores.

## Key takeaways

- Local per-contract nonReentrant modifiers fail against cross-contract and read-only reentrancy; multi-contract protocols must share one centralized LockHub and assert !isEntered inside price/rate view getters.
- ERC-777 tokens invoke tokensToSend on the sender BEFORE updating balances—breaking balance-delta deposit accounting unless deposit itself carries nonReentrant.
- Cancun EIP-1153 TLOAD/TSTORE cuts reentrancy guard gas by 94% (~300 gas total) and powers Uniswap v4 transient flash-accounting deltas.
- Hardened protocols upgrade CEI to FREI-PI, adding post-interaction global solvency invariant assertions before releasing the transient lock.

## 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.
- **Concentrated Liquidity AMM Mathematical Specification** (CL-AMM) — product: Algorithmic market-making protocol allowing liquidity providers to allocate capital within discrete price intervals, maximizing capital efficiency.
- **Uniswap v4 Singleton & Hook Architecture** (UNI-V4) — product: Fourth-generation decentralized exchange protocol featuring a unified singleton contract and modular hooks that customize pool execution logic.

## Analysis

Single-function ETH `withdraw` reentrancy (`The 2016 DAO hack`) is caught in 2 seconds by static analyzers like Slither—yet reentrancy **still stole over `$350M` between 2022 and 2026**! Why? Because modern exploits pivot across **four subtler boundaries** where function-local `nonReentrant` modifiers fail completely:
1. **Cross-Function Reentrancy** (`entering transfer while inside withdraw`).
2. **Cross-Contract Shared-State Reentrancy** (`entering VaultDebtRouter while CollateralManager is mid-callback`).
3. **[Read-Only Reentrancy](/protocols/read-only-reentrancy-balancer-curve-lp-virtual-price-skew)** (`reading unguarded view getters while a mutating lock is active`).
4. **Hidden Token-Standard Callbacks** (`ERC-777 tokensToSend, ERC-1363 transferAndCall, ERC-721/1155 safeTransfer, and Uniswap v4 hooks`).

Anchored in our [cross-chain bridge, oracle & exploit RCA master guide](/protocols/cross-chain-bridge-verification-oracle-exploit-rca-guide-2026), mastering the **[Checks-Effects-Interactions (CEI) Smart-Contract Security Pattern](/tokens/cei-smart-contract-security-pattern)** alongside **Cancun EIP-1153 Global Transient Locks** protects every multi-contract DEX and lending suite across our [marketplaces directory](/marketplaces) (from [9mm Pro](/marketplaces/9mm-pro) to [Uniswap v4 singleton](/tokens/uniswap-v4-singleton-architecture) hook ecosystems).

## Why ERC-777 `tokensToSend` Breaks Even `ReentrancyGuard`-Free Accounting!

Watch how **Pre-Transfer Sender Hooks (`ERC-777 IMBTC / Lendf.Me $25M & Cream $18M exploits`)** flip developer intuition upside down!
- Suppose a lending market writes `deposit(token, amount)`:
 `uint256 beforeBal = token.balanceOf(address(this)); token.safeTransferFrom(msg.sender, address(this), amount); shares[msg.sender] += (token.balanceOf(address(this)) - beforeBal);`
- Look closely: in `deposit`, you MUST call `transferFrom` *before* measuring `balanceOf(after) - beforeBal` (`to handle fee-on-transfer tokens!`).
- **The Trap**: If `token` implements **ERC-777** (`e.g., legacy imBTC or AMP`) and `deposit` lacks `nonReentrant`, `transferFrom` calls **`IERC777Sender(msg.sender).tokensToSend` BEFORE moving balances**! Inside `tokensToSend`, the attacker calls `deposit` a *second* time: the inner `deposit` moves `100 tokens` and credits `+100 shares`, and when control unwinds to the outer `deposit`, `balanceOf(after) - beforeBal` sees **both** transfers (`+200`!) and credits `+200` *additional* shares (`300 shares minted for 200 tokens!`)!

![Universal Protocol-Wide Reentrancy Architecture combining Global EIP-1153 Hub Lock, Strict CEI, and View Inspection](/api/figure?type=flow&title=Protocol-Wide%20Global%20Transient%20Lock%20%2B%20Strict%20CEI%20Architecture&subtitle=Defeating%20cross-function%2C%20cross-contract%2C%20ERC-777%20pre-hook%2C%20and%20read-only%20view%20reentrancy%20in%20300%20gas&steps=1.%20Global%20Hub%20TSTORE%3A%3AEvery%20mutating%20router%2Fpool%20acquires%20ONE%20shared%20EIP-1153%20lock%20on%20Hub%7C2.%20Strict%20Checks%3A%3AValidate%20inputs%2C%20oracle%20freshness%2C%20and%20!Hub.isLocked%28%29%20on%20view%20reads!%7C3.%20Complete%20Effects%3A%3ACommit%20ALL%20storage%20accounting%2C%20burns%2C%20and%20event%20logs%20internally%7C4.%20Final%20Interactions%3A%3AExecute%20ETH%20transfers%2C%20ERC-20%2F721%20calls%20%26%20clear%20Hub%20TSTORE%20lock&metrics=EIP-1153%20TLOAD%2FTSTORE%3A%3A100%20Gas%20%2F%20Op%3A%3AAuto-wiped%20at%20end%20of%20EVM%20transaction%7CERC-1820%20REGISTRY%3A%3AERC-777%20Trap%3A%3APre-transfer%20tokensToSend%28%29%20sender%20hook!%7CFLASH%20ACCOUNTING%3A%3AUniswap%20v4%20Lock%3A%3AAllows%20controlled%20callback%20%2B%20delta%3D%3D0%7CVIEW%20GUARD%20COST%3A%3A100g%20TLOAD%3A%3ABlocks%20read-only%20reentrancy%20cleanly)

## Controlled Reentrancy (`Flash Accounting`) vs Accidental Reentrancy!

Wait: if reentrancy is blocked globally, how does the **[Uniswap v4 Singleton](/tokens/uniswap-v4-singleton-architecture)** (`PoolManager.unlock`) or Balancer V3 allow flash swaps and multi-hop settlement callbacks?!
By replacing ad-hoc callbacks with **Explicit Invariant-Gated Flash Accounting (`Transient Currency Deltas`)**:
1. External callers **cannot** call `PoolManager.swap` or `modifyLiquidity` directly (`reverts ManagerLocked`).
2. Instead, the caller invokes `PoolManager.unlock(data)`, which sets `isUnlocked = true` in EIP-1153 transient storage and calls `IUnlockCallback(msg.sender).unlockCallback(data)`.
3. Inside `unlockCallback`, the router executes 5 hops, accumulating signed `int256` net currency deltas in transient storage (`zero ERC-20 transfers mid-route!`), settles net balances at the end, and **`unlock` reverts the entire transaction unless `NonzeroDeltaCount == 0`** upon exit!

## Reentrancy Vector & Defense Coverage Matrix

| Reentrancy Variant | Why Local `nonReentrant` Fails | Exploited Real-World Examples | Deterministic Architectural Fix |
| :--- | :--- | :--- | :--- |
| Single-Function ETH Callback | N/A (Local guard blocks it) | The DAO ($60M), SpankChain | CEI + Local `ReentrancyGuardTransient` |
| Cross-Function (Same Contract) | Developer forgot `nonReentrant` on `transfer` | Fei Rari ($80M), Omni ($1.4M) | Apply `nonReentrant` to **100% of external mutators** |
| **Cross-Contract (Multi-Module)** | Contract A & Contract B have **separate** `_status` slots! | Cream / Hundred Finance, Market.xyz | **Centralized `LockHub`** (`1 shared lock across suite!`) |
| **[Read-Only View Reentrancy](/protocols/read-only-reentrancy-balancer-curve-lp-virtual-price-skew)** | `view` getters omit `nonReentrant` | Sentiment, Sturdy, Midas | Assert `!reentrancyGuardEntered` inside `getPrice` / `getRate`! |

![EVM gas overhead of reentrancy guards across multi-contract calls using SSTORE vs Cancun EIP-1153 TSTORE](/api/figure?type=bars&title=Protocol-Wide%20Lock%20Overhead%3A%20Legacy%20Storage%20vs%20EIP-1153&subtitle=Total%20gas%20consumed%20by%20reentrancy%20protection%20%2B%20view-oracle%20lock%20checks%20across%20a%203-contract%20DeFi%20tx&steps=3%20Separate%20SSTORE%20Locks%3A%3A~15%2C300%20gas%20AND%20still%20vulnerable%20to%20cross-contract%20reentrancy!%7CShared%20External%20SSTORE%20Hub%3A%3A~7%2C800%20gas%20%28external%20CALLs%20%2B%20warm%20storage%20writes%2Fclears%29%7CLocal%20EIP-1153%20Transient%3A%3A~300%20gas%20per%20contract%20%28-94%25%20gas%20vs%20OpenZeppelin%20v4%20SSTORE%29%7CSingleton%20%2B%20EIP-1153%20TSTORE%3A%3A~300%20gas%20TOTAL%20%2B%20100-gas%20TLOAD%20read-only%20oracle%20protection!&metrics=VYPER%20SAFE%20VERSION%3A%3A%3E%3D%200.3.10%20%2F%200.4%2B%3A%3APatched%20slot-allocation%20compiler%20bug%7CSLITHER%20CI%20RULE%3A%3Areentrancy-*%20%3D%3D%200%3A%3AZero%20unreviewed%20external-before-write%7CFREI-PI%20PATTERN%3A%3APre%20%2B%20Post%20Invariant%3A%3AFunction%20Requirements-Effects-Interactions-Protocol%20Invariants%7CGAS%20STIPEND%20MYTH%3A%3ANever%20Trust%202%2C300g%3A%3AEIP-2929%2FEIP-1884%20broke%20transfer%28%29%2Fsend%28%29)

## Extending CEI to **FREI-PI** (`Protocol Invariant Post-Checks`)

Nascent and Trail of Bits security engineers extend classic `CEI` into **`FREI-PI` (`Function Requirements -> Effects -> Interactions -> Protocol Invariants`)**—asserting global vault solvency **both before AND after** any external token interaction:

```formula
1) Classic CEI vs Hardened FREI-PI Execution Ordering:
 [F] Function Requirements: require(!globalLock.isEntered && amount > 0 && authOk); globalLock.enter;
 [E] Effects (Internal State): userDebt[u] += borrowAmt; totalDebt += borrowAmt; [100% committed BEFORE call!]
 [I] Interactions (Untrusted): IERC20(asset).safeTransfer(u, borrowAmt); [Untrusted ERC-777 / 7702 call]
 [PI] Protocol Invariants: require(getHealthFactor(u) >= 1e18 && cash + totalDebt >= totalShares, "SolvencyBroken!");
 globalLock.exit;

2) Why Never Use Solidity .transfer(amt) or .send(amt) (2,300 Gas Stipend Anti-Pattern):
 - Breaks legitimate Safe multisig & EIP-7702 smart-contract wallets (whose receive needs >2,300 gas)!
 - Does NOT stop gas-less state exploits if future EVM opcode repricing lowers SLOAD/TSTORE costs!
 => ALWAYS use: (bool ok, ) = to.call{value: amt}(""); require(ok); GATED BY CEI + ReentrancyGuardTransient!
```

## Defending Governance Contracts Against Same-Block Flash Borrowing Next

Even when every lending and swap function enforces airtight `FREI-PI` + `EIP-1153` locks, what stops an attacker from flash-borrowing `$50,000,000` of governance tokens, passing an instant malicious proposal, and repaying the flash loan in **12 seconds**? Audit governance checkpoints next in [flash-loan governance quorum hijacks & snapshot checkpointing](/protocols/flash-loan-governance-quorum-hijack-snapshot-checkpointing) inside our [Cross-Chain Bridge & Oracle Security hub](/topics/cross-chain-bridge-validator-exploits).

## Frequently asked questions

### Why is Solidity payable(user).transfer(ethAmount) considered a dangerous anti-pattern today?

transfer hardcodes a 2,300-gas stipend, causing legitimate withdrawals to Gnosis Safe multisigs, proxies, and EIP-7702 smart accounts to revert out-of-gas; use .call{value: amt}("") protected by CEI and ReentrancyGuardTransient.

### How did ERC-777 tokens drain Lendf.Me ($25M) and Cream Finance ($18.8M) without any ETH callback?

ERC-777 registers a pre-transfer sender hook via ERC-1820 (tokensToSend), handing execution back to the attacker contract inside ERC20 transferFrom BEFORE token balances move.

### Why can two contracts that BOTH use OpenZeppelin ReentrancyGuard still suffer cross-contract reentrancy?

Each contract stores its own independent _status variable; when Contract A locks A._status and sends ETH, the attacker callback can still enter Contract B (where B._status is unlocked) and mutate shared state.

### What is the FREI-PI security pattern in DeFi smart contracts?

Coined by Nascent, FREI-PI stands for Function Requirements, Effects, Interactions, and Protocol Invariants—appending explicit post-call global solvency checks (such as HealthFactor >= 1.0) after external interactions.


## Source URLs

- https://docs.openzeppelin.com/contracts/5.x/api/utils#ReentrancyGuardTransient
- https://eips.ethereum.org/EIPS/eip-1153
- https://detectors.auditbase.com/cei-pattern-solidity

## Citation

- APA: Dr. Devon Kurosawa, PhD. (2026). Checks-Effects-Interactions (CEI), Cross-Contract Locks & Cancun EIP-1153 Transient Guards. NFTVenue Ledger. https://nftvenueledger.com/protocols/cei-checks-effects-interactions-reentrancyguard-transient
- Canonical article: [Checks-Effects-Interactions (CEI), Cross-Contract Locks & Cancun EIP-1153 Transient Guards](https://nftvenueledger.com/protocols/cei-checks-effects-interactions-reentrancyguard-transient)
- Site research index: [NFTVenue Ledger](https://nftvenueledger.com/llms-full.txt)
