Skip to content

Commit

Permalink
feat: remove unneeded oracle interface from EigenPodManager
Browse files Browse the repository at this point in the history
  • Loading branch information
wadealexc committed Apr 24, 2024
1 parent 705b81d commit d621f35
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 42 deletions.
2 changes: 0 additions & 2 deletions src/contracts/interfaces/IEigenPod.sol
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,8 @@ interface IEigenPod {
struct Checkpoint {
bytes32 beaconBlockRoot;
bytes32 beaconStateRoot;

uint256 podBalanceGwei;
int256 balanceDeltasGwei;

uint256 proofsRemaining;
}

Expand Down
6 changes: 0 additions & 6 deletions src/contracts/interfaces/IEigenPodManager.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand Down
33 changes: 30 additions & 3 deletions src/contracts/pods/EigenPod.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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
*******************************************************************************/
Expand Down Expand Up @@ -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
});
Expand Down Expand Up @@ -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
});
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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));
}
Expand Down
20 changes: 0 additions & 20 deletions src/contracts/pods/EigenPodManager.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
7 changes: 0 additions & 7 deletions src/contracts/pods/EigenPodManagerStorage.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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
*******************************************************************************/
Expand Down
4 changes: 0 additions & 4 deletions src/test/mocks/EigenPodManagerMock.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit d621f35

Please sign in to comment.