From fce652f9fb2ca4b7cbc96f4de1d205ee6f3e39d0 Mon Sep 17 00:00:00 2001 From: trestin Date: Mon, 23 Sep 2024 17:24:06 +0800 Subject: [PATCH] fix some issuses --- precompiles/avs/IAVSManager.sol | 130 +------------- precompiles/avs/abi.json | 295 +------------------------------- precompiles/avs/events.go | 6 +- x/avs/keeper/task.go | 29 ++-- 4 files changed, 23 insertions(+), 437 deletions(-) diff --git a/precompiles/avs/IAVSManager.sol b/precompiles/avs/IAVSManager.sol index 839ab0df0..7e9204463 100644 --- a/precompiles/avs/IAVSManager.sol +++ b/precompiles/avs/IAVSManager.sol @@ -185,118 +185,9 @@ interface IAVSManager { string memory operatorAddr ) external view returns (uint256 amount); - /// @dev RegisterBLSPublicKey Emitted when `operator` registers with the public keys `pubKey`. - /// @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, - bytes pubkeyRegistrationSignature, - bytes pubkeyRegistrationMessageHash - ); - - /// @dev RegisterAVS Emitted when `avs` register to exocore. - /// @dev Register AVS contract to EXO. - /// @param avsAddress The address of AVS. - /// @param avsName The name of AVS. - /// @param minStakeAmount The minimum amount of funds staked by each operator. - /// @param taskAddr The task address of AVS. - /// @param slashAddr The slash address of AVS. - /// @param rewardAddr The reward address of AVS. - /// @param avsOwnerAddress The owners who have permission for AVS. - /// @param assetIds The basic asset information of AVS. - /// @param avsUnbondingPeriod The unbonding duration of AVS. - /// @param minSelfDelegation The minimum delegation amount for an operator. - /// @param epochIdentifier The AVS epoch identifier. - /// @param params 1.miniOptInOperators The minimum number of opt-in operators. - ///2.minTotalStakeAmount The minimum total amount of stake by all operators. - ///3.avsReward The proportion of reward for AVS. - ///4.avsSlash The proportion of slash for AVS. - event RegisterAVS( - string indexed avsAddress, - string avsName, - uint64 minStakeAmount, - address taskAddr, - address slashAddr, - address rewardAddr, - address[] avsOwnerAddress, - string[] assetIds, - uint64 avsUnbondingPeriod, - uint64 minSelfDelegation, - string epochIdentifier, - uint64[] params - ); - - /// @dev UpdateAVS Emitted when `avs` update to exocore. - /// @param avsAddress The address of AVS. - /// @param avsName The name of AVS. - /// @param minStakeAmount The minimum amount of funds staked by each operator. - /// @param taskAddr The task address of AVS. - /// @param slashAddr The slash address of AVS. - /// @param rewardAddr The reward address of AVS. - /// @param avsOwnerAddress The owners who have permission for AVS. - /// @param assetIds The basic asset information of AVS. - /// @param avsUnbondingPeriod The unbonding duration of AVS. - /// @param minSelfDelegation The minimum delegation amount for an operator. - /// @param epochIdentifier The AVS epoch identifier. - /// @param params 1.miniOptInOperators The minimum number of opt-in operators. - ///2.minTotalStakeAmount The minimum total amount of stake by all operators. - ///3.avsReward The proportion of reward for AVS. - ///4.avsSlash The proportion of slash for AVS. - event UpdateAVS( - string indexed avsAddress, - string avsName, - uint64 minStakeAmount, - address taskAddr, - address slashAddr, - address rewardAddr, - address[] avsOwnerAddress, - string[] assetIds, - uint64 avsUnbondingPeriod, - uint64 minSelfDelegation, - string epochIdentifier, - uint64[] params - ); - - /// @dev DeregisterAVS Emitted when `avs` Deregister to exocore. - /// @param avsAddress The address of AVS. - /// @param avsName The name of AVS. - event DeregisterAVS( - string indexed avsAddress, - string avsName - ); - - /// @dev RegisterOperatorToAVS Emitted when `operator` opt-in to avs. - /// @param operator address. - /// @param avsAddress The address of AVS. - event RegisterOperatorToAVS( - string indexed operator, - string indexed avsAddress - ); - - /// @dev DeregisterOperatorFromAVS Emitted when `operator` opt-out to avs. - /// @param operator address. - /// @param avsAddress The address of AVS. - event DeregisterOperatorFromAVS( - string indexed operator, - string indexed avsAddress - ); - - /// @dev CreateTask Emitted when `avs` CreateTask. - /// @param taskContractAddress The contract address of AVSTask. - /// @param taskId The task ID of the task. - /// @param name The name of the task. - /// @param hash The data supplied by the contract, usually ABI-encoded. - /// @param taskResponsePeriod The deadline for task response. - /// @param taskChallengePeriod The challenge period for the task. - /// @param thresholdPercentage The signature threshold percentage. - /// @param taskStatisticalPeriod The statistical period for the task. - - event CreateTask( - string indexed taskContractAddress, - string indexed taskId, + event TaskCreated( + uint64 indexed taskId, + string taskContractAddress, string name, bytes hash, uint64 taskResponsePeriod, @@ -304,17 +195,4 @@ interface IAVSManager { uint64 thresholdPercentage, uint64 taskStatisticalPeriod ); - /// @dev SubmitProof Emitted when task contract submit proof. - /// @param taskContractAddress The contract address of AVSTask. - /// @param taskId The task ID of the task. - /// @param aggregator The aggregator address. - /// @param avsAddress The address of AVS. - /// @param operatorStatuses The status and proof of operators. - event SubmitProof( - string indexed taskContractAddress, - string indexed taskId, - string aggregator, - string avsAddress, - bytes operatorStatuses - ); -} + } diff --git a/precompiles/avs/abi.json b/precompiles/avs/abi.json index da2a860a6..414a6f262 100644 --- a/precompiles/avs/abi.json +++ b/precompiles/avs/abi.json @@ -4,14 +4,14 @@ "inputs": [ { "indexed": true, - "internalType": "string", - "name": "taskContractAddress", - "type": "string" + "internalType": "uint64", + "name": "taskId", + "type": "uint64" }, { - "indexed": true, + "indexed": false, "internalType": "string", - "name": "taskId", + "name": "taskContractAddress", "type": "string" }, { @@ -51,290 +51,7 @@ "type": "uint64" } ], - "name": "CreateTask", - "type": "event" - }, - { - "anonymous": false, - "inputs": [ - { - "indexed": true, - "internalType": "string", - "name": "avsAddress", - "type": "string" - }, - { - "indexed": false, - "internalType": "string", - "name": "avsName", - "type": "string" - } - ], - "name": "DeregisterAVS", - "type": "event" - }, - { - "anonymous": false, - "inputs": [ - { - "indexed": true, - "internalType": "string", - "name": "operator", - "type": "string" - }, - { - "indexed": true, - "internalType": "string", - "name": "avsAddress", - "type": "string" - } - ], - "name": "DeregisterOperatorFromAVS", - "type": "event" - }, - { - "anonymous": false, - "inputs": [ - { - "indexed": true, - "internalType": "string", - "name": "avsAddress", - "type": "string" - }, - { - "indexed": false, - "internalType": "string", - "name": "avsName", - "type": "string" - }, - { - "indexed": false, - "internalType": "uint64", - "name": "minStakeAmount", - "type": "uint64" - }, - { - "indexed": false, - "internalType": "address", - "name": "taskAddr", - "type": "address" - }, - { - "indexed": false, - "internalType": "address", - "name": "slashAddr", - "type": "address" - }, - { - "indexed": false, - "internalType": "address", - "name": "rewardAddr", - "type": "address" - }, - { - "indexed": false, - "internalType": "address[]", - "name": "avsOwnerAddress", - "type": "address[]" - }, - { - "indexed": false, - "internalType": "string[]", - "name": "assetIds", - "type": "string[]" - }, - { - "indexed": false, - "internalType": "uint64", - "name": "avsUnbondingPeriod", - "type": "uint64" - }, - { - "indexed": false, - "internalType": "uint64", - "name": "minSelfDelegation", - "type": "uint64" - }, - { - "indexed": false, - "internalType": "string", - "name": "epochIdentifier", - "type": "string" - }, - { - "indexed": false, - "internalType": "uint64[]", - "name": "params", - "type": "uint64[]" - } - ], - "name": "RegisterAVS", - "type": "event" - }, - { - "anonymous": false, - "inputs": [ - { - "indexed": false, - "internalType": "string", - "name": "name", - "type": "string" - }, - { - "indexed": false, - "internalType": "bytes", - "name": "pubKey", - "type": "bytes" - }, - { - "indexed": false, - "internalType": "bytes", - "name": "pubkeyRegistrationSignature", - "type": "bytes" - }, - { - "indexed": false, - "internalType": "bytes", - "name": "pubkeyRegistrationMessageHash", - "type": "bytes" - } - ], - "name": "RegisterBLSPublicKey", - "type": "event" - }, - { - "anonymous": false, - "inputs": [ - { - "indexed": true, - "internalType": "string", - "name": "operator", - "type": "string" - }, - { - "indexed": true, - "internalType": "string", - "name": "avsAddress", - "type": "string" - } - ], - "name": "RegisterOperatorToAVS", - "type": "event" - }, - { - "anonymous": false, - "inputs": [ - { - "indexed": true, - "internalType": "string", - "name": "taskContractAddress", - "type": "string" - }, - { - "indexed": true, - "internalType": "string", - "name": "taskId", - "type": "string" - }, - { - "indexed": false, - "internalType": "string", - "name": "aggregator", - "type": "string" - }, - { - "indexed": false, - "internalType": "string", - "name": "avsAddress", - "type": "string" - }, - { - "indexed": false, - "internalType": "bytes", - "name": "operatorStatuses", - "type": "bytes" - } - ], - "name": "SubmitProof", - "type": "event" - }, - { - "anonymous": false, - "inputs": [ - { - "indexed": true, - "internalType": "string", - "name": "avsAddress", - "type": "string" - }, - { - "indexed": false, - "internalType": "string", - "name": "avsName", - "type": "string" - }, - { - "indexed": false, - "internalType": "uint64", - "name": "minStakeAmount", - "type": "uint64" - }, - { - "indexed": false, - "internalType": "address", - "name": "taskAddr", - "type": "address" - }, - { - "indexed": false, - "internalType": "address", - "name": "slashAddr", - "type": "address" - }, - { - "indexed": false, - "internalType": "address", - "name": "rewardAddr", - "type": "address" - }, - { - "indexed": false, - "internalType": "address[]", - "name": "avsOwnerAddress", - "type": "address[]" - }, - { - "indexed": false, - "internalType": "string[]", - "name": "assetIds", - "type": "string[]" - }, - { - "indexed": false, - "internalType": "uint64", - "name": "avsUnbondingPeriod", - "type": "uint64" - }, - { - "indexed": false, - "internalType": "uint64", - "name": "minSelfDelegation", - "type": "uint64" - }, - { - "indexed": false, - "internalType": "string", - "name": "epochIdentifier", - "type": "string" - }, - { - "indexed": false, - "internalType": "uint64[]", - "name": "params", - "type": "uint64[]" - } - ], - "name": "UpdateAVS", + "name": "TaskCreated", "type": "event" }, { diff --git a/precompiles/avs/events.go b/precompiles/avs/events.go index 793e29e28..b246631cd 100644 --- a/precompiles/avs/events.go +++ b/precompiles/avs/events.go @@ -11,7 +11,7 @@ import ( const ( // EventTypeRegisterAVSTask defines the event type for the avs CreateAVSTask transaction. - EventTypeRegisterAVSTask = "CreateTask" + EventTypeRegisterAVSTask = "TaskCreated" ) // EmitCreateAVSTaskEvent creates a new event emitted on a EmitCreateAVSTaskEvent transaction. @@ -36,8 +36,8 @@ func (p Precompile) EmitCreateAVSTaskEvent(ctx sdk.Context, stateDB vm.StateDB, } // Pack the arguments to be used as the Data field - arguments := event.Inputs[2:7] - packed, err := arguments.Pack(task.TaskName, task.Hash, task.TaskResponsePeriod, task.TaskChallengePeriod, task.ThresholdPercentage) + arguments := event.Inputs[1:8] + packed, err := arguments.Pack(task.TaskContractAddress, task.TaskName, task.Hash, task.TaskResponsePeriod, task.TaskChallengePeriod, task.ThresholdPercentage, task.TaskStatisticalPeriod) if err != nil { return err } diff --git a/x/avs/keeper/task.go b/x/avs/keeper/task.go index 9a99403e5..561ee3a23 100644 --- a/x/avs/keeper/task.go +++ b/x/avs/keeper/task.go @@ -249,26 +249,17 @@ func (k *Keeper) SetTaskResultInfo( ) } - // check hash + // calculate hash by original task taskResponseDigest := crypto.Keccak256Hash(info.TaskResponse) - // if info.TaskResponseHash != "" { - // hashWithoutPrefix := strings.TrimPrefix(taskResponseDigest.String(), "0x") - // if hashWithoutPrefix != info.TaskResponseHash { - // return errorsmod.Wrap( - // types.ErrHashValue, - // "SetTaskResultInfo: task response is nil", - // ) - // } - //} - - // TODO :check 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), - // ) - //} + + // check 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), + ) + } // check bls sig flag, err := blst.VerifySignature(info.BlsSignature, taskResponseDigest, pubKey) if !flag || err != nil {