Skip to content

Commit a6f0b7b

Browse files
authored
EIP-1153 Arithmetization: Transient storage opcodes (#135)
1 parent a3a00be commit a6f0b7b

31 files changed

+691
-26
lines changed
Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
# Tasks
2+
3+
## Transient perspective and columns
4+
5+
- `PEEK_AT_TRANSIENT ≡ TRN`
6+
- it can only be on during `TX_EXEC`
7+
- transient columns
8+
```rust
9+
transient/ADDRESS_HI
10+
transient/ADDRESS_LO
11+
transient/STORAGE_KEY_HI
12+
transient/STORAGE_KEY_LO
13+
transient/VALUE_CURR_HI
14+
transient/VALUE_CURR_LO
15+
transient/VALUE_NEXT_HI
16+
transient/VALUE_NEXT_LO
17+
```
18+
- macros
19+
```rust
20+
sameTransientStorageValue[ relof ]
21+
undoTransientStorageValueUpdate[ relof_undo, relof_do ]
22+
```
23+
24+
## Instruction handling
25+
26+
- updating the storage family
27+
- flags, including staticFlag
28+
- decoded flags
29+
- processing
30+
- acceptable exceptions
31+
- exceptions:
32+
- SUX
33+
- OOGX
34+
```rust
35+
STACK
36+
```
37+
- STATICX (TSTORE only)
38+
```rust
39+
STACK
40+
CONTEXT
41+
```
42+
- unexceptional WILL_REVERT
43+
```rust
44+
STACK
45+
CONTEXT
46+
TRANSIENT // doing
47+
TRANSIENT // undoing
48+
```
49+
- unexceptional WONT_REVERT
50+
```rust
51+
STACK
52+
CONTEXT
53+
TRANSIENT // doing
54+
```
55+
- starting with `STATICX` we check whether the context is static
56+
- as soon as unexceptional we also retrieve the `context/ACCOUNT_ADDRESS`
57+
- just as with `SLOAD` we don't print anything on the stack unless the instruction is unexceptional
58+
- contrary to `SSTORE` / `SLOAD` we don't have to read storage to price it, in particular we don't need to retrieve transient storage data and play with warmth
59+
- if `CN_WILL_REVERT` we require two rows for `TSTORE`
60+
61+
## Consistency arguments
62+
63+
- permutation according to
64+
```rust
65+
(
66+
// order imposing columns
67+
+ PEEK_AT_TRANSIENT,
68+
+ ABSOLUTE_TRANSACTION_NUMBER,
69+
+ transient/ADDRESS_HI,
70+
+ transient/ADDRESS_LO,
71+
+ transient/STORAGE_KEY_HI,
72+
+ transient/STORAGE_KEY_LO,
73+
+ DOM_STAMP,
74+
- SUB_STAMP,
75+
// along for the ride
76+
transient/VALUE_CURR_HI,
77+
transient/VALUE_CURR_LO,
78+
transient/VALUE_NEXT_HI,
79+
transient/VALUE_NEXT_LO,
80+
)
81+
```
82+
- extraneous columns
83+
```rust
84+
// tcp ≡ transient consistency permutation
85+
tcp_FIRST_IN_TXN
86+
tcp_AGAIN_IN_TXN
87+
// no ``tcp_FINAL_IN_TXN'' column required
88+
```
89+
- constraints
90+
- standard constraints for FIRST/AGAIN
91+
- consistency is trivial: FIRST you have zero, when when meeting an [ADDRESS,STORAGE_KEY] pair AGAIN you get the previously updated value

hub/_all_hub.tex

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
\usepackage{../pkg/warm}
1414
\usepackage{../pkg/misc}
1515
\usepackage{../pkg/xkeyval_macros/context}
16+
\usepackage{../pkg/xkeyval_macros/transient}
1617
\usepackage{../pkg/xkeyval_macros/dom_sub_stamps}
1718
\usepackage{../pkg/xkeyval_macros/mmu_instructions}
1819
\usepackage{../pkg/xkeyval_macros/mxp_instructions}

hub/columns/_inputs.tex

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,5 @@ \subsection{Column names for storage-rows \lispDone{}} \label{hub
1010
\subsection{Column names for transaction-rows \lispDone{}} \label{hub: transaction columns} \input{columns/transaction}
1111
\subsection{Column names for miscellaneous-rows \lispDone{}} \label{hub: miscellaneous columns} \input{columns/miscellaneous/_inputs}
1212
\subsection{Column names for scenario-rows \lispDone{}} \label{hub: scenario columns} \input{columns/scenarios/_inputs}
13+
\subsection{Column names for transient-storage-rows \lispDone{}} \label{hub: transient storage columns} \input{columns/transient}
1314
\subsection{Column names for consistency arguments \lispDone{}} \label{hub: consistency argument columns} \input{columns/consistency_aux}

hub/columns/shared.tex

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,9 +95,10 @@
9595
(\emph{b}) \textbf{context-rows} display \textbf{context data}; they are characterized by $\peekContext \equiv 1$
9696
(\emph{c}) \textbf{miscellaneous-rows} log data to be externalized for further processing to other modules; they are characterized by $\peekMisc \equiv 1$
9797
(\emph{d}) \textbf{scenario-rows} are used to simplify the control flow of complex instructions; they are characterized by $\peekScenario \equiv 1$
98-
(\emph{e}) \textbf{stack rows} display \textbf{stack data}; they are characterized by $\peekStack \equiv 1$
98+
(\emph{e}) \textbf{stack-rows} display \textbf{stack data}; they are characterized by $\peekStack \equiv 1$
9999
(\emph{f}) \textbf{storage-rows} display \textbf{storage data}; they are characterized by $\peekStorage \equiv 1$
100100
(\emph{g}) \textbf{transaction-rows} display \textbf{transaction data}; they are characterized by $\peekTransaction \equiv 1$.
101+
(\emph{h}) \textbf{transient-storage-rows} display \textbf{transient storage data}; they are characterized by $\peekTransient \equiv 1$.
101102
\begin{enumerate}[resume]
102103
\item $\PEEKACCOUNT$:
103104
binary column which switches on \emph{if and only if} the current row peeks into account data (from which we \emph{exclude} storage data);
@@ -120,6 +121,9 @@
120121
\item $\PEEKTRANSACTION$:
121122
binary column which switches on \emph{if and only if} the current row peeks into transaction data;
122123
abbreviated to $\peekTransaction$;
124+
\item $\PEEKTRANSIENT$:
125+
binary column which switches on \emph{if and only if} the current row peeks into transient storage data;
126+
abbreviated to $\peekTransient$;
123127
\end{enumerate}
124128
\noindent We list some gas columns:
125129
\begin{enumerate}[resume]

hub/columns/stack.tex

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,12 +55,12 @@
5555
\item $\stackDecStackRamFlag$
5656
\item $\stackDecStoFlag$
5757
\item $\stackDecSwapFlag$
58+
\item $\stackDecTransFlag$
5859
\item $\stackDecTxnFlag$
5960
\item $\stackDecWcpFlag$
6061
\item[\vspace{\fill}]
6162
\item[\vspace{\fill}]
6263
\item[\vspace{\fill}]
63-
\item[\vspace{\fill}]
6464
\end{enumerate}
6565
\end{multicols}
6666
The following flags allow us to simply distinguish instructions within a given instruction family.

hub/columns/transient.tex

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
\textbf{Transient-storage-rows} are characterized by $\peekTransient \equiv 1$.
2+
Columns pertaining to that perspective are prefixed with the following symbol: $\transientSignifier$.
3+
We introduce the following columns:
4+
\begin{enumerate}
5+
\item
6+
$\transAddressHi$,
7+
$\transAddressLo$:
8+
high and low parts of an account address;
9+
\item
10+
$\transKeyHi$,
11+
$\transKeyLo$:
12+
high and low parts of a transient storage key of said account address;
13+
\item
14+
$\transCurrValueHi$,
15+
$\transCurrValueLo$:
16+
high and low parts of the value currently found at the transient storage key;
17+
\item
18+
$\transNextValueHi$,
19+
$\transNextValueLo$:
20+
high and low parts of the updated value in transient storage;
21+
\end{enumerate}
22+
\saNote{}
23+
The \zkEvm{} may produce transient-storage-rows in the following contexts \emph{only} and \emph{exclusively},
24+
(\emph{a}) when processing the \inst{TLOAD} instruction or
25+
(\emph{b}) when processing the \inst{TSTORE} instruction.

hub/consistencies/_inputs.tex

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
\input{consistencies/_local}
22

33
\section{Consistencies} \label{hub: consistencies}
4-
\subsection{Introduction} \label{hub: consistencies: intro} \input{consistencies/intro} \newpage
5-
\subsection{Execution environment consistency constraints \lispDone{}} \label{hub: consistencies: environment} \input{consistencies/environment/_inputs} \newpage
6-
\subsection{Context consistency constraints \lispDone{}} \label{hub: consistencies: context} \input{consistencies/context/_inputs} \newpage
7-
\subsection{Stack consistency constraints \lispDone{}} \label{hub: consistencies: stack} \input{consistencies/stack/_inputs} \newpage
8-
\subsection{Account consistency constraints \lispDone{}} \label{hub: consistencies: account} \input{consistencies/account/_inputs} \newpage
9-
\subsection{Storage consistency constraints \lispDone{}} \label{hub: consistencies: storage} \input{consistencies/storage/_inputs} \newpage
4+
\subsection{Introduction} \label{hub: consistencies: intro} \input{consistencies/intro} \newpage
5+
\subsection{Execution environment consistency constraints \lispDone{}} \label{hub: consistencies: environment} \input{consistencies/environment/_inputs} \newpage
6+
\subsection{Context consistency constraints \lispDone{}} \label{hub: consistencies: context} \input{consistencies/context/_inputs} \newpage
7+
\subsection{Stack consistency constraints \lispDone{}} \label{hub: consistencies: stack} \input{consistencies/stack/_inputs} \newpage
8+
\subsection{Account consistency constraints \lispDone{}} \label{hub: consistencies: account} \input{consistencies/account/_inputs} \newpage
9+
\subsection{Storage consistency constraints \lispDone{}} \label{hub: consistencies: storage} \input{consistencies/storage/_inputs} \newpage
10+
\subsection{Transient storage consistency constraints \lispTodo{}} \label{hub: consistencies: transient storage} \input{consistencies/transient/_inputs} \newpage

hub/consistencies/_local.tex

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
\def\locFullAddress {\col{full\_address}}
22
\def\locAccFullAddress {\order{\accountSignifier\locFullAddress}}
33
\def\locStoFullAddress {\order{\storageSignifier\locFullAddress}}
4+
\def\locTransientFullAddress {\order{\transientSignifier\locFullAddress}}
5+
6+
\def\locTransientTransitionTransaction {\col{transition\_transaction}}
47

58
\def\locAccTransition {\accountSignifier\col{transition}}
69
\def\locAccTransitionSum {\locAccTransition\col{\_sum}}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
\subsubsection{Properties of the permutation \lispTodo{}} \label{hub: consistencies: transient storage: permutation} \input{consistencies/transient/permutation}
2+
\subsubsection{Permuted columns \lispTodo{}} \label{hub: consistencies: transient storage: columns} \input{consistencies/transient/columns}
3+
\subsubsection{Constraints for ``\col{FIRST}'' and ``\col{AGAIN}'' columns \lispTodo{}} \label{hub: consistencies: transient storage: first again} \input{consistencies/transient/first_again}
4+
\subsubsection{Constraints \lispTodo{}} \label{hub: consistencies: transient storage: constraints} \input{consistencies/transient/constraints}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
We list the columns that must be row-permuted according to the previously described row-permutation.
2+
\begin{multicols}{3}
3+
\begin{enumerate}
4+
\item $\order{\transAddressHi}$
5+
\item $\order{\transAddressLo}$
6+
\item $\order{\transKeyHi}$
7+
\item $\order{\transKeyLo}$
8+
\item $\order{\transCurrValueHi}$
9+
\item $\order{\transCurrValueLo}$
10+
\item $\order{\transNextValueHi}$
11+
\item $\order{\transNextValueLo}$
12+
\item $\order{\peekTransient}$
13+
\item $\order{\absTxNum}$
14+
\item $\order{\domStamp}$
15+
\item $\order{\subStamp}$
16+
% \item[\vspace{\fill}]
17+
\end{enumerate}
18+
\end{multicols}
19+
\noindent We further define the following shorthand
20+
\[
21+
\locTransientFullAddress _{i}
22+
\define
23+
256^\llarge \cdot \order{\transAddressHi}_{i} + \order{\transAddressLo}_{i}
24+
\]
25+
\noindent We introduce some more columns.
26+
Similar remarks to those of section~(\ref{hub: consistencies: account: first again final}) apply to these following columns.
27+
\begin{multicols}{2}
28+
\begin{enumerate}
29+
\item $\transientFirstInTransaction$
30+
\item $\transientAgainInTransaction$
31+
\end{enumerate}
32+
\end{multicols}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
We now go on to consistency constraints proper.
2+
\begin{description}
3+
\item[\underline{\underline{Initial transient storage values are zero:}}]
4+
\If $\transientFirstInTransaction _{i} = 1$ \Then
5+
we impose that
6+
\[
7+
\left\{ \begin{array}{lcl}
8+
\order{\transCurrValueHi}_{i} & = & 0 \\
9+
\order{\transCurrValueLo}_{i} & = & 0 \\
10+
\end{array} \right.
11+
\]
12+
\item[\underline{\underline{Linking of transient storage values:}}]
13+
\If $\transientAgainInTransaction _{i} = 1$ \Then
14+
we impose that
15+
\[
16+
\left\{ \begin{array}{lcl}
17+
\order{\transCurrValueHi}_{i} & = & \order{\transNextValueHi}_{i - 1} \\
18+
\order{\transCurrValueLo}_{i} & = & \order{\transNextValueLo}_{i - 1} \\
19+
\end{array} \right.
20+
\]
21+
\end{description}
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
\begin{description}
2+
\item[\underline{\underline{Generalities:}}]
3+
we impose the following
4+
\begin{enumerate}
5+
\item $\transientFirstInTransaction$ is binary
6+
\item $\transientAgainInTransaction$ is binary
7+
\item we unconditionally impose that
8+
\[
9+
\order{\peekTransient} _{i}
10+
=
11+
\transientFirstInTransaction _{i} + \transientAgainInTransaction _{i}
12+
\]
13+
\end{enumerate}
14+
% \end{description}
15+
% We define the following shorthand:
16+
% \[
17+
% \locTransientTransitionTransaction \define \transientFinalInTransaction _{i - 1} + \transientFirstInTransaction _{i}
18+
% \]
19+
% \begin{description}
20+
\item[\underline{\underline{First transient row:}}]
21+
\If $\order{\peekTransient} _{i - 1} = 0$ \Then $\order{\peekTransient} _{i} = \transientFirstInTransaction _{i}$
22+
\item[\underline{\underline{Repeat transient row:}}]
23+
we impose that
24+
\If
25+
\[
26+
\left\{ \begin{array}{lclc}
27+
\order{\peekTransient} _{i - 1} & = & 1 & \et \\
28+
\order{\peekTransient} _{i} & = & 1 \\
29+
\end{array} \right.
30+
\]
31+
\Then we impose that
32+
\begin{enumerate}
33+
\item \If $\locTransientFullAddress _{i - 1} \neq \locTransientFullAddress _{i}$ \Then
34+
\[
35+
\left\{ \begin{array}{lclr}
36+
\transientFirstInTransaction _{i} & = & 1 \\
37+
\transientAgainInTransaction _{i} & = & 0 & (\sanityCheck) \\
38+
\end{array} \right.
39+
\]
40+
\item \If $\order{\transKeyHi} _{i - 1} \neq \order{\transKeyHi} _{i}$ \Then
41+
\[
42+
\left\{ \begin{array}{lclr}
43+
\transientFirstInTransaction _{i} & = & 1 \\
44+
\transientAgainInTransaction _{i} & = & 0 & (\sanityCheck) \\
45+
\end{array} \right.
46+
\]
47+
\item \If $\order{\transKeyLo} _{i - 1} \neq \order{\transKeyLo} _{i}$ \Then
48+
\[
49+
\left\{ \begin{array}{lclr}
50+
\transientFirstInTransaction _{i} & = & 1 \\
51+
\transientAgainInTransaction _{i} & = & 0 & (\sanityCheck) \\
52+
\end{array} \right.
53+
\]
54+
\item \If $\order{\absTxNum} _{i - 1} \neq \order{\absTxNum} _{i}$ \Then
55+
\[
56+
\left\{ \begin{array}{lclr}
57+
\transientFirstInTransaction _{i} & = & 1 \\
58+
\transientAgainInTransaction _{i} & = & 0 & (\sanityCheck) \\
59+
\end{array} \right.
60+
\]
61+
\item \If
62+
\[
63+
\left\{ \begin{array}{lclc}
64+
\locTransientFullAddress _{i - 1} & \!\!\! = \!\!\! & \locTransientFullAddress _{i} & \et \\
65+
\order{\transKeyHi} _{i - 1} & \!\!\! = \!\!\! & \order{\transKeyHi} _{i} & \et \\
66+
\order{\transKeyLo} _{i - 1} & \!\!\! = \!\!\! & \order{\transKeyLo} _{i} & \et \\
67+
\order{\absTxNum} _{i - 1} & \!\!\! = \!\!\! & \order{\absTxNum} _{i} \\
68+
\end{array} \right.
69+
\]
70+
\Then
71+
\[
72+
\left\{ \begin{array}{lclr}
73+
\transientFirstInTransaction _{i} & = & 0 & (\sanityCheck) \\
74+
\transientAgainInTransaction _{i} & = & 1 \\
75+
\end{array} \right.
76+
\]
77+
\end{enumerate}
78+
\end{description}
79+
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
We consider a row permutation $\col{X}\rightsquigarrow\order{\col{X}}$ with the property that within the row-permuted columns
2+
\[
3+
\left[ \begin{array}{c|l}
4+
\nearrow & \order{\peekTransient}, \\
5+
\nearrow & \quad\quad \order{\transAddressHi}, \\
6+
\nearrow & \quad\quad \quad\quad \order{\transAddressLo}, \\
7+
\nearrow & \quad\quad \quad\quad \quad\quad \order{\transKeyHi}, \\
8+
\nearrow & \quad\quad \quad\quad \quad\quad \quad\quad \order{\transKeyLo}, \\
9+
\nearrow & \quad\quad \quad\quad \quad\quad \quad\quad \quad\quad \order{\absTxNum}, \\
10+
\nearrow & \quad\quad \quad\quad \quad\quad \quad\quad \quad\quad \quad\quad \order{\domStamp}, \\
11+
\searrow & \quad\quad \quad\quad \quad\quad \quad\quad \quad\quad \quad\quad \quad\quad \order{\subStamp}, \\
12+
\end{array} \right]
13+
\]
14+
\noindent
15+
(\emph{a}) (reordered) padding-rows precede all non-padding-rows
16+
(\emph{b}) \textbf{(reordered) transient-storage-rows}\footnote{by extension rows where $\order{\peekStorage} \equiv 1$} are contiguous
17+
(\emph{c}) along the (reordered) storage-rows the remaining columns are $(+, +, +, +, +, +, +, -)$-lexicographically ordered.

hub/heartbeat/peeking_flags.tex

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@
44
$\peekContext$,
55
$\peekAccount$,
66
$\peekStorage$,
7-
$\peekTransaction$
7+
$\peekTransaction$,
8+
$\peekTransient$
89
which specify which data store the present peeks into as well as
910
$\peekMisc$ which highlights rows that are used to trigger certain lookups and
1011
$\peekScenario$ which is used to simplify the control flow of complex instructions.
@@ -15,8 +16,10 @@
1516
$\peekMisc$,
1617
$\peekScenario$
1718
$\peekStack$,
18-
$\peekStorage$ and
19-
$\peekTransaction$
19+
$\peekStorage$,
20+
$\peekTransaction$,
21+
and
22+
$\peekTransient$
2023
are binary;
2124
\end{enumerate}
2225
We define the following shorthand:
@@ -31,6 +34,7 @@
3134
+ & \peekStack _{i} \\
3235
+ & \peekStorage _{i} \\
3336
+ & \peekTransaction _{i} \\
37+
+ & \peekTransient _{i} \\
3438
\end{array} \right]
3539
\]
3640
and we impose
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
\input{instruction_handling/storage/_local}
2-
\subsubsection{Supported instructions and flags} \label{hub: instruction handling: storage: flags} \input{instruction_handling/storage/flags}
3-
\subsubsection{Shorthands} \label{hub: instruction handling: storage: shorthands} \input{instruction_handling/storage/shorthands}
4-
\subsubsection{Constraints} \label{hub: instruction handling: storage: constraints} \input{instruction_handling/storage/constraints}
2+
\subsubsection{Supported instructions and flags \lispDone{}} \label{hub: instruction handling: storage: flags} \input{instruction_handling/storage/flags}
3+
\subsubsection{Shorthands \lispDone{}} \label{hub: instruction handling: storage: shorthands} \input{instruction_handling/storage/shorthands}
4+
\subsubsection{Constraints \lispDone{}} \label{hub: instruction handling: storage: constraints} \input{instruction_handling/storage/constraints}

0 commit comments

Comments
 (0)