Skip to content
Merged
20 changes: 1 addition & 19 deletions ante/evm/05_signature_verification.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,9 @@ func NewEthSigVerificationDecorator(ek anteinterfaces.EVMKeeper) EthSigVerificat
// Failure in RecheckTx will prevent tx to be included into block, especially when CheckTx succeed, in which case user
// won't see the error message.
func (esvd EthSigVerificationDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, simulate bool, next sdk.AnteHandler) (newCtx sdk.Context, err error) {
evmParams := esvd.evmKeeper.GetParams(ctx)
ethCfg := evmtypes.GetEthChainConfig()
blockNum := big.NewInt(ctx.BlockHeight())
signer := ethtypes.MakeSigner(ethCfg, blockNum, uint64(ctx.BlockTime().Unix())) //#nosec G115 -- int overflow is not a concern here
allowUnprotectedTxs := evmParams.GetAllowUnprotectedTxs()

msgs := tx.GetMsgs()
if msgs == nil {
Expand All @@ -49,7 +47,7 @@ func (esvd EthSigVerificationDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, s
return ctx, errorsmod.Wrapf(errortypes.ErrUnknownRequest, "invalid message type %T, expected %T", msg, (*evmtypes.MsgEthereumTx)(nil))
}

err := SignatureVerification(msgEthTx, msgEthTx.AsTransaction(), signer, allowUnprotectedTxs)
err := SignatureVerification(msgEthTx, msgEthTx.AsTransaction(), signer)
if err != nil {
return ctx, err
}
Expand All @@ -66,23 +64,7 @@ func SignatureVerification(
msg *evmtypes.MsgEthereumTx,
ethTx *ethtypes.Transaction,
signer ethtypes.Signer,
allowUnprotectedTxs bool,
) error {
ethCfg := evmtypes.GetEthChainConfig()

if !allowUnprotectedTxs {
if !ethTx.Protected() {
return errorsmod.Wrapf(
errortypes.ErrNotSupported,
"rejected unprotected ethereum transaction; please sign your transaction according to EIP-155 to protect it against replay-attacks")
}
if ethTx.ChainId().Uint64() != ethCfg.ChainID.Uint64() {
return errorsmod.Wrapf(
errortypes.ErrInvalidChainID,
"rejected ethereum transaction with incorrect chain-id; expected %d, got %d", ethCfg.ChainID, ethTx.ChainId())
}
}

if err := msg.VerifySender(signer); err != nil {
return errorsmod.Wrapf(errortypes.ErrorInvalidSigner, "signature verification failed: %s", err.Error())
}
Expand Down
1 change: 0 additions & 1 deletion ante/evm/mono_decorator.go
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,6 @@ func (md MonoDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, simulate bool, ne
ethMsg,
ethTx,
decUtils.Signer,
decUtils.EvmParams.AllowUnprotectedTxs,
); err != nil {
return ctx, err
}
Expand Down
625 changes: 279 additions & 346 deletions api/cosmos/evm/vm/v1/evm.pulsar.go

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions proto/cosmos/evm/vm/v1/evm.proto
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
option go_package = "github.com/cosmos/evm/x/vm/types";

// Params defines the EVM module parameters
message Params {

Check failure on line 11 in proto/cosmos/evm/vm/v1/evm.proto

View workflow job for this annotation

GitHub Actions / break-check

Previously present field "5" with name "allow_unprotected_txs" on message "Params" was deleted.
option (amino.name) = "cosmos/evm/x/vm/Params";
// evm_denom represents the token denomination used to run the EVM state
// transitions.
Expand All @@ -20,9 +20,9 @@
(gogoproto.customname) = "ExtraEIPs",
(gogoproto.moretags) = "yaml:\"extra_eips\""
];
// allow_unprotected_txs defines if replay-protected (i.e non EIP155
// signed) transactions can be executed on the state machine.
bool allow_unprotected_txs = 5;
// Acceptance of non-protected transactions (i.e non EIP-155 signed)
// is managed independently by each node.
reserved 5;
// renamed active_precompiles to active_static_precompiles
reserved 6;
// evm_channels is the list of channel identifiers from EVM compatible chains
Expand Down
24 changes: 9 additions & 15 deletions tests/integration/ante/test_evm_ante.go
Original file line number Diff line number Diff line change
Expand Up @@ -1264,14 +1264,13 @@ func (s *EvmAnteTestSuite) TestEthSigVerificationDecorator() {
s.Require().NoError(err)

testCases := []struct {
name string
tx sdk.Tx
allowUnprotectedTxs bool
reCheckTx bool
expPass bool
name string
tx sdk.Tx
reCheckTx bool
expPass bool
}{
{"ReCheckTx", &utiltx.InvalidTx{}, false, true, false},
{"invalid transaction type", &utiltx.InvalidTx{}, false, false, false},
{"ReCheckTx", &utiltx.InvalidTx{}, true, false},
{"invalid transaction type", &utiltx.InvalidTx{}, false, false},
{
"invalid sender",
evmtypes.NewTx(&evmtypes.EvmTxArgs{
Expand All @@ -1281,20 +1280,16 @@ func (s *EvmAnteTestSuite) TestEthSigVerificationDecorator() {
GasLimit: 1000,
GasPrice: big.NewInt(1),
}),
true,
false,
false,
},
{"successful signature verification", signedTx, false, false, true},
{"invalid, reject unprotected txs", unprotectedTx, false, false, false},
{"successful, allow unprotected txs", unprotectedTx, true, false, true},
{"successful signature verification", signedTx, false, true},
{"invalid, reject unprotected txs", unprotectedTx, false, false},
{"successful, allow unprotected txs", unprotectedTx, false, true},
}

for _, tc := range testCases {
s.Run(tc.name, func() {
s.WithEvmParamsOptions(func(params *evmtypes.Params) {
params.AllowUnprotectedTxs = tc.allowUnprotectedTxs
})
s.SetupTest()
dec := ethante.NewEthSigVerificationDecorator(s.GetNetwork().App.GetEVMKeeper())
_, err := dec.AnteHandle(s.GetNetwork().GetContext().WithIsReCheckTx(tc.reCheckTx), tc.tx, false, testutil.NoOpNextFn)
Expand All @@ -1306,7 +1301,6 @@ func (s *EvmAnteTestSuite) TestEthSigVerificationDecorator() {
}
})
}
s.WithEvmParamsOptions(nil)
}

func (s *EvmAnteTestSuite) TestSignatures() {
Expand Down
15 changes: 0 additions & 15 deletions tests/integration/x/vm/test_params.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,21 +63,6 @@ func (s *KeeperTestSuite) TestParams() {
},
true,
},
{
"success - Check AllowUnprotectedTxs param is set to false and can be retrieved correctly",
func() interface{} {
params := defaultChainEVMParams
params.AllowUnprotectedTxs = false
err := s.Network.App.GetEVMKeeper().SetParams(s.Network.GetContext(), params)
s.Require().NoError(err)
return params.AllowUnprotectedTxs
},
func() interface{} {
evmParams := s.Network.App.GetEVMKeeper().GetParams(s.Network.GetContext())
return evmParams.GetAllowUnprotectedTxs()
},
true,
},
{
name: "success - Active precompiles are sorted when setting params",
paramsFun: func() interface{} {
Expand Down
Loading
Loading