Skip to content

Commit b5143d0

Browse files
feat: TRM redesign (#106)
Signed-off-by: F Bojarski <[email protected]> Co-authored-by: Olivier Bégassat <[email protected]> Co-authored-by: Olivier Bégassat <[email protected]>
1 parent 3a08ee6 commit b5143d0

16 files changed

+232
-115
lines changed

.github/workflows/compile.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ jobs:
1212
- name: Install JetBrainsMono
1313
run: mkdir JetBrainsMono
1414
&& cd JetBrainsMono
15-
&& wget https://download.jetbrains.com/fonts/JetBrainsMono-2.304.zip
15+
&& wget https://download.jetbrains.com/fonts/JetBrainsMono-2.304.zip
1616
&& unzip JetBrainsMono-2.304.zip
1717
&& sudo mv fonts/ttf/*.ttf /usr/share/fonts/
1818
&& cd -

pkg/trm.sty

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
1-
\newcommand{\iAddrHi} {\imported{\addr\high}}
2-
\newcommand{\iAddrLo} {\imported{\addr\low}}
31
\newcommand{\trmAddrHi} {\trmMod\col{\_}\addr\col{\_HI}}
42
\newcommand{\rawAddrHi} {\col{RAW\_ADDR\_HI}}
53
\newcommand{\rawAddrLo} {\col{RAW\_ADDR\_LO}}
64
\newcommand{\isPrecompile} {\col{IS\_PRECOMPILE}}
7-
\newcommand{\plateauBit} {\col{PLATEAU\_BIT}}
5+
\newcommand{\trmLeadHi} {\col{leading\_bytes}}
6+
\newcommand{\first} {\col{FIRST}}
7+
8+
\newcommand{\maxPrecompileAddressName} {\red{\texttt{MAX\_PRC\_ADDRESS}}}
9+
\newcommand{\maxPrecompileAddress} {\red{9}}

trm/.DS_Store

6 KB
Binary file not shown.

trm/_all_trm.tex

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
\documentclass{article}
1+
\documentclass[fleqn]{report}
22
\usepackage[dvipsnames]{xcolor}
33
\usepackage{../pkg/common}
4+
\usepackage{xkeyval}
45
% \usepackage{../pkg/dark_theme}
56
\usepackage{../pkg/std}
67
\usepackage{../pkg/flags_stamps_selectors}
@@ -14,6 +15,10 @@
1415
\usepackage{../pkg/exponent}
1516
\usepackage{../pkg/thm_env}
1617
\usepackage{../pkg/offset_processor}
18+
\usepackage{../pkg/wc3}
19+
\usepackage{../pkg/xkeyval_macros/wcp_calls}
20+
\usepackage{../pkg/draculatheme}
21+
\usepackage{../pkg/iomf_done}
1722

1823
\title{Address trimming module}
1924
\author{Rollup team}

trm/_inputs.tex

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
\input{_local}
12
\section{Address trimming module}
23
\subsection{Introduction} \input{introduction}
34
\subsection{Columns} \input{columns}
@@ -6,7 +7,5 @@ \section{Constraints}
67
\subsection{Heartbeat} \label{sec: heartbeat} \input{heartbeat}
78
\subsection{Counter constancies} \input{constancies}
89
\subsection{Binary constraints} \input{binary}
9-
\subsection{\plateauBit{} contraints} \input{plateau}
10-
\subsection{Byte decomposition} \input{byteDec}
11-
\subsection{Target constraints} \input{target}
12-
\subsection{Identifying precompiles} \input{precompiles}
10+
\subsection{Computations} \input{setting_wcp_arg}
11+
\subsection{Lookup} \input{lookup}

trm/_local.tex

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
\def\locCtMaxTrm {\yellowm{3}}
2+
\def\locCtMaxTrmName {\yellowm{{\texttt{ct\_max\_trm}}}}
3+
\def\locAddressIsZero {\col{address\_is\_zero}}
4+
\def\locAddressIsNonzero {\col{address\_is\_nonzero}}
5+
\def\locAddressIsAtMostMaxPrecompileAddress {\col{address\_at\_most\_max\_PRC}}
6+
%
7+
\def\anchorRow {\redm{4}}
8+
%
9+
\def\rowOffsetAddress {\redm{0}}
10+
\def\rowOffsetAddressTrm {\redm{1}}
11+
\def\rowOffsetNonZeroAddr {\redm{2}}
12+
\def\rowOffsetPrcAddr {\redm{3}}

trm/binary.tex

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
The following columns are binary:
22
\begin{multicols}{3}
33
\begin{enumerate}
4-
\item $\isPrecompile$
5-
\item $\plateauBit$
6-
\item $\bit{1}$
4+
\item $\iomf$
5+
\item $\first$ \quad (\trash)
6+
\item $\isPrecompile$ \quad (\trash)
77
\end{enumerate}
88
\end{multicols}

trm/byteDec.tex

Lines changed: 0 additions & 24 deletions
This file was deleted.

trm/columns.tex

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,24 @@
11
\begin{enumerate}
2-
\item $\trmStamp$:
3-
stamp column; starts at $0$ and grows by 1 with every served request; like many other stamp columns its main purpose is to separate the different requests to that module;
4-
\item $\rawAddrHi$ and $\rawAddrLo$:
2+
\item $\iomf$:
3+
monotonous bit column that lights up for non-padding rows;
4+
\item $\first$:
5+
bit column that lights up precisely at the first row of all counter-loop;
6+
\item
57
\godGiven{}
8+
$\rawAddrHi$ and $\rawAddrLo$:
69
\ccc{}; contains the high and low part of some stack value which ought to be interpreted as an address;
7-
\item $\trmAddrHi$:
10+
\item
11+
\markAsJustifiedHere{}
812
\godGiven{}
13+
$\trmAddrHi$:
914
\ccc{}; contains the trimmed version of the high part of the address argument;
10-
\item $\isPrecompile$:
15+
\item
16+
\markAsJustifiedHere{}
1117
\godGiven{}
12-
\ccbc{}; equals $1$ \emph{if and only if} the trimmed address is in the range $\{1, 2,\dots, 9\}$;
18+
$\isPrecompile$:
19+
\ccbc{}; equals $1$ \emph{if and only if} the trimmed address is in the range $\{1, 2,\dots, \maxPrecompileAddress\}$;
1320
\item $\ct$:
14-
counter column: counts continuously from $0$ to $\llargeMO$ and resets;
15-
\item $\byteCol{HI}$ and $\acc{HI}$:
16-
byte column and associated accumulator column;
17-
\item $\byteCol{LO}$ and $\acc{LO}$:
18-
byte column and associated accumulator column;
19-
\item $\acc{T}$:
20-
accumulator column; accumulates some of the bytes from $\byteCol{HI}$;
21-
\item $\plateauBit$:
22-
binary column that implements a \textbf{binary plateau constraint} in that it switches from $0$ to $1$ when $\ct_{i} = 12$;
23-
\item $\bit{1}$:
24-
binary column; used in establishing that a (trimmed) address is that of a precompile.
21+
counter column: counts continuously from $0$ to $\locCtMaxTrmName$ ($= \locCtMaxTrm$) and resets;
22+
\item $\argOneHi$, $\argOneLo$, $\argTwoHi$, $\argTwoLo$, $\res$, $\INST$:
23+
arguments for calls to the \wcpMod{} module;
2524
\end{enumerate}

trm/constancies.tex

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@
33
\If \ct_{i} \neq 0 ~ \Then \col{X}_{i} = \col{X}_{i - 1}.
44
\]
55
We impose that the following columns be counter constant:
6-
\begin{multicols}{4}
6+
\begin{multicols}{2}
77
\begin{enumerate}
8-
\item $\rawAddrHi$
9-
\item $\rawAddrLo$
10-
\item $\trmAddrHi$
8+
\item $\rawAddrHi$
9+
\item $\rawAddrLo$
10+
\item $\trmAddrHi$
1111
\item $\isPrecompile$
1212
\end{enumerate}
1313
\end{multicols}

trm/heartbeat.tex

Lines changed: 20 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,24 @@
1-
The heartbeat of the address trimming module is very simple: the \ct{} column counts from $0$ to $\llargeMO$ unless the $\trmStamp$ is zero, in which case it hovers at $0$.
1+
The heartbeat of the address trimming module is very simple: the \ct{} column counts from $0$ to $\locCtMaxTrm$ unless $\iomf$ is zero, in which case it hovers at $0$.
22
\begin{enumerate}
3-
\item $\trmStamp_{0} = 0$
4-
\item $\trmStamp_{i + 1} \in \{ \trmStamp_{i}, 1 + \trmStamp_{i} \}$
5-
\item \If $\trmStamp_{i} = 0$ \Then
6-
\[
7-
\left\{ \begin{array}{lcl}
8-
\rawAddrHi_{i} & \!\!\! = \!\!\! & 0 \\
9-
\rawAddrLo_{i} & \!\!\! = \!\!\! & 0 \\
10-
\trmAddrHi_{i} & \!\!\! = \!\!\! & 0 \\
11-
\isPrecompile_{i} & \!\!\! = \!\!\! & 0 \\
12-
\end{array} \right.
13-
\qquad
14-
\left\{ \begin{array}{lcl}
15-
\ct_{i} & \!\!\! = \!\!\! & 0 \quad (\trash) \\
16-
\byteCol{HI}_{i} & \!\!\! = \!\!\! & 0 \quad (\trash) \\
17-
\byteCol{LO}_{i} & \!\!\! = \!\!\! & 0 \quad (\trash) \\
18-
\end{array} \right.
19-
\]
20-
%$\ct_{i} = 0$
21-
\item \If $\trmStamp_{i + 1} \neq \trmStamp_{i}$ \Then $\ct_{i + 1} = 0$
22-
\item \If $\trmStamp_{i} \neq 0$ \Then
3+
\item $\iomf_{0} = 0$
4+
\item $\iomf_{i + 1} \in \{ \iomf_{i}, 1 + \iomf_{i} \}$
5+
\item \If $\iomf_{i} = 0$ \Then
236
\begin{enumerate}
24-
\item \If $\ct_{i} \neq \llargeMO$ \Then $\ct_{i + 1} = 1 + \ct_{i}$
25-
\item \If $\ct_{i} = \llargeMO$ \Then $\trmStamp_{i + 1} = 1 + \trmStamp_{i}$
7+
\item $\rawAddrHi_{i} = 0 $
8+
\item $\rawAddrLo_{i} = 0 $
9+
\item $\trmAddrHi_{i} = 0 $
10+
\item $\isPrecompile_{i} = 0 $
11+
\item $\ct_{i+1} = 0 $
2612
\end{enumerate}
27-
\item \If $\trmStamp_{N} \neq 0$ \Then $\ct_{N} = \llargeMO$
13+
\item \If $\iomf_{i} = 1$ \Then
14+
\begin{enumerate}
15+
\item \If $\ct_{i} = 0$ \Then $\first_{i} = 1$
16+
\item \If $\ct_{i} \neq 0$ \Then $\first_{i} = 0$ (\trash)
17+
\item \If $\ct_{i} \neq \locCtMaxTrm$ \Then $\ct_{i + 1} = 1 + \ct_{i}$
18+
\item \If $\ct_{i} = \locCtMaxTrm$ \Then $\ct_{i + 1} = 0$
19+
\end{enumerate}
20+
\item \If $\iomf_{N} = 1$ \Then $\ct_{i} = \locCtMaxTrm$
2821
\end{enumerate}
22+
\saNote{}
23+
There is actually no need to constrain $\first$ to vanish outside of the first row.
24+
If one writes different values in this column outside of the first row traces will fail.

trm/introduction.tex

Lines changed: 21 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,33 @@
1-
The \textbf{address trimming module} is a tiny module whose purpose is twofold:
1+
The \textbf{address trimming module} is a tiny module whose purpose is manyfold:
22
(\emph{a})
33
reduce 32 byte strings modulo $2^{160}$
44
(\emph{b})
55
identify addresses of precompiles.
6+
%(\emph{c})
7+
%proving the smallness of addresses on behalf of \rlpTxnMod{}. TODO reenable with RLP_TXN update
68
Recall that some opcodes take an address stack argument which may require trimming to be interpreted as an address.
79
Furthermore when computing a deployment address associated with an invokation of a \inst{CREATE}-type instruction the \rlpAddrMod{} module is called, too, to trim down the raw \texttt{KECCAK} hash.
810
Also every new address appearing in the \hubMod{} module is automatically trimmed upon first encounter.
911
Note that carrying out the first of these tasks boils down to trimming off the leading bytes off of the high part of the imported address. The following opcodes may trigger it:
1012
\begin{multicols}{4}
11-
\begin{enumerate}
12-
\item \inst{BALANCE}
13-
\item \inst{EXTCODESIZE}
14-
\item \inst{EXTCODECOPY}
15-
\item \inst{EXTCODEHASH}
16-
\item \inst{CALL}
17-
\item \inst{CALLCODE}
18-
\item \inst{STATICCALL}
19-
\item \inst{DELEGATECALL}
20-
\item \inst{SELFDESTRUCT}
21-
\item[\vspace{\fill}]
22-
\end{enumerate}
13+
\begin{enumerate}
14+
\item \inst{BALANCE}
15+
\item[\vspace{\fill}]
16+
\item[\vspace{\fill}]
17+
\item[\vspace{\fill}]
18+
\item \inst{EXTCODESIZE}
19+
\item \inst{EXTCODECOPY}
20+
\item \inst{EXTCODEHASH}
21+
\item[\vspace{\fill}]
22+
\item \inst{CALL}
23+
\item \inst{CALLCODE}
24+
\item \inst{STATICCALL}
25+
\item \inst{DELEGATECALL}
26+
\item \inst{SELFDESTRUCT}
27+
\item[\vspace{\fill}]
28+
\item[\vspace{\fill}]
29+
\item[\vspace{\fill}]
30+
\end{enumerate}
2331
\end{multicols}
2432
These are precisely the instructions which raise the $\trmFlag$ in the \hubMod{}.
2533

trm/lookup.tex

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
\begin{description}
2+
\item[\underline{Selector:}] none
3+
\item[\underline{Source columns:}] ---
4+
\begin{multicols}{3}
5+
\begin{enumerate}
6+
\item $\argOneHi$
7+
\item $\argOneLo$
8+
\item $\argTwoHi$
9+
\item $\argTwoLo$
10+
\item $\res$
11+
\item $\INST$
12+
\end{enumerate}
13+
\end{multicols}
14+
\item[\underline{Target columns:}] ---
15+
\begin{multicols}{3}
16+
\begin{enumerate}
17+
\item $\argOneHi$
18+
\item $\argOneLo$
19+
\item $\argTwoHi$
20+
\item $\argTwoLo$
21+
\item $\res$
22+
\item $\INST$
23+
\end{enumerate}
24+
\end{multicols}
25+
\end{description}

trm/plateau.tex

Lines changed: 0 additions & 8 deletions
This file was deleted.

0 commit comments

Comments
 (0)