Skip to content

Account for zero vs non-zero calldata bytes for L2 gas estimation #515

@K-Ho

Description

@K-Ho

Describe the bug
Current Fee estimation logic:

dataLen := int64(ROLLUP_BASE_TX_SIZE + len(data))
// get the data fee
dataFee := new(big.Int).Mul(dataPrice, big.NewInt(dataLen))
executionFee := new(big.Int).Mul(executionPrice, new(big.Int).SetUint64(gasUsed))

Rather than logic being gasPrice * dataLen + executionPrice * gasUsed, logic should be:
gasPrice * (4*zeroDataBytes + 16*nonZeroDataBytes + nonCallDataL1GasOverhead) + executionPrice * gasUsed

  1. dataPrice is currently the L1 gas price, not the price per byte of data. Non-zero data bytes cost 16 gas and zero data bytes cost 4 gas. We must iterate through the data, count # of zero, non-zero bytes, then calculate the cost.
  2. There is currently a non-calldata per tx overhead for batch submission. The naive solution is to have this parameterizable in the config. Ideally we can query the L1 CTC to find a running average of the tx batch size and use that to parameterize this added cost.

Non calldata cost per tx (Assuming each tx has its own batch context):

Batches of 10 txs:
9145 gas per tx

Batches of 50 txs:
5253 gas per tx

Batches of 200 txs:
2661 gas per tx

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-bugCategory: bugs

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions