Skip to content

Commit

Permalink
fix some comments
Browse files Browse the repository at this point in the history
  • Loading branch information
trestinlsd committed Sep 5, 2024
1 parent bf369ac commit fb0aca8
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 28 deletions.
6 changes: 4 additions & 2 deletions precompiles/avs/avs.sol → precompiles/avs/IAVSManager.sol
Original file line number Diff line number Diff line change
Expand Up @@ -170,8 +170,10 @@ interface IAVSManager {
) external view returns (uint256 amount);

/// @dev RegisterBLSPublicKey Emitted when `operator` registers with the public keys `pubKey`.
/// @param operator the address of the delegator
/// @param pubKey the address of the validator
/// @param name the name of the blsKey
/// @param pubKey the public key of the operator
/// @param pubkeyRegistrationSignature the sig of the operator
/// @param pubkeyRegistrationMessageHash the sig hash of the operator
event RegisterBLSPublicKey(
string name,
bytes pubKey,
Expand Down
3 changes: 2 additions & 1 deletion x/avs/client/cli/query.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
//nolint:dupl
package cli

import (
Expand Down Expand Up @@ -169,7 +170,7 @@ func QueryChallengeInfo() *cobra.Command {
Args: cobra.ExactArgs(3),
RunE: func(cmd *cobra.Command, args []string) error {
if !common.IsHexAddress(args[0]) {
return xerrors.Errorf("invalid task address,err:%s", types.ErrInvalidAddr)
return xerrors.Errorf("invalid address,err:%s", types.ErrInvalidAddr)
}
clientCtx, err := client.GetClientQueryContext(cmd)
if err != nil {
Expand Down
1 change: 1 addition & 0 deletions x/avs/keeper/avs.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ func (k *Keeper) GetTaskStatisticalEpochEndAVSs(ctx sdk.Context, epochIdentifier
// Determine if the statistical period has passed, the range of the statistical period is the num marked (StartingEpoch) add TaskStatisticalPeriod
// #nosec G115
if epochIdentifier == avsInfo.EpochIdentifier && epochNumber ==
// #nosec G115
int64(taskInfo.StartingEpoch)+int64(taskInfo.TaskResponsePeriod)+int64(taskInfo.TaskStatisticalPeriod) {
taskResList = append(taskResList, info)
}
Expand Down
44 changes: 26 additions & 18 deletions x/avs/keeper/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,10 @@ func (k Keeper) UpdateAVSInfo(ctx sdk.Context, params *types.AVSRegisterOrDeregi
if !found {
return errorsmod.Wrap(types.ErrEpochNotFound, fmt.Sprintf("epoch info not found %s", epochIdentifier))
}

if k.GetAVSInfoByTaskAddress(ctx, params.TaskAddr).AvsAddress != "" {
return errorsmod.Wrap(types.ErrAlreadyRegistered, fmt.Sprintf("this TaskAddr has already been used by other AVS,the TaskAddr is :%s", params.TaskAddr))
}
switch action {
case RegisterAction:
if avsInfo != nil {
Expand All @@ -96,8 +100,10 @@ func (k Keeper) UpdateAVSInfo(ctx sdk.Context, params *types.AVSRegisterOrDeregi
TaskAddr: params.TaskAddr,
MinStakeAmount: params.MinStakeAmount, // Effective at CurrentEpoch+1, avoid immediate effects and ensure that the first epoch time of avs is equal to a normal identifier
MinTotalStakeAmount: params.MinTotalStakeAmount,
AvsSlash: sdk.NewDecWithPrec(int64(params.AvsSlash), 2), // #nosec G115
AvsReward: sdk.NewDecWithPrec(int64(params.AvsReward), 2), // #nosec G115
// #nosec G115
AvsSlash: sdk.NewDecWithPrec(int64(params.AvsSlash), 2),
// #nosec G115
AvsReward: sdk.NewDecWithPrec(int64(params.AvsReward), 2),
}

return k.SetAVSInfo(ctx, avs)
Expand Down Expand Up @@ -125,16 +131,15 @@ func (k Keeper) UpdateAVSInfo(ctx sdk.Context, params *types.AVSRegisterOrDeregi
if avsInfo == nil {
return errorsmod.Wrap(types.ErrUnregisterNonExistent, fmt.Sprintf("the avsaddress is :%s", params.AvsAddress))
}
// TODO: The AvsUnbondingPeriod is used for undelegation, but this check currently blocks updates to AVS information. Remove this check to allow AVS updates, while detailed control mechanisms for updates should be considered and implemented in the future.
// If avs UpdateAction check UnbondingPeriod

// #nosec G115
// if int64(avsInfo.Info.AvsUnbondingPeriod) < (epoch.CurrentEpoch - int64(avsInfo.GetInfo().StartingEpoch)) {
// return errorsmod.Wrap(types.ErrUnbondingPeriod, fmt.Sprintf("not qualified to deregister %s", avsInfo))
//}

// }
// If avs UpdateAction check CallerAddress
if !slices.Contains(avsInfo.Info.AvsOwnerAddress, params.CallerAddress) {
return errorsmod.Wrap(types.ErrCallerAddressUnauthorized, fmt.Sprintf("this caller not qualified to update %s", params.CallerAddress))
}

avs := avsInfo.Info

if params.AvsName != "" {
Expand Down Expand Up @@ -176,10 +181,12 @@ func (k Keeper) UpdateAVSInfo(ctx sdk.Context, params *types.AVSRegisterOrDeregi
avs.MinTotalStakeAmount = params.MinTotalStakeAmount
}
if params.AvsSlash > 0 {
avs.AvsSlash = sdk.NewDecWithPrec(int64(params.AvsSlash), 2) // #nosec G115
// #nosec G115
avs.AvsSlash = sdk.NewDecWithPrec(int64(params.AvsSlash), 2)
}
if params.AvsReward > 0 {
avs.AvsReward = sdk.NewDecWithPrec(int64(params.AvsReward), 2) // #nosec G115
// #nosec G115
avs.AvsReward = sdk.NewDecWithPrec(int64(params.AvsReward), 2)
}
avs.AvsAddress = params.AvsAddress
avs.StartingEpoch = uint64(epoch.CurrentEpoch + 1)
Expand Down Expand Up @@ -254,7 +261,7 @@ func (k Keeper) OperatorOptAction(ctx sdk.Context, params *OperatorOptParams) er
}

if !k.operatorKeeper.IsOperator(ctx, opAccAddr) {
return errorsmod.Wrap(delegationtypes.ErrOperatorNotExist, fmt.Sprintf("AVSInfoUpdate: invalid operator address:%s", operatorAddress))
return errorsmod.Wrap(delegationtypes.ErrOperatorNotExist, fmt.Sprintf("UpdateAVSInfo: invalid operator address:%s", operatorAddress))
}

f, err := k.IsAVS(ctx, params.AvsAddress)
Expand Down Expand Up @@ -348,16 +355,13 @@ func (k Keeper) RaiseAndResolveChallenge(ctx sdk.Context, params *ChallengeParam
return fmt.Errorf("task does not exist,this task address: %s", params.TaskContractAddress)
}
// check Task
if taskInfo.TaskContractAddress != params.TaskContractAddress.String() || taskInfo.TaskId != params.TaskID ||
hex.EncodeToString(taskInfo.Hash) != hex.EncodeToString(params.TaskHash) {
if hex.EncodeToString(taskInfo.Hash) != hex.EncodeToString(params.TaskHash) {
return errorsmod.Wrap(err, fmt.Sprintf("error Task hasn't been responded to yet: %s", params.TaskContractAddress))
}
// check Task result
res, err := k.GetTaskResultInfo(ctx, params.OperatorAddress.String(), params.TaskContractAddress.String(),
params.TaskID)
if err != nil || res.OperatorAddress != params.OperatorAddress.String() ||
res.TaskContractAddress != params.TaskContractAddress.String() ||
res.TaskId != params.TaskID || res.TaskResponseHash != hex.EncodeToString(params.TaskResponseHash) {
if err != nil || res.TaskId != params.TaskID || res.TaskResponseHash != hex.EncodeToString(params.TaskResponseHash) {
return errorsmod.Wrap(
types.ErrInconsistentParams,
fmt.Sprintf("Task response does not match the one recorded,task addr: %s ,(TaskContractAddress: %s)"+
Expand All @@ -379,14 +383,18 @@ func (k Keeper) RaiseAndResolveChallenge(ctx sdk.Context, params *ChallengeParam
return errorsmod.Wrap(types.ErrEpochNotFound, fmt.Sprintf("epoch info not found %s",
avsInfo.EpochIdentifier))
}
if epoch.CurrentEpoch <= int64(taskInfo.StartingEpoch)+int64(taskInfo.TaskResponsePeriod)+int64(taskInfo.TaskStatisticalPeriod) || //nolint:gosec
epoch.CurrentEpoch > int64(taskInfo.StartingEpoch)+int64(taskInfo.TaskResponsePeriod)+int64(taskInfo.TaskStatisticalPeriod)+int64(taskInfo.TaskChallengePeriod) { //nolint:gosec
if epoch.CurrentEpoch <= int64(taskInfo.StartingEpoch)+int64(taskInfo.TaskResponsePeriod)+int64(taskInfo.TaskStatisticalPeriod) { //nolint:gosec
return errorsmod.Wrap(
types.ErrSubmitTooLateError,
fmt.Sprintf("SetTaskResultInfo:the challenge period has not started , CurrentEpoch:%d", epoch.CurrentEpoch),
)
}
if epoch.CurrentEpoch > int64(taskInfo.StartingEpoch)+int64(taskInfo.TaskResponsePeriod)+int64(taskInfo.TaskStatisticalPeriod)+int64(taskInfo.TaskChallengePeriod) { //nolint:gosec
return errorsmod.Wrap(
types.ErrSubmitTooLateError,
fmt.Sprintf("SetTaskResultInfo:submit too late, CurrentEpoch:%d", epoch.CurrentEpoch),
)
}

return k.SetTaskChallengedInfo(ctx, params.TaskID, params.OperatorAddress.String(),
params.TaskContractAddress, params.CallerAddress)
}
18 changes: 12 additions & 6 deletions x/avs/keeper/task.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@ package keeper
import (
"bytes"
"fmt"
"github.com/ethereum/go-ethereum/crypto"
"strconv"
"strings"

"github.com/ethereum/go-ethereum/crypto"

errorsmod "cosmossdk.io/errors"

assetstype "github.com/ExocoreNetwork/exocore/x/assets/types"
Expand Down Expand Up @@ -185,6 +186,13 @@ func (k *Keeper) SetTaskResultInfo(
info.OperatorAddress, info.TaskContractAddress, info.TaskId),
)
}
// check parameters
if info.BlsSignature == nil {
return errorsmod.Wrap(
types.ErrInconsistentParams,
fmt.Sprintf("SetTaskResultInfo: invalid param BlsSignature is not be null (BlsSignature: %s)", info.BlsSignature),
)
}
if info.TaskResponseHash != "" || info.TaskResponse != nil {
return errorsmod.Wrap(
types.ErrParamNotEmptyError,
Expand Down Expand Up @@ -218,9 +226,7 @@ func (k *Keeper) SetTaskResultInfo(
}
// check parameters
res, err := k.GetTaskResultInfo(ctx, info.OperatorAddress, info.TaskContractAddress, info.TaskId)
if err != nil || res.OperatorAddress != info.OperatorAddress ||
res.TaskContractAddress != info.TaskContractAddress ||
res.TaskId != info.TaskId || !bytes.Equal(res.BlsSignature, info.BlsSignature) {
if err != nil || !bytes.Equal(res.BlsSignature, info.BlsSignature) {
return errorsmod.Wrap(
types.ErrInconsistentParams,
fmt.Sprintf("SetTaskResultInfo: invalid param OperatorAddress: %s ,(TaskContractAddress: %s)"+
Expand Down Expand Up @@ -248,8 +254,8 @@ func (k *Keeper) SetTaskResultInfo(
)
}
// TODO :check taskID
//resp, err := types.UnmarshalTaskResponse(info.TaskResponse)
//if err != nil || info.TaskId != resp.TaskID {
// resp, err := types.UnmarshalTaskResponse(info.TaskResponse)
// if err != nil || info.TaskId != resp.TaskID {
// return errorsmod.Wrap(
// types.ErrParamError,
// fmt.Sprintf("SetTaskResultInfo: invalid param value:%s", info.Stage),
Expand Down
3 changes: 2 additions & 1 deletion x/avs/types/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,11 @@ import (
"encoding/hex"
"encoding/json"
"fmt"
"github.com/ethereum/go-ethereum/accounts/abi"
"math/big"
"strings"

"github.com/ethereum/go-ethereum/accounts/abi"

ibcclienttypes "github.com/cosmos/ibc-go/v7/modules/core/02-client/types"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/common/hexutil"
Expand Down

0 comments on commit fb0aca8

Please sign in to comment.