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

fix: rm approvalselfregisteroperators and add power threshold to selfregisteroperators #13

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
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
2 changes: 1 addition & 1 deletion lib/core
Submodule core updated 213 files
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ contract SelfRegisterEd25519Middleware is
address owner
) internal initializer {
__BaseMiddleware_init(network, slashingWindow, vaultRegistry, operatorRegistry, operatorNetOptin, reader);
__SelfRegisterOperators_init("SelfRegisterEd25519Middleware");
__SelfRegisterOperators_init("SelfRegisterEd25519Middleware", 0);
__OwnableAccessManager_init(owner);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ contract SelfRegisterMiddleware is
address owner
) internal initializer {
__BaseMiddleware_init(network, slashingWindow, vaultRegistry, operatorRegistry, operatorNetOptIn, reader);
__SelfRegisterOperators_init("SelfRegisterMiddleware");
__SelfRegisterOperators_init("SelfRegisterMiddleware", 0);
__OwnableAccessManager_init(owner);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ contract SelfRegisterSqrtTaskMiddleware is
INetworkRegistry(networkRegistry).registerNetwork();
__BaseMiddleware_init(address(this), slashingWindow, vaultRegistry, operatorRegistry, operatorNetOptin, reader);
__OwnableAccessManager_init(owner);
__SelfRegisterOperators_init("SelfRegisterSqrtTaskMiddleware");
__SelfRegisterOperators_init("SelfRegisterSqrtTaskMiddleware", 0);
}

function createTask(uint256 value, address validator) external returns (uint256 taskIndex) {
Expand Down
110 changes: 0 additions & 110 deletions src/extensions/operators/ApprovalRegisterOperators.sol

This file was deleted.

61 changes: 0 additions & 61 deletions src/extensions/operators/ForcePauseApprovalRegisterOperators.sol

This file was deleted.

39 changes: 29 additions & 10 deletions src/extensions/operators/SelfRegisterOperators.sol
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ abstract contract SelfRegisterOperators is BaseOperators, SigManager, EIP712Upgr
keccak256("UnpauseOperatorVault(address operator,address vault,uint256 nonce)");

struct SelfRegisterOperatorsStorage {
uint256 minPower;
mapping(address => uint256) nonces;
}

Expand All @@ -49,27 +50,29 @@ abstract contract SelfRegisterOperators is BaseOperators, SigManager, EIP712Upgr
}
}

function nonces(
address operator
) public view returns (uint256) {
return _getSelfRegisterOperatorsStorage().nonces[operator];
}

/**
* @notice Initializes the contract with EIP712 domain separator
* @notice Initializes the contract with EIP712 domain separator and minimum power threshold
* @param name The name to use for the EIP712 domain separator
* @param _minPower The minimum power threshold
*/
function __SelfRegisterOperators_init(
string memory name
) internal onlyInitializing {
function __SelfRegisterOperators_init(string memory name, uint256 _minPower) internal onlyInitializing {
__EIP712_init(name, "1");
SelfRegisterOperatorsStorage storage $ = _getSelfRegisterOperatorsStorage();
$.minPower = _minPower;
}

function nonces(
address operator
) public view returns (uint256) {
return _getSelfRegisterOperatorsStorage().nonces[operator];
}

/**
* @inheritdoc ISelfRegisterOperators
*/
function registerOperator(bytes memory key, address vault, bytes memory signature) external virtual {
_verifyKey(msg.sender, key, signature);
_checkMinPower(msg.sender, vault);
_registerOperatorImpl(msg.sender, key, vault);
}

Expand All @@ -84,6 +87,7 @@ abstract contract SelfRegisterOperators is BaseOperators, SigManager, EIP712Upgr
bytes memory keySignature
) public virtual {
_verifyKey(operator, key, keySignature);
_checkMinPower(operator, vault);
SelfRegisterOperatorsStorage storage $ = _getSelfRegisterOperatorsStorage();
_verifyEIP712(
operator,
Expand Down Expand Up @@ -265,6 +269,21 @@ abstract contract SelfRegisterOperators is BaseOperators, SigManager, EIP712Upgr
_unpauseOperatorVaultImpl(operator, vault);
}

function _checkMinPower(address operator, address vault) internal view {
SelfRegisterOperatorsStorage storage $ = _getSelfRegisterOperatorsStorage();
address[] memory vaults = _activeVaults();
uint160[] memory subnetworks = _activeSubnetworks();
uint256 power = _getOperatorPower(operator, vaults, subnetworks);
if (address(vault) != address(0)) {
vaults = new address[](1);
vaults[0] = vault;
power += _getOperatorPower(operator, vaults, subnetworks);
}
if (power < $.minPower) {
revert NotEnoughPower();
}
}

/**
* @notice Verifies a key signature
* @param operator The address of the operator
Expand Down
63 changes: 0 additions & 63 deletions src/interfaces/extensions/operators/IApprovalRegisterOperators.sol

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ pragma solidity ^0.8.25;
*/
interface ISelfRegisterOperators {
error InvalidSignature();
error NotEnoughPower();

/**
* @notice Returns the nonce for an operator address
Expand Down
9 changes: 6 additions & 3 deletions src/managers/VaultManager.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down Expand Up @@ -733,8 +734,10 @@ abstract contract VaultManager is NetworkStorage, SlashingWindowStorage, Capture
function _validateOperatorVault(address operator, address vault) internal view {
address delegator = IVault(vault).delegator();
if (
IEntity(delegator).TYPE() != uint64(DelegatorType.OPERATOR_SPECIFIC)
|| IOperatorSpecificDelegator(delegator).operator() != operator
(
IEntity(delegator).TYPE() != uint64(DelegatorType.OPERATOR_SPECIFIC)
&& IEntity(delegator).TYPE() != uint64(DelegatorType.OPERATOR_NETWORK_SPECIFIC)
) || IOperatorSpecificDelegator(delegator).operator() != operator
) {
revert NotOperatorSpecificVault();
}
Expand Down
Loading