diff --git a/proto/exocore/avs/v1/tx.proto b/proto/exocore/avs/v1/tx.proto index 9535cc59b..0859b72e7 100644 --- a/proto/exocore/avs/v1/tx.proto +++ b/proto/exocore/avs/v1/tx.proto @@ -86,7 +86,8 @@ message TaskInfo { uint64 task_id = 4; // Deadline for task response uint64 task_response_period = 5; - // Statistical period: threshold calculation, signature verification, nosig quantity statistics, operator submits messages corresponding to signatures + // Statistical period: threshold calculation, signature verification, + // nosig quantity statistics, operator submits messages corresponding to signatures uint64 task_statistical_period = 6; //challenge period for task uint64 task_challenge_period = 7; diff --git a/x/avs/keeper/epoch_test.go b/x/avs/keeper/epoch_test.go new file mode 100644 index 000000000..d782792f0 --- /dev/null +++ b/x/avs/keeper/epoch_test.go @@ -0,0 +1,47 @@ +package keeper_test + +import ( + "fmt" + avstypes "github.com/ExocoreNetwork/exocore/x/avs/types" + "github.com/ethereum/go-ethereum/crypto" + "math/big" +) + +func (suite *AVSTestSuite) TestSubmitTask1() { + suite.prepare() + taskRes := avstypes.TaskResponse{TaskID: 1, NumberSum: big.NewInt(100)} + jsonData, err := avstypes.MarshalTaskResponse(taskRes) + suite.NoError(err) + _ = crypto.Keccak256Hash(jsonData) + + // pub, err := suite.App.AVSManagerKeeper.GetOperatorPubKey(suite.Ctx, suite.operatorAddr.String()) + suite.NoError(err) + + msg, _ := avstypes.GetTaskResponseDigest(taskRes) + msgBytes := msg[:] + sig := suite.blsKey.Sign(msgBytes) + + info := &avstypes.TaskResultInfo{ + TaskContractAddress: suite.taskAddress.String(), + OperatorAddress: suite.operatorAddr.String(), + TaskId: suite.taskId, + TaskResponseHash: "", + TaskResponse: nil, + BlsSignature: sig.Marshal(), + Stage: avstypes.TwoPhaseCommitOne, + } + err = suite.App.AVSManagerKeeper.SetTaskResultInfo(suite.Ctx, suite.operatorAddr.String(), info) + suite.NoError(err) + +} + +func (suite *AVSTestSuite) TestAVSUSDValue1() { + suite.prepare() + avsUSDValue, err := suite.App.OperatorKeeper.GetAVSUSDValue(suite.Ctx, suite.avsAddr) + suite.NoError(err) + optedUSDValues, err := suite.App.OperatorKeeper.GetOperatorOptedUSDValue(suite.Ctx, suite.avsAddr, suite.operatorAddr.String()) + suite.NoError(err) + fmt.Println(avsUSDValue) + fmt.Println(optedUSDValues) + +} diff --git a/x/avs/keeper/keeper.go b/x/avs/keeper/keeper.go index 0cfa182d6..33cbde1a2 100644 --- a/x/avs/keeper/keeper.go +++ b/x/avs/keeper/keeper.go @@ -124,9 +124,9 @@ func (k Keeper) AVSInfoUpdate(ctx sdk.Context, params *types.AVSRegisterOrDeregi return errorsmod.Wrap(types.ErrUnregisterNonExistent, fmt.Sprintf("the avsaddress is :%s", params.AvsAddress)) } // If avs UpdateAction check UnbondingPeriod - 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 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)) diff --git a/x/avs/keeper/setup_test.go b/x/avs/keeper/setup_test.go index dea207e82..43304ddbd 100644 --- a/x/avs/keeper/setup_test.go +++ b/x/avs/keeper/setup_test.go @@ -4,6 +4,7 @@ import ( sdkmath "cosmossdk.io/math" blscommon "github.com/prysmaticlabs/prysm/v4/crypto/bls/common" "testing" + "time" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/ethereum/go-ethereum/common" @@ -40,6 +41,7 @@ type AVSTestSuite struct { taskAddress common.Address taskId uint64 blsKey blscommon.SecretKey + EpochDuration time.Duration } var s *AVSTestSuite @@ -57,5 +59,8 @@ func (suite *AVSTestSuite) SetupTest() { suite.DoSetupTest() suite.avsAddress = utiltx.GenerateAddress() suite.taskAddress = utiltx.GenerateAddress() + epochID := suite.App.StakingKeeper.GetEpochIdentifier(suite.Ctx) + epochInfo, _ := suite.App.EpochsKeeper.GetEpochInfo(suite.Ctx, epochID) + suite.EpochDuration = epochInfo.Duration + time.Nanosecond // extra buffer } diff --git a/x/avs/keeper/submit_task_test.go b/x/avs/keeper/submit_task_test.go index fbcd7c601..d7b122b64 100644 --- a/x/avs/keeper/submit_task_test.go +++ b/x/avs/keeper/submit_task_test.go @@ -157,7 +157,7 @@ func (suite *AVSTestSuite) prepare() { suite.CommitAfter(time.Hour*1 + time.Nanosecond) } -func (suite *AVSTestSuite) TestSubmitTask() { +func (suite *AVSTestSuite) TestSubmitTask_PhaseOne() { suite.prepare() taskRes := avstypes.TaskResponse{TaskID: 1, NumberSum: big.NewInt(100)} jsonData, err := avstypes.MarshalTaskResponse(taskRes) @@ -184,17 +184,37 @@ func (suite *AVSTestSuite) TestSubmitTask() { suite.NoError(err) } -func (suite *AVSTestSuite) TestOptInList() { - suite.prepare() - operatorList, err := suite.App.OperatorKeeper.GetOptedInOperatorListByAVS(suite.Ctx, suite.avsAddr) + +func (suite *AVSTestSuite) TestSubmitTask_PhaseTwo() { + suite.TestSubmitTask_PhaseOne() + suite.CommitAfter(suite.EpochDuration) + + taskRes := avstypes.TaskResponse{TaskID: 1, NumberSum: big.NewInt(100)} + jsonData, err := avstypes.MarshalTaskResponse(taskRes) suite.NoError(err) - suite.Contains(operatorList, suite.operatorAddr.String()) + hash := crypto.Keccak256Hash(jsonData) - avsList, err := suite.App.OperatorKeeper.GetOptedInAVSForOperator(suite.Ctx, suite.operatorAddr.String()) + // pub, err := suite.App.AVSManagerKeeper.GetOperatorPubKey(suite.Ctx, suite.operatorAddr.String()) + suite.NoError(err) + + msg, _ := avstypes.GetTaskResponseDigest(taskRes) + msgBytes := msg[:] + sig := suite.blsKey.Sign(msgBytes) + + info := &avstypes.TaskResultInfo{ + TaskContractAddress: suite.taskAddress.String(), + OperatorAddress: suite.operatorAddr.String(), + TaskId: suite.taskId, + TaskResponseHash: hash.String(), + TaskResponse: jsonData, + BlsSignature: sig.Marshal(), + Stage: avstypes.TwoPhaseCommitTwo, + } + err = suite.App.AVSManagerKeeper.SetTaskResultInfo(suite.Ctx, suite.operatorAddr.String(), info) suite.NoError(err) - suite.Contains(avsList, suite.avsAddr) } + func (suite *AVSTestSuite) TestAVSUSDValue() { suite.prepare() avsUSDValue, err := suite.App.OperatorKeeper.GetAVSUSDValue(suite.Ctx, suite.avsAddr) diff --git a/x/avs/keeper/task.go b/x/avs/keeper/task.go index 37a04a83c..8e4fc9c6f 100644 --- a/x/avs/keeper/task.go +++ b/x/avs/keeper/task.go @@ -2,7 +2,6 @@ package keeper import ( "bytes" - "encoding/hex" "fmt" "strconv" @@ -193,6 +192,7 @@ func (k *Keeper) SetTaskResultInfo( info.TaskResponseHash, info.TaskResponse), ) } + // check epoch,The first stage submission must be within the response window period if epoch.CurrentEpoch > int64(task.StartingEpoch)+int64(task.TaskResponsePeriod) { return errorsmod.Wrap( types.ErrSubmitTooLateError, @@ -227,9 +227,9 @@ 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 if epoch.CurrentEpoch <= int64(task.StartingEpoch)+int64(task.TaskResponsePeriod) || - epoch.CurrentEpoch >= int64(task.StartingEpoch)+int64(task.TaskResponsePeriod)+int64(task.TaskStatisticalPeriod) { + epoch.CurrentEpoch > int64(task.StartingEpoch)+int64(task.TaskResponsePeriod)+int64(task.TaskStatisticalPeriod) { return errorsmod.Wrap( types.ErrSubmitTooLateError, fmt.Sprintf("SetTaskResultInfo:submit too late, CurrentEpoch:%d", epoch.CurrentEpoch), @@ -238,7 +238,7 @@ func (k *Keeper) SetTaskResultInfo( // check hash taskResponseDigest := crypto.Keccak256Hash(info.TaskResponse) - if hex.EncodeToString(taskResponseDigest[:]) != info.TaskResponseHash { + if taskResponseDigest.String() != info.TaskResponseHash { return errorsmod.Wrap( types.ErrHashValue, "SetTaskResultInfo: task response is nil", diff --git a/x/avs/keeper/task_result_info_test.go b/x/avs/keeper/task_result_info_test.go deleted file mode 100644 index b55569d4a..000000000 --- a/x/avs/keeper/task_result_info_test.go +++ /dev/null @@ -1 +0,0 @@ -package keeper