Skip to content

Commit

Permalink
refacotr: remove unused fields for ExoCapsuleStorage.Validator
Browse files Browse the repository at this point in the history
  • Loading branch information
adu-web3 committed Jul 29, 2024
1 parent 4cb7879 commit 463d07b
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 17 deletions.
12 changes: 3 additions & 9 deletions src/core/ExoCapsule.sol
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ contract ExoCapsule is ReentrancyGuardUpgradeable, ExoCapsuleStorage, IExoCapsul
revert DoubleDepositedValidator(validatorPubkey);
}

if (_isStaleProof(validator, proof.beaconBlockTimestamp)) {
if (_isStaleProof(proof.beaconBlockTimestamp)) {
revert StaleValidatorContainer(validatorPubkey, proof.beaconBlockTimestamp);
}

Expand All @@ -194,13 +194,10 @@ contract ExoCapsule is ReentrancyGuardUpgradeable, ExoCapsuleStorage, IExoCapsul

validator.status = VALIDATOR_STATUS.REGISTERED;
validator.validatorIndex = proof.validatorIndex;
validator.mostRecentBalanceUpdateTimestamp = proof.beaconBlockTimestamp;
uint64 depositAmountGwei = validatorContainer.getEffectiveBalance();
if (depositAmountGwei > MAX_RESTAKED_BALANCE_GWEI_PER_VALIDATOR) {
validator.restakedBalanceGwei = MAX_RESTAKED_BALANCE_GWEI_PER_VALIDATOR;
depositAmount = MAX_RESTAKED_BALANCE_GWEI_PER_VALIDATOR * GWEI_TO_WEI;
} else {
validator.restakedBalanceGwei = depositAmountGwei;
depositAmount = depositAmountGwei * GWEI_TO_WEI;
}

Expand Down Expand Up @@ -249,7 +246,6 @@ contract ExoCapsule is ReentrancyGuardUpgradeable, ExoCapsuleStorage, IExoCapsul
} else {
// Full withdrawal
validator.status = VALIDATOR_STATUS.WITHDRAWN;
validator.restakedBalanceGwei = 0;
// If over MAX_RESTAKED_BALANCE_GWEI_PER_VALIDATOR = 32 * 1e9, then send remaining amount immediately
emit FullWithdrawalRedeemed(validatorPubkey, withdrawalEpoch, capsuleOwner, withdrawalAmountGwei);
if (withdrawalAmountGwei > MAX_RESTAKED_BALANCE_GWEI_PER_VALIDATOR) {
Expand Down Expand Up @@ -415,11 +411,9 @@ contract ExoCapsule is ReentrancyGuardUpgradeable, ExoCapsuleStorage, IExoCapsul
}

/// @dev Checks if the proof is stale (too old).
/// @param validator The validator to check.
/// @param proofTimestamp The timestamp of the proof.
function _isStaleProof(Validator storage validator, uint256 proofTimestamp) internal view returns (bool) {
return proofTimestamp + VERIFY_BALANCE_UPDATE_WINDOW_SECONDS < block.timestamp
|| proofTimestamp <= validator.mostRecentBalanceUpdateTimestamp;
function _isStaleProof(uint256 proofTimestamp) internal view returns (bool) {
return proofTimestamp + VERIFY_BALANCE_UPDATE_WINDOW_SECONDS < block.timestamp;
}

/// @dev Checks if the validator has fully withdrawn.
Expand Down
4 changes: 0 additions & 4 deletions src/storage/ExoCapsuleStorage.sol
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,6 @@ contract ExoCapsuleStorage {
struct Validator {
// index of the validator in the beacon chain
uint256 validatorIndex;
// amount of beacon chain ETH restaked on Exocore in gwei
uint64 restakedBalanceGwei;
//timestamp of the validator's most recent balance update
uint256 mostRecentBalanceUpdateTimestamp;
// status of the validator
VALIDATOR_STATUS status;
}
Expand Down
4 changes: 0 additions & 4 deletions test/foundry/unit/ExoCapsule.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -139,8 +139,6 @@ contract VerifyDepositProof is DepositSetup {
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_validatorAlreadyDeposited() public {
Expand Down Expand Up @@ -377,8 +375,6 @@ contract WithdrawalSetup is Test {
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, depositAmount / 1e9);

vm.deal(address(capsule), 1 ether); // Deposit 1 ether to handle excess amount withdraw
}
Expand Down

0 comments on commit 463d07b

Please sign in to comment.