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.
99 lines
2.9 KiB
TeX
99 lines
2.9 KiB
TeX
\section{Oracle Security}
|
|
|
|
|
|
\subsection{MEV Protection Mechanisms}
|
|
|
|
Maximum Extractable Value (MEV) poses significant risks to oracle updates. Lux implements several protection mechanisms:
|
|
|
|
\begin{enumerate}
|
|
\item \textbf{Commit-Reveal Scheme}: Two-phase oracle updates prevent front-running
|
|
\item \textbf{Time-Weighted Average Prices (TWAP)}: Resistance to flash loan attacks
|
|
\item \textbf{Private Mempool}: Oracle transactions bypass public mempool
|
|
\item \textbf{Threshold Signatures}: Multiple validators must agree on updates
|
|
\end{enumerate}
|
|
|
|
\subsection{Oracle Manipulation Attacks}
|
|
|
|
Protection against various manipulation vectors:
|
|
|
|
\begin{lstlisting}[caption={Oracle Manipulation Protection}]
|
|
contract SecureOracle {
|
|
uint256 constant MAX_DEVIATION = 500; // 5%
|
|
uint256 constant MIN_SOURCES = 3;
|
|
|
|
function validatePrice(
|
|
uint256 newPrice,
|
|
uint256 currentPrice,
|
|
uint256[] memory sources
|
|
) internal pure returns (bool) {
|
|
require(sources.length >= MIN_SOURCES);
|
|
|
|
uint256 deviation = abs(newPrice - currentPrice)
|
|
* 10000 / currentPrice;
|
|
require(deviation <= MAX_DEVIATION);
|
|
|
|
uint256 median = calculateMedian(sources);
|
|
uint256 priceDeviation = abs(newPrice - median)
|
|
* 10000 / median;
|
|
require(priceDeviation <= MAX_DEVIATION);
|
|
|
|
return true;
|
|
}
|
|
}
|
|
\end{lstlisting}
|
|
|
|
\subsection{Multi-Source Validation}
|
|
|
|
Oracle data validation across multiple independent sources:
|
|
|
|
\begin{equation}
|
|
\text{Valid} = \begin{cases}
|
|
\text{true} & \text{if } |\frac{P_i - P_{median}}{P_{median}}| < \theta \text{ for all } i \\
|
|
\text{false} & \text{otherwise}
|
|
\end{cases}
|
|
\end{equation}
|
|
|
|
Where $\theta$ is the maximum allowed deviation threshold (typically 5\%).
|
|
|
|
\subsection{Circuit Breakers and Anomaly Detection}
|
|
|
|
Automated safeguards against extreme market conditions:
|
|
|
|
\begin{lstlisting}[caption={Circuit Breaker Implementation}]
|
|
contract CircuitBreaker {
|
|
mapping(address => PriceData) public priceHistory;
|
|
uint256 public circuitBreakerThreshold = 2000; // 20%
|
|
|
|
struct PriceData {
|
|
uint256 price;
|
|
uint256 timestamp;
|
|
bool paused;
|
|
}
|
|
|
|
function checkCircuitBreaker(
|
|
address token,
|
|
uint256 newPrice
|
|
) internal {
|
|
PriceData memory lastData = priceHistory[token];
|
|
|
|
if (lastData.timestamp > 0) {
|
|
uint256 priceChange = abs(newPrice - lastData.price)
|
|
* 10000 / lastData.price;
|
|
|
|
if (priceChange > circuitBreakerThreshold) {
|
|
priceHistory[token].paused = true;
|
|
emit CircuitBreakerTriggered(token, priceChange);
|
|
require(false, "Circuit breaker activated");
|
|
}
|
|
}
|
|
|
|
priceHistory[token] = PriceData({
|
|
price: newPrice,
|
|
timestamp: block.timestamp,
|
|
paused: false
|
|
});
|
|
}
|
|
}
|
|
\end{lstlisting}
|
|
|