# Fee model

### Overview

Like other rollups (e.g., ZKsync), Via Network must cover the cost of publishing transactions from L2 back to L1. Because of this, fees on Via Network depend on:

* **Layer‑1 gas prices**
* **DA layer gas cost parameters**
* **L2 minimum gas price parameters**&#x20;

These combine to form an L2 gas price that balances **fair fee pricing** and **operational cost recovery**.<br>

The core output of this model is a set of values called the **batch fee inputs**, including:

* `l1_gas_price`: the scaled L1 gas price
* `fair_l2_gas_price`: the L2 gas price that transactions must pay
* `fair_pubdata_price`: the scaled pubdata price for publishing data

These values are passed to the rest of the system to determine final transaction fees.

### Fee Model Structure

The Via Network fee model is composed of three main pieces:

1. **Fee parameter provider** – supplies real‑time L1 price information.
2. **Batch fee input calculator** – computes the fair L2 gas price and pubdata price.
3. **Clipping logic** – enforces operational caps to ensure continuity [GitHub](https://raw.githubusercontent.com/vianetwork/via-core/refs/heads/main/core/node/via_fee_model/src/lib.rs)

<table><thead><tr><th width="182.609375">Term</th><th>Meaning</th></tr></thead><tbody><tr><td><strong>L1 Gas Price</strong></td><td>Cost (in base tokens) to publish on the Layer‑1 chain (scaled).</td></tr><tr><td><strong>Fair L2 Gas Price</strong></td><td>A baseline gas price that L2 transactions must meet, covering overhead and minimum thresholds.</td></tr><tr><td><strong>Fair Pubdata Price</strong></td><td>A price for bytes of pubdata, tied to the base L1 price.</td></tr></tbody></table>

### Deriving the Fee&#x20;

#### Get L1 Prices

Via’s fee model starts by querying the Bitcoin L1 price from an external provider for:

* `l1_gas_price`: the L1 gas price history
* `l1_pubdata_price`: the estimated cost per pubdata unit

These come from an implementation of `ViaBaseTokenRatioProvider`.

#### Compute Fair L2 Gas Price

The fair L2 gas price is computed based on **batch overheads** and a **minimum L2 gas price** provided in the configuration. The formula is:

```rust
let mut fair_l2_gas_price = gas_price_satoshi + config.minimal_l2_gas_price;
```

Where:

* `batch_overhead_l1_gas`: L1 gas cost per batch (operational overhead)
* `config.max_gas_per_batch`: max gas units per batch
* `config.minimal_l2_gas_price`: minimum allowable L2 gas price

This produces a **fair L2 gas price** that covers overheads and respects the configured minimum

#### Pubdata Price

Via uses the scaled L1 pubdata price parameter (relatively constant cost on DA layer) directly as the **fair pubdata price**:

```rust
let mut fair_pubdata_price = scaled_l1_pubdata_price;
```

This price roughly tracks how much it costs to post data to DA layer(Celestia).

When submitting a transaction, your **effective gas cost** will depend on:

* Current L1 gas price (from real feeds)
* Pubdata pricing tied to DA pubdata cost
* L2 minimum gas price.

These combine to give a per‑unit **L2 gas price** for your transaction, ensuring both fair pricing and operational cost coverage.

#### MAX\_TRANSACTION\_GAS\_LIMIT <a href="#max_transaction_gas_limit" id="max_transaction_gas_limit"></a>

A recommended maximal amount of gas that a transaction can spend on computation is `MAX_TRANSACTION_GAS_LIMIT=1125899906842624`. <br>

### Reference:

* For the full Rust source, see: [Github](https://github.com/vianetwork/via-core/blob/main/core/node/via_fee_model/src/lib.rs)
* Zksync [fee model](https://docs.zksync.io/zksync-protocol/era-vm/transactions/fee-model)
