Fee formula
willow-fee-v1 is the formula Willow uses for eth_gasPrice,
eth_maxPriorityFeePerGas, eth_blobBaseFee, and eth_feeHistory. It reads
nothing but verified blocks, so anyone can recompute each value from
willow_getFeeProof
or
willow_getFeeHistoryProof,
which carry exactly the headers and bodies the formula reads. The standard fee
methods return the formula at the newest block Willow serves, and the
verifying client computes it at the newest block it
has anchored.
The formula is ported line for line from geth v1.17.10 (consensus/misc/eip1559,
consensus/misc/eip4844, eth/gasprice) and, on the OP Stack chains, from
op-geth v1.101702.3. A few deviations keep it stateless and its proof small;
they are listed below.
The formula has rules for Ethereum, Base, OP Mainnet, Unichain, Ink, Arbitrum
One, and Robinhood Chain. On the other chains Willow serves, the fee methods
and their proofs are refused with -32601 (the fee methods are not served on chain {id}: willow-fee-v1 has no rules for this chain), so a router sends
them to another provider.
Definitions
Section titled “Definitions”- H is the block the fees are computed at.
- base(b) is block b’s
baseFeePerGas. - tip(t, b) is transaction t’s effective tip in block b, as geth’s
EffectiveGasTipcomputes it:- for a transaction with
maxPriorityFeePerGas(EIP-1559, blob, and EIP-7702 transactions): min(maxPriorityFeePerGas,maxFeePerGas− base(b)); - for a legacy or EIP-2930 transaction:
gasPrice− base(b); - for an OP Stack deposit and Arbitrum’s own transaction types: 0.
- for a transaction with
- Before London (Ethereum block 12,965,000), a block has no base fee:
base(b) is 0, tip(t, b) is the transaction’s
gasPrice, and nextBaseFee of the block before London is 1 gwei.
All arithmetic is on integers, and every division rounds down.
eth_maxPriorityFeePerGas
Section titled “eth_maxPriorityFeePerGas”Ethereum. geth’s SuggestTipCap, over the 4 blocks up to H:
S = []for b in H-3 ..= H: sort b's transactions by tip(t, b), lowest first skip those with tip(t, b) < 2 wei, and those sent by b's miner add the first 3 remaining tips to Stip = 1,000,000 wei if S is empty sorted(S)[(len(S) - 1) * 60 / 100] otherwiseeth_maxPriorityFeePerGas = min(tip, 500 gwei)Base, OP Mainnet, Unichain, and Ink. op-geth’s
SuggestOptimismPriorityFee, over H alone:
min = 1,000,000 weimaxTx = the largest gasUsed of any transaction in H, from H's receiptstip = minif maxTx <= H.gasLimit and H.gasUsed + maxTx > H.gasLimit: # H was full m = the median of tip(t, H) over H's transactions (sorted, element len / 2) tip = max(min, m + m / 10)eth_maxPriorityFeePerGas = min(tip, 500 gwei)Arbitrum One and Robinhood Chain. 0, as Nitro returns.
eth_gasPrice
Section titled “eth_gasPrice”eth_gasPrice = nextBaseFee(H) + eth_maxPriorityFeePerGasnextBaseFee(H) is the base fee of the block after H:
- Ethereum. EIP-1559, as geth’s
CalcBaseFee:- target = H.gasLimit / 2;
- if H.gasUsed = target: base(H);
- if H.gasUsed > target: base(H) + max(1, base(H) × (H.gasUsed − target) / target / 8);
- if H.gasUsed < target: base(H) − base(H) × (target − H.gasUsed) / target / 8.
- Base, OP Mainnet, Unichain, and Ink. op-geth’s
CalcBaseFee, the same rule with the chain’s parameters. The elasticity is 6, and the denominator 50, or 250 from Canyon. From Holocene, the denominator and elasticity are read from H’sextraData(bytes 1 to 4 and 5 to 8, big-endian). From Jovian,extraDataalso carries a minimum base fee (bytes 9 to 16), the result is at least that minimum, and the gas metered is max(H.gasUsed, H.blobGasUsed), whereblobGasUsedholds the block’s data-availability footprint. - Arbitrum One and Robinhood Chain. base(H). ArbOS sets the next base fee from its own state, not from the header.
The OP Stack activation times the formula uses, from op-geth v1.101702.3’s superchain registry (Base’s from the registry’s last version that listed it, which match OP Mainnet’s):
| Chain | Canyon | Holocene | Jovian |
|---|---|---|---|
| Base, OP Mainnet | 1,704,992,401 | 1,736,445,601 | 1,764,691,201 |
| Unichain | genesis | 1,736,445,601 | 1,764,691,201 |
| Ink | genesis | 1,742,396,400 | 1,764,691,201 |
Holocene and Jovian are compared with H’s timestamp, and Canyon with H’s timestamp plus 1, as op-geth computes it.
eth_blobBaseFee
Section titled “eth_blobBaseFee”- Ethereum. The blob base fee of H itself, as geth returns for its head:
fake_exponential(1, H.excessBlobGas, fraction)(EIP-4844), with the update fraction in force at H’s timestamp. - Base, OP Mainnet, Unichain, and Ink. 1, as op-geth returns. Their
headers’
excessBlobGasis always 0, and a proof with another value fails verification. - Arbitrum One and Robinhood Chain.
null, as Nitro returns. Their headers carry noexcessBlobGas.
Ethereum’s blob parameters, from geth v1.17.10’s mainnet blobSchedule:
| Fork | From (unix time) | Target blobs | Max blobs | Update fraction |
|---|---|---|---|---|
| Cancun | 1,710,338,135 | 3 | 6 | 3,338,477 |
| Prague | 1,746,612,311 | 6 | 9 | 5,007,716 |
| BPO1 | 1,765,290,071 | 10 | 15 | 8,346,193 |
| BPO2 | 1,767,747,671 | 14 | 21 | 11,684,671 |
eth_feeHistory
Section titled “eth_feeHistory”As geth’s FeeHistory, over the requested range, from its oldest block to its
newest:
oldestBlock: the first block of the range.baseFeePerGas: base(b) for each block, and one more entry, nextBaseFee(newest), as above.gasUsedRatio: gasUsed / gasLimit for each block, as a floating-point number.baseFeePerBlobGas: each block’s blob base fee, and one more entry, the next block’s, from geth’sCalcExcessBlobGas(with EIP-7918 from Osaka). Absent on Arbitrum One and Robinhood Chain.blobGasUsedRatio: blobGasUsed / the fork’s maximum blob gas for each block, 0 where there is none. Absent on Arbitrum One and Robinhood Chain.reward, only when reward percentiles are requested: for each block, its transactions sorted by tip(t, b), each weighted by its gas used, read at each percentile of the block’sgasUsed. An empty block gives zeros. On Arbitrum One and Robinhood Chain the rewards are zeros, as Nitro returns.
A count above 1,024 is cut to 1,024, and a count of 0 returns
{"oldestBlock": "0x0", "gasUsedRatio": null}, as geth does. The standard
eth_feeHistory with reward percentiles reads at most 64 whole blocks, so a
longer range is cut at its oldest end, as geth cuts at 1,024. Invalid reward
percentiles are refused with -32602 (geth returns -32000).
Differences from geth
Section titled “Differences from geth”- Ethereum samples 4 blocks, not 20. Twenty Ethereum blocks with their transactions are several megabytes, which a fee proof would have to carry. geth also reads further back when a block yields at most one tip, and this formula never does.
- No state between calls. A block with no tip to sample adds nothing, where geth adds its last price, and an empty sample gives the constant 1,000,000 wei (0.001 gwei, geth’s starting price).
eth_gasPriceadds the next block’s base fee, where geth adds H’s own.- Arbitrum One and Robinhood Chain:
gasUsedRatiois gasUsed / gasLimit, where Nitro’s own figure comes from ArbOS state that no header commits to. The lastbaseFeePerGasis base(newest), which equals Nitro’s when the newest block is the head; for an older newest block, Nitro reports the next block’s actual base fee.
In testing, nextBaseFee(H) equaled block H+1’s actual baseFeePerGas on 1,000
of 1,000 consecutive blocks on Ethereum, OP Mainnet, Base, Unichain, and Ink.
eth_maxPriorityFeePerGas on the OP Stack chains equaled the public nodes’ on
48 of 48 heads. eth_feeHistory equaled the public nodes’ over 1,024 blocks on
the same five chains, and with reward percentiles over 4 Ethereum blocks and 16
on each OP Stack chain. On Ethereum, compared with a port of geth’s 20-block
rule over 1,000 heads, the tip was equal on 807, lower on 180, and higher on 13.
Both are tiny there, with a median of 12 wei.