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

added read functions for eigenpods #338

Closed
wants to merge 8 commits into from
Closed
Show file tree
Hide file tree
Changes from 4 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
10 changes: 9 additions & 1 deletion src/contracts/interfaces/IEigenPod.sol
Original file line number Diff line number Diff line change
Expand Up @@ -138,12 +138,20 @@ interface IEigenPod {
/// @notice Returns the validatorInfo struct for the provided pubkeyHash
function validatorPubkeyHashToInfo(bytes32 validatorPubkeyHash) external view returns (ValidatorInfo memory);

/// @notice Returns the validatorInfo struct for the provided pubkey
function validatorPubkeyToInfo(bytes calldata validatorPubkey) external view returns (ValidatorInfo memory);


///@notice mapping that tracks proven withdrawals
function provenWithdrawal(bytes32 validatorPubkeyHash, uint64 slot) external view returns (bool);

/// @notice This returns the status of a given validator
/// @notice This returns the status of a given validator pubkey hash
function validatorStatus(bytes32 pubkeyHash) external view returns (VALIDATOR_STATUS);

/// @notice This returns the status of a given validator pubkey
function validatorStatus(bytes calldata validatorPubkey) external view returns (VALIDATOR_STATUS);


/**
* @notice This function verifies that the withdrawal credentials of validator(s) owned by the podOwner are pointed to
* this contract. It also verifies the effective balance of the validator. It verifies the provided proof of the ETH validator against the beacon chain state
Expand Down
17 changes: 17 additions & 0 deletions src/contracts/pods/EigenPod.sol
Original file line number Diff line number Diff line change
Expand Up @@ -756,6 +756,13 @@ contract EigenPod is IEigenPod, Initializable, ReentrancyGuardUpgradeable, Eigen
return abi.encodePacked(bytes1(uint8(1)), bytes11(0), address(this));
}

function _calculateValidatorPubkeyHash(bytes memory validatorPubkey) internal view returns(bytes32){
Sidu28 marked this conversation as resolved.
Show resolved Hide resolved
require(validatorPubkey.length == 48, "EigenPod._calculateValidatorPubkeyHash must be a 48-byte BLS public key");
bytes16 zeroPadding = bytes16(0);
bytes memory paddedPubkey = abi.encodePacked(validatorPubkey, zeroPadding);
return sha256(paddedPubkey);
Sidu28 marked this conversation as resolved.
Show resolved Hide resolved
}

/**
* Calculates delta between two share amounts and returns as an int256
*/
Expand Down Expand Up @@ -786,6 +793,16 @@ contract EigenPod is IEigenPod, Initializable, ReentrancyGuardUpgradeable, Eigen
return _validatorPubkeyHashToInfo[pubkeyHash].status;
}

function validatorPubkeyToInfo(bytes calldata validatorPubkey) external view returns (ValidatorInfo memory) {
Sidu28 marked this conversation as resolved.
Show resolved Hide resolved
return _validatorPubkeyHashToInfo[_calculateValidatorPubkeyHash(validatorPubkey)];
}

function validatorStatus(bytes calldata validatorPubkey) external view returns (VALIDATOR_STATUS) {
Sidu28 marked this conversation as resolved.
Show resolved Hide resolved
require(validatorPubkey.length == 48, "EigenPod.validatorPubkeyHashToInfo must be a 48-byte BLS public key");
bytes32 validatorPubkeyHash = _calculateValidatorPubkeyHash(validatorPubkey);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is a duplicate check -- you have the same require statement in the _calculateValidatorPubkeyHash function. I think it's reasonable to delete this first check (since you also use the length check in validatorPubkeyToInfo, you should not delete the check in _calculateValidatorPubkeyHash)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed!

return _validatorPubkeyHashToInfo[validatorPubkeyHash].status;
}


/**
* @dev This empty reserved space is put in place to allow future versions to add new
Expand Down
30 changes: 30 additions & 0 deletions src/test/EigenPod.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -1380,6 +1380,36 @@ contract EigenPodTests is ProofParsing, EigenPodPausingConstants {
cheats.stopPrank();
}

function test_validatorPubkeyToInfo() external {
bytes memory pubkey = hex"93a0dd04ccddf3f1b419fdebf99481a2182c17d67cf14d32d6e50fc4bf8effc8db4a04b7c2f3a5975c1b9b74e2841888";

setJSON("./src/test/test-data/withdrawal_credential_proof_302913.json");
_testDeployAndVerifyNewEigenPod(podOwner, signature, depositDataRoot);
IEigenPod pod = eigenPodManager.getPod(podOwner);

IEigenPod.ValidatorInfo memory info1 = pod.validatorPubkeyToInfo(pubkey);
IEigenPod.ValidatorInfo memory info2 = pod.validatorPubkeyHashToInfo(getValidatorPubkeyHash());

require(info1.validatorIndex == info2.validatorIndex, "validatorIndex does not match");
require(info1.restakedBalanceGwei > 0, "restakedBalanceGwei is 0");
require(info1.restakedBalanceGwei == info2.restakedBalanceGwei, "restakedBalanceGwei does not match");
require(info1.mostRecentBalanceUpdateTimestamp == info2.mostRecentBalanceUpdateTimestamp, "mostRecentBalanceUpdateTimestamp does not match");
require(info1.status == info2.status, "status does not match");
}

function test_validatorStatus() external {
bytes memory pubkey = hex"93a0dd04ccddf3f1b419fdebf99481a2182c17d67cf14d32d6e50fc4bf8effc8db4a04b7c2f3a5975c1b9b74e2841888";

setJSON("./src/test/test-data/withdrawal_credential_proof_302913.json");
_testDeployAndVerifyNewEigenPod(podOwner, signature, depositDataRoot);
IEigenPod pod = eigenPodManager.getPod(podOwner);

IEigenPod.VALIDATOR_STATUS status1 = pod.validatorStatus(pubkey);
IEigenPod.VALIDATOR_STATUS status2 = pod.validatorStatus(getValidatorPubkeyHash());

require(status1 == status2, "status does not match");
}

/* TODO: reimplement similar tests
function testQueueBeaconChainETHWithdrawalWithoutProvingFullWithdrawal() external {
// ./solidityProofGen -newBalance=32000115173 "ValidatorFieldsProof" 302913 true "data/withdrawal_proof_goerli/goerli_block_header_6399998.json" "data/withdrawal_proof_goerli/goerli_slot_6399998.json" "withdrawal_credential_proof_302913.json"
Expand Down
3 changes: 3 additions & 0 deletions src/test/mocks/EigenPodMock.sol
Original file line number Diff line number Diff line change
Expand Up @@ -87,4 +87,7 @@ contract EigenPodMock is IEigenPod, Test {

/// @notice called by owner of a pod to remove any ERC20s deposited in the pod
function recoverTokens(IERC20[] memory tokenList, uint256[] memory amountsToWithdraw, address recipient) external {}

function validatorStatus(bytes calldata pubkey) external view returns (VALIDATOR_STATUS){}
function validatorPubkeyToInfo(bytes calldata validatorPubkey) external view returns (ValidatorInfo memory){}
}
Loading