Skip to content

Commit

Permalink
almost all tests working
Browse files Browse the repository at this point in the history
  • Loading branch information
Sidu28 committed Oct 9, 2023
1 parent 505b37b commit 381b75c
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 19 deletions.
11 changes: 1 addition & 10 deletions src/contracts/pods/EigenPod.sol
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@ import "../interfaces/IPausable.sol";

import "./EigenPodPausingConstants.sol";

import "forge-std/Test.sol";

/**
* @title The implementation contract used for restaking beacon chain ETH on EigenLayer
* @author Layr Labs, Inc.
Expand All @@ -36,7 +34,7 @@ import "forge-std/Test.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 IEigenPod, Initializable, ReentrancyGuardUpgradeable, EigenPodPausingConstants, Test {
contract EigenPod is IEigenPod, Initializable, ReentrancyGuardUpgradeable, EigenPodPausingConstants {
using BytesLib for bytes;
using SafeERC20 for IERC20;

Expand Down Expand Up @@ -208,18 +206,11 @@ contract EigenPod is IEigenPod, Initializable, ReentrancyGuardUpgradeable, Eigen
bytes32[] calldata validatorFields
) external onlyWhenNotPaused(PAUSED_EIGENPODS_VERIFY_BALANCE_UPDATE) {
// ensure that the timestamp being proven against is not "too stale", i.e. that the validator's balance *recently* changed.
emit log_named_uint("oracleTimestamp", oracleTimestamp);
emit log_named_uint("block.timestamp", block.timestamp);
require(
oracleTimestamp + VERIFY_BALANCE_UPDATE_WINDOW_SECONDS >= block.timestamp,
"EigenPod.verifyBalanceUpdate: specified timestamp is too far in past"
);

emit log_named_uint("withdrawable epoch", Endian.fromLittleEndianUint64(validatorFields[BeaconChainProofs.VALIDATOR_WITHDRAWABLE_EPOCH_INDEX]));
emit log_named_uint("current epoch", _computeSlotAtTimestamp(oracleTimestamp) / BeaconChainProofs.SLOTS_PER_EPOCH);
emit log_named_uint("slot at timestamp", _computeSlotAtTimestamp(oracleTimestamp));


/**
* checks that a balance update can only be made before the validator is withdrawable. If this is not checked
* anyone can prove the withdrawn validator's balance as 0 before the validator is able to prove their full withdrawal
Expand Down
18 changes: 9 additions & 9 deletions src/test/EigenPod.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -555,14 +555,17 @@ contract EigenPodTests is ProofParsing, EigenPodPausingConstants {
/// @notice verifies that multiple full withdrawals for a single validator fail
function testDoubleFullWithdrawal() public returns(IEigenPod newPod) {
newPod = testFullWithdrawalFlow();
uint64 withdrawalAmountGwei = Endian.fromLittleEndianUint64(withdrawalFields[BeaconChainProofs.WITHDRAWAL_VALIDATOR_AMOUNT_INDEX]);
emit log_named_uint("HELLOWOWOWOWO", newPod.nonBeaconChainETHBalanceWei());
uint64 leftOverBalanceWEI = uint64(withdrawalAmountGwei - newPod.MAX_RESTAKED_BALANCE_GWEI_PER_VALIDATOR()) * uint64(GWEI_TO_WEI);
emit log("hello");
cheats.deal(address(newPod), leftOverBalanceWEI);


BeaconChainProofs.WithdrawalProof memory withdrawalProofs = _getWithdrawalProof();
bytes memory validatorFieldsProof = abi.encodePacked(getValidatorProof());
withdrawalFields = getWithdrawalFields();
validatorFields = getValidatorFields();

uint64 withdrawalAmountGwei = Endian.fromLittleEndianUint64(withdrawalFields[BeaconChainProofs.WITHDRAWAL_VALIDATOR_AMOUNT_INDEX]);
uint64 leftOverBalanceWEI = uint64(withdrawalAmountGwei - newPod.MAX_RESTAKED_BALANCE_GWEI_PER_VALIDATOR()) * uint64(GWEI_TO_WEI);
cheats.deal(address(newPod), leftOverBalanceWEI);

BeaconChainProofs.WithdrawalProof[] memory withdrawalProofsArray = new BeaconChainProofs.WithdrawalProof[](1);
withdrawalProofsArray[0] = withdrawalProofs;
Expand Down Expand Up @@ -1196,22 +1199,19 @@ contract EigenPodTests is ProofParsing, EigenPodPausingConstants {

BeaconChainProofs.StateRootProof memory stateRootProofStruct = _getStateRootProof();


//cheats.expectEmit(true, true, true, true, address(newPod));
emit FullWithdrawalRedeemed(validatorIndex, _computeTimestampAtSlot(Endian.fromLittleEndianUint64(withdrawalProofsArray[0].slotRoot)), podOwner, withdrawalAmountGwei);
newPod.verifyAndProcessWithdrawals(0, stateRootProofStruct, withdrawalProofsArray, validatorFieldsProofArray, validatorFieldsArray, withdrawalFieldsArray);
}
require(newPod.withdrawableRestakedExecutionLayerGwei() - restakedExecutionLayerGweiBefore == newPod.MAX_RESTAKED_BALANCE_GWEI_PER_VALIDATOR(),
"restakedExecutionLayerGwei has not been incremented correctly");
require(address(delayedWithdrawalRouter).balance - delayedWithdrawalRouterContractBalanceBefore == leftOverBalanceWEI,
"pod delayed withdrawal balance hasn't been updated correctly");
require(newPod.validatorPubkeyHashToInfo(getValidatorPubkeyHash()).restakedBalanceGwei == 0, "balance not reset correctly");

cheats.roll(block.number + WITHDRAWAL_DELAY_BLOCKS + 1);
uint256 podOwnerBalanceBefore = address(podOwner).balance;
delayedWithdrawalRouter.claimDelayedWithdrawals(podOwner, 1);
require(address(podOwner).balance - podOwnerBalanceBefore == leftOverBalanceWEI, "Pod owner balance hasn't been updated correctly");

return newPod;
}

// simply tries to register 'sender' as a delegate, setting their 'DelegationTerms' contract in DelegationManager to 'dt'
Expand Down

0 comments on commit 381b75c

Please sign in to comment.