Skip to content

Commit

Permalink
fix: bugfix for GAS_NEXT of CREATE's
Browse files Browse the repository at this point in the history
- exceptional CREATE's consume all gas
- aborted CREATE's consume only the upfront gas cost
- CREATE's that raise the Failure Condition F consume the upfront gas
cost + the 63/64ths given to the child context which they don't get back
- CREATE's with empty init code get those 63/64ths back immediately so
from the zkevm POV don't pay for it at all
- CREATE's with nonempty init code consume the upfront ga cost + the
63/64th's which they provide to the child context (and may et back in
part)
  • Loading branch information
OlivierBBB committed Dec 9, 2024
1 parent 1ab7d29 commit c63467a
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 14 deletions.
3 changes: 2 additions & 1 deletion hub/instruction_handling/create/_local.tex
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,8 @@
\def\locAuxId {\col{aux\_id}}
\def\locExoSum {\col{exo\_sum}}


\def\locCreateUpfrontGasCost {\col{upfront\_gas\_cost}}
\def\locCreateFullGasCost {\col{full\_gas\_cost}}

% CALL specific row offset constants
\def\createFirstStackRowOffset {\greenm{2}}
Expand Down
43 changes: 30 additions & 13 deletions hub/instruction_handling/create/generalities/all.tex
Original file line number Diff line number Diff line change
Expand Up @@ -243,24 +243,41 @@
\If \scenCreateExecutionNonEmptyInitCode _{i} = 1 & \Then & \nextContextIsNew _{i} \\
\end{array} \right.
\]
\end{description}
Let us define the following shorthands:
\[
\left\{ \begin{array}{lcl}
\locCreateUpfrontGasCost & \define & G_\text{create} + \locMxpGas \\
\locCreateFullGasCost & \define & \locCreateUpfrontGasCost + \locStpGasPoop \\
\end{array} \right.
\]
\begin{description}
\item[\underline{Setting the \gasCost{}:}]
we impose
\begin{enumerate}
\item \If $\locStaticx + \locMxpx = 1$ \Then $\gasCost _{i} = 0$
\item \If $\locOogx + \scenCreateUnexceptional = 1$ \Then $\gasCost _{i} = G_\text{create} + \locMxpGas$
\item \If $\locOogx + \scenCreateUnexceptional = 1$ \Then $\gasCost _{i} = \locCreateUpfrontGasCost$
\end{enumerate}
\item[\underline{Setting the \gasNext{}:}]
we impose
\begin{enumerate}
\item \If $\scenCreateException _{i} = 1$ \Then $\gasNext_{i} = 0$ (\trash)
\item \If $\scenCreateNoContextChange _{i} = 1$ \Then $\gasNext_{i} = \gasActual_{i} - \gasCost_{i}$
\item \If $\scenCreateExecutionNonEmptyInitCode _{i} = 1$ \Then
\[
\gasNext_{i} = \gasActual_{i} -
\left[ \begin{array}{cl}
+ & \gasCost_{i} \\
+ & \locStpGasPoop \\
\end{array} \right]
\]
\end{enumerate}
\[
\hspace*{-0.5cm}
\left\{ \begin{array}{lcl}
\If \scenCreateException _{i} = 1 & \Then & \gasNext _{i} = 0 ~ (\trash) \\
\If \scenCreateAbort _{i} = 1 & \Then & \gasNext _{i} = \gasActual _{i} - \locCreateUpfrontGasCost \\
\If \scenCreateFCond _{i} = 1 & \Then & \gasNext _{i} = \gasActual _{i} - \locCreateFullGasCost \\
\If \scenCreateExecutionEmptyInitCode _{i} = 1 & \Then & \gasNext _{i} = \gasActual _{i} - \locCreateUpfrontGasCost \\
\If \scenCreateExecutionNonEmptyInitCode _{i} = 1 & \Then & \gasNext _{i} = \gasActual _{i} - \locCreateFullGasCost \\
\end{array} \right.
\]
\saNote{}
We provide some details.
Exceptional \inst{CREATE}-type instructions, like any exceptional instruction, fully consume the currently available gas.
Aborted \inst{CREATE}-type instructions only pay for the \locCreateUpfrontGasCost{} (and there is no child context.)
\inst{CREATE}-type instructions that raise the \textbf{Failure Condition $\bm{F}$} pay the \locCreateFullGasCost{}, including the ``\texttt{(63/64)-ths}'' to the child context, and don't get any of it back.
\inst{CREATE}-type instructions that lead to execution pay for \locCreateFullGasCost{}.
However, if the provided initialization code is \emph{empty}, then the execution context doesn't change and gets the entire ``\texttt{(63/64)-ths}'' back immediately.
The effective gas cost is therefore the \locCreateUpfrontGasCost{}.
If the provided initialization code is \emph{nonempty} then the execution context pays the \locCreateFullGasCost{}.
It \emph{may} get some of it back later down the line.
\end{description}

0 comments on commit c63467a

Please sign in to comment.