Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ReentrancyGuard status getter #3714

Merged
merged 15 commits into from
Oct 17, 2022
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ With the new `ERC721Consecutive` extension, the internal workings of `ERC721` ar
* `Initializable`: add a reinitializer modifier that enables the initialization of new modules, added to already initialized contracts through upgradeability. ([#3232](https://github.com/OpenZeppelin/openzeppelin-contracts/pull/3232))
* `Initializable`: add an Initialized event that tracks initialized version numbers. ([#3294](https://github.com/OpenZeppelin/openzeppelin-contracts/pull/3294))
* `ERC2981`: make `royaltyInfo` public to allow super call in overrides. ([#3305](https://github.com/OpenZeppelin/openzeppelin-contracts/pull/3305))
* `ReentrancyGuard`: Add a `_reentrancyGuardStatus` function to expose the guard status. ([#3713](https://github.com/OpenZeppelin/openzeppelin-contracts/pull/3713))

### Upgradeability notice

Expand Down
2 changes: 2 additions & 0 deletions contracts/mocks/ReentrancyMock.sol
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ contract ReentrancyMock is ReentrancyGuard {
_count();
bytes4 func = bytes4(keccak256("callback()"));
attacker.callSender(func);

require(_reentrancyGuardStatus() == 2, "ReentrancyMock: _reentrancyGuardStatus failed");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this is getting executed, the attacker line above probably reverts.

Please add a separate test specifically for the guard status, and for the various values it can have.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1 for specific testing

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

Sorry for late response, busy doing a bunch of other things lol:)

}

function _count() private {
Expand Down
7 changes: 7 additions & 0 deletions contracts/security/ReentrancyGuard.sol
Original file line number Diff line number Diff line change
Expand Up @@ -66,4 +66,11 @@ abstract contract ReentrancyGuard {
// https://eips.ethereum.org/EIPS/eip-2200)
_status = _NOT_ENTERED;
}

/**
* expose _status as internal function, the caller decides what to do with it
*/
function _reentrancyGuardStatus() internal view returns (uint256) {
return _status;
}
}