Skip to content
This repository has been archived by the owner on Jul 9, 2021. It is now read-only.

Commit

Permalink
Revert to old ReentrancyGuard implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
abandeali1 committed Aug 25, 2019
1 parent 3cd327a commit 83a3eb1
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 18 deletions.
26 changes: 15 additions & 11 deletions contracts/utils/contracts/src/ReentrancyGuard.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
9 changes: 2 additions & 7 deletions contracts/utils/contracts/test/TestReentrancyGuard.sol
Original file line number Diff line number Diff line change
Expand Up @@ -47,19 +47,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;
Expand Down

0 comments on commit 83a3eb1

Please sign in to comment.