diff --git a/x/evm/keeper/keeper.go b/x/evm/keeper/keeper.go index 121b2118d..50bfafd8b 100644 --- a/x/evm/keeper/keeper.go +++ b/x/evm/keeper/keeper.go @@ -148,7 +148,11 @@ func (k *Keeper) GetHashFn(ctx sdk.Context) vm.GetHashFunc { func (k *Keeper) GetEVMTxDeferredInfo(ctx sdk.Context) (res []EvmTxDeferredInfo) { k.deferredInfo.Range(func(key, value any) bool { txIdx := key.(int) - if txIdx >= 0 && txIdx < len(k.txResults) && k.txResults[txIdx].Code == 0 { + if txIdx < 0 || txIdx >= len(k.txResults) { + ctx.Logger().Error(fmt.Sprintf("getting invalid tx index in EVM deferred info: %d, num of txs: %d", txIdx, len(k.txResults))) + return true + } + if k.txResults[txIdx].Code == 0 { res = append(res, *(value.(*EvmTxDeferredInfo))) } return true diff --git a/x/evm/keeper/wei_test.go b/x/evm/keeper/wei_test.go index 420a8654c..8885cfb97 100644 --- a/x/evm/keeper/wei_test.go +++ b/x/evm/keeper/wei_test.go @@ -12,6 +12,7 @@ import ( "github.com/sei-protocol/sei-chain/x/evm/state" "github.com/sei-protocol/sei-chain/x/evm/types" "github.com/stretchr/testify/require" + abci "github.com/tendermint/tendermint/abci/types" ) func TestSettleCommon(t *testing.T) { @@ -51,6 +52,7 @@ func TestSettleCommon(t *testing.T) { globalEscrowBalance := k.BankKeeper().GetBalance(ctx, k.AccountKeeper().GetModuleAddress(banktypes.WeiEscrowName), "usei") require.True(t, globalEscrowBalance.Amount.IsZero()) + k.SetTxResults([]*abci.ExecTxResult{{Code: 0}, {Code: 0}, {Code: 0}, {Code: 0}}) deferredInfo := k.GetEVMTxDeferredInfo(ctx) k.SettleWeiEscrowAccounts(ctx, deferredInfo) globalEscrowBalance = k.BankKeeper().GetBalance(ctx, k.AccountKeeper().GetModuleAddress(banktypes.WeiEscrowName), "usei") @@ -99,6 +101,7 @@ func TestSettleMultiRedeem(t *testing.T) { globalEscrowBalance := k.BankKeeper().GetBalance(ctx, k.AccountKeeper().GetModuleAddress(banktypes.WeiEscrowName), "usei") require.True(t, globalEscrowBalance.Amount.IsZero()) + k.SetTxResults([]*abci.ExecTxResult{{Code: 0}, {Code: 0}, {Code: 0}}) deferredInfo := k.GetEVMTxDeferredInfo(ctx) k.SettleWeiEscrowAccounts(ctx, deferredInfo) globalEscrowBalance = k.BankKeeper().GetBalance(ctx, k.AccountKeeper().GetModuleAddress(banktypes.WeiEscrowName), "usei")