-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix reentrancy by protecting podBalanceOf() and balanceOf() from acce…
…ss during updateBalances() loop
- Loading branch information
Showing
2 changed files
with
58 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
// SPDX-License-Identifier: MIT | ||
|
||
pragma solidity ^0.8.0; | ||
|
||
library ReentrancyGuardLib { | ||
error ReentrantCall(); | ||
|
||
uint256 private constant _NOT_ENTERED = 1; | ||
uint256 private constant _ENTERED = 2; | ||
|
||
struct Data { | ||
uint256 _status; | ||
} | ||
|
||
function init(Data storage self) internal { | ||
self._status = _NOT_ENTERED; | ||
} | ||
|
||
function enter(Data storage self) internal { | ||
if (self._status == _ENTERED) revert ReentrantCall(); | ||
self._status = _ENTERED; | ||
} | ||
|
||
function exit(Data storage self) internal { | ||
self._status = _NOT_ENTERED; | ||
} | ||
|
||
function check(Data storage self) internal view returns (bool) { | ||
return self._status == _ENTERED; | ||
} | ||
} | ||
|
||
contract ReentrancyGuardExt { | ||
using ReentrancyGuardLib for ReentrancyGuardLib.Data; | ||
error AccessDenied(); | ||
|
||
modifier nonReentrant(ReentrancyGuardLib.Data storage self) { | ||
self.enter(); | ||
_; | ||
self.exit(); | ||
} | ||
|
||
modifier nonReentrantView(ReentrancyGuardLib.Data storage self) { | ||
if (self.check()) revert ReentrancyGuardLib.ReentrantCall(); | ||
_; | ||
} | ||
} |