Skip to content

Commit fd28375

Browse files
committed
test: update eigen pod unit tests with new balance update functionality
1 parent a0fa1b3 commit fd28375

File tree

3 files changed

+328
-45
lines changed

3 files changed

+328
-45
lines changed

src/contracts/pods/EigenPod.sol

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -748,7 +748,7 @@ contract EigenPod is IEigenPod, Initializable, ReentrancyGuardUpgradeable, Eigen
748748
}
749749

750750
///@notice Calculates the pubkey hash of a validator's pubkey as per SSZ spec
751-
function _calculateValidatorPubkeyHash(bytes memory validatorPubkey) internal view returns(bytes32){
751+
function _calculateValidatorPubkeyHash(bytes memory validatorPubkey) internal pure returns (bytes32){
752752
require(validatorPubkey.length == 48, "EigenPod._calculateValidatorPubkeyHash must be a 48-byte BLS public key");
753753
return sha256(abi.encodePacked(validatorPubkey, bytes16(0)));
754754
}

src/test/unit/EigenPod-PodManagerUnit.t.sol

Lines changed: 25 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -142,21 +142,19 @@ contract EigenPod_PodManager_UnitTests_EigenPodPausing is EigenPod_PodManager_Un
142142
uint8 internal constant PAUSED_EIGENPODS_VERIFY_WITHDRAWAL = 4;
143143

144144
function test_verifyBalanceUpdates_revert_pausedEigenVerifyBalanceUpdate() public {
145-
bytes32[][] memory validatorFieldsArray = new bytes32[][](1);
145+
BeaconChainProofs.StateRootProof memory stateRootProofStruct;
146146

147+
bytes32[][] memory validatorFieldsArray = new bytes32[][](1);
148+
bytes[] memory proofsArray = new bytes[](1);
147149
uint40[] memory validatorIndices = new uint40[](1);
148150

149-
BeaconChainProofs.BalanceUpdateProof[] memory proofs = new BeaconChainProofs.BalanceUpdateProof[](1);
150-
151-
BeaconChainProofs.StateRootProof memory stateRootProofStruct;
152-
153151
// pause the contract
154152
cheats.prank(address(pauser));
155153
eigenPodManager.pause(2 ** PAUSED_EIGENPODS_VERIFY_BALANCE_UPDATE);
156154

157155
cheats.prank(address(podOwner));
158156
cheats.expectRevert(bytes("EigenPod.onlyWhenNotPaused: index is paused in EigenPodManager"));
159-
eigenPod.verifyBalanceUpdates(0, validatorIndices, stateRootProofStruct, proofs, validatorFieldsArray);
157+
eigenPod.verifyBalanceUpdates(0, validatorIndices, stateRootProofStruct, proofsArray, validatorFieldsArray);
160158
}
161159

162160
function test_verifyAndProcessWithdrawals_revert_pausedEigenVerifyWithdrawal() public {
@@ -268,7 +266,7 @@ contract EigenPod_PodManager_UnitTests_EigenPodManager is EigenPod_PodManager_Un
268266
uint40[] validatorIndices;
269267
bytes[] validatorFieldsProofs;
270268
bytes32[][] validatorFields;
271-
BeaconChainProofs.BalanceUpdateProof[] balanceUpdateProof;
269+
// BeaconChainProofs.BalanceUpdateProof[] balanceUpdateProof;
272270
BeaconChainProofs.WithdrawalProof[] withdrawalProofs;
273271
bytes32[][] withdrawalFields;
274272

@@ -318,14 +316,14 @@ contract EigenPod_PodManager_UnitTests_EigenPodManager is EigenPod_PodManager_Un
318316

319317
// Save state for checks
320318
int256 initialShares = eigenPodManager.podOwnerShares(podOwner);
321-
uint64 newValidatorBalance = balanceUpdateProof[0].balanceRoot.getBalanceAtIndex(validatorIndices[0]);
319+
uint64 newValidatorBalance = validatorFields[0].getEffectiveBalanceGwei();
322320

323321
// Verify balance update
324322
eigenPod.verifyBalanceUpdates(
325323
oracleTimestamp,
326324
validatorIndices,
327325
stateRootProofStruct,
328-
balanceUpdateProof,
326+
validatorFieldsProofs,
329327
validatorFields
330328
);
331329

@@ -344,7 +342,7 @@ contract EigenPod_PodManager_UnitTests_EigenPodManager is EigenPod_PodManager_Un
344342
_verifyWithdrawalCredentials();
345343

346344
// Set JSON
347-
setJSON("src/test/test-data/balanceUpdateProof_overCommitted_302913.json");
345+
setJSON("src/test/test-data/balanceUpdateProof_notOverCommitted_302913.json");
348346
bytes32 validatorPubkeyHash = validatorFields[0].getPubkeyHash();
349347

350348
// Set proof params, oracle block root, and warp time
@@ -355,14 +353,14 @@ contract EigenPod_PodManager_UnitTests_EigenPodManager is EigenPod_PodManager_Un
355353

356354
// Save state for checks
357355
int256 initialShares = eigenPodManager.podOwnerShares(podOwner);
358-
uint64 newValidatorBalance = balanceUpdateProof[0].balanceRoot.getBalanceAtIndex(validatorIndices[0]);
356+
uint64 newValidatorBalance = validatorFields[0].getEffectiveBalanceGwei();
359357

360358
// Verify balance update
361359
eigenPod.verifyBalanceUpdates(
362360
oracleTimestamp,
363361
validatorIndices,
364362
stateRootProofStruct,
365-
balanceUpdateProof,
363+
validatorFieldsProofs,
366364
validatorFields
367365
);
368366

@@ -575,20 +573,20 @@ contract EigenPod_PodManager_UnitTests_EigenPodManager is EigenPod_PodManager_Un
575573
// Reset arrays
576574
delete validatorIndices;
577575
delete validatorFields;
578-
delete balanceUpdateProof;
576+
delete validatorFieldsProofs;
579577

580578
// Set state proof struct
581579
stateRootProofStruct = _getStateRootProof();
582-
583-
// Set validator index, beacon state root, balance update proof, and validator fields
580+
581+
// Set validator indices
584582
uint40 validatorIndex = uint40(getValidatorIndex());
585583
validatorIndices.push(validatorIndex);
586584

587-
// Set validatorFields array
585+
// Set validatorFieldsArray
588586
validatorFields.push(getValidatorFields());
589587

590-
// Set balance update proof
591-
balanceUpdateProof.push(_getBalanceUpdateProof());
588+
// Set validator fields proof
589+
validatorFieldsProofs.push(abi.encodePacked(getBalanceUpdateProof())); // Validator fields are proven here
592590
}
593591

594592
function _setWithdrawalProofParams() internal {
@@ -614,15 +612,15 @@ contract EigenPod_PodManager_UnitTests_EigenPodManager is EigenPod_PodManager_Un
614612
withdrawalProofs.push(_getWithdrawalProof());
615613
}
616614

617-
function _getBalanceUpdateProof() internal returns (BeaconChainProofs.BalanceUpdateProof memory) {
618-
bytes32 balanceRoot = getBalanceRoot();
619-
BeaconChainProofs.BalanceUpdateProof memory proofs = BeaconChainProofs.BalanceUpdateProof(
620-
abi.encodePacked(getValidatorBalanceProof()),
621-
abi.encodePacked(getWithdrawalCredentialProof()), //technically this is to verify validator pubkey in the validator fields, but the WC proof is effectively the same so we use it here again.
622-
balanceRoot
623-
);
624-
return proofs;
625-
}
615+
// function _getBalanceUpdateProof() internal returns (BeaconChainProofs.BalanceUpdateProof memory) {
616+
// bytes32 balanceRoot = getBalanceRoot();
617+
// BeaconChainProofs.BalanceUpdateProof memory proofs = BeaconChainProofs.BalanceUpdateProof(
618+
// abi.encodePacked(getValidatorBalanceProof()),
619+
// abi.encodePacked(getWithdrawalCredentialProof()), //technically this is to verify validator pubkey in the validator fields, but the WC proof is effectively the same so we use it here again.
620+
// balanceRoot
621+
// );
622+
// return proofs;
623+
// }
626624

627625
/// @notice this function just generates a valid proof so that we can test other functionalities of the withdrawal flow
628626
function _getWithdrawalProof() internal returns (BeaconChainProofs.WithdrawalProof memory) {

0 commit comments

Comments
 (0)