mirror of
https://github.com/lux-apps/papers.git
synced 2026-10-30 18:15:21 +00:00
Restructured from flat .tex/.pdf files into per-paper subdirectories. Added Antje Worring as co-author on all papers. Synced PDFs to pdfs/ for download site.
145 lines
4.4 KiB
TeX
145 lines
4.4 KiB
TeX
\section{EVM Optimization Strategies}
|
|
|
|
|
|
\subsection{Keccak-CTR vs. SHAKE for XOF}
|
|
|
|
\subsubsection{The SHAKE Cost Problem}
|
|
|
|
SHAKE256 is a standardized XOF based on Keccak permutation. However:
|
|
\begin{itemize}
|
|
\item EVM provides native Keccak256 precompile (30 gas + 6 gas/word)
|
|
\item SHAKE uses different padding (0x1F vs 0x01 for Keccak256)
|
|
\item Implementing SHAKE in Solidity requires:
|
|
\begin{itemize}
|
|
\item Full Keccak permutation in pure Solidity ($>$300k gas)
|
|
\item Multiple state transformations for XOF mode ($>$500k total)
|
|
\end{itemize}
|
|
\end{itemize}
|
|
|
|
SHAKE operations in HashToPoint dominate 70\% of FALCON verification cost on EVM.
|
|
|
|
\subsubsection{Keccak-CTR Construction}
|
|
|
|
We replace SHAKE with a Keccak-based counter mode (Keccak-CTR):
|
|
|
|
\textbf{Construction:}
|
|
\begin{algorithmic}[1]
|
|
\STATE $\text{state} \gets \text{Keccak256}(r \| m)$
|
|
\STATE $i \gets 0$
|
|
\WHILE{need more output}
|
|
\STATE $\text{block} \gets \text{Keccak256}(\text{state} \| i)$
|
|
\STATE Emit 256 bits from block
|
|
\STATE $i \gets i + 1$
|
|
\ENDWHILE
|
|
\end{algorithmic}
|
|
|
|
\textbf{Security Argument:} Keccak-CTR instantiates a pseudorandom function (PRF) under the random oracle model. Each counter value produces independent 256-bit blocks. The construction is similar to CTR-DRBG in NIST SP 800-90A \cite{nist800-90a}.
|
|
|
|
\textbf{Gas Cost Comparison:}
|
|
\begin{center}
|
|
\begin{tabular}{lrr}
|
|
\hline
|
|
\textbf{Operation} & \textbf{SHAKE256} & \textbf{Keccak-CTR} \\
|
|
\hline
|
|
Initialization & 300k gas & 30 gas \\
|
|
Per 256-bit block & 500k gas & 30 gas \\
|
|
Total (512 coefficients) & $>$16M gas & $<$10k gas \\
|
|
\hline
|
|
\end{tabular}
|
|
\end{center}
|
|
|
|
This single optimization reduces verification cost by $>$15M gas (75\% of total).
|
|
|
|
\subsection{NTT Implementation Strategies}
|
|
|
|
\subsubsection{Recursive vs. Iterative NTT}
|
|
|
|
FALCON's reference NTT is recursive (Cooley-Tukey):
|
|
\begin{lstlisting}[language=C]
|
|
void ntt_recursive(int *a, int n) {
|
|
if (n == 1) return;
|
|
int *even = split_even(a, n);
|
|
int *odd = split_odd(a, n);
|
|
ntt_recursive(even, n/2);
|
|
ntt_recursive(odd, n/2);
|
|
combine(a, even, odd, n);
|
|
}
|
|
\end{lstlisting}
|
|
|
|
\textbf{Solidity Limitations:}
|
|
\begin{itemize}
|
|
\item No native recursion support (stack depth limited)
|
|
\item Memory allocation expensive ($>$1000 gas per allocation)
|
|
\item Function calls cost 2400 gas base + memory expansion
|
|
\end{itemize}
|
|
|
|
\textbf{Iterative NTT:} We implement Gentleman-Sande butterfly network:
|
|
\begin{algorithmic}[1]
|
|
\STATE Bit-reverse permutation of input
|
|
\FOR{$s = 1$ to $\log_2 n$}
|
|
\STATE $m \gets 2^s$
|
|
\STATE $\omega_m \gets \omega^{n/m}$ (precomputed root)
|
|
\FOR{$k = 0$ to $n-1$ by $m$}
|
|
\STATE $\omega \gets 1$
|
|
\FOR{$j = 0$ to $m/2 - 1$}
|
|
\STATE $t \gets \omega \cdot a[k+j+m/2]$
|
|
\STATE $u \gets a[k+j]$
|
|
\STATE $a[k+j] \gets u + t \mod q$
|
|
\STATE $a[k+j+m/2] \gets u - t \mod q$
|
|
\STATE $\omega \gets \omega \cdot \omega_m \mod q$
|
|
\ENDFOR
|
|
\ENDFOR
|
|
\ENDFOR
|
|
\end{algorithmic}
|
|
|
|
\textbf{Cost Comparison (512-point NTT):}
|
|
\begin{center}
|
|
\begin{tabular}{lrr}
|
|
\hline
|
|
\textbf{Implementation} & \textbf{Gas Cost} & \textbf{Speedup} \\
|
|
\hline
|
|
Recursive Solidity & 4.5M & 1.0x \\
|
|
Iterative Solidity & 1.8M & 2.5x \\
|
|
Yul optimized & 0.9M & 5.0x \\
|
|
\hline
|
|
\end{tabular}
|
|
\end{center}
|
|
|
|
\subsubsection{16-Bit Coefficient Packing}
|
|
|
|
FALCON operates over $\mathbb{Z}_q$ where $q = 12289 < 2^{14}$. We pack 16 coefficients per 256-bit EVM word:
|
|
|
|
\textbf{Encoding:} Polynomial $p = \sum_{i=0}^{511} p_i x^i$ becomes 32 uint256 words:
|
|
\begin{equation}
|
|
W_k = \sum_{i=0}^{15} p_{16k+i} \cdot 2^{16i}, \quad k = 0, \ldots, 31
|
|
\end{equation}
|
|
|
|
\textbf{Benefits:}
|
|
\begin{itemize}
|
|
\item Calldata cost: 16 bytes/coefficient $\times$ 4 gas/byte = 64 gas/coeff
|
|
\item vs. 32 bytes/word $\times$ 4 gas = 128 gas (50\% saving)
|
|
\item Native bitshift operations for unpacking (3 gas each)
|
|
\item Aligned with EVM's 256-bit architecture
|
|
\end{itemize}
|
|
|
|
\subsection{Gas Cost Breakdown}
|
|
|
|
\textbf{ETHFALCON Verification (1.8M gas):}
|
|
\begin{center}
|
|
\begin{tabular}{lrr}
|
|
\hline
|
|
\textbf{Operation} & \textbf{Gas} & \textbf{\% Total} \\
|
|
\hline
|
|
Keccak-CTR HashToPoint & 150k & 8.3\% \\
|
|
NTT forward (2x) & 1.8M & 100\%* \\
|
|
Pointwise multiplication & 80k & 4.4\% \\
|
|
Norm check & 120k & 6.7\% \\
|
|
Calldata (666 bytes) & 50k & 2.8\% \\
|
|
\hline
|
|
\textbf{Total} & \textbf{1.8M} & \textbf{100\%} \\
|
|
\hline
|
|
\multicolumn{3}{l}{* NTT dominates; other ops occur during NTT}
|
|
\end{tabular}
|
|
\end{center}
|
|
|