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

refactor: remove isActivatedAtEpoch check for ExoCapsule.verifyDepositProof #62

Merged
merged 4 commits into from
Jul 30, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
18 changes: 0 additions & 18 deletions src/core/ExoCapsule.sol
Original file line number Diff line number Diff line change
Expand Up @@ -182,10 +182,6 @@ contract ExoCapsule is ReentrancyGuardUpgradeable, ExoCapsuleStorage, IExoCapsul
revert StaleValidatorContainer(validatorPubkey, proof.beaconBlockTimestamp);
}

if (!_isActivatedAtEpoch(validatorContainer, proof.beaconBlockTimestamp)) {
revert InactiveValidatorContainer(validatorPubkey);
}

if (withdrawalCredentials != bytes32(capsuleWithdrawalCredentials())) {
revert WithdrawalCredentialsNotMatch();
}
Expand Down Expand Up @@ -400,20 +396,6 @@ contract ExoCapsule is ReentrancyGuardUpgradeable, ExoCapsuleStorage, IExoCapsul
}
}

/// @dev Checks if the validator is activated at the given epoch.
/// @param validatorContainer The validator container.
/// @param atTimestamp The timestamp at which the activation is checked.
function _isActivatedAtEpoch(bytes32[] calldata validatorContainer, uint256 atTimestamp)
internal
pure
returns (bool)
{
uint64 atEpoch = _timestampToEpoch(atTimestamp);
uint64 activationEpoch = validatorContainer.getActivationEpoch();

return atEpoch >= activationEpoch;
}

/// @dev Checks if the proof is stale (too old).
/// @param validator The validator to check.
/// @param proofTimestamp The timestamp of the proof.
Expand Down
13 changes: 9 additions & 4 deletions test/foundry/unit/ExoCapsule.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ contract VerifyDepositProof is DepositSetup {
capsule.verifyDepositProof(validatorContainer, validatorProof);
}

function test_verifyDepositProof_revert_inactiveValidatorContainer() public {
function test_verifyDepositProof_success_inactiveValidatorContainer() public {
uint256 activationTimestamp =
BEACON_CHAIN_GENESIS_TIME + _getActivationEpoch(validatorContainer) * SECONDS_PER_EPOCH;

Expand All @@ -236,10 +236,15 @@ contract VerifyDepositProof is DepositSetup {
mockCurrentBlockTimestamp = mockProofTimestamp + SECONDS_PER_SLOT;
vm.warp(mockCurrentBlockTimestamp);
validatorProof.beaconBlockTimestamp = mockProofTimestamp;
vm.expectRevert(
abi.encodeWithSelector(ExoCapsule.InactiveValidatorContainer.selector, _getPubkey(validatorContainer))
);

capsule.verifyDepositProof(validatorContainer, validatorProof);

ExoCapsuleStorage.Validator memory validator =
capsule.getRegisteredValidatorByPubkey(_getPubkey(validatorContainer));
assertEq(uint8(validator.status), uint8(ExoCapsuleStorage.VALIDATOR_STATUS.REGISTERED));
assertEq(validator.validatorIndex, validatorProof.validatorIndex);
assertEq(validator.mostRecentBalanceUpdateTimestamp, validatorProof.beaconBlockTimestamp);
assertEq(validator.restakedBalanceGwei, _getEffectiveBalance(validatorContainer));
}

function test_verifyDepositProof_revert_mismatchWithdrawalCredentials() public {
Expand Down
Loading