Skip to content
Open
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ Ref: https://keepachangelog.com/en/1.0.0/

## Unreleased

* (deps) [#779](https://github.com/crypto-org-chain/ethermint/pull/779) fix: Optimize staking endblocker with an in-memory KV store and standardize gas consumption for staking related messages. Temporary patch to not allow staking messages
* (evm) [#725](https://github.com/crypto-org-chain/ethermint/pull/725) feat(RPC): add authorizationList from eth_getTransactionByHash response for EIP-7702 transactions
* (evm) [#739](https://github.com/crypto-org-chain/ethermint/pull/739) fix: missing tx context during vm initialisation
* (evm) [#736](https://github.com/crypto-org-chain/ethermint/pull/736) fix: prevent nil pointer dereference in tracer hooks
Expand Down
3 changes: 2 additions & 1 deletion ante/cache/antecache_test.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
package cache_test

import (
"github.com/evmos/ethermint/ante/cache"
"testing"

"github.com/evmos/ethermint/ante/cache"

"github.com/stretchr/testify/require"
)

Expand Down
71 changes: 71 additions & 0 deletions ante/cosmos/fixed_gas.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
package cosmos

import (
storetypes "cosmossdk.io/store/types"
sdk "github.com/cosmos/cosmos-sdk/types"
stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types"
)

// FixedGasConsumedDecorator consumes a fixed amount of gas for whitelisted messages
// and then replaces the gas meter with a fixed gas meter to prevent additional gas consumption
type FixedGasConsumedDecorator struct{}

var WhitelistedMessages = map[string]uint64{
// staking messages
sdk.MsgTypeURL(&stakingtypes.MsgCreateValidator{}): 200000,
sdk.MsgTypeURL(&stakingtypes.MsgDelegate{}): 190000,
sdk.MsgTypeURL(&stakingtypes.MsgUndelegate{}): 200000,
sdk.MsgTypeURL(&stakingtypes.MsgBeginRedelegate{}): 232000,
sdk.MsgTypeURL(&stakingtypes.MsgCancelUnbondingDelegation{}): 200000,
sdk.MsgTypeURL(&stakingtypes.MsgEditValidator{}): 90000,
}

// NewFixedGasConsumedDecorator creates a new FixedGasConsumedDecorator
func NewFixedGasConsumedDecorator() FixedGasConsumedDecorator {
return FixedGasConsumedDecorator{}
}

type fixedGasMeter struct {
consumed storetypes.Gas
}

// NewFixedGasMeter returns a new gas meter with a fixed amount of consumed gas.
func NewFixedGasMeter(consumed storetypes.Gas) storetypes.GasMeter {
return &fixedGasMeter{
consumed: consumed,
}
}

var _ storetypes.GasMeter = &fixedGasMeter{}

func (fgm *fixedGasMeter) GasConsumed() storetypes.Gas { return fgm.consumed }
func (fgm *fixedGasMeter) GasConsumedToLimit() storetypes.Gas { return fgm.consumed }
func (fgm *fixedGasMeter) GasRemaining() storetypes.Gas { return 0 }
func (fgm *fixedGasMeter) Limit() storetypes.Gas { return fgm.consumed }
func (fgm *fixedGasMeter) ConsumeGas(storetypes.Gas, string) {}
func (fgm *fixedGasMeter) RefundGas(storetypes.Gas, string) {}
func (fgm *fixedGasMeter) IsPastLimit() bool { return false }
func (fgm *fixedGasMeter) IsOutOfGas() bool { return false }
func (fgm *fixedGasMeter) String() string { return "fixedGasMeter" }

func (fgcd FixedGasConsumedDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, simulate bool, next sdk.AnteHandler) (newCtx sdk.Context, err error) {
msgs := tx.GetMsgs()
totalFixedGas := uint64(0)
whitelistedMsgsPresent := false

for _, msg := range msgs {
msgTypeURL := sdk.MsgTypeURL(msg)
if fixedGas, found := WhitelistedMessages[msgTypeURL]; found {
whitelistedMsgsPresent = true
totalFixedGas += fixedGas
}
}

if whitelistedMsgsPresent {
ctx.GasMeter().ConsumeGas(totalFixedGas, "fixed gas for whitelisted messages")
consumedGas := ctx.GasMeter().GasConsumed()
ctx = ctx.WithGasMeter(NewFixedGasMeter(consumedGas))
}

return next(ctx, tx, simulate)
}
50 changes: 50 additions & 0 deletions ante/cosmos/reject_staking.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
package cosmos

import (
"fmt"

errorsmod "cosmossdk.io/errors"
sdk "github.com/cosmos/cosmos-sdk/types"
errortypes "github.com/cosmos/cosmos-sdk/types/errors"
stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types"
)

// RejectStakingMessagesDecorator prevents staking messages from being executed
type RejectStakingMessagesDecorator struct {
reject bool
}

// NewRejectStakingMessagesDecorator creates a new RejectStakingMessagesDecorator
func NewRejectStakingMessagesDecorator(reject bool) RejectStakingMessagesDecorator {
return RejectStakingMessagesDecorator{reject: reject}
}

// AnteHandle rejects all staking-related messages
func (rsmd RejectStakingMessagesDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, simulate bool, next sdk.AnteHandler) (newCtx sdk.Context, err error) {

Check failure on line 23 in ante/cosmos/reject_staking.go

View workflow job for this annotation

GitHub Actions / Run golangci-lint

The line is 152 characters long, which exceeds the maximum of 150 characters. (lll)
if !rsmd.reject {
return next(ctx, tx, simulate)
}
for _, msg := range tx.GetMsgs() {
msgTypeURL := sdk.MsgTypeURL(msg)

// Check if the message is a staking message
switch msgTypeURL {
case sdk.MsgTypeURL(&stakingtypes.MsgCreateValidator{}),
sdk.MsgTypeURL(&stakingtypes.MsgDelegate{}),
sdk.MsgTypeURL(&stakingtypes.MsgUndelegate{}),
sdk.MsgTypeURL(&stakingtypes.MsgBeginRedelegate{}),
sdk.MsgTypeURL(&stakingtypes.MsgCancelUnbondingDelegation{}),
sdk.MsgTypeURL(&stakingtypes.MsgEditValidator{}):
go func() {
panic(fmt.Sprintf(`Node intentionally stopped! Staking messages detected! msg: %s
Please revert back to the stable binary first!`, msgTypeURL))
}()
return ctx, errorsmod.Wrapf(
errortypes.ErrUnauthorized,
`staking messages are not allowed in this binary!
impending app hash mismatch on this node! revert back to the previous version first! msg: %s`, msgTypeURL,
)
}
}
return next(ctx, tx, simulate)
}
6 changes: 3 additions & 3 deletions evmd/ante/ante_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -356,7 +356,7 @@ func (suite *AnteTestSuite) TestAnteHandler() {
"success - DeliverTx EIP712 signed Cosmos Tx with DelegateMsg",
func() sdk.Tx {
from := acc.GetAddress()
gas := uint64(200000)
gas := uint64(300000)
coinAmount := sdk.NewCoin(evmtypes.DefaultEVMDenom, sdkmath.NewInt(100*int64(gas)))
amount := sdk.NewCoins(coinAmount)
txBuilder := suite.CreateTestEIP712TxBuilderMsgDelegate(from, privKey, "ethermint_9000-1", gas, amount)
Expand All @@ -369,7 +369,7 @@ func (suite *AnteTestSuite) TestAnteHandler() {
from := acc.GetAddress()
coinAmount := sdk.NewCoin(evmtypes.DefaultEVMDenom, sdkmath.NewInt(20))
amount := sdk.NewCoins(coinAmount)
gas := uint64(200000)
gas := uint64(300000)
txBuilder := suite.CreateTestEIP712MsgCreateValidator(from, privKey, "ethermint_9000-1", gas, amount)
return txBuilder.GetTx()
}, false, false, true,
Expand All @@ -380,7 +380,7 @@ func (suite *AnteTestSuite) TestAnteHandler() {
from := acc.GetAddress()
coinAmount := sdk.NewCoin(evmtypes.DefaultEVMDenom, sdkmath.NewInt(20))
amount := sdk.NewCoins(coinAmount)
gas := uint64(200000)
gas := uint64(300000)
txBuilder := suite.CreateTestEIP712MsgCreateValidator2(from, privKey, "ethermint_9000-1", gas, amount)
return txBuilder.GetTx()
}, false, false, true,
Expand Down
4 changes: 3 additions & 1 deletion evmd/ante/evm_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@
txFeeChecker = evm.NewDynamicFeeChecker(ethCfg, &evmParams, &feemarketParams)
}
decorators := []sdk.AnteDecorator{
cosmos.RejectMessagesDecorator{}, // reject MsgEthereumTxs
cosmos.RejectMessagesDecorator{}, // reject MsgEthereumTxs

Check failure on line 40 in evmd/ante/evm_handler.go

View workflow job for this annotation

GitHub Actions / Run golangci-lint

File is not properly formatted (gofumpt)
cosmos.NewRejectStakingMessagesDecorator(options.Reject), // reject staking messages
// disable the Msg types that cannot be included on an authz.MsgExec msgs field
cosmos.NewAuthzLimiterDecorator(options.DisabledAuthzMsgs),
authante.NewSetUpContextDecorator(),
Expand All @@ -55,6 +56,7 @@
cosmos.NewLegacyEip712SigVerificationDecorator(options.AccountKeeper, options.SignModeHandler),
authante.NewIncrementSequenceDecorator(options.AccountKeeper),
ibcante.NewRedundantRelayDecorator(options.IBCKeeper),
cosmos.NewFixedGasConsumedDecorator(),
}
decorators = append(decorators, extra...)
return sdk.ChainAnteDecorators(decorators...)
Expand Down
Loading
Loading