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

fix:add missing fields #64

Merged
merged 4 commits into from
May 30, 2024
Merged

Conversation

trestinlsd
Copy link
Contributor

@trestinlsd trestinlsd commented May 22, 2024

Description


avs module add missing fields

Fix vulnerability GO-2024-2694 in github.com/cosmos/ibc-go/v7

  • Upgraded github.com/cosmos/ibc-go/v7 to version v7.4.0 to address GO-2024-2694 vulnerability.
  • Fixed potential reentrancy issue in ibc-hooks.
  • Updated dependencies to ensure code integrity and security.

@cloud8little
Copy link
Contributor

Test passed with 745b278
avs owner address is added.

exocored q avs AVSInfo exo1l7m80efn6lfkdcng47rwy2rma6xsqywu6cwe2v --home ~/.tmp-exocored
info:
  asset_id:
  - "123"
  avs_address: exo1l7m80efn6lfkdcng47rwy2rma6xsqywu6cwe2v
  avs_owner_address: exo1nkh04qzxed98megzz53xx9a4uju599zg3rw0mj
  name: avs01
  operator_address:
  - exo18cggcpvwspnd5c6ny8wrqxpffj5zmhklprtnph

@cloud8little cloud8little added this to the Testnet V3 milestone May 24, 2024
Copy link
Contributor

@TimmyExogenous TimmyExogenous left a comment

Choose a reason for hiding this comment

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

It seems that the register and deregister functions of the AVS can still be called by any address, right?
If the owner address of the AVS is a parameter passed in during registration, then deregistration or updates would require signature verification of the owner address. Implementing such permission verification is relatively complex. Moreover, this PR only adds an owner address parameter initialization and does not address the permission control issues related to AVS operations. The key should be to use the "from" address in the msg call as the owner address. You can refer to the implementation of other similar functionalities for details.

@cloud8little
Copy link
Contributor

Move to further milestone as the owner address needs to be well-designed.

@cloud8little cloud8little removed this from the Testnet V3 milestone May 27, 2024
bz, err = p.AVSInfoRegisterOrDeregister(ctx, evm.Origin, contract, stateDB, method, args)
case MethodRegisterOperatorToAVS:
Copy link
Contributor

Choose a reason for hiding this comment

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

So won't you support operator deregister from AVS?

Copy link
Contributor Author

@trestinlsd trestinlsd May 29, 2024

Choose a reason for hiding this comment

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

Supported

)

const (
// AVSRegister defines the ABI method name for the avs
// related transaction.
MethodAVSAction = "AVSAction"
MethodAVSAction = "AVSAction"
MethodRegisterOperatorToAVS = "registerOperatorToAVS"
Copy link
Contributor

Choose a reason for hiding this comment

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

Same here

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fixed

@@ -33,3 +45,35 @@ func (p Precompile) AVSInfoRegisterOrDeregister(
}
return method.Outputs.Pack(true)
}

func (p Precompile) OperatorInfoRegister(
Copy link
Contributor

Choose a reason for hiding this comment

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

The name of this function is confused, the operator is registered via the operator module, what you'd do is to register operator to avs, shouldn't this added in operator module?

Copy link
Contributor

Choose a reason for hiding this comment

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

Also need to support operator deregister from avs

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fixed

return nil
}

func (k *Keeper) GetOperator(ctx sdk.Context, addr string) (operator types.OperatorInfo, err error) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Why not get operator in operator module?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fixed

Copy link
Contributor

@mikebraver mikebraver left a comment

Choose a reason for hiding this comment

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

Many places need to be updated!

// registered operator of avs
repeated string operator_address = 3;
// slash address of avs
string slash_addr = 3;
// the owner who has permission for avs
string avs_owner_address = 4;
Copy link
Contributor

Choose a reason for hiding this comment

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

Won't there's any case that avs has multiple owners or operators?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

supported

}
avsParams.AssetID = assetID
avsParams.UnbondingEpochs = unbondingEpochs
Copy link
Contributor

Choose a reason for hiding this comment

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

You defined both unbondingEpochs and Epochs in protobuf struct, why there's only unbondingEpochs set here?

EpochInfo avs_epoch = 8;
}
// The information of OperatorInfo in opt-in avs
message OperatorInfo {
Copy link
Contributor

Choose a reason for hiding this comment

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

Shouldn't it store the avs meta info within this struct?

sdk "github.com/cosmos/cosmos-sdk/types"
)

func (k *Keeper) GetAVSSupportedAssets(ctx sdk.Context, avsAddr string) ([]string, error) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Please reuse the function GetAVSInfo to get avs info, and return res.AssetId then

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fixed


return ret.AssetId, nil
}
func (k *Keeper) GetAVSSlashContract(ctx sdk.Context, avsAddr string) (string, error) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Same here

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fixed

@mikebraver
Copy link
Contributor

Please also fix all action errors

@github-actions github-actions bot added the C:CLI label May 28, 2024
precompiles/avs/tx.go Fixed Show fixed Hide fixed
@@ -1 +1,19 @@
package types

func ContainsString(slice []string, target string) bool {
Copy link
Contributor

Choose a reason for hiding this comment

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

No need to re-implement it, just use import slices and slices.Contains()

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fixed

precompiles/avs/tx.go Fixed Show fixed Hide fixed
Copy link
Contributor

@mikebraver mikebraver left a comment

Choose a reason for hiding this comment

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

Can merge it after all comments and action error are resolved

"name": "assetID",
"type": "string"
"internalType": "uint64",
"name": "unbondingEpochs",
Copy link
Contributor

Choose a reason for hiding this comment

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

unbondingEpoch: it's better named it unbondingTime or unbondingPeriod

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fixed

uint64 action,
string memory avsOwnerAddress,
string memory assetID
uint64 minimumDelegation,
Copy link
Contributor

Choose a reason for hiding this comment

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

is this minimumSelfDelegation ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Minimum stake quantity for Operator

string memory avsOwnerAddress,
string memory assetID
uint64 minimumDelegation,
uint64 unbondingEpochs
Copy link
Contributor

Choose a reason for hiding this comment

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

unbondingTime/unbondingPeriod would be better.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fixed


exocmn "github.com/ExocoreNetwork/exocore/precompiles/common"
util "github.com/ExocoreNetwork/exocore/utils"
avstypes "github.com/ExocoreNetwork/exocore/x/avs/keeper"
Copy link
Contributor

Choose a reason for hiding this comment

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

this should be avskeeper not avstypes. please change the related places.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fixed

if err != nil {
return nil, errorsmod.Wrap(err, "parse args error")
}
avsAddress, err := util.ProcessAvsAddress(contract.Address().String())
Copy link
Contributor

Choose a reason for hiding this comment

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

ProcessAVSAddress

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fixed

// related transaction.
MethodAVSAction = "AVSAction"
MethodAVSAction = "AVSAction"
MethodOperatorAction = "OperatorOptAction"
)

// AVSInfoRegister register the avs related information and change the state in avs keeper module.
func (p Precompile) AVSInfoRegisterOrDeregister(
Copy link
Contributor

Choose a reason for hiding this comment

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

AVSInfoRegisterOrDeregister:
Although this function name describes its functionality, it is a bit long and not specific enough. Consider using a more concise and clear name.It is recommended to change it to RegisterOrDeregisterAVSInfo, which better follows the action + object naming convention for functions.

OperatorBindingAvs:
This function name can also be more specific, clearly indicating that it binds an operator to AVS.
It is recommended to change it to BindOperatorToAVS, which more clearly expresses the function's purpose.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fixed

func (k *Keeper) GetAVSSlashContract(ctx sdk.Context, avsAddr string) (string, error) {
avsInfo, err := k.GetAVSInfo(ctx, avsAddr)
if err != nil {
return "", errorsmod.Wrap(err, fmt.Sprintf("GetAVSSupportedAssets: key is %s", avsAddr))
Copy link
Contributor

Choose a reason for hiding this comment

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

this function log GetAVSSupportedAssets is not right

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fixed

func (k *Keeper) GetAVSMinimumSelfDelegation(ctx sdk.Context, avsAddr string) (sdkmath.LegacyDec, error) {
avsInfo, err := k.GetAVSInfo(ctx, avsAddr)
if err != nil {
return sdkmath.LegacyNewDec(0), errorsmod.Wrap(err, fmt.Sprintf("GetAVSSupportedAssets: key is %s", avsAddr))
Copy link
Contributor

Choose a reason for hiding this comment

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

here function log : GetAVSSupportedAssets

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fixed

SlashAddr: params.SlashContractAddr,
AvsOwnerAddress: params.AvsOwnerAddress,
AssetId: params.AssetID,
AvsUnbondingEpochs: uint32(params.MinimumDelegation),
Copy link
Contributor

@bwhour bwhour May 29, 2024

Choose a reason for hiding this comment

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

this param has a lot of types in different places: unit32, uint64, int64. please have a check.
this assignment is strange :

AvsUnbondingEpochs: uint32(params.MinimumDelegation),
MinimumDelegation: sdk.NewIntFromUint64(params.UnbondingEpochs),

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fixed

action := params.Action

if action == RegisterAction && avsInfo != nil {
return errorsmod.Wrap(types.ErrAlreadyRegistered, fmt.Sprintf("the error input arg is:%s", params.AvsAddress))
Copy link
Contributor

Choose a reason for hiding this comment

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

can replace this with specific error " the avsaddress is :%s",

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fixed

}

if avsInfo == nil {
return errorsmod.Wrap(types.ErrUnregisterNonExistent, fmt.Sprintf("the error input arg is:%s", avsInfo))
Copy link
Contributor

Choose a reason for hiding this comment

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

avsInfo == nil so this line has no meaning print: fmt.Sprintf("the error input arg is:%s", avsInfo)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

unregistration must be done with data available

}
avsInfo, err := k.GetAVSInfo(ctx, params.AvsAddress)
if err != nil {
if err != nil || avsInfo.GetInfo() == nil {
Copy link
Contributor

Choose a reason for hiding this comment

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

there are two lines call avsInfo.GetInfo(), can we call once ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fixed

return errorsmod.Wrap(err, fmt.Sprintf("error occurred when get avs info %s", avsInfo))
}
if avsInfo.Info.AvsOwnerAddress != params.AvsOwnerAddress {
return errorsmod.Wrap(err, fmt.Sprintf("not qualified to deregister %s", avsInfo))
avs := avsInfo.GetInfo()
Copy link
Contributor

Choose a reason for hiding this comment

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

see above comment

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fixed

ret.OperatorAddress = append(ret.OperatorAddress, operatorAddress)
ret.AssetId = append(ret.AssetId, assetID)

AVSInfo := avs
Copy link
Contributor

Choose a reason for hiding this comment

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

this AVSInfo variable is the same as types.AVSInfo

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fixed

Copy link
Contributor

@bwhour bwhour left a comment

Choose a reason for hiding this comment

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

some comments left need to be fixed.

@trestinlsd trestinlsd merged commit 34cf62f into ExocoreNetwork:develop May 30, 2024
19 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants