Do Reentrancy Guards Protect against Both Single-Function and Cross-Function Attacks?

Yes, a properly implemented reentrancy guard can protect against both types of attacks. The guard typically uses a lock that is applied at the contract level, not just for a single function.

When any function with the guard modifier is entered, the lock is activated. If an external call from this function leads to a re-entrant call to any other function that also has the guard, the second function will see the lock is active and will revert the transaction.

This prevents both recursive calls to the same function and calls to other state-sharing functions within the contract.

What Is a ‘Reentrancy Attack’?
Can This Attack Be Prevented by Using a Non-Reentrant Lock?
How Can a Time-Lock Smart Contract Be Used to Prevent the Immediate Withdrawal of LP Tokens?
What Is a “Reentrancy Attack” in Smart Contract Security?
What Is the Role of a Fallback Function in Facilitating a Reentrancy Attack?
How Does the Nonreentrant Modifier Implement the CEI Principle?
How Can Reentrancy Attacks Be Prevented in Smart Contracts?
Can a Reentrancy Attack Be Performed without a Fallback Function?

Glossar