From d3a14f2073f14561900327c59f72817122281750 Mon Sep 17 00:00:00 2001 From: 0xvv Date: Wed, 15 Jan 2025 15:01:27 +0100 Subject: [PATCH] remove setWithdrawer() and unused code(fix #2, #5, #6, #7, #8) --- src/contracts/StakingContract.sol | 44 ------------ .../libs/StakingContractStorageLib.sol | 15 ---- src/test/StakingContract.t.sol | 72 ------------------- 3 files changed, 131 deletions(-) diff --git a/src/contracts/StakingContract.sol b/src/contracts/StakingContract.sol index 7f1d45d..e4f2bfb 100644 --- a/src/contracts/StakingContract.sol +++ b/src/contracts/StakingContract.sol @@ -53,14 +53,6 @@ contract StakingContract { error AddressSanctioned(address sanctionedAccount); error AddressBlocked(address blockedAccount); - struct ValidatorAllocationCache { - bool used; - uint8 operatorIndex; - uint32 funded; - uint32 toDeposit; - uint32 available; - } - event Deposit(address indexed caller, address indexed withdrawer, bytes publicKey, bytes signature); event ValidatorKeysAdded(uint256 indexed operatorIndex, bytes publicKeys, bytes signatures); event ValidatorKeyRemoved(uint256 indexed operatorIndex, bytes publicKey); @@ -75,7 +67,6 @@ contract StakingContract { event ChangedOperatorAddresses(uint256 operatorIndex, address operatorAddress, address feeRecipientAddress); event DeactivatedOperator(uint256 _operatorIndex); event ActivatedOperator(uint256 _operatorIndex); - event SetWithdrawerCustomizationStatus(bool _status); event ExitRequest(address caller, bytes pubkey); event ValidatorsEdited(uint256 blockNumber); @@ -199,13 +190,6 @@ contract StakingContract { StakingContractStorageLib.setOperatorCommissionLimit(operatorCommissionLimitBPS); } - /// @notice Changes the behavior of the withdrawer customization logic - /// @param _enabled True to allow users to customize the withdrawer - function setWithdrawerCustomizationEnabled(bool _enabled) external onlyAdmin { - StakingContractStorageLib.setWithdrawerCustomizationEnabled(_enabled); - emit SetWithdrawerCustomizationStatus(_enabled); - } - /// @notice Changes the sanctions oracle address /// @param _sanctionsOracle New sanctions oracle address /// @dev If the address is address(0), the sanctions oracle checks are skipped @@ -433,27 +417,6 @@ contract StakingContract { emit ChangedOperatorAddresses(_operatorIndex, _operatorAddress, _feeRecipientAddress); } - /// @notice Set withdrawer for public key - /// @dev Only callable by current public key withdrawer - /// @param _publicKey Public key to change withdrawer - /// @param _newWithdrawer New withdrawer address - function setWithdrawer(bytes calldata _publicKey, address _newWithdrawer) external { - if (!StakingContractStorageLib.getWithdrawerCustomizationEnabled()) { - revert Forbidden(); - } - _checkAddress(_newWithdrawer); - bytes32 pubkeyRoot = _getPubKeyRoot(_publicKey); - StakingContractStorageLib.WithdrawersSlot storage withdrawers = StakingContractStorageLib.getWithdrawers(); - - if (withdrawers.value[pubkeyRoot] != msg.sender) { - revert Unauthorized(); - } - - emit ChangedWithdrawer(_publicKey, _newWithdrawer); - - withdrawers.value[pubkeyRoot] = _newWithdrawer; - } - /// @notice Set operator staking limits /// @dev Only callable by admin /// @dev Limit should not exceed the validator key count of the operator @@ -967,13 +930,6 @@ contract StakingContract { _depositOnOneOperator(depositCount, totalAvailableValidators); } - function _min(uint256 _a, uint256 _b) internal pure returns (uint256) { - if (_a < _b) { - return _a; - } - return _b; - } - /// @notice Internal utility to compute the receiver deterministic address /// @param _publicKey Public Key assigned to the receiver /// @param _prefix Prefix used to generate multiple receivers per public key diff --git a/src/contracts/libs/StakingContractStorageLib.sol b/src/contracts/libs/StakingContractStorageLib.sol index 911412d..7b57616 100644 --- a/src/contracts/libs/StakingContractStorageLib.sol +++ b/src/contracts/libs/StakingContractStorageLib.sol @@ -315,21 +315,6 @@ library StakingContractStorageLib { =========================================== =========================================*/ - bytes32 internal constant WITHDRAWER_CUSTOMIZATION_ENABLED_SLOT = - keccak256("StakingContract.withdrawerCustomizationEnabled"); - - function getWithdrawerCustomizationEnabled() internal view returns (bool) { - return getBool(WITHDRAWER_CUSTOMIZATION_ENABLED_SLOT); - } - - function setWithdrawerCustomizationEnabled(bool _enabled) internal { - setBool(WITHDRAWER_CUSTOMIZATION_ENABLED_SLOT, _enabled); - } - - /* ======================================== - =========================================== - =========================================*/ - bytes32 internal constant EXIT_REQUEST_MAPPING_SLOT = bytes32(uint256(keccak256("StakingContract.exitRequest")) - 1); diff --git a/src/test/StakingContract.t.sol b/src/test/StakingContract.t.sol index ac13545..627a4e2 100644 --- a/src/test/StakingContract.t.sol +++ b/src/test/StakingContract.t.sol @@ -787,78 +787,6 @@ contract StakingContractTest is Test { vm.stopPrank(); } - event SetWithdrawerCustomizationStatus(bool _status); - - function testSetWithdrawer(address user, address anotherUser) public { - vm.assume(user != address(depositContract) && anotherUser != address(depositContract)); - vm.assume(anotherUser != address(0)); - vm.deal(user, 32 * 3 ether); - - vm.startPrank(user); - (bool _success, ) = address(stakingContract).call{value: 32 * 3 ether}(""); - assert(_success == true); - vm.stopPrank(); - - assertEq(user.balance, 0); - - bytes memory pk = PUBKEY_1; - - assertEq(stakingContract.getWithdrawer(pk), user); - - vm.startPrank(admin); - vm.expectEmit(true, true, true, true); - emit SetWithdrawerCustomizationStatus(true); - stakingContract.setWithdrawerCustomizationEnabled(true); - vm.stopPrank(); - - vm.startPrank(user); - stakingContract.setWithdrawer(pk, anotherUser); - vm.stopPrank(); - } - - function testSetWithdrawerForbidden(address user, address anotherUser) public { - vm.assume(user != address(depositContract) && anotherUser != address(depositContract)); - vm.deal(user, 32 * 3 ether); - - vm.startPrank(user); - (bool _success, ) = address(stakingContract).call{value: 32 * 3 ether}(""); - assert(_success == true); - vm.stopPrank(); - - assertEq(user.balance, 0); - - assertEq(stakingContract.getWithdrawer(PUBKEY_1), user); - - vm.startPrank(user); - vm.expectRevert(abi.encodeWithSignature("Forbidden()")); - stakingContract.setWithdrawer(PUBKEY_1, anotherUser); - vm.stopPrank(); - } - - function testSetWithdrawerUnauthorized(address user, address anotherUser) public { - vm.assume(user != address(depositContract) && anotherUser != address(depositContract)); - vm.assume(anotherUser != address(0) && anotherUser != user); - vm.deal(user, 32 * 3 ether); - - vm.startPrank(user); - (bool _success, ) = address(stakingContract).call{value: 32 * 3 ether}(""); - assert(_success == true); - vm.stopPrank(); - - assertEq(user.balance, 0); - - vm.startPrank(admin); - stakingContract.setWithdrawerCustomizationEnabled(true); - vm.stopPrank(); - - assertEq(stakingContract.getWithdrawer(PUBKEY_1), user); - - vm.startPrank(anotherUser); - vm.expectRevert(abi.encodeWithSignature("Unauthorized()")); - stakingContract.setWithdrawer(PUBKEY_1, anotherUser); - vm.stopPrank(); - } - event ChangedTreasury(address newTreasury); function testSetTreasury(address newTreasury) public {