Revert to old ReentrancyGuard implementation
This commit is contained in:
parent
020e7609c3
commit
793e338dd3
@ -24,22 +24,26 @@ import "./LibRichErrors.sol";
|
||||
|
||||
contract ReentrancyGuard {
|
||||
|
||||
// Mutex counter.
|
||||
// Starts at 1 and increases whenever a nonReentrant function is called.
|
||||
uint256 private reentrancyGuardCounter = 1;
|
||||
// Locked state of mutex.
|
||||
bool private locked = false;
|
||||
|
||||
/// @dev Functions with this modifer cannot be reentered.
|
||||
/// @dev Functions with this modifer cannot be reentered. The mutex will be locked
|
||||
/// before function execution and unlocked after.
|
||||
modifier nonReentrant() {
|
||||
// Increment and remember the current counter value.
|
||||
uint256 localCounter = ++reentrancyGuardCounter;
|
||||
// Call the function.
|
||||
_;
|
||||
// If the counter value is different from what we remember, the function
|
||||
// was called more than once and an illegal reentrancy occured.
|
||||
if (localCounter != reentrancyGuardCounter) {
|
||||
// Ensure mutex is unlocked.
|
||||
if (locked) {
|
||||
LibRichErrors.rrevert(
|
||||
LibReentrancyGuardRichErrors.IllegalReentrancyError()
|
||||
);
|
||||
}
|
||||
|
||||
// Lock mutex before function call
|
||||
locked = true;
|
||||
|
||||
// Perform function call
|
||||
_;
|
||||
|
||||
// Unlock mutex after function call
|
||||
locked = false;
|
||||
}
|
||||
}
|
||||
|
@ -24,8 +24,6 @@ import "../src/ReentrancyGuard.sol";
|
||||
contract TestReentrancyGuard is
|
||||
ReentrancyGuard
|
||||
{
|
||||
uint256 internal counter = 2;
|
||||
|
||||
/// @dev Exposes the nonReentrant modifier publicly.
|
||||
/// @param shouldBeAttacked True if the contract should be attacked.
|
||||
/// @return True if successful.
|
||||
@ -47,19 +45,14 @@ contract TestReentrancyGuard is
|
||||
external
|
||||
returns (bool)
|
||||
{
|
||||
if (counter > 0) {
|
||||
counter--;
|
||||
this.guarded(true);
|
||||
} else {
|
||||
counter = 2;
|
||||
return true;
|
||||
}
|
||||
return this.guarded(true);
|
||||
}
|
||||
|
||||
/// @dev This is a function that will not reenter the current contract.
|
||||
/// @return True if successful.
|
||||
function nonExploitive()
|
||||
external
|
||||
pure
|
||||
returns (bool)
|
||||
{
|
||||
return true;
|
||||
|
Loading…
x
Reference in New Issue
Block a user