From 8a92aa9e1e6f58533b3cc9d7327ff90037028f52 Mon Sep 17 00:00:00 2001
From: codchen <codchen03@gmail.com>
Date: Fri, 26 Jul 2024 14:12:55 +0800
Subject: [PATCH] Fix log index on synthetic receipt (#1784)

# Conflicts:
#	app/receipt.go
---
 app/receipt.go      | 3 +++
 app/receipt_test.go | 1 +
 2 files changed, 4 insertions(+)

diff --git a/app/receipt.go b/app/receipt.go
index 703cc3ec7a..2afdb6465c 100644
--- a/app/receipt.go
+++ b/app/receipt.go
@@ -80,6 +80,9 @@ func (app *App) AddCosmosEventsToEVMReceiptIfApplicable(ctx sdk.Context, tx sdk.
 	var bloom ethtypes.Bloom
 	if receipt, err := app.EvmKeeper.GetTransientReceipt(ctx, txHash); err == nil && receipt != nil {
 		receipt.Logs = append(receipt.Logs, addedLogs...)
+		for i, l := range receipt.Logs {
+			l.Index = uint32(i)
+		}
 		bloom = ethtypes.CreateBloom(ethtypes.Receipts{&ethtypes.Receipt{Logs: evmkeeper.GetLogsForTx(receipt)}})
 		receipt.LogsBloom = bloom[:]
 		_ = app.EvmKeeper.SetTransientReceipt(ctx, txHash, receipt)
diff --git a/app/receipt_test.go b/app/receipt_test.go
index a76912f269..d1ce00052e 100644
--- a/app/receipt_test.go
+++ b/app/receipt_test.go
@@ -257,6 +257,7 @@ func TestEvmEventsForCw721(t *testing.T) {
 	require.Equal(t, 1, len(receipt.Logs))
 	require.NotEmpty(t, receipt.LogsBloom)
 	require.Equal(t, mockPointerAddr.Hex(), receipt.Logs[0].Address)
+	require.Equal(t, uint32(0), receipt.Logs[0].Index)
 	_, found = testkeeper.EVMTestApp.EvmKeeper.GetEVMTxDeferredInfo(ctx)
 	require.True(t, found)
 	require.Equal(t, common.HexToHash("0x2").Bytes(), receipt.Logs[0].Data)