Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: use tx gas limit for root trace #3719

Merged
merged 1 commit into from
Jul 11, 2023

Conversation

mattsse
Copy link
Collaborator

@mattsse mattsse commented Jul 11, 2023

ref #3678

the gas limit for the root trace should be the transaction's gas limit not the call input gas limit which already has init cost subtracted

that's also how geth does it

trace[0] is distinct in having tx instead of call-frame parameters. We might consider at some point making this distinction explicit by moving these fields into a separate object.

ref ethereum/go-ethereum#27029

cc @jsvisa

@mattsse mattsse added the A-rpc Related to the RPC implementation label Jul 11, 2023
@codecov
Copy link

codecov bot commented Jul 11, 2023

Codecov Report

Merging #3719 (c790428) into main (1763b5e) will decrease coverage by 0.02%.
The diff coverage is 0.00%.

Impacted file tree graph

Impacted Files Coverage Δ
crates/revm/revm-inspectors/src/tracing/mod.rs 0.00% <0.00%> (ø)

... and 9 files with indirect coverage changes

Flag Coverage Δ
integration-tests 15.87% <0.00%> (+0.01%) ⬆️
unit-tests 64.17% <0.00%> (-0.03%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

Components Coverage Δ
reth binary 26.31% <ø> (ø)
blockchain tree 81.58% <ø> (ø)
pipeline 87.11% <ø> (ø)
storage (db) 73.57% <ø> (ø)
trie 94.66% <ø> (ø)
txpool 48.78% <ø> (-0.61%) ⬇️
networking 77.89% <ø> (+0.09%) ⬆️
rpc 58.30% <ø> (+<0.01%) ⬆️
consensus 63.40% <ø> (ø)
revm 34.83% <0.00%> (-0.03%) ⬇️
payload builder 6.83% <ø> (ø)
primitives 88.23% <ø> (-0.02%) ⬇️

Copy link
Member

@Rjected Rjected left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@mattsse mattsse added this pull request to the merge queue Jul 11, 2023
Merged via the queue into main with commit 5dd4bc6 Jul 11, 2023
26 checks passed
@mattsse mattsse deleted the matt/use-tx-gas-limit-for-root-call branch July 11, 2023 21:32
merklefruit pushed a commit to anton-rs/op-reth that referenced this pull request Jul 18, 2023
merklefruit pushed a commit to merklefruit/op-reth-old that referenced this pull request Jul 26, 2023
merklefruit pushed a commit to anton-rs/op-reth that referenced this pull request Jul 27, 2023
mattsse pushed a commit to paradigmxyz/revm-inspectors that referenced this pull request Jul 25, 2024
## Description

This pull request is Part 1/2 of fixing the bug where the `gas` and
`gasUsed` fields in Parity Trace root are incorrect.

Part 2/2 paradigmxyz/reth#9761

## Related Issues and Pull Requests

- Follow: ethereum/go-ethereum#27029
- Improve: paradigmxyz/reth#3678 and paradigmxyz/reth#3719
- Fix: paradigmxyz/reth#9142 with #170 
- Update: paradigmxyz/reth#3782

## Problem

The `gas` and `gasUsed` fields in Geth Debug Trace root should be the
gas limit and gas used for the entire transaction.

However, two fields in Parity Trace root should be the original ones.

### Reproducible Example

With the latest version Reth v1.0.3, using `trace_transaction()` to
trace
the transaction
`0x03128677ee3a9623d20f3c677f423ccc592d126374bf32e331343dd1bdf38b61`

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

**From Reth**

```
gas: 0x55493 (349331)
gasUsed: 0x32d16 (208150)
```

**From
[Etherscan](https://etherscan.io/vmtrace?txhash=0x03128677ee3a9623d20f3c677f423ccc592d126374bf32e331343dd1bdf38b61&type=parity#raw)
and QuickNode**

```
gas: 0x4f227 (324135)
gasUsed: 0x36622 (222754)
```

## Solution for `revm-inspectors`

1. Not modify `gas_limit` and `gas_used` in the trace root

    ```diff
    - gas_limit = context.env.tx.gas_limit;
    - trace.set_root_trace_gas_used(gas_used);
- trace.gas_used = gas_used(context.spec_id(), gas.spent(),
gas.refunded() as u64);
    ```

2. The modification in Step 1 will cause another problem

The `gas` field for Geth Debug Trace root will also be reset (not the
gas limitation for the entire transaction).

therefore, can define `set_transaction_gas_limit()` and
`with_transaction_gas_limit()` for Geth Debug,

which is similar to current `set_transaction_gas_used()` and
`with_transaction_gas_used()` for Parity.

3. Then, modify the Reth Part: 

`crates/rpc/rpc/src/trace.rs` and `crates/rpc/rpc/src/debug.rs` to
completely fix the bug.

## Miscellaneous

- Actually, I love the current design, but the results are inconsistent
with those of others.

- When I used `make pr` to test the Reth Part, the issue
paradigmxyz/reth#9381 still exists for me.

    I should only skip tests for `lockfile` and test them seperately.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-rpc Related to the RPC implementation
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants