> For the complete documentation index, see [llms.txt](https://notes.nomanaziz.me/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://notes.nomanaziz.me/development/blockchain/freecodecamp-course/13.-reentrancy-attack.md).

# 13. Reentrancy Attack

## Problem

* If we call a function of another contract in the middle of a **withdraw**, the other contract may have malicious function which may recalls the withdraw function again and again resulting in draining of all the funds
* <https://solidity-by-example.org/hacks/re-entrancy/>

## Solution (Easy Way)

* Always call another contract in the last step of transaction
* Updated balances (**change state**) before calling another contract

## Solution (Mutex)

* Use a mutex
* Openzepplin provides a way to safeguard i.e a Modifier
  * Contract name is [**ReentrancyGuard**](https://docs.openzeppelin.com/contracts/4.x/api/security#ReentrancyGuard)

***
