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

refactor: optimize reentrancy guard #1017

Open
wants to merge 1 commit into
base: slashing-magnitudes-fixes
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all 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
8 changes: 5 additions & 3 deletions src/contracts/core/AVSDirectory.sol
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,20 @@ pragma solidity ^0.8.27;

import "@openzeppelin-upgrades/contracts/proxy/utils/Initializable.sol";
import "@openzeppelin-upgrades/contracts/access/OwnableUpgradeable.sol";
import "@openzeppelin-upgrades/contracts/security/ReentrancyGuardUpgradeable.sol";

import "../mixins/SignatureUtils.sol";
import "../permissions/Pausable.sol";

import "../mixins/ReentrancyGuardMixin.sol";
import "../mixins/SignatureUtils.sol";

import "./AVSDirectoryStorage.sol";

contract AVSDirectory is
Initializable,
OwnableUpgradeable,
Pausable,
AVSDirectoryStorage,
ReentrancyGuardUpgradeable,
ReentrancyGuardMixin,
SignatureUtils
{
/**
Expand Down
4 changes: 2 additions & 2 deletions src/contracts/core/AllocationManager.sol
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ pragma solidity ^0.8.27;

import "@openzeppelin-upgrades/contracts/proxy/utils/Initializable.sol";
import "@openzeppelin-upgrades/contracts/access/OwnableUpgradeable.sol";
import "@openzeppelin-upgrades/contracts/security/ReentrancyGuardUpgradeable.sol";

import "../mixins/ReentrancyGuardMixin.sol";
import "../mixins/PermissionControllerMixin.sol";
import "../permissions/Pausable.sol";
import "../libraries/SlashingLib.sol";
Expand All @@ -16,7 +16,7 @@ contract AllocationManager is
OwnableUpgradeable,
Pausable,
AllocationManagerStorage,
ReentrancyGuardUpgradeable,
ReentrancyGuardMixin,
PermissionControllerMixin
{
using DoubleEndedQueue for DoubleEndedQueue.Bytes32Deque;
Expand Down
9 changes: 6 additions & 3 deletions src/contracts/core/DelegationManager.sol
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,16 @@ pragma solidity ^0.8.27;

import "@openzeppelin-upgrades/contracts/proxy/utils/Initializable.sol";
import "@openzeppelin-upgrades/contracts/access/OwnableUpgradeable.sol";
import "@openzeppelin-upgrades/contracts/security/ReentrancyGuardUpgradeable.sol";

import "../permissions/Pausable.sol";

import "../mixins/ReentrancyGuardMixin.sol";
import "../mixins/SignatureUtils.sol";
import "../mixins/PermissionControllerMixin.sol";
import "../permissions/Pausable.sol";

import "../libraries/SlashingLib.sol";
import "../libraries/Snapshots.sol";

import "./DelegationManagerStorage.sol";

/**
Expand All @@ -27,7 +30,7 @@ contract DelegationManager is
OwnableUpgradeable,
Pausable,
DelegationManagerStorage,
ReentrancyGuardUpgradeable,
ReentrancyGuardMixin,
SignatureUtils,
PermissionControllerMixin
{
Expand Down
4 changes: 2 additions & 2 deletions src/contracts/core/RewardsCoordinator.sol
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ pragma solidity ^0.8.27;

import "@openzeppelin-upgrades/contracts/proxy/utils/Initializable.sol";
import "@openzeppelin-upgrades/contracts/access/OwnableUpgradeable.sol";
import "@openzeppelin-upgrades/contracts/security/ReentrancyGuardUpgradeable.sol";
import "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol";

import "../mixins/ReentrancyGuardMixin.sol";
import "../libraries/Merkle.sol";
import "../permissions/Pausable.sol";
import "./RewardsCoordinatorStorage.sol";
Expand All @@ -24,7 +24,7 @@ contract RewardsCoordinator is
Initializable,
OwnableUpgradeable,
Pausable,
ReentrancyGuardUpgradeable,
ReentrancyGuardMixin,
RewardsCoordinatorStorage,
PermissionControllerMixin
{
Expand Down
4 changes: 2 additions & 2 deletions src/contracts/core/StrategyManager.sol
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ pragma solidity ^0.8.27;

import "@openzeppelin-upgrades/contracts/proxy/utils/Initializable.sol";
import "@openzeppelin-upgrades/contracts/access/OwnableUpgradeable.sol";
import "@openzeppelin-upgrades/contracts/security/ReentrancyGuardUpgradeable.sol";
import "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol";

import "../mixins/ReentrancyGuardMixin.sol";
import "../mixins/SignatureUtils.sol";
import "../interfaces/IEigenPodManager.sol";
import "../permissions/Pausable.sol";
Expand All @@ -23,7 +23,7 @@ import "./StrategyManagerStorage.sol";
contract StrategyManager is
Initializable,
OwnableUpgradeable,
ReentrancyGuardUpgradeable,
ReentrancyGuardMixin,
Pausable,
StrategyManagerStorage,
SignatureUtils
Expand Down
34 changes: 34 additions & 0 deletions src/contracts/mixins/ReentrancyGuardMixin.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
// SPDX-License-Identifier: BUSL-1.1
pragma solidity ^0.8.27;

/**
* @dev Variant of {ReentrancyGuard} that uses transient storage.
*
* NOTE: This variant only works on networks where EIP-1153 is available.
*/
abstract contract ReentrancyGuardMixin {
// keccak256(abi.encode(uint256(keccak256("eigenlayer.storage.ReentrancyGuardMixin")) - 1)) & ~bytes32(uint256(0xff))
uint256 private constant _REENTRANCY_GUARD_SLOT =
0x61bb794ad7a504b3613420bc192fca11ecb0ea36bf99527d17aa6bd66a5db500;

/// @dev Unauthorized reentrant call.
error Reentrancy();

/// @dev Guards a function from reentrancy.
modifier nonReentrant() virtual {
uint256 s = _REENTRANCY_GUARD_SLOT;
/// @solidity memory-safe-assembly
assembly {
if tload(s) {
mstore(0x00, 0xab143c06) // `Reentrancy()`.
revert(0x1c, 0x04)
}
tstore(s, address())
}
_;
/// @solidity memory-safe-assembly
assembly {
tstore(s, 0)
}
}
}
5 changes: 3 additions & 2 deletions src/contracts/pods/EigenPod.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@
pragma solidity ^0.8.27;

import "@openzeppelin-upgrades/contracts/proxy/utils/Initializable.sol";
import "@openzeppelin-upgrades/contracts/security/ReentrancyGuardUpgradeable.sol";
import "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol";

import "../mixins/ReentrancyGuardMixin.sol";

import "../libraries/BeaconChainProofs.sol";
import "../libraries/BytesLib.sol";

Expand All @@ -23,7 +24,7 @@ import "./EigenPodStorage.sol";
* @dev Note that all beacon chain balances are stored as gwei within the beacon chain datastructures. We choose
* to account balances in terms of gwei in the EigenPod contract and convert to wei when making calls to other contracts
*/
contract EigenPod is Initializable, ReentrancyGuardUpgradeable, EigenPodPausingConstants, EigenPodStorage {
contract EigenPod is Initializable, ReentrancyGuardMixin, EigenPodPausingConstants, EigenPodStorage {
using BytesLib for bytes;
using SafeERC20 for IERC20;
using BeaconChainProofs for *;
Expand Down
4 changes: 2 additions & 2 deletions src/contracts/pods/EigenPodManager.sol
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ pragma solidity ^0.8.27;
import "@openzeppelin/contracts/utils/Create2.sol";
import "@openzeppelin-upgrades/contracts/proxy/utils/Initializable.sol";
import "@openzeppelin-upgrades/contracts/access/OwnableUpgradeable.sol";
import "@openzeppelin-upgrades/contracts/security/ReentrancyGuardUpgradeable.sol";

import "../mixins/ReentrancyGuardMixin.sol";
import "../libraries/SlashingLib.sol";
import "../permissions/Pausable.sol";
import "./EigenPodPausingConstants.sol";
Expand All @@ -27,7 +27,7 @@ contract EigenPodManager is
Pausable,
EigenPodPausingConstants,
EigenPodManagerStorage,
ReentrancyGuardUpgradeable
ReentrancyGuardMixin
{
using SlashingLib for *;
using Math for *;
Expand Down
Loading