Skip to content

Commit 01cf513

Browse files
authored
release: v0.0.5 (#2)
1 parent 6b5bb4e commit 01cf513

File tree

1 file changed

+67
-14
lines changed

1 file changed

+67
-14
lines changed

src/main.tex

Lines changed: 67 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,14 @@
1414
pdfpagemode=FullScreen,
1515
}
1616
\urlstyle{same}
17+
\usepackage{booktabs} % professional-quality tables
18+
\usepackage{amsfonts} % blackboard math symbols
19+
\usepackage{nicefrac} % compact symbols for 1/2, etc.
20+
\usepackage{microtype} % microtypography
21+
22+
\usepackage{listings}
23+
\usepackage{amsmath}
24+
\usepackage{cleveref} % smart cross-referencing, load after amsmath
1725

1826
% This LaTeX Document is intended to be used on Overleaf
1927

@@ -50,29 +58,35 @@
5058

5159
\tableofcontents
5260

53-
61+
\newpage
5462
%--------------------------------------------------------------------------------------------------------------------------------------
55-
\chapter{Overview}
63+
\chapter{Protocol Specificcation}
5664
\begin{abstract}
5765
MEV is sucks. \newline
58-
MEV suck, Sandwhiches sucks, use OpenMEVs.~\cite{openmev}.
66+
MEV suck, Sandwiches sucks, use OpenMEVs.~\cite{openmev}.
5967
\end{abstract}
6068

69+
\subsection{Design}
70+
The Original design for the router was to use flashloans only to arbitrage then immediately distribute profits to hard coded addresses. Apart from the issue of hard coded addresses, this setup was inefficient because of small amounts frequently being split and transferring to multiple addresses being expensive. This opened the possibility of leaving profits to accumulate on the router. Furthermore it provides a way to arbitrage without a flashloan, saving gas and the loan fee (i.e. more profit, less gas). Additionally, the harvesting profits means ownership control of the router. A more robust 2 step process was chosen to control and transfer router ownership and harvest control. Ideal setup would be multisig consensus ownership.
71+
72+
\footnote{Ownership control of the router is not an issue, as a new router can be used or fallback to the legacy router contract.}
73+
6174

75+
\newpage
6276
\section{Motivation and Requirements}
6377

64-
%------------------------------------------------------------------------------------------------------------------------------------------------
78+
%---------------------------------------------------------------------------------------------------------------------------
6579
\subsection{Security properties}
6680

6781
In following the standards set forth by the UniswapV02/SushiswapV01 router contracts, the SushiswapV02 router contracts are intended to be safe to use with:
6882

69-
Potentially reentrant tokens
83+
Potentially re-entrant tokens
7084
Tokens that do not return from transfer
7185
Pathological Tokens The SushiswapV02 router contracts are not intended to be used tokens that exhibit the following behavior
7286
Tokens that exhibit a discretizing inflation curve
7387
Tokens that exhibit an 'unowned' supply
7488
Tokens that implement user defined types for standard mathematical operations
75-
Numerical error analysis The engineering team would like to request a review of the numerical error incurred during contract execution, with a focus on the desirable invariants proposed by both the development team and auditors. Examples include any significant rounding error, if any, in a swap, favors the pool. etc.
89+
Numerical error analysis The engineering team would like to request a review of the numerical error incurred during contract execution, with a focus on the desirable invariant proposed by both the development team and auditors. Examples include any significant rounding error, if any, in a swap, favors the pool. etc.
7690

7791
%----------------------------------------------------------------------------------------------------------------------------------------
7892

@@ -95,8 +109,44 @@ \section{Swap Execution}
95109
Profits are distributed to liquidity providers, in turn giving users better rates. Extracting MEV at source protects user trades from front-run attacks inherently and helps prevent fee spikes from attackers.
96110

97111

112+
Slippage: The amount of price impact that a liquidator engenders when trying to sell collateral.
113+
Slippage is denoted \text{$\Delta p(q)$} and is formally defined as the difference between the midpoint price at time $t, p_{\text {mid }}(t)$ and the execution price, \text{$p_{\text {exec }}(q, t)$} for a traded quantity $q$ at time $$t, \Delta p(q, t)=p_{\text {mid }}(t)-p_{\text {exec }}(q, t)$$. This quantity is usually a function of other variables, such as implied and realized volatility.
114+
\footnote{Slippage is also known as market impact within academic literature.}
115+
98116

99-
\newpage
117+
\subsection{Router Implementation}
118+
As a general approach to security, deviation from current UniswapV2Router was kept to a minimum. Pair contract calls should be consistent with the existing router. Reliance on the new router storing and transferring tokens brings in a new attack vector. A robust Ownership setup, as above, was chosen to mitigate this threat along with reduction of functions accessing the funds. 2 helper libraries were also chosen from \text{solmate} to supersede \text{UniswapV2Helper} libraries for security.
119+
120+
safeTransferLib
121+
ERC20
122+
Since UniswapV2Router was not designed to store tokens, some functions are not compatible and had to be changed. E.g.
123+
124+
\begin{minted}{lexer.py:SolidityLexer -x}
125+
126+
removeLiquidityETHSupportingFeeOnTransferTokens
127+
128+
(, amountETH) = removeLiquidity(
129+
token,
130+
WETH,
131+
liquidity,
132+
amountTokenMin,
133+
amountETHMin,
134+
address(this),
135+
deadline
136+
);
137+
TransferHelper.safeTransfer(token, to, IERC20(token).balanceOf(address(this)));
138+
\end{minted}
139+
Changes to
140+
141+
\begin{minted}{lexer.py:SolidityLexer -x}
142+
uint256 balanceBefore = ERC20(token).balanceOf(address(this));
143+
(, amountETH) = removeLiquidity(token, weth, liquidity, amountTokenMin, amountETHMin,
144+
address(this),
145+
deadline);
146+
ERC20(token).safeTransfer(to, ERC20(token).balanceOf(address(this)) - balanceBefore);
147+
\end{minted}
148+
149+
\newpage
100150

101151
\chapter{Mathematical Model}
102152

@@ -412,8 +462,9 @@ \subsection{Uint256 overflow}
412462

413463
However we found this lost precision and failed echidna tests.
414464
\label{Uint256 overflow:5}
415-
\begin{minted}{lexer.py:SolidityLexer -x}
416-
{\em echidna} test
465+
\begin{lstlisting}
466+
467+
# echidna test
417468
echidna_mulUint: failed!
418469
Call sequence:
419470
setX1(1106235220955)
@@ -429,11 +480,12 @@ \subsection{Uint256 overflow}
429480
Call sequence:
430481
setX(10417774989007224423389698535018119)
431482
setX1(1)
432-
\end{minted}
483+
\end{lstlisting}
484+
433485

434486
We also tried PRBMath\footnote{https://github.com/paulrberg/prb-math/} library. These faired better in echidna tests but still suffered overflow issues.
435487

436-
\begin{minted}{javascript}
488+
\begin{lstlisting}
437489
echidna_mulUint: failed!
438490
Call sequence:
439491
setX(115916773041390072873637598212453390567932363729484377996870)
@@ -448,13 +500,14 @@ \subsection{Uint256 overflow}
448500
Call sequence:
449501
setX(115989750869986627937072895547572258287879165164826483095329)
450502
setX1(1)
451-
\end{minted}
503+
\end{lstlisting}
504+
452505

453506
Ultimately we settled on Uint512 \footnote{see $github.com/SimonSuckut/Solidity_Uint512/blob/main/contracts/Uint512.sol$} which both passed echidna and overflow issue.
454-
\begin{minted}{javascript}
507+
\begin{lstlisting}
455508
echidna_mulUint: passed!
456509
echidna_divUint: passed!
457-
\end{minted}
510+
\end{lstlisting}
458511

459512

460513

0 commit comments

Comments
 (0)