Skip to content

Commit eb0d6ad

Browse files
authored
chore: bump slashing core dependency (#312)
* chore: bump to slashing branch * chore: bump compiler version * fix: dep interface changes * fix: compiler errors from interface changes and type changes * fix: compiler errors * chore: bump dependencies * chore: bump core dependency and resolve issues * chore: bump core dependency and fix compiler errors * feat: integrate AllocationManager * feat: add a slashing permission to the service manager * chore: remove unneeded casting * feat: implement a slasher permission and forward call to AllocationManager * feat: add simiple slasher starting point * chore: bump slashing magnitudes * chore: bump core slashing-magnitudes branch
1 parent e0a79f1 commit eb0d6ad

34 files changed

+1032
-622
lines changed

foundry.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ optimizer_runs = 200
1515
# Whether or not to use the Yul intermediate representation compilation pipeline
1616
via_ir = false
1717
# Override the Solidity version (this overrides `auto_detect_solc`)
18-
solc_version = '0.8.12'
18+
solc_version = '0.8.27'
1919

2020
[etherscan]
2121
mainnet = { key = "${ETHERSCAN_API_KEY}" }

lib/eigenlayer-contracts

script/OperatorSetUpgrade.s.sol

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import {IBLSApkRegistry} from "../src/interfaces/IBLSApkRegistry.sol";
1212
import {IIndexRegistry} from "../src/interfaces/IIndexRegistry.sol";
1313
import {IRewardsCoordinator} from "eigenlayer-contracts/src/contracts/interfaces/IRewardsCoordinator.sol";
1414
import {IAVSDirectory} from "eigenlayer-contracts/src/contracts/interfaces/IAVSDirectory.sol";
15+
import {IAllocationManager} from "eigenlayer-contracts/src/contracts/interfaces/IAllocationManager.sol";
1516
import {IDelegationManager} from "eigenlayer-contracts/src/contracts/interfaces/IDelegationManager.sol";
1617
interface IServiceManagerMigration {
1718
function getOperatorsToMigrate()
@@ -46,6 +47,7 @@ contract OperatorSetUpgradeScript is Script {
4647
address public delegationManager;
4748
address public blsApkRegistry;
4849
address public indexRegistry;
50+
address public allocationManager;
4951

5052
function setUp() public {
5153
vm.label(DEFAULT_FORGE_SENDER, "DEFAULT FORGE SENDER");
@@ -145,7 +147,7 @@ contract OperatorSetUpgradeScript is Script {
145147
function _upgradeAvsDirectory() internal {
146148
address proxyAdmin = OperatorSetUpgradeLib.getAdmin(avsDirectory);
147149
address avsDirectoryOwner = Ownable(proxyAdmin).owner();
148-
AVSDirectory avsDirectoryImpl = new AVSDirectory(IDelegationManager(delegationManager));
150+
AVSDirectory avsDirectoryImpl = new AVSDirectory(IDelegationManager(delegationManager), 0); // TODO: config
149151

150152
vm.startPrank(avsDirectoryOwner);
151153
OperatorSetUpgradeLib.upgrade(avsDirectory, address(avsDirectoryImpl));
@@ -211,7 +213,8 @@ contract OperatorSetUpgradeScript is Script {
211213
IAVSDirectory(avsDirectory),
212214
IRewardsCoordinator(rewardsCoordinator),
213215
IRegistryCoordinator(registryCoordinator),
214-
IStakeRegistry(stakeRegistry)
216+
IStakeRegistry(stakeRegistry),
217+
IAllocationManager(allocationManager)
215218
));
216219
address newRegistryCoordinatorImpl = address(new RegistryCoordinator(
217220
IServiceManager(serviceManager),

src/BLSSignatureChecker.sol

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -193,9 +193,11 @@ contract BLSSignatureChecker is IBLSSignatureChecker {
193193
*/
194194
{
195195
bool _staleStakesForbidden = staleStakesForbidden;
196-
uint256 withdrawalDelayBlocks = _staleStakesForbidden
197-
? delegation.minWithdrawalDelayBlocks()
198-
: 0;
196+
/// TODO: FIX
197+
uint256 withdrawalDelayBlocks = 0;
198+
// uint256 withdrawalDelayBlocks = _staleStakesForbidden
199+
// ? delegation.minWithdrawalDelayBlocks()
200+
// : 0;
199201

200202
for (uint256 i = 0; i < quorumNumbers.length; i++) {
201203
// If we're disallowing stale stake updates, check that each quorum's last update block

src/RegistryCoordinator.sol

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ pragma solidity ^0.8.12;
33

44
import {IPauserRegistry} from "eigenlayer-contracts/src/contracts/interfaces/IPauserRegistry.sol";
55
import {ISignatureUtils} from "eigenlayer-contracts/src/contracts/interfaces/ISignatureUtils.sol";
6-
import {IAVSDirectory} from "eigenlayer-contracts/src/contracts/interfaces/IAVSDirectory.sol";
6+
import {IAVSDirectory, OperatorSet} from "eigenlayer-contracts/src/contracts/interfaces/IAVSDirectory.sol";
77
import {ISocketUpdater} from "./interfaces/ISocketUpdater.sol";
88
import {IBLSApkRegistry} from "./interfaces/IBLSApkRegistry.sol";
99
import {IStakeRegistry} from "./interfaces/IStakeRegistry.sol";
@@ -676,7 +676,7 @@ contract RegistryCoordinator is
676676
for (uint256 i = 0; i < quorumBytes.length; i++) {
677677
/// We need to track forceDeregistrations so we don't pass an id that was already deregistered on the AVSDirectory
678678
/// but hasnt yet been recorded in the middleware contracts
679-
if (!avsDirectory.isMember(operator, IAVSDirectory.OperatorSet(address(serviceManager), uint8(quorumBytes[i])))){
679+
if (!avsDirectory.isMember(operator, OperatorSet(address(serviceManager), uint8(quorumBytes[i])))){
680680
forceDeregistrationCount++;
681681
}
682682
operatorSetIds[i] = uint8(quorumBytes[i]);
@@ -687,7 +687,7 @@ contract RegistryCoordinator is
687687
uint32[] memory filteredOperatorSetIds = new uint32[](operatorSetIds.length - forceDeregistrationCount);
688688
uint256 offset;
689689
for (uint256 i; i < operatorSetIds.length; i++){
690-
if (avsDirectory.isMember(operator, IAVSDirectory.OperatorSet(address(serviceManager), operatorSetIds[i]))){
690+
if (avsDirectory.isMember(operator, OperatorSet(address(serviceManager), operatorSetIds[i]))){
691691
filteredOperatorSetIds[i] = operatorSetIds[i+offset];
692692
} else {
693693
offset++;

src/ServiceManagerBase.sol

Lines changed: 45 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import {ISignatureUtils} from "eigenlayer-contracts/src/contracts/interfaces/ISi
66
import {IAVSDirectory} from "eigenlayer-contracts/src/contracts/interfaces/IAVSDirectory.sol";
77
import {IRewardsCoordinator} from
88
"eigenlayer-contracts/src/contracts/interfaces/IRewardsCoordinator.sol";
9+
import {IAllocationManager} from "eigenlayer-contracts/src/contracts/interfaces/IAllocationManager.sol";
910

1011
import {ServiceManagerBaseStorage} from "./ServiceManagerBaseStorage.sol";
1112
import {IServiceManager} from "./interfaces/IServiceManager.sol";
@@ -38,36 +39,39 @@ abstract contract ServiceManagerBase is ServiceManagerBaseStorage {
3839
_;
3940
}
4041

41-
function _checkRewardsInitiator() internal view {
42-
require(
43-
msg.sender == rewardsInitiator,
44-
"ServiceManagerBase.onlyRewardsInitiator: caller is not the rewards initiator"
45-
);
42+
/// @notice only slasher can call functions with this modifier
43+
modifier onlySlasher() {
44+
_checkSlasher();
45+
_;
4646
}
4747

4848
/// @notice Sets the (immutable) `_registryCoordinator` address
4949
constructor(
5050
IAVSDirectory __avsDirectory,
5151
IRewardsCoordinator __rewardsCoordinator,
5252
IRegistryCoordinator __registryCoordinator,
53-
IStakeRegistry __stakeRegistry
53+
IStakeRegistry __stakeRegistry,
54+
IAllocationManager __allocationManager
5455
)
5556
ServiceManagerBaseStorage(
5657
__avsDirectory,
5758
__rewardsCoordinator,
5859
__registryCoordinator,
59-
__stakeRegistry
60+
__stakeRegistry,
61+
__allocationManager
6062
)
6163
{
6264
_disableInitializers();
6365
}
6466

6567
function __ServiceManagerBase_init(
6668
address initialOwner,
67-
address _rewardsInitiator
69+
address _rewardsInitiator,
70+
address _slasher
6871
) internal virtual onlyInitializing {
6972
_transferOwnership(initialOwner);
7073
_setRewardsInitiator(_rewardsInitiator);
74+
_setSlasher(_slasher);
7175
}
7276

7377
/**
@@ -79,6 +83,10 @@ abstract contract ServiceManagerBase is ServiceManagerBaseStorage {
7983
_avsDirectory.updateAVSMetadataURI(_metadataURI);
8084
}
8185

86+
function slashOperator(IAllocationManager.SlashingParams memory params) external onlySlasher {
87+
_allocationManager.slashOperator(params);
88+
}
89+
8290
/**
8391
* @notice Creates a new rewards submission to the EigenLayer RewardsCoordinator contract, to be split amongst the
8492
* set of stakers delegated to operators who are registered to this `avs`
@@ -168,6 +176,15 @@ abstract contract ServiceManagerBase is ServiceManagerBaseStorage {
168176
_setRewardsInitiator(newRewardsInitiator);
169177
}
170178

179+
/**
180+
* @notice Sets the slasher address
181+
* @param newSlasher The new slasher address
182+
* @dev only callable by the owner
183+
*/
184+
function setSlasher(address newSlasher) external onlyOwner {
185+
_setSlasher(newSlasher);
186+
}
187+
171188
/**
172189
* @notice Migrates the AVS to use operator sets and creates new operator set IDs.
173190
* @param operatorSetsToCreate An array of operator set IDs to create.
@@ -325,6 +342,11 @@ abstract contract ServiceManagerBase is ServiceManagerBaseStorage {
325342
rewardsInitiator = newRewardsInitiator;
326343
}
327344

345+
function _setSlasher(address newSlasher) internal {
346+
emit SlasherUpdated(slasher, newSlasher);
347+
slasher = newSlasher;
348+
}
349+
328350
/**
329351
* @notice Returns the list of strategies that the AVS supports for restaking
330352
* @dev This function is intended to be called off-chain
@@ -402,4 +424,19 @@ abstract contract ServiceManagerBase is ServiceManagerBaseStorage {
402424
function avsDirectory() external view override returns (address) {
403425
return address(_avsDirectory);
404426
}
427+
428+
function _checkRewardsInitiator() internal view {
429+
require(
430+
msg.sender == rewardsInitiator,
431+
"ServiceManagerBase.onlyRewardsInitiator: caller is not the rewards initiator"
432+
);
433+
}
434+
435+
436+
function _checkSlasher() internal view {
437+
require(
438+
msg.sender == slasher,
439+
"ServiceManagerBase.onlySlasher: caller is not the slasher"
440+
);
441+
}
405442
}

src/ServiceManagerBaseStorage.sol

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import {IStakeRegistry} from "./interfaces/IStakeRegistry.sol";
99

1010
import {IAVSDirectory} from "eigenlayer-contracts/src/contracts/interfaces/IAVSDirectory.sol";
1111
import {IRewardsCoordinator} from "eigenlayer-contracts/src/contracts/interfaces/IRewardsCoordinator.sol";
12+
import {IAllocationManager} from "eigenlayer-contracts/src/contracts/interfaces/IAllocationManager.sol";
1213

1314
/**
1415
* @title Storage variables for the `ServiceManagerBase` contract.
@@ -25,6 +26,7 @@ abstract contract ServiceManagerBaseStorage is IServiceManager, OwnableUpgradeab
2526
IRewardsCoordinator internal immutable _rewardsCoordinator;
2627
IRegistryCoordinator internal immutable _registryCoordinator;
2728
IStakeRegistry internal immutable _stakeRegistry;
29+
IAllocationManager internal immutable _allocationManager;
2830

2931
/**
3032
*
@@ -35,21 +37,26 @@ abstract contract ServiceManagerBaseStorage is IServiceManager, OwnableUpgradeab
3537
/// @notice The address of the entity that can initiate rewards
3638
address public rewardsInitiator;
3739

40+
/// @notice The address of the slasher account
41+
address public slasher;
42+
3843
bool public migrationFinalized;
3944

40-
/// @notice Sets the (immutable) `_avsDirectory`, `_rewardsCoordinator`, `_registryCoordinator`, and `_stakeRegistry` addresses
45+
/// @notice Sets the (immutable) `_avsDirectory`, `_rewardsCoordinator`, `_registryCoordinator`, `_stakeRegistry`, and `_allocationManager` addresses
4146
constructor(
4247
IAVSDirectory __avsDirectory,
4348
IRewardsCoordinator __rewardsCoordinator,
4449
IRegistryCoordinator __registryCoordinator,
45-
IStakeRegistry __stakeRegistry
50+
IStakeRegistry __stakeRegistry,
51+
IAllocationManager __allocationManager
4652
) {
4753
_avsDirectory = __avsDirectory;
4854
_rewardsCoordinator = __rewardsCoordinator;
4955
_registryCoordinator = __registryCoordinator;
5056
_stakeRegistry = __stakeRegistry;
57+
_allocationManager = __allocationManager;
5158
}
5259

5360
// storage gap for upgradeability
54-
uint256[49] private __GAP;
61+
uint256[48] private __GAP;
5562
}

src/StakeRegistry.sol

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
pragma solidity ^0.8.12;
33

44
import {IDelegationManager} from "eigenlayer-contracts/src/contracts/interfaces/IDelegationManager.sol";
5-
import {IAVSDirectory} from "eigenlayer-contracts/src/contracts/interfaces/IAVSDirectory.sol";
5+
import {IAVSDirectory, OperatorSet} from "eigenlayer-contracts/src/contracts/interfaces/IAVSDirectory.sol";
66
import {IServiceManager} from "./interfaces/IServiceManager.sol";
77

88
import {StakeRegistryStorage, IStrategy} from "./StakeRegistryStorage.sol";
@@ -182,7 +182,7 @@ contract StakeRegistry is StakeRegistryStorage {
182182
// Query the AVSDirectory to check if the operator is directly unregistered
183183
operatorRegistered = avsDirectory.isMember(
184184
operator,
185-
IAVSDirectory.OperatorSet(address(serviceManager), operatorSetId)
185+
OperatorSet(address(serviceManager), operatorSetId)
186186
);
187187

188188
if (!hasMinimumStake || (isOperatorSetAVS && !operatorRegistered)) {
@@ -491,7 +491,8 @@ contract StakeRegistry is StakeRegistryStorage {
491491
uint256 stratsLength = strategyParamsLength(quorumNumber);
492492
StrategyParams memory strategyAndMultiplier;
493493

494-
uint256[] memory strategyShares = delegation.getOperatorShares(operator, strategiesPerQuorum[quorumNumber]);
494+
uint256[] memory strategyShares;
495+
// = delegation.getDelegatableShares(operator, strategiesPerQuorum[quorumNumber]);
495496
for (uint256 i = 0; i < stratsLength; i++) {
496497
// accessing i^th StrategyParams struct for the quorumNumber
497498
strategyAndMultiplier = strategyParams[quorumNumber][i];

src/interfaces/IServiceManager.sol

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ pragma solidity >=0.5.0;
44
import {IRewardsCoordinator} from "eigenlayer-contracts/src/contracts/interfaces/IRewardsCoordinator.sol";
55
import {IServiceManagerUI} from "./IServiceManagerUI.sol";
66
import {ISignatureUtils} from "eigenlayer-contracts/src/contracts/interfaces/ISignatureUtils.sol";
7+
import {IAllocationManagerTypes} from "eigenlayer-contracts/src/contracts/interfaces/IAllocationManager.sol";
78

89
/**
910
* @title Minimal interface for a ServiceManager-type contract that forms the single point for an AVS to push updates to EigenLayer
@@ -23,7 +24,7 @@ interface IServiceManager is IServiceManagerUI {
2324
*/
2425
function createAVSRewardsSubmission(IRewardsCoordinator.RewardsSubmission[] calldata rewardsSubmissions) external;
2526

26-
function createOperatorSets(uint32[] memory operatorSetIds) external ;
27+
function createOperatorSets(uint32[] memory operatorSetIds) external;
2728

2829
/**
2930
* @notice Forwards a call to EigenLayer's AVSDirectory contract to register an operator to operator sets
@@ -44,6 +45,9 @@ interface IServiceManager is IServiceManagerUI {
4445
*/
4546
function deregisterOperatorFromOperatorSets(address operator, uint32[] calldata operatorSetIds) external;
4647

48+
function slashOperator(IAllocationManagerTypes.SlashingParams memory params) external;
49+
4750
// EVENTS
4851
event RewardsInitiatorUpdated(address prevRewardsInitiator, address newRewardsInitiator);
52+
event SlasherUpdated(address prevSlasher, address newSlasher);
4953
}

src/libraries/SignatureCheckerLib.sol

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
// SPDX-License-Identifier: BUSL-1.1
22
pragma solidity ^0.8.12;
33

4-
import {EIP1271SignatureUtils} from
5-
"eigenlayer-contracts/src/contracts/libraries/EIP1271SignatureUtils.sol";
4+
import "@openzeppelin-upgrades/contracts/utils/cryptography/SignatureCheckerUpgradeable.sol";
65

76
/**
87
* @title SignatureCheckerLib
@@ -11,6 +10,8 @@ import {EIP1271SignatureUtils} from
1110
* validation logic to this external library.
1211
*/
1312
library SignatureCheckerLib {
13+
error InvalidSignature();
14+
1415
/**
1516
* @notice Validates a signature using EIP-1271 standard.
1617
* @param signer The address of the signer.
@@ -22,6 +23,8 @@ library SignatureCheckerLib {
2223
bytes32 digestHash,
2324
bytes memory signature
2425
) external view {
25-
EIP1271SignatureUtils.checkSignature_EIP1271(signer, digestHash, signature);
26+
if (!SignatureCheckerUpgradeable.isValidSignatureNow(signer, digestHash, signature)) {
27+
revert InvalidSignature();
28+
}
2629
}
2730
}

0 commit comments

Comments
 (0)