From c000b6a5f324412fefcd0a25b87e0f0ad81bdced Mon Sep 17 00:00:00 2001 From: beer-1 Date: Tue, 5 Nov 2024 16:32:56 +0900 Subject: [PATCH] update precompiles --- go.mod | 2 +- go.sum | 4 +- integration-tests/go.mod | 2 +- integration-tests/go.sum | 4 +- x/evm/keeper/context.go | 9 +-- x/evm/keeper/keeper.go | 9 ++- x/evm/keeper/precompiles.go | 57 +++++++------------ x/evm/precompiles/cosmos/contract.go | 23 ++++---- x/evm/precompiles/cosmos/contract_test.go | 18 +++--- x/evm/precompiles/erc20_registry/contract.go | 21 ++++--- .../erc20_registry/contract_test.go | 2 +- x/evm/types/address.go | 8 --- x/evm/types/expected_keeper.go | 4 +- 13 files changed, 72 insertions(+), 91 deletions(-) diff --git a/go.mod b/go.mod index 3ccb822..7830b3c 100644 --- a/go.mod +++ b/go.mod @@ -288,7 +288,7 @@ replace ( replace ( github.com/cometbft/cometbft => github.com/initia-labs/cometbft v0.0.0-20240925132752-ff8ff0126261 github.com/cosmos/ibc-go/v8 => github.com/initia-labs/ibc-go/v8 v8.0.0-20240802003717-19c0b4ad450d - github.com/ethereum/go-ethereum => github.com/initia-labs/evm v0.0.0-20241104061036-f8482395518d + github.com/ethereum/go-ethereum => github.com/initia-labs/evm v0.0.0-20241105070652-c43b570a4e98 // use custom version until this PR is merged // - https://github.com/strangelove-ventures/cometbft-client/pull/10 diff --git a/go.sum b/go.sum index dc02c9f..447fba6 100644 --- a/go.sum +++ b/go.sum @@ -1440,8 +1440,8 @@ github.com/initia-labs/cometbft v0.0.0-20240925132752-ff8ff0126261 h1:V62KOhe6Em github.com/initia-labs/cometbft v0.0.0-20240925132752-ff8ff0126261/go.mod h1:KsQ7Wm/dw9N0l7Ypn3QKGwgUX5XinTlcHGIF0DSjsw4= github.com/initia-labs/cometbft-client v0.0.0-20240924071428-ef115cefa07e h1:k+pg63SFozCAK4LZFSiZtof6z69Tlu0O/Zftj1aAwes= github.com/initia-labs/cometbft-client v0.0.0-20240924071428-ef115cefa07e/go.mod h1:aVposiPW9FOUeAeJ7JjJRdE3g+L6i8YDxFn6Cv6+Az4= -github.com/initia-labs/evm v0.0.0-20241104061036-f8482395518d h1:9fqIEcfMe10BjfNWmuQDqYGmvtTIMRcMXJi26VCs5DM= -github.com/initia-labs/evm v0.0.0-20241104061036-f8482395518d/go.mod h1:+l/fr42Mma+xBnhefL/+z11/hcmJ2egl+ScIVPjhc7E= +github.com/initia-labs/evm v0.0.0-20241105070652-c43b570a4e98 h1:JmJpxtYnF++Lj9MhD2LxOtgNAJM0aYqgO9nBkuhiGlI= +github.com/initia-labs/evm v0.0.0-20241105070652-c43b570a4e98/go.mod h1:+l/fr42Mma+xBnhefL/+z11/hcmJ2egl+ScIVPjhc7E= github.com/initia-labs/ibc-go/v8 v8.0.0-20240802003717-19c0b4ad450d h1:TLq8lB1PtQ0pjGf+bN8YgGVeLMuytZ26SBGMOs1seKY= github.com/initia-labs/ibc-go/v8 v8.0.0-20240802003717-19c0b4ad450d/go.mod h1:zh6x1osR0hNvEcFrC/lhGD08sMfQmr9wHVvZ/mRWMCs= github.com/initia-labs/initia v0.6.0 h1:/39ZN26zeixxZZdcfY1sOitiBhfnG3lcbPtpFqd9z7A= diff --git a/integration-tests/go.mod b/integration-tests/go.mod index 491a9d2..79d24a5 100644 --- a/integration-tests/go.mod +++ b/integration-tests/go.mod @@ -271,7 +271,7 @@ replace ( replace ( github.com/cometbft/cometbft => github.com/initia-labs/cometbft v0.0.0-20240925132752-ff8ff0126261 github.com/cosmos/ibc-go/v8 => github.com/initia-labs/ibc-go/v8 v8.0.0-20240802003717-19c0b4ad450d - github.com/ethereum/go-ethereum => github.com/initia-labs/evm v0.0.0-20241104061036-f8482395518d + github.com/ethereum/go-ethereum => github.com/initia-labs/evm v0.0.0-20241105070652-c43b570a4e98 // use custom version until this PR is merged // - https://github.com/strangelove-ventures/cometbft-client/pull/10 diff --git a/integration-tests/go.sum b/integration-tests/go.sum index db97e37..fafc6d6 100644 --- a/integration-tests/go.sum +++ b/integration-tests/go.sum @@ -1398,8 +1398,8 @@ github.com/initia-labs/OPinit/api v0.5.1 h1:zwyJf7HtKJCKvLJ1R9PjVfJO1L+d/jKoeFyT github.com/initia-labs/OPinit/api v0.5.1/go.mod h1:gHK6DEWb3/DqQD5LjKirUx9jilAh2UioXanoQdgqVfU= github.com/initia-labs/cometbft v0.0.0-20240925132752-ff8ff0126261 h1:V62KOhe6Em3wAvJsDVP+3is98I3mk/29OKNVs4IxeFQ= github.com/initia-labs/cometbft v0.0.0-20240925132752-ff8ff0126261/go.mod h1:KsQ7Wm/dw9N0l7Ypn3QKGwgUX5XinTlcHGIF0DSjsw4= -github.com/initia-labs/evm v0.0.0-20241104061036-f8482395518d h1:9fqIEcfMe10BjfNWmuQDqYGmvtTIMRcMXJi26VCs5DM= -github.com/initia-labs/evm v0.0.0-20241104061036-f8482395518d/go.mod h1:+l/fr42Mma+xBnhefL/+z11/hcmJ2egl+ScIVPjhc7E= +github.com/initia-labs/evm v0.0.0-20241105070652-c43b570a4e98 h1:JmJpxtYnF++Lj9MhD2LxOtgNAJM0aYqgO9nBkuhiGlI= +github.com/initia-labs/evm v0.0.0-20241105070652-c43b570a4e98/go.mod h1:+l/fr42Mma+xBnhefL/+z11/hcmJ2egl+ScIVPjhc7E= github.com/initia-labs/ibc-go/v8 v8.0.0-20240802003717-19c0b4ad450d h1:TLq8lB1PtQ0pjGf+bN8YgGVeLMuytZ26SBGMOs1seKY= github.com/initia-labs/ibc-go/v8 v8.0.0-20240802003717-19c0b4ad450d/go.mod h1:zh6x1osR0hNvEcFrC/lhGD08sMfQmr9wHVvZ/mRWMCs= github.com/initia-labs/initia v0.6.0 h1:/39ZN26zeixxZZdcfY1sOitiBhfnG3lcbPtpFqd9z7A= diff --git a/x/evm/keeper/context.go b/x/evm/keeper/context.go index 140154c..91ebce7 100644 --- a/x/evm/keeper/context.go +++ b/x/evm/keeper/context.go @@ -193,7 +193,8 @@ func (k Keeper) CreateEVM(ctx context.Context, caller common.Address, tracer *tr stateDB, types.DefaultChainConfig(ctx), vmConfig, - k.precompiles.toMap(stateDB), + // use custom precompiles + k.Precompiles(stateDB), ) if tracer != nil { @@ -238,7 +239,7 @@ func (k Keeper) EVMStaticCallWithTracer(ctx context.Context, caller common.Addre sdkCtx := sdk.UnwrapSDKContext(ctx) gasBalance := k.computeGasLimit(sdkCtx) rules := evm.ChainConfig().Rules(evm.Context.BlockNumber, evm.Context.Random != nil, evm.Context.Time) - evm.StateDB.Prepare(rules, caller, types.NullAddress, &contractAddr, append(vm.ActivePrecompiles(rules), k.precompiles.toAddrs()...), accessList) + evm.StateDB.Prepare(rules, caller, types.NullAddress, &contractAddr, k.precompileAddrs, accessList) retBz, gasRemaining, err := evm.StaticCall( vm.AccountRef(caller), @@ -276,7 +277,7 @@ func (k Keeper) EVMCallWithTracer(ctx context.Context, caller common.Address, co } rules := evm.ChainConfig().Rules(evm.Context.BlockNumber, evm.Context.Random != nil, evm.Context.Time) - evm.StateDB.Prepare(rules, caller, types.NullAddress, &contractAddr, append(vm.ActivePrecompiles(rules), k.precompiles.toAddrs()...), accessList) + evm.StateDB.Prepare(rules, caller, types.NullAddress, &contractAddr, k.precompileAddrs, accessList) retBz, gasRemaining, err := evm.Call( vm.AccountRef(caller), @@ -370,7 +371,7 @@ func (k Keeper) EVMCreateWithTracer(ctx context.Context, caller common.Address, } rules := evm.ChainConfig().Rules(evm.Context.BlockNumber, evm.Context.Random != nil, evm.Context.Time) - evm.StateDB.Prepare(rules, caller, types.NullAddress, nil, append(vm.ActivePrecompiles(rules), k.precompiles.toAddrs()...), accessList) + evm.StateDB.Prepare(rules, caller, types.NullAddress, nil, k.precompileAddrs, accessList) var gasRemaining uint64 if salt == nil { diff --git a/x/evm/keeper/keeper.go b/x/evm/keeper/keeper.go index 64fb107..6c53cf5 100644 --- a/x/evm/keeper/keeper.go +++ b/x/evm/keeper/keeper.go @@ -12,6 +12,7 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" "github.com/ethereum/go-ethereum/accounts/abi" "github.com/ethereum/go-ethereum/common" + "github.com/ethereum/go-ethereum/core/vm" evmconfig "github.com/initia-labs/minievm/x/evm/config" "github.com/initia-labs/minievm/x/evm/contracts/i_cosmos_callback" @@ -77,7 +78,9 @@ type Keeper struct { // evm stores EVMBlockHashes collections.Map[uint64, []byte] - precompiles precompiles + precompiles vm.PrecompiledContracts + precompileAddrs []common.Address + queryCosmosWhitelist types.QueryCosmosWhitelist cosmosCallbackABI *abi.ABI } @@ -154,7 +157,9 @@ func NewKeeper( EVMBlockHashes: collections.NewMap(sb, types.EVMBlockHashPrefix, "evm_block_hashes", collections.Uint64Key, collections.BytesValue), - precompiles: []precompile{}, + precompiles: vm.PrecompiledContracts{}, + precompileAddrs: []common.Address{}, + queryCosmosWhitelist: queryCosmosWhitelist, cosmosCallbackABI: cosmosCallbackABI, } diff --git a/x/evm/keeper/precompiles.go b/x/evm/keeper/precompiles.go index e290b68..a303bf6 100644 --- a/x/evm/keeper/precompiles.go +++ b/x/evm/keeper/precompiles.go @@ -1,20 +1,18 @@ package keeper import ( - "github.com/ethereum/go-ethereum/common" + "math/big" + "slices" + "github.com/ethereum/go-ethereum/core/vm" + sdk "github.com/cosmos/cosmos-sdk/types" + cosmosprecompile "github.com/initia-labs/minievm/x/evm/precompiles/cosmos" erc20registryprecompile "github.com/initia-labs/minievm/x/evm/precompiles/erc20_registry" "github.com/initia-labs/minievm/x/evm/types" ) -// precompile is a precompiled contract. -type precompile struct { - addr common.Address - contract vm.PrecompiledContract -} - // loadPrecompiles loads the precompiled contracts. func (k *Keeper) loadPrecompiles() error { erc20RegistryPrecompile, err := erc20registryprecompile.NewERC20RegistryPrecompile(k.erc20StoresKeeper) @@ -35,38 +33,25 @@ func (k *Keeper) loadPrecompiles() error { return err } - k.precompiles = precompiles{ - { - addr: common.BytesToAddress([]byte{0xf1}), - contract: cosmosPrecompile, - }, - { - addr: common.BytesToAddress([]byte{0xf2}), - contract: erc20RegistryPrecompile, - }, - } - - return nil -} + // prepare precompiles; always use latest chain config + // to load all precompiles. + chainConfig := types.DefaultChainConfig(sdk.Context{}) + rules := chainConfig.Rules(big.NewInt(1), true, 1) -// precompiles is a list of precompiled contracts. -type precompiles []precompile + precompiles := vm.ActivePrecompiledContracts(rules) + precompiles[types.CosmosPrecompileAddress] = cosmosPrecompile + precompiles[types.ERC20RegistryPrecompileAddress] = erc20RegistryPrecompile + k.precompiles = precompiles -// toMap converts the precompiles to a map. -func (ps precompiles) toMap(stateDB types.StateDB) map[common.Address]vm.PrecompiledContract { - m := make(map[common.Address]vm.PrecompiledContract) - for _, p := range ps { - m[p.addr] = p.contract.(types.WithStateDB).WithStateDB(stateDB) - } + precompileAddrs := slices.Clone(vm.ActivePrecompiles(rules)) + precompileAddrs = append(precompileAddrs, types.CosmosPrecompileAddress, types.ERC20RegistryPrecompileAddress) + k.precompileAddrs = precompileAddrs - return m + return nil } -func (ps precompiles) toAddrs() []common.Address { - addrs := make([]common.Address, len(ps)) - for i, p := range ps { - addrs[i] = p.addr - } - - return addrs +func (k *Keeper) Precompiles(stateDB types.StateDB) vm.PrecompiledContracts { + k.precompiles[types.CosmosPrecompileAddress].(types.SetStateDB).SetStateDB(stateDB) + k.precompiles[types.ERC20RegistryPrecompileAddress].(types.SetStateDB).SetStateDB(stateDB) + return k.precompiles } diff --git a/x/evm/precompiles/cosmos/contract.go b/x/evm/precompiles/cosmos/contract.go index 1e06a1f..3ca9cf6 100644 --- a/x/evm/precompiles/cosmos/contract.go +++ b/x/evm/precompiles/cosmos/contract.go @@ -22,9 +22,9 @@ import ( "github.com/initia-labs/minievm/x/evm/types" ) -var _ vm.ExtendedPrecompiledContract = CosmosPrecompile{} -var _ vm.PrecompiledContract = CosmosPrecompile{} -var _ types.WithStateDB = CosmosPrecompile{} +var _ vm.ExtendedPrecompiledContract = &CosmosPrecompile{} +var _ vm.PrecompiledContract = &CosmosPrecompile{} +var _ types.SetStateDB = &CosmosPrecompile{} type CosmosPrecompile struct { *abi.ABI @@ -49,13 +49,13 @@ func NewCosmosPrecompile( edk types.ERC20DenomKeeper, grpcRouter types.GRPCRouter, queryWhitelist types.QueryCosmosWhitelist, -) (CosmosPrecompile, error) { +) (*CosmosPrecompile, error) { abi, err := i_cosmos.ICosmosMetaData.GetAbi() if err != nil { - return CosmosPrecompile{}, err + return nil, err } - return CosmosPrecompile{ + return &CosmosPrecompile{ ABI: abi, cdc: cdc, ac: ac, @@ -67,12 +67,11 @@ func NewCosmosPrecompile( }, nil } -func (e CosmosPrecompile) WithStateDB(stateDB types.StateDB) vm.PrecompiledContract { +func (e *CosmosPrecompile) SetStateDB(stateDB types.StateDB) { e.stateDB = stateDB - return e } -func (e CosmosPrecompile) originAddress(ctx context.Context, addrBz []byte) (sdk.AccAddress, error) { +func (e *CosmosPrecompile) originAddress(ctx context.Context, addrBz []byte) (sdk.AccAddress, error) { account := e.ak.GetAccount(ctx, addrBz) if shorthandCallerAccount, ok := account.(types.ShorthandAccountI); ok { addr, err := shorthandCallerAccount.GetOriginalAddress(e.ac) @@ -87,7 +86,7 @@ func (e CosmosPrecompile) originAddress(ctx context.Context, addrBz []byte) (sdk } // ExtendedRun implements vm.ExtendedPrecompiledContract. -func (e CosmosPrecompile) ExtendedRun(caller vm.ContractRef, input []byte, suppliedGas uint64, readOnly bool) (resBz []byte, usedGas uint64, err error) { +func (e *CosmosPrecompile) ExtendedRun(caller vm.ContractRef, input []byte, suppliedGas uint64, readOnly bool) (resBz []byte, usedGas uint64, err error) { snapshot := e.stateDB.Snapshot() ctx := e.stateDB.ContextOfSnapshot(snapshot).WithGasMeter(storetypes.NewGasMeter(suppliedGas)) @@ -345,11 +344,11 @@ func (e CosmosPrecompile) ExtendedRun(caller vm.ContractRef, input []byte, suppl } // RequiredGas implements vm.PrecompiledContract. -func (e CosmosPrecompile) RequiredGas(input []byte) uint64 { +func (e *CosmosPrecompile) RequiredGas(input []byte) uint64 { return 0 } // Run implements vm.PrecompiledContract. -func (e CosmosPrecompile) Run(input []byte) ([]byte, error) { +func (e *CosmosPrecompile) Run(input []byte) ([]byte, error) { return nil, errors.New("the CosmosPrecompile works exclusively with ExtendedRun") } diff --git a/x/evm/precompiles/cosmos/contract_test.go b/x/evm/precompiles/cosmos/contract_test.go index 8d2de8e..e15ecf7 100644 --- a/x/evm/precompiles/cosmos/contract_test.go +++ b/x/evm/precompiles/cosmos/contract_test.go @@ -67,7 +67,7 @@ func Test_CosmosPrecompile_IsBlockedAddress(t *testing.T) { require.NoError(t, err) stateDB := NewMockStateDB(ctx) - cosmosPrecompile = cosmosPrecompile.WithStateDB(stateDB).(precompiles.CosmosPrecompile) + cosmosPrecompile.SetStateDB(stateDB) evmAddr := common.HexToAddress("0x1") cosmosAddr, err := ac.BytesToString(evmAddr.Bytes()) @@ -113,7 +113,7 @@ func Test_CosmosPrecompile_IsModuleAddress(t *testing.T) { require.NoError(t, err) stateDB := NewMockStateDB(ctx) - cosmosPrecompile = cosmosPrecompile.WithStateDB(stateDB).(precompiles.CosmosPrecompile) + cosmosPrecompile.SetStateDB(stateDB) evmAddr := common.HexToAddress("0x1") cosmosAddr, err := ac.BytesToString(evmAddr.Bytes()) @@ -159,7 +159,7 @@ func Test_CosmosPrecompile_ToCosmosAddress(t *testing.T) { require.NoError(t, err) stateDB := NewMockStateDB(ctx) - cosmosPrecompile = cosmosPrecompile.WithStateDB(stateDB).(precompiles.CosmosPrecompile) + cosmosPrecompile.SetStateDB(stateDB) evmAddr := common.HexToAddress("0x1") cosmosAddr, err := ac.BytesToString(evmAddr.Bytes()) @@ -190,7 +190,7 @@ func Test_CosmosPrecompile_ToEVMAddress(t *testing.T) { require.NoError(t, err) stateDB := NewMockStateDB(ctx) - cosmosPrecompile = cosmosPrecompile.WithStateDB(stateDB).(precompiles.CosmosPrecompile) + cosmosPrecompile.SetStateDB(stateDB) evmAddr := common.HexToAddress("0x1") cosmosAddr, err := ac.BytesToString(evmAddr.Bytes()) @@ -221,7 +221,7 @@ func Test_ExecuteCosmos(t *testing.T) { require.NoError(t, err) stateDB := NewMockStateDB(ctx) - cosmosPrecompile = cosmosPrecompile.WithStateDB(stateDB).(precompiles.CosmosPrecompile) + cosmosPrecompile.SetStateDB(stateDB) evmAddr := common.HexToAddress("0x1") cosmosAddr, err := ac.BytesToString(evmAddr.Bytes()) @@ -294,7 +294,7 @@ func Test_ExecuteCosmosWithOptions(t *testing.T) { require.NoError(t, err) stateDB := NewMockStateDB(ctx) - cosmosPrecompile = cosmosPrecompile.WithStateDB(stateDB).(precompiles.CosmosPrecompile) + cosmosPrecompile.SetStateDB(stateDB) evmAddr := common.HexToAddress("0x1") cosmosAddr, err := ac.BytesToString(evmAddr.Bytes()) @@ -400,7 +400,7 @@ func Test_QueryCosmos(t *testing.T) { require.NoError(t, err) stateDB := NewMockStateDB(ctx) - cosmosPrecompile = cosmosPrecompile.WithStateDB(stateDB).(precompiles.CosmosPrecompile) + cosmosPrecompile.SetStateDB(stateDB) evmAddr := common.HexToAddress("0x1") @@ -447,7 +447,7 @@ func Test_ToDenom(t *testing.T) { require.NoError(t, err) stateDB := NewMockStateDB(ctx) - cosmosPrecompile = cosmosPrecompile.WithStateDB(stateDB).(precompiles.CosmosPrecompile) + cosmosPrecompile.SetStateDB(stateDB) evmAddr := common.HexToAddress("0x1") @@ -489,7 +489,7 @@ func Test_ToErc20(t *testing.T) { require.NoError(t, err) stateDB := NewMockStateDB(ctx) - cosmosPrecompile = cosmosPrecompile.WithStateDB(stateDB).(precompiles.CosmosPrecompile) + cosmosPrecompile.SetStateDB(stateDB) evmAddr := common.HexToAddress("0x1") diff --git a/x/evm/precompiles/erc20_registry/contract.go b/x/evm/precompiles/erc20_registry/contract.go index 3e2739b..6e15c76 100644 --- a/x/evm/precompiles/erc20_registry/contract.go +++ b/x/evm/precompiles/erc20_registry/contract.go @@ -12,9 +12,9 @@ import ( "github.com/initia-labs/minievm/x/evm/types" ) -var _ vm.ExtendedPrecompiledContract = ERC20RegistryPrecompile{} -var _ vm.PrecompiledContract = ERC20RegistryPrecompile{} -var _ types.WithStateDB = ERC20RegistryPrecompile{} +var _ vm.ExtendedPrecompiledContract = &ERC20RegistryPrecompile{} +var _ vm.PrecompiledContract = &ERC20RegistryPrecompile{} +var _ types.SetStateDB = &ERC20RegistryPrecompile{} type ERC20RegistryPrecompile struct { *abi.ABI @@ -22,18 +22,17 @@ type ERC20RegistryPrecompile struct { k types.IERC20StoresKeeper } -func NewERC20RegistryPrecompile(k types.IERC20StoresKeeper) (ERC20RegistryPrecompile, error) { +func NewERC20RegistryPrecompile(k types.IERC20StoresKeeper) (*ERC20RegistryPrecompile, error) { abi, err := i_erc20_registry.IErc20RegistryMetaData.GetAbi() if err != nil { - return ERC20RegistryPrecompile{}, err + return nil, err } - return ERC20RegistryPrecompile{ABI: abi, k: k}, nil + return &ERC20RegistryPrecompile{ABI: abi, k: k}, nil } -func (e ERC20RegistryPrecompile) WithStateDB(stateDB types.StateDB) vm.PrecompiledContract { +func (e *ERC20RegistryPrecompile) SetStateDB(stateDB types.StateDB) { e.stateDB = stateDB - return e } const ( @@ -44,7 +43,7 @@ const ( ) // ExtendedRun implements vm.ExtendedPrecompiledContract. -func (e ERC20RegistryPrecompile) ExtendedRun(caller vm.ContractRef, input []byte, suppliedGas uint64, readOnly bool) (resBz []byte, usedGas uint64, err error) { +func (e *ERC20RegistryPrecompile) ExtendedRun(caller vm.ContractRef, input []byte, suppliedGas uint64, readOnly bool) (resBz []byte, usedGas uint64, err error) { snapshot := e.stateDB.Snapshot() ctx := e.stateDB.ContextOfSnapshot(snapshot).WithGasMeter(storetypes.NewGasMeter(suppliedGas)) @@ -159,11 +158,11 @@ func (e ERC20RegistryPrecompile) ExtendedRun(caller vm.ContractRef, input []byte } // RequiredGas implements vm.PrecompiledContract. -func (e ERC20RegistryPrecompile) RequiredGas(input []byte) uint64 { +func (e *ERC20RegistryPrecompile) RequiredGas(input []byte) uint64 { return 0 } // Run implements vm.PrecompiledContract. -func (e ERC20RegistryPrecompile) Run(input []byte) ([]byte, error) { +func (e *ERC20RegistryPrecompile) Run(input []byte) ([]byte, error) { return nil, errors.New("the ERC20RegistryPrecompile works exclusively with ExtendedRun") } diff --git a/x/evm/precompiles/erc20_registry/contract_test.go b/x/evm/precompiles/erc20_registry/contract_test.go index d7494f9..57126c9 100644 --- a/x/evm/precompiles/erc20_registry/contract_test.go +++ b/x/evm/precompiles/erc20_registry/contract_test.go @@ -76,7 +76,7 @@ func Test_ERC20RegistryPrecompile(t *testing.T) { // set context stateDB := NewMockStateDB(ctx) - registry = registry.WithStateDB(stateDB).(precompiles.ERC20RegistryPrecompile) + registry.SetStateDB(stateDB) erc20Addr := common.HexToAddress("0x1") accountAddr := common.HexToAddress("0x2") diff --git a/x/evm/types/address.go b/x/evm/types/address.go index 30b6e69..ed764c7 100644 --- a/x/evm/types/address.go +++ b/x/evm/types/address.go @@ -22,14 +22,6 @@ var CosmosPrecompileAddress common.Address = common.HexToAddress("0xf1") // 0xf2 ERC20Registry precompile address var ERC20RegistryPrecompileAddress common.Address = common.HexToAddress("0xf2") -// 0xf3 ERC721Registry precompile address -var ERC721RegistryPrecompileAddress common.Address = common.HexToAddress("0xf3") - -// IsPrecompileAddress checks if the address is a precompile address -func IsPrecompileAddress(addr common.Address) bool { - return addr == ERC20RegistryPrecompileAddress || addr == CosmosPrecompileAddress -} - // Parse string contract address to sdk.AccAddress func ContractAddressFromString(ac address.Codec, contractAddrInString string) (contractAddr common.Address, err error) { if common.IsHexAddress(contractAddrInString) { diff --git a/x/evm/types/expected_keeper.go b/x/evm/types/expected_keeper.go index 6546333..85ecd85 100644 --- a/x/evm/types/expected_keeper.go +++ b/x/evm/types/expected_keeper.go @@ -90,8 +90,8 @@ type StateDB interface { ContextOfSnapshot(i int) sdk.Context } -type WithStateDB interface { - WithStateDB(stateDB StateDB) vm.PrecompiledContract +type SetStateDB interface { + SetStateDB(stateDB StateDB) } type GRPCRouter interface {