diff --git a/precompiles/avs/IAVSManager.sol b/precompiles/avs/IAVSManager.sol index d84730680..c347d2ff2 100644 --- a/precompiles/avs/IAVSManager.sol +++ b/precompiles/avs/IAVSManager.sol @@ -12,18 +12,18 @@ IAVSManager constant AVSMANAGER_CONTRACT = IAVSManager( /// @dev The interface through which solidity contracts will interact with AVS-Manager /// @custom:address 0x0000000000000000000000000000000000000901 interface IAVSManager { - event AVSRegistered(address indexed sender, string avsName); - event AVSUpdated(address indexed sender, string avsName); - event AVSDeregistered(address indexed sender, string avsName); - event OperatorJoined(address indexed sender); - event OperatorOuted(address indexed sender); - event TaskCreated(address indexed sender,uint64 taskId,address indexed taskContractAddress,string name,bytes hash, + event AVSRegistered(address indexed avsAddr, string sender, string avsName); + event AVSUpdated(address indexed avsAddr, string sender, string avsName); + event AVSDeregistered(address indexed avsAddr, string sender, string avsName); + event OperatorJoined(address indexed avsAddr,string sender); + event OperatorOuted(address indexed avsAddr,string sender); + event TaskCreated(string sender,uint64 taskId,address indexed taskContractAddress,string name,bytes hash, uint64 taskResponsePeriod,uint64 taskChallengePeriod,uint64 thresholdPercentage,uint64 taskStatisticalPeriod ); - event ChallengeInitiated(address indexed sender, bytes taskHash, uint64 taskID, bytes taskResponseHash, + event ChallengeInitiated(string sender, bytes taskHash, uint64 taskID, bytes taskResponseHash, string operatorAddress); - event PublicKeyRegistered(address indexed sender, string name); - event TaskSubmittedByOperator(address indexed sender, uint64 taskID, bytes taskResponse, + event PublicKeyRegistered(string sender, string name); + event TaskSubmittedByOperator(string sender, uint64 taskID, bytes taskResponse, bytes blsSignature, address indexed taskContractAddress, uint8 phase); @@ -199,7 +199,7 @@ interface IAVSManager { string memory operatorAddr ) external view returns (uint256 amount); - /// @dev getAVSInfo is a function to query Avs info. + /// @dev getAVSInfo is a function to query Avs epochIdentifier info. /// @param avsAddr The address of the avs function getAVSInfo( address avsAddr diff --git a/precompiles/avs/abi.json b/precompiles/avs/abi.json index a4c3b2506..7cbbdb7fc 100644 --- a/precompiles/avs/abi.json +++ b/precompiles/avs/abi.json @@ -5,9 +5,15 @@ { "indexed": true, "internalType": "address", - "name": "sender", + "name": "avsAddr", "type": "address" }, + { + "indexed": false, + "internalType": "string", + "name": "sender", + "type": "string" + }, { "indexed": false, "internalType": "string", @@ -24,9 +30,15 @@ { "indexed": true, "internalType": "address", - "name": "sender", + "name": "avsAddr", "type": "address" }, + { + "indexed": false, + "internalType": "string", + "name": "sender", + "type": "string" + }, { "indexed": false, "internalType": "string", @@ -43,9 +55,15 @@ { "indexed": true, "internalType": "address", - "name": "sender", + "name": "avsAddr", "type": "address" }, + { + "indexed": false, + "internalType": "string", + "name": "sender", + "type": "string" + }, { "indexed": false, "internalType": "string", @@ -60,10 +78,10 @@ "anonymous": false, "inputs": [ { - "indexed": true, - "internalType": "address", + "indexed": false, + "internalType": "string", "name": "sender", - "type": "address" + "type": "string" }, { "indexed": false, @@ -99,8 +117,14 @@ { "indexed": true, "internalType": "address", - "name": "sender", + "name": "avsAddr", "type": "address" + }, + { + "indexed": false, + "internalType": "string", + "name": "sender", + "type": "string" } ], "name": "OperatorJoined", @@ -112,8 +136,14 @@ { "indexed": true, "internalType": "address", - "name": "sender", + "name": "avsAddr", "type": "address" + }, + { + "indexed": false, + "internalType": "string", + "name": "sender", + "type": "string" } ], "name": "OperatorOuted", @@ -123,10 +153,10 @@ "anonymous": false, "inputs": [ { - "indexed": true, - "internalType": "address", + "indexed": false, + "internalType": "string", "name": "sender", - "type": "address" + "type": "string" }, { "indexed": false, @@ -142,10 +172,10 @@ "anonymous": false, "inputs": [ { - "indexed": true, - "internalType": "address", + "indexed": false, + "internalType": "string", "name": "sender", - "type": "address" + "type": "string" }, { "indexed": false, @@ -203,10 +233,10 @@ "anonymous": false, "inputs": [ { - "indexed": true, - "internalType": "address", + "indexed": false, + "internalType": "string", "name": "sender", - "type": "address" + "type": "string" }, { "indexed": false, diff --git a/precompiles/avs/avs.go b/precompiles/avs/avs.go index fc49f0835..5a050ea2b 100644 --- a/precompiles/avs/avs.go +++ b/precompiles/avs/avs.go @@ -135,7 +135,7 @@ func (p Precompile) Run(evm *vm.EVM, contract *vm.Contract, readOnly bool) (bz [ bz, err = p.GetOptedInOperatorAccAddrs(ctx, contract, method, args) if err != nil { ctx.Logger().Error("internal error when calling avs precompile", "module", "avs precompile", "method", method.Name, "err", err) - bz, err = method.Outputs.Pack([]string(nil)) + bz, err = method.Outputs.Pack([]string{}) } case MethodGetAVSInfo: bz, err = p.GetAVSInfo(ctx, contract, method, args) @@ -147,7 +147,7 @@ func (p Precompile) Run(evm *vm.EVM, contract *vm.Contract, readOnly bool) (bz [ bz, err = p.GetTaskInfo(ctx, contract, method, args) if err != nil { ctx.Logger().Error("internal error when calling avs precompile", "module", "avs precompile", "method", method.Name, "err", err) - bz, err = method.Outputs.Pack([]uint64(nil)) + bz, err = method.Outputs.Pack([]uint64{}) } case MethodIsOperator: bz, err = p.IsOperator(ctx, contract, method, args) @@ -167,7 +167,7 @@ func (p Precompile) Run(evm *vm.EVM, contract *vm.Contract, readOnly bool) (bz [ bz, err = p.GetRegisteredPubkey(ctx, contract, method, args) if err != nil { ctx.Logger().Error("internal error when calling avs precompile", "module", "avs precompile", "method", method.Name, "err", err) - bz, err = method.Outputs.Pack([]byte(nil)) + bz, err = method.Outputs.Pack([]byte{}) } case MethodGetOperatorOptedUSDValue: bz, err = p.GetOperatorOptedUSDValue(ctx, contract, method, args) diff --git a/precompiles/avs/avs_test.go b/precompiles/avs/avs_test.go index 40d267168..4261ba031 100644 --- a/precompiles/avs/avs_test.go +++ b/precompiles/avs/avs_test.go @@ -245,8 +245,8 @@ func (suite *AVSManagerPrecompileSuite) TestDeregisterAVS() { MinStakeAmount: minStakeAmount, MinOptInOperators: params[0], MinTotalStakeAmount: params[1], - AvsReward: sdk.MustNewDecFromStr(strconv.FormatUint(params[1], 10)), - AvsSlash: sdk.MustNewDecFromStr(strconv.FormatUint(params[2], 10)), + AvsReward: sdk.MustNewDecFromStr(strconv.Itoa(int(params[1]))), + AvsSlash: sdk.MustNewDecFromStr(strconv.Itoa(int(params[2]))), } err := suite.App.AVSManagerKeeper.SetAVSInfo(suite.Ctx, avs) @@ -391,8 +391,8 @@ func (suite *AVSManagerPrecompileSuite) TestUpdateAVS() { MinStakeAmount: minStakeAmount, MinOptInOperators: params[0], MinTotalStakeAmount: params[1], - AvsReward: sdk.MustNewDecFromStr(strconv.FormatUint(params[1], 10)), - AvsSlash: sdk.MustNewDecFromStr(strconv.FormatUint(params[2], 10)), + AvsReward: sdk.MustNewDecFromStr(strconv.Itoa(int(params[1]))), + AvsSlash: sdk.MustNewDecFromStr(strconv.Itoa(int(params[2]))), } err := suite.App.AVSManagerKeeper.SetAVSInfo(suite.Ctx, avs) @@ -536,7 +536,7 @@ func (suite *AVSManagerPrecompileSuite) TestRegisterOperatorToAVS() { _, defaultAssetID := assetstypes.GetStakerIDAndAssetIDFromStr(asset.LayerZeroChainID, "", asset.Address) err = suite.App.AVSManagerKeeper.UpdateAVSInfo(suite.Ctx, &types.AVSRegisterOrDeregisterParams{ Action: types.UpdateAction, - AvsAddress: avsAddr.String(), + AvsAddress: avsAddr, AssetID: []string{defaultAssetID}, }) suite.NoError(err) diff --git a/precompiles/avs/events.go b/precompiles/avs/events.go index d24470c97..824ead060 100644 --- a/precompiles/avs/events.go +++ b/precompiles/avs/events.go @@ -54,42 +54,47 @@ func (p Precompile) emitEvent(ctx sdk.Context, stateDB vm.StateDB, eventName str func (p Precompile) EmitAVSRegistered(ctx sdk.Context, stateDB vm.StateDB, avs *avstypes.AVSRegisterOrDeregisterParams) error { arguments := p.ABI.Events[EventTypeAVSRegistered].Inputs return p.emitEvent(ctx, stateDB, EventTypeAVSRegistered, arguments, - common.HexToAddress(avs.CallerAddress), + avs.AvsAddress, + avs.CallerAddress.String(), avs.AvsName) } func (p Precompile) EmitAVSUpdated(ctx sdk.Context, stateDB vm.StateDB, avs *avstypes.AVSRegisterOrDeregisterParams) error { arguments := p.ABI.Events[EventTypeAVSUpdated].Inputs return p.emitEvent(ctx, stateDB, EventTypeAVSUpdated, arguments, - common.HexToAddress(avs.CallerAddress), + avs.AvsAddress, + avs.CallerAddress.String(), avs.AvsName) } func (p Precompile) EmitAVSDeregistered(ctx sdk.Context, stateDB vm.StateDB, avs *avstypes.AVSRegisterOrDeregisterParams) error { arguments := p.ABI.Events[EventTypeAVSDeregistered].Inputs return p.emitEvent(ctx, stateDB, EventTypeAVSDeregistered, arguments, - common.HexToAddress(avs.CallerAddress), + avs.AvsAddress, + avs.CallerAddress.String(), avs.AvsName) } func (p Precompile) EmitOperatorJoined(ctx sdk.Context, stateDB vm.StateDB, params *avstypes.OperatorOptParams) error { arguments := p.ABI.Events[EventTypeOperatorJoined].Inputs return p.emitEvent(ctx, stateDB, EventTypeOperatorJoined, arguments, - common.HexToAddress(params.OperatorAddress)) + params.AvsAddress, + params.OperatorAddress.String()) } func (p Precompile) EmitOperatorOuted(ctx sdk.Context, stateDB vm.StateDB, params *avstypes.OperatorOptParams) error { arguments := p.ABI.Events[EventTypeOperatorOuted].Inputs return p.emitEvent(ctx, stateDB, EventTypeOperatorOuted, arguments, - common.HexToAddress(params.OperatorAddress)) + params.AvsAddress, + params.OperatorAddress.String()) } func (p Precompile) EmitTaskCreated(ctx sdk.Context, stateDB vm.StateDB, task *avstypes.TaskInfoParams) error { arguments := p.ABI.Events[EventTypeTaskCreated].Inputs return p.emitEvent(ctx, stateDB, EventTypeTaskCreated, arguments, - common.HexToAddress(task.CallerAddress), + task.CallerAddress.String(), task.TaskID, - common.HexToAddress(task.TaskContractAddress), + task.TaskContractAddress, task.TaskName, task.Hash, task.TaskResponsePeriod, @@ -101,7 +106,7 @@ func (p Precompile) EmitTaskCreated(ctx sdk.Context, stateDB vm.StateDB, task *a func (p Precompile) EmitChallengeInitiated(ctx sdk.Context, stateDB vm.StateDB, params *avstypes.ChallengeParams) error { arguments := p.ABI.Events[EventTypeChallengeInitiated].Inputs return p.emitEvent(ctx, stateDB, EventTypeChallengeInitiated, arguments, - common.HexToAddress(params.CallerAddress), + params.CallerAddress.String(), params.TaskHash, params.TaskID, params.TaskResponseHash, @@ -111,14 +116,14 @@ func (p Precompile) EmitChallengeInitiated(ctx sdk.Context, stateDB vm.StateDB, func (p Precompile) EmitPublicKeyRegistered(ctx sdk.Context, stateDB vm.StateDB, params *avstypes.BlsParams) error { arguments := p.ABI.Events[EventTypePublicKeyRegistered].Inputs return p.emitEvent(ctx, stateDB, EventTypePublicKeyRegistered, arguments, - common.HexToAddress(params.Operator), + params.Operator.String(), params.Name) } func (p Precompile) EmitTaskSubmittedByOperator(ctx sdk.Context, stateDB vm.StateDB, params *avstypes.TaskResultParams) error { arguments := p.ABI.Events[EventTypeTaskSubmittedByOperator].Inputs return p.emitEvent(ctx, stateDB, EventTypeTaskSubmittedByOperator, arguments, - common.HexToAddress(params.CallerAddress), + params.CallerAddress.String(), params.TaskID, params.TaskResponse, params.BlsSignature, diff --git a/precompiles/avs/query.go b/precompiles/avs/query.go index c4a3801cf..036fef55b 100644 --- a/precompiles/avs/query.go +++ b/precompiles/avs/query.go @@ -35,16 +35,18 @@ func (p Precompile) GetRegisteredPubkey( if len(args) != len(p.ABI.Methods[MethodGetRegisteredPubkey].Inputs) { return nil, fmt.Errorf(cmn.ErrInvalidNumberOfArgs, len(p.ABI.Methods[MethodGetRegisteredPubkey].Inputs), len(args)) } - // the key is set using the operator's acc address so the same logic should apply here addr, ok := args[0].(string) if !ok { return nil, fmt.Errorf(exocmn.ErrContractInputParaOrType, 0, "string", addr) } - blsPubkeyInfo, err := p.avsKeeper.GetOperatorPubKey(ctx, addr) + blsPubKeyInfo, err := p.avsKeeper.GetOperatorPubKey(ctx, addr) if err != nil { + if errors.Is(err, avstype.ErrNoKeyInTheStore) { + return method.Outputs.Pack([]byte{}) + } return nil, err } - return method.Outputs.Pack(blsPubkeyInfo.PubKey) + return method.Outputs.Pack(blsPubKeyInfo.PubKey) } func (p Precompile) GetOptedInOperatorAccAddrs( @@ -85,6 +87,9 @@ func (p Precompile) GetAVSUSDValue( } amount, err := p.avsKeeper.GetOperatorKeeper().GetAVSUSDValue(ctx, addr.String()) if err != nil { + if errors.Is(err, avstype.ErrNoKeyInTheStore) { + return method.Outputs.Pack(common.Big0) + } return nil, err } return method.Outputs.Pack(amount.BigInt()) @@ -110,6 +115,9 @@ func (p Precompile) GetOperatorOptedUSDValue( } amount, err := p.avsKeeper.GetOperatorKeeper().GetOperatorOptedUSDValue(ctx, avsAddr.String(), operatorAddr) if err != nil { + if errors.Is(err, avstype.ErrNoKeyInTheStore) { + return method.Outputs.Pack(common.Big0) + } return nil, err } return method.Outputs.Pack(amount.ActiveUSDValue.BigInt()) @@ -124,7 +132,6 @@ func (p Precompile) GetAVSInfo( if len(args) != len(p.ABI.Methods[MethodGetAVSInfo].Inputs) { return nil, fmt.Errorf(cmn.ErrInvalidNumberOfArgs, len(p.ABI.Methods[MethodGetAVSInfo].Inputs), len(args)) } - // the key is set using the operator's acc address so the same logic should apply here addr, ok := args[0].(common.Address) if !ok { return nil, fmt.Errorf(exocmn.ErrContractInputParaOrType, 0, "common.Address", addr) @@ -174,7 +181,6 @@ func (p Precompile) GetTaskInfo( if len(args) != len(p.ABI.Methods[MethodGetTaskInfo].Inputs) { return nil, fmt.Errorf(cmn.ErrInvalidNumberOfArgs, len(p.ABI.Methods[MethodGetTaskInfo].Inputs), len(args)) } - // the key is set using the operator's acc address so the same logic should apply here addr, ok := args[0].(common.Address) if !ok { return nil, fmt.Errorf(exocmn.ErrContractInputParaOrType, 0, "common.Address", addr) diff --git a/precompiles/avs/tx.go b/precompiles/avs/tx.go index 7e8f2d06e..b468de81d 100644 --- a/precompiles/avs/tx.go +++ b/precompiles/avs/tx.go @@ -43,11 +43,11 @@ func (p Precompile) RegisterAVS( return nil, errorsmod.Wrap(err, "parse args error") } // verification of the calling address to ensure it is avs contract owner - if !slices.Contains(avsParams.AvsOwnerAddress, avsParams.CallerAddress) { + if !slices.Contains(avsParams.AvsOwnerAddress, avsParams.CallerAddress.String()) { return nil, errorsmod.Wrap(err, "not qualified to registerOrDeregister") } // The AVS registration is done by the calling contract. - avsParams.AvsAddress = contract.CallerAddress.String() + avsParams.AvsAddress = contract.CallerAddress avsParams.Action = avstypes.RegisterAction // Finally, update the AVS information in the keeper. err = p.avsKeeper.UpdateAVSInfo(ctx, avsParams) @@ -77,14 +77,14 @@ func (p Precompile) DeregisterAVS( if !ok || (callerAddress == common.Address{}) { return nil, fmt.Errorf(exocmn.ErrContractInputParaOrType, 0, "common.Address", callerAddress) } - avsParams.CallerAddress = sdk.AccAddress(callerAddress[:]).String() + avsParams.CallerAddress = callerAddress[:] avsName, ok := args[1].(string) if !ok || avsName == "" { return nil, fmt.Errorf(exocmn.ErrContractInputParaOrType, 1, "string", avsName) } avsParams.AvsName = avsName - avsParams.AvsAddress = contract.CallerAddress.String() + avsParams.AvsAddress = contract.CallerAddress avsParams.Action = avstypes.DeRegisterAction // validates that this is owner @@ -112,14 +112,14 @@ func (p Precompile) UpdateAVS( return nil, errorsmod.Wrap(err, "parse args error") } - avsParams.AvsAddress = contract.CallerAddress.String() + avsParams.AvsAddress = contract.CallerAddress avsParams.Action = avstypes.UpdateAction - previousAVSInfo, err := p.avsKeeper.GetAVSInfo(ctx, avsParams.AvsAddress) + previousAVSInfo, err := p.avsKeeper.GetAVSInfo(ctx, avsParams.AvsAddress.String()) if err != nil { return nil, err } // If avs UpdateAction check CallerAddress - if !slices.Contains(previousAVSInfo.Info.AvsOwnerAddress, avsParams.CallerAddress) { + if !slices.Contains(previousAVSInfo.Info.AvsOwnerAddress, avsParams.CallerAddress.String()) { return nil, fmt.Errorf("this caller not qualified to update %s", avsParams.CallerAddress) } err = p.avsKeeper.UpdateAVSInfo(ctx, avsParams) @@ -150,8 +150,8 @@ func (p Precompile) BindOperatorToAVS( } operatorParams := &avstypes.OperatorOptParams{} - operatorParams.OperatorAddress = sdk.AccAddress(callerAddress[:]).String() - operatorParams.AvsAddress = contract.CallerAddress.String() + operatorParams.OperatorAddress = callerAddress[:] + operatorParams.AvsAddress = contract.CallerAddress operatorParams.Action = avstypes.RegisterAction err := p.avsKeeper.OperatorOptAction(ctx, operatorParams) if err != nil { @@ -179,8 +179,8 @@ func (p Precompile) UnbindOperatorToAVS( return nil, fmt.Errorf(exocmn.ErrContractInputParaOrType, 0, "common.Address", callerAddress) } operatorParams := &avstypes.OperatorOptParams{} - operatorParams.OperatorAddress = sdk.AccAddress(callerAddress[:]).String() - operatorParams.AvsAddress = contract.CallerAddress.String() + operatorParams.OperatorAddress = callerAddress[:] + operatorParams.AvsAddress = contract.CallerAddress operatorParams.Action = avstypes.DeRegisterAction err := p.avsKeeper.OperatorOptAction(ctx, operatorParams) if err != nil { @@ -205,7 +205,7 @@ func (p Precompile) CreateAVSTask( if err != nil { return nil, err } - params.TaskContractAddress = contract.CallerAddress.String() + params.TaskContractAddress = contract.CallerAddress taskID, err := p.avsKeeper.CreateAVSTask(ctx, params) if err != nil { return nil, err @@ -234,7 +234,7 @@ func (p Precompile) Challenge( if !ok || (callerAddress == common.Address{}) { return nil, fmt.Errorf(exocmn.ErrContractInputParaOrType, 0, "common.Address", callerAddress) } - challengeParams.CallerAddress = sdk.AccAddress(callerAddress[:]).String() + challengeParams.CallerAddress = callerAddress[:] taskHash, ok := args[1].([]byte) if !ok { @@ -292,7 +292,7 @@ func (p Precompile) RegisterBLSPublicKey( if !ok || (callerAddress == common.Address{}) { return nil, fmt.Errorf(exocmn.ErrContractInputParaOrType, 0, "common.Address", callerAddress) } - blsParams.Operator = sdk.AccAddress(callerAddress[:]).String() + blsParams.Operator = callerAddress[:] name, ok := args[1].(string) if !ok || name == "" { return nil, fmt.Errorf(exocmn.ErrContractInputParaOrType, 1, "string", name) @@ -346,7 +346,7 @@ func (p Precompile) OperatorSubmitTask( if !ok || (callerAddress == common.Address{}) { return nil, fmt.Errorf(exocmn.ErrContractInputParaOrType, 0, "common.Address", callerAddress) } - resultParams.CallerAddress = sdk.AccAddress(callerAddress[:]).String() + resultParams.CallerAddress = callerAddress[:] taskID, ok := args[1].(uint64) if !ok { @@ -382,13 +382,13 @@ func (p Precompile) OperatorSubmitTask( result := &avstypes.TaskResultInfo{ TaskId: resultParams.TaskID, - OperatorAddress: resultParams.OperatorAddress, + OperatorAddress: resultParams.OperatorAddress.String(), TaskContractAddress: resultParams.TaskContractAddress.String(), TaskResponse: resultParams.TaskResponse, BlsSignature: resultParams.BlsSignature, Phase: uint32(resultParams.Phase), } - err := p.avsKeeper.SetTaskResultInfo(ctx, resultParams.OperatorAddress, result) + err := p.avsKeeper.SetTaskResultInfo(ctx, resultParams.OperatorAddress.String(), result) if err != nil { return nil, err } diff --git a/precompiles/avs/types.go b/precompiles/avs/types.go index 2e2352292..155325731 100644 --- a/precompiles/avs/types.go +++ b/precompiles/avs/types.go @@ -23,7 +23,7 @@ func (p Precompile) GetAVSParamsFromInputs(_ sdk.Context, args []interface{}) (* if !ok || (callerAddress == common.Address{}) { return nil, fmt.Errorf(exocmn.ErrContractInputParaOrType, 0, "common.Address", callerAddress) } - avsParams.CallerAddress = sdk.AccAddress(callerAddress[:]).String() + avsParams.CallerAddress = callerAddress[:] avsName, ok := args[1].(string) if !ok || avsName == "" { return nil, fmt.Errorf(exocmn.ErrContractInputParaOrType, 1, "string", avsName) @@ -40,19 +40,19 @@ func (p Precompile) GetAVSParamsFromInputs(_ sdk.Context, args []interface{}) (* if !ok || taskAddr == (common.Address{}) { return nil, xerrors.Errorf(exocmn.ErrContractInputParaOrType, 3, "common.Address", taskAddr) } - avsParams.TaskAddr = taskAddr.String() + avsParams.TaskAddr = taskAddr slashContractAddr, ok := args[4].(common.Address) if !ok || (slashContractAddr == common.Address{}) { return nil, xerrors.Errorf(exocmn.ErrContractInputParaOrType, 4, "common.Address", slashContractAddr) } - avsParams.SlashContractAddr = slashContractAddr.String() + avsParams.SlashContractAddr = slashContractAddr rewardContractAddr, ok := args[5].(common.Address) if !ok || (rewardContractAddr == common.Address{}) { return nil, xerrors.Errorf(exocmn.ErrContractInputParaOrType, 5, "common.Address", rewardContractAddr) } - avsParams.RewardContractAddr = rewardContractAddr.String() + avsParams.RewardContractAddr = rewardContractAddr // bech32 avsOwnerAddress, ok := args[6].([]string) @@ -125,7 +125,7 @@ func (p Precompile) GetAVSParamsFromUpdateInputs(_ sdk.Context, args []interface if !ok || (callerAddress == common.Address{}) { return nil, fmt.Errorf(exocmn.ErrContractInputParaOrType, 0, "common.Address", callerAddress) } - avsParams.CallerAddress = sdk.AccAddress(callerAddress[:]).String() + avsParams.CallerAddress = callerAddress[:] avsName, ok := args[1].(string) if !ok { @@ -143,19 +143,19 @@ func (p Precompile) GetAVSParamsFromUpdateInputs(_ sdk.Context, args []interface if !ok || taskAddr == (common.Address{}) { return nil, xerrors.Errorf(exocmn.ErrContractInputParaOrType, 3, "common.Address", taskAddr) } - avsParams.TaskAddr = taskAddr.String() + avsParams.TaskAddr = taskAddr slashContractAddr, ok := args[4].(common.Address) if !ok { return nil, xerrors.Errorf(exocmn.ErrContractInputParaOrType, 4, "common.Address", slashContractAddr) } - avsParams.SlashContractAddr = slashContractAddr.String() + avsParams.SlashContractAddr = slashContractAddr rewardContractAddr, ok := args[5].(common.Address) if !ok { return nil, xerrors.Errorf(exocmn.ErrContractInputParaOrType, 5, "common.Address", rewardContractAddr) } - avsParams.RewardContractAddr = rewardContractAddr.String() + avsParams.RewardContractAddr = rewardContractAddr // bech32 avsOwnerAddress, ok := args[6].([]string) @@ -228,7 +228,7 @@ func (p Precompile) GetTaskParamsFromInputs(_ sdk.Context, args []interface{}) ( if !ok || (callerAddress == common.Address{}) { return nil, fmt.Errorf(exocmn.ErrContractInputParaOrType, 0, "common.Address", callerAddress) } - taskParams.CallerAddress = sdk.AccAddress(callerAddress[:]).String() + taskParams.CallerAddress = callerAddress[:] name, ok := args[1].(string) if !ok || name == "" { return nil, fmt.Errorf(exocmn.ErrContractInputParaOrType, 1, "string", name) diff --git a/precompiles/avs/utils_test.go b/precompiles/avs/utils_test.go index 74519ca1d..00a78dc5f 100644 --- a/precompiles/avs/utils_test.go +++ b/precompiles/avs/utils_test.go @@ -103,9 +103,9 @@ func (suite *AVSManagerPrecompileSuite) prepareAvs(assetIDs []string, task strin err := suite.App.AVSManagerKeeper.UpdateAVSInfo(suite.Ctx, &avstypes.AVSRegisterOrDeregisterParams{ Action: avstypes.RegisterAction, EpochIdentifier: epochstypes.HourEpochID, - AvsAddress: suite.avsAddr, + AvsAddress: common.HexToAddress(suite.avsAddr), AssetID: assetIDs, - TaskAddr: task, + TaskAddr: common.HexToAddress(task), AvsOwnerAddress: avsOwnerAddress, }) suite.NoError(err) @@ -150,6 +150,7 @@ func (suite *AVSManagerPrecompileSuite) TestOptIn() { usdValue := operatorKeeper.CalculateUSDValue(suite.delegationAmount, price.Value, suite.assetDecimal, price.Decimal) expectedState := &StateForCheck{ OptedInfo: &operatorTypes.OptedInfo{ + SlashContract: "0x0000000000000000000000000000000000000000", OptedInHeight: uint64(suite.Ctx.BlockHeight()), OptedOutHeight: operatorTypes.DefaultOptedOutHeight, }, @@ -199,6 +200,7 @@ func (suite *AVSManagerPrecompileSuite) TestOptOut() { expectedState := &StateForCheck{ OptedInfo: &operatorTypes.OptedInfo{ + SlashContract: "0x0000000000000000000000000000000000000000", OptedInHeight: uint64(optInHeight), OptedOutHeight: uint64(suite.Ctx.BlockHeight()), }, diff --git a/x/avs/keeper/avs.go b/x/avs/keeper/avs.go index abbf48b77..f63ba2eea 100644 --- a/x/avs/keeper/avs.go +++ b/x/avs/keeper/avs.go @@ -85,7 +85,7 @@ func (k *Keeper) GetEpochEndAVSs(ctx sdk.Context, epochIdentifier string, ending // TODO:this function is frequently used while its implementation iterates over existing avs to find the target avs by task contract address, we should use a reverse mapping to avoid iteration func (k *Keeper) GetAVSInfoByTaskAddress(ctx sdk.Context, taskAddr string) types.AVSInfo { var avs types.AVSInfo - if taskAddr == "" { + if taskAddr == "" || taskAddr == "0x0000000000000000000000000000000000000000" { return avs } k.IterateAVSInfo(ctx, func(_ int64, avsInfo types.AVSInfo) (stop bool) { @@ -161,7 +161,7 @@ func (k Keeper) RegisterAVSWithChainID( return common.Address{}, err } // SetAVSInfo expects HexAddress for the AvsAddress - params.AvsAddress = avsAddrStr + params.AvsAddress = avsAddr params.Action = types.RegisterAction if err := k.UpdateAVSInfo(ctx, params); err != nil { diff --git a/x/avs/keeper/avs_test.go b/x/avs/keeper/avs_test.go index ad99f5a47..bf124a9e7 100644 --- a/x/avs/keeper/avs_test.go +++ b/x/avs/keeper/avs_test.go @@ -3,6 +3,7 @@ package keeper_test import ( "cosmossdk.io/math" assetstypes "github.com/ExocoreNetwork/exocore/x/assets/types" + "github.com/ethereum/go-ethereum/common" "math/big" "time" @@ -62,20 +63,20 @@ func (suite *AVSTestSuite) TestAVS() { } func (suite *AVSTestSuite) TestUpdateAVSInfo_Register() { - avsName, avsAddres, slashAddress, rewardAddress := "avsTest", "exo18cggcpvwspnd5c6ny8wrqxpffj5zmhklprtnph", "0xDF907c29719154eb9872f021d21CAE6E5025d7aB", "0xDF907c29719154eb9872f021d21CAE6E5025d7aB" + avsName, avsAddres, slashAddress, rewardAddress := "avsTest", "0xDF907c29719154eb9872f021d21CAE6E5025d7aB", "0xDF907c29719154eb9872f021d21CAE6E5025d7aB", "0xDF907c29719154eb9872f021d21CAE6E5025d7aB" avsOwnerAddress := []string{"exo13h6xg79g82e2g2vhjwg7j4r2z2hlncelwutkjr", "exo13h6xg79g82e2g2vhjwg7j4r2z2hlncelwutkj1", "exo13h6xg79g82e2g2vhjwg7j4r2z2hlncelwutkj2"} assetID := suite.AssetIDs avsParams := &types.AVSRegisterOrDeregisterParams{ AvsName: avsName, - AvsAddress: avsAddres, + AvsAddress: common.HexToAddress(avsAddres), Action: avstypes.RegisterAction, - RewardContractAddr: rewardAddress, + RewardContractAddr: common.HexToAddress(rewardAddress), AvsOwnerAddress: avsOwnerAddress, AssetID: assetID, MinSelfDelegation: uint64(10), UnbondingPeriod: uint64(2), - SlashContractAddr: slashAddress, + SlashContractAddr: common.HexToAddress(slashAddress), EpochIdentifier: epochstypes.DayEpochID, } @@ -94,19 +95,19 @@ func (suite *AVSTestSuite) TestUpdateAVSInfo_Register() { func (suite *AVSTestSuite) TestUpdateAVSInfo_DeRegister() { // Test case setup - avsName, avsAddres, slashAddress := "avsTest", suite.avsAddress.String(), "exo13h6xg79g82e2g2vhjwg7j4r2z2hlncelwutash" + avsName, avsAddress, slashAddress := "avsTest", suite.avsAddress.String(), "0xDF907c29719154eb9872f021d21CAE6E5025d7aB" avsOwnerAddress := []string{"exo13h6xg79g82e2g2vhjwg7j4r2z2hlncelwutkjr", "exo13h6xg79g82e2g2vhjwg7j4r2z2hlncelwutkj1", "exo13h6xg79g82e2g2vhjwg7j4r2z2hlncelwutkj2"} assetID := suite.AssetIDs avsParams := &types.AVSRegisterOrDeregisterParams{ AvsName: avsName, - AvsAddress: avsAddres, + AvsAddress: common.HexToAddress(avsAddress), Action: avstypes.DeRegisterAction, AvsOwnerAddress: avsOwnerAddress, AssetID: assetID, MinSelfDelegation: uint64(10), UnbondingPeriod: uint64(2), - SlashContractAddr: slashAddress, + SlashContractAddr: common.HexToAddress(slashAddress), EpochIdentifier: epochstypes.DayEpochID, } @@ -117,43 +118,41 @@ func (suite *AVSTestSuite) TestUpdateAVSInfo_DeRegister() { avsParams.Action = avstypes.RegisterAction err = suite.App.AVSManagerKeeper.UpdateAVSInfo(suite.Ctx, avsParams) suite.NoError(err) - info, err := suite.App.AVSManagerKeeper.GetAVSInfo(suite.Ctx, avsAddres) - suite.Equal(avsAddres, info.GetInfo().AvsAddress) + info, err := suite.App.AVSManagerKeeper.GetAVSInfo(suite.Ctx, avsAddress) + suite.Equal(avsAddress, info.GetInfo().AvsAddress) suite.CommitAfter(48*time.Hour + time.Nanosecond) suite.CommitAfter(48*time.Hour + time.Nanosecond) suite.CommitAfter(48*time.Hour + time.Nanosecond) suite.CommitAfter(48*time.Hour + time.Nanosecond) avsParams.Action = avstypes.DeRegisterAction - avsParams.CallerAddress = "exo13h6xg79g82e2g2vhjwg7j4r2z2hlncelwutkjr" + avsParams.CallerAddress, err = sdk.AccAddressFromBech32("exo13h6xg79g82e2g2vhjwg7j4r2z2hlncelwutkjr") err = suite.App.AVSManagerKeeper.UpdateAVSInfo(suite.Ctx, avsParams) suite.NoError(err) - info, err = suite.App.AVSManagerKeeper.GetAVSInfo(suite.Ctx, avsAddres) + info, err = suite.App.AVSManagerKeeper.GetAVSInfo(suite.Ctx, avsAddress) suite.Error(err) suite.Contains(err.Error(), types.ErrNoKeyInTheStore.Error()) } func (suite *AVSTestSuite) TestUpdateAVSInfoWithOperator_Register() { avsAddress := suite.avsAddress - operatorAddress := sdk.AccAddress(utiltx.GenerateAddress().Bytes()).String() + operatorAddress := sdk.AccAddress(utiltx.GenerateAddress().Bytes()) - opAccAddr, err := sdk.AccAddressFromBech32(operatorAddress) - suite.NoError(err) operatorParams := &avstypes.OperatorOptParams{ - AvsAddress: avsAddress.String(), + AvsAddress: avsAddress, Action: avstypes.RegisterAction, OperatorAddress: operatorAddress, } // operator Not Exist - err = suite.App.AVSManagerKeeper.OperatorOptAction(suite.Ctx, operatorParams) + err := suite.App.AVSManagerKeeper.OperatorOptAction(suite.Ctx, operatorParams) suite.Error(err) suite.Contains(err.Error(), delegationtypes.ErrOperatorNotExist.Error()) // register operator but avs not register // register operator registerReq := &operatorTypes.RegisterOperatorReq{ - FromAddress: opAccAddr.String(), + FromAddress: operatorAddress.String(), Info: &operatorTypes.OperatorInfo{ - EarningsAddr: opAccAddr.String(), + EarningsAddr: operatorAddress.String(), }, } _, err = suite.OperatorMsgServer.RegisterOperator(sdk.WrapSDKContext(suite.Ctx), registerReq) @@ -164,7 +163,7 @@ func (suite *AVSTestSuite) TestUpdateAVSInfoWithOperator_Register() { _, assetID := assetstypes.GetStakerIDAndAssetIDFromStr(asset.LayerZeroChainID, "", asset.Address) selfDelegateAmount := big.NewInt(10) minPrecisionSelfDelegateAmount := big.NewInt(0).Mul(selfDelegateAmount, big.NewInt(0).Exp(big.NewInt(10), big.NewInt(int64(asset.Decimals)), nil)) - err = suite.App.AssetsKeeper.UpdateOperatorAssetState(suite.Ctx, opAccAddr, assetID, assetstypes.DeltaOperatorSingleAsset{ + err = suite.App.AssetsKeeper.UpdateOperatorAssetState(suite.Ctx, operatorAddress, assetID, assetstypes.DeltaOperatorSingleAsset{ TotalAmount: math.NewIntFromBigInt(minPrecisionSelfDelegateAmount), TotalShare: math.LegacyNewDecFromBigInt(minPrecisionSelfDelegateAmount), OperatorShare: math.LegacyNewDecFromBigInt(minPrecisionSelfDelegateAmount), diff --git a/x/avs/keeper/epoch_test.go b/x/avs/keeper/epoch_test.go index eb9ab2e44..779251da6 100644 --- a/x/avs/keeper/epoch_test.go +++ b/x/avs/keeper/epoch_test.go @@ -23,7 +23,7 @@ func (suite *AVSTestSuite) TestEpochEnd_TaskCalculation() { suite.CommitAfter(suite.EpochDuration) suite.CommitAfter(suite.EpochDuration) suite.CommitAfter(suite.EpochDuration) - info, err := suite.App.AVSManagerKeeper.GetTaskInfo(suite.Ctx, strconv.FormatUint(suite.taskId, 10), common.Address(suite.taskAddress.Bytes()).String()) + info, err := suite.App.AVSManagerKeeper.GetTaskInfo(suite.Ctx, strconv.Itoa(int(suite.taskId)), common.Address(suite.taskAddress.Bytes()).String()) suite.NoError(err) expectInfo := &avstypes.TaskInfo{ TaskContractAddress: suite.taskAddress.String(), diff --git a/x/avs/keeper/keeper.go b/x/avs/keeper/keeper.go index ad81f0dd8..bdefca350 100644 --- a/x/avs/keeper/keeper.go +++ b/x/avs/keeper/keeper.go @@ -77,7 +77,7 @@ func (k Keeper) ValidateAssetIDs(ctx sdk.Context, assetIDs []string) error { } func (k Keeper) UpdateAVSInfo(ctx sdk.Context, params *types.AVSRegisterOrDeregisterParams) error { - avsInfo, _ := k.GetAVSInfo(ctx, params.AvsAddress) + avsInfo, _ := k.GetAVSInfo(ctx, params.AvsAddress.String()) action := params.Action epochIdentifier := params.EpochIdentifier if avsInfo != nil && avsInfo.Info.EpochIdentifier != "" { @@ -92,7 +92,7 @@ func (k Keeper) UpdateAVSInfo(ctx sdk.Context, params *types.AVSRegisterOrDeregi if avsInfo != nil { return errorsmod.Wrap(types.ErrAlreadyRegistered, fmt.Sprintf("the avsaddress is :%s", params.AvsAddress)) } - if k.GetAVSInfoByTaskAddress(ctx, params.TaskAddr).AvsAddress != "" { + if k.GetAVSInfoByTaskAddress(ctx, params.TaskAddr.String()).AvsAddress != "" { return errorsmod.Wrap(types.ErrAlreadyRegistered, fmt.Sprintf("this TaskAddr has already been used by other AVS,the TaskAddr is :%s", params.TaskAddr)) } startingEpoch := uint64(epoch.CurrentEpoch + 1) @@ -107,9 +107,9 @@ func (k Keeper) UpdateAVSInfo(ctx sdk.Context, params *types.AVSRegisterOrDeregi avs := &types.AVSInfo{ Name: params.AvsName, - AvsAddress: params.AvsAddress, - RewardAddr: params.RewardContractAddr, - SlashAddr: params.SlashContractAddr, + AvsAddress: params.AvsAddress.String(), + RewardAddr: params.RewardContractAddr.String(), + SlashAddr: params.SlashContractAddr.String(), AvsOwnerAddress: params.AvsOwnerAddress, AssetIDs: params.AssetID, MinSelfDelegation: params.MinSelfDelegation, @@ -117,7 +117,7 @@ func (k Keeper) UpdateAVSInfo(ctx sdk.Context, params *types.AVSRegisterOrDeregi EpochIdentifier: epochIdentifier, StartingEpoch: startingEpoch, MinOptInOperators: params.MinOptInOperators, - TaskAddr: params.TaskAddr, + TaskAddr: params.TaskAddr.String(), 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, // #nosec G115 @@ -132,7 +132,7 @@ func (k Keeper) UpdateAVSInfo(ctx sdk.Context, params *types.AVSRegisterOrDeregi return errorsmod.Wrap(types.ErrUnregisterNonExistent, fmt.Sprintf("the avsaddress is :%s", params.AvsAddress)) } // If avs DeRegisterAction check CallerAddress - if !slices.Contains(avsInfo.Info.AvsOwnerAddress, params.CallerAddress) { + if !slices.Contains(avsInfo.Info.AvsOwnerAddress, params.CallerAddress.String()) { return errorsmod.Wrap(types.ErrCallerAddressUnauthorized, fmt.Sprintf("this caller not qualified to deregister %s", params.CallerAddress)) } @@ -146,25 +146,19 @@ func (k Keeper) UpdateAVSInfo(ctx sdk.Context, params *types.AVSRegisterOrDeregi if avsInfo.Info.Name != params.AvsName { return errorsmod.Wrap(types.ErrAvsNameMismatch, fmt.Sprintf("Unregistered AVS name is incorrect %s", params.AvsName)) } - return k.DeleteAVSInfo(ctx, params.AvsAddress) + return k.DeleteAVSInfo(ctx, params.AvsAddress.String()) case types.UpdateAction: if avsInfo == nil { return errorsmod.Wrap(types.ErrUnregisterNonExistent, fmt.Sprintf("the avsaddress is :%s", params.AvsAddress)) } // Check here to ensure that the task address is only used by one avs - avsAddress := k.GetAVSInfoByTaskAddress(ctx, params.TaskAddr).AvsAddress + avsAddress := k.GetAVSInfoByTaskAddress(ctx, params.TaskAddr.String()).AvsAddress if avsAddress != "" && avsAddress != avsInfo.Info.AvsAddress { return errorsmod.Wrap(types.ErrAlreadyRegistered, fmt.Sprintf("this TaskAddr has already been used by other AVS,the TaskAddr is :%s", params.TaskAddr)) } // 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 - avs := avsInfo.Info if params.AvsName != "" { @@ -173,14 +167,14 @@ func (k Keeper) UpdateAVSInfo(ctx sdk.Context, params *types.AVSRegisterOrDeregi if params.MinStakeAmount > 0 { avs.MinStakeAmount = params.MinStakeAmount } - if params.TaskAddr != "" { - avs.TaskAddr = params.TaskAddr + if params.TaskAddr.String() != "" { + avs.TaskAddr = params.TaskAddr.String() } - if params.SlashContractAddr != "" { - avs.SlashAddr = params.SlashContractAddr + if params.SlashContractAddr.String() != "" { + avs.SlashAddr = params.SlashContractAddr.String() } - if params.RewardContractAddr != "" { - avs.RewardAddr = params.RewardContractAddr + if params.RewardContractAddr.String() != "" { + avs.RewardAddr = params.RewardContractAddr.String() } if params.AvsOwnerAddress != nil { avs.AvsOwnerAddress = params.AvsOwnerAddress @@ -216,7 +210,7 @@ func (k Keeper) UpdateAVSInfo(ctx sdk.Context, params *types.AVSRegisterOrDeregi // #nosec G115 avs.AvsReward = sdk.NewDecWithPrec(int64(params.AvsReward), 2) } - avs.AvsAddress = params.AvsAddress + avs.AvsAddress = params.AvsAddress.String() avs.StartingEpoch = uint64(epoch.CurrentEpoch + 1) return k.SetAVSInfo(ctx, avs) @@ -226,12 +220,12 @@ func (k Keeper) UpdateAVSInfo(ctx sdk.Context, params *types.AVSRegisterOrDeregi } func (k Keeper) CreateAVSTask(ctx sdk.Context, params *types.TaskInfoParams) (uint64, error) { - avsInfo := k.GetAVSInfoByTaskAddress(ctx, params.TaskContractAddress) + avsInfo := k.GetAVSInfoByTaskAddress(ctx, params.TaskContractAddress.String()) if avsInfo.AvsAddress == "" { return types.InvalidTaskID, errorsmod.Wrap(types.ErrUnregisterNonExistent, fmt.Sprintf("the taskaddr is :%s", params.TaskContractAddress)) } // If avs CreateAVSTask check CallerAddress - if !slices.Contains(avsInfo.AvsOwnerAddress, params.CallerAddress) { + if !slices.Contains(avsInfo.AvsOwnerAddress, params.CallerAddress.String()) { return types.InvalidTaskID, errorsmod.Wrap(types.ErrCallerAddressUnauthorized, fmt.Sprintf("this caller not qualified to CreateAVSTask %s", params.CallerAddress)) } taskPowerTotal, err := k.operatorKeeper.GetAVSUSDValue(ctx, avsInfo.AvsAddress) @@ -247,18 +241,18 @@ func (k Keeper) CreateAVSTask(ctx sdk.Context, params *types.TaskInfoParams) (ui return types.InvalidTaskID, errorsmod.Wrap(types.ErrEpochNotFound, fmt.Sprintf("epoch info not found %s", avsInfo.EpochIdentifier)) } - if k.IsExistTask(ctx, strconv.FormatUint(params.TaskID, 10), params.TaskContractAddress) { + if k.IsExistTask(ctx, strconv.FormatUint(params.TaskID, 10), params.TaskContractAddress.String()) { return types.InvalidTaskID, errorsmod.Wrap(types.ErrAlreadyExists, fmt.Sprintf("the task is :%s", strconv.FormatUint(params.TaskID, 10))) } operatorList, err := k.operatorKeeper.GetOptedInOperatorListByAVS(ctx, avsInfo.AvsAddress) if err != nil { return 0, errorsmod.Wrap(err, "CreateAVSTask: failed to get opt-in operators") } - params.TaskID = k.GetTaskID(ctx, common.HexToAddress(params.TaskContractAddress)) + params.TaskID = k.GetTaskID(ctx, common.HexToAddress(params.TaskContractAddress.String())) task := &types.TaskInfo{ Name: params.TaskName, Hash: params.Hash, - TaskContractAddress: params.TaskContractAddress, + TaskContractAddress: params.TaskContractAddress.String(), TaskId: params.TaskID, TaskChallengePeriod: params.TaskChallengePeriod, ThresholdPercentage: params.ThresholdPercentage, @@ -281,29 +275,24 @@ func (k Keeper) RegisterBLSPublicKey(ctx sdk.Context, params *types.BlsParams) e return errorsmod.Wrap(types.ErrSigNotMatchPubKey, fmt.Sprintf("the operator is :%s", params.Operator)) } - if k.IsExistPubKey(ctx, params.Operator) { + if k.IsExistPubKey(ctx, params.Operator.String()) { return errorsmod.Wrap(types.ErrAlreadyExists, fmt.Sprintf("the operator is :%s", params.Operator)) } bls := &types.BlsPubKeyInfo{ Name: params.Name, - Operator: params.Operator, + Operator: params.Operator.String(), PubKey: params.PubKey, } return k.SetOperatorPubKey(ctx, bls) } func (k Keeper) OperatorOptAction(ctx sdk.Context, params *types.OperatorOptParams) error { - operatorAddress := params.OperatorAddress - opAccAddr, err := sdk.AccAddressFromBech32(operatorAddress) - if err != nil { - return errorsmod.Wrap(err, fmt.Sprintf("error occurred when parse acc address from Bech32,the addr is:%s", operatorAddress)) - } - + opAccAddr := params.OperatorAddress if !k.operatorKeeper.IsOperator(ctx, opAccAddr) { - return errorsmod.Wrap(delegationtypes.ErrOperatorNotExist, fmt.Sprintf("UpdateAVSInfo: invalid operator address:%s", operatorAddress)) + return errorsmod.Wrap(delegationtypes.ErrOperatorNotExist, fmt.Sprintf("UpdateAVSInfo: invalid operator address:%s", opAccAddr.String())) } - f, err := k.IsAVS(ctx, params.AvsAddress) + f, err := k.IsAVS(ctx, params.AvsAddress.String()) if err != nil { return errorsmod.Wrap(err, fmt.Sprintf("error occurred when get avs info,this avs address: %s", params.AvsAddress)) } @@ -313,9 +302,9 @@ func (k Keeper) OperatorOptAction(ctx sdk.Context, params *types.OperatorOptPara switch params.Action { case types.RegisterAction: - return k.operatorKeeper.OptIn(ctx, opAccAddr, params.AvsAddress) + return k.operatorKeeper.OptIn(ctx, opAccAddr, params.AvsAddress.String()) case types.DeRegisterAction: - return k.operatorKeeper.OptOut(ctx, opAccAddr, params.AvsAddress) + return k.operatorKeeper.OptOut(ctx, opAccAddr, params.AvsAddress.String()) default: return errorsmod.Wrap(types.ErrInvalidAction, fmt.Sprintf("Invalid action: %d", params.Action)) } @@ -444,6 +433,6 @@ func (k Keeper) RaiseAndResolveChallenge(ctx sdk.Context, params *types.Challeng fmt.Sprintf("SetTaskResultInfo:submit too late, CurrentEpoch:%d", epoch.CurrentEpoch), ) } - return k.SetTaskChallengedInfo(ctx, params.TaskID, params.OperatorAddress.String(), params.CallerAddress, + return k.SetTaskChallengedInfo(ctx, params.TaskID, params.OperatorAddress.String(), params.CallerAddress.String(), params.TaskContractAddress) } diff --git a/x/avs/keeper/multi_operator_submit_task_test.go b/x/avs/keeper/multi_operator_submit_task_test.go index 7320ea4b7..e11bbbda7 100644 --- a/x/avs/keeper/multi_operator_submit_task_test.go +++ b/x/avs/keeper/multi_operator_submit_task_test.go @@ -87,11 +87,11 @@ func (suite *AVSTestSuite) prepareMulAvs(assetIDs []string) { AvsName: "avs01", Action: avstypes.RegisterAction, EpochIdentifier: epochstypes.HourEpochID, - AvsAddress: suite.avsAddr, + AvsAddress: common.HexToAddress(suite.avsAddr), AssetID: assetIDs, - TaskAddr: suite.taskAddress.String(), - SlashContractAddr: "", - RewardContractAddr: "", + TaskAddr: suite.taskAddress, + SlashContractAddr: common.Address{}, + RewardContractAddr: common.Address{}, MinSelfDelegation: 0, AvsOwnerAddress: nil, UnbondingPeriod: 7, diff --git a/x/avs/keeper/submit_task_test.go b/x/avs/keeper/submit_task_test.go index d9d0867dd..aea3bd56a 100644 --- a/x/avs/keeper/submit_task_test.go +++ b/x/avs/keeper/submit_task_test.go @@ -80,11 +80,11 @@ func (suite *AVSTestSuite) prepareAvs(assetIDs []string) { AvsName: "avs01", Action: avstypes.RegisterAction, EpochIdentifier: epochstypes.HourEpochID, - AvsAddress: suite.avsAddr, + AvsAddress: common.HexToAddress(suite.avsAddr), AssetID: assetIDs, - TaskAddr: suite.taskAddress.String(), - SlashContractAddr: "", - RewardContractAddr: "", + TaskAddr: suite.taskAddress, + SlashContractAddr: common.Address{}, + RewardContractAddr: common.Address{}, MinSelfDelegation: 3, AvsOwnerAddress: nil, UnbondingPeriod: 7, @@ -142,7 +142,7 @@ func (suite *AVSTestSuite) prepareTaskInfo() { err = suite.App.AVSManagerKeeper.SetTaskInfo(suite.Ctx, info) suite.NoError(err) - getTaskInfo, err := suite.App.AVSManagerKeeper.GetTaskInfo(suite.Ctx, strconv.FormatUint(suite.taskId, 10), common.Address(suite.taskAddress.Bytes()).String()) + getTaskInfo, err := suite.App.AVSManagerKeeper.GetTaskInfo(suite.Ctx, strconv.Itoa(int(suite.taskId)), common.Address(suite.taskAddress.Bytes()).String()) suite.NoError(err) suite.Equal(*info, *getTaskInfo) } diff --git a/x/avs/keeper/task.go b/x/avs/keeper/task.go index 4d3c29bd4..349f6fd1b 100644 --- a/x/avs/keeper/task.go +++ b/x/avs/keeper/task.go @@ -172,9 +172,9 @@ func (k *Keeper) SetTaskResultInfo( } // check prescribed period - // If submitted in the first stage, in order to avoid plagiarism by other operators, + // If submitted in the first phase, in order to avoid plagiarism by other operators, // TaskResponse and TaskResponseHash must be null values - // At the same time, it must be submitted within the response deadline in the first stage + // At the same time, it must be submitted within the response deadline in the first phase avsInfo := k.GetAVSInfoByTaskAddress(ctx, info.TaskContractAddress) epoch, found := k.epochsKeeper.GetEpochInfo(ctx, avsInfo.EpochIdentifier) if !found { @@ -206,7 +206,7 @@ func (k *Keeper) SetTaskResultInfo( info.TaskResponseHash, info.TaskResponse), ) } - // check epoch,The first stage submission must be within the response window period + // check epoch,The first phase submission must be within the response window period // #nosec G115 if epoch.CurrentEpoch > int64(task.StartingEpoch)+int64(task.TaskResponsePeriod) { return errorsmod.Wrap( @@ -240,7 +240,7 @@ func (k *Keeper) SetTaskResultInfo( info.OperatorAddress, info.TaskContractAddress, info.TaskId, info.BlsSignature), ) } - // check epoch,The second stage submission must be within the statistical window period + // check epoch,The second phase submission must be within the statistical window period // #nosec G115 if epoch.CurrentEpoch <= int64(task.StartingEpoch)+int64(task.TaskResponsePeriod) { return errorsmod.Wrap( diff --git a/x/avs/types/errors.go b/x/avs/types/errors.go index cea46359b..3db686b13 100644 --- a/x/avs/types/errors.go +++ b/x/avs/types/errors.go @@ -81,7 +81,7 @@ var ( ErrParamNotEmptyError = errorsmod.Register( ModuleName, 19, - "In the first stage, the parameter must be empty.", + "In the first phase, the parameter must be empty.", ) ErrSubmitTooLateError = errorsmod.Register( ModuleName, 20, diff --git a/x/avs/types/types.go b/x/avs/types/types.go index 175b714d1..905a1988f 100644 --- a/x/avs/types/types.go +++ b/x/avs/types/types.go @@ -8,6 +8,8 @@ import ( "sort" "strings" + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/ethereum/go-ethereum/accounts/abi" ibcclienttypes "github.com/cosmos/ibc-go/v7/modules/core/02-client/types" @@ -52,15 +54,15 @@ type AVSRegisterOrDeregisterParams struct { // AvsName is the name of the AVS as an arbitrary string. AvsName string // AvsAddress is the hex address of the AVS. - AvsAddress string + AvsAddress common.Address // MinStakeAmount is the minimum amount of stake for a task to be considered valid. MinStakeAmount uint64 // TaskAddr is the hex address of the task contract. - TaskAddr string + TaskAddr common.Address // SlashContractAddr is the hex address of the slash contract. - SlashContractAddr string + SlashContractAddr common.Address // RewardContractAddr is the hex address of the reward contract. - RewardContractAddr string + RewardContractAddr common.Address // AvsOwnerAddress is the list of bech32 addresses of the AVS owners. AvsOwnerAddress []string // AssetID is the list of asset IDs that the AVS is allowed to use. @@ -71,12 +73,11 @@ type AVSRegisterOrDeregisterParams struct { EpochIdentifier string MinOptInOperators uint64 MinTotalStakeAmount uint64 - // CallerAddress is the bech32 address of the precompile caller. - CallerAddress string - ChainID string - AvsReward uint64 - AvsSlash uint64 - Action uint64 + CallerAddress sdk.AccAddress + ChainID string + AvsReward uint64 + AvsSlash uint64 + Action uint64 } var ( diff --git a/x/avs/types/utils.go b/x/avs/types/utils.go index e0ea1bac2..0ea705155 100644 --- a/x/avs/types/utils.go +++ b/x/avs/types/utils.go @@ -14,39 +14,39 @@ const ( ) type OperatorOptParams struct { - Name string `json:"name"` - BlsPublicKey string `json:"bls_public_key"` - IsRegistered bool `json:"is_registered"` - Action uint64 `json:"action"` - OperatorAddress string `json:"operator_address"` - Status string `json:"status"` - AvsAddress string `json:"avs_address"` + Name string `json:"name"` + BlsPublicKey string `json:"bls_public_key"` + IsRegistered bool `json:"is_registered"` + Action uint64 `json:"action"` + OperatorAddress sdk.AccAddress `json:"operator_address"` + Status string `json:"status"` + AvsAddress common.Address `json:"avs_address"` } type TaskInfoParams struct { - TaskContractAddress string `json:"task_contract_address"` - TaskName string `json:"name"` - Hash []byte `json:"hash"` - TaskID uint64 `json:"task_id"` - TaskResponsePeriod uint64 `json:"task_response_period"` - TaskStatisticalPeriod uint64 `json:"task_statistical_period"` - TaskChallengePeriod uint64 `json:"task_challenge_period"` - ThresholdPercentage uint64 `json:"threshold_percentage"` - StartingEpoch uint64 `json:"starting_epoch"` - OperatorAddress string `json:"operator_address"` - TaskResponseHash string `json:"task_response_hash"` - TaskResponse []byte `json:"task_response"` - BlsSignature []byte `json:"bls_signature"` - Stage string `json:"stage"` - ActualThreshold uint64 `json:"actual_threshold"` - OptInCount uint64 `json:"opt_in_count"` - SignedCount uint64 `json:"signed_count"` - NoSignedCount uint64 `json:"no_signed_count"` - ErrSignedCount uint64 `json:"err_signed_count"` - CallerAddress string `json:"caller_address"` + TaskContractAddress common.Address `json:"task_contract_address"` + TaskName string `json:"name"` + Hash []byte `json:"hash"` + TaskID uint64 `json:"task_id"` + TaskResponsePeriod uint64 `json:"task_response_period"` + TaskStatisticalPeriod uint64 `json:"task_statistical_period"` + TaskChallengePeriod uint64 `json:"task_challenge_period"` + ThresholdPercentage uint64 `json:"threshold_percentage"` + StartingEpoch uint64 `json:"starting_epoch"` + OperatorAddress sdk.AccAddress `json:"operator_address"` + TaskResponseHash string `json:"task_response_hash"` + TaskResponse []byte `json:"task_response"` + BlsSignature []byte `json:"bls_signature"` + Phase string `json:"phase"` + ActualThreshold uint64 `json:"actual_threshold"` + OptInCount uint64 `json:"opt_in_count"` + SignedCount uint64 `json:"signed_count"` + NoSignedCount uint64 `json:"no_signed_count"` + ErrSignedCount uint64 `json:"err_signed_count"` + CallerAddress sdk.AccAddress `json:"caller_address"` } type BlsParams struct { - Operator string + Operator sdk.AccAddress Name string PubKey []byte PubkeyRegistrationSignature []byte @@ -55,14 +55,14 @@ type BlsParams struct { type ProofParams struct { TaskID string - TaskContractAddress string - AvsAddress string + TaskContractAddress common.Address + AvsAddress common.Address Aggregator string OperatorStatus []OperatorStatusParams - CallerAddress string + CallerAddress sdk.AccAddress } type OperatorStatusParams struct { - OperatorAddress string + OperatorAddress sdk.AccAddress Status string ProofData string } @@ -79,23 +79,16 @@ type ChallengeParams struct { TaskID uint64 `json:"task_id"` OperatorAddress sdk.AccAddress `json:"operator_address"` TaskResponseHash []byte `json:"task_response_hash"` - CallerAddress string `json:"caller_address"` + CallerAddress sdk.AccAddress `json:"caller_address"` } type TaskResultParams struct { - OperatorAddress string `json:"operator_address"` + OperatorAddress sdk.AccAddress `json:"operator_address"` TaskResponseHash string `json:"task_response_hash"` TaskResponse []byte `json:"task_response"` BlsSignature []byte `json:"bls_signature"` TaskContractAddress common.Address `json:"task_contract_address"` TaskID uint64 `json:"task_id"` Phase uint8 `json:"phase"` - CallerAddress string `json:"caller_address"` -} - -type OperatorParams struct { - EarningsAddr string `json:"earnings_addr"` - ApproveAddr string `json:"approve_addr"` - OperatorMetaInfo string `json:"operator_meta_info"` - CallerAddress sdk.AccAddress `json:"caller_address"` + CallerAddress sdk.AccAddress `json:"caller_address"` } diff --git a/x/dogfood/keeper/msg_server.go b/x/dogfood/keeper/msg_server.go index 88ee914d2..32e03755d 100644 --- a/x/dogfood/keeper/msg_server.go +++ b/x/dogfood/keeper/msg_server.go @@ -4,6 +4,8 @@ import ( "context" "strings" + "github.com/ethereum/go-ethereum/common" + "cosmossdk.io/errors" "github.com/ExocoreNetwork/exocore/utils" avstypes "github.com/ExocoreNetwork/exocore/x/avs/types" @@ -120,7 +122,7 @@ func (k Keeper) UpdateParams( } err := k.avsKeeper.UpdateAVSInfo(c, &avstypes.AVSRegisterOrDeregisterParams{ AvsName: c.ChainID(), - AvsAddress: avsAddr, + AvsAddress: common.HexToAddress(avsAddr), AssetID: nextParams.AssetIDs, UnbondingPeriod: uint64(nextParams.EpochsUntilUnbonded), MinSelfDelegation: nextParams.MinSelfDelegation.Uint64(), diff --git a/x/operator/keeper/opt_test.go b/x/operator/keeper/opt_test.go index 1662c20ca..56e54a175 100644 --- a/x/operator/keeper/opt_test.go +++ b/x/operator/keeper/opt_test.go @@ -95,7 +95,7 @@ func (suite *OperatorTestSuite) prepareAvs(assetIDs []string) { err := suite.App.AVSManagerKeeper.UpdateAVSInfo(suite.Ctx, &avstypes.AVSRegisterOrDeregisterParams{ Action: avstypes.RegisterAction, EpochIdentifier: epochstypes.HourEpochID, - AvsAddress: suite.avsAddr, + AvsAddress: common.HexToAddress(suite.avsAddr), AssetID: assetIDs, }) suite.NoError(err)