Skip to content

Commit

Permalink
remove submit task param response-hash
Browse files Browse the repository at this point in the history
  • Loading branch information
trestinlsd committed Sep 24, 2024
1 parent fce652f commit 3bf9e3f
Show file tree
Hide file tree
Showing 8 changed files with 34 additions and 35 deletions.
2 changes: 1 addition & 1 deletion precompiles/avs/IAVSManager.sol
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ interface IAVSManager {
) external view returns (uint256 amount);

event TaskCreated(
uint64 indexed taskId,
uint64 taskId,
string taskContractAddress,
string name,
bytes hash,
Expand Down
2 changes: 1 addition & 1 deletion precompiles/avs/abi.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"anonymous": false,
"inputs": [
{
"indexed": true,
"indexed": false,
"internalType": "uint64",
"name": "taskId",
"type": "uint64"
Expand Down
16 changes: 3 additions & 13 deletions precompiles/avs/events.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (
"github.com/ethereum/go-ethereum/common"
ethtypes "github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/core/vm"
cmn "github.com/evmos/evmos/v14/precompiles/common"
)

const (
Expand All @@ -19,25 +18,16 @@ func (p Precompile) EmitCreateAVSTaskEvent(ctx sdk.Context, stateDB vm.StateDB,
// Prepare the event topics
event := p.ABI.Events[EventTypeRegisterAVSTask]

topics := make([]common.Hash, 3)
topics := make([]common.Hash, 1)

// The first topic is always the signature of the event.
topics[0] = event.ID

var err error
topics[1], err = cmn.MakeTopic(common.HexToAddress(task.TaskContractAddress))
if err != nil {
return err
}

topics[2], err = cmn.MakeTopic(task.TaskID)
if err != nil {
return err
}

// Pack the arguments to be used as the Data field
arguments := event.Inputs[1:8]
packed, err := arguments.Pack(task.TaskContractAddress, task.TaskName, task.Hash, task.TaskResponsePeriod, task.TaskChallengePeriod, task.ThresholdPercentage, task.TaskStatisticalPeriod)
arguments := event.Inputs[0:8]
packed, err := arguments.Pack(task.TaskID, task.TaskContractAddress, task.TaskName, task.Hash, task.TaskResponsePeriod, task.TaskChallengePeriod, task.ThresholdPercentage, task.TaskStatisticalPeriod)
if err != nil {
return err
}
Expand Down
1 change: 1 addition & 0 deletions precompiles/avs/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package avs

import (
"fmt"

exocmn "github.com/ExocoreNetwork/exocore/precompiles/common"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/ethereum/go-ethereum/accounts/abi"
Expand Down
7 changes: 0 additions & 7 deletions x/avs/client/cli/tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import (

const (
FlagOperatorAddress = "operator-address"
FlagTaskResponseHash = "task-response-hash"
FlagTaskResponse = "task-response"
FlagBlsSignature = "bls-signature"
FlagTaskContractAddress = "task-contract-address"
Expand Down Expand Up @@ -67,9 +66,6 @@ func CmdSubmitTaskResult() *cobra.Command {
FlagOperatorAddress, "", "The address of the operator being queried "+
" If not provided, it will default to the sender's address.",
)
f.String(
FlagTaskResponseHash, "", "The task response msg hash",
)
f.String(
FlagTaskResponse, "", "The task response data",
)
Expand Down Expand Up @@ -105,8 +101,6 @@ func newBuildMsg(
if operatorAddress == "" {
operatorAddress = sender.String()
}
taskResponseHash, _ := fs.GetString(FlagTaskResponseHash)

taskResponse, _ := fs.GetString(FlagTaskResponse)
taskRes, _ := hex.DecodeString(taskResponse)
blsSignature, _ := fs.GetString(FlagBlsSignature)
Expand All @@ -120,7 +114,6 @@ func newBuildMsg(
FromAddress: sender.String(),
Info: &types.TaskResultInfo{
OperatorAddress: operatorAddress,
TaskResponseHash: taskResponseHash,
TaskResponse: taskRes,
BlsSignature: sig,
TaskContractAddress: taskContractAddress,
Expand Down
9 changes: 4 additions & 5 deletions x/avs/keeper/bls_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,11 @@ func (suite *AVSTestSuite) TestOperator_pubkey() {
suite.NoError(err)
suite.Equal(publicKey.Marshal(), pub.PubKey)

taskRes := types.TaskResponse{TaskID: 17, NumberSum: big.NewInt(1000)}
taskRes := types.TaskResponse{TaskID: 1, NumberSum: big.NewInt(1000)}

hashAbi, _ := types.GetTaskResponseDigestEncodeByAbi(taskRes)
hash, _ := types.GetTaskResponseDigestEncodeByjson(taskRes)

msgBytes := hashAbi[:]
msgBytes := hash[:]
fmt.Println("ResHash:", hex.EncodeToString(msgBytes))

sig := privateKey.Sign(msgBytes)
Expand All @@ -43,14 +43,13 @@ func (suite *AVSTestSuite) TestOperator_pubkey() {
valid := sig.Verify(publicKey, msgBytes)
suite.True(valid)

valid1, _ := blst.VerifySignature(sig.Marshal(), hashAbi, publicKey)
valid1, _ := blst.VerifySignature(sig.Marshal(), hash, publicKey)
suite.NoError(err)

suite.True(valid1)

jsonData, err := types.MarshalTaskResponse(taskRes)
fmt.Println("jsondata:", hex.EncodeToString(jsonData))

}

func (suite *AVSTestSuite) Test_hash() {
Expand Down
16 changes: 13 additions & 3 deletions x/avs/keeper/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,12 @@ package keeper
import (
"encoding/hex"
"fmt"
"github.com/prysmaticlabs/prysm/v4/crypto/bls"
"github.com/prysmaticlabs/prysm/v4/crypto/bls/blst"
"slices"
"strconv"

"github.com/prysmaticlabs/prysm/v4/crypto/bls"
"github.com/prysmaticlabs/prysm/v4/crypto/bls/blst"

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

errorsmod "cosmossdk.io/errors"
Expand Down Expand Up @@ -378,7 +379,16 @@ func (k Keeper) RaiseAndResolveChallenge(ctx sdk.Context, params *ChallengeParam
// check Task result
res, err := k.GetTaskResultInfo(ctx, params.OperatorAddress.String(), params.TaskContractAddress.String(),
params.TaskID)
if err != nil || res.TaskId != params.TaskID || res.TaskResponseHash != hex.EncodeToString(params.TaskResponseHash) {
if err != nil {
return fmt.Errorf("task result does not exist, this task address: %s", params.TaskContractAddress)
}
taskRes, err := types.UnmarshalTaskResponse(res.TaskResponse)
if err != nil {
return errorsmod.Wrap(err, fmt.Sprintf("error occurred when unmarshal task response, this task address: %s", params.TaskContractAddress))
}
hash, err := types.GetTaskResponseDigestEncodeByAbi(taskRes)

if err != nil || res.TaskId != params.TaskID || hex.EncodeToString(hash[:]) != 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 Down
16 changes: 11 additions & 5 deletions x/avs/keeper/task.go
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,13 @@ func (k *Keeper) SetTaskResultInfo(
)
}
// check operator bls pubkey
keyInfo, _ := k.GetOperatorPubKey(ctx, info.OperatorAddress)
keyInfo, err := k.GetOperatorPubKey(ctx, info.OperatorAddress)
if err != nil || keyInfo.PubKey == nil {
return errorsmod.Wrap(
types.ErrPubKeyIsNotExists,
fmt.Sprintf("SetTaskResultInfo:get operator address:%s", opAccAddr),
)
}
pubKey, err := blst.PublicKeyFromBytes(keyInfo.PubKey)
if err != nil || pubKey == nil {
return errorsmod.Wrap(
Expand Down Expand Up @@ -217,11 +223,11 @@ func (k *Keeper) SetTaskResultInfo(

case types.TwoPhaseCommitTwo:
// check task response
if info.TaskResponseHash == "" || info.TaskResponse == nil {
if info.TaskResponse == nil {
return errorsmod.Wrap(
types.ErrNotNull,
fmt.Sprintf("SetTaskResultInfo: invalid param TaskResponseHash: %s (TaskResponse: %d)",
info.TaskResponseHash, info.TaskResponse),
fmt.Sprintf("SetTaskResultInfo: invalid param (TaskResponse: %d)",
info.TaskResponse),
)
}
// check parameters
Expand Down Expand Up @@ -251,7 +257,7 @@ func (k *Keeper) SetTaskResultInfo(

// calculate hash by original task
taskResponseDigest := crypto.Keccak256Hash(info.TaskResponse)

info.TaskResponseHash = taskResponseDigest.String()
// check taskID
resp, err := types.UnmarshalTaskResponse(info.TaskResponse)
if err != nil || info.TaskId != resp.TaskID {
Expand Down

0 comments on commit 3bf9e3f

Please sign in to comment.