Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bugfix for GAS_NEXT of CREATE's #15

Closed
wants to merge 9 commits into from
3 changes: 2 additions & 1 deletion hub/instruction_handling/create/_local.tex
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,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
57 changes: 37 additions & 20 deletions hub/instruction_handling/create/generalities/all.tex
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
\scenCreateSum _{i} & = & 1 \\
\end{array} \right.}
\end{center}
The present section deals with generalities pertaining to \inst{CREATE}-type instructions. These constraints hold regardless of anything else.
The present section deals with generalities pertaining to \inst{CREATE}-type instructions. These constraints hold regardless of anything else.
\begin{description}
\item[\underline{Setting the stack pattern:}]
we impose $\createSP_{i - \createFirstStackRowOffset}\big[ \locIsCreateTwo \big]$;
Expand Down Expand Up @@ -47,7 +47,7 @@
\[
\locStaticx = \locIsStatic
\]
\item[\underline{Setting the module flags of miscellaneous-row $n^°(i + \createMiscRowOffset)$::}]
\item[\underline{Setting the module flags of miscellaneous-row $n^°(i + \createMiscRowOffset)$::}]
every processing path for \inst{CREATE}-type instructions contains a single \textbf{miscellaneous-row}
\[
\weightedMiscFlagSum
Expand Down Expand Up @@ -129,12 +129,12 @@
where we define the following shorthands:
\[
\left\{ \begin{array}{lclc}
\If \locTriggerRlpAddr = 0 ~ \Then
\If \locTriggerRlpAddr = 0 ~ \Then
\left\{ \begin{array}{lclc}
\locCreateeNonce & = & 0 \\
\locCreateeHasCode & = & 0 \\
\end{array} \right. \\
\If \locTriggerRlpAddr = 1 ~ \Then
\If \locTriggerRlpAddr = 1 ~ \Then
\left\{ \begin{array}{lclc}
\locCreateeNonce & = & \accNonce _{i + \createFirstCreateeAccountRowOffset} \\
\locCreateeHasCode & = & \accHasCode _{i + \createFirstCreateeAccountRowOffset} \\
Expand Down Expand Up @@ -199,23 +199,23 @@
\]
where we have used the following (as of yet undefined) shorthands \locTgtId{}, \locAuxId{} and \locExoSum{} which we define as follows:
\begin{enumerate}
\item \If $\locHashInitCode = 1$ \Then
\item \If $\locHashInitCode = 1$ \Then
\[
\left\{ \begin{array}{lcl}
\locTgtId & \define & \nothing \\
\locAuxId & \define & 1 + \hubStamp_{i} \\
\locExoSum & \define & \exoWeightKec \\
\end{array} \right.
\]
\item \If $\locHashInitCodeAndSendToRom = 1$ \Then
\item \If $\locHashInitCodeAndSendToRom = 1$ \Then
\[
\left\{ \begin{array}{lcl}
\locTgtId & \define & \locDepCfi \\
\locAuxId & \define & 1 + \hubStamp_{i} \\
\locExoSum & \define & \exoWeightRom + \exoWeightKec \\
\end{array} \right.
\]
\item \If $\locSendInitCodeToRom = 1$ \Then
\item \If $\locSendInitCodeToRom = 1$ \Then
\[
\left\{ \begin{array}{lcl}
\locTgtId & \define & \locDepCfi \\
Expand All @@ -234,24 +234,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 \\
Copy link
Collaborator Author

@OlivierBBB OlivierBBB Dec 2, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This line right here is the bug fix: scenario/CREATE_FAILURE_CONDITION had wrong gas comuptation

\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.
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the fix. The issue was with Failure Condition F raising CREATE's not following the same pattern as other scenarios in \scenCreateNoContextChange

Copy link
Collaborator Author

@OlivierBBB OlivierBBB Dec 2, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For context, Failure Condition F in the yellow paper, around page 12. Here we only care about the state collision bit, i.e. the first line

image

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And the associated effect on returned gas
image

\end{description}