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

feat: require avs register metadata in allocation manager #1025

Open
wants to merge 7 commits into
base: slashing-magnitudes-fixes
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
7 changes: 7 additions & 0 deletions src/contracts/core/AllocationManager.sol
Original file line number Diff line number Diff line change
Expand Up @@ -324,11 +324,18 @@ contract AllocationManager is

/// @inheritdoc IAllocationManager
function updateAVSMetadataURI(address avs, string calldata metadataURI) external checkCanCall(avs) {
if (!_avsRegisteredMetadata[avs]) {
bowenli86 marked this conversation as resolved.
Show resolved Hide resolved
_avsRegisteredMetadata[avs] = true;
}

emit AVSMetadataURIUpdated(avs, metadataURI);
}

/// @inheritdoc IAllocationManager
function createOperatorSets(address avs, CreateSetParams[] calldata params) external checkCanCall(avs) {
// Check that the AVS exists and has registered metadata
require(_avsRegisteredMetadata[avs], InvalidAVSWithNoMetadataRegistered());

for (uint256 i = 0; i < params.length; i++) {
OperatorSet memory operatorSet = OperatorSet(avs, params[i].operatorSetId);

Expand Down
6 changes: 5 additions & 1 deletion src/contracts/core/AllocationManagerStorage.sol
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,10 @@ abstract contract AllocationManagerStorage is IAllocationManager {
/// These must be completed in order to free up magnitude for future allocation
mapping(address operator => mapping(IStrategy strategy => DoubleEndedQueue.Bytes32Deque)) internal deallocationQueue;

/// @dev Lists the AVSs who has registered metadata and claimed itself as an AVS
/// @notice bool is not used and is always true if the avs has registered metadata
mapping(address avs => bool) internal _avsRegisteredMetadata;

// Construction

constructor(IDelegationManager _delegation, uint32 _DEALLOCATION_DELAY, uint32 _ALLOCATION_CONFIGURATION_DELAY) {
Expand All @@ -102,5 +106,5 @@ abstract contract AllocationManagerStorage is IAllocationManager {
* variables without shifting down storage in the inheritance chain.
* See https://docs.openzeppelin.com/contracts/4.x/upgradeable#storage_gaps
*/
uint256[37] private __gap;
uint256[36] private __gap;
}
2 changes: 2 additions & 0 deletions src/contracts/interfaces/IAllocationManager.sol
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ interface IAllocationManagerErrors {

/// @dev Thrown when an invalid operator is provided.
error InvalidOperator();
/// @dev Thrown when an invalid avs whose metadata is not registered is provided.
error InvalidAVSWithNoMetadataRegistered();
/// @dev Thrown when an operator's allocation delay has yet to be set.
error UninitializedAllocationDelay();
/// @dev Thrown when attempting to slash an operator when they are not slashable.
Expand Down
1 change: 1 addition & 0 deletions src/test/integration/IntegrationBase.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@ abstract contract IntegrationBase is IntegrationDeployer, TypeImporter {
function _newRandomAVS() internal returns (AVS avs, OperatorSet[] memory operatorSets) {
string memory avsName = string.concat("avs", numAVSs.toString());
avs = _genRandAVS(avsName);
avs.updateAVSMetadataURI("https://example.com");
operatorSets = avs.createOperatorSets(_randomStrategies());
++numAVSs;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,9 @@ contract Integration_Deposit_Delegate_Allocate_Slash_Queue_Redeposit is Integrat
staker.delegateTo(operator);
check_Delegation_State(staker, operator, strategies, shares);

// update AVS metadata URI
avs.updateAVSMetadataURI("https://example.com");

// Create operator set and register operator
operatorSet = avs.createOperatorSet(strategies);
operator.registerForOperatorSet(operatorSet);
Expand Down
12 changes: 12 additions & 0 deletions src/test/integration/users/AVS.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,18 @@ contract AVS is Logger, IAllocationManagerTypes, IAVSRegistrar {
/// AllocationManager
/// -----------------------------------------------------------------------

function updateAVSMetadataURI(
string memory uri
) public createSnapshot {
print.method("updateAVSMetadataURI");

console.log("Setting AVS metadata URI to: %s", uri);
_tryPrankAppointee_AllocationManager(IAllocationManager.updateAVSMetadataURI.selector);
allocationManager.updateAVSMetadataURI(address(this), uri);

print.gasUsed();
}

function createOperatorSets(
IStrategy[][] memory strategies
) public createSnapshot returns (OperatorSet[] memory operatorSets) {
Expand Down
14 changes: 14 additions & 0 deletions src/test/unit/AllocationManagerUnit.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,10 @@ contract AllocationManagerUnitTests is EigenLayerUnitTestSetup, IAllocationManag
defaultStrategies = strategyMock.toArray();
defaultOperatorSet = OperatorSet(defaultAVS, 0);

cheats.prank(defaultAVS);
allocationManager.updateAVSMetadataURI(defaultAVS, "https://example.com");


_createOperatorSet(defaultOperatorSet, defaultStrategies);
_registerOperator(defaultOperator);
_setAllocationDelay(defaultOperator, DEFAULT_OPERATOR_ALLOCATION_DELAY);
Expand Down Expand Up @@ -3830,13 +3834,23 @@ contract AllocationManagerUnitTests_createOperatorSets is AllocationManagerUnitT
allocationManager.createOperatorSets(defaultAVS, CreateSetParams(defaultOperatorSet.id, defaultStrategies).toArray());
}

function testRevert_createOperatorSets_InvalidAVSWithNoMetadataRegistered(Randomness r) public rand(r) {
address avs = r.Address();
cheats.expectRevert(InvalidAVSWithNoMetadataRegistered.selector);
cheats.prank(avs);
allocationManager.createOperatorSets(avs, CreateSetParams(defaultOperatorSet.id, defaultStrategies).toArray());
}

function testFuzz_createOperatorSets_Correctness(
Randomness r
) public rand(r) {
address avs = r.Address();
uint256 numOpSets = r.Uint256(1, FUZZ_MAX_OP_SETS);
uint256 numStrategies = r.Uint256(1, FUZZ_MAX_STRATS);

cheats.prank(avs);
allocationManager.updateAVSMetadataURI(avs, "https://example.com");

CreateSetParams[] memory createSetParams = new CreateSetParams[](numOpSets);

for (uint256 i; i < numOpSets; ++i) {
Expand Down
Loading