Skip to content

Commit

Permalink
Merge pull request #17 from symbioticfi/statemind-readuit-fixes
Browse files Browse the repository at this point in the history
Statemind readuit fixes
  • Loading branch information
1kresh authored Jan 22, 2025
2 parents 6eeb9af + 9f22b9a commit 2f29699
Show file tree
Hide file tree
Showing 10 changed files with 61 additions and 65 deletions.
13 changes: 3 additions & 10 deletions src/examples/simple-pos-network/SimplePosMiddleware.sol
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ contract SimplePosMiddleware is

params.vaults = _activeVaultsAt(params.epochStart, params.operator);
params.subnetworks = _activeSubnetworksAt(params.epochStart);
params.totalPower = _getOperatorPower(params.operator, params.vaults, params.subnetworks);
params.totalPower = _getOperatorPowerAt(params.epochStart, params.operator, params.vaults, params.subnetworks);
uint256 vaultsLength = params.vaults.length;
uint256 subnetworksLength = params.subnetworks.length;

Expand Down Expand Up @@ -178,15 +178,8 @@ contract SimplePosMiddleware is
}
}

function executeSlash(
uint48 epochStart,
address vault,
bytes32 subnetwork,
address operator,
uint256 amount,
bytes memory hints
) external checkAccess {
_slashVault(epochStart, vault, subnetwork, operator, amount, hints);
function executeSlash(address vault, uint256 slashIndex, bytes memory hints) external checkAccess {
_executeSlash(vault, slashIndex, hints);
}

function _checkCanSlash(uint48 epochStart, bytes32 key, address operator) internal view {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import {KeyManagerAddress} from "../../extensions/managers/keys/KeyManagerAddres
import {TimestampCapture} from "../../extensions/managers/capture-timestamps/TimestampCapture.sol";
import {EqualStakePower} from "../../extensions/managers/stake-powers/EqualStakePower.sol";

// WARING: this is a simple example, it's not secure and should not be used in production
/**
* @title SelfRegisterSqrtTaskMiddleware
* @notice Middleware for managing sqrt computation tasks with self-registering operators
Expand Down Expand Up @@ -200,15 +201,8 @@ contract SelfRegisterSqrtTaskMiddleware is
}
}

function executeSlash(
uint48 epochStart,
address vault,
bytes32 subnetwork,
address operator,
uint256 amount,
bytes memory hints
) external checkAccess {
_slashVault(epochStart, vault, subnetwork, operator, amount, hints);
function executeSlash(address vault, uint256 slashIndex, bytes memory hints) external checkAccess {
_executeSlash(vault, slashIndex, hints);
}

function _beforeRegisterOperatorVault(address operator, address vault) internal override {
Expand Down
12 changes: 3 additions & 9 deletions src/examples/sqrt-task-network/SqrtTaskMiddleware.sol
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import {NoKeyManager} from "../../extensions/managers/keys/NoKeyManager.sol";
import {TimestampCapture} from "../../extensions/managers/capture-timestamps/TimestampCapture.sol";
import {EqualStakePower} from "../../extensions/managers/stake-powers/EqualStakePower.sol";

// WARING: this is a simple example, it's not secure and should not be used in production
contract SqrtTaskMiddleware is
SharedVaults,
Operators,
Expand Down Expand Up @@ -166,14 +167,7 @@ contract SqrtTaskMiddleware is
}
}

function executeSlash(
uint48 epochStart,
address vault,
bytes32 subnetwork,
address operator,
uint256 amount,
bytes memory hints
) external checkAccess {
_slashVault(epochStart, vault, subnetwork, operator, amount, hints);
function executeSlash(address vault, uint256 slashIndex, bytes memory hints) external checkAccess {
_executeSlash(vault, slashIndex, hints);
}
}
10 changes: 6 additions & 4 deletions src/extensions/managers/access/OwnableAccessManager.sol
Original file line number Diff line number Diff line change
Expand Up @@ -30,16 +30,15 @@ abstract contract OwnableAccessManager is AccessManager, IOwnableAccessManager {
function __OwnableAccessManager_init(
address owner_
) internal onlyInitializing {
if (owner_ == address(0)) {
revert InvalidOwner(address(0));
}
_setOwner(owner_);
}

function _setOwner(
address owner_
) private {
if (owner_ == address(0)) {
revert InvalidOwner(address(0));
}

bytes32 location = OwnableAccessManagerStorageLocation;
assembly {
sstore(location, owner_)
Expand Down Expand Up @@ -69,6 +68,9 @@ abstract contract OwnableAccessManager is AccessManager, IOwnableAccessManager {
function setOwner(
address owner_
) public checkAccess {
if (owner_ == address(0)) {
revert InvalidOwner(address(0));
}
_setOwner(owner_);
}

Expand Down
2 changes: 1 addition & 1 deletion src/extensions/managers/keys/KeyManagerAddress.sol
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ abstract contract KeyManagerAddress is KeyManager {

// keccak256(abi.encode(uint256(keccak256("symbiotic.storage.KeyManagerAddress")) - 1)) & ~bytes32(uint256(0xff))
bytes32 private constant KeyManagerAddressStorageLocation =
0x3da47716e6090d5a5545e03387f4dac112d37cd069a5573bb81de8579bd9dc00;
0xb864e827a56afd83aa8f7940e556fe526831aa2e6001c2c692580b8e7a7d1d00;

function _getKeyManagerAddressStorage() internal pure returns (KeyManagerAddressStorage storage s) {
bytes32 location = KeyManagerAddressStorageLocation;
Expand Down
2 changes: 1 addition & 1 deletion src/extensions/operators/BaseOperators.sol
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ abstract contract BaseOperators is BaseMiddleware {
function _registerOperatorImpl(address operator, bytes memory key, address vault) internal virtual {
_beforeRegisterOperator(operator, key, vault);
_registerOperator(operator);
_updateKey(operator, key);
_updateOperatorKeyImpl(operator, key);
if (vault != address(0)) {
_beforeRegisterOperatorVault(operator, vault);
_registerOperatorVault(operator, vault);
Expand Down
67 changes: 40 additions & 27 deletions src/extensions/operators/ForcePauseSelfRegisterOperators.sol
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,16 @@ pragma solidity ^0.8.25;
import {SelfRegisterOperators} from "./SelfRegisterOperators.sol";
import {IForcePauseSelfRegisterOperators} from
"../../interfaces/extensions/operators/IForcePauseSelfRegisterOperators.sol";
import {EnumerableMap} from "@openzeppelin/contracts/utils/structs/EnumerableMap.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 ForcePauseSelfRegisterOperators is SelfRegisterOperators, IForcePauseSelfRegisterOperators {
using EnumerableMap for EnumerableMap.AddressToAddressMap;

uint64 public constant ForcePauseSelfRegisterOperators_VERSION = 1;

struct ForcePauseSelfRegisterOperatorsStorage {
Expand All @@ -37,9 +40,8 @@ abstract contract ForcePauseSelfRegisterOperators is SelfRegisterOperators, IFor
) external checkAccess {
ForcePauseSelfRegisterOperatorsStorage storage $ = _getForcePauseStorage();
$.forcePaused[operator] = true;
_beforePauseOperator(operator);
if (_operatorWasActiveAt(_now(), operator)) {
_pauseOperator(operator);
if (_operatorWasActiveAt(_now() + 1, operator)) {
_pauseOperatorImpl(operator);
}
}

Expand All @@ -51,8 +53,10 @@ abstract contract ForcePauseSelfRegisterOperators is SelfRegisterOperators, IFor
) external checkAccess {
ForcePauseSelfRegisterOperatorsStorage storage $ = _getForcePauseStorage();
$.forcePaused[operator] = false;
_beforeUnpauseOperator(operator);
_unpauseOperator(operator);
if (!_isOperatorRegistered(operator)) {
return;
}
_unpauseOperatorImpl(operator);
}

/**
Expand All @@ -61,8 +65,7 @@ abstract contract ForcePauseSelfRegisterOperators is SelfRegisterOperators, IFor
function forceUnregisterOperator(
address operator
) external checkAccess {
_beforeUnregisterOperator(operator);
_unregisterOperator(operator);
_unregisterOperatorImpl(operator);
}

/**
Expand All @@ -71,9 +74,8 @@ abstract contract ForcePauseSelfRegisterOperators is SelfRegisterOperators, IFor
function forcePauseOperatorVault(address operator, address vault) external checkAccess {
ForcePauseSelfRegisterOperatorsStorage storage $ = _getForcePauseStorage();
$.forcePausedVault[operator][vault] = true;
_beforePauseOperatorVault(operator, vault);
if (_operatorVaultWasActiveAt(_now(), operator, vault)) {
_pauseOperatorVault(operator, vault);
if (_operatorVaultWasActiveAt(_now() + 1, operator, vault)) {
_pauseOperatorVaultImpl(operator, vault);
}
}

Expand All @@ -83,16 +85,18 @@ abstract contract ForcePauseSelfRegisterOperators is SelfRegisterOperators, IFor
function forceUnpauseOperatorVault(address operator, address vault) external checkAccess {
ForcePauseSelfRegisterOperatorsStorage storage $ = _getForcePauseStorage();
$.forcePausedVault[operator][vault] = false;
_beforeUnpauseOperatorVault(operator, vault);
_unpauseOperatorVault(operator, vault);
VaultManagerStorage storage s = _getVaultManagerStorage();
if (!s._vaultOperator.contains(vault)) {
return;
}
_unpauseOperatorVaultImpl(operator, vault);
}

/**
* @inheritdoc IForcePauseSelfRegisterOperators
*/
function forceUnregisterOperatorVault(address operator, address vault) external checkAccess {
_beforeUnregisterOperatorVault(operator, vault);
_unregisterOperatorVault(operator, vault);
_unregisterOperatorVaultImpl(operator, vault);
}

/**
Expand All @@ -108,15 +112,14 @@ abstract contract ForcePauseSelfRegisterOperators is SelfRegisterOperators, IFor
}

/**
* @notice Override to prevent unregistering force-paused operators
* @notice Override to prevent registering force-paused operators
* @param operator The operator address
* @param key The operator's public key
* @param vault The vault address
*/
function _beforeUnregisterOperator(
address operator
) internal virtual override {
super._beforeUnregisterOperator(operator);
ForcePauseSelfRegisterOperatorsStorage storage $ = _getForcePauseStorage();
if ($.forcePaused[operator]) revert OperatorForcePaused();
function _beforeRegisterOperator(address operator, bytes memory key, address vault) internal virtual override {
super._beforeRegisterOperator(operator, key, vault);
if (_operatorForcePaused(operator)) revert OperatorForcePaused();
}

/**
Expand All @@ -126,18 +129,28 @@ abstract contract ForcePauseSelfRegisterOperators is SelfRegisterOperators, IFor
*/
function _beforeUnpauseOperatorVault(address operator, address vault) internal virtual override {
super._beforeUnpauseOperatorVault(operator, vault);
ForcePauseSelfRegisterOperatorsStorage storage $ = _getForcePauseStorage();
if ($.forcePausedVault[operator][vault]) revert OperatorVaultForcePaused();
if (_operatorVaultForcePaused(operator, vault)) revert OperatorVaultForcePaused();
}

/**
* @notice Override to prevent unregistering force-paused operator-vault pairs
* @notice Override to prevent registering force-paused operator-vault pairs
* @param operator The operator address
* @param vault The vault address
*/
function _beforeUnregisterOperatorVault(address operator, address vault) internal virtual override {
super._beforeUnregisterOperatorVault(operator, vault);
function _beforeRegisterOperatorVault(address operator, address vault) internal virtual override {
super._beforeRegisterOperatorVault(operator, vault);
if (_operatorVaultForcePaused(operator, vault)) revert OperatorVaultForcePaused();
}

function _operatorForcePaused(
address operator
) private view returns (bool) {
ForcePauseSelfRegisterOperatorsStorage storage $ = _getForcePauseStorage();
return $.forcePaused[operator];
}

function _operatorVaultForcePaused(address operator, address vault) private view returns (bool) {
ForcePauseSelfRegisterOperatorsStorage storage $ = _getForcePauseStorage();
if ($.forcePausedVault[operator][vault]) revert OperatorVaultForcePaused();
return $.forcePausedVault[operator][vault];
}
}
4 changes: 2 additions & 2 deletions src/managers/VaultManager.sol
Original file line number Diff line number Diff line change
Expand Up @@ -434,7 +434,7 @@ abstract contract VaultManager is NetworkStorage, SlashingWindowStorage, Capture
address[] memory vaults = _activeVaultsAt(timestamp, operator);
uint160[] memory subnetworks = _activeSubnetworksAt(timestamp);

return _getOperatorPower(operator, vaults, subnetworks);
return _getOperatorPowerAt(timestamp, operator, vaults, subnetworks);
}

/**
Expand Down Expand Up @@ -683,7 +683,7 @@ abstract contract VaultManager is NetworkStorage, SlashingWindowStorage, Capture
function _executeSlash(
address vault,
uint256 slashIndex,
bytes calldata hints
bytes memory hints
) internal returns (uint256 slashedAmount) {
address slasher = IVault(vault).slasher();
uint64 slasherType = IEntity(slasher).TYPE();
Expand Down
2 changes: 1 addition & 1 deletion src/managers/storages/NetworkStorage.sol
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import {Initializable} from "@openzeppelin/contracts-upgradeable/proxy/utils/Ini
*/
abstract contract NetworkStorage is Initializable {
// keccak256(abi.encode(uint256(keccak256("symbiotic.storage.NetworkStorage")) - 1)) & ~bytes32(uint256(0xff))
bytes32 private constant NetworkStorageLocation = 0x779150488f5e984d1f840ba606e388ada6c73b44f261274c3595c61a30023e00;
bytes32 private constant NetworkStorageLocation = 0x933223a21808ea6583da836861e2265bfa3c7e3b9070740cd75dc9ff6fb41700;

/**
* @notice Initializes the NetworkManager contract
Expand Down
2 changes: 1 addition & 1 deletion src/managers/storages/SlashingWindowStorage.sol
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import {Initializable} from "@openzeppelin/contracts-upgradeable/proxy/utils/Ini
abstract contract SlashingWindowStorage is Initializable {
// keccak256(abi.encode(uint256(keccak256("symbiotic.storage.SlashingWindowStorage")) - 1)) & ~bytes32(uint256(0xff))
bytes32 private constant SlashingWindowStorageLocation =
0x52becd5b30d67421b1f63b9d90d513daf82b3973912d3edfdac9468c1743c000;
0x937e0d2984afc3afaa413d74098ba180cc0c6aae6527cc2713827ed6bc72f200;

/**
* @notice Initializes the SlashingWindowStorage contract
Expand Down

0 comments on commit 2f29699

Please sign in to comment.