Skip to content

Commit a8e259d

Browse files
authored
Merge pull request #348 from Layr-Labs/add-read-functions-to-m2mainnet
Add Read Functions to M2 Mainnet
2 parents 7ef4f3e + f417cbe commit a8e259d

File tree

4 files changed

+56
-0
lines changed

4 files changed

+56
-0
lines changed

src/contracts/interfaces/IEigenPod.sol

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,12 +138,18 @@ interface IEigenPod {
138138
/// @notice Returns the validatorInfo struct for the provided pubkeyHash
139139
function validatorPubkeyHashToInfo(bytes32 validatorPubkeyHash) external view returns (ValidatorInfo memory);
140140

141+
/// @notice Returns the validatorInfo struct for the provided pubkey
142+
function validatorPubkeyToInfo(bytes calldata validatorPubkey) external view returns (ValidatorInfo memory);
143+
141144
///@notice mapping that tracks proven withdrawals
142145
function provenWithdrawal(bytes32 validatorPubkeyHash, uint64 slot) external view returns (bool);
143146

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

150+
/// @notice This returns the status of a given validator pubkey
151+
function validatorStatus(bytes calldata validatorPubkey) external view returns (VALIDATOR_STATUS);
152+
147153
/**
148154
* @notice This function verifies that the withdrawal credentials of validator(s) owned by the podOwner are pointed to
149155
* 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

src/contracts/pods/EigenPod.sol

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -747,6 +747,12 @@ contract EigenPod is IEigenPod, Initializable, ReentrancyGuardUpgradeable, Eigen
747747
return abi.encodePacked(bytes1(uint8(1)), bytes11(0), address(this));
748748
}
749749

750+
///@notice Calculates the pubkey hash of a validator's pubkey as per SSZ spec
751+
function _calculateValidatorPubkeyHash(bytes memory validatorPubkey) internal view returns(bytes32){
752+
require(validatorPubkey.length == 48, "EigenPod._calculateValidatorPubkeyHash must be a 48-byte BLS public key");
753+
return sha256(abi.encodePacked(validatorPubkey, bytes16(0)));
754+
}
755+
750756
/**
751757
* Calculates delta between two share amounts and returns as an int256
752758
*/
@@ -773,10 +779,21 @@ contract EigenPod is IEigenPod, Initializable, ReentrancyGuardUpgradeable, Eigen
773779
return _validatorPubkeyHashToInfo[validatorPubkeyHash];
774780
}
775781

782+
/// @notice Returns the validatorInfo for a given validatorPubkey
783+
function validatorPubkeyToInfo(bytes calldata validatorPubkey) external view returns (ValidatorInfo memory) {
784+
return _validatorPubkeyHashToInfo[_calculateValidatorPubkeyHash(validatorPubkey)];
785+
}
786+
776787
function validatorStatus(bytes32 pubkeyHash) external view returns (VALIDATOR_STATUS) {
777788
return _validatorPubkeyHashToInfo[pubkeyHash].status;
778789
}
779790

791+
/// @notice Returns the validator status for a given validatorPubkey
792+
function validatorStatus(bytes calldata validatorPubkey) external view returns (VALIDATOR_STATUS) {
793+
bytes32 validatorPubkeyHash = _calculateValidatorPubkeyHash(validatorPubkey);
794+
return _validatorPubkeyHashToInfo[validatorPubkeyHash].status;
795+
}
796+
780797

781798
/**
782799
* @dev This empty reserved space is put in place to allow future versions to add new

src/test/EigenPod.t.sol

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1371,6 +1371,36 @@ contract EigenPodTests is ProofParsing, EigenPodPausingConstants {
13711371
cheats.stopPrank();
13721372
}
13731373

1374+
function test_validatorPubkeyToInfo() external {
1375+
bytes memory pubkey = hex"93a0dd04ccddf3f1b419fdebf99481a2182c17d67cf14d32d6e50fc4bf8effc8db4a04b7c2f3a5975c1b9b74e2841888";
1376+
1377+
setJSON("./src/test/test-data/withdrawal_credential_proof_302913.json");
1378+
_testDeployAndVerifyNewEigenPod(podOwner, signature, depositDataRoot);
1379+
IEigenPod pod = eigenPodManager.getPod(podOwner);
1380+
1381+
IEigenPod.ValidatorInfo memory info1 = pod.validatorPubkeyToInfo(pubkey);
1382+
IEigenPod.ValidatorInfo memory info2 = pod.validatorPubkeyHashToInfo(getValidatorPubkeyHash());
1383+
1384+
require(info1.validatorIndex == info2.validatorIndex, "validatorIndex does not match");
1385+
require(info1.restakedBalanceGwei > 0, "restakedBalanceGwei is 0");
1386+
require(info1.restakedBalanceGwei == info2.restakedBalanceGwei, "restakedBalanceGwei does not match");
1387+
require(info1.mostRecentBalanceUpdateTimestamp == info2.mostRecentBalanceUpdateTimestamp, "mostRecentBalanceUpdateTimestamp does not match");
1388+
require(info1.status == info2.status, "status does not match");
1389+
}
1390+
1391+
function test_validatorStatus() external {
1392+
bytes memory pubkey = hex"93a0dd04ccddf3f1b419fdebf99481a2182c17d67cf14d32d6e50fc4bf8effc8db4a04b7c2f3a5975c1b9b74e2841888";
1393+
1394+
setJSON("./src/test/test-data/withdrawal_credential_proof_302913.json");
1395+
_testDeployAndVerifyNewEigenPod(podOwner, signature, depositDataRoot);
1396+
IEigenPod pod = eigenPodManager.getPod(podOwner);
1397+
1398+
IEigenPod.VALIDATOR_STATUS status1 = pod.validatorStatus(pubkey);
1399+
IEigenPod.VALIDATOR_STATUS status2 = pod.validatorStatus(getValidatorPubkeyHash());
1400+
1401+
require(status1 == status2, "status does not match");
1402+
}
1403+
13741404
/* TODO: reimplement similar tests
13751405
function testQueueBeaconChainETHWithdrawalWithoutProvingFullWithdrawal() external {
13761406
// ./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"

src/test/mocks/EigenPodMock.sol

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,4 +87,7 @@ contract EigenPodMock is IEigenPod, Test {
8787

8888
/// @notice called by owner of a pod to remove any ERC20s deposited in the pod
8989
function recoverTokens(IERC20[] memory tokenList, uint256[] memory amountsToWithdraw, address recipient) external {}
90+
91+
function validatorStatus(bytes calldata pubkey) external view returns (VALIDATOR_STATUS){}
92+
function validatorPubkeyToInfo(bytes calldata validatorPubkey) external view returns (ValidatorInfo memory){}
9093
}

0 commit comments

Comments
 (0)