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

Pass enabled precompiles to geth #61

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 1 addition & 1 deletion app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -426,7 +426,7 @@ func NewEthermintApp(
appCodec, keys[evmtypes.StoreKey], tkeys[evmtypes.TransientKey],
authtypes.NewModuleAddress(govtypes.ModuleName),
app.AccountKeeper, app.BankKeeper, stakingKeeper, app.FeeMarketKeeper,
vm.NewEVM, tracer, evmSs,
vm.NewEVMWithEnabledPrecompiles, tracer, evmSs,
)

// Create IBC Keeper
Expand Down
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ require (
github.com/gorilla/mux v1.8.0
github.com/gorilla/websocket v1.5.0
github.com/grpc-ecosystem/grpc-gateway v1.16.0
github.com/holiman/uint256 v1.2.1
github.com/improbable-eng/grpc-web v0.15.0
github.com/onsi/ginkgo/v2 v2.9.1
github.com/onsi/gomega v1.27.4
Expand Down Expand Up @@ -142,6 +141,7 @@ require (
github.com/hashicorp/hcl v1.0.0 // indirect
github.com/hdevalence/ed25519consensus v0.1.0 // indirect
github.com/holiman/bloomfilter/v2 v2.0.3 // indirect
github.com/holiman/uint256 v1.2.1 // indirect
github.com/huandu/skiplist v1.2.0 // indirect
github.com/huin/goupnp v1.0.3 // indirect
github.com/inconshreveable/mousetrap v1.1.0 // indirect
Expand Down Expand Up @@ -223,7 +223,7 @@ replace (
github.com/99designs/keyring => github.com/cosmos/keyring v1.2.0
// Use cosmos-sdk fork with staking transfer events, and custom tally handler support
github.com/cosmos/cosmos-sdk => github.com/kava-labs/cosmos-sdk v0.47.10-kava.2
github.com/ethereum/go-ethereum => github.com/Kava-Labs/go-ethereum v1.10.27-0.20240308170502-da7973e5eee0
github.com/ethereum/go-ethereum => github.com/Kava-Labs/go-ethereum v1.10.27-0.20240513233504-6e038346780b
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If it relies on a specific geth git hash / pr, it would be useful to link to it in the pr description 😄 so its easier to track which requires which

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, it relies on latest commit of kava/release/1.10/ which is our main branch in geth fork.
So basically I just updated geth dependency, because I needed NewEVMWithEnabledPrecompiles which we recently merged into geth fork.

// 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.9.0
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -230,8 +230,8 @@ github.com/DataDog/datadog-go v3.2.0+incompatible/go.mod h1:LButxg5PwREeZtORoXG3
github.com/DataDog/zstd v1.5.0/go.mod h1:g4AWEaM3yOg3HYfnJ3YIawPnVdXJh9QME85blwSAmyw=
github.com/DataDog/zstd v1.5.2 h1:vUG4lAyuPCXO0TLbXvPv7EB7cNK1QV/luu55UHLrrn8=
github.com/DataDog/zstd v1.5.2/go.mod h1:g4AWEaM3yOg3HYfnJ3YIawPnVdXJh9QME85blwSAmyw=
github.com/Kava-Labs/go-ethereum v1.10.27-0.20240308170502-da7973e5eee0 h1:pPFzOjEZmihLk70TQRPUCWs8uar6nfh4vZ/I1r0zeso=
github.com/Kava-Labs/go-ethereum v1.10.27-0.20240308170502-da7973e5eee0/go.mod h1:/6CsT5Ceen2WPLI/oCA3xMcZ5sWMF/D46SjM/ayY0Oo=
github.com/Kava-Labs/go-ethereum v1.10.27-0.20240513233504-6e038346780b h1:gTLS1VJL+6TEcttEmQ9rAmm/UZZw23WlQf6n8R/Xjx0=
github.com/Kava-Labs/go-ethereum v1.10.27-0.20240513233504-6e038346780b/go.mod h1:tvRm5KYJQ6LT+uss34spIP1oi6JgCfsFYiMKwJLZr6M=
github.com/Knetic/govaluate v3.0.1-0.20171022003610-9aa49832a739+incompatible/go.mod h1:r7JcOSlj0wfOMncg0iLm8Leh48TZaKVeNIfJntJ2wa0=
github.com/Microsoft/go-winio v0.6.0 h1:slsWYD/zyx7lCXoZVlvQrj0hPTM1HI4+v1sIda2yDvg=
github.com/Microsoft/go-winio v0.6.0/go.mod h1:cTAf44im0RAYeL23bpB+fzCyDH2MJiz2BO69KH/soAE=
Expand Down
4 changes: 2 additions & 2 deletions gomod2nix.toml
Original file line number Diff line number Diff line change
Expand Up @@ -211,8 +211,8 @@ schema = 3
version = "v1.4.2"
hash = "sha256-g9MC558WBelvkVbOZMGrPz2B4OnYwrOWWkC7OHfc8TI="
[mod."github.com/ethereum/go-ethereum"]
version = "v1.10.27-0.20240308170502-da7973e5eee0"
hash = "sha256-/KkxjI8UtvtIriAcAySHQcmKyohO9W0vLdBLVo47myM="
version = "v1.10.27-0.20240513233504-6e038346780b"
hash = "sha256-4bTz1DhUk2dvcPog0hMrEFw96aVWyr/EjhfGmPI/CT0="
replaced = "github.com/Kava-Labs/go-ethereum"
[mod."github.com/felixge/httpsnoop"]
version = "v1.0.2"
Expand Down
6 changes: 3 additions & 3 deletions x/evm/keeper/params_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ func (suite *KeeperTestSuite) TestLegacyParamsKeyTableRegistration() {
cdc, storeKey, tKey, authtypes.NewModuleAddress("gov"),
ak,
nil, nil, nil, // OK to pass nil in for these since we only instantiate and use params
vm.NewEVM,
vm.NewEVMWithEnabledPrecompiles,
"",
unregisteredSubspace,
)
Expand Down Expand Up @@ -274,7 +274,7 @@ func (suite *KeeperTestSuite) TestRenamedFieldReturnsProperValueForLegacyParams(
cdc, storeKey, tKey, authtypes.NewModuleAddress("gov"),
ak,
nil, nil, nil,
vm.NewEVM,
vm.NewEVMWithEnabledPrecompiles,
"",
subspace,
)
Expand Down Expand Up @@ -306,7 +306,7 @@ func (suite *KeeperTestSuite) TestNilLegacyParamsDoNotPanic() {
cdc, storeKey, tKey, authtypes.NewModuleAddress("gov"),
ak,
nil, nil, nil, // OK to pass nil in for these since we only instantiate and use params
vm.NewEVM,
vm.NewEVMWithEnabledPrecompiles,
"",
subspace,
)
Expand Down
2 changes: 1 addition & 1 deletion x/evm/keeper/state_transition.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ func (k *Keeper) NewEVM(
tracer = k.Tracer(ctx, msg, cfg.ChainConfig)
}
vmConfig := k.VMConfig(ctx, msg, cfg, tracer)
return k.evmConstructor(blockCtx, txCtx, stateDB, cfg.ChainConfig, vmConfig)
return k.evmConstructor(blockCtx, txCtx, stateDB, cfg.ChainConfig, vmConfig, cfg.Params.EnabledPrecompileAddrs())
}

// GetHashFn implements vm.GetHashFunc for Ethermint. It handles 3 cases:
Expand Down
2 changes: 1 addition & 1 deletion x/evm/migrations/v3/store_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ func TestKeyTableCompatiabilityWithKeeper(t *testing.T) {
cdc, storeKey, tKey, authtypes.NewModuleAddress("gov"),
ak,
nil, nil, nil,
vm.NewEVM,
vm.NewEVMWithEnabledPrecompiles,
"",
subspace,
)
Expand Down
2 changes: 2 additions & 0 deletions x/evm/types/interfaces.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
paramtypes "github.com/cosmos/cosmos-sdk/x/params/types"
stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core"
ethtypes "github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/core/vm"
Expand Down Expand Up @@ -93,4 +94,5 @@ type Constructor func(
stateDB vm.StateDB,
chainConfig *params.ChainConfig,
config vm.Config,
enabledPrecompiles []common.Address,
) *vm.EVM
10 changes: 10 additions & 0 deletions x/evm/types/params.go
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,16 @@ func (p Params) EIPs() []int {
return eips
}

// EnabledPrecompileAddrs returns enabled precompiles as a list of addresses.
func (p Params) EnabledPrecompileAddrs() []common.Address {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add doc comment for public method, and some basic tests would be good

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed

addrs := make([]common.Address, len(p.EnabledPrecompiles))
for i, p := range p.EnabledPrecompiles {
addrs[i] = common.HexToAddress(p)
}

return addrs
}

func validateEVMDenom(i interface{}) error {
denom, ok := i.(string)
if !ok {
Expand Down
48 changes: 48 additions & 0 deletions x/evm/types/params_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,54 @@ func TestEnabledPrecompilesUniquenessInBytesRepr(t *testing.T) {
}
}

func TestEnabledPrecompileAddrs(t *testing.T) {
const (
addr1 = "0x1000000000000000000000000000000000000000"
addr2 = "0x2000000000000000000000000000000000000000"
)

testCases := []struct {
name string
getParams func() Params
expected []common.Address
}{
{
name: "enabled precompiles list is nil",
getParams: func() Params {
params := DefaultParams()
params.EnabledPrecompiles = nil
return params
},
expected: []common.Address{},
},
{
name: "enabled precompiles list is empty",
getParams: func() Params {
params := DefaultParams()
params.EnabledPrecompiles = []string{}
return params
},
expected: []common.Address{},
},
{
name: "enabled precompiles list is non-empty",
getParams: func() Params {
params := DefaultParams()
params.EnabledPrecompiles = []string{addr1, addr2}
return params
},
expected: []common.Address{common.HexToAddress(addr1), common.HexToAddress(addr2)},
},
}

for _, tc := range testCases {
t.Run(tc.name, func(t *testing.T) {
enabledPrecompileAddrs := tc.getParams().EnabledPrecompileAddrs()
require.Equal(t, tc.expected, enabledPrecompileAddrs)
})
}
}

func TestParamsEIPs(t *testing.T) {
extraEips := []int64{2929, 1884, 1344}
params := NewParams("ara", false, true, true, DefaultChainConfig(), extraEips, []EIP712AllowedMsg{})
Expand Down
Loading