Gas Oracle

Scroll Alpha Testnet is now deprecated.

Please visit our new documentation for the Scroll Sepolia Testnet at https://docs.scroll.io/

Scroll Alpha has a pre-deployed contract L1GasPriceOracle (contract address 0x5300000000000000000000000000000000000002) used to estimate the L1 gas fee given raw transaction data. This is a push oracle, updated by a relayer run by Scroll.

It stores the L1 base fee gas price and provides a public API, which can be used to estimate the total transaction fee for some L2 transactions.

How does it work?

The L1 fee calculation works as follows.

  1. Read three fields l1BaseFee, overhead, scalar from the L1GasPriceOracle contract. The slots for these fields in the contract are

FieldSlot

l1BaseFee

1

overhead

2

scalar

3

  1. Count the number of zero bytes and non-zero bytes from the transaction callData.

  2. Calculate the sumL1 data fee (PRECISION = 1e9)

What does the commit tx consist of?

Encoding of a transaction in the commit tx [length] [RLP-encoded transaction with signature] consists of two parts:

  1. The sum of zero bytes and non-zero bytes in the RLP-encoded transaction without signature

  2. Additional 74 bytes

    • 4 bytes: the length prefix of transaction data

    • 1 byte: RLP prefix for V

    • 3 bytes: V

    • 1 byte: RLP prefix for R

    • 32 bytes: R

    • 1 byte: RLP prefix for S

    • 32 bytes: S

You can find more details on the formula in the L1 fee article.

API

overhead

function overhead() external view returns (uint256);

Returns the current L1 fee overhead

scalar

function scalar() external view returns (uint256);

Returns the current l1 fee scalar

l1BaseFee

function l1BaseFee() external view returns (uint256);

Returns the latest known l1 base fee

getL1Fee

function getL1Fee(bytes memory data) external view returns (uint256);

Computes the L1 portion of the fee based on the size of the RLP encoded input transaction, the current L1 base fee, and the various dynamic parameters.

Returns: L1 fee that should be paid for the transaction

ParameterDescription

data

data Unsigned fully RLP-encoded transaction to get the L1 fee for.

getL1GasUsed

function getL1GasUsed(bytes memory data) external view returns (uint256);

Computes the amount of L1 gas used for a transaction. Adds the overhead which represents the per-transaction gas overhead of posting the transaction and state roots to L1. Adds 74 bytes of padding to account for the fact that the input does not have a signature.

Returns: Amount of L1 gas used to publish the transaction.

ParameterDescription

data

data Unsigned fully RLP-encoded transaction to get the L1 fee for.

Last updated