Join our Newsletter — 33% off our NHI Course
Home› Glossary› Architecture & Implementation› Reentrancy Lock
Architecture & Implementation

Reentrancy Lock

← Back to Glossary
By NHI Mgmt Group Updated October 29, 2026 Domain: Architecture & Implementation

A reentrancy lock is a state flag used in smart contracts to stop the same function being entered again before the first call finishes. It blocks recursive or nested execution during an external call, reducing the risk that an attacker can repeat state-changing actions before balances or permissions are updated.

What the Reentrancy Lock Actually Prevents

A reentrancy lock is a defensive state flag in smart contracts that prevents a function from being entered again while its first execution is still in progress. It is designed to stop nested or recursive calls from observing an inconsistent intermediate state.

This matters because many contract exploits depend on triggering an external call before balances, ownership, or other critical state variables have been updated. By forcing a single active execution path, the lock narrows the window in which an attacker can repeat a state-changing action.

Why Reentrancy Becomes Dangerous in Contract Execution

Reentrancy is dangerous when a contract interacts with an external address or contract and then continues processing after control returns. If the contract has not yet finalized its own state, the external call can re-enter the same logic and exploit assumptions that were only true at the start of execution.

The problem is not recursion by itself, but uncontrolled re-entry across a trust boundary. Any function that sends value, calls an untrusted contract, or depends on post-call invariants can become sensitive to this pattern.

How the Lock Changes Control Flow and State Safety

The lock works by marking the function, or sometimes the whole contract, as busy before the external interaction occurs, then clearing the flag only after the function completes. That simple guard prevents the same protected code path from being entered again until the original call has finished updating state.

In practice, a reentrancy lock is often paired with disciplined ordering of state changes, so the contract records the outcome first and only then performs external interactions. The lock is a safeguard, not a substitute for safe execution design, because it does not fix broken accounting logic or unsafe external dependencies on its own.

For a broader view of how reentrancy fits into smart contract defense, see the Smart Contract Security Guide and the OWASP Smart Contract Top 10 Guide.

Common Failure Modes and Design Limits

Reentrancy locks can fail when they are applied too narrowly, bypassed through alternate code paths, or introduced into contracts that still make unsafe assumptions about external calls. They also need careful handling in upgradeable or composable systems, where multiple execution paths may touch the same mutable state.

They are most effective when combined with checks-effects-interactions discipline, minimal external calls during sensitive state transitions, and clear separation between internal accounting and external side effects. A lock reduces exposure, but it does not eliminate the need to reason about every callable path that can touch value or permissions.

Risk and Threat Considerations

Reentrancy is a high-impact failure pattern because it can let an attacker repeat withdrawals, duplicate state transitions, or bypass business rules before the contract finishes updating its own records. In systems that hold value or manage permissions, that can turn a single call into a multi-step drain or unauthorized action.

Failure mechanism: The attacker uses an external call to re-enter the same function before state changes are finalized, exploiting the gap between control transfer and post-call state updates.

Impact: Funds, assets, or privileges can be manipulated more than once from a single initiating transaction, which can lead to direct loss, corrupted balances, and compromised contract integrity.

Standards & Framework Alignment

This section maps relevant standards and security frameworks to the operational risks and controls described in this guidance.

MITRE ATT&CK addresses the attack and risk surface, while OWASP ASVS, CIS Controls v8 and OWASP SAMM set the governance and control requirements practitioners need to meet.

FrameworkControl / ReferenceRelevance
OWASP ASVSV15 — Secure Coding and ArchitectureReentrancy locks are a defensive coding pattern for controlling unsafe execution flow in contract logic.
Recommendation — Design contract flows to preserve invariants before any external interaction can re-enter the same logic.
CIS Controls v8CIS-16 — Application Software SecurityThe term concerns secure application logic and preventing exploitable coding flaws in deployed software.
Recommendation — Review application code paths for state-changing logic that can be re-entered before invariants are restored.
OWASP SAMMDesign — DesignReentrancy protection belongs in secure design practices for software that handles value or critical state.
Recommendation — Embed reentrancy-safe execution patterns into security design reviews for contract development.
MITRE ATT&CKT1499 — Endpoint Denial of ServiceReentrancy-style abuse can repeatedly trigger costly or destabilizing execution paths in software systems.
Recommendation — Map repeated call abuse to attack-path analysis and monitor for abnormal nested execution patterns.

Practitioner Guidance

What to watch for: Treat any function that performs an external call before finalizing state as a review candidate. The most important judgement is not whether a lock exists, but whether every relevant execution path preserves invariants even if control briefly leaves the contract.

Practitioner takeaway: Use the lock as one layer in a broader contract safety pattern, and verify that the contract remains correct even when an external callee behaves adversarially.

Free weekly newsletter

Subscribe to the NHI & AI Identity Journal

The latest on NHI and Agentic AI security – articles, research, breaches, news and events every week.

Bonus 33% off our NHI Course when you subscribe.

NHIMG Editorial Note
Reviewed and updated by the NHIMG editorial team on October 29, 2026.
NHI Mgmt Group — the #1 independent authority on Non-Human Identity, IAM, and Agentic AI security. nhimg.org