Skip to content

Use effectiveGasPrice for fee calculation on L2 networks#1386

Open
h45hc47 wants to merge 3 commits intotrezor:masterfrom
h45hc47:eth-l2-use-effective_gas_price
Open

Use effectiveGasPrice for fee calculation on L2 networks#1386
h45hc47 wants to merge 3 commits intotrezor:masterfrom
h45hc47:eth-l2-use-effective_gas_price

Conversation

@h45hc47
Copy link
Copy Markdown

@h45hc47 h45hc47 commented Jan 11, 2026

Problem

On L2 networks (Arbitrum, Optimism, Base, etc.), the fees field in API responses returns incorrect values.

Example from issue #1227:

Transaction: 0xc53e311af533dc185732c2299f7c585a8a65f8b5319ab82a1b01f03c86c3e97b

  • Blockbook returns: 66373200000000 (incorrect)
  • Arbiscan shows: 553110000000 (correct)

Root Cause

The fee was calculated as gasPrice * gasUsed, but gasPrice from the transaction is the "Gas Price Bid" (what user was willing to pay), not the actual price paid.
On L2 networks, the actual gas price (effectiveGasPrice) is returned in the transaction receipt and can differ significantly from the bid price.

Solution

  1. Added EffectiveGasPrice field to RpcReceipt struct
  2. Added field to protobuf schema for persistent storage
  3. Updated PackTx/UnpackTx to serialize/deserialize the new field
  4. Modified fee calculation in api/worker.go to use effectiveGasPrice when available, with fallback to gasPrice for older transactions

Files Changed

  • bchain/types_ethereum_type.go - Added EffectiveGasPrice to RpcReceipt
  • bchain/coins/eth/ethtx.proto - Added field to protobuf schema
  • bchain/coins/eth/ethtx.pb.go - Regenerated protobuf
  • bchain/coins/eth/ethparser.go - Updated Pack/Unpack andGetEthereumTxData
  • api/worker.go - Updated fee calculation logic

Testing

Verified on Arbitrum transactions from issue #1227 - fees now match Arbiscan values.

On L2 networks like Arbitrum, the gasPrice in transaction represents "Gas Price Bid", not the actual price paid. The actual price is returned as effectiveGasPrice in the transaction receipt.

This fix:
- Adds EffectiveGasPrice field to RpcReceipt struct
- Adds EffectiveGasPrice to protobuf schema for storage
- Updates fee calculation to use effectiveGasPrice when available, falling back to gasPrice for backward compatibility

Fixes incorrect fee display on Arbitrum, Optimism, Base and other L2 networks.

Closes trezor#1227
Copy link
Copy Markdown
Contributor

@pragmaxim pragmaxim left a comment

Choose a reason for hiding this comment

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

Hey, thanks for the contribution, it looks great! I found just two little issues :

And missing L1 fees in balance history fees, with inline comment.

Comment thread api/worker.go
@h45hc47
Copy link
Copy Markdown
Author

h45hc47 commented Feb 19, 2026

Sorry for that to take so long. Do i also need to add this field to blockbook-api.ts?

@h45hc47 h45hc47 requested a review from pragmaxim February 19, 2026 11:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants