Skip to content

Commit 19aba73

Browse files
authored
fix(latex): make latex chill (#4)
1 parent 9049a35 commit 19aba73

File tree

1 file changed

+114
-49
lines changed

1 file changed

+114
-49
lines changed

src/main.tex

Lines changed: 114 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,19 @@
2020
\usepackage{microtype} % microtypography
2121

2222
\usepackage{listings}
23+
\lstdefinestyle{Bash}
24+
{language=bash,
25+
keywordstyle=\color{blue},
26+
basicstyle=\ttfamily,
27+
morekeywords={setX},
28+
alsoletter={:~$},
29+
morekeywords=[2]{setX:},
30+
keywordstyle=[2]{\color{red}},
31+
literate={\$}{{\textcolor{red}{\$}}}1
32+
{!}{{\textcolor{red}{!}}}1
33+
{~}{{\textcolor{red}{\textasciitilde}}}1,
34+
}
35+
2336
\usepackage{amsmath}
2437
\usepackage{cleveref} % smart cross-referencing, load after amsmath
2538
@@ -50,30 +63,38 @@
5063
\email{\{sandy,sam\}@manifoldfinance.com}\\
5164
5265
53-
66+
\thanks{Thanks to Johannes, Kitsuana, et al}
5467
%
5568
\maketitle % typeset the header of the contribution
5669
5770
\keywords{MEV, \and Miner Extractable Value \and trade optimization, \and EVM \and uniswap \and sushiswap \and ethereum \and formal verification}
5871
5972
\tableofcontents
6073
74+
75+
6176
\newpage
62-
%--------------------------------------------------------------------------------------------------------------------------------------
77+
6378
\chapter{Protocol Specification}
6479
\begin{abstract}
65-
MEV is sucks. \newline
66-
MEV suck, Sandwiches sucks, use OpenMEVs.~\cite{openmev}.
80+
\text{}
81+
\newline
82+
\newline
83+
\textbf{MEV is sucks. }\newline
84+
MEV suck, \textbf{Sandwiches sucks}, \newline
85+
\newline
86+
use OpenMEVs.\footnote{Bacha, Sam "MEV is essentially looking for the reachable state where their balance is maximized. Given any arbitrary re-ordering, insertion or censorship of pending or existing transactions, this can suck, suck real hard."}
6787
\end{abstract}
6888
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.
89+
\section{Motivation}
90+
\text{see} \textbf{\emph{Abstract}}.
7191
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.}
92+
\subsection{Design}
93+
\paragrah{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.}\footnote{Ownership control of the router is not an issue, as a new router can be used or fallback to the legacy router contract.}
7394
7495
7596
\newpage
76-
\section{Motivation and Requirements}
97+
\section{Requirements}
7798
7899
%---------------------------------------------------------------------------------------------------------------------------
79100
\subsection{Security properties}
@@ -97,7 +118,7 @@ \subsection{Conformant Algorithms}
97118
98119
\hfill \break
99120
100-
Conformance requirements phrased as algorithms or specific steps that can be implemented in any manner, so long as the end result are equivalent. In particular, the algorithms defined in this specification are intended to be easy to understand and are not necessarily intended to be performant. Implementer's are encouraged to either: switch to an L2, optimize, or use Vyper\footnote{Vyperlang: https://vyper.readthedocs.io/en/stable/}.
121+
Conformance requirements phrased as algorithms or specific steps that can be implemented in any manner, so long as the end result are equivalent. In particular, the algorithms defined in this specification are intended to be easy to understand and are not necessarily intended to be performant. Implementers are encouraged to either: switch to an L2, optimize, or use Vyper\footnote{Vyperlang: https://vyper.readthedocs.io/en/stable/}.
101122
102123
103124
%------------------------------------------------------------------------------------------------------------------------------------------------
@@ -308,8 +329,10 @@ \chapter{Equivalence Checking}
308329
\subsection{Backrun placement}
309330
310331
By definition, backruns must occur after user to user swap. From a design point of view the simplest place to insert the backrun function would be in the internal $_swap$ function which is called by the other swaps. However, some of the swap variants eg $swapTokensForExactETH$ perform user actions after $_swap$ is called. This is not ideal, as we do not want to interfere with the user swap. Moreover, other swap variants such as $swapExactTokensForTokensSupportingFeeOnTransferTokens$ do not use $_swap$. Backrun functions were therefore placed at the end of each external swap variant. E.g.
311-
312-
Original
332+
\begin{figure}
333+
\centering
334+
\caption{Backrun Placement}
335+
\label{fig:Backrun Placement}
313336
\label{Before swapExactTokensforTokens:1}
314337
\begin{minted}{lexer.py:SolidityLexer -x}
315338
function swapExactTokensForTokens(
@@ -318,7 +341,8 @@ \subsection{Backrun placement}
318341
address[] calldata path,
319342
address to,
320343
uint deadline
321-
) external virtual override ensure(deadline) returns (uint[] memory amounts) {
344+
) external virtual override ensure(deadline) returns
345+
(uint[] memory amounts) {
322346
amounts = UniswapV2Library.getAmountsOut(factory, amountIn, path);
323347
require(amounts[amounts.length - 1]
324348
>= amountOutMin, 'UniswapV2Router: INSUFFICIENT_OUTPUT_AMOUNT');
@@ -329,9 +353,13 @@ \subsection{Backrun placement}
329353
_swap(amounts, path, to);
330354
}
331355
\end{minted}
356+
\end{figure}
332357
333-
Design change:
334358
359+
\begin{figure}
360+
\centering
361+
\caption{Backrun Implementation}
362+
\label{fig:Backrun Implementation}
335363
\label{After swapExactTokensforTokens:2}
336364
\begin{minted}{lexer.py:SolidityLexer -x}
337365
function swapExactTokensForTokens(
@@ -353,8 +381,11 @@ \subsection{Backrun placement}
353381
_backrunSwaps(path);
354382
}
355383
\end{minted}
384+
\end{figure}
385+
386+
\newpage
356387
357-
Multiple factories
388+
\subsection{Multiple factories}
358389
Multiple factories (at least 2) are required for the backrun arbitrage. The adoption of multiple factories within the router, lead to some internal function changes. In particular $pairFor$.
359390
360391
\label{CREATE2 Factory:3}
@@ -376,8 +407,13 @@ \subsection{Backrun placement}
376407
)))));
377408
}
378409
\end{minted}
410+
\newpage
379411
380-
Changes to
412+
\text{Changes to}
413+
\begin{figure}
414+
\centering
415+
\caption{New Factories Implementation}
416+
\label{fig:New Factories}
381417
\begin{minted}{lexer.py:SolidityLexer -x}
382418
383419
function pairFor(address factory, address tokenA, address tokenB)
@@ -394,6 +430,7 @@ \subsection{Backrun placement}
394430
)))));
395431
}
396432
\end{minted}
433+
\end{figure}
397434
398435
\subsection{Fallback factory}
399436
Since the extra factory is required for the arbitrage, we can use it, for the user, to check for an available swap on the alternate factory if it would otherwise fail on the default factory through slippage.
@@ -405,6 +442,10 @@ \subsection{Fallback factory}
405442
>= amountOutMin, 'UniswapV2Router: INSUFFICIENT_OUTPUT_AMOUNT');
406443
\end{minted}
407444
Changes to
445+
\begin{figure}
446+
\centering
447+
\caption{Fallback Factory Implementation}
448+
\label{fig:Fallback Factory Implementation}
408449
\begin{minted}{lexer.py:SolidityLexer -x}
409450
address factory = SUSHI_FACTORY;
410451
amounts = _getAmountsOut(factory, amountIn, path);
@@ -416,13 +457,14 @@ \subsection{Fallback factory}
416457
factory = BACKUP_FACTORY;
417458
}
418459
\end{minted}
460+
\end{figure}
419461
420462
\chapter{Math Libraries and BigInt support}
421463
422464
\paragraph{These following sections describe testing various math libraries to accommodate the additional calculations required of the router.}
423465
424466
\subsection{Uint256 overflow}
425-
Optimal arbitrage calculations were overflowing uint256. e.g.
467+
\text{Optimal arbitrage calculations were overflowing uint256. i.e.}
426468
\label{Uint256 overflow:5}
427469
\begin{minted}{lexer.py:SolidityLexer -x}
428470
uint Cd = reserve0Token1.mul(997).mul(997);
@@ -452,66 +494,88 @@ \subsection{Uint256 overflow}
452494
\end{minted}
453495
\newpage
454496
455-
ABDKMath \footnote{$https://github.com/abdk-consulting/abdk-libraries-solidity$} library was used for a time, as it avoided overflow by dropping to floats.
456-
457-
ABDKMath Example
497+
\subsubsection{ABDKMath}
498+
\text{ABDKMath library was used for a time, as it avoided overflow by dropping to floats.}\footnote{$https://github.com/abdk-consulting/abdk-libraries-solidity$}
458499
\begin{minted}{lexer.py:SolidityLexer -x}
459500
bytes16 _Cg = ABDKMathQuad.fromUInt(Cg);
460501
bytes16 _a = ABDKMathQuad.mul(_Cg, _Cg);
461502
\end{minted}
462503
463-
However we found this lost precision and failed echidna tests.
464-
\label{Uint256 overflow:5}
465-
\begin{lstlisting}
504+
\text{However we found this lost precision and failed echidna tests.}
505+
466506
467-
# echidna test
468-
echidna_mulUint: failed!
507+
\label{Uint256 overflow:5}
508+
\begin{figure}
509+
\centering
510+
\caption{Uint256 overflow:5}
511+
\label{fig:Echidna Uint56 Overflow Tests}
512+
\begin{lstlisting}[style=Bash]
513+
echidna_mulUint:
514+
failed!
469515
Call sequence:
470516
setX1(1106235220955)
471517
setX(9390953368914254812617)
472518
473-
474-
echidna_Uint_convertion: failed!
519+
echidna_Uint_conversion:
520+
failed!
475521
Call sequence:
476522
setX(10518526264810785485368401065708505)
477523
478-
479-
echidna_divUint: failed!
524+
echidna_divUint:
525+
failed!
480526
Call sequence:
481527
setX(10417774989007224423389698535018119)
482528
setX1(1)
483529
\end{lstlisting}
530+
\end{figure}
484531
532+
\newpage
533+
\subsubsection{PRBMath}
485534
486-
We also tried PRBMath\footnote{https://github.com/paulrberg/prb-math/} library. These faired better in echidna tests but still suffered overflow issues.
535+
We also tried PRBMath\footnote{https://github.com/paulrberg/prb-math/} library. These performed better in echidna tests but still suffered overflow issues.
487536
488-
\begin{lstlisting}
489-
echidna_mulUint: failed!
537+
\begin{figure}
538+
\centering
539+
\caption{PRBMath}
540+
\label{fig:Echidna PRBMath Tests}
541+
\begin{lstlisting}[style=Bash]
542+
echidna_mulUint:
543+
~ failed!
490544
Call sequence:
491-
setX(115916773041390072873637598212453390567932363729484377996870)
545+
setX1(1106235220955)
546+
setX(9390953368914254812617)
492547
493548
494-
echidna_Uint_convertion: failed!
549+
echidna_Uint_convertion:
550+
~ failed!
495551
Call sequence:
496-
setX(115962837499224411198969207499961588040517688084412876519766)
552+
setX(10518526264810785485368401065708505)
497553
498554
499-
echidna_divUint: failed!
555+
echidna_divUint:
556+
~ failed!
500557
Call sequence:
501-
setX(115989750869986627937072895547572258287879165164826483095329)
558+
setX(10417774989007224423389698535018119)
502559
setX1(1)
503560
\end{lstlisting}
561+
\end{figure}
562+
563+
\subsubsection{Uint512}
564+
\text{Ultimately we settled on Uint512 which both passed echidna and overflow issue.}\footnote{see $github.com/SimonSuckut/Solidity_Uint512/blob/main/contracts/Uint512.sol$}
504565
505566
506-
Ultimately we settled on Uint512 \footnote{see $github.com/SimonSuckut/Solidity_Uint512/blob/main/contracts/Uint512.sol$} which both passed echidna and overflow issue.
567+
\begin{figure}
568+
\centering
569+
\caption{Uint512 }
570+
\label{fig:Echidna Uint512 Tests}
507571
\begin{lstlisting}
508-
echidna_mulUint: passed!
509-
echidna_divUint: passed!
572+
echidna_mulUint: ~ passed!
573+
echidna_divUint: ~ passed!
510574
\end{lstlisting}
575+
\end{figure}
511576
512577
513-
514-
\chapter{Conclusions and Future Work}
578+
\section{Conclusions and Future Work}
515579
516580
\newpage
517581
%
@@ -524,52 +588,53 @@ \chapter{Conclusions and Future Work}
524588
% \bibliography{mybibliography}
525589
%
526590
\chapter{Bibliography}
591+
527592
\begin{thebibliography}{1}
528-
\bibitem{openmev}
593+
\bibitem{[2022]Bacha}
594+
Sam Bacha, Sandy Bradley.
529595
OpenMEV source code, \url{github.com/manifoldfinance/OpenMevRouter}.
530596
Last accessed 20 April 2022
531597
\bibliographystyle{unsrtnat}
532598
\bibliography{references} %%% Uncomment this line and comment out the ``thebibliography'' section below to use the external .bib file (using bibtex) .
533599
\newline
534-
\bibitem{Angeris2020}
600+
\bibitem{[2020]Angeris:2020}
535601
Guillermo Angeris, Tarun Chitra, Alex Evans, Stephen Boyd
536602
\newblock Guillermo Angeris et al. Optimal Routing for Constant Function Market Makers. arXiv:2204.05238
537603
\newblock In {\em arXiv 1911.03380}, 26 Jul 2021
538604
Optimization and Control (math.OC); Trading and Market Microstructure (q-fin.TR)
539605
540606
\hfill \break
541-
\bibitem{Angeris2019}
607+
\bibitem{[2019]Angeris:2019}
542608
Guillermo Angeris et al. An analysis of Uniswap markets. 2019. arXiv: 1911.03380
543609
\newblock An analysis of Uniswap markets.
544610
Mathematical Finance (q-fin.MF); Optimization and Control; Trading and Market Microstructure (q-fin.TR)
545611
\newblock {\em arXiv: 1911.03380},
546612
547613
\hfill \break
548-
\bibitem{Angeris2019}
614+
\bibitem{[2019]Angeris}
549615
Guillermo Angeris, Alex Evans, Tarun Chitra
550616
\newblock Replicating Market Makers
551617
Mathematical Finance (q-fin.MF); Optimization and Control; Trading and Market Microstructure (q-fin.TR)
552618
\newblock {\em arXiv:2103.14769}, 26 Mar 2021.
553619
554620
\hfill \break
555-
\bibitem{Tarun2021}
621+
\bibitem{[2021]Tarun:2021}
556622
Guillermo Angeris, Alex Evans, Tarun Chitra
557623
\newblock Constant Function Market Makers: Multi-Asset Trades via Convex Optimization
558624
Mathematical Finance (q-fin.MF); Optimization and Control; Trading and Market Microstructure (q-fin.TR)
559625
\newblock {\em arXiv:2107.12484 }, 26 Jul 2021]
560626
\url{https://doi.org/10.48550/arXiv.2107.12484}
561627
562628
\hfill \break
563-
\bibitem{Tarun2022}
629+
\bibitem{[2022]Tarun:2022}
564630
Guillermo Angeris, Tarun Chitra, Alex Evans, Stephen Boyd
565631
\newblock Optimal Routing for Constant Function Market Makers
566632
Optimization and Control (math.OC); Trading and Market Microstructure (q-fin.TR)
567633
\newblock {\em arXiv:2204.05238}, 11 Apr 2022]
568634
\url{https://arxiv.org/abs/2204.05238v1}
569-
\hfill \break
570635
571636
\hfill \break
572-
\bibitem{Suckut, 2022}
637+
\bibitem{[2022]Suckut}
573638
Suckut, Simon
574639
\newblock Uint512 Solidity Library
575640
\newblock {\em GitHub}, 11 Apr 2022]

0 commit comments

Comments
 (0)