Skip to content

Commit 197deb2

Browse files
committed
new technology page
1 parent b619bc1 commit 197deb2

File tree

3 files changed

+171
-158
lines changed

3 files changed

+171
-158
lines changed
Lines changed: 12 additions & 158 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,21 @@
11
---
2-
Title: Estimate gas costs
2+
title: Estimate gas costs
33
description: How to estimate gas costs on Linea
44
sidebar_position: 6
55
image: /img/socialCards/how-to-estimate-linea-gas-costs.jpg
66
---
77

88
import Tabs from '@theme/Tabs'; import TabItem from '@theme/TabItem';
99

10-
`linea_estimateGas` is the recommended method for estimating gas on Linea. See our [reference page](../../api/reference/linea-estimategas.mdx) for more information.
10+
:::tip
11+
Linea supports the [Ethereum EIP-1559 gas price model](https://ethereum.org/developers/docs/gas):
12+
```
13+
total fee = units of gas used * (base fee + priority fee)
14+
```
15+
and includes support for type 0, type 1 and type 2 transactions.
16+
:::
17+
18+
`linea_estimateGas` is the recommended method for estimating gas on Linea. See our [reference page](../../api/reference/linea-estimategas.mdx) for more information, or our [technology section](../../technology/gas.mdx) for more information about how gas works on Linea.
1119

1220
Linea also supports:
1321
- [`eth_estimateGas`](https://docs.infura.io/api/networks/linea/json-rpc-methods/eth_estimategas)
@@ -17,7 +25,7 @@ Linea also supports:
1725

1826
## [`linea_estimateGas`](../../api/reference/linea-estimategas.mdx)
1927

20-
'linea_estimateGas' returns `gasLimit`,
28+
`linea_estimateGas` returns `gasLimit`,
2129
`baseFeePerGas`, and `priorityFeePerGas`, and therefore provides a more precise gas estimate than
2230
the alternatives.
2331

@@ -48,158 +56,4 @@ curl https://linea-mainnet.infura.io/v3/YOUR-API-KEY \
4856
}
4957
```
5058

51-
See the [reference page](../../api/reference/linea-estimategas.mdx) for full usage.
52-
53-
## How `linea_estimateGas` calculates the gas price
54-
55-
The gas price returned by `linea_estimateGas` is based on the variable data cost of the previous
56-
block with a multiplier applied as a buffer to ensure inclusion.
57-
58-
Each Linea block's `extraData` field is populated with the following gas price values that are used
59-
by `linea_estimateGas` to calculate the cost of a transaction:
60-
- A `FIXED_COST` of 0.03 Gwei, which reflects infrastructure costs;
61-
- `ADJUSTED_VARIABLE_COST`, which is the cost per byte of data submitted to L1, and;
62-
- `ETH_GAS_PRICE`, used to set a more accurate return value for any `eth_gasPrice` calls.
63-
64-
:::note
65-
66-
The `extraData` field is a 32-byte space used to store arbitrary data, such as metadata or
67-
additional information relevant to the block.
68-
69-
On Linea, it's used by the sequencer and Linea Besu nodes running the correct plugins to expose
70-
`linea_estimateGas`.
71-
72-
:::
73-
74-
Variable cost is calculated with the following formula:
75-
76-
```bash
77-
ADJUSTED_VARIABLE_COST = max(base_variable_cost, previous_variable_cost * ( 1 + delta / CHANGE_DENOMINATOR )
78-
```
79-
80-
Where:
81-
- `base_variable_cost` is calculated with the below formula:
82-
```python
83-
variable_cost (4 bytes) = min(max(
84-
(
85-
(
86-
((averageWeightedBaseFee + averageWeightedPriorityFee) *
87-
blob-submission-expected-execution-gas + averageWeightedBlobBaseFee * expected-blob-gas
88-
) / bytes-per-data-submission) * profit-margin
89-
)
90-
, min-bound), max-bound)
91-
```
92-
The `profit-margin` ensures the network is sustainable. `min-bound` and `max-bound` are variable,
93-
and guarantee the gas price stays within a reasonable range.
94-
- `previous_variable_cost` is the value of the last `ADJUSTED_VARIABLE_COST` calculation
95-
- `delta` is a decimal number that fluctuates between `-1.0` and `1.0` and is calculated as:
96-
```bash
97-
delta = (sum(block_calldata_size over BLOCK_COUNT) - calldata_target) / calldata_target
98-
```
99-
Where:
100-
- `BLOCK_COUNT` is a constant at `5`
101-
- `block_calldata_size` is the total calldata size of the target block
102-
- `calldata_target` = `109,000 * BLOCK_COUNT / 2` (given that 109,000 is the maximum calldata
103-
size allowed in each L2 block)
104-
- `CHANGE_DENOMINATOR` is a constant, currently set to `32`, designed to control the rate of change
105-
of `ADJUSTED_VARIABLE_COST`
106-
107-
### Base variable cost
108-
109-
The variable cost formula enables `linea_estimateGas` to price according to the variable costs of
110-
submitting blob data to L1, working out the per-byte cost of that data. The amount of the blob data
111-
in each block stays roughly consistent, though the amount _per transaction_ varies, so the
112-
`linea_estimateGas` API accounts for this, and ensures a gas price is returned for the transaction
113-
that reflects the amount of data it contains. In turn, it ensures that the network is sustainable,
114-
and that the cost to the protocol of L1 data availability is covered.
115-
116-
### Adjusted variable cost
117-
118-
The overarching adjusted variable cost formula enables the gas price for the end user to
119-
automatically adjust to prevent denial-of-service (DoS) attacks where a malicious actor could submit
120-
a large volume of low-compute, high-data transactions at minimal cost. In theory, such a scenario
121-
could prevent good-faith users from submitting transactions because all of the block's space for
122-
data would be taken up by the malicious actor's transactions.
123-
124-
If the calldata space of successive blocks was fully occupied, `ADJUSTED_VARIABLE_COST` would
125-
increase exponentially: `1 + 1 / 32` (i.e. `1 + delta / CHANGE_DENOMINATOR`) would cause the
126-
variable cost to double every 22 blocks (44 seconds) — 10,000x over 10 minutes. The gas cost for the
127-
attacker — who needs to fund many transactions — would quickly snowball to a prohibitively high
128-
number, while remaining acceptable for regular users who only need to submit a handful of
129-
transactions.
130-
131-
This effect also works in the reverse: when calldata space usage falls, the variable cost will
132-
exponentially decrease and eventually revert to `base_variable_cost`, depending on calldata usage.
133-
134-
### Variable cost and `linea_estimateGas`
135-
136-
To determine the priority fee per gas, `linea_estimateGas` takes the previous block's `VARIABLE_COST`
137-
into account:
138-
```python
139-
min-gas-price = previousBlock.extraData.variable_cost
140-
baseFeePerGas = vanillaProtocolBaseFee
141-
priorityFeePerGas = MINIMUM_MARGIN * (min-gas-price * L2_compressed_tx_size_in_bytes / L2_tx_gas_used + extraData.fixed_cost)
142-
```
143-
144-
Where:
145-
- `extraData.variable_cost` is where the previous block's `VARIABLE_COST` is stored
146-
block
147-
- `MINIMUM_MARGIN` varies depending on the stage of the transaction:
148-
- RPC method, i.e. calling `linea_estimateGas`: `1.2`
149-
- In the transaction pool: `0.8`
150-
- At transaction selection stage: `1.0`
151-
152-
:::note
153-
The RPC method and transaction pool values are configurable by RPC providers or those running their
154-
own nodes according to preference; the transaction selection stage value is fixed. For example,
155-
it may be preferable to set a lower margin to facilitate lower gas prices, but this risks
156-
transactions not being included.
157-
:::
158-
159-
`linea_estimateGas` simulates the transaction ordering logic that the sequencer uses when building
160-
blocks, and then obtains a gas price that will ensure that the priority fee is high enough for
161-
inclusion. The sequencer's transaction ordering policy includes transactions in block in order of
162-
highest priority fee, a system known as a priority gas auction. It also checks that the priority
163-
fees offered by each transaction are high enough to support network sustainability, and cover L1
164-
data costs.
165-
166-
In some cases, transactions with lower priority fees are included ahead of others with higher
167-
priority fees. This is because the nonce order of transactions submitted from the same account
168-
takes precedence.
169-
170-
171-
## More information
172-
173-
### How gas works on Linea
174-
175-
Linea supports the [Ethereum EIP-1559 gas price model](https://ethereum.org/developers/docs/gas):
176-
```
177-
total fee = units of gas used * (base fee + priority fee)
178-
```
179-
and includes support for type 0, type 1 and type 2 transactions.
180-
181-
Linea is EVM-equivalent, and gas therefore works extremely similarly to Ethereum. The main difference
182-
is that **the base fee effectively stabilizes at 7 wei.** Linea blocks use up to around 50% of the
183-
maximum block size of 2 billion gas, and the base fee decreases or increases by 12.5% per block
184-
according to network traffic, identically to Ethereum. However, when the base fee reaches 7 wei,
185-
12.5% is less than 1 wei, and the reduction is rounded down to zero; so the fee remains 7 wei.
186-
The base fee is also burned, like on Ethereum.
187-
188-
The gas cost to submit your transaction and include it on Ethereum involves the following fee
189-
components:
190-
191-
- **Layer 2 cost**: The execution fee; the cost of including your transaction on the Linea
192-
sequencer, and calculated using a similar formula to Ethereum (as described above).
193-
- **Layer 1 cost**: The cost of publishing your L2 transaction on Ethereum, which varies
194-
based on the blob fee market.
195-
196-
These two resource costs are abstracted by the rollup and covered by the recommended L2 gas price
197-
and gas used.
198-
199-
> Learn more about gas on Linea on our [support page](https://support.linea.build/getting-started/what-does-gas-pay-for)
200-
and release notes for [Alpha v2](../../release-notes.mdx#alpha-v2) and [Alpha v3](../../release-notes.mdx#alpha-v30).
201-
202-
Linea also supports:
203-
- [`eth_estimateGas`](https://docs.infura.io/api/networks/linea/json-rpc-methods/eth_estimategas)
204-
- [`eth_gasPrice`](https://docs.infura.io/api/networks/linea/json-rpc-methods/eth_gasprice)
205-
- [`eth_feeHistory`](https://docs.infura.io/api/networks/linea/json-rpc-methods/eth_feehistory).
59+
See the [reference page](../../api/reference/linea-estimategas.mdx) for full usage.

docs/technology/gas.mdx

Lines changed: 158 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,158 @@
1+
---
2+
title: Gas
3+
description: How gas works on Linea
4+
image: /img/socialCards/gas.jpg
5+
---
6+
7+
`linea_estimateGas` is the recommended method for estimating gas on Linea. See our [API reference](../../api/reference/linea-estimategas.mdx) and [guide](../../get-started/how-to/gas-fees.mdx) for more information.
8+
9+
Linea also supports:
10+
- [`eth_estimateGas`](https://docs.infura.io/api/networks/linea/json-rpc-methods/eth_estimategas)
11+
- [`eth_gasPrice`](https://docs.infura.io/api/networks/linea/json-rpc-methods/eth_gasprice)
12+
- [`eth_feeHistory`](https://docs.infura.io/api/networks/linea/json-rpc-methods/eth_feehistory).
13+
14+
## How gas works on Linea
15+
16+
Linea supports the [Ethereum EIP-1559 gas price model](https://ethereum.org/developers/docs/gas):
17+
```
18+
total fee = units of gas used * (base fee + priority fee)
19+
```
20+
and includes support for type 0, type 1 and type 2 transactions.
21+
22+
Linea is EVM-equivalent, and gas therefore works extremely similarly to Ethereum. The main difference
23+
is that **the base fee effectively stabilizes at 7 wei.** Linea blocks use up to around 50% of the
24+
maximum block size of 2 billion gas, and the base fee decreases or increases by 12.5% per block
25+
according to network traffic, identically to Ethereum. However, when the base fee reaches 7 wei,
26+
12.5% is less than 1 wei, and the reduction is rounded down to zero; so the fee remains 7 wei.
27+
The base fee is also burned, like on Ethereum.
28+
29+
The gas cost to submit your transaction and include it on Ethereum involves the following fee
30+
components:
31+
32+
- **Layer 2 cost**: The execution fee; the cost of including your transaction on the Linea
33+
sequencer, and calculated using a similar formula to Ethereum (as described above).
34+
- **Layer 1 cost**: The cost of publishing your L2 transaction on Ethereum, which varies
35+
based on the blob fee market.
36+
37+
These two resource costs are abstracted by the rollup and covered by the recommended L2 gas price
38+
and gas used.
39+
40+
> Learn more about gas on Linea on our [support page](https://support.linea.build/getting-started/what-does-gas-pay-for)
41+
and release notes for [Alpha v2](../../release-notes.mdx#alpha-v2) and [Alpha v3](../../release-notes.mdx#alpha-v30).
42+
43+
## How `linea_estimateGas` calculates the gas price
44+
45+
The gas price returned by `linea_estimateGas` is based on the variable data cost of the previous
46+
block with a multiplier applied as a buffer to ensure inclusion.
47+
48+
Each Linea block's `extraData` field is populated with the following gas price values that are used
49+
by `linea_estimateGas` to calculate the cost of a transaction:
50+
- A `FIXED_COST` of 0.03 Gwei, which reflects infrastructure costs;
51+
- `ADJUSTED_VARIABLE_COST`, which is the cost per byte of data submitted to L1, and;
52+
- `ETH_GAS_PRICE`, used to set a more accurate return value for any `eth_gasPrice` calls.
53+
54+
:::note
55+
56+
The `extraData` field is a 32-byte space used to store arbitrary data, such as metadata or
57+
additional information relevant to the block.
58+
59+
On Linea, it's used by the sequencer and Linea Besu nodes running the correct plugins to expose
60+
`linea_estimateGas`.
61+
62+
:::
63+
64+
Variable cost is calculated with the following formula:
65+
66+
```bash
67+
ADJUSTED_VARIABLE_COST = max(base_variable_cost, previous_variable_cost * ( 1 + delta / CHANGE_DENOMINATOR )
68+
```
69+
70+
Where:
71+
- `base_variable_cost` is calculated with the below formula:
72+
```python
73+
variable_cost (4 bytes) = min(max(
74+
(
75+
(
76+
((averageWeightedBaseFee + averageWeightedPriorityFee) *
77+
blob-submission-expected-execution-gas + averageWeightedBlobBaseFee * expected-blob-gas
78+
) / bytes-per-data-submission) * profit-margin
79+
)
80+
, min-bound), max-bound)
81+
```
82+
The `profit-margin` ensures the network is sustainable. `min-bound` and `max-bound` are variable,
83+
and guarantee the gas price stays within a reasonable range.
84+
- `previous_variable_cost` is the value of the last `ADJUSTED_VARIABLE_COST` calculation
85+
- `delta` is a decimal number that fluctuates between `-1.0` and `1.0` and is calculated as:
86+
```bash
87+
delta = (sum(block_calldata_size over BLOCK_COUNT) - calldata_target) / calldata_target
88+
```
89+
Where:
90+
- `BLOCK_COUNT` is a constant at `5`
91+
- `block_calldata_size` is the total calldata size of the target block
92+
- `calldata_target` = `109,000 * BLOCK_COUNT / 2` (given that 109,000 is the maximum calldata
93+
size allowed in each L2 block)
94+
- `CHANGE_DENOMINATOR` is a constant, currently set to `32`, designed to control the rate of change
95+
of `ADJUSTED_VARIABLE_COST`
96+
97+
### Base variable cost
98+
99+
The variable cost formula enables `linea_estimateGas` to price according to the variable costs of
100+
submitting blob data to L1, working out the per-byte cost of that data. The amount of the blob data
101+
in each block stays roughly consistent, though the amount _per transaction_ varies, so the
102+
`linea_estimateGas` API accounts for this, and ensures a gas price is returned for the transaction
103+
that reflects the amount of data it contains. In turn, it ensures that the network is sustainable,
104+
and that the cost to the protocol of L1 data availability is covered.
105+
106+
### Adjusted variable cost
107+
108+
The overarching adjusted variable cost formula enables the gas price for the end user to
109+
automatically adjust to prevent denial-of-service (DoS) attacks where a malicious actor could submit
110+
a large volume of low-compute, high-data transactions at minimal cost. In theory, such a scenario
111+
could prevent good-faith users from submitting transactions because all of the block's space for
112+
data would be taken up by the malicious actor's transactions.
113+
114+
If the calldata space of successive blocks was fully occupied, `ADJUSTED_VARIABLE_COST` would
115+
increase exponentially: `1 + 1 / 32` (i.e. `1 + delta / CHANGE_DENOMINATOR`) would cause the
116+
variable cost to double every 22 blocks (44 seconds) — 10,000x over 10 minutes. The gas cost for the
117+
attacker — who needs to fund many transactions — would quickly snowball to a prohibitively high
118+
number, while remaining acceptable for regular users who only need to submit a handful of
119+
transactions.
120+
121+
This effect also works in the reverse: when calldata space usage falls, the variable cost will
122+
exponentially decrease and eventually revert to `base_variable_cost`, depending on calldata usage.
123+
124+
### Variable cost and `linea_estimateGas`
125+
126+
To determine the priority fee per gas, `linea_estimateGas` takes the previous block's `VARIABLE_COST`
127+
into account:
128+
```python
129+
min-gas-price = previousBlock.extraData.variable_cost
130+
baseFeePerGas = vanillaProtocolBaseFee
131+
priorityFeePerGas = MINIMUM_MARGIN * (min-gas-price * L2_compressed_tx_size_in_bytes / L2_tx_gas_used + extraData.fixed_cost)
132+
```
133+
134+
Where:
135+
- `extraData.variable_cost` is where the previous block's `VARIABLE_COST` is stored
136+
block
137+
- `MINIMUM_MARGIN` varies depending on the stage of the transaction:
138+
- RPC method, i.e. calling `linea_estimateGas`: `1.2`
139+
- In the transaction pool: `0.8`
140+
- At transaction selection stage: `1.0`
141+
142+
:::note
143+
The RPC method and transaction pool values are configurable by RPC providers or those running their
144+
own nodes according to preference; the transaction selection stage value is fixed. For example,
145+
it may be preferable to set a lower margin to facilitate lower gas prices, but this risks
146+
transactions not being included.
147+
:::
148+
149+
`linea_estimateGas` simulates the transaction ordering logic that the sequencer uses when building
150+
blocks, and then obtains a gas price that will ensure that the priority fee is high enough for
151+
inclusion. The sequencer's transaction ordering policy includes transactions in block in order of
152+
highest priority fee, a system known as a priority gas auction. It also checks that the priority
153+
fees offered by each transaction are high enough to support network sustainability, and cover L1
154+
data costs.
155+
156+
In some cases, transactions with lower priority fees are included ahead of others with higher
157+
priority fees. This is because the nonce order of transactions submitted from the same account
158+
takes precedence.

sidebars.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -591,6 +591,7 @@ const sidebars = {
591591
"technology/burn",
592592
"technology/repos",
593593
"technology/transaction-lifecycle",
594+
"technology/gas",
594595
"technology/network-data",
595596
"technology/canonical-token-bridge",
596597
{

0 commit comments

Comments
 (0)