Skip to content

Commit

Permalink
remove setWithdrawer() and unused code(fix #2, #5, #6, #7, #8)
Browse files Browse the repository at this point in the history
  • Loading branch information
0xvv committed Jan 20, 2025
1 parent 9fc63c3 commit 8c23b6f
Show file tree
Hide file tree
Showing 3 changed files with 0 additions and 131 deletions.
44 changes: 0 additions & 44 deletions src/contracts/StakingContract.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
15 changes: 0 additions & 15 deletions src/contracts/libs/StakingContractStorageLib.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
72 changes: 0 additions & 72 deletions src/test/StakingContract.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 8c23b6f

Please sign in to comment.