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

Fix ReentrancyGuard for Proxy Pattern #2171

Merged
merged 5 commits into from
May 12, 2020
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 8 additions & 5 deletions contracts/utils/ReentrancyGuard.sol
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,10 @@ pragma solidity ^0.6.0;
* https://blog.openzeppelin.com/reentrancy-after-istanbul/[Reentrancy After Istanbul].
*/
contract ReentrancyGuard {
bool private _notEntered;
uint256 private constant _NOT_ENTERED = 1;
uint256 private constant _ENTERED = uint256(int256(-1));
nventuro marked this conversation as resolved.
Show resolved Hide resolved

uint256 private _status;
frangio marked this conversation as resolved.
Show resolved Hide resolved

constructor () internal {
// Storing an initial non-zero value makes deployment a bit more
Expand All @@ -26,7 +29,7 @@ contract ReentrancyGuard {
// the total transaction's gas, it is best to keep them low in cases
// like this one, to increase the likelihood of the full refund coming
// into effect.
_notEntered = true;
_status = _NOT_ENTERED;
}

/**
Expand All @@ -38,15 +41,15 @@ contract ReentrancyGuard {
*/
modifier nonReentrant() {
// On the first call to nonReentrant, _notEntered will be true
require(_notEntered, "ReentrancyGuard: reentrant call");
require(_status != _ENTERED, "ReentrancyGuard: reentrant call");

// Any calls to nonReentrant after this point will fail
_notEntered = false;
_status = _ENTERED;

_;

// By storing the original value once again, a refund is triggered (see
// https://eips.ethereum.org/EIPS/eip-2200)
_notEntered = true;
_status = _NOT_ENTERED;
}
}