Skip to content
This repository has been archived by the owner on Apr 4, 2024. It is now read-only.

feat: support stateful precompiled contracts #1650

Closed
wants to merge 45 commits into from
Closed
Show file tree
Hide file tree
Changes from 12 commits
Commits
Show all changes
45 commits
Select commit Hold shift + click to select a range
dae19d4
demonstrate use new cache store clone to integrate native stateful pr…
yihuang Jan 10, 2023
76d65bf
fix to BenchmarkMessageCall
mmsqe Jan 11, 2023
869b33f
Bank precompiled contract
yihuang Jun 16, 2022
b6007dc
replace extStates commit with executeNativeAction
mmsqe Jan 30, 2023
a98437d
avoid inject precompile contracts
mmsqe Jan 31, 2023
bb913f1
avoid fork
mmsqe Jan 31, 2023
f8bac9b
check readonly per run instead of contract
mmsqe Feb 1, 2023
aa03962
test delegatecall
mmsqe Feb 3, 2023
c074d40
Merge branch 'main' into precompiled
mmsqe Feb 3, 2023
4337fb4
test delegatecall
mmsqe Feb 4, 2023
a740db1
update geth
mmsqe Feb 4, 2023
13d1ec9
sort contracts by asc
mmsqe Feb 4, 2023
46b69f9
replace with precompile list
mmsqe Feb 6, 2023
6dfc48f
align amt
mmsqe Feb 6, 2023
96ea97f
test recursive transfer
mmsqe Feb 6, 2023
e73d46d
test nested call
mmsqe Feb 6, 2023
df95629
clean up vm related stuff
mmsqe Feb 7, 2023
e43465f
clean up
mmsqe Feb 7, 2023
918dc3c
rm test transfer
mmsqe Feb 7, 2023
4c0ee05
use stable sort
mmsqe Feb 7, 2023
84059d7
demonstrate use new cache store clone to integrate native stateful pr…
yihuang Jan 10, 2023
5477df9
vendor clone cache store implementation for statedb
yihuang Feb 17, 2023
605c757
Update x/evm/statedb/statedb.go
yihuang Feb 17, 2023
f736990
Merge branch 'main' into precompiled
mmsqe Feb 20, 2023
67c926b
transfer crc20 <-> native token
mmsqe Feb 20, 2023
bd38738
add burn
mmsqe Feb 20, 2023
8fc3db7
validate coins and recipient
mmsqe Feb 20, 2023
bfb8e54
fix lint
mmsqe Feb 20, 2023
1804680
fix commit
yihuang Feb 20, 2023
778e165
fix test
mmsqe Feb 17, 2023
2b4e507
fix build
mmsqe Feb 17, 2023
ae30385
pass keys
mmsqe Feb 18, 2023
5a1b0e0
add keys for CanTransferDecorator
mmsqe Feb 19, 2023
18c3e93
Merge branch 'precompiled' into precompiled
mmsqe Feb 20, 2023
54091f4
fix nix
mmsqe Feb 20, 2023
692e69f
fix crc20 <-> native token
mmsqe Feb 21, 2023
6f5ac41
test delegate & static call
mmsqe Feb 21, 2023
c0804be
fix lint
mmsqe Feb 21, 2023
d680d76
rm AppendJournalEntry
mmsqe Apr 13, 2023
4ea07ae
Merge branch 'main' into precompiled
mmsqe Apr 13, 2023
7f6a1c2
fix resolve
mmsqe Apr 13, 2023
ac011e6
revert cache store refactor
mmsqe Apr 13, 2023
d0451c7
fix writeCache
mmsqe Apr 13, 2023
aa147e6
check nil for writeCache and ms
mmsqe Apr 13, 2023
5377940
add bank msg utility cmd
mmsqe Apr 17, 2023
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
15 changes: 3 additions & 12 deletions app/ante/eth.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import (
evmtypes "github.com/evmos/ethermint/x/evm/types"

"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core"
ethtypes "github.com/ethereum/go-ethereum/core/types"
)

Expand Down Expand Up @@ -294,20 +295,10 @@ func (ctd CanTransferDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, simulate
}
}

// NOTE: pass in an empty coinbase address and nil tracer as we don't need them for the check below
cfg := &statedb.EVMConfig{
ChainConfig: ethCfg,
Params: params,
CoinBase: common.Address{},
BaseFee: baseFee,
}

stateDB := statedb.New(ctx, ctd.evmKeeper, statedb.NewEmptyTxConfig(common.BytesToHash(ctx.HeaderHash().Bytes())))
evm := ctd.evmKeeper.NewEVM(ctx, coreMsg, cfg, evmtypes.NewNoOpTracer(), stateDB)

stateDB := ctd.evmKeeper.StateDB(ctx, statedb.NewEmptyTxConfig(common.BytesToHash(ctx.HeaderHash().Bytes())))
// check that caller has enough balance to cover asset transfer for **topmost** call
// NOTE: here the gas consumed is from the context with the infinite gas meter
if coreMsg.Value().Sign() > 0 && !evm.Context().CanTransfer(stateDB, coreMsg.From(), coreMsg.Value()) {
if coreMsg.Value().Sign() > 0 && !core.CanTransfer(stateDB, coreMsg.From(), coreMsg.Value()) {
return ctx, errorsmod.Wrapf(
errortypes.ErrInsufficientFunds,
"failed to transfer %s from address %s using the EVM block context transfer function",
Expand Down
5 changes: 1 addition & 4 deletions app/ante/interfaces.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,10 @@ import (
tx "github.com/cosmos/cosmos-sdk/types/tx"

"github.com/ethereum/go-ethereum/common"
"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"
)

Expand All @@ -44,12 +41,12 @@ type EVMKeeper interface {
statedb.Keeper
DynamicFeeEVMKeeper

NewEVM(ctx sdk.Context, msg core.Message, cfg *statedb.EVMConfig, tracer vm.EVMLogger, stateDB vm.StateDB) evm.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)
GetTxIndexTransient(ctx sdk.Context) uint64
GetParams(ctx sdk.Context) evmtypes.Params
StateDB(ctx sdk.Context, txConfig statedb.TxConfig) *statedb.StateDB
}

type protoTxProvider interface {
Expand Down
10 changes: 8 additions & 2 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (
"encoding/json"
"fmt"
"io"
"math/big"
"net/http"
"os"
"path/filepath"
Expand Down Expand Up @@ -124,13 +125,16 @@ import (
ethermint "github.com/evmos/ethermint/types"
"github.com/evmos/ethermint/x/evm"
evmkeeper "github.com/evmos/ethermint/x/evm/keeper"
"github.com/evmos/ethermint/x/evm/keeper/precompiles"
evmtypes "github.com/evmos/ethermint/x/evm/types"
"github.com/evmos/ethermint/x/evm/vm"
"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"

// Force-load the tracer engines to trigger registration due to Go-Ethereum v1.10.15 changes
"github.com/ethereum/go-ethereum/common"
_ "github.com/ethereum/go-ethereum/eth/tracers/js"
_ "github.com/ethereum/go-ethereum/eth/tracers/native"
)
Expand Down Expand Up @@ -417,13 +421,15 @@ func NewEthermintApp(
appCodec, authtypes.NewModuleAddress(govtypes.ModuleName),
keys[feemarkettypes.StoreKey], tkeys[feemarkettypes.TransientKey], feeMarketSs,
)

contracts := map[common.Address]vm.PrecompiledContractCreator{
common.BigToAddress(big.NewInt(100)): precompiles.NewBankContractCreator(app.BankKeeper),
}
// Set authority to x/gov module account to only expect the module account to update params
evmSs := app.GetSubspace(evmtypes.ModuleName)
app.EvmKeeper = evmkeeper.NewKeeper(
appCodec, keys[evmtypes.StoreKey], tkeys[evmtypes.TransientKey], authtypes.NewModuleAddress(govtypes.ModuleName),
app.AccountKeeper, app.BankKeeper, app.StakingKeeper, app.FeeMarketKeeper,
nil, geth.NewEVM, tracer, evmSs,
contracts, geth.NewEVM, tracer, evmSs,
)

// Create IBC Keeper
Expand Down
6 changes: 5 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -162,8 +162,10 @@ require (
github.com/stretchr/objx v0.5.0 // indirect
github.com/subosito/gotenv v1.4.2 // indirect
github.com/syndtr/goleveldb v1.0.1-0.20210819022825-2ae1ddf74ef7 // indirect
github.com/tendermint/btcd v0.1.1 // indirect
github.com/tendermint/crypto v0.0.0-20191022145703-50d29ede1e15 // indirect
github.com/tendermint/go-amino v0.16.0 // indirect
github.com/tidwall/btree v1.5.0 // indirect
github.com/tidwall/btree v1.6.0 // indirect
github.com/tklauser/go-sysconf v0.3.10 // indirect
github.com/tklauser/numcpus v0.4.0 // indirect
github.com/ulikunitz/xz v0.5.8 // indirect
Expand Down Expand Up @@ -191,6 +193,8 @@ require (
replace (
// use cosmos keyring
github.com/99designs/keyring => github.com/cosmos/keyring v1.1.7-0.20210622111912-ef00f8ac3d76
github.com/cosmos/cosmos-sdk => github.com/mmsqe/cosmos-sdk v0.46.6-0.20230110154545-70f48768ca49
github.com/ethereum/go-ethereum => github.com/evmos/go-ethereum v1.10.26-evmos-rc1
// Fix upstream GHSA-h395-qcrw-5vmq vulnerability.
// TODO Remove it: https://github.com/cosmos/cosmos-sdk/issues/10409
github.com/gin-gonic/gin => github.com/gin-gonic/gin v1.7.0
Expand Down
Loading