You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

exercises.tex 4.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. \documentclass [10pt]{article}
  2. \usepackage{latexsym}
  3. \usepackage{amssymb}
  4. \usepackage{epsfig}
  5. \usepackage{fullpage}
  6. \usepackage{enumerate}
  7. \usepackage{xspace}
  8. \usepackage{todonotes}
  9. \usepackage{listings}
  10. \newcommand{\true}{true}
  11. \newcommand{\false}{false}
  12. \usepackage[ruled,linesnumbered]{algorithm2e} % Enables the writing of pseudo code.
  13. \pagestyle{plain}
  14. \bibliographystyle{plain}
  15. \title{192.127 Seminar in Software Engineering (Smart Contracts) \\
  16. SWC-124: Write to Arbitrary Storage Location}
  17. \author{Exercises}
  18. \date{WT 2023/24}
  19. \author{\textbf{*** YOUR NAME AND STUDENT ID ***}}
  20. \newtheorem{theorem}{Theorem}
  21. \newtheorem{lemma}[theorem]{Lemma}
  22. \newtheorem{corollary}[theorem]{Corollary}
  23. \newtheorem{proposition}[theorem]{Proposition}
  24. \newtheorem{conjecture}[theorem]{Conjecture}
  25. \newtheorem{definition}[theorem]{Definition}
  26. \newtheorem{example}[theorem]{Example}
  27. \newtheorem{remark}[theorem]{Remark}
  28. \newtheorem{exercise}[theorem]{Exercise}
  29. \renewcommand{\labelenumi}{(\alph{enumi})}
  30. \usepackage{xcolor}
  31. \definecolor{codegreen}{rgb}{0,0.6,0}
  32. \definecolor{codegray}{rgb}{0.5,0.5,0.5}
  33. \definecolor{codepurple}{rgb}{0.58,0,0.82}
  34. \definecolor{backcolour}{rgb}{0.95,0.95,0.92}
  35. \lstdefinestyle{mystyle}{
  36. backgroundcolor=\color{backcolour},
  37. commentstyle=\color{codegreen},
  38. keywordstyle=\color{magenta},
  39. numberstyle=\tiny\color{codegray},
  40. stringstyle=\color{codepurple},
  41. basicstyle=\ttfamily\footnotesize,
  42. breakatwhitespace=false,
  43. breaklines=true,
  44. captionpos=b,
  45. keepspaces=true,
  46. numbers=left,
  47. numbersep=5pt,
  48. showspaces=false,
  49. showstringspaces=false,
  50. showtabs=false,
  51. tabsize=2
  52. }
  53. \begin{document}
  54. \maketitle
  55. \section{Weakness and consequences}
  56. \subsection{Solidity storage layout}
  57. Any contract's storage is a continuous 256-bit address space consisting of 32-bit values. In order to implement dynamically sized data structures like maps and arrays, Solidity distributes their entries in a pseudo-random location. Due to the vast 256-bit range of addresses collisions are statistically extremely improbable and of no practical relevance.
  58. \medspace
  59. In the case of a dynamic array at variable slot $p$, data is written to continuous locations starting at $keccak(p)$. The array itself contains the length information. It is worth noting that Solidity does not come with utility functions to manipulate arrays, and the developer is required to correctly maintain the length value in order to keep track of the array's state.
  60. \medspace
  61. For maps stored in variable slot $p$ the data for index $k$ can be found at $keccak(k . p)$ where $.$ is the concatenation operator.
  62. \subsection{The Weakness}
  63. Any unchecked array write is potentially dangerous, as the storage-location of all variables is publicly known and an unconstrained array index can be reverse engineered to target them.
  64. \lstset{style=mystyle}
  65. \begin{algorithm}
  66. \begin{lstlisting}[language=Octave]
  67. pragma solidity 0.4.25;
  68. contract MyContract {
  69. uint[] private arr;
  70. address private owner;
  71. function write(unit index, uint value) {
  72. arr[index] = value;
  73. }
  74. }
  75. \end{lstlisting}
  76. \caption{A completely unchecked array write}
  77. \label{alg:agf-opt-merge}
  78. \end{algorithm}
  79. In the case of dynamic arrays an improper constraint of the $length$ can be dangerous. As $length$ is unsigned, it is possible to underflow it past $2^{256} - 1$ by decrementing the length below zero, thereby effectively marking the whole address space as part of it.
  80. \section{Vulnerable contracts in literature}
  81. collect vulnerable contracts used by different papers to motivate/illustrate the weakness
  82. \section{Code properties and automatic detection}
  83. summarize the code properties that tools are looking for so that they can detect the weakness
  84. \section{Exploit sketch}
  85. sketch ways to potentially exploit the different variants of the weakness.
  86. %remove this later%
  87. \cite{10.1145/3243734.3243780}
  88. \cite{10.1145/3578527.3578538}
  89. \cite{217464}
  90. \cite{9678888}
  91. \bibliography{exercise.bib}
  92. \end{document}