|
| 1 | +\begin{center} |
| 2 | + \boxed{% |
| 3 | + \text{The stack constraints presented below assume } |
| 4 | + \begin{cases} |
| 5 | + \peekStack _{i} = 1 \\ |
| 6 | + \stackDecMcopyFlag _{i} = 1 \\ |
| 7 | + \stackSux _{i} + \stackSox _{i} = 0 \\ |
| 8 | + \end{cases}} |
| 9 | +\end{center} |
| 10 | +The constraints are as follows: |
| 11 | +\begin{description} |
| 12 | + \item[\underline{Setting the stack pattern:}] |
| 13 | + we impose $\threeZeroSP_{i}$; |
| 14 | +\end{description} |
| 15 | +We deal with the \inst{MCOPY} instruction slightly differently from other instructions. |
| 16 | +The typical \emph{modus operandi} is to specify peeking flags and then to fill the relevant lookups etc\dots{} |
| 17 | +With the present instruction we begin by specifying a single miscellaneous-row which is unconditionally present. |
| 18 | +\begin{description} |
| 19 | + \item[\underline{The first row must be a miscellaneous-row:}] |
| 20 | + we unconditionally impose that $\peekMisc _{i + \locMcopyFrstMiscOffset} = 1$; |
| 21 | + \item[\underline{Calling the \mxpMod{}-module:}] |
| 22 | + we unconditionally call the \mxpMod{} module |
| 23 | + $\miscMxpFlag _{i + \locMcopyFrstMiscOffset} = 1$; |
| 24 | + \item[\underline{Defining the \mxpMod{}-instruction:}] |
| 25 | + we impose |
| 26 | + \[ |
| 27 | + \setMxpInstructionMcopy { |
| 28 | + anchorRow = i , |
| 29 | + relOffset = \locMcopyFrstMiscOffset , |
| 30 | + targetOffsetHi = \locTgtOffsetHi , |
| 31 | + targetOffsetLo = \locTgtOffsetLo , |
| 32 | + sourceOffsetHi = \locSrcOffsetHi , |
| 33 | + sourceOffsetLo = \locSrcOffsetLo , |
| 34 | + sizeHi = \locSizeHi , |
| 35 | + sizeLo = \locSizeLo , |
| 36 | + } |
| 37 | + \] |
| 38 | + \item[\underline{Defining module triggers:}] |
| 39 | + the module triggers will be used to |
| 40 | + unconditionally call the \mxpMod{} module |
| 41 | + and call the \mmuMod{} module \emph{iff} |
| 42 | + the underlying \inst{MCOPY} instruction is unexceptional ($\xAhoy \equiv 0$) |
| 43 | + and its size parameter is nonzero ($\locMcopyMxpSizeOneNonZeroNoMxpx \equiv 1$.) |
| 44 | + \[ |
| 45 | + \left\{ \begin{array}{lcl} |
| 46 | + \locTriggerMxp & \define & 1 \\ |
| 47 | + \locTriggerMmu & \define & (1 - \xAhoy _{i}) \cdot \locMcopyMxpSizeOneNonZeroNoMxpx \\ |
| 48 | + \end{array} \right. |
| 49 | + \] |
| 50 | + In other words |
| 51 | + \begin{enumerate} |
| 52 | + \item \If $\xAhoy_{i} = 1$ \Then $\locTriggerMmu = 0$ \quad (\trash) |
| 53 | + \item \If $\xAhoy_{i} = 0$ \Then |
| 54 | + \begin{enumerate} |
| 55 | + \item \If $\locSizeLo = 0$ \Then $\locTriggerMmu = 0$ \quad (\trash) |
| 56 | + \item \If $\locSizeLo \neq 0$ \Then $\locTriggerMmu = 1$ \quad (\trash) |
| 57 | + \end{enumerate} |
| 58 | + \end{enumerate} |
| 59 | +\end{description} |
| 60 | +We are now in a position to specify the peeking flags. |
| 61 | +\begin{description} |
| 62 | + \item[\underline{Setting $\nonStackRows$ and peeking flags:}] |
| 63 | + we impose that |
| 64 | + \begin{enumerate} |
| 65 | + \item \If $\xAhoy _{i} = 1$ \Then $\nonStackRows_{i} = 2$. |
| 66 | + \item \If $\xAhoy _{i} = 0$ \Then $\nonStackRows_{i} = 1 + \locTriggerMmu$. |
| 67 | + \end{enumerate} |
| 68 | + \item[\underline{Setting the peeking flags:}] |
| 69 | + we impose that |
| 70 | + \begin{enumerate} |
| 71 | + \item \If $\xAhoy _{i} = 1$ \Then $\nonStackRows_{i} = 2$ and |
| 72 | + \[ |
| 73 | + \left[ \begin{array}{r} |
| 74 | + + \peekMisc _{i + \locMcopyFrstMiscOffset} \\ |
| 75 | + + \peekContext _{i + \locMcopyExceptionalContextOffset} \\ |
| 76 | + \end{array} \right] |
| 77 | + = \nonStackRows_{i} |
| 78 | + \] |
| 79 | + \saNote{} |
| 80 | + We don't need to (and won't) specify the contents of the final context row in the case that $\xAhoy \equiv 1$. |
| 81 | + This is already implicitly taken care of with |
| 82 | + section~(\ref{hub: generalities: context: exceptions lead to providing empty return data}). |
| 83 | + |
| 84 | + \saNote{} |
| 85 | + For instructions raising the $\stackDecMcopyFlag$ one has $\cmc \equiv \xAhoy$. |
| 86 | + \item \If $\xAhoy _{i} = 0$ \Then $\nonStackRows_{i} = 1 + \locTriggerMmu$ and |
| 87 | + \[ |
| 88 | + \left[ \begin{array}{cr} |
| 89 | + + & \peekMisc _{i + \locMcopyFrstMiscOffset} \\ |
| 90 | + + & \locTriggerMmu \cdot \peekMisc _{i + \locMcopyScndMiscOffset} \\ |
| 91 | + \end{array} \right] |
| 92 | + = \nonStackRows_{i} |
| 93 | + \] |
| 94 | + \end{enumerate} |
| 95 | + \item[\underline{Justiyfing the \stackMxpx{} flag:}] |
| 96 | + we impose that |
| 97 | + \[ |
| 98 | + \stackMxpx _{i} |
| 99 | + = |
| 100 | + \locMcopyMxpMxpx |
| 101 | + \] |
| 102 | + \item[\underline{Setting the gas cost:}] |
| 103 | + we impose that |
| 104 | + \begin{enumerate} |
| 105 | + \item \If $\stackMxpx _{i} = 0$ \Then \( \gasCost_{i} = \stackStaticGas _{i} + \locMcopyMxpGas \) |
| 106 | + \item \If $\stackMxpx _{i} = 1$ \Then \( \gasCost_{i} = 0 \) |
| 107 | + \end{enumerate} |
| 108 | + \item[\underline{Miscellaneous-row $n^°(i + \locMcopyFrstMiscOffset)$: flags:}] |
| 109 | + we impose that |
| 110 | + \[ |
| 111 | + \weightedMiscFlagSum {i}{\locMcopyFrstMiscOffset} |
| 112 | + = |
| 113 | + \left[ \begin{array}{llcl} |
| 114 | + + & \miscMmuWeight & \!\!\!\cdot\!\!\! & \locCallMmu \\ |
| 115 | + + & \miscMxpWeight \\ |
| 116 | + \end{array} \right] |
| 117 | + \] |
| 118 | + in other words |
| 119 | + \[ |
| 120 | + \left\{ \begin{array}{lclr} |
| 121 | + \miscExpFlag _{i + \locMcopyFrstMiscOffset} & = & \gZero & (\trash) \\ |
| 122 | + \miscMmuFlag _{i + \locMcopyFrstMiscOffset} & = & \locCallMmu & (\trash) \\ |
| 123 | + \miscMxpFlag _{i + \locMcopyFrstMiscOffset} & = & \one & (\trash) \\ |
| 124 | + \miscOobFlag _{i + \locMcopyFrstMiscOffset} & = & \gZero & (\trash) \\ |
| 125 | + \miscStpFlag _{i + \locMcopyFrstMiscOffset} & = & \gZero & (\trash) \\ |
| 126 | + \end{array} \right. |
| 127 | + \] |
| 128 | + \item[\underline{Miscellaneous-row $n^°(i + \locMcopyScndMiscOffset)$: flags:}] |
| 129 | + \If $\locTriggerMmu = 1$ \Then we impose that |
| 130 | + \[ |
| 131 | + \weightedMiscFlagSum {i}{\locMcopyScndMiscOffset} |
| 132 | + = |
| 133 | + \miscMmuWeight |
| 134 | + \] |
| 135 | + in other words |
| 136 | + \[ |
| 137 | + \left\{ \begin{array}{lclr} |
| 138 | + \miscExpFlag _{i + \locMcopyScndMiscOffset} & = & \gZero & (\trash) \\ |
| 139 | + \miscMmuFlag _{i + \locMcopyScndMiscOffset} & = & \one & (\trash) \\ |
| 140 | + \miscMxpFlag _{i + \locMcopyScndMiscOffset} & = & \gZero & (\trash) \\ |
| 141 | + \miscOobFlag _{i + \locMcopyScndMiscOffset} & = & \gZero & (\trash) \\ |
| 142 | + \miscStpFlag _{i + \locMcopyScndMiscOffset} & = & \gZero & (\trash) \\ |
| 143 | + \end{array} \right. |
| 144 | + \] |
| 145 | + \saNote{} The binary flag \locCallMmu{} will be defined below. |
| 146 | +\end{description} |
| 147 | +The \zkEvm{} carries out the \inst{MCOPY} instruction in two steps, |
| 148 | +similarly to how it deals with the \inst{IDENTITY} precompile, |
| 149 | +see section~(\ref{hub: instruction handling: call: precompiles: identity}). |
| 150 | +The first step is to carry out a full copy of the specified (\emph{nonempty}) source memory span into a new, |
| 151 | +hitherto untouched, memory span with fresh (and as of yet, unclaimed) identifier $1 + \hubStamp_{i}$. |
| 152 | +The second step is to copy the contents over from that new memory span to the target memory span. |
| 153 | +In the above the source memory span starts at offset $\locSrcOffsetLo$ an occupies $\locSizeLo$ many bytes, and |
| 154 | +the target memory span starts at offset $\locTgtOffsetLo$ an (also) occupies $\locSizeLo$ many bytes. |
| 155 | +Both have identifier $\cn _{i}$. |
| 156 | + |
| 157 | +This approach avoids difficulties related to |
| 158 | +(\emph{a}) overlapping source and target memory spans |
| 159 | +(\emph{b}) relative position of the source and target spans (source on the left of target and \emph{vice versa}.) |
| 160 | +\begin{description} |
| 161 | + \item[\underline{Miscellaneous-row $n^°(i + \locMcopyFrstMiscOffset)$: \mmuMod{} data:}] |
| 162 | + \If $\locTriggerMmu = 1$ \Then |
| 163 | + \[ |
| 164 | + \setMmuInstructionParametersRamToRamSansPadding { |
| 165 | + anchorRow = i , |
| 166 | + relOffset = \locMcopyFrstMiscOffset , |
| 167 | + sourceId = \cn_{i} , |
| 168 | + targetId = 1 + \hubStamp_{i} , |
| 169 | + % auxiliaryId = 1 + \hubStamp_{i} , |
| 170 | + % sourceOffsetHi = \col{src\_offset\_hi} , |
| 171 | + sourceOffsetLo = \locSrcOffsetLo , |
| 172 | + % targetOffsetLo = \locTgtOffsetLo , |
| 173 | + size = \locSizeLo , |
| 174 | + referenceOffset = 0 , |
| 175 | + referenceSize = \locSizeLo , |
| 176 | + % successBit = \nothing , |
| 177 | + % limbOne = \col{limb\_1} , |
| 178 | + % limbTwo = \col{limb\_2} , |
| 179 | + % exoSum = \exoWeightKec , |
| 180 | + % phase = \nothing , |
| 181 | + } |
| 182 | + \] |
| 183 | + \item[\underline{Miscellaneous-row $n^°(i + \locMcopyScndMiscOffset)$: \mmuMod{} data:}] |
| 184 | + \If $\locTriggerMmu = 1$ \Then |
| 185 | + \[ |
| 186 | + \setMmuInstructionParametersRamToRamSansPadding { |
| 187 | + anchorRow = i , |
| 188 | + relOffset = \locMcopyScndMiscOffset , |
| 189 | + sourceId = 1 + \hubStamp_{i} , |
| 190 | + targetId = \cn_{i} , |
| 191 | + % auxiliaryId = \nothing , |
| 192 | + % sourceOffsetHi = \col{src\_offset\_hi} , |
| 193 | + sourceOffsetLo = 0 , |
| 194 | + % targetOffsetLo = \locTgtOffsetLo , |
| 195 | + size = \locSizeLo , |
| 196 | + referenceOffset = \locTgtOffsetLo , |
| 197 | + referenceSize = \locSizeLo , |
| 198 | + % successBit = \nothing , |
| 199 | + % limbOne = \col{limb\_1} , |
| 200 | + % limbTwo = \col{limb\_2} , |
| 201 | + % exoSum = \exoWeightKec , |
| 202 | + % phase = \nothing , |
| 203 | + } |
| 204 | + \] |
| 205 | + \saNote{} |
| 206 | + The current context and caller context (which may own the call data) are provided by the lookup. |
| 207 | +\end{description} |
0 commit comments