From d621f3543c2fdd05120adbd046ee8f4ec89bf610 Mon Sep 17 00:00:00 2001 From: wadealexc Date: Wed, 24 Apr 2024 21:46:07 +0000 Subject: [PATCH] feat: remove unneeded oracle interface from EigenPodManager --- src/contracts/interfaces/IEigenPod.sol | 2 -- src/contracts/interfaces/IEigenPodManager.sol | 6 ---- src/contracts/pods/EigenPod.sol | 33 +++++++++++++++++-- src/contracts/pods/EigenPodManager.sol | 20 ----------- src/contracts/pods/EigenPodManagerStorage.sol | 7 ---- src/test/mocks/EigenPodManagerMock.sol | 4 --- 6 files changed, 30 insertions(+), 42 deletions(-) diff --git a/src/contracts/interfaces/IEigenPod.sol b/src/contracts/interfaces/IEigenPod.sol index bddfd563f..4b527adb7 100644 --- a/src/contracts/interfaces/IEigenPod.sol +++ b/src/contracts/interfaces/IEigenPod.sol @@ -42,10 +42,8 @@ interface IEigenPod { struct Checkpoint { bytes32 beaconBlockRoot; bytes32 beaconStateRoot; - uint256 podBalanceGwei; int256 balanceDeltasGwei; - uint256 proofsRemaining; } diff --git a/src/contracts/interfaces/IEigenPodManager.sol b/src/contracts/interfaces/IEigenPodManager.sol index cc8a81b68..1620ad8b6 100644 --- a/src/contracts/interfaces/IEigenPodManager.sol +++ b/src/contracts/interfaces/IEigenPodManager.sol @@ -130,12 +130,6 @@ interface IEigenPodManager is IPausable { */ function withdrawSharesAsTokens(address podOwner, address destination, uint256 shares) external; - /// @notice Query the 4788 oracle to get the parent block root of the slot with the given `timestamp` - /// @param timestamp of the block for which the parent block root will be returned. MUST correspond - /// to an existing slot within the last 24 hours. If the slot at `timestamp` was skipped, this method - /// will revert. - function getParentBlockRoot(uint64 timestamp) external view returns (bytes32); - /** * @notice the deneb hard fork timestamp used to determine which proof path to use for proving a withdrawal */ diff --git a/src/contracts/pods/EigenPod.sol b/src/contracts/pods/EigenPod.sol index 5a8c1c264..19d36cd2a 100644 --- a/src/contracts/pods/EigenPod.sol +++ b/src/contracts/pods/EigenPod.sol @@ -67,6 +67,13 @@ contract EigenPod is /// to a pod owner to prove the slashed validator's balance uint256 internal constant STALENESS_GRACE_PERIOD = 6 hours; + /// @notice The address of the EIP-4788 beacon block root oracle + /// (See https://eips.ethereum.org/EIPS/eip-4788) + address internal constant BEACON_ROOTS_ADDRESS = 0x000F3df6D732807Ef1319fB7B8bB8522d0Beac02; + + /// @notice The length of the EIP-4799 beacon block root ring buffer + uint256 internal constant BEACON_ROOTS_HISTORY_BUFFER_LENGTH = 8191; + /******************************************************************************* MODIFIERS *******************************************************************************/ @@ -271,7 +278,7 @@ contract EigenPod is // Verify passed-in beaconStateRoot against oracle-provided block root: BeaconChainProofs.verifyStateRootAgainstLatestBlockRoot({ - latestBlockRoot: eigenPodManager.getParentBlockRoot(beaconTimestamp), + latestBlockRoot: _getParentBlockRoot(beaconTimestamp), beaconStateRoot: stateRootProof.beaconStateRoot, stateRootProof: stateRootProof.proof }); @@ -345,7 +352,7 @@ contract EigenPod is // Verify `beaconStateRoot` against beacon block root BeaconChainProofs.verifyStateRootAgainstLatestBlockRoot({ - latestBlockRoot: eigenPodManager.getParentBlockRoot(beaconTimestamp), + latestBlockRoot: _getParentBlockRoot(beaconTimestamp), beaconStateRoot: stateRootProof.beaconStateRoot, stateRootProof: stateRootProof.proof }); @@ -577,7 +584,7 @@ contract EigenPod is - (withdrawableRestakedExecutionLayerGwei * GWEI_TO_WEI); Checkpoint memory checkpoint = Checkpoint({ - beaconBlockRoot: eigenPodManager.getParentBlockRoot(uint64(block.timestamp)), + beaconBlockRoot: _getParentBlockRoot(uint64(block.timestamp)), beaconStateRoot: bytes32(0), podBalanceGwei: podBalanceWei / GWEI_TO_WEI, balanceDeltasGwei: 0, @@ -634,6 +641,26 @@ contract EigenPod is delayedWithdrawalRouter.createDelayedWithdrawal{value: amountWei}(podOwner, recipient); } + /// @notice Query the 4788 oracle to get the parent block root of the slot with the given `timestamp` + /// @param timestamp of the block for which the parent block root will be returned. MUST correspond + /// to an existing slot within the last 24 hours. If the slot at `timestamp` was skipped, this method + /// will revert. + function _getParentBlockRoot(uint64 timestamp) internal view returns (bytes32) { + require( + block.timestamp - timestamp < BEACON_ROOTS_HISTORY_BUFFER_LENGTH * 12, + "EigenPod._getParentBlockRoot: timestamp out of range" + ); + + (bool success, bytes memory result) = + BEACON_ROOTS_ADDRESS.staticcall(abi.encode(timestamp)); + + if (success && result.length > 0) { + return abi.decode(result, (bytes32)); + } else { + revert("EigenPod._getParentBlockRoot: invalid block root returned"); + } + } + function _podWithdrawalCredentials() internal view returns (bytes memory) { return abi.encodePacked(bytes1(uint8(1)), bytes11(0), address(this)); } diff --git a/src/contracts/pods/EigenPodManager.sol b/src/contracts/pods/EigenPodManager.sol index 2c332b0bc..108ed9028 100644 --- a/src/contracts/pods/EigenPodManager.sol +++ b/src/contracts/pods/EigenPodManager.sol @@ -297,26 +297,6 @@ contract EigenPodManager is return address(ownerToPod[podOwner]) != address(0); } - /// @notice Query the 4788 oracle to get the parent block root of the slot with the given `timestamp` - /// @param timestamp of the block for which the parent block root will be returned. MUST correspond - /// to an existing slot within the last 24 hours. If the slot at `timestamp` was skipped, this method - /// will revert. - function getParentBlockRoot(uint64 timestamp) external view returns (bytes32) { - require( - block.timestamp - timestamp < BEACON_ROOTS_HISTORY_BUFFER_LENGTH * 12, - "EigenPodManager.getParentBlockRoot: timestamp out of range" - ); - - (bool success, bytes memory result) = - BEACON_ROOTS_ADDRESS.staticcall(abi.encode(timestamp)); - - if (success && result.length > 0) { - return abi.decode(result, (bytes32)); - } else { - revert("EigenPodManager.getParentBlockRoot: invalid block root returned"); - } - } - /** * @notice Wrapper around the `_denebForkTimestamp` storage variable that returns type(uint64).max if the storage variable is unset. * @dev This allows restricting the storage variable to be set once and only once. diff --git a/src/contracts/pods/EigenPodManagerStorage.sol b/src/contracts/pods/EigenPodManagerStorage.sol index 2bf8a50fa..238a89da1 100644 --- a/src/contracts/pods/EigenPodManagerStorage.sol +++ b/src/contracts/pods/EigenPodManagerStorage.sol @@ -45,13 +45,6 @@ abstract contract EigenPodManagerStorage is IEigenPodManager { /// @notice Canonical, virtual beacon chain ETH strategy IStrategy public constant beaconChainETHStrategy = IStrategy(0xbeaC0eeEeeeeEEeEeEEEEeeEEeEeeeEeeEEBEaC0); - /// @notice The address of the EIP-4788 beacon block root oracle - /// (See https://eips.ethereum.org/EIPS/eip-4788) - address internal constant BEACON_ROOTS_ADDRESS = 0x000F3df6D732807Ef1319fB7B8bB8522d0Beac02; - - /// @notice The length of the EIP-4799 beacon block root ring buffer - uint256 internal constant BEACON_ROOTS_HISTORY_BUFFER_LENGTH = 8191; - /******************************************************************************* STATE VARIABLES *******************************************************************************/ diff --git a/src/test/mocks/EigenPodManagerMock.sol b/src/test/mocks/EigenPodManagerMock.sol index 308b2e553..06d03afea 100644 --- a/src/test/mocks/EigenPodManagerMock.sol +++ b/src/test/mocks/EigenPodManagerMock.sol @@ -74,10 +74,6 @@ contract EigenPodManagerMock is IEigenPodManager, Test { function numPods() external view returns (uint256) {} - function getParentBlockRoot(uint64 timestamp) external view returns (bytes32) { - return bytes32(0); - } - function updateStaleValidatorCount(address, int256) external {} function denebForkTimestamp() external pure returns (uint64) {