Skip to content

Commit

Permalink
added check for validator balance update against withdrawable epoch
Browse files Browse the repository at this point in the history
  • Loading branch information
Sidu28 committed Oct 9, 2023
1 parent 05e754d commit 51f9667
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions src/contracts/pods/EigenPod.sol
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@ contract EigenPod is IEigenPod, Initializable, ReentrancyGuardUpgradeable, Eigen
/// @notice Maximum "staleness" of a Beacon Chain state root against which `verifyBalanceUpdate` or `verifyWithdrawalCredentials` may be proven.
uint256 internal constant VERIFY_BALANCE_UPDATE_WINDOW_SECONDS = 4.5 hours;

/// @notice The number of seconds in a slot in the beacon chain
uint256 internal constant SECONDS_PER_SLOT = 12;

/// @notice This is the beacon chain deposit contract
IETHPOSDeposit public immutable ethPOS;

Expand All @@ -63,6 +66,9 @@ contract EigenPod is IEigenPod, Initializable, ReentrancyGuardUpgradeable, Eigen
*/
uint64 public immutable RESTAKED_BALANCE_OFFSET_GWEI;

/// @notice This is the genesis time of the beacon state, to help us calculate conversions between slot and timestamp
uint64 public immutable GENESIS_TIME;

// STORAGE VARIABLES
/// @notice The owner of this EigenPod
address public podOwner;
Expand Down Expand Up @@ -203,6 +209,10 @@ contract EigenPod is IEigenPod, Initializable, ReentrancyGuardUpgradeable, Eigen
"EigenPod.verifyBalanceUpdate: specified timestamp is too far in past"
);

require(Endian.fromLittleEndianUint64(validatorFields[BeaconChainProofs.VALIDATOR_WITHDRAWABLE_EPOCH_INDEX]) >
(_computeSlotAtTimestamp(oracleTimestamp)) / BeaconChainProofs.SLOTS_PER_EPOCH, "balance update is being proven after a validator is withdrawable");


bytes32 validatorPubkeyHash = validatorFields[BeaconChainProofs.VALIDATOR_PUBKEY_INDEX];

ValidatorInfo memory validatorInfo = _validatorPubkeyHashToInfo[validatorPubkeyHash];
Expand Down Expand Up @@ -760,6 +770,13 @@ contract EigenPod is IEigenPod, Initializable, ReentrancyGuardUpgradeable, Eigen
return (int256(newAmountWei) - int256(currentAmountWei));
}

// reference: https://github.com/ethereum/consensus-specs/blob/ce240ca795e257fc83059c4adfd591328c7a7f21/specs/bellatrix/beacon-chain.md#compute_timestamp_at_slot
function _computeSlotAtTimestamp(uint64 timestamp) internal view returns (uint64) {
require(timestamp >= GENESIS_TIME, "EigenPod._computeSlotAtTimestamp: timestamp is before genesis");
return (timestamp - GENESIS_TIME) / SECONDS_PER_SLOT;
}


/**
* @dev This empty reserved space is put in place to allow future versions to add new
* variables without shifting down storage in the inheritance chain.
Expand Down

0 comments on commit 51f9667

Please sign in to comment.