bsc icon indicating copy to clipboard operation
bsc copied to clipboard

eth/tracers/native: add log index field to callTracer output

Open Copilot opened this issue 1 month ago • 11 comments

  • [x] Analyze the issue and understand the expected behavior
  • [x] Identify the relevant code in eth/tracers/native/call.go
  • [x] Add Index field to callLog struct in call.go
  • [x] Update OnLog function to populate the Index field from log.Index
  • [x] Update erc7562.go to also include Index in log output
  • [x] Update test struct in calltrace_test.go to include Index field
  • [x] Update test data files to include index field in expected output
  • [x] Run existing tests to verify the changes work correctly
  • [x] Run code review and address any feedback
  • [x] Run CodeQL security checks
  • [x] Fix commit message format to follow BSC conventions

Summary

This PR adds the missing index field to the log entries returned by debug_traceTransaction when using the callTracer with withLog: true.

Problem

When calling debug_traceTransaction with the callTracer and withLog: true config, the returned logs were missing the index field which indicates the position of each log in the block/transaction. This made it inconsistent with other implementations like Erigon that include this field.

Solution

  • Added Index field of type hexutil.Uint to the callLog struct in eth/tracers/native/call.go
  • Updated the OnLog function to populate the Index field from log.Index (which is set by the EVM state during log emission)
  • Applied the same fix to erc7562.go tracer for consistency
  • Updated all test files to expect the new index field in log output

Example Output

{
  "logs": [
    {
      "address": "0xf4eced2f682ce333f96f2d8966c613ded8fc95dd",
      "topics": ["0xddf252ad..."],
      "data": "0x...",
      "position": "0x0",
      "index": "0x0"
    }
  ]
}
Original prompt

This section details on the original issue you should resolve

<issue_title>debug_traceTransaction missing log index</issue_title> <issue_description>#### System information Geth version: v1.6.3 OS & Version: Linux Arguments:

ExecStart=/usr/local/bin/geth \
  --datadir=/data/geth/ \
  --http \
  --http.port=8545 \
  --http.addr=0.0.0.0 \
  --http.api=eth,txpool,net,web3,debug \
  --http.vhosts="*" \
  --http.corsdomain="*" \
  --ws \
  --ws.port=8546 \
  --ws.addr=0.0.0.0 \
  --ws.origins="*" \
  --ws.api=eth,txpool,net,web3,debug \
  --networkid=56 \
  --verbosity=3 \
  --syncmode=full \
  --gcmode=archive \
  --state.scheme=path \
  --history.state=0 \
  --history.transactions=0 \
  --maxpeers=100 \
  --metrics \
  --metrics.addr=0.0.0.0 \
  --metrics.port="6060" \
  --cache=51200 \
  --cache.database=50 \
  --cache.trie=30 \
  --cache.snapshot=15 \
  --cache.gc=5 \
  --cache.blocklogs=1024 \
  --triesInMemory=256 \
  --rpc.allow-unprotected-txs=true \
  --rpc.gascap=0 \
  --miner.gasprice=50000000 \
  --txpool.pricelimit=50000000 \
  --rpc.batch-response-max-size=250000000

Description

  • Steps to reproduce the behaviour call:
{
  "jsonrpc": "2.0",
  "id": 12120,
  "method": "debug_traceTransaction",
  "params": [
    "0xec1081486c18067d6fa39aa5eae131955da91d6194fd1cbdb541330328ce5c1a",
    {
      "tracer": "callTracer",
      "tracerConfig": {
        "onlyTopCall": false,
        "withLog": true
      }
    }
  ]
}
  • Expected behaviour Logs have indexes.

  • Actual behaviour Indexes are missing for logs.

left: geth, right: erigon

Image

Comments on the Issue (you are @copilot in this section)

  • Fixes bnb-chain/bsc#3474

💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Copilot avatar Dec 05 '25 01:12 Copilot

@copilot go-ethereum has the same issue?

buddh0 avatar Dec 05 '25 02:12 buddh0

@copilot go-ethereum has the same issue?

Yes, go-ethereum has the same issue. Their callLog struct in eth/tracers/native/call.go also lacks the index field - it only has Address, Topics, Data, and Position. This fix could be upstreamed to go-ethereum as well.

Copilot avatar Dec 05 '25 02:12 Copilot

@copilot go-ethereum has the same issue?

Yes, go-ethereum has the same issue. Their callLog struct in eth/tracers/native/call.go also lacks the index field - it only has Address, Topics, Data, and Position. This fix could be upstreamed to go-ethereum as well.

@copilot so I think, bsc aligning the beheaviour with go-thereum is better, what's your opion?

buddh0 avatar Dec 05 '25 02:12 buddh0

@copilot go-ethereum has the same issue?

Yes, go-ethereum has the same issue. Their callLog struct in eth/tracers/native/call.go also lacks the index field - it only has Address, `T...

That's a fair point. The tradeoff is:

Align with go-ethereum (revert this PR): Maintains consistency with upstream, but leaves users without the index field that Erigon provides.

Keep this fix: Provides better compatibility with tools expecting Erigon-style output, but diverges from go-ethereum.

If you prefer aligning with go-ethereum, I can revert these changes. Let me know your decision.

Copilot avatar Dec 05 '25 02:12 Copilot

the Lint CI fails:

in bsc, the commit msg begins with the path of mainly changed files, so the commit msg begin with "eth/tracers/native:" is better, also watch the total length of msg @copilot

buddh0 avatar Dec 05 '25 02:12 buddh0

the Lint CI fails:

in bsc, the commit msg begins with the path of mainly changed files, so the commit msg begin with "eth/tracers/native:" is better, also watch the total length of msg ...

Fixed the commit message format in 1444613: eth/tracers/native: add log index field to callTracer output

Copilot avatar Dec 05 '25 02:12 Copilot

@copilot please solve this issue base on latest develop branch, not master

buddh0 avatar Dec 05 '25 06:12 buddh0

@copilot please solve this issue base on latest develop branch, not master

I cannot rebase or change the branch base directly as I don't have access to force push. The current branch is based on master (v1.6.4), which is a merge commit from develop.

Options:

  1. You can rebase this branch onto develop manually
  2. I can create a new PR description noting it should target develop instead of master
  3. Close this PR and I can describe the changes needed for someone to apply on develop

Please let me know how you'd like to proceed.

Copilot avatar Dec 05 '25 06:12 Copilot

based

ok, I have done it manually

buddh0 avatar Dec 05 '25 06:12 buddh0

شماهرراهی که دسترسی بدهدراانجام دهید،مجوز دارید

در تاریخ جمعه ۵ دسامبر ۲۰۲۵،‏ ۰۹:۳۹ buddho @.***> نوشت:

buddh0 left a comment (bnb-chain/bsc#3476) https://github.com/bnb-chain/bsc/pull/3476#issuecomment-3615451319

based

ok, I have done it manually

— Reply to this email directly, view it on GitHub https://github.com/bnb-chain/bsc/pull/3476#issuecomment-3615451319, or unsubscribe https://github.com/notifications/unsubscribe-auth/BELDIUQ3QTQZJMBOSWP3E4T4AEOTFAVCNFSM6AAAAACODKF5WWVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZTMMJVGQ2TCMZRHE . You are receiving this because you are subscribed to this thread.Message ID: @.***>

kuordstankm13545 avatar Dec 07 '25 00:12 kuordstankm13545

جناب کمک خلبان ازطرف من اجازه دارندکه هرراهی که به ختم هرچه سریعتراین قضیه میشود راانجام دهید

در تاریخ جمعه ۵ دسامبر ۲۰۲۵،‏ ۰۶:۱۵ Copilot @.***> نوشت:

Copilot left a comment (bnb-chain/bsc#3476) https://github.com/bnb-chain/bsc/pull/3476#issuecomment-3615086963

the Lint CI fails:

in bsc, the commit msg begins with the path of mainly changed files, so the commit msg begin with "eth/tracers/native:" is better, also watch the total length of msg ...

Fixed the commit message format in 1444613 https://github.com/bnb-chain/bsc/commit/1444613c9ae42f55fecef65b41e4c84e46126fe6: eth/tracers/native: add log index field to callTracer output

— Reply to this email directly, view it on GitHub https://github.com/bnb-chain/bsc/pull/3476#issuecomment-3615086963, or unsubscribe https://github.com/notifications/unsubscribe-auth/BELDIUR6WMLILUAV4O5XYKL4ADWUBAVCNFSM6AAAAACODKF5WWVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZTMMJVGA4DMOJWGM . You are receiving this because you are subscribed to this thread.Message ID: @.***>

kuordstankm13545 avatar Dec 07 '25 00:12 kuordstankm13545