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 app/ante/evm_delivertx.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ func DecorateNonceCallback(ctx sdk.Context, ek *evmkeeper.Keeper, evmAddr common
// bump nonce if it is for some reason not incremented (e.g. ante failure)
if ek.GetNonce(callCtx, evmAddr) == startingNonce {
ek.SetNonce(callCtx, evmAddr, startingNonce+1)
ek.SetNonceBumped(callCtx)
}
})
}
1 change: 1 addition & 0 deletions go.work.sum
Original file line number Diff line number Diff line change
Expand Up @@ -948,6 +948,7 @@ github.com/kataras/pio v0.0.11 h1:kqreJ5KOEXGMwHAWHDwIl+mjfNCPhAwZPa8gK7MKlyw=
github.com/kataras/sitemap v0.0.6 h1:w71CRMMKYMJh6LR2wTgnk5hSgjVNB9KL60n5e2KHvLY=
github.com/kataras/tunnel v0.0.4 h1:sCAqWuJV7nPzGrlb0os3j49lk2JhILT0rID38NHNLpA=
github.com/kballard/go-shellquote v0.0.0-20180428030007-95032a82bc51 h1:Z9n2FFNUXsshfwJMBgNA0RU6/i7WVaAegv3PtuIHPMs=
github.com/keybase/go-keychain v0.0.0-20190712205309-48d3d31d256d h1:Z+RDyXzjKE0i2sTjZ/b1uxiGtPhFy34Ou/Tk0qwN0kM=
github.com/kilic/bls12-381 v0.1.0 h1:encrdjqKMEvabVQ7qYOKu1OvhqpK4s47wDYtNiPtlp4=
github.com/kkdai/bstream v0.0.0-20161212061736-f391b8402d23 h1:FOOIBWrEkLgmlgGfMuZT83xIwfPDxEI2OHu6xUmJMFE=
github.com/klauspost/asmfmt v1.3.2 h1:4Ri7ox3EwapiOjCki+hw14RyKk201CN4rzyCJRFLpK4=
Expand Down
1 change: 1 addition & 0 deletions x/evm/ante/basic.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ func (gl BasicDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, simulate bool, n
// bump nonce if it is for some reason not incremented (e.g. ante failure)
if gl.k.GetNonce(callCtx, msg.Derived.SenderEVMAddr) == startingNonce {
gl.k.SetNonce(callCtx, msg.Derived.SenderEVMAddr, startingNonce+1)
gl.k.SetNonceBumped(callCtx)
}
})
}
Expand Down
3 changes: 3 additions & 0 deletions x/evm/keeper/abci.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,9 @@
for _, deferredInfo := range evmTxDeferredInfoList {
txHash := common.BytesToHash(deferredInfo.TxHash)
if deferredInfo.Error != "" && txHash.Cmp(ethtypes.EmptyTxsHash) != 0 {
if !k.GetNonceBumped(ctx, deferredInfo.TxIndex) {

Check warning

Code scanning / CodeQL

Panic in BeginBock or EndBlock consensus methods Warning

path flow from Begin/EndBlock to a panic call
path flow from Begin/EndBlock to a panic call
path flow from Begin/EndBlock to a panic call
path flow from Begin/EndBlock to a panic call
path flow from Begin/EndBlock to a panic call
continue
}
_ = k.SetTransientReceipt(ctx, txHash, &types.Receipt{
TxHashHex: txHash.Hex(),
TransactionIndex: deferredInfo.TxIndex,
Expand Down
53 changes: 53 additions & 0 deletions x/evm/keeper/abci_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
package keeper_test

import (
"testing"

"github.com/sei-protocol/sei-chain/app"
abci "github.com/sei-protocol/sei-chain/sei-tendermint/abci/types"
"github.com/sei-protocol/sei-chain/x/evm/types"
"github.com/stretchr/testify/require"
)

func TestEndBlock_NoReceiptForNonceMismatch(t *testing.T) {
a := app.Setup(t, false, false, false)
k := a.EvmKeeper
ctx := a.GetContextForDeliverTx([]byte{}).WithBlockHeight(8)

msg := mockEVMTransactionMessage(t)
etx, _ := msg.AsTransaction()
txHash := etx.Hash()

k.BeginBlock(ctx)
k.SetMsgs([]*types.MsgEVMTransaction{msg})
k.SetTxResults([]*abci.ExecTxResult{{Code: 1, Log: "nonce mismatch"}})
// No SetNonceBumped call — simulates a tx where startingNonce != txNonce,
// so the nonce bump callback was never registered/executed.
k.EndBlock(ctx, 0, 0)

_, err := k.GetTransientReceipt(ctx, txHash, 0)
require.Error(t, err, "should not create a receipt when nonce was not bumped")
}

func TestEndBlock_ReceiptCreatedWhenNonceBumped(t *testing.T) {
a := app.Setup(t, false, false, false)
k := a.EvmKeeper
ctx := a.GetContextForDeliverTx([]byte{}).WithBlockHeight(8)

msg := mockEVMTransactionMessage(t)
etx, _ := msg.AsTransaction()
txHash := etx.Hash()

k.BeginBlock(ctx)
k.SetMsgs([]*types.MsgEVMTransaction{msg})
k.SetTxResults([]*abci.ExecTxResult{{Code: 1, Log: "some ante error"}})
// Simulate that the nonce bump callback ran (startingNonce == txNonce).
k.SetNonceBumped(ctx.WithTxIndex(0))
k.EndBlock(ctx, 0, 0)

receipt, err := k.GetTransientReceipt(ctx, txHash, 0)
require.NoError(t, err, "should create a receipt when nonce was bumped")
require.Equal(t, txHash.Hex(), receipt.TxHashHex)
require.Equal(t, "some ante error", receipt.VmError)
require.Equal(t, uint64(8), receipt.BlockNumber)
}
12 changes: 12 additions & 0 deletions x/evm/keeper/deferred.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,18 @@ func (k *Keeper) AppendToEvmTxDeferredInfo(ctx sdk.Context, bloom ethtypes.Bloom
prefix.NewStore(ctx.TransientStore(k.transientStoreKey), types.DeferredInfoPrefix).Set(key, bz)
}

func (k *Keeper) SetNonceBumped(ctx sdk.Context) {
key := make([]byte, 8)
binary.BigEndian.PutUint64(key, uint64(ctx.TxIndex())) //nolint:gosec
prefix.NewStore(ctx.TransientStore(k.transientStoreKey), types.NonceBumpPrefix).Set(key, []byte{1})
}

func (k *Keeper) GetNonceBumped(ctx sdk.Context, txIndex uint32) bool {
key := make([]byte, 8)
binary.BigEndian.PutUint64(key, uint64(txIndex))
return prefix.NewStore(ctx.TransientStore(k.transientStoreKey), types.NonceBumpPrefix).Has(key)
}

func (k *Keeper) GetEVMTxDeferredInfo(ctx sdk.Context) (*types.DeferredInfo, bool) {
key := make([]byte, 8)
binary.BigEndian.PutUint64(key, uint64(ctx.TxIndex())) //nolint:gosec
Expand Down
1 change: 1 addition & 0 deletions x/evm/types/keys.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ var (
NextBaseFeePerGasPrefix = []byte{0x1c}
EvmOnlyBlockBloomPrefix = []byte{0x1d}
ZeroStorageCleanupCheckpointKey = []byte{0x1e}
NonceBumpPrefix = []byte{0x1f} // transient
)

var (
Expand Down
Loading