> For the complete documentation index, see [llms.txt](https://scroll-zkp.gitbook.io/scroll-guide/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://scroll-zkp.gitbook.io/scroll-guide/developers/transaction-fees-on-scroll-l2/gas-oracle.md).

# Gas Oracle

{% hint style="danger" %}
**Scroll Alpha Testnet is now deprecated.**

Please visit our new documentation for the Scroll Sepolia Testnet at <https://docs.scroll.io/>
{% endhint %}

Scroll Alpha has a pre-deployed contract `L1GasPriceOracle` (contract address [`0x5300000000000000000000000000000000000002`](https://blockscout.scroll.io/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

| Field     | Slot |
| --------- | ---- |
| l1BaseFee | 1    |
| overhead  | 2    |
| scalar    | 3    |

2. Count the number of zero bytes and non-zero bytes from the transaction callData.
3. 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&#x20;
2. Additional 74 bytes&#x20;
   * 4 bytes: the length prefix of transaction data&#x20;
   * 1 byte: RLP prefix for V&#x20;
   * 3 bytes: V&#x20;
   * 1 byte: RLP prefix for R&#x20;
   * 32 bytes: R&#x20;
   * 1 byte: RLP prefix for S&#x20;
   * 32 bytes: S

{% hint style="info" %}
You can find more details on the formula in the [L1 fee](/scroll-guide/developers/transaction-fees-on-scroll-l2/l1-fee.md) article.
{% endhint %}

## API

### overhead

```solidity
function overhead() external view returns (uint256);
```

Returns the current L1 fee overhead

### scalar

```solidity
function scalar() external view returns (uint256);
```

Returns the current l1 fee scalar

### l1BaseFee

```solidity
function l1BaseFee() external view returns (uint256);
```

Returns the latest known l1 base fee

### getL1Fee

```solidity
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

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

### getL1GasUsed

```solidity
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.

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