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.
66 lines
1.8 KiB
TeX
66 lines
1.8 KiB
TeX
\section{Error Handling}
|
|
|
|
|
|
\subsection{Precompile Error Semantics}
|
|
|
|
When a precompile returns an error, the EVM:
|
|
\begin{enumerate}[nosep]
|
|
\item Consumes all gas provided to the call.
|
|
\item Returns no output data.
|
|
\item Reverts state changes made within the call (but the gas is still consumed).
|
|
\end{enumerate}
|
|
|
|
\subsection{Input Validation}
|
|
|
|
Every precompile validates inputs before processing:
|
|
|
|
\begin{lstlisting}[language=Go,caption={Input validation pattern}]
|
|
func (c *dilithiumVerify) Run(input []byte) ([]byte, error) {
|
|
// Check total length
|
|
if len(input) < PubKeyLen+SigLen+32 {
|
|
return nil, errInvalidInputLength
|
|
}
|
|
|
|
// Decode public key
|
|
pk, err := decodeDilithiumPubKey(input[:PubKeyLen])
|
|
if err != nil {
|
|
return nil, errInvalidPublicKey
|
|
}
|
|
|
|
// Decode signature
|
|
sig, err := decodeDilithiumSig(input[PubKeyLen : PubKeyLen+SigLen])
|
|
if err != nil {
|
|
return nil, errInvalidSignature
|
|
}
|
|
|
|
// Message is the remainder
|
|
msg := input[PubKeyLen+SigLen:]
|
|
|
|
// Verify
|
|
valid := dilithium.Verify(pk, msg, sig)
|
|
|
|
output := make([]byte, 32)
|
|
if valid {
|
|
output[31] = 1
|
|
}
|
|
return output, nil
|
|
}
|
|
\end{lstlisting}
|
|
|
|
\subsection{Denial-of-Service Resistance}
|
|
|
|
The \texttt{RequiredGas} function must accurately bound the computation cost. For
|
|
variable-cost operations (e.g., pairing with $k$ pairs), the gas scales linearly:
|
|
|
|
\begin{lstlisting}[language=Go,caption={Variable gas cost for pairing}]
|
|
func (c *bls12381Pairing) RequiredGas(input []byte) uint64 {
|
|
if len(input) == 0 || len(input)%128 != 0 {
|
|
return 0 // Will fail in Run
|
|
}
|
|
k := uint64(len(input)) / 128
|
|
return 43000 + k*70000 // Base + per-pair cost
|
|
}
|
|
\end{lstlisting}
|
|
|
|
%% ============================================================
|