paradigmxyz / reth

Modular, contributor-friendly and blazing-fast implementation of the Ethereum protocol, in Rust
https://reth.rs/
Apache License 2.0
3.8k stars 1.03k forks source link

Geth Debug Tracing Inconsistency when having selfdestruct #10554

Closed ZzPoLariszZ closed 1 week ago

ZzPoLariszZ commented 2 weeks ago

Describe the bug

If the selfdestruct can de derived from the root frame, the Geth debug tracing result is wrong.

Steps to reproduce

curl http://localhost:8545 \
-X POST \
-H "Content-Type: application/json" \
--data '{"method":"debug_traceTransaction","params":["0x95de6d33743576a762e720e4978a63e99238495abdbf79f459640c7c82d2a29f", {"tracer": "callTracer"}], "id":1,"jsonrpc":"2.0"}'

From Reth

{'calls': [{'from': '0x44d139f02b5819b4a12777a89706b33065311dbd',
            'gas': '0x0',
            'gasUsed': '0x0',
            'input': '0x',
            'type': 'SELFDESTRUCT'}],
 'from': '0xd9046c5d48ac38926978fc6193ae481e39c19810',
 'gas': '0x7530',
 'gasUsed': '0x6693',
 'input': '0x83197ef0',
 'to': '0x44d139f02b5819b4a12777a89706b33065311dbd',
 'type': 'CALL',
 'value': '0x0'}

From Etherscan and QuickNode

{'calls': [{'from': '0x44d139f02b5819b4a12777a89706b33065311dbd',
            'gas': '0x0',
            'gasUsed': '0x0',
            'input': '0x',
            'to': '0xd9046c5d48ac38926978fc6193ae481e39c19810',
            'type': 'SELFDESTRUCT',
            'value': '0x15becdbedc98e80'}],
 'from': '0xd9046c5d48ac38926978fc6193ae481e39c19810',
 'gas': '0x7530',
 'gasUsed': '0x6693',
 'input': '0x83197ef0',
 'to': '0x44d139f02b5819b4a12777a89706b33065311dbd',
 'type': 'CALL',
 'value': '0x0'}

The to field (selfdestruct_refund_target) and value field (selfdestruct_transferred_value) are missing.

Node logs

No response

Platform(s)

Linux (x86)

What version/commit are you on?

reth Version: 1.0.5

What database version are you on?

Current database version: 2 Local database version: 2

Which chain / network are you on?

mainnet

What type of node are you running?

Archive (default)

What prune config do you use, if any?

No response

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

No response

Code of Conduct

ZzPoLariszZ commented 2 weeks ago

Reason

The tracers field of inspector after this line: https://github.com/paradigmxyz/reth/blob/main/crates/rpc/rpc/src/debug.rs#L701

did not update the selfdestruct_refund_target and selfdestruct_transferred_value fields after the EVM executions.

traces: CallTraceArena {
        arena: [
            CallTraceNode {
                parent: None,
                children: [],
                idx: 0,
                trace: CallTrace {
                    depth: 0,
                    success: true,
                    caller: 0xd9046c5d48ac38926978fc6193ae481e39c19810,
                    address: 0x44d139f02b5819b4a12777a89706b33065311dbd,
                    maybe_precompile: None,
                    selfdestruct_refund_target: None,
                    selfdestruct_transferred_value: None,
                    kind: Call,
                    value: 0,
                    data: 0x83197ef0,
                    output: 0x,
                    gas_used: 5195,
                    gas_limit: 8936,
                    status: SelfDestruct,
                    steps: [],
                    decoded: DecodedCallTrace {
                        label: None,
                        return_data: None,
                        call_data: None,
                    },
                },
                logs: [],
                ordering: [],
            },
        ],
    },

May need to modify revm 🤔

mattsse commented 2 weeks ago

hmm, this is odd,

it looks like this is never called? https://github.com/paradigmxyz/evm-inspectors/blob/2c49c7cd81ee78faa5d58d5a6eac77cb8b05bb2b/src/tracing/mod.rs#L658-L661

I wonder if this has something to do with this being the root call or something else is wrong here:

https://github.com/paradigmxyz/evm-inspectors/blob/2c49c7cd81ee78faa5d58d5a6eac77cb8b05bb2b/src/tracing/builder/geth.rs#L128-L132

ZzPoLariszZ commented 2 weeks ago

I think this call is never called.

hmm, this is odd,

it looks like this is never called? https://github.com/paradigmxyz/evm-inspectors/blob/2c49c7cd81ee78faa5d58d5a6eac77cb8b05bb2b/src/tracing/mod.rs#L658-L661

Dealing with root call should be correct since it can correctly process its derived selfdestruct call like pushing into calls and handling the from address. I still believe that it is the inspector and revm problem, selfdestruct_refund_target and selfdestruct_transferred_value fields are not correctely updated (still None) after the EVM executions. Therefore, when root call deals with to and value fields in its derived selfdestruct call, two fields are missing.

I wonder if this has something to do with this being the root call or something else is wrong here:

https://github.com/paradigmxyz/evm-inspectors/blob/2c49c7cd81ee78faa5d58d5a6eac77cb8b05bb2b/src/tracing/builder/geth.rs#L128-L132

ZzPoLariszZ commented 1 week ago

This problem also happens when the SELFDESTRUCT can be derived from a DELEGATECALL

Example to Reproduce

curl http://localhost:8545 \
-X POST \
-H "Content-Type: application/json" \
--data '{"method":"debug_traceTransaction","params":["0xece7c7e45ff6a500a272676969cbdf6c4d5095484b7ea6d211eb3c4fb9f4544f", {"tracer": "callTracer"}], "id":1,"jsonrpc":"2.0"}'

From Reth

-- skip --
           {'calls': [{'calls': [{'from': '0x0a252663dbcc0b073063d6420a40319e438cfa59',
                                  'gas': '0x0',
                                  'gasUsed': '0x0',
                                  'input': '0x',
                                  'type': 'SELFDESTRUCT'}],
                       'from': '0xf0ef973bb461c54a4fd452c598da4ec5f696b9c2',
                       'gas': '0x29422',
                       'gasUsed': '0x14a8',
                       'input': '0x928dd2a7',
                       'to': '0x0a252663dbcc0b073063d6420a40319e438cfa59',
                       'type': 'DELEGATECALL',
                       'value': '0x0'}],
            'from': '0x0a252663dbcc0b073063d6420a40319e438cfa59',
            'gas': '0x29f1e',
            'gasUsed': '0x154b',
            'input': '0x928dd2a7',
            'to': '0xf0ef973bb461c54a4fd452c598da4ec5f696b9c2',
            'type': 'CALL',
            'value': '0x0'}],
-- skip --

From Etherscan and QuickNode

-- skip --
           {'calls': [{'calls': [{'from': '0xf0ef973bb461c54a4fd452c598da4ec5f696b9c2',
                                  'gas': '0x0',
                                  'gasUsed': '0x0',
                                  'input': '0x',
                                  'to': '0x0000000000000000000000000000000000000000',
                                  'type': 'SELFDESTRUCT',
                                  'value': '0x0'}],
                       'from': '0xf0ef973bb461c54a4fd452c598da4ec5f696b9c2',
                       'gas': '0x29422',
                       'gasUsed': '0x14a8',
                       'input': '0x928dd2a7',
                       'to': '0x0a252663dbcc0b073063d6420a40319e438cfa59',
                       'type': 'DELEGATECALL',
                       'value': '0x0'}],
            'from': '0x0a252663dbcc0b073063d6420a40319e438cfa59',
            'gas': '0x29f1e',
            'gasUsed': '0x154b',
            'input': '0x928dd2a7',
            'to': '0xf0ef973bb461c54a4fd452c598da4ec5f696b9c2',
            'type': 'CALL',
            'value': '0x0'}],
-- skip --

The to and value fields are missing in the SELFDESTRUCT call frame.

The from field is also incorrect, which should be same as

jsvisa commented 1 week ago

@mattsse @ZzPoLariszZ I think https://github.com/bluealloy/revm/pull/1746 will fix the first issue. I found the refund and value missing only happened in transactions which were before the cancun upgrade, the old ones were correct, eg 0x9aac76c9ed191da631b5e70c8824f2ad106a0f5147d57c611ed64653734dd85f

And for the second issue:

The from field is also incorrect, which should be same as

I think this may be another issue, maybe related to the delegatecall, will dig into it later.

ZzPoLariszZ commented 1 week ago

For the DELEGATECALL related, should we open another issue or just keep this issue open? @rakita

rakita commented 1 week ago

For the DELEGATECALL related, should we open another issue or just keep this issue open? @rakita

Can you test if delegatecall is fixed with selfdestruct fix. Not saying it is, but maybe they are related.