Skip to content

Commit

Permalink
feat:Add implementation for task module
Browse files Browse the repository at this point in the history
  • Loading branch information
trestinlsd committed Apr 10, 2024
1 parent 3eb094d commit 85151f0
Show file tree
Hide file tree
Showing 37 changed files with 3,691 additions and 3 deletions.
12 changes: 12 additions & 0 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ import (
"context"
"encoding/json"
"fmt"
"github.com/ExocoreNetwork/exocore/x/avs_task"
taskKeeper "github.com/ExocoreNetwork/exocore/x/avs_task/keeper"
taskTypes "github.com/ExocoreNetwork/exocore/x/avs_task/types"
"io"
"net/http"
"os"
Expand Down Expand Up @@ -274,6 +277,7 @@ var (
reward.AppModuleBasic{},
exoslash.AppModuleBasic{},
avs.AppModuleBasic{},
avs_task.AppModuleBasic{},
)

// module account permissions
Expand Down Expand Up @@ -358,6 +362,7 @@ type ExocoreApp struct {
OperatorKeeper operatorKeeper.Keeper
ExoSlashKeeper slashKeeper.Keeper
AVSManagerKeeper avsManagerKeeper.Keeper
TaskKeeper taskKeeper.Keeper
// the module manager
mm *module.Manager

Expand Down Expand Up @@ -441,6 +446,7 @@ func NewExocoreApp(
exoslashTypes.StoreKey,
operatorTypes.StoreKey,
avsManagerTypes.StoreKey,
taskTypes.StoreKey,
)

// Add the EVM transient store key
Expand Down Expand Up @@ -658,6 +664,7 @@ func NewExocoreApp(
app.RewardKeeper = *rewardKeeper.NewKeeper(appCodec, keys[rewardTypes.StoreKey], app.AssetsKeeper)
app.ExoSlashKeeper = slashKeeper.NewKeeper(appCodec, keys[exoslashTypes.StoreKey], app.AssetsKeeper)
app.AVSManagerKeeper = *avsManagerKeeper.NewKeeper(appCodec, keys[avsManagerTypes.StoreKey], &app.OperatorKeeper, app.AssetsKeeper)
app.TaskKeeper = taskKeeper.NewKeeper(appCodec, keys[taskTypes.StoreKey], taskTypes.AvsKeeperMock{})
// We call this after setting the hooks to ensure that the hooks are set on the keeper
evmKeeper.WithPrecompiles(
evmkeeper.AvailablePrecompiles(
Expand All @@ -672,6 +679,7 @@ func NewExocoreApp(
app.ExoSlashKeeper,
app.RewardKeeper,
app.AVSManagerKeeper,
app.TaskKeeper,
),
)
epochsKeeper := epochskeeper.NewKeeper(appCodec, keys[epochstypes.StoreKey])
Expand Down Expand Up @@ -845,6 +853,7 @@ func NewExocoreApp(
reward.NewAppModule(appCodec, app.RewardKeeper),
exoslash.NewAppModule(appCodec, app.ExoSlashKeeper),
avs.NewAppModule(appCodec, app.AVSManagerKeeper),
avs_task.NewAppModule(appCodec, app.TaskKeeper),
)

// During begin block slashing happens after reward.BeginBlocker so that
Expand Down Expand Up @@ -889,6 +898,7 @@ func NewExocoreApp(
rewardTypes.ModuleName,
exoslashTypes.ModuleName,
avsManagerTypes.ModuleName,
taskTypes.ModuleName,
)

// NOTE: fee market module must go last in order to retrieve the block gas used.
Expand Down Expand Up @@ -928,6 +938,7 @@ func NewExocoreApp(
rewardTypes.ModuleName,
exoslashTypes.ModuleName,
avsManagerTypes.ModuleName,
taskTypes.ModuleName,
)

// NOTE: The genutils module must occur after staking so that pools are
Expand Down Expand Up @@ -973,6 +984,7 @@ func NewExocoreApp(
crisistypes.ModuleName,
consensusparamtypes.ModuleName,
avsManagerTypes.ModuleName,
taskTypes.ModuleName,
)

app.mm.RegisterInvariants(&app.CrisisKeeper)
Expand Down
2 changes: 0 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -1696,8 +1696,6 @@ golang.org/x/net v0.7.0/go.mod h1:2Tu9+aMcznHK/AK1HMvgo6xiTLG5rD5rZLDS+rp2Bjs=
golang.org/x/net v0.8.0/go.mod h1:QVkue5JL9kW//ek3r6jTKnTFis1tRmNAW2P1shuFdJc=
golang.org/x/net v0.9.0/go.mod h1:d48xBJpPfHeWQsugry2m+kC02ZBRGRgulfHnEXEuWns=
golang.org/x/net v0.10.0/go.mod h1:0qNGK6F8kojg2nk9dLZ2mShWaEBan6FAoqfSigmmuDg=
golang.org/x/net v0.22.0 h1:9sGLhx7iRIHEiX0oAJ3MRZMUCElJgy7Br1nO+AMN3Tc=
golang.org/x/net v0.22.0/go.mod h1:JKghWKKOSdJwpW2GEx0Ja7fmaKnMsbu+MWVZTokSYmg=
golang.org/x/net v0.23.0 h1:7EYJ93RZ9vYSZAIb2x3lnuvqO5zneoD6IvWjuhfxjTs=
golang.org/x/net v0.23.0/go.mod h1:JKghWKKOSdJwpW2GEx0Ja7fmaKnMsbu+MWVZTokSYmg=
golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U=
Expand Down
122 changes: 122 additions & 0 deletions precompiles/avsTask/abi.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
[
{
"anonymous": false,
"inputs": [
{
"indexed": true,
"internalType": "address",
"name": "operator",
"type": "address"
},
{
"indexed": false,
"internalType": "bytes",
"name": "pubkeyG1",
"type": "bytes"
}
],
"name": "NewPubkeyRegistration",
"type": "event"
},
{
"inputs": [
{
"internalType": "bytes32",
"name": "msgHash",
"type": "bytes32"
},
{
"internalType": "bytes",
"name": "signature",
"type": "bytes"
},
{
"internalType": "bytes",
"name": "pubkey",
"type": "bytes"
}
],
"name": "checkSignatures",
"outputs": [
{
"internalType": "bool",
"name": "valid",
"type": "bool"
}
],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [
{
"internalType": "address",
"name": "operator",
"type": "address"
}
],
"name": "getRegisteredPubkey",
"outputs": [
{
"internalType": "bytes32",
"name": "",
"type": "bytes32"
}
],
"stateMutability": "nonpayable",
"type": "function"
},
{
"inputs": [
{
"internalType": "string",
"name": "TaskContractAddress",
"type": "string"
},
{
"internalType": "string",
"name": "Name",
"type": "string"
},
{
"internalType": "string",
"name": "MetaInfo",
"type": "string"
}
],
"name": "registerAVSTask",
"outputs": [
{
"internalType": "bool",
"name": "success",
"type": "bool"
}
],
"stateMutability": "nonpayable",
"type": "function"
},
{
"inputs": [
{
"internalType": "string",
"name": "operator",
"type": "string"
},
{
"internalType": "bytes",
"name": "pubKey",
"type": "bytes"
}
],
"name": "registerBLSPublicKey",
"outputs": [
{
"internalType": "bool",
"name": "success",
"type": "bool"
}
],
"stateMutability": "nonpayable",
"type": "function"
}
]
53 changes: 53 additions & 0 deletions precompiles/avsTask/avsTask.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
pragma solidity >=0.8.17 .0;

/// @dev The AVSTask contract's address.
address constant AVSTASK_PRECOMPILE_ADDRESS = 0x0000000000000000000000000000000000000901;

/// @dev The AVSTask contract's instance.
IAVSTask constant AVSTASK_CONTRACT = IAVSTask(
AVSTASK_PRECOMPILE_ADDRESS
);

/// @author Exocore Team
/// @title AVSTask Precompile Contract
/// @dev The interface through which solidity contracts will interact with AVSTask
/// @custom:address 0x0000000000000000000000000000000000000901

interface IAVSTask {
/// TRANSACTIONS
/// @dev IAVSTask the oprator, that will change the state in AVSTask module
/// @param TaskContractAddress task Contract Address
/// @param Name task name
/// @param MetaInfo task desc
function registerAVSTask(
string memory TaskContractAddress,
string memory Name,
string memory MetaInfo
) external returns (bool success);

/// TRANSACTIONS
/// @dev Called by the avs manager service register an operator as the owner of a BLS public key.
/// @param operator is the operator for whom the key is being registered
/// @param pubKey the public keys of the operator
function registerBLSPublicKey(
string memory operator,
bytes calldata pubKey
) external returns (bool success);

/// TRANSACTIONS
/// @dev Returns the pubkey and pubkey hash of an operator,Reverts if the operator has not registered a valid pubkey
/// @param operator is the operator for whom the key is being registered
function getRegisteredPubkey(address operator) external returns (bytes32);

/// TRANSACTIONS
/// @dev Get the count of the current task
function checkSignatures(
bytes32 msgHash,
bytes calldata signature,
bytes calldata pubkey
) external view returns (bool valid);

// EVENTS
/// @notice Emitted when `operator` registers with the public keys `pubkeyG1`.
event NewPubkeyRegistration(address indexed operator, bytes pubkeyG1);
}
8 changes: 8 additions & 0 deletions precompiles/avsTask/error.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package task

const (
ErrContractInputParaOrType = "the contract input parameter type or value error,arg index:%d, type is:%s,value:%v"
ErrContractCaller = "the caller doesn't have the permission to call this function,caller:%s,need:%s"
ErrInputClientChainAddrLength = "the length of input client chain addr doesn't match,input:%d,need:%d"
ErrNotYetRegistered = "this AVS has not been registered yet,input:%d"
)
52 changes: 52 additions & 0 deletions precompiles/avsTask/events.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
package task

import (
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/ethereum/go-ethereum/accounts/abi"
"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 (
// EventTypeNewTaskCreated defines the event type for the task create transaction.
EventTypeNewPubkeyRegistration = "NewPubkeyRegistration"
)

// EmitEventTypeNewPubkeyRegistration new bls pubkey reg
func (p Precompile) EmitEventTypeNewPubkeyRegistration(
ctx sdk.Context,
stateDB vm.StateDB,
operator string,
pubkey []byte,
) error {
event := p.ABI.Events[EventTypeNewPubkeyRegistration]
topics := make([]common.Hash, 3)

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

var err error
// sender and receiver are indexed
topics[1], err = cmn.MakeTopic(operator)
if err != nil {
return err
}

// Prepare the event data: denom, amount, memo
arguments := abi.Arguments{event.Inputs[2]}
packed, err := arguments.Pack(pubkey)
if err != nil {
return err
}

stateDB.AddLog(&ethtypes.Log{
Address: p.Address(),
Topics: topics,
Data: packed,
BlockNumber: uint64(ctx.BlockHeight()),

Check failure

Code scanning / gosec

Potential integer overflow by integer type conversion Error

Potential integer overflow by integer type conversion
})

return nil
}
Loading

0 comments on commit 85151f0

Please sign in to comment.