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(avs):implement whitelist feature for AVS #262

Open
wants to merge 3 commits into
base: develop
Choose a base branch
from

Conversation

trestinlsd
Copy link
Contributor

@trestinlsd trestinlsd commented Dec 10, 2024

Description


implement whitelist feature for AVS

Summary by CodeRabbit

Release Notes

  • New Features

    • Added support for operator whitelisting in AVS registration and updates.
    • Introduced new events for AVS registration, deregistration, and updates.
    • Implemented a method to check if an operator is whitelisted.
  • Bug Fixes

    • Enhanced error handling for AVS operations with clearer messages.
  • Tests

    • Added tests to verify operator whitelisting functionality and ensure correct AVS registration and deregistration behavior.

Copy link
Contributor

coderabbitai bot commented Dec 10, 2024

Walkthrough

The changes in this pull request primarily involve modifications to the IAVSManager interface and related components to include a new whitelistAddress parameter in the registerAVS and updateAVS functions. Additionally, several new events are added to the abi.json file, and the AVSInfo structure is updated to support whitelisting of operator addresses. Various methods across multiple files have been adjusted to accommodate these changes, enhancing the functionality and validation processes related to AVS management.

Changes

File Change Summary
precompiles/avs/IAVSManager.sol Updated registerAVS and updateAVS function signatures to include whitelistAddress (string[]).
precompiles/avs/abi.json Added new events: AVSDeregistered, AVSRegistered, AVSUpdated, ChallengeInitiated, OperatorJoined, OperatorLeft, PublicKeyRegistered. Updated TaskCreated and TaskSubmittedByOperator events. Modified registerAVS and updateAVS signatures to include whitelistAddress (string[]).
precompiles/avs/types.go Updated GetAVSParamsFromInputs and GetAVSParamsFromUpdateInputs methods to include whitelistAddress []string as the seventh argument.
proto/exocore/avs/v1/tx.proto Added repeated string whitelist_address field to AVSInfo message.
x/avs/keeper/avs.go Added IsWhitelisted method to Keeper struct for checking if an operator is whitelisted. Enhanced error handling in existing methods.
x/avs/keeper/avs_test.go Introduced tests for whitelisting functionality, including checks for operator registration and deregistration scenarios.
x/avs/keeper/keeper.go Added WhitelistAddress field to AVSInfo structure. Updated UpdateAVSInfo and SetAVSInfo methods accordingly.
x/avs/types/types.go Added WhitelistAddress []string field to AVSRegisterOrDeregisterParams struct.
x/operator/keeper/opt.go Added a whitelisting check in the OptIn method for operators.
x/operator/types/expected_keepers.go Added IsWhitelisted(ctx sdk.Context, avsAddr, operatorAddr string) (bool, error) method to AVSKeeper interface.

Possibly related PRs

Suggested labels

C:Types

Suggested reviewers

  • cloud8little
  • TimmyExogenous
  • leonz789
  • bwhour
  • MaxMustermann2
  • adu-web3
  • mikebraver

🐰 In the meadow, where the code does flow,
A whitelist blooms, helping contracts grow.
With functions updated, and tests now in place,
The AVS shines bright, a new feature to embrace!
Hops of joy echo, as changes take flight,
For every operator, the future looks bright! 🌟


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR. (Experiment)
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 8

🧹 Outside diff range and nitpick comments (5)
x/avs/keeper/avs_test.go (2)

26-27: Consider using a more descriptive variable name.

The variable name operatorAddress could be more descriptive, such as whitelistedOperatorAddress, to better reflect its purpose in testing the whitelist feature.


43-43: Enhance test coverage for whitelist feature.

Consider adding test cases for:

  1. Multiple whitelisted operators
  2. Empty whitelist
  3. Invalid operator addresses
proto/exocore/avs/v1/tx.proto (1)

57-58: Consider adding field options for better type safety.

Add the cosmos_proto.scalar option to ensure proper type validation for bech32 addresses:

  // whitelist_address are the bech32 addresses ,whitelist address of supported operators
- repeated string whitelist_address = 19;
+ repeated string whitelist_address = 19 [(cosmos_proto.scalar) = "cosmos.AddressString"];
precompiles/avs/IAVSManager.sol (1)

52-52: Enhance the whitelist parameter documentation.

The documentation for whitelistAddress parameter should be more descriptive and include:

  • Purpose of the whitelist
  • Format requirements for addresses
  • Validation rules or constraints
  • Maximum allowed addresses
precompiles/avs/types.go (1)

71-84: Reduce code duplication in whitelist address validation.

The whitelist address validation logic is duplicated between GetAVSParamsFromInputs and GetAVSParamsFromUpdateInputs. Consider extracting this into a helper function.

Example refactor:

func validateWhitelistAddresses(addresses []string, argIndex int) ([]string, error) {
    if addresses == nil {
        return nil, fmt.Errorf(exocmn.ErrContractInputParaOrType, argIndex, "[]string", addresses)
    }
    exoWhiteAddresses := make([]string, len(addresses))
    for i, addr := range addresses {
        accAddr, err := sdk.AccAddressFromBech32(addr)
        if err != nil {
            return nil, fmt.Errorf(exocmn.ErrContractInputParaOrType, argIndex, "[]string", addresses)
        }
        exoWhiteAddresses[i] = accAddr.String()
    }
    return exoWhiteAddresses, nil
}

Also applies to: 187-200

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 27a99e2 and 7e89c4a.

⛔ Files ignored due to path filters (1)
  • x/avs/types/tx.pb.go is excluded by !**/*.pb.go
📒 Files selected for processing (10)
  • precompiles/avs/IAVSManager.sol (4 hunks)
  • precompiles/avs/abi.json (2 hunks)
  • precompiles/avs/types.go (2 hunks)
  • proto/exocore/avs/v1/tx.proto (1 hunks)
  • x/avs/keeper/avs.go (2 hunks)
  • x/avs/keeper/avs_test.go (2 hunks)
  • x/avs/keeper/keeper.go (2 hunks)
  • x/avs/types/types.go (1 hunks)
  • x/operator/keeper/opt.go (1 hunks)
  • x/operator/types/expected_keepers.go (1 hunks)
🧰 Additional context used
📓 Learnings (1)
x/operator/types/expected_keepers.go (2)
Learnt from: MaxMustermann2
PR: ExocoreNetwork/exocore#149
File: x/operator/keeper/slash.go:227-227
Timestamp: 2024-11-12T10:03:15.304Z
Learning: The `GetAVSAddrByChainID` function in `x/operator/keeper/slash.go` does not require error handling since validation is performed prior to its call.
Learnt from: MaxMustermann2
PR: ExocoreNetwork/exocore#220
File: x/avs/types/expected_keepers.go:47-48
Timestamp: 2024-11-12T10:03:10.791Z
Learning: Adding new methods to the `OperatorKeeper` interface in `x/avs/types/expected_keepers.go` is acceptable, even if there are other unmodifiable `OperatorKeeper` interfaces elsewhere, because interfaces can be extended without causing conflicts.
🪛 golangci-lint (1.62.2)
x/avs/keeper/avs.go

4-4: File is not gofumpt-ed

(gofumpt)

🪛 GitHub Check: Run golangci-lint
x/avs/keeper/avs.go

[failure] 4-4:
File is not gofumpt-ed (gofumpt)

🔇 Additional comments (3)
x/operator/types/expected_keepers.go (1)

116-116: LGTM: Interface extension is well-designed

The addition of the IsWhitelisted method to the AVSKeeper interface is clean and follows the existing patterns. The method signature appropriately returns both the whitelist status and potential errors.

x/operator/keeper/opt.go (1)

32-35: LGTM: Validation order is correct

The placement of the whitelist check after the AVS registration check but before the opted-in check is logical and maintains proper validation order.

precompiles/avs/abi.json (1)

649-653: LGTM! ABI changes are consistent and well-structured.

The changes to the ABI:

  1. Correctly add the whitelistAddress parameter to both registerAVS and updateAVS functions
  2. Maintain consistent type definitions
  3. Include proper event definitions for tracking AVS operations

Also applies to: 786-790

x/avs/types/types.go Show resolved Hide resolved
x/operator/keeper/opt.go Outdated Show resolved Hide resolved
x/avs/keeper/avs_test.go Show resolved Hide resolved
x/avs/keeper/avs.go Outdated Show resolved Hide resolved
precompiles/avs/IAVSManager.sol Show resolved Hide resolved
precompiles/avs/types.go Outdated Show resolved Hide resolved
Comment on lines +189 to +191
if params.WhitelistAddress != nil {
avs.WhitelistAddress = params.WhitelistAddress
}
Copy link
Contributor

@coderabbitai coderabbitai bot Dec 10, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Add validation for WhitelistAddress during AVS updates

Similar to the registration flow, the update flow also lacks address validation for WhitelistAddress.

Add validation before updating WhitelistAddress:

 if params.WhitelistAddress != nil {
+    if err := k.validateAddresses(params.WhitelistAddress); err != nil {
+        return err
+    }
     avs.WhitelistAddress = params.WhitelistAddress
 }
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
if params.WhitelistAddress != nil {
avs.WhitelistAddress = params.WhitelistAddress
}
if params.WhitelistAddress != nil {
if err := k.validateAddresses(params.WhitelistAddress); err != nil {
return err
}
avs.WhitelistAddress = params.WhitelistAddress
}

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please consider this comment from the AI.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@MaxMustermann2, here's an example of how you could incorporate address validation for the WhitelistAddress before updating:

// helper function to validate a list of Bech32 addresses
func (k Keeper) validateAddresses(addresses []string) error {
	for _, addr := range addresses {
		if _, err := sdk.AccAddressFromBech32(addr); err != nil {
			return errorsmod.Wrap(types.ErrInvalidAddr, fmt.Sprintf("Invalid whitelist address: %s", addr))
		}
	}
	return nil
}

// snippet inside UpdateAVSInfo
if params.WhitelistAddress != nil {
	if err := k.validateAddresses(params.WhitelistAddress); err != nil {
		return err
	}
	avs.WhitelistAddress = params.WhitelistAddress
}

This ensures each address is checked for validity prior to updating the whitelist.

x/avs/keeper/keeper.go Show resolved Hide resolved
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Outside diff range and nitpick comments (3)
precompiles/avs/avs_test.go (3)

Line range hint 4-6: Consider using constants for magic numbers and improving variable names.

The test setup uses several magic numbers (e.g., uint64(3)) and could benefit from more descriptive variable names. This would make the tests more maintainable and self-documenting.

Consider defining constants and using more descriptive names:

+ const (
+   DefaultUnbondingPeriod = uint64(3)
+   DefaultMinStakeAmount  = uint64(3)
+   DefaultMinSelfDelegation = uint64(3)
+   DefaultMinOperators = uint64(2)
+   DefaultMinTotalStake = uint64(3)
+   DefaultRewardRate = uint64(4)
+   DefaultSlashRate = uint64(4)
+ )

- minStakeAmount, taskAddr := uint64(3), "0x3e..."
- avsUnbondingPeriod, minSelfDelegation := uint64(3), uint64(3)
- params := []uint64{2, 3, 4, 4}
+ minStakeAmount, taskAddr := DefaultMinStakeAmount, "0x3e..."
+ avsUnbondingPeriod, minSelfDelegation := DefaultUnbondingPeriod, DefaultMinSelfDelegation
+ params := []uint64{DefaultMinOperators, DefaultMinTotalStake, DefaultRewardRate, DefaultSlashRate}

Also applies to: 12-24


Line range hint 1-1000: Enhance test coverage with error cases and edge scenarios.

The current test suite primarily focuses on successful scenarios. Consider adding test cases for:

  • Invalid inputs (e.g., empty addresses, zero values)
  • Error conditions (e.g., duplicate registrations, invalid state transitions)
  • Edge cases (e.g., maximum values, boundary conditions)

Example test cases to add:

// Test invalid AVS registration
{
    name: "fail - empty AVS name",
    malleate: func() (common.Address, []byte) {
        input, err := suite.precompile.Pack(
            avs.MethodRegisterAVS,
            suite.Address,
            "", // empty name
            minStakeAmount,
            // ... rest of parameters
        )
        return suite.Address, input
    },
    expPass: false,
    errContains: "empty AVS name",
},
{
    name: "fail - zero stake amount",
    malleate: func() (common.Address, []byte) {
        input, err := suite.precompile.Pack(
            avs.MethodRegisterAVS,
            suite.Address,
            avsName,
            uint64(0), // zero stake
            // ... rest of parameters
        )
        return suite.Address, input
    },
    expPass: false,
    errContains: "invalid stake amount",
}

Line range hint 1-1000: Improve test organization and reduce duplication.

The test methods are quite long and contain duplicated setup code. Consider refactoring to:

  1. Extract common test setup into reusable helper functions
  2. Split large test methods into smaller, focused test cases
  3. Use table-driven tests more consistently

Example refactoring:

// Common setup helper
func (suite *AVSManagerPrecompileSuite) setupTestAVS(name string, stake uint64) *types.AVSInfo {
    slashAddress := "0xDF907c29719154eb9872f021d21CAE6E5025d7aB"
    rewardAddress := "0xDF907c29719154eb9872f021d21CAE6E5025d7aB"
    avsOwnerAddress := []string{
        sdk.AccAddress(suite.Address.Bytes()).String(),
        sdk.AccAddress(utiltx.GenerateAddress().Bytes()).String(),
        sdk.AccAddress(utiltx.GenerateAddress().Bytes()).String(),
    }
    // ... rest of setup
    return avs
}

// Smaller, focused test method
func (suite *AVSManagerPrecompileSuite) TestRegisterAVS_Validation() {
    testCases := []struct {
        name string
        avs  *types.AVSInfo
        err  string
    }{
        {
            name: "valid AVS",
            avs:  suite.setupTestAVS("test", 100),
            err:  "",
        },
        // ... more test cases
    }
    // ... test execution
}
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 7e89c4a and 00eeed8.

📒 Files selected for processing (2)
  • precompiles/avs/avs_test.go (2 hunks)
  • x/avs/keeper/avs.go (2 hunks)
🔇 Additional comments (2)
x/avs/keeper/avs.go (2)

6-6: LGTM!

The addition of the slices package is appropriate for the new whitelist functionality.


229-247: ⚠️ Potential issue

Fix error handling and improve validation.

Several critical issues still need to be addressed:

  1. Missing validation for avsAddr format using common.IsHexAddress
  2. Line 244 incorrectly uses a nil err in error wrapping
  3. Missing function documentation
  4. The empty whitelist behavior should be documented

Please refer to the previous review comment for the detailed fix.

precompiles/avs/avs_test.go Outdated Show resolved Hide resolved
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 00eeed8 and 93c545a.

📒 Files selected for processing (4)
  • precompiles/avs/avs_test.go (4 hunks)
  • precompiles/avs/types.go (2 hunks)
  • x/avs/keeper/avs.go (2 hunks)
  • x/operator/keeper/opt.go (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • x/operator/keeper/opt.go
🔇 Additional comments (2)
x/avs/keeper/avs.go (1)

229-251: ⚠️ Potential issue

Fix error handling and improve validation.

Several issues need to be addressed:

  1. Line 248 incorrectly uses a nil err in error wrapping
  2. Missing validation for avsAddr format using common.IsHexAddress
  3. The empty whitelist behavior should be documented

Apply this diff to fix the issues:

// IsWhitelisted checks if an operator is in the AVS whitelist.
// If the whitelist is empty, any operator is considered whitelisted.
// Returns true if the operator is whitelisted, false otherwise.
// Returns an error if the AVS address is invalid, the operator address is invalid,
// or if the operator is not in the whitelist.
func (k *Keeper) IsWhitelisted(ctx sdk.Context, avsAddr, operatorAddr string) (bool, error) {
+   if !common.IsHexAddress(avsAddr) {
+       return false, errorsmod.Wrap(types.ErrInvalidAddr, fmt.Sprintf("IsWhitelisted: invalid AVS address %s", avsAddr))
+   }
    avsInfo, err := k.GetAVSInfo(ctx, avsAddr)
    if err != nil {
        return false, errorsmod.Wrap(err, fmt.Sprintf("IsWhitelisted: key is %s", avsAddr))
    }
    _, err = sdk.AccAddressFromBech32(operatorAddr)
    if err != nil {
        return false, errorsmod.Wrap(err, "IsWhitelisted: error occurred when parse acc address from Bech32")
    }
    // Currently avs has no whitelist set and any operator can optin
    if len(avsInfo.Info.WhitelistAddress) == 0 {
        return true, nil
    }
    if !slices.Contains(avsInfo.Info.WhitelistAddress, operatorAddr) {
-       return false, errorsmod.Wrap(err, fmt.Sprintf("operator %s not in whitelist", operatorAddr))
+       return false, errorsmod.Wrap(types.ErrNotWhitelisted, fmt.Sprintf("operator %s not in whitelist", operatorAddr))
    }
    return true, nil
}

Likely invalid or redundant comment.

precompiles/avs/types.go (1)

198-198: ⚠️ Potential issue

Fix critical bug: Using wrong slice variable for whitelist addresses.

The code is using exoAddresses instead of exoWhiteAddresses when storing validated whitelist addresses. This bug will cause the whitelist to be corrupted with owner addresses.

Apply this fix:

-       exoAddresses[i] = accAddr.String()
+       exoWhiteAddresses[i] = accAddr.String()

Likely invalid or redundant comment.

precompiles/avs/avs_test.go Show resolved Hide resolved
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Outside diff range and nitpick comments (1)
precompiles/avs/avs_test.go (1)

Line range hint 1-1000: Add test cases for concurrent whitelist operations.

The test suite should include scenarios testing concurrent operations with the whitelist:

  1. Multiple operators attempting to register simultaneously
  2. Whitelist updates while operator registration is in progress
  3. Race conditions during whitelist modifications
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 93c545a and 70cd42e.

📒 Files selected for processing (4)
  • precompiles/avs/avs_test.go (4 hunks)
  • precompiles/avs/types.go (2 hunks)
  • x/avs/keeper/avs.go (2 hunks)
  • x/operator/keeper/opt.go (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (2)
  • x/operator/keeper/opt.go
  • precompiles/avs/types.go
🔇 Additional comments (4)
x/avs/keeper/avs.go (2)

6-6: LGTM!

The addition of the slices package is appropriate for the new whitelist functionality.


229-251: ⚠️ Potential issue

Fix error handling and enhance validation

In addition to the previously identified issues, consider:

  1. Adding example usage in the documentation
  2. Enhancing empty whitelist validation with size limits

Apply this diff to fix the issues:

// IsWhitelisted checks if an operator is in the AVS whitelist.
// If the whitelist is empty, any operator is considered whitelisted.
// Returns true if the operator is whitelisted, false otherwise.
// Returns an error if the AVS address is invalid, the operator address is invalid,
// or if the operator is not in the whitelist.
//
// Example:
//
//	isWhitelisted, err := k.IsWhitelisted(ctx, "0x123...", "exo1...")
//	if err != nil {
//	    return err
//	}
func (k *Keeper) IsWhitelisted(ctx sdk.Context, avsAddr, operatorAddr string) (bool, error) {
+   if !common.IsHexAddress(avsAddr) {
+       return false, errorsmod.Wrap(types.ErrInvalidAddr, fmt.Sprintf("invalid AVS address format: %s", avsAddr))
+   }
    avsInfo, err := k.GetAVSInfo(ctx, avsAddr)
    if err != nil {
        return false, errorsmod.Wrap(err, fmt.Sprintf("failed to get AVS info for address: %s", avsAddr))
    }
    _, err = sdk.AccAddressFromBech32(operatorAddr)
    if err != nil {
        return false, errorsmod.Wrap(err, fmt.Sprintf("invalid operator address format: %s", operatorAddr))
    }
    // Currently avs has no whitelist set and any operator can optin
+   // Ensure whitelist size doesn't exceed maximum allowed size
+   if len(avsInfo.Info.WhitelistAddress) > types.MaxWhitelistSize {
+       return false, errorsmod.Wrap(types.ErrInvalidWhitelist, "whitelist exceeds maximum size")
+   }
    if len(avsInfo.Info.WhitelistAddress) == 0 {
        return true, nil
    }
    if !slices.Contains(avsInfo.Info.WhitelistAddress, operatorAddr) {
-       return false, errorsmod.Wrap(err, fmt.Sprintf("operator %s not in whitelist", operatorAddr))
+       return false, errorsmod.Wrap(types.ErrNotWhitelisted, fmt.Sprintf("operator %s not in whitelist", operatorAddr))
    }
    return true, nil
}

Additionally, ensure these error types are defined in x/avs/types/errors.go:

// Error codes for AVS module
const (
    ErrNotWhitelisted    = "not_whitelisted"
    ErrInvalidWhitelist  = "invalid_whitelist"
    MaxWhitelistSize     = 1000 // Adjust this value based on your requirements
)
precompiles/avs/avs_test.go (2)

96-99: Add comprehensive test cases for whitelist functionality.

The test suite needs additional test cases to verify the whitelist feature thoroughly:

  1. Empty whitelist behavior
  2. Invalid whitelist addresses
  3. Non-whitelisted operator registration attempts
  4. Whitelist updates during AVS updates

Also applies to: 357-360


115-115: Verify whitelist parameter consistency across test cases.

The whitelist parameter has been added to both register and update AVS methods, but the test cases don't verify:

  1. Whitelist validation during registration
  2. Whitelist modifications during updates
  3. Error cases for invalid whitelist entries

Also applies to: 376-376

✅ Verification successful

Whitelist parameter validation is properly implemented and tested

Based on the code analysis:

  1. The whitelist parameter is properly validated in both registration and update methods:

    • In types.go, both GetAVSParamsFromInputs and GetAVSParamsFromUpdateInputs validate the whitelist addresses by:
      • Checking for nil/empty arrays
      • Converting and validating each address using sdk.AccAddressFromBech32
      • Returning appropriate error messages for invalid inputs
  2. Test cases in avs_test.go verify whitelist functionality:

    • Tests include valid whitelist addresses using exoWhiteAddresses
    • Addresses are properly generated and formatted using sdk.AccAddress
    • Whitelist parameter is consistently used in both registration and update test cases

The implementation shows proper validation and consistent usage across the codebase, with no issues found.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify whitelist parameter usage consistency

# Check for whitelist parameter validation
rg -A 5 "whitelist.*validation|validate.*whitelist" precompiles/

# Check for whitelist-related error handling
rg "whitelist.*error|error.*whitelist" precompiles/

# Check for whitelist update handling
ast-grep --pattern 'func $_(_, _) {
  $$$
  whitelist$_
  $$$
}'

Length of output: 187


Script:

#!/bin/bash
# Let's check for whitelist-related test cases and implementation

# Search for whitelist-related test cases
rg -B 2 -A 2 "whitelist" precompiles/avs/avs_test.go

# Check the AVS contract implementation for whitelist handling
rg -B 2 -A 2 "whitelist" precompiles/avs/avs.go

# Look for any whitelist-related structs or types
ast-grep --pattern 'type $_ struct {
  $$$
  whitelist$_
  $$$
}'

Length of output: 168


Script:

#!/bin/bash
# Let's try a different approach to find whitelist-related code

# Search for any files containing 'whitelist' in the precompiles directory
fd . precompiles -t f -x grep -l "whitelist" {} \;

# Look for test functions that might be testing whitelist functionality
ast-grep --pattern 'func Test$_(t *testing.T) {
  $$$
}'  precompiles/avs/avs_test.go

# Check for any registration or update method implementations
ast-grep --pattern 'func (c *Contract) Register($$$) error {
  $$$
}'

ast-grep --pattern 'func (c *Contract) Update($$$) error {
  $$$
}'

Length of output: 364


Script:

#!/bin/bash
# Let's examine the content of the identified files

# Check the interface definition
cat precompiles/avs/IAVSManager.sol

# Check the types definition
cat precompiles/avs/types.go

# Look for whitelist-related test cases with more context
rg -B 5 -A 5 "exoWhiteAddresses" precompiles/avs/avs_test.go

Length of output: 23316

precompiles/avs/avs_test.go Show resolved Hide resolved
x/operator/keeper/opt.go Show resolved Hide resolved
Comment on lines +189 to +191
if params.WhitelistAddress != nil {
avs.WhitelistAddress = params.WhitelistAddress
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please consider this comment from the AI.

@@ -96,6 +99,7 @@ interface IAVSManager {
address slashAddr,
address rewardAddr,
string[] memory avsOwnerAddress,
string[] memory whitelistAddress,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why choose string type for these addresses and not address which is Solidity native and has great support? Each exo1... bech32-encoded address can be represented as a hex address and vice-versa.

@@ -49,6 +49,7 @@ interface IAVSManager {
/// @param slashAddr The slash address of AVS.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Have you verified that this file compiles? Too many local variables (within a function) can cause Solidity to complain "stack too deep"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants