reth: incorrect gasUsed with debug_traceCallMany/debug_traceTransaction/debug_traceBlockByNumber and callTracer

Describe the bug

While simulating a tx/block with debug_traceCallMany/debug_traceTransaction/debug_traceBlockByNumber and callTracer, I’m getting incorrect gasUsed.

Steps to reproduce

block #17933760 correct gasUsed: 11,808,302 tx 0x28ef70e4edcd6ce7b7ec80bf516adcaf73da5c1be5fef1e9a37aa600a8e80a69 correct gasUsed: 51,214

def sum_gas_used(data):
    total = int(data['gasUsed'], 16)
    if 'calls' in data:
        for call in data['calls']:
            total += sum_gas_used(call)
    return total

# RPC request to -> eth_getBlockByNumber([
#     hex(17933760),
#     True
# ])
int(response["gasUsed"], 16)
# 11,808,302, correct

# RPC request to -> eth_getTransactionReceipt("0x28ef70e4edcd6ce7b7ec80bf516adcaf73da5c1be5fef1e9a37aa600a8e80a69")
int(response['gasUsed'], 16)
# 51,214, correct

# RPC request to -> debug_traceBlockByNumber([
#     hex(17933760), 
#     {
#         "tracer": "callTracer"
#     }
# ])
sum([sum_gas_used(tx['result']) for tx in response])
# 20,284,310, incorrect

# RPC request to -> debug_traceTransaction([
#     "0x28ef70e4edcd6ce7b7ec80bf516adcaf73da5c1be5fef1e9a37aa600a8e80a69",
#     {
#         "tracer": "callTracer"
#     }
# ])
sum_gas_used(response)
# 54,359, incorrect

# RPC request to -> debug_traceCallMany([
#     [
#         {
#             "transactions": [...], # response of eth_getBlockByNumber([hex(17933760), True])['transactions']
#             "blockOverride": {
#                 "number": hex(17933760),
#             }
#         }
#     ], 
#     {
#         "blockNumber": hex(17933760),
#         "transactionIndex": 0,
#     },
#     {
#         "tracer": "callTracer",
#         "tracerConfig": {
#             "onlyTopCall": False,
#             "withLog": False
#         }
#     }
# ])
sum([sum_gas_used(x) for x in response])
# 20,284,310, incorrect

Node logs

No response

Platform(s)

Linux (x86)

What version/commit are you on?

reth Version: 0.1.0-alpha.6
Commit SHA: 639a6eac
Build Timestamp: 2023-08-17T10:45:03.473434751Z
Build Features: default,jemalloc
Build Profile: maxperf

What database version are you on?

Current database version: 1
Local database version: 1

If you’ve built Reth from source, provide the full command you used

LD_PRELOAD=/usr/local/lib/libjemalloc.so RUSTFLAGS="-C target-cpu=native" cargo build --profile maxperf --features jemalloc

Code of Conduct

  • I agree to follow the Code of Conduct

About this issue

  • Original URL
  • State: closed
  • Created 10 months ago
  • Comments: 23 (1 by maintainers)

Most upvoted comments

the tracing fix does not require any db changes

it only changes what values are used when re-executing the transaction to populate the trace

thanks for flagging, for calltracer, this should be fixed by #4293

works now! thank you!