Skip to content

Commit 2cbdd91

Browse files
committed
reject staking related messages
1 parent 9220f2d commit 2cbdd91

File tree

4 files changed

+44
-3
lines changed

4 files changed

+44
-3
lines changed

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ Ref: https://keepachangelog.com/en/1.0.0/
3737

3838
## Unreleased
3939

40-
* (deps) [#776](https://github.com/crypto-org-chain/ethermint/pull/776) fix: Optimize staking endblocker with an in-memory KV store and standardize gas consumption for staking related messages
40+
* (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
4141
* (evm) [#725](https://github.com/crypto-org-chain/ethermint/pull/725) feat(RPC): add authorizationList from eth_getTransactionByHash response for EIP-7702 transactions
4242
* (evm) [#739](https://github.com/crypto-org-chain/ethermint/pull/739) fix: missing tx context during vm initialisation
4343
* (evm) [#736](https://github.com/crypto-org-chain/ethermint/pull/736) fix: prevent nil pointer dereference in tracer hooks

ante/cosmos/reject_staking.go

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
package cosmos
2+
3+
import (
4+
errorsmod "cosmossdk.io/errors"
5+
sdk "github.com/cosmos/cosmos-sdk/types"
6+
errortypes "github.com/cosmos/cosmos-sdk/types/errors"
7+
stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types"
8+
)
9+
10+
// RejectStakingMessagesDecorator prevents staking messages from being executed
11+
type RejectStakingMessagesDecorator struct{}
12+
13+
// NewRejectStakingMessagesDecorator creates a new RejectStakingMessagesDecorator
14+
func NewRejectStakingMessagesDecorator() RejectStakingMessagesDecorator {
15+
return RejectStakingMessagesDecorator{}
16+
}
17+
18+
// AnteHandle rejects all staking-related messages
19+
func (rsmd RejectStakingMessagesDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, simulate bool, next sdk.AnteHandler) (newCtx sdk.Context, err error) {
20+
for _, msg := range tx.GetMsgs() {
21+
msgTypeURL := sdk.MsgTypeURL(msg)
22+
23+
// Check if the message is a staking message
24+
switch msgTypeURL {
25+
case sdk.MsgTypeURL(&stakingtypes.MsgCreateValidator{}),
26+
sdk.MsgTypeURL(&stakingtypes.MsgDelegate{}),
27+
sdk.MsgTypeURL(&stakingtypes.MsgUndelegate{}),
28+
sdk.MsgTypeURL(&stakingtypes.MsgBeginRedelegate{}),
29+
sdk.MsgTypeURL(&stakingtypes.MsgCancelUnbondingDelegation{}),
30+
sdk.MsgTypeURL(&stakingtypes.MsgEditValidator{}),
31+
sdk.MsgTypeURL(&stakingtypes.MsgUpdateParams{}):
32+
return ctx, errorsmod.Wrapf(
33+
errortypes.ErrUnauthorized,
34+
"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,
35+
)
36+
}
37+
}
38+
return next(ctx, tx, simulate)
39+
}

evmd/ante/evm_handler.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,8 @@ func newLegacyCosmosAnteHandlerEip712(ctx sdk.Context, options HandlerOptions, e
3737
txFeeChecker = evm.NewDynamicFeeChecker(ethCfg, &evmParams, &feemarketParams)
3838
}
3939
decorators := []sdk.AnteDecorator{
40-
cosmos.RejectMessagesDecorator{}, // reject MsgEthereumTxs
40+
cosmos.RejectMessagesDecorator{}, // reject MsgEthereumTxs
41+
cosmos.NewRejectStakingMessagesDecorator(), // reject staking messages
4142
// disable the Msg types that cannot be included on an authz.MsgExec msgs field
4243
cosmos.NewAuthzLimiterDecorator(options.DisabledAuthzMsgs),
4344
authante.NewSetUpContextDecorator(),

evmd/ante/handler_options.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,8 @@ func newCosmosAnteHandler(ctx sdk.Context, options HandlerOptions, extra ...sdk.
183183
txFeeChecker = evm.NewDynamicFeeChecker(ethCfg, &evmParams, &feemarketParams)
184184
}
185185
decorators := []sdk.AnteDecorator{
186-
cosmos.RejectMessagesDecorator{}, // reject MsgEthereumTxs
186+
cosmos.RejectMessagesDecorator{}, // reject MsgEthereumTxs
187+
cosmos.NewRejectStakingMessagesDecorator(), // reject staking messages
187188
// disable the Msg types that cannot be included on an authz.MsgExec msgs field
188189
cosmos.NewAuthzLimiterDecorator(options.DisabledAuthzMsgs),
189190
ante.NewSetUpContextDecorator(),

0 commit comments

Comments
 (0)