Solidity security: The Reentrancy Guard pattern
In this story, I focus on one of the pattern to protect against one of the main attacks: Reentrancy attack.
ReentrancyGuard
prevents reentrant calls to a function.
By inheriting ReentrancyGuard
, a contract can use the nonReentrant
modifier, which ensures that a function cannot have nested (reentrant) calls to it.
There is one limitation: functions marked as nonReentrant
cannot call each other.
Example
// SPDX-License-Identifier: GPL-3.0
pragma…