Skip to content

Commit

Permalink
fix: fix compilation issues and tests
Browse files Browse the repository at this point in the history
  • Loading branch information
wadealexc committed Oct 30, 2023
1 parent 066a6dc commit 12b09de
Show file tree
Hide file tree
Showing 23 changed files with 845 additions and 750 deletions.
4 changes: 2 additions & 2 deletions src/BLSPubkeyRegistry.sol
Original file line number Diff line number Diff line change
Expand Up @@ -94,10 +94,10 @@ contract BLSPubkeyRegistry is BLSPubkeyRegistryStorage {
}

/**
* @notice Creates a new quorum by pushing its first apk update
* @notice Initializes a new quorum by pushing its first apk update
* @param quorumNumber The number of the new quorum
*/
function createQuorum(uint8 quorumNumber) public virtual onlyRegistryCoordinator {
function initializeQuorum(uint8 quorumNumber) public virtual onlyRegistryCoordinator {
require(quorumApkUpdates[quorumNumber].length == 0, "BLSPubkeyRegistry.createQuorum: quorum already exists");

quorumApkUpdates[quorumNumber].push(ApkUpdate({
Expand Down
26 changes: 10 additions & 16 deletions src/BLSRegistryCoordinatorWithIndices.sol
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import "src/interfaces/IBLSRegistryCoordinatorWithIndices.sol";
import "src/interfaces/ISocketUpdater.sol";
import "src/interfaces/IServiceManager.sol";
import "src/interfaces/IBLSPubkeyRegistry.sol";
import "src/interfaces/IVoteWeigher.sol";
import "src/interfaces/IStakeRegistry.sol";
import "src/interfaces/IIndexRegistry.sol";
import "src/interfaces/IRegistryCoordinator.sol";
Expand Down Expand Up @@ -50,11 +49,11 @@ contract BLSRegistryCoordinatorWithIndices is EIP712, Initializable, IBLSRegistr
/// @notice the Service Manager for the service that this contract is coordinating
IServiceManager public immutable serviceManager;
/// @notice the BLS Pubkey Registry contract that will keep track of operators' BLS public keys
BLSPubkeyRegistry public immutable blsPubkeyRegistry;
IBLSPubkeyRegistry public immutable blsPubkeyRegistry;
/// @notice the Stake Registry contract that will keep track of operators' stakes
StakeRegistry public immutable stakeRegistry;
IStakeRegistry public immutable stakeRegistry;
/// @notice the Index Registry contract that will keep track of operators' indexes
IndexRegistry public immutable indexRegistry;
IIndexRegistry public immutable indexRegistry;

/// @notice the current number of quorums supported by the registry coordinator
uint8 public quorumCount;
Expand Down Expand Up @@ -113,7 +112,7 @@ contract BLSRegistryCoordinatorWithIndices is EIP712, Initializable, IBLSRegistr
uint256 _initialPausedStatus,
OperatorSetParam[] memory _operatorSetParams,
uint96[] memory _minimumStakes,
IVoteWeigher.StrategyAndWeightingMultiplier[][] memory _strategyParams
IStakeRegistry.StrategyAndWeightingMultiplier[][] memory _strategyParams
) external initializer {
require(
_operatorSetParams.length == _minimumStakes.length && _minimumStakes.length == _strategyParams.length,
Expand Down Expand Up @@ -342,7 +341,7 @@ contract BLSRegistryCoordinatorWithIndices is EIP712, Initializable, IBLSRegistr
function createQuorum(
OperatorSetParam memory operatorSetParams,
uint96 minimumStake,
IVoteWeigher.StrategyAndWeightingMultiplier[] memory strategyParams
IStakeRegistry.StrategyAndWeightingMultiplier[] memory strategyParams
) external virtual onlyServiceManagerOwner {
_createQuorum(operatorSetParams, minimumStake, strategyParams);
}
Expand Down Expand Up @@ -388,12 +387,7 @@ contract BLSRegistryCoordinatorWithIndices is EIP712, Initializable, IBLSRegistr
bytes calldata quorumNumbers,
BN254.G1Point memory pubkey,
string memory socket
) internal virtual returns(uint32[] memory) {
// require(
// slasher.contractCanSlashOperatorUntilBlock(operator, address(serviceManager)) == type(uint32).max,
// "StakeRegistry._registerOperator: operator must be opted into slashing by the serviceManager"
// );

) internal virtual returns(uint32[] memory) {
// get the quorum bitmap from the quorum numbers
uint256 quorumBitmap = BitmapUtils.orderedBytesArrayToBitmap(quorumNumbers);
require(quorumBitmap <= MAX_QUORUM_BITMAP, "BLSRegistryCoordinatorWithIndices._registerOperatorWithCoordinator: quorumBitmap exceeds of max bitmap size");
Expand Down Expand Up @@ -553,7 +547,7 @@ contract BLSRegistryCoordinatorWithIndices is EIP712, Initializable, IBLSRegistr
function _createQuorum(
OperatorSetParam memory operatorSetParams,
uint96 minimumStake,
IVoteWeigher.StrategyAndWeightingMultiplier[] memory strategyParams
IStakeRegistry.StrategyAndWeightingMultiplier[] memory strategyParams
) internal {
// Increment the total quorum count. Fails if we're already at the max
uint8 prevQuorumCount = quorumCount;
Expand All @@ -565,9 +559,9 @@ contract BLSRegistryCoordinatorWithIndices is EIP712, Initializable, IBLSRegistr

// Initialize the quorum here and in each registry
_setOperatorSetParams(quorumNumber, operatorSetParams);
stakeRegistry.createQuorum(quorumNumber, minimumStake, strategyParams);
indexRegistry.createQuorum(quorumNumber);
blsPubkeyRegistry.createQuorum(quorumNumber);
stakeRegistry.initializeQuorum(quorumNumber, minimumStake, strategyParams);
indexRegistry.initializeQuorum(quorumNumber);
blsPubkeyRegistry.initializeQuorum(quorumNumber);
}

function _setOperatorSetParams(uint8 quorumNumber, OperatorSetParam memory operatorSetParams) internal {
Expand Down
13 changes: 7 additions & 6 deletions src/IndexRegistry.sol
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ contract IndexRegistry is IndexRegistryStorage {
for (uint256 i = 0; i < quorumNumbers.length; i++) {
uint8 quorumNumber = uint8(quorumNumbers[i]);
uint32 indexOfOperatorToRemove = operatorIdToIndex[quorumNumber][operatorId];
uint256 historyLength = _totalOperatorsHistory[quorumNumber].length;
_processOperatorRemoval({
operatorId: operatorId,
quorumNumber: quorumNumber,
Expand All @@ -99,10 +100,10 @@ contract IndexRegistry is IndexRegistryStorage {
}

/**
* @notice Creates a new quorum by pushing its first quorum update
* @notice Initialize a quorum by pushing its first quorum update
* @param quorumNumber The number of the new quorum
*/
function createQuorum(uint8 quorumNumber) public virtual onlyRegistryCoordinator {
function initializeQuorum(uint8 quorumNumber) public virtual onlyRegistryCoordinator {
require(_totalOperatorsHistory[quorumNumber].length == 0, "IndexRegistry.createQuorum: quorum already exists");

_totalOperatorsHistory[quorumNumber].push(QuorumUpdate({
Expand Down Expand Up @@ -133,10 +134,10 @@ contract IndexRegistry is IndexRegistryStorage {
* @param index the latest index of that operator in the list of operators registered for this quorum
*/
function _updateOperatorIdToIndexHistory(bytes32 operatorId, uint8 quorumNumber, uint32 index) internal {
OperatorUpdate memory latestOperatorUpdate;
latestOperatorUpdate.operatorId = operatorId;
latestOperatorUpdate.fromBlockNumber = uint32(block.number);
_indexToOperatorIdHistory[quorumNumber][index].push(latestOperatorUpdate);
_indexToOperatorIdHistory[quorumNumber][index].push(OperatorUpdate({
operatorId: operatorId,
fromBlockNumber: uint32(block.number)
}));

operatorIdToIndex[quorumNumber][operatorId] = index;

Expand Down
23 changes: 14 additions & 9 deletions src/StakeRegistry.sol
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import "src/interfaces/IServiceManager.sol";
import "src/interfaces/IStakeRegistry.sol";
import "src/interfaces/IRegistryCoordinator.sol";
import "src/StakeRegistryStorage.sol";
import "src/VoteWeigherBaseStorage.sol";

/**
* @title A `Registry` that keeps track of stakes of operators for up to 256 quorums.
Expand All @@ -18,7 +17,7 @@ import "src/VoteWeigherBaseStorage.sol";
* It allows an additional functionality (in addition to registering and deregistering) to update the stake of an operator.
* @author Layr Labs, Inc.
*/
contract StakeRegistry is VoteWeigherBaseStorage, StakeRegistryStorage {
contract StakeRegistry is StakeRegistryStorage {

modifier onlyRegistryCoordinator() {
require(
Expand All @@ -42,7 +41,7 @@ contract StakeRegistry is VoteWeigherBaseStorage, StakeRegistryStorage {
IRegistryCoordinator _registryCoordinator,
IDelegationManager _delegationManager,
IServiceManager _serviceManager
) VoteWeigherBaseStorage(_delegationManager, _serviceManager) StakeRegistryStorage(_registryCoordinator) {}
) StakeRegistryStorage(_registryCoordinator, _delegationManager, _serviceManager) {}

/*******************************************************************************
EXTERNAL FUNCTIONS
Expand Down Expand Up @@ -187,15 +186,21 @@ contract StakeRegistry is VoteWeigherBaseStorage, StakeRegistryStorage {
}
}

/// @notice Create a new quorum and add the strategies and their associated weights to the quorum.
function createQuorum(
/// @notice Initialize a new quorum and push its first history update
function initializeQuorum(
uint8 quorumNumber,
uint96 minimumStake,
StrategyAndWeightingMultiplier[] memory strategyParams
) public virtual onlyRegistryCoordinator {
require(_totalStakeHistory[quorumNumber].length == 0, "StakeRegistry.createQuorum: quorum already exists");
require(_totalStakeHistory[quorumNumber].length == 0, "StakeRegistry.initializeQuorum: quorum already exists");
_addStrategyParams(quorumNumber, strategyParams);
_setMinimumStakeForQuorum(quorumNumber, minimumStake);

_totalStakeHistory[quorumNumber].push(OperatorStakeUpdate({
updateBlockNumber: uint32(block.number),
nextUpdateBlockNumber: 0,
stake: 0
}));
}

function setMinimumStakeForQuorum(
Expand All @@ -211,7 +216,7 @@ contract StakeRegistry is VoteWeigherBaseStorage, StakeRegistryStorage {
* @dev This function has no check to make sure that the strategies for a single quorum have the same underlying asset. This is a concious choice,
* since a middleware may want, e.g., a stablecoin quorum that accepts USDC, USDT, DAI, etc. as underlying assets and trades them as "equivalent".
*/
function addStrategyParams(
function addStrategies(
uint8 quorumNumber,
StrategyAndWeightingMultiplier[] memory strategyParams
) public virtual onlyServiceManagerOwner quorumExists(quorumNumber) {
Expand All @@ -223,7 +228,7 @@ contract StakeRegistry is VoteWeigherBaseStorage, StakeRegistryStorage {
* @dev higher indices should be *first* in the list of @param indicesToRemove, since otherwise
* the removal of lower index entries will cause a shift in the indices of the other strategies to remove
*/
function removeStrategyParams(
function removeStrategies(
uint8 quorumNumber,
uint256[] memory indicesToRemove
) public virtual onlyServiceManagerOwner quorumExists(quorumNumber) {
Expand Down Expand Up @@ -492,7 +497,7 @@ contract StakeRegistry is VoteWeigherBaseStorage, StakeRegistryStorage {
* @notice This function computes the total weight of the @param operator in the quorum @param quorumNumber.
* @dev this method DOES NOT check that the quorum exists
*/
function _weightOfOperatorForQuorum(uint8 quorumNumber, address operator) internal view returns (uint96) {
function _weightOfOperatorForQuorum(uint8 quorumNumber, address operator) internal virtual view returns (uint96) {
uint96 weight;
uint256 stratsLength = strategiesConsideredAndMultipliersLength(quorumNumber);
StrategyAndWeightingMultiplier memory strategyAndMultiplier;
Expand Down
32 changes: 30 additions & 2 deletions src/StakeRegistryStorage.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
pragma solidity =0.8.12;

import {IStrategyManager} from "eigenlayer-contracts/src/contracts/interfaces/IStrategyManager.sol";
import {IDelegationManager} from "eigenlayer-contracts/src/contracts/interfaces/IDelegationManager.sol";

import {IServiceManager} from "src/interfaces/IServiceManager.sol";
import {IStakeRegistry} from "src/interfaces/IStakeRegistry.sol";
import {IRegistryCoordinator} from "src/interfaces/IRegistryCoordinator.sol";
Expand All @@ -12,6 +14,20 @@ import {IRegistryCoordinator} from "src/interfaces/IRegistryCoordinator.sol";
* @notice This storage contract is separate from the logic to simplify the upgrade process.
*/
abstract contract StakeRegistryStorage is IStakeRegistry {

/// @notice Constant used as a divisor in calculating weights.
uint256 public constant WEIGHTING_DIVISOR = 1e18;
/// @notice Maximum length of dynamic arrays in the `strategiesConsideredAndMultipliers` mapping.
uint8 public constant MAX_WEIGHING_FUNCTION_LENGTH = 32;
/// @notice Constant used as a divisor in dealing with BIPS amounts.
uint256 internal constant MAX_BIPS = 10000;

/// @notice The address of the Delegation contract for EigenLayer.
IDelegationManager public immutable delegation;

/// @notice The ServiceManager contract for this middleware, where tasks are created / initiated.
IServiceManager public immutable serviceManager;

/// @notice the coordinator contract that this registry is associated with
IRegistryCoordinator public immutable registryCoordinator;

Expand All @@ -25,11 +41,23 @@ abstract contract StakeRegistryStorage is IStakeRegistry {
/// @notice mapping from operator's operatorId to the history of their stake updates
mapping(bytes32 => mapping(uint8 => OperatorStakeUpdate[])) internal operatorIdToStakeHistory;

constructor(IRegistryCoordinator _registryCoordinator) {
/**
* @notice mapping from quorum number to the list of strategies considered and their
* corresponding multipliers for that specific quorum
*/
mapping(uint8 => StrategyAndWeightingMultiplier[]) public strategiesConsideredAndMultipliers;

constructor(
IRegistryCoordinator _registryCoordinator,
IDelegationManager _delegationManager,
IServiceManager _serviceManager
) {
registryCoordinator = _registryCoordinator;
delegation = _delegationManager;
serviceManager = _serviceManager;
}

// storage gap for upgradeability
// slither-disable-next-line shadowing-state
uint256[65] private __GAP;
uint256[64] private __GAP;
}
50 changes: 0 additions & 50 deletions src/VoteWeigherBaseStorage.sol

This file was deleted.

6 changes: 6 additions & 0 deletions src/interfaces/IBLSPubkeyRegistry.sol
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,12 @@ interface IBLSPubkeyRegistry is IRegistry {
*/
function deregisterOperator(address operator, bytes calldata quorumNumbers, BN254.G1Point memory pubkey) external;

/**
* @notice Initializes a new quorum by pushing its first apk update
* @param quorumNumber The number of the new quorum
*/
function initializeQuorum(uint8 quorumNumber) external;

/// @notice Returns the current APK for the provided `quorumNumber `
function getApkForQuorum(uint8 quorumNumber) external view returns (BN254.G1Point memory);

Expand Down
6 changes: 6 additions & 0 deletions src/interfaces/IIndexRegistry.sol
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,12 @@ interface IIndexRegistry is IRegistry {
*/
function deregisterOperator(bytes32 operatorId, bytes calldata quorumNumbers) external;

/**
* @notice Initialize a quorum by pushing its first quorum update
* @param quorumNumber The number of the new quorum
*/
function initializeQuorum(uint8 quorumNumber) external;

/// @notice Returns the _indexToOperatorIdHistory entry for the specified `operatorIndex` and `quorumNumber` at the specified `index`
function getOperatorIndexUpdateOfIndexForQuorumAtIndex(uint32 operatorIndex, uint8 quorumNumber, uint32 index) external view returns (OperatorUpdate memory);

Expand Down
3 changes: 3 additions & 0 deletions src/interfaces/IRegistryCoordinator.sol
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@ interface IRegistryCoordinator {
uint192 quorumBitmap;
}

/// @notice Returns the number of quorums the registry coordinator has created
function quorumCount() external view returns (uint8);

/// @notice Returns the operator struct for the given `operator`
function getOperator(address operator) external view returns (Operator memory);

Expand Down
Loading

0 comments on commit 12b09de

Please sign in to comment.