Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat!: add stateful precompiles support #2633

Merged
merged 32 commits into from
Aug 27, 2024
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
f9f2c05
chore: cleanup Makefile and go.mod
fbac Aug 5, 2024
e449a1b
feat: introduce stateful precompiles initial support
fbac Aug 5, 2024
4ca59cb
chore: remove simapp as a dependency
fbac Aug 5, 2024
d8256c9
fix: adapt to testutil to changes
fbac Aug 7, 2024
5f2e9c8
Merge branch 'develop' into feat/stateful-precompiled-contracts
fbac Aug 7, 2024
d987a02
fix: linting
fbac Aug 8, 2024
12eb98b
Merge branch 'develop' into feat/stateful-precompiled-contracts
fbac Aug 8, 2024
ac03a5d
chore: add changelog and remove unused vars
fbac Aug 8, 2024
a6fa3e7
fix: create aggregateAllKeys function
fbac Aug 8, 2024
871cdd1
feat: add e2e test stateful contract (#2703)
Aug 21, 2024
796112a
resolve conflicts
fbac Aug 21, 2024
42110e0
formatting
fbac Aug 21, 2024
0488bad
new generated mocks
fbac Aug 21, 2024
e531669
skip precompile tests during upgrade
fbac Aug 21, 2024
e8af6b8
skip precompile
fbac Aug 23, 2024
56f4a1a
Merge branch 'develop' into feat/stateful-precompiled-contracts
skosito Aug 26, 2024
48035a4
try to fix generate
skosito Aug 26, 2024
16f2b0f
debug script
skosito Aug 26, 2024
de59aa8
install solc in generate files
skosito Aug 26, 2024
a8566a0
install abigen
skosito Aug 26, 2024
9f2d914
cleanup action
skosito Aug 27, 2024
e83aa70
PR comments pt1
skosito Aug 27, 2024
8a91d5f
group prototype unit tests a bit
skosito Aug 27, 2024
ac9f98e
PR comment missing test
skosito Aug 27, 2024
45370d4
cleanup action a bit
skosito Aug 27, 2024
c0a1d60
add solc checks to script
skosito Aug 27, 2024
e3649c1
cleanup not needed changes
skosito Aug 27, 2024
4aba6e0
revert ibc change in test
skosito Aug 27, 2024
c840542
remove new test
skosito Aug 27, 2024
15c277f
Merge branch 'develop' into feat/stateful-precompiled-contracts
swift1337 Aug 27, 2024
ecdc35f
reduce simple operations gas required to 500
skosito Aug 27, 2024
fffd126
Merge branch 'develop' into feat/stateful-precompiled-contracts
skosito Aug 27, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 7 additions & 9 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
.PHONY: build

PACKAGE_NAME := github.com/zeta-chain/node
VERSION := $(shell ./version.sh)
COMMIT := $(shell [ -z "${COMMIT_ID}" ] && git log -1 --format='%H' || echo ${COMMIT_ID} )
BUILDTIME := $(shell date -u +"%Y%m%d.%H%M%S" )
Expand All @@ -8,7 +9,9 @@ DOCKER ?= docker
# useful for setting profiles
DOCKER_COMPOSE ?= $(DOCKER) compose $(COMPOSE_ARGS)
DOCKER_BUF := $(DOCKER) run --rm -v $(CURDIR):/workspace --workdir /workspace bufbuild/buf
GOFLAGS:=""
GOFLAGS := ""
GOLANG_CROSS_VERSION ?= v1.22.4
GOPATH ?= '$(HOME)/go'

ldflags = -X github.com/cosmos/cosmos-sdk/version.Name=zetacore \
-X github.com/cosmos/cosmos-sdk/version.ServerName=zetacored \
Expand All @@ -23,7 +26,7 @@ ldflags = -X github.com/cosmos/cosmos-sdk/version.Name=zetacore \

BUILD_FLAGS := -ldflags '$(ldflags)' -tags pebbledb,ledger

TEST_DIR?="./..."
TEST_DIR ?= "./..."
TEST_BUILD_FLAGS := -tags pebbledb,ledger
HSM_BUILD_FLAGS := -tags pebbledb,ledger,hsm_test

Expand Down Expand Up @@ -53,11 +56,11 @@ go.sum: go.mod
### Test commands ###
###############################################################################

test: clean-test-dir run-test

run-test:
@go test ${TEST_BUILD_FLAGS} ${TEST_DIR}

test :clean-test-dir run-test

test-hsm:
@go test ${HSM_BUILD_FLAGS} ${TEST_DIR}

Expand Down Expand Up @@ -288,7 +291,6 @@ zetanode-upgrade: zetanode
.PHONY: zetanode-upgrade
endif


start-upgrade-test: zetanode-upgrade
@echo "--> Starting upgrade test"
export LOCALNET_MODE=upgrade && \
Expand All @@ -301,7 +303,6 @@ start-upgrade-test-light: zetanode-upgrade
export UPGRADE_HEIGHT=90 && \
cd contrib/localnet/ && $(DOCKER_COMPOSE) --profile upgrade -f docker-compose.yml -f docker-compose-upgrade.yml up -d


start-upgrade-test-admin: zetanode-upgrade
@echo "--> Starting admin upgrade test"
export LOCALNET_MODE=upgrade && \
Expand All @@ -321,9 +322,6 @@ start-upgrade-import-mainnet-test: zetanode-upgrade
### GoReleaser ###
###############################################################################

PACKAGE_NAME := github.com/zeta-chain/node
GOLANG_CROSS_VERSION ?= v1.22.4
GOPATH ?= '$(HOME)/go'
release-dry-run:
docker run \
--rm \
Expand Down
2 changes: 1 addition & 1 deletion app/ante/ante.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
// GNU Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with the Ethermint library. If not, see https://github.com/evmos/ethermint/blob/main/LICENSE
// along with the Ethermint library. If not, see https://github.com/zeta-chain/ethermint/blob/main/LICENSE
package ante

import (
Expand Down
4 changes: 2 additions & 2 deletions app/ante/fees.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
// GNU Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with the Ethermint library. If not, see https://github.com/evmos/ethermint/blob/main/LICENSE
// along with the Ethermint library. If not, see https://github.com/zeta-chain/ethermint/blob/main/LICENSE

// Copyright 2023 ZetaChain
// modified to exclude gentx transaction type from the min gas price check
Expand All @@ -26,7 +26,7 @@ import (
errortypes "github.com/cosmos/cosmos-sdk/types/errors"
stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types"
ethtypes "github.com/ethereum/go-ethereum/core/types"
evmtypes "github.com/evmos/ethermint/x/evm/types"
evmtypes "github.com/zeta-chain/ethermint/x/evm/types"
)

var (
Expand Down
8 changes: 4 additions & 4 deletions app/ante/handler_options.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
// GNU Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with the Ethermint library. If not, see https://github.com/evmos/ethermint/blob/main/LICENSE
// along with the Ethermint library. If not, see https://github.com/zeta-chain/ethermint/blob/main/LICENSE

package ante

Expand All @@ -29,9 +29,9 @@ import (
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
ibcante "github.com/cosmos/ibc-go/v7/modules/core/ante"
ibckeeper "github.com/cosmos/ibc-go/v7/modules/core/keeper"
ethante "github.com/evmos/ethermint/app/ante"
ethermint "github.com/evmos/ethermint/types"
evmtypes "github.com/evmos/ethermint/x/evm/types"
ethante "github.com/zeta-chain/ethermint/app/ante"
ethermint "github.com/zeta-chain/ethermint/types"
evmtypes "github.com/zeta-chain/ethermint/x/evm/types"

observerkeeper "github.com/zeta-chain/zetacore/x/observer/keeper"
)
Expand Down
11 changes: 5 additions & 6 deletions app/ante/interfaces.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
// GNU Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with the Ethermint library. If not, see https://github.com/evmos/ethermint/blob/main/LICENSE
// along with the Ethermint library. If not, see https://github.com/zeta-chain/ethermint/blob/main/LICENSE

package ante

Expand All @@ -24,10 +24,9 @@ import (
"github.com/ethereum/go-ethereum/core"
"github.com/ethereum/go-ethereum/core/vm"
"github.com/ethereum/go-ethereum/params"
"github.com/evmos/ethermint/x/evm/statedb"
evmtypes "github.com/evmos/ethermint/x/evm/types"
evm "github.com/evmos/ethermint/x/evm/vm"
feemarkettypes "github.com/evmos/ethermint/x/feemarket/types"
"github.com/zeta-chain/ethermint/x/evm/statedb"
evmtypes "github.com/zeta-chain/ethermint/x/evm/types"
feemarkettypes "github.com/zeta-chain/ethermint/x/feemarket/types"
)

// DynamicFeeEVMKeeper is a subset of EVMKeeper interface that supports dynamic fee checker
Expand All @@ -42,7 +41,7 @@ type EVMKeeper interface {
statedb.Keeper
DynamicFeeEVMKeeper

NewEVM(ctx sdk.Context, msg core.Message, cfg *statedb.EVMConfig, tracer vm.EVMLogger, stateDB vm.StateDB) evm.EVM
NewEVM(ctx sdk.Context, msg core.Message, cfg *statedb.EVMConfig, tracer vm.EVMLogger, stateDB vm.StateDB) *vm.EVM
DeductTxCostsFromUserBalance(ctx sdk.Context, fees sdk.Coins, from common.Address) error
GetBalance(ctx sdk.Context, addr common.Address) *big.Int
ResetTransientGasUsed(ctx sdk.Context)
Expand Down
38 changes: 25 additions & 13 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (
"time"

cosmoserrors "cosmossdk.io/errors"
appparams "cosmossdk.io/simapp/params"
dbm "github.com/cometbft/cometbft-db"
abci "github.com/cometbft/cometbft/abci/types"
tmjson "github.com/cometbft/cometbft/libs/json"
Expand Down Expand Up @@ -78,18 +77,17 @@ import (
upgradeclient "github.com/cosmos/cosmos-sdk/x/upgrade/client"
upgradekeeper "github.com/cosmos/cosmos-sdk/x/upgrade/keeper"
upgradetypes "github.com/cosmos/cosmos-sdk/x/upgrade/types"
evmante "github.com/evmos/ethermint/app/ante"
ethermint "github.com/evmos/ethermint/types"
"github.com/evmos/ethermint/x/evm"
evmkeeper "github.com/evmos/ethermint/x/evm/keeper"
evmtypes "github.com/evmos/ethermint/x/evm/types"
"github.com/evmos/ethermint/x/evm/vm/geth"
"github.com/evmos/ethermint/x/feemarket"
feemarketkeeper "github.com/evmos/ethermint/x/feemarket/keeper"
feemarkettypes "github.com/evmos/ethermint/x/feemarket/types"
"github.com/gorilla/mux"
"github.com/rakyll/statik/fs"
"github.com/spf13/cast"
evmante "github.com/zeta-chain/ethermint/app/ante"
ethermint "github.com/zeta-chain/ethermint/types"
"github.com/zeta-chain/ethermint/x/evm"
evmkeeper "github.com/zeta-chain/ethermint/x/evm/keeper"
evmtypes "github.com/zeta-chain/ethermint/x/evm/types"
"github.com/zeta-chain/ethermint/x/feemarket"
feemarketkeeper "github.com/zeta-chain/ethermint/x/feemarket/keeper"
feemarkettypes "github.com/zeta-chain/ethermint/x/feemarket/types"

"github.com/zeta-chain/zetacore/app/ante"
"github.com/zeta-chain/zetacore/docs/openapi"
Expand Down Expand Up @@ -315,7 +313,7 @@ func New(
skipUpgradeHeights map[int64]bool,
homePath string,
invCheckPeriod uint,
encodingConfig appparams.EncodingConfig,
encodingConfig ethermint.EncodingConfig,
appOpts servertypes.AppOptions,
baseAppOptions ...func(*baseapp.BaseApp),
) *App {
Expand Down Expand Up @@ -561,6 +559,20 @@ func New(
app.ConsensusParamsKeeper,
)
evmSs := app.GetSubspace(evmtypes.ModuleName)

allKeys := make(map[string]storetypes.StoreKey, len(keys)+len(tkeys)+len(memKeys))
for k, v := range keys {
allKeys[k] = v
}
for k, v := range tkeys {
allKeys[k] = v
}
for k, v := range memKeys {
allKeys[k] = v
}
fbac marked this conversation as resolved.
Show resolved Hide resolved

//gasConfig := storetypes.TransientGasConfig()

app.EvmKeeper = evmkeeper.NewKeeper(
appCodec,
keys[evmtypes.StoreKey],
Expand All @@ -570,11 +582,11 @@ func New(
app.BankKeeper,
app.StakingKeeper,
&app.FeeMarketKeeper,
nil,
geth.NewEVM,
tracer,
evmSs,
[]evmkeeper.CustomContractFn{},
app.ConsensusParamsKeeper,
allKeys,
)

app.FungibleKeeper = *fungiblekeeper.NewKeeper(
Expand Down
6 changes: 3 additions & 3 deletions app/encoding.go
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
package app

import (
"cosmossdk.io/simapp/params"
evmenc "github.com/evmos/ethermint/encoding"
evmenc "github.com/zeta-chain/ethermint/encoding"
ethermint "github.com/zeta-chain/ethermint/types"
)

// MakeEncodingConfig creates an EncodingConfig for testing
func MakeEncodingConfig() params.EncodingConfig {
func MakeEncodingConfig() ethermint.EncodingConfig {
//encodingConfig := params.MakeEncodingConfig()
encodingConfig := evmenc.MakeConfig(ModuleBasics)
//std.RegisterLegacyAminoCodec(encodingConfig.Amino)
Expand Down
4 changes: 2 additions & 2 deletions app/init_genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ import (
slashingtypes "github.com/cosmos/cosmos-sdk/x/slashing/types"
stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types"
upgradetypes "github.com/cosmos/cosmos-sdk/x/upgrade/types"
evmtypes "github.com/evmos/ethermint/x/evm/types"
feemarkettypes "github.com/evmos/ethermint/x/feemarket/types"
evmtypes "github.com/zeta-chain/ethermint/x/evm/types"
feemarkettypes "github.com/zeta-chain/ethermint/x/feemarket/types"

authoritytypes "github.com/zeta-chain/zetacore/x/authority/types"
crosschaintypes "github.com/zeta-chain/zetacore/x/crosschain/types"
Expand Down
2 changes: 1 addition & 1 deletion app/prefix.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package app

import (
sdk "github.com/cosmos/cosmos-sdk/types"
ethcfg "github.com/evmos/ethermint/cmd/config"
ethcfg "github.com/zeta-chain/ethermint/cmd/config"

cmdcfg "github.com/zeta-chain/zetacore/cmd/zetacored/config"
)
Expand Down
4 changes: 2 additions & 2 deletions cmd/zetacored/add_observer_list.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ import (
"github.com/cosmos/cosmos-sdk/x/gov/types/v1beta1"
stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types"
ethcommon "github.com/ethereum/go-ethereum/common"
ethermint "github.com/evmos/ethermint/types"
evmtypes "github.com/evmos/ethermint/x/evm/types"
"github.com/spf13/cobra"
ethermint "github.com/zeta-chain/ethermint/types"
evmtypes "github.com/zeta-chain/ethermint/x/evm/types"

"github.com/zeta-chain/zetacore/app"
"github.com/zeta-chain/zetacore/cmd/zetacored/config"
Expand Down
2 changes: 1 addition & 1 deletion cmd/zetacored/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package config

import (
sdk "github.com/cosmos/cosmos-sdk/types"
ethermint "github.com/evmos/ethermint/types"
ethermint "github.com/zeta-chain/ethermint/types"
)

// SetBech32Prefixes sets the global prefixes to be used when serializing addresses and public keys to Bech32 strings.
Expand Down
4 changes: 2 additions & 2 deletions cmd/zetacored/genaccounts.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ import (
"github.com/cosmos/cosmos-sdk/x/genutil"
genutiltypes "github.com/cosmos/cosmos-sdk/x/genutil/types"
"github.com/ethereum/go-ethereum/common"
ethermint "github.com/evmos/ethermint/types"
evmtypes "github.com/evmos/ethermint/x/evm/types"
"github.com/spf13/cobra"
ethermint "github.com/zeta-chain/ethermint/types"
evmtypes "github.com/zeta-chain/ethermint/x/evm/types"
)

const (
Expand Down
4 changes: 2 additions & 2 deletions cmd/zetacored/parse_genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@ import (
slashingtypes "github.com/cosmos/cosmos-sdk/x/slashing/types"
stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types"
upgradetypes "github.com/cosmos/cosmos-sdk/x/upgrade/types"
evmtypes "github.com/evmos/ethermint/x/evm/types"
feemarkettypes "github.com/evmos/ethermint/x/feemarket/types"
"github.com/spf13/cobra"
evmtypes "github.com/zeta-chain/ethermint/x/evm/types"
feemarkettypes "github.com/zeta-chain/ethermint/x/feemarket/types"

"github.com/zeta-chain/zetacore/app"
crosschaintypes "github.com/zeta-chain/zetacore/x/crosschain/types"
Expand Down
12 changes: 6 additions & 6 deletions cmd/zetacored/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (
"io"
"os"

appparams "cosmossdk.io/simapp/params"
rosettaCmd "cosmossdk.io/tools/rosetta/cmd"
dbm "github.com/cometbft/cometbft-db"
tmcfg "github.com/cometbft/cometbft/config"
Expand All @@ -28,10 +27,11 @@ import (
"github.com/cosmos/cosmos-sdk/x/crisis"
genutilcli "github.com/cosmos/cosmos-sdk/x/genutil/client/cli"
genutiltypes "github.com/cosmos/cosmos-sdk/x/genutil/types"
ethermintclient "github.com/evmos/ethermint/client"
"github.com/evmos/ethermint/crypto/hd"
"github.com/spf13/cast"
"github.com/spf13/cobra"
ethermintclient "github.com/zeta-chain/ethermint/client"
"github.com/zeta-chain/ethermint/crypto/hd"
"github.com/zeta-chain/ethermint/types"

"github.com/zeta-chain/zetacore/app"
zetacoredconfig "github.com/zeta-chain/zetacore/cmd/zetacored/config"
Expand All @@ -45,7 +45,7 @@ const EnvPrefix = "zetacore"
// NewRootCmd creates a new root command for wasmd. It is called once in the
// main function.

func NewRootCmd() (*cobra.Command, appparams.EncodingConfig) {
func NewRootCmd() (*cobra.Command, types.EncodingConfig) {
encodingConfig := app.MakeEncodingConfig()

cfg := sdk.GetConfig()
Expand Down Expand Up @@ -119,7 +119,7 @@ func initTmConfig() *tmcfg.Config {
return cfg
}

func initRootCmd(rootCmd *cobra.Command, encodingConfig appparams.EncodingConfig) {
func initRootCmd(rootCmd *cobra.Command, encodingConfig types.EncodingConfig) {
ac := appCreator{
encCfg: encodingConfig,
}
Expand Down Expand Up @@ -236,7 +236,7 @@ func txCommand() *cobra.Command {
}

type appCreator struct {
encCfg appparams.EncodingConfig
encCfg types.EncodingConfig
}

func (ac appCreator) newApp(
Expand Down
2 changes: 1 addition & 1 deletion e2e/contracts/contextapp/bindings.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
"encoding/json"

"github.com/ethereum/go-ethereum/accounts/abi"
evmtypes "github.com/evmos/ethermint/x/evm/types"
evmtypes "github.com/zeta-chain/ethermint/x/evm/types"
)

type CompiledContract struct {
Expand Down
6 changes: 3 additions & 3 deletions e2e/txserver/zeta_tx_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@ import (
stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types"
upgradetypes "github.com/cosmos/cosmos-sdk/x/upgrade/types"
ethcommon "github.com/ethereum/go-ethereum/common"
"github.com/evmos/ethermint/crypto/hd"
etherminttypes "github.com/evmos/ethermint/types"
evmtypes "github.com/evmos/ethermint/x/evm/types"
"github.com/zeta-chain/ethermint/crypto/hd"
etherminttypes "github.com/zeta-chain/ethermint/types"
evmtypes "github.com/zeta-chain/ethermint/x/evm/types"

"github.com/zeta-chain/zetacore/app"
"github.com/zeta-chain/zetacore/cmd/zetacored/config"
Expand Down
Loading
Loading