From 68334572da818cc547aca8e729321e98df97a2a8 Mon Sep 17 00:00:00 2001 From: Kresh Date: Tue, 7 Jan 2025 16:20:16 +0400 Subject: [PATCH] feat: support new delegator type --- .../operators/ApprovalRegisterOperators.sol | 110 ------------------ .../ForcePauseApprovalRegisterOperators.sol | 61 ---------- .../operators/IApprovalRegisterOperators.sol | 63 ---------- src/managers/VaultManager.sol | 10 +- 4 files changed, 7 insertions(+), 237 deletions(-) delete mode 100644 src/extensions/operators/ApprovalRegisterOperators.sol delete mode 100644 src/extensions/operators/ForcePauseApprovalRegisterOperators.sol delete mode 100644 src/interfaces/extensions/operators/IApprovalRegisterOperators.sol diff --git a/src/extensions/operators/ApprovalRegisterOperators.sol b/src/extensions/operators/ApprovalRegisterOperators.sol deleted file mode 100644 index dda290e..0000000 --- a/src/extensions/operators/ApprovalRegisterOperators.sol +++ /dev/null @@ -1,110 +0,0 @@ -// SPDX-License-Identifier: MIT -pragma solidity ^0.8.25; - -import {SelfRegisterOperators} from "./SelfRegisterOperators.sol"; -import {IApprovalRegisterOperators} from "../../interfaces/extensions/operators/IApprovalRegisterOperators.sol"; -/** - * @title ApprovalRegisterOperators - * @notice Extends SelfRegisterOperators to add approval-based registration - */ - -abstract contract ApprovalRegisterOperators is SelfRegisterOperators, IApprovalRegisterOperators { - uint64 public constant ApprovalRegisterOperators_VERSION = 1; - - struct ApprovalRegisterOperatorsStorage { - RegistrationRequest[] requests; - } - - // keccak256(abi.encode(uint256(keccak256("symbiotic.storage.ApprovalRegisterOperators")) - 1)) & ~bytes32(uint256(0xff)) - bytes32 private constant ApprovalRegisterOperators_STORAGE_LOCATION = - 0x8d3c0d900c3fcfbc53470fac03a90d5cf6aa7b77c3f1ed10e6c6bd4d192eaf00; - - function _getApprovalRegisterOperatorsStorage() private pure returns (ApprovalRegisterOperatorsStorage storage $) { - bytes32 location = ApprovalRegisterOperators_STORAGE_LOCATION; - assembly { - $.slot := location - } - } - - /** - * @inheritdoc IApprovalRegisterOperators - */ - function getRegistrationRequestCount() public view returns (uint256) { - return _getApprovalRegisterOperatorsStorage().requests.length; - } - - /** - * @inheritdoc IApprovalRegisterOperators - */ - function getRegistrationRequest( - uint256 index - ) public view returns (RegistrationRequest memory) { - return _getApprovalRegisterOperatorsStorage().requests[index]; - } - - /** - * @inheritdoc IApprovalRegisterOperators - */ - function registerOperator( - uint256 requestIndex - ) external checkAccess { - RegistrationRequest memory request = getRegistrationRequest(requestIndex); - _registerOperatorImpl(request.operator, request.key, request.vault); - ApprovalRegisterOperatorsStorage storage $ = _getApprovalRegisterOperatorsStorage(); - uint256 lastIndex = $.requests.length - 1; - if (requestIndex != lastIndex) { - $.requests[requestIndex] = $.requests[lastIndex]; - } - $.requests.pop(); - } - - /** - * @notice Override to prevent direct registration - */ - function registerOperator(bytes memory key, address vault, bytes memory signature) external virtual override { - revert DirectRegistrationNotAllowed(); - } - - /** - * @notice Override to prevent direct registration - */ - function registerOperator( - address operator, - bytes memory key, - address vault, - bytes memory signature, - bytes memory keySignature - ) public virtual override { - revert DirectRegistrationNotAllowed(); - } - - /** - * @inheritdoc IApprovalRegisterOperators - */ - function requestRegisterOperator(bytes memory key, address vault, bytes memory signature) external { - _verifyKey(msg.sender, key, signature); - ApprovalRegisterOperatorsStorage storage $ = _getApprovalRegisterOperatorsStorage(); - $.requests.push(RegistrationRequest({operator: msg.sender, vault: vault, key: key})); - } - - /** - * @inheritdoc IApprovalRegisterOperators - */ - function requestRegisterOperator( - address operator, - bytes memory key, - address vault, - bytes memory signature, - bytes memory keySignature - ) public { - SelfRegisterOperatorsStorage storage s = _getSelfRegisterOperatorsStorage(); - _verifyEIP712( - operator, - keccak256(abi.encode(REGISTER_OPERATOR_TYPEHASH, operator, keccak256(key), vault, s.nonces[operator]++)), - signature - ); - _verifyKey(operator, key, keySignature); - ApprovalRegisterOperatorsStorage storage $ = _getApprovalRegisterOperatorsStorage(); - $.requests.push(RegistrationRequest({operator: operator, vault: vault, key: key})); - } -} diff --git a/src/extensions/operators/ForcePauseApprovalRegisterOperators.sol b/src/extensions/operators/ForcePauseApprovalRegisterOperators.sol deleted file mode 100644 index 5ec1e29..0000000 --- a/src/extensions/operators/ForcePauseApprovalRegisterOperators.sol +++ /dev/null @@ -1,61 +0,0 @@ -// SPDX-License-Identifier: MIT -pragma solidity ^0.8.25; - -import {ApprovalRegisterOperators} from "./ApprovalRegisterOperators.sol"; -import {SelfRegisterOperators} from "./SelfRegisterOperators.sol"; -import {ForcePauseSelfRegisterOperators} from "./ForcePauseSelfRegisterOperators.sol"; -import {BaseOperators} from "./BaseOperators.sol"; -/** - * @title ForcePauseSelfRegisterOperators - * @notice Extension of SelfRegisterOperators that allows authorized addresses to forcefully pause operators - * @dev Implements force pause functionality and prevents unpausing of force-paused operators - */ - -abstract contract ForcePauseApprovalRegisterOperators is ForcePauseSelfRegisterOperators, ApprovalRegisterOperators { - uint64 public constant ForcePauseApprovalRegisterOperators_VERSION = 1; - - function registerOperator( - bytes memory key, - address vault, - bytes memory signature - ) external override(ApprovalRegisterOperators, SelfRegisterOperators) { - revert DirectRegistrationNotAllowed(); - } - - // Override the registerOperator function to resolve ambiguity - function registerOperator( - address operator, - bytes memory key, - address vault, - bytes memory signature, - bytes memory keySignature - ) public override(ApprovalRegisterOperators, SelfRegisterOperators) { - revert DirectRegistrationNotAllowed(); - } - - function _beforeUnpauseOperator( - address operator - ) internal virtual override(ForcePauseSelfRegisterOperators, BaseOperators) { - super._beforeUnpauseOperator(operator); - } - - function _beforeUnpauseOperatorVault( - address operator, - address vault - ) internal virtual override(ForcePauseSelfRegisterOperators, BaseOperators) { - super._beforeUnpauseOperatorVault(operator, vault); - } - - function _beforeUnregisterOperator( - address operator - ) internal virtual override(ForcePauseSelfRegisterOperators, BaseOperators) { - super._beforeUnregisterOperator(operator); - } - - function _beforeUnregisterOperatorVault( - address operator, - address vault - ) internal virtual override(BaseOperators, ForcePauseSelfRegisterOperators) { - super._beforeUnregisterOperatorVault(operator, vault); - } -} diff --git a/src/interfaces/extensions/operators/IApprovalRegisterOperators.sol b/src/interfaces/extensions/operators/IApprovalRegisterOperators.sol deleted file mode 100644 index 5aa416d..0000000 --- a/src/interfaces/extensions/operators/IApprovalRegisterOperators.sol +++ /dev/null @@ -1,63 +0,0 @@ -// SPDX-License-Identifier: MIT -pragma solidity ^0.8.25; - -/** - * @title IApprovalRegisterOperators - * @notice Interface for approval-based operator registration - */ -interface IApprovalRegisterOperators { - struct RegistrationRequest { - address operator; - address vault; - bytes key; - } - - error DirectRegistrationNotAllowed(); - - /** - * @notice Get the total number of pending registration requests - * @return The number of requests - */ - function getRegistrationRequestCount() external view returns (uint256); - - /** - * @notice Get a specific registration request by index - * @param index The index of the request to retrieve - * @return The registration request details - */ - function getRegistrationRequest( - uint256 index - ) external view returns (RegistrationRequest memory); - - /** - * @notice Register an operator based on a pending request - * @param requestIndex The index of the request to register - */ - function registerOperator( - uint256 requestIndex - ) external; - - /** - * @notice Request registration as an operator - * @param key The operator's public key - * @param vault Optional vault address to associate - * @param signature Signature proving ownership of the key - */ - function requestRegisterOperator(bytes memory key, address vault, bytes memory signature) external; - - /** - * @notice Request registration on behalf of another operator - * @param operator The address of the operator to register - * @param key The operator's public key - * @param vault Optional vault address to associate - * @param signature EIP712 signature authorizing registration - * @param keySignature Signature proving ownership of the key - */ - function requestRegisterOperator( - address operator, - bytes memory key, - address vault, - bytes memory signature, - bytes memory keySignature - ) external; -} diff --git a/src/managers/VaultManager.sol b/src/managers/VaultManager.sol index 0a5cc9f..615a75f 100644 --- a/src/managers/VaultManager.sol +++ b/src/managers/VaultManager.sol @@ -65,7 +65,8 @@ abstract contract VaultManager is NetworkStorage, SlashingWindowStorage, Capture enum DelegatorType { FULL_RESTAKE, NETWORK_RESTAKE, - OPERATOR_SPECIFIC + OPERATOR_SPECIFIC, + OPERATOR_NETWORK_SPECIFIC } // keccak256(abi.encode(uint256(keccak256("symbiotic.storage.VaultManager")) - 1)) & ~bytes32(uint256(0xff)) @@ -732,9 +733,12 @@ abstract contract VaultManager is NetworkStorage, SlashingWindowStorage, Capture function _validateOperatorVault(address operator, address vault) internal view { address delegator = IVault(vault).delegator(); + uint64 delegatorType = IEntity(delegator).TYPE(); if ( - IEntity(delegator).TYPE() != uint64(DelegatorType.OPERATOR_SPECIFIC) - || IOperatorSpecificDelegator(delegator).operator() != operator + ( + delegatorType != uint64(DelegatorType.OPERATOR_SPECIFIC) + && delegatorType != uint64(DelegatorType.OPERATOR_NETWORK_SPECIFIC) + ) || IOperatorSpecificDelegator(delegator).operator() != operator ) { revert NotOperatorSpecificVault(); }