Skip to content
This repository was archived by the owner on Nov 30, 2021. It is now read-only.

Commit d7bdbd7

Browse files
authored
Fix nonce issue for replay attack (#692)
* fix nonce issue for replay attack * fix lint * add to changelog
1 parent 4a619b1 commit d7bdbd7

File tree

3 files changed

+10
-8
lines changed

3 files changed

+10
-8
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,8 @@ Ref: https://keepachangelog.com/en/1.0.0/
4444

4545
### Bug Fixes
4646

47+
* (evm) [\#687](https://github.com/cosmos/ethermint/issues/687) Fix nonce check to explicitly check for the correct nonce, rather than a simple 'greater than' comparison.
48+
* (api) [\#687](https://github.com/cosmos/ethermint/issues/687) Returns error for a transaction with an incorrect nonce.
4749
* (evm) [\#674](https://github.com/cosmos/ethermint/issues/674) Reset all cache after account data has been committed in `EndBlock` to make sure every node state consistent.
4850
* (evm) [\#672](https://github.com/cosmos/ethermint/issues/672) Fix panic of `wrong Block.Header.AppHash` when restart a node with snapshot.
4951

app/ante/eth.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -257,7 +257,7 @@ func (nvd NonceVerificationDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, sim
257257
// if multiple transactions are submitted in succession with increasing nonces,
258258
// all will be rejected except the first, since the first needs to be included in a block
259259
// before the sequence increments
260-
if msgEthTx.Data.AccountNonce < seq {
260+
if msgEthTx.Data.AccountNonce != seq {
261261
return ctx, sdkerrors.Wrapf(
262262
sdkerrors.ErrInvalidSequence,
263263
"invalid nonce; got %d, expected %d", msgEthTx.Data.AccountNonce, seq,

rpc/namespaces/eth/api.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1000,16 +1000,16 @@ func (api *PublicEthereumAPI) generateFromArgs(args rpctypes.SendTxArgs) (*evmty
10001000
gasPrice = big.NewInt(ethermint.DefaultGasPrice)
10011001
}
10021002

1003-
if args.Nonce == nil {
1004-
// get the nonce from the account retriever and the pending transactions
1005-
nonce, err = api.accountNonce(api.clientCtx, args.From, true)
1006-
} else {
1007-
nonce = (uint64)(*args.Nonce)
1008-
}
1009-
1003+
// get the nonce from the account retriever and the pending transactions
1004+
nonce, err = api.accountNonce(api.clientCtx, args.From, true)
10101005
if err != nil {
10111006
return nil, err
10121007
}
1008+
if args.Nonce != nil {
1009+
if nonce != (uint64)(*args.Nonce) {
1010+
return nil, fmt.Errorf(fmt.Sprintf("invalid nonce; got %d, expected %d", (uint64)(*args.Nonce), nonce))
1011+
}
1012+
}
10131013

10141014
if args.Data != nil && args.Input != nil && !bytes.Equal(*args.Data, *args.Input) {
10151015
return nil, errors.New("both 'data' and 'input' are set and not equal. Please use 'input' to pass transaction call data")

0 commit comments

Comments
 (0)