Skip to content

opgeth-decoupling: create op-core/fees (L1 cost + operator-fee math) #20261

Closed

Description

@sebastianst

Part of #20257. See plan §4 in the op-geth decoupling doc.

🤖 Updated to match the implementation (#21314). Changes from the original spec: TxRollupCostData uses tx.MarshalBinary() rather than tx.Data() (the original sketch would compute the DA cost over only the calldata field — see comment); OperatorCost is split into OperatorCostIsthmus + OperatorCostJovian; the pure-math Bedrock/Ecotone cost funcs are also ported (they are used by e2e tests); and #17817 is fixed in the same PR.

Goal

Create op-core/fees containing OP-Stack L1 cost + operator-fee calculations. Consumers import as opfees. Sibling to op-core/types — no cycle (pure math on bytes + big.Int).

Scope

Port from op-geth's core/types/rollup_cost.go. Production code (op-service, op-batcher) uses only the Fjord-era subset, but e2e tests also use the pre-Fjord pure-math helpers, so those are ported too. The state-reading dispatchers (NewL1CostFunc/NewOperatorCostFunc, which need a ChainConfig + StateGetter) are not ported — post-decoupling they're test-only and are handled in the Phase-4 e2e test migration.

package fees

type RollupCostData struct { Zeroes, Ones, FastLzSize uint64 }

func NewRollupCostData(data []byte) RollupCostData
func (r RollupCostData) EstimatedDASize() *big.Int

type L1CostFunc func(RollupCostData, blockTime uint64) *big.Int
func L1CostBedrock(rollupDataGas uint64, l1BaseFee, overhead, scalar *big.Int) *big.Int
func NewL1CostFuncEcotone(l1BaseFee, l1BlobBaseFee, baseFeeScalar, blobBaseFeeScalar *big.Int) L1CostFunc
func NewL1CostFuncFjord(l1BaseFee, l1BlobBaseFee, baseFeeScalar, blobFeeScalar *big.Int) L1CostFunc

// Replaces inline operator-fee math duplicated across
// op-service/txinclude/txbudget.go and op-service/txinclude/operator_cost_oracle.go.
// Isthmus: (gasUsed * scalar / 1_000_000) + constant.  Jovian: (gasUsed * scalar * 100) + constant.
func OperatorCostIsthmus(gasUsed, scalar, constant uint64) *big.Int
func OperatorCostJovian(gasUsed, scalar, constant uint64) *big.Int

// Replaces (tx *types.Transaction).RollupCostData() op-geth method. Mirrors op-geth: empty for
// deposits, and computed over the full encoded transaction (MarshalBinary), not just tx.Data().
func TxRollupCostData(tx *types.Transaction) RollupCostData

Dependencies: stdlib + go-ethereum core/types (for TxRollupCostData) and params (EIP-2028 gas schedule). No import of op-core/types. No cycle possible.

Dependencies

None. Can start immediately.

🤖 Generated by Claude Code

Activity

  1. self-assigned this
    on May 5, 2026
  2. sebastianst commented on Jun 9, 2026

    @sebastianst
    MemberAuthor

    🤖 Claude says: Implemented in #21314. A few corrections / decisions surfaced while building op-core/fees, for context:

    1. TxRollupCostData must use tx.MarshalBinary(), not tx.Data(). The sketch in this issue (return NewRollupCostData(tx.Data())) computes the DA cost over only the calldata field. op-geth's (*Transaction).RollupCostData() computes it over the full binary-encoded transaction and returns empty for deposits — using tx.Data() undercounts badly (e.g. a 9-byte-calldata tx → 4 non-zero bytes instead of the real ~36). The implementation (fees.go#L63) uses MarshalBinary + a deposit short-circuit, enforced by a parity test against op-geth's method across legacy/dynamic-fee/blob/deposit txs. The description has been updated.

    2. Pre-Fjord cost funcs are not entirely unused. True for production (op-service/op-batcher use only Fjord), but e2e tests do: op-e2e/actions/derivation/system_config_test.go uses types.L1Cost (Bedrock) and op-e2e/system/fees/fees_test.go uses types.NewL1CostFunc/NewOperatorCostFunc (the state-reading dispatchers). Decision: ported the pure-math legacy funcs (L1CostBedrock, NewL1CostFuncEcotone) now; deferred the state-reading dispatchers to Phase 4, since post-decoupling they're test-only (the L2 STF is op-reth/kona) and would couple this pure-math package to op-core/params + a StateGetter.

    3. OperatorCost → OperatorCostIsthmus, plus a new OperatorCostJovian. Renamed so the fork is explicit (consistent with NewL1CostFuncFjord); added the Jovian variant (gasUsed*scalar*100 + constant). The Jovian roadmap note was kept out of the code doc.

    4. #17817 was small enough to include here — fixed by always using the Jovian operator-fee formula in txinclude (both the estimate and the actual-cost refund). Jovian is exact on Jovian chains (all production chains) and >= Isthmus for any inputs, so on a pre-Jovian chain it only over-reserves budget. IsthmusCostOracle was renamed to OperatorCostOracle.

    🤖 Generated by Claude Code

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions