1

I am testing Ethereum on a private network. While verifying the transaction fees received by a validator, I noticed a slight discrepancy between the calculated transaction fee and the actual transaction fee.

Here are the values retrieved

From eth.getTransactionReceipt:

{
  blockHash: "0x35291ba92d58e8427e19a5e5c485e5c5f05585bcd0a84084ab5167c3180894b7",
  blockNumber: 812,
  contractAddress: null,
  cumulativeGasUsed: 21000,
  effectiveGasPrice: 1000000007,
  from: "0x123463a4b065722e99115d6c222f267d9cabb524",
  gasUsed: 21000,
  logs: [],
  logsBloom: "0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
  status: "0x1",
  to: "0xdbd40e5d7f282700aa28315129b550e4b2bd3449",
  transactionHash: "0xec9b83ff08a6157d88a7205ebd1724abd0c4f0a6472900000eeda82c5b282694",
  transactionIndex: 0,
  type: "0x2"
}

From eth.getBlock:

{
  baseFeePerGas: 7,
  difficulty: 0,
  extraData: "0xd883010e0c846765746888676f312e32322e32856c696e7578",
  gasLimit: 30000000,
  gasUsed: 21000,
  hash: "0x35291ba92d58e8427e19a5e5c485e5c5f05585bcd0a84084ab5167c3180894b7",
  logsBloom: "0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
  miner: "0xdbd40e5d7f282700aa28315129b550e4b2bd3449",
  mixHash: "0xa44d27625f3f7553202488b20178d8707382c47a602712ecd0099feb79e8d19a",
  nonce: "0x0000000000000000",
  number: 812,
  parentHash: "0x4e86939660aa9db3d2393714ed73caeec15539c8da664685afb042fdada035c4",
  receiptsRoot: "0xf78dfb743fbd92ade140711c8bbc542b5e307f0ab7984eff35d751969fe57efa",
  sha3Uncles: "0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347",
  size: 696,
  stateRoot: "0x833b1f64f3351d7a7ef5a3432d4c8c37ae8979e0c181d014ca33974fb2655244",
  timestamp: 1732533924,
  totalDifficulty: 1,
  transactions: ["0xec9b83ff08a6157d88a7205ebd1724abd0c4f0a6472900000eeda82c5b282694"],
  transactionsRoot: "0xdc94dacc92cfa43ed2834ab65a3aa95f7744c3600502d841002ab5375a86c1c3",
  uncles: [],
  withdrawals: [],
  withdrawalsRoot: "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421"
}

To calculate the transaction fee received by the validator, I used the formula:

gasUsed × (effectiveGasPrice − baseFeePerGas) ⇒21000 × (1000000007 − 7) = 21,000000000000

Calculated fee (from the formula): 21,000,000,000,000 wei

Actual fee received: 20,999,999,979,520 wei

What causes the discrepancy between the calculated fee and the actual fee received?

3 Answers 3

1

The actual fee varies because integer truncation occuring on the EVM to ensure it falls short rather than overspends, which would cause some instability and vulnerability in macro.

If the actual EffectiveGasPrice calculation involves truncating a fractional wei value, e.g

1000000007−7

is performed internally with more precision, such as including fractions of wei (even though fractions aren’t usually shown). Thereby

Effective Gas Price − Base Fee Per Gas = 1000000000.0001wei (hypothetical)

This represents a tiny fractional value (0.0001 wei) that would not appear in your inputs. Likely Cause: Truncation of Per-Gas Calculations The key computation involves the per-gas reward:

EffectiveGasPrice − BaseFeePerGas

If this subtraction doesn't perfectly divide into GasUsed, the truncation happens per-gas-unit, introducing a cumulative error.

Example with a Small Adjustment

Let’s hypothesize a slight adjustment in the EffectiveGasPrice after subtracting BaseFeePerGas:

EffectiveGasPrice − BaseFeePerGas = 1000000000 − ϵ

where

𝜖 is a small value caused by rounding or truncation.

If

𝜖 = 0.000022857142857

we get:

(1000000000 − ϵ) × 21000 ≈ 20,999,999,979,520 wei (reverse engineering the result)

There is also some variability in the cost of assembly operations internally, meaning likely each time you run this calculation you'll get a non-constant discrepancy over many tx's.

1

The observed discrepancy:

21,000,000,000,000 − 20,999,999,979,520 = 20,480 Wei

It's likely due to rounding and truncation errors during internal gas price calculations or fee allocations.

These small differences are expected and within the bounds of precision limitations in Ethereum’s gas system.

One possibility is that the baseFeePerGas reported as 7 Wei could be an approximation, and the actual internal value used might include fractional wei values not shown in the JSON output.

0

I apologize. Upon reviewing the source code, I found that Geth was correctly handling fees as integers. The discrepancies were consistently caused by my test environment, where the balance was being processed as a floating-point number.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.