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.
79 lines
2.9 KiB
TeX
79 lines
2.9 KiB
TeX
\section{Precompile Architecture}
|
|
\label{sec:architecture}
|
|
|
|
\subsection{Address Space}
|
|
|
|
Lux precompiles occupy the address range \texttt{0x0200000000000000000000000000000000000001} through \texttt{0x02000000000000000000000000000000000000FF}, avoiding collision with Ethereum precompiles (\texttt{0x01}--\texttt{0x09}) and proposed precompiles (\texttt{0x0A}--\texttt{0x13}).
|
|
|
|
\begin{table}[H]
|
|
\centering
|
|
\caption{Lux custom precompile address assignments.}
|
|
\label{tab:addresses}
|
|
\begin{tabular}{llr}
|
|
\toprule
|
|
\textbf{Address (suffix)} & \textbf{Precompile} & \textbf{Gas Base} \\
|
|
\midrule
|
|
\texttt{0x01} & BLS12-381 G1 Add & 500 \\
|
|
\texttt{0x02} & BLS12-381 G1 Mul & 12,000 \\
|
|
\texttt{0x03} & BLS12-381 G1 Multi-Exp & 12,000$+$ \\
|
|
\texttt{0x04} & BLS12-381 G2 Add & 800 \\
|
|
\texttt{0x05} & BLS12-381 G2 Mul & 45,000 \\
|
|
\texttt{0x06} & BLS12-381 Pairing & 113,000$+$ \\
|
|
\texttt{0x07} & BLS12-381 Map to G1 & 5,500 \\
|
|
\texttt{0x08} & BLS12-381 Map to G2 & 110,000 \\
|
|
\texttt{0x10} & BN254 Extended Pairing & 80,000$+$ \\
|
|
\texttt{0x11} & BN254 Batch Pairing & 45,000$+$ \\
|
|
\texttt{0x20} & secp256k1 Batch Verify & 3,000$+$ \\
|
|
\texttt{0x30} & Dilithium-3 Verify & 35,000 \\
|
|
\texttt{0x31} & FALCON-512 Verify & 28,000 \\
|
|
\texttt{0x32} & FALCON-1024 Verify & 42,000 \\
|
|
\texttt{0x40} & Warp Message Verify & 50,000 \\
|
|
\texttt{0x41} & SHA3-256 (Keccak) & 30$+$ \\
|
|
\texttt{0x42} & BLAKE2b-256 & 25$+$ \\
|
|
\bottomrule
|
|
\end{tabular}
|
|
\end{table}
|
|
|
|
\subsection{Calling Convention}
|
|
|
|
All precompiles follow the standard EVM precompile calling convention:
|
|
\begin{itemize}
|
|
\item Input: ABI-encoded arguments passed via \texttt{STATICCALL} or \texttt{CALL}.
|
|
\item Output: ABI-encoded result written to return data.
|
|
\item Gas: Deducted before execution; excess refunded.
|
|
\item Errors: Return empty data on invalid input (gas still consumed).
|
|
\end{itemize}
|
|
|
|
\begin{lstlisting}[language=Solidity,caption={Solidity interface for BLS12-381 pairing precompile.},label={lst:interface}]
|
|
interface IBLS12381 {
|
|
// Verify pairing equation: e(a1,b1) * e(a2,b2) * ... == 1
|
|
// Input: pairs of (G1, G2) points concatenated
|
|
// Output: bool (32 bytes, 0x01 or 0x00)
|
|
function pairing(bytes calldata input)
|
|
external view returns (bool);
|
|
}
|
|
\end{lstlisting}
|
|
|
|
\subsection{Execution Model}
|
|
|
|
Precompile functions execute in native Go, outside the EVM interpreter. The execution flow is:
|
|
|
|
\begin{algorithm}[H]
|
|
\caption{Precompile Dispatch}
|
|
\label{alg:dispatch}
|
|
\begin{algorithmic}[1]
|
|
\Require Call to address $A$ with input $I$ and gas $G$
|
|
\State Look up precompile handler $P$ for address $A$
|
|
\State $g \gets P.\mathsf{RequiredGas}(I)$ \Comment{Compute required gas}
|
|
\If{$G < g$}
|
|
\State \Return out-of-gas error
|
|
\EndIf
|
|
\State $(R, \text{err}) \gets P.\mathsf{Run}(I)$ \Comment{Execute native code}
|
|
\If{err $\neq$ nil}
|
|
\State \Return empty data, consume all gas
|
|
\EndIf
|
|
\State \Return $R$, refund $G - g$
|
|
\end{algorithmic}
|
|
\end{algorithm}
|
|
|