Skip to content
This repository has been archived by the owner on Apr 4, 2024. It is now read-only.

feat!: Reject not replay-protected tx to prevent replay attack #1124

Merged
merged 12 commits into from
Jun 13, 2022
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,10 @@ Ref: https://keepachangelog.com/en/1.0.0/

## Unreleased

### State Machine Breaking

- (evm) [tharsis#]() Reject non-replay-protected tx in ante handler to prevent replay attack.
yihuang marked this conversation as resolved.
Show resolved Hide resolved

### Bug Fixes

* (evm) [tharsis#1118](https://github.com/tharsis/ethermint/pull/1118) Fix `Type()` `Account` method `EmptyCodeHash` comparison
Expand Down
7 changes: 6 additions & 1 deletion app/ante/eth.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,12 @@ func (esvd EthSigVerificationDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, s
return ctx, sdkerrors.Wrapf(sdkerrors.ErrUnknownRequest, "invalid message type %T, expected %T", msg, (*evmtypes.MsgEthereumTx)(nil))
}

sender, err := signer.Sender(msgEthTx.AsTransaction())
ethTx := msgEthTx.AsTransaction()
if !ethTx.Protected() {
fedekunze marked this conversation as resolved.
Show resolved Hide resolved
fedekunze marked this conversation as resolved.
Show resolved Hide resolved
return ctx, sdkerrors.Wrapf(sdkerrors.ErrUnknownRequest, "eth tx is not replay-protected")
}

sender, err := signer.Sender(ethTx)
if err != nil {
return ctx, sdkerrors.Wrapf(
sdkerrors.ErrorInvalidSigner,
Expand Down
6 changes: 6 additions & 0 deletions app/ante/eth_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,11 @@ func (suite AnteTestSuite) TestEthSigVerificationDecorator() {
err := signedTx.Sign(suite.ethSigner, tests.NewSigner(privKey))
suite.Require().NoError(err)

unprotectedTx := evmtypes.NewTxContract(nil, 1, big.NewInt(10), 1000, big.NewInt(1), nil, nil, nil, nil)
unprotectedTx.From = addr.Hex()
err = unprotectedTx.Sign(ethtypes.HomesteadSigner{}, tests.NewSigner(privKey))
suite.Require().NoError(err)

testCases := []struct {
name string
tx sdk.Tx
Expand All @@ -38,6 +43,7 @@ func (suite AnteTestSuite) TestEthSigVerificationDecorator() {
false,
},
{"successful signature verification", signedTx, false, true},
{"invalid, not replay-protected", unprotectedTx, false, false},
fedekunze marked this conversation as resolved.
Show resolved Hide resolved
}

for _, tc := range testCases {
Expand Down