Sequencer

Sequencers receive transactions from users, package and bundle them into blocks, execute transactions, etc. However, nearly all Layer 2 sequencers are centralized, which presents several issues, such as transaction censorship, unrestricted Miner Extractable Value (MEV) extraction, and single points of failure

In this phase of the end-to-end transaction flow, transactions go through different stages, depending on the user’s GasPriceSigned:

  1. Sequencing transactions coming from the transaction pool manager.

  2. Estimating the effective gas price (EEGP) using the current L1GasPrice and RPC’s estimated GasUsedRPC.

    EffectiveGasPrice=BreakEvenGasPrice(1+PriorityRatio)\texttt{EffectiveGasPrice} = \texttt{BreakEvenGasPrice} \cdot \big(1 + \texttt{PriorityRatio}\big)

    where the priority ratio is given by:

    PriorityRatio=SignedGasPricesuggestedGasPrice1\texttt{PriorityRatio} = \frac{\texttt{SignedGasPrice}}{\texttt{suggestedGasPrice}} - 1

    Depending on whether GasPriceSignedEEGP\texttt{GasPriceSigned} \leq \texttt{EEGP} or not, transactions get executed with either the GasPriceSigned\texttt{GasPriceSigned} or the EEGP\texttt{EEGP}

  3. Amongst the transactions that are computed with the EEGP\texttt{EEGP} , further gas savings can be achieved by:

    • Computing the new effective gas price (NEGP), using the current state and the EEGP.

    • Calculating the gas consumption deviation percentage and comparing it to a fixed deviation parameter. i.e. FinalDeviationParameter=10\texttt{FinalDeviationParameter} = 10

    • There’s no further execution if the gas consumption deviation percentage is less than the fixed parameter, FinalDeviationParameter=10\texttt{FinalDeviationParameter} = 10

    • Otherwise, check if GasPriceSignedNEGP\texttt{GasPriceSigned} \leq \texttt{NEGP} If true, then execute transactions again using the GasPriceSigned\texttt{GasPriceSigned} If false, continue to the next stage.

  4. Checking the usage of GASPRICE\texttt{GASPRICE} and BALANCE\texttt{BALANCE} opcodes

    1. Transactions with these two opcodes get executed with the GasPriceSigned\texttt{GasPriceSigned}

    2. Otherwise, they are executed with the NEGP\texttt{NEGP}

Since the sequencer is obliged to execute all transactions in the transaction pool manager, each transaction is executed during a particular stage of the flow described above.

The entire sequencer flow is summarized in the figure below.

Example (Sequencer flow)

Let’s continue the numerical example we have been using throughout this document.

As seen in previous examples, the figure below displays L1 gas prices above the timeline, while the associated suggested L2 gas prices are shown below the timeline.

At the time of sequencing the transaction, the suggested gas price is given by,

GasPriceSuggested=0.15L1GasPrice\texttt{GasPriceSuggested} = 0.15 \cdot \texttt{L1GasPrice}
  1. Suppose the user signed a gas price of 3.3 GWei/Gas3.3\ \texttt{GWei/Gas}

    Recall how we previously obtained the BreakEvenGasPriceRPC\texttt{BreakEvenGasPriceRPC} of 2.52 GWei/Gas2.52\ \texttt{GWei/Gas}

    According to the figure above, the network recommends a gas price of 3, which corresponds to an L1 gas price of 20.

    This results in the following priority factor:

    PriorityRatio=SignedGasPriceSuggestedGasPrice1 =3.331=0.1\begin{aligned} \texttt{PriorityRatio} &= \frac{\texttt{SignedGasPrice}}{\texttt{SuggestedGasPrice}} - 1 \\ \text{ } &= \frac{3.3}{3} - 1 = 0.1 \end{aligned}

    and an estimated effective gas price:

    EEGP=BreakEvenGasPrice(1+PriorityRatio) =2.52(1+0.1)=2.722 GWei/Gas\begin{aligned} \texttt{EEGP} &= \texttt{BreakEvenGasPrice} \cdot \big(1 + \texttt{PriorityRatio}\big) \\ \text{ } &= 2.52 \cdot \big( 1 + 0.1 \big) = 2.722\ \texttt{GWei/Gas} \end{aligned}

    This amounts to a 10%10\% increment to the gas price for transaction prioritization.

  2. Since the signed gas price is bigger than the estimated effective gas price, SignedGasPrice=3.3>2.772=EEGP\texttt{SignedGasPrice} = 3.3 > 2.772 = \texttt{EEGP} the transaction can be executed with the SignedGasPrice\texttt{SignedGasPrice}

  3. The sequencer can use the current and correct state, together with the computed EEGP\texttt{EEGP} , in order to obtain a more accurate measure of the gas used, call it GasUsedNew\texttt{GasUsedNew}. Suppose that, in this case, we obtain

    GasUsedNew=95,000 Gas\texttt{GasUsedNew} = 95,000\ \texttt{Gas} which is bigger than the RPC-estimated gas of 60,00060,000

  4. With the new GasUsedNew\texttt{GasUsedNew} an adjusted effective gas price NEGP\texttt{NEGP} can be computed by the following steps. Firstly, the total transaction cost:

    TxCostNew=(20016+1004)20+95,000200.04=148,000 GWei\texttt{TxCostNew} = (200 · 16 + 100 · 4) · 20 + 95,000 · 20 · 0.04 = 148,000 \ \texttt{GWei} where a 20%20\% breakeven factor is applied. Thirdly, the new effective gas price:

    NEGP=BreakEvenGasPriceNew(1+PriorityRatio) =1.869(1+(SignedGasPriceSuggestedGasPrice1)) =1.869(1+(3.331)) =1.8691.1=2.056 GWei/Gas\begin{aligned} \texttt{NEGP} &= \texttt{BreakEvenGasPriceNew} \cdot \big(1 + \texttt{PriorityRatio}\big) \\ \text{ } &= 1.869 · \big( 1 + \big( \frac{\texttt{SignedGasPrice}}{\texttt{SuggestedGasPrice}} - 1 \big) \big) \\ \text{ } &= 1.869 · \big( 1 + \big( \frac{3.3}{3} - 1 \big) \big) \\ \text{ } &= 1.869 · 1.1 = 2.056\ \texttt{GWei/Gas} \end{aligned} Observe that the transaction cost is much higher than the RPC-estimation of 126,000126,000 , even when the L1 gas price has decreased from 21 to 20 due to a huge increase in gas.

  5. Observe that there is a significant deviation between both effective gas prices: NEGPEEGPEEGP100=25.82>10\frac{|\texttt{NEGP} − \texttt{EEGP}|}{\texttt{EEGP}} \cdot 100 = 25.82 > 10

    Executing the transaction with the signed gas price, while the deviation is this big, amounts to penalizing the user unfairly.

    Thus, since the new EGP is smaller than the signed gas price:

    SignedGasPrice =3.3>2.52= EEGP2.056= NEGP\texttt{SignedGasPrice}\ = 3.3 > 2.52 =\ \texttt{EEGP} ≫ 2.056 =\ \texttt{NEGP} instead of charging the signed gas price, a further attempt to adjust the gas price is made by charging the NEGP=2.056\texttt{NEGP} = 2.056 to the user.

  6. In the case where the transaction has none of the two opcodes, GASPRICE\texttt{GASPRICE} and BALANCE\texttt{BALANCE}, in the source address opcodes, the transaction gets executed with the NEGP:

    GasPriceFinal=NEGP=2.056 GWei/Gas\texttt{GasPriceFinal} = \texttt{NEGP} = 2.056\ \texttt{GWei/Gas} Observe that GasUsedFinal\texttt{GasUsedFinal} should be the same as GasUsedNew=95,000\texttt{GasUsedNew} = 95,000. Finally, the EffectivePercentage\texttt{EffectivePercentage} and EffectivePercentageByte\texttt{EffectivePercentageByte} are computed as follows:

    EffectivePercentage=GasPriceFinalSignedGasPrice=2.0563.3=0.623.\texttt{EffectivePercentage} = \frac{\texttt{GasPriceFinal}}{\texttt{SignedGasPrice}} = \frac{2.056}{3.3} = 0.623.

    EffectivePercentageByte=EffectivePercentage2561=158\texttt{EffectivePercentageByte} = \lfloor \texttt{EffectivePercentage} · 256 \rfloor − 1 = 158 Observe that the user has been charged 62.3%62.3\% of the gas price they signed at the time of sending the transaction.

Last updated