Files
zeekay abf99d05fc papers: reorganize into per-paper dirs, add Antje Worring as co-author
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.
2026-04-18 21:50:07 -07:00

37 lines
1.6 KiB
TeX

\section{What Is a Precompile}
\subsection{The EVM Execution Model}
The EVM executes smart contracts as sequences of opcodes (bytecodes). Each opcode has a
fixed gas cost. Opcodes provide basic operations: arithmetic, memory access, storage,
control flow. There are no opcodes for complex cryptographic operations like pairing
checks or post-quantum signature verification.
\subsection{Precompiles: Native Extensions}
A precompile is a special contract address (typically in the range \texttt{0x0001}--\texttt{0x00ff}
for Ethereum, \texttt{0x0200}--\texttt{0x02ff} for Lux extensions) where a \texttt{CALL}
or \texttt{STATICCALL} invokes a native Go function instead of interpreting EVM bytecode.
From Solidity's perspective, a precompile call looks like a normal external call:
\begin{lstlisting}[language=Solidity,caption={Calling a precompile from Solidity}]
// Call the BLS12-381 pairing precompile at 0x0200
(bool success, bytes memory result) = address(0x0200).staticcall(
abi.encodePacked(g1Point, g2Point)
);
require(success, "pairing check failed");
bool pairingResult = abi.decode(result, (bool));
\end{lstlisting}
\subsection{Why Precompiles Instead of Libraries}
Implementing BLS12-381 pairing in Solidity would cost approximately 50M gas (most of the
block gas limit). The same operation as a precompile costs 113,000 gas---a 440x reduction.
The reason: EVM opcodes have overhead per operation (gas metering, stack manipulation,
memory management), and cryptographic operations require millions of field multiplications
that incur this overhead for each one.
%% ============================================================