OpenZeppelin / OpenZeppelin/openzeppelin-contracts

ReentrancyGuard should expose the `_status` publicly

Open
#3,829 3 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Solidity
Stars
27.2k
Forks
12.4k
Avg merge
2d 19h
Merged PRs (30d)
33

Description

🧐 Motivation

An increasingly common security issue is "read-only reentrancy". These issues arise when protocol A relies on the state of protocol B, and protocol B's state can temporarily be manipulated. Even if protocol B uses reentrancy guards to protect against this manipulated state, protocol A can't inspect B's reentrancy guard itself, which can make integration nearly impossible. Some recent examples of this issue include a vulnerable integration with Euler and vulnerable integrations with Curve. In the case of the Curve integration bugs, the only fix for the vulnerability was to add an otherwise unnecessary call to a state modifying function that has a nonReentrant guard, which is a very hacky fix. In some cases, there might not be a good nonReentrant function that can be called "for free", so the mitigation would involve try-catching a call to such a function and inspecting if the error message is "ReentrancyGuard: reentrant call", which would be an even uglier fix.

📝 Details

It would make much more sense for ReentrancyGuard.sol to expose the _status variable publicly in some way. A simple fix for this would be to mark the internal _reentrancyGuardEntered function as public:

- function _reentrancyGuardEntered() internal view returns (bool) {
+ function reentrancyGuardEntered() public view returns (bool) {
     return _status == _ENTERED;
 }

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start in contracts/security/ReentrancyGuard.sol at _reentrancyGuardEntered and review how _status and the guard constants are used. Make the reentrancy state externally inspectable without changing guard behavior, then verify the existing ReentrancyGuard coverage still passes and confirms the new public access.

Written by the indexing model from the issue text.

Assessment

Tech stack
solidity
Domain
blockchain, security
Issue type
Feature
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
52/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.