-
Notifications
You must be signed in to change notification settings - Fork 157
/
Copy pathutxo.tex
368 lines (360 loc) · 13.6 KB
/
utxo.tex
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
\section{UTxO}
\label{sec:utxo}
Some of the functions related to scripts, datums and collateral need
to be adjusted for the new features. Most of these adjustments are
self-explanatory. Note that the new $\fun{collOuts}$ function
generates a single output with an index $| \txouts{txb} |$. This is to
avoid potential confusion for transactions spending that output. Note
that $\TxId$ can only hold integers up to $2^{16} - 1$. In case of an
overflow, we let this number be $2^{16} - 1$.
\begin{figure*}[htb]
\emph{Functions}
%
\begin{align*}
& \fun{isTwoPhaseScriptAddress} : \Tx \to \hldiff{\UTxO} \to \Addr \to \Bool \\
& \fun{isTwoPhaseScriptAddress}~tx~\hldiff{utxo}~a = \\
&\quad\begin{cases}
\True & a \in \AddrScr \land \fun{validatorHash}~a \mapsto s \in \fun{txscripts}~tx~\hldiff{utxo} \land s \in \ScriptPhTwo \\
\False & \text{otherwise}
\end{cases}
\nextdef
& \fun{collOuts} : \TxBody \to \UTxO \\
& \fun{collOuts}~txb =
\begin{cases}
\emptyset & \fun{collRet}~txb = \Nothing \\
\{ (\txid{txb}, | \txouts{txb} |) \mapsto \fun{collRet}~txb \} & \text{otherwise}
\end{cases}
\nextdef
& \fun{collBalance} : \TxBody \to \UTxO \to \Value \\
& \fun{collBalance}~txb~utxo = \fun{ubalance}~(\var{utxo}|_{\fun{collInputs}~{txb}}) - \fun{ubalance}~(\fun{collOuts}~txb)
\nextdef
& \fun{feesOK} : \PParams \to \Tx \to \UTxO \to \Bool \\
& \fun{feesOK}~\var{pp}~tx~utxo = \\
&~~ \minfee{pp}{tx} \leq \txfee{tx} \wedge (\fun{txrdmrs}~tx \neq \Nothing \Rightarrow \\
&~~~~~~~~~~\forall (a, \wcard, \wcard, \wcard) \in \fun{range}~(\fun{collInputs}~tx \restrictdom \var{utxo}), a \in \AddrVKey \\
&~~~~~~\wedge \fun{adaOnly}~\var{balance} \\
&~~~~~~\wedge \var{balance} \geq \hldiff{\txfee{txb} * \fun{collateralPercent}~pp / 100} \\
&~~~~~~\wedge \hldiff{(\fun{txcoll}~tx \neq \Nothing) \Rightarrow \var{balance} = \fun{txcoll}~tx} \\
&~~~~~~\wedge \fun{collInputs}~{tx} \neq \emptyset) \\
&~~ \where \\
& ~~~~~~~ \var{balance}=\hldiff{\fun{collBalance}~tx~utxo}
\end{align*}
\caption{Functions related to fees and collateral}
\label{fig:functions:utxo}
\end{figure*}
\begin{figure*}
\begin{align*}
& \fun{getDatum} : \Tx \to \UTxO \to \ScriptPurpose \to \seqof{\Datum} \\
& \fun{getDatum}~{tx}~{utxo}~{sp} =
\begin{cases}
[\var{d}] & \var{sp} \in \TxIn, (\_, \_, h, \_) \in \var{utxo}~\var{sp},~ \var{d}\in\fun{txdats}~(\fun{txwits}~tx)~\var{h} \\
[\var{d}] & \hldiff{\var{sp} \in \TxIn, (\_, \_, d, \_) \in \var{utxo}~\var{sp},~ \var{d} \in \Datum} \\
\epsilon & \text{otherwise}
\end{cases}
\nextdef
& \fun{refScripts} : \Tx \to \hldiff{\UTxO} \to \ScriptHash \pto \Script \\
& \fun{refScripts}~tx~utxo = \{ \fun{hash}~s \mapsto s \mid (\_, \_, \_, s) \in \var{utxo}~(\fun{spendInputs}~tx \cup \fun{refInputs}~tx)\}
\nextdef
& \fun{txscripts} : \Tx \to \hldiff{\UTxO} \to \ScriptHash \pto \Script \\
& \fun{txscripts}~tx~utxo = \fun{txwitscripts}~tx \cup \hldiff{\fun{refScripts}~tx~utxo}
\nextdef
& \fun{allOuts} : \Tx \to \powerset{\TxOut} \\
& \fun{allOuts}~tx = \range \txouts{tx} \cup \fun{collRet}~tx
\nextdef
& \fun{languages} : \Tx \to \UTxO \to \powerset{\Language} \\
& \fun{languages}~tx~utxo =
\{\fun{language}~s \mid s \in \range (\fun{txscripts}~tx~\hldiff{utxo}) \cap \ScriptPhTwo\}
\nextdef
& \fun{allowedLanguages} : \Tx \to \UTxO \to \powerset{\Language} \\
& \fun{allowedLanguages}~tx~utxo = \\
& \begin{cases}
\emptyset & \text{if}~\exists (a, \_, \_, \_) \in os, a \in \AddrBS \\
\{ \PlutusVII \} & \text{if}~\exists (\_, \_, d, s) \in os, d \in \Datum \lor s \neq \Nothing \lor \fun{refInputs}~tx \neq \emptyset \\
\{ \PlutusVI, \PlutusVII \} & \text{otherwise}
\end{cases} \\
& \where \var{os} = \range \txouts{tx} \cup \var{utxo}~(\fun{spendInputs}~tx \cup \fun{refInputs}~tx)
\end{align*}
\caption{Functions related to scripts}
\label{fig:functions:data}
\end{figure*}
\begin{figure}[htb]
\begin{equation}
\inference[Scripts-Yes]
{
\var{txb}\leteq\txbody{tx} &
\var{sLst} := \fun{collectTwoPhaseScriptInputs}~\var{pp}~\var{tx}~\var{utxo}
\\~\\
{
\begin{array}{r}
\var{slot} \\
\var{pp} \\
\var{genDelegs} \\
\end{array}
}
\vdash \var{pup} \trans{\hyperref[fig:rules:update]{ppup}}{\fun{txup}~\var{tx}} \var{pup'}
\\~\\
\var{refunded} \leteq \keyRefunds{pp}{txb}
\\
\var{depositChange} \leteq
\fun{totalDeposits}~{pp}~\var{poolParams}~(\txcerts{txb})~-~\var{refunded}
\\~\\
\fun{isValid}~\var{tx} = \fun{evalScripts}~\var{tx}~\var{sLst} = \True
}
{
\begin{array}{l}
\var{slot}\\
\var{pp}\\
\var{poolParams}\\
\var{genDelegs}\\
\end{array}
\vdash
\left(
\begin{array}{r}
\var{utxo} \\
\var{deposits} \\
\var{fees} \\
\var{pup} \\
\end{array}
\right)
\trans{utxos}{tx}
\left(
\begin{array}{r}
\varUpdate{\var{(\fun{spendInputs}~txb \subtractdom \var{utxo}) \cup \outs{txb}}} \\
\varUpdate{\var{deposits} + \var{depositChange}} \\
\varUpdate{\var{fees} + \txfee{txb}} \\
\varUpdate{\var{pup'}} \\
\end{array}
\right) \\
}
\end{equation}
\begin{equation}
\inference[Scripts-No]
{
\var{txb}\leteq\txbody{tx} &
\var{sLst} := \fun{collectTwoPhaseScriptInputs}~\var{pp}~\var{tx}~\var{utxo} \\
\hldiff{\var{collateralFees} := \fun{valueToCoin}~(\fun{collBalance}~txb~utxo)}
\\
~
\\
\fun{isValid}~\var{tx} = \fun{evalScripts}~\var{tx}~\var{sLst} = \False
}
{
\begin{array}{l}
\var{slot}\\
\var{pp}\\
\var{poolParams}\\
\var{genDelegs}\\
\end{array}
\vdash
\left(
\begin{array}{r}
\var{utxo} \\
\var{deposits} \\
\var{fees} \\
\var{pup} \\
\end{array}
\right)
\trans{utxos}{tx}
\left(
\begin{array}{r}
\varUpdate{\var{(\fun{collInputs}~{txb} \subtractdom \var{utxo})} \cup \hldiff{\fun{collOuts}~txb}} \\
\var{deposits} \\
\varUpdate{\var{fees} + \hldiff{\var{collateralFees}}} \\
\var{pup} \\
\end{array}
\right)
}
\end{equation}
\caption{State update rules}
\label{fig:rules:utxo-state-upd}
\end{figure}
In the UTXO rule, we switch from a manual estimation of the size consumed by $\UTxO$ entries to an estimation using the serialization. However, since the $\TxIn$ used as a key in the $\UTxO$ map is not part of the serialization, we need to account for it manually. By itself it is $40$ bytes, but we add another $120$ bytes of overhead for the in-memory representation of Haskell data.
\begin{figure}[htb]
\begin{equation}
\inference[UTxO-inductive]
{
\var{txb}\leteq\txbody{tx} &
\fun{ininterval}~\var{slot}~(\fun{txvldt}~{txb}) &
\var{(\wcard, i_f)}\leteq\fun{txvldt}~{tx} \\~\\
\Nothing \notin \{\fun{txrdmrs}~\var{tx}, i_f\} \Rightarrow \fun{epochInfoSlotToUTCTime}~\mathsf{EI}~\mathsf{SysSt}~i_f \neq \Nothing \\
\fun{spendInputs}~txb \neq \emptyset
& \fun{feesOK}~pp~tx~utxo
\\
\fun{spendInputs}~txb \cup \fun{collInputs}~txb \cup \hldiff{\fun{refInputs}~{tx}} \subseteq \dom \var{utxo} \\
\consumed{pp}{utxo}{txb} = \produced{pp}{poolParams}~{txb}
\\~\\
\mathsf{adaID}\notin \supp {\fun{mint}~tx} \\~\\
\forall txout \in \hldiff{\fun{allOuts}~txb}, \\
\fun{getValue}~txout \geq \fun{inject}~(\hldiff{(\fun{serSize}~txout + 160) * \fun{coinsPerUTxOByte}~pp}) \\~
\\
\forall txout \in \hldiff{\fun{allOuts}~txb},\\
\fun{serSize}~(\fun{getValue}~txout) \leq \fun{maxValSize}~pp \\~
\\
\forall (\wcard\mapsto (a,~\wcard, \wcard, \wcard)) \in \hldiff{\fun{allOuts}~txb}, a \in \AddrBS \Rightarrow \fun{bootstrapAttrsSize}~a \leq 64 \\
\forall (\wcard\mapsto (a,~\wcard, \wcard, \wcard)) \in \hldiff{\fun{allOuts}~txb}, \fun{netId}~a = \NetworkId
\\
\forall (a\mapsto\wcard) \in \txwdrls{txb}, \fun{netId}~a = \NetworkId \\
(\fun{txnetworkid}~\var{txb} = \NetworkId) \vee (\fun{txnetworkid}~\var{txb} = \Nothing)
\\~\\
\fun{txsize}~{tx}\leq\fun{maxTxSize}~\var{pp} \\~\\
\fun{totExunits}~{tx} \leq \fun{maxTxExUnits}~{pp} & \| \fun{collInputs}~{tx} \| \leq \fun{maxCollateralInputs}~{pp}
\\
~
\\
{
\begin{array}{c}
\var{slot}\\
\var{pp}\\
\var{poolParams}\\
\var{genDelegs}\\
\end{array}
}
\vdash
{
\left(
\begin{array}{r}
\var{utxo} \\
\var{deposits} \\
\var{fees} \\
\var{pup}\\
\end{array}
\right)
}
\trans{utxos}{\var{tx}}
{
\left(
\begin{array}{r}
\var{utxo'} \\
\var{deposits'} \\
\var{fees'} \\
\var{pup'}\\
\end{array}
\right)
}
}
{
\begin{array}{l}
\var{slot}\\
\var{pp}\\
\var{poolParams}\\
\var{genDelegs}\\
\end{array}
\vdash
\left(
\begin{array}{r}
\var{utxo} \\
\var{deposits} \\
\var{fees} \\
\var{pup}\\
\end{array}
\right)
\trans{utxo}{tx}
\left(
\begin{array}{r}
\varUpdate{\var{utxo'}} \\
\varUpdate{\var{deposits'}} \\
\varUpdate{\var{fees'}} \\
\varUpdate{\var{pup'}}\\
\end{array}
\right)
}
\end{equation}
\caption{UTxO inference rules}
\label{fig:rules:utxo-babbage}
\end{figure}
To the UTXOW rule, in addition to the changes required by the new
features, we add a check that all scripts and datums involved in the
transaction are well-formed. We forbid transactions that try to
execute $\PlutusVI$ scripts and use the new features which can't be
translated to $\PlutusVI$'s $\TxInfo$ (reference inputs, inline datums
and reference scripts). We also forbid transactions that involve Byron
addresses.
\begin{figure}
\begin{equation}
\label{eq:utxo-witness-inductive-babbage}
\inference[UTxO-witG]
{
\var{txb}\leteq\txbody{tx} &
\var{txw}\leteq\fun{txwits}~{tx} \\
(utxo, \wcard, \wcard, \wcard) \leteq \var{utxoSt} \\
\var{witsKeyHashes} \leteq \{\fun{hashKey}~\var{vk} \vert \var{vk} \in
\dom (\txwitsVKey{txw}) \}\\
\var{inputHashes}\leteq \left\{ h \,\middle|
{
\begin{array}{l}
(a, \_, h, \_) \in \range(\var{utxo}|_{\fun{spendInputs}~tx}) \\
\fun{isTwoPhaseScriptAddress}~tx~\hldiff{utxo}~a \\
\end{array}
}
\right\} - \hldiff{\Datum} \\~\\
\var{neededHashes}\leteq \{ h \mid (\_, h) \in \fun{scriptsNeeded}~\var{utxo}~txb\} \\
\forall \var{s} \in (\fun{txscripts}~txw~\hldiff{utxo~\var{neededHashes}}) \cap \ScriptPhOne,
\fun{validateScript}~\var{s}~\var{tx}\\~\\
\var{neededHashes} - \hldiff{\dom (\fun{refScripts}~tx~utxo)} = \dom (\fun{txwitscripts}~txw) \\~\\
\var{inputHashes} \subseteq \dom (\fun{txdats}~{txw}) \\
\dom (\fun{txdats}~{txw}) \subseteq \var{inputHashes} \cup {\{h \mid (\wcard, \wcard, h, \wcard)\in\fun{allOuts}~tx \cup \hldiff{\var{utxo}~(\fun{refInputs}~{tx})}\}} \\~\\
\\~\\
\dom (\fun{txrdmrs}~tx) = \left\{ \fun{rdptr}~txb~sp \,\middle|
{
\begin{array}{l}
(sp,h) \in \fun{scriptsNeeded}~\var{utxo}~txb \\
\fun{txscripts}~{txw}~\hldiff{utxo}~h \in \ScriptPhTwo
\end{array}
} \right\}
\\~\\
\var{txbodyHash}\leteq\fun{hash}~(\txbody{tx}) \\
\forall \var{vk} \mapsto \sigma \in \txwitsVKey{tx},
\mathcal{V}_{\var{vk}}{\serialised{txbodyHash}}_{\sigma} \\
\fun{witsVKeyNeeded}~{utxo}~{tx}~{genDelegs} \subseteq witsKeyHashes
\\~\\
genSig \leteq
\left\{
\fun{hashKey}~gkey \vert gkey \in\dom{genDelegs}
\right\}
\cap
\var{witsKeyHashes}
\\
\left\{
c\in\txcerts{txb}~\cap\DCertMir
\right\} \neq\emptyset \implies \vert genSig\vert \geq \Quorum
\\~\\
\var{adh}\leteq\fun{txADhash}~\var{txb}
&
\var{ad}\leteq\fun{auxiliaryData}~\var{tx}
\\
(\var{adh}=\Nothing \land \var{ad}=\Nothing)
\lor
(\var{adh}=\fun{hashAD}~\var{ad})
\\~\\
\hldiff{\forall x \in \range (\fun{txdats}~txw) \cup \range (\fun{txwitscripts}~txw)} \\
\hldiff{\cup \bigcup_{(\_, \_, d, s) \in \hldiff{\fun{allOuts}~txb}} \{s, d\} \cup \fun{scripts}~(\fun{auxiliaryData}~tx),} \\
\hldiff{x \in \Script \cup \Datum \Rightarrow \fun{isWellFormed}~x}
\\~\\
\fun{languages}~tx~\hldiff{utxo} \subseteq \dom(\fun{costmdls}~pp) \cap \fun{allowedLanguages}~tx~utxo \\
\fun{scriptIntegrityHash}~{txb} =
\fun{hashScriptIntegrity}~\var{pp}~(\fun{languages}~{txw}~\hldiff{utxo})~(\fun{txrdmrs}~{txw})~(\fun{txdats}~{txw})
\\~\\
{
\begin{array}{r}
\var{slot}\\
\var{pp}\\
\var{poolParams}\\
\var{genDelegs}\\
\end{array}
}
\vdash \var{utxoSt} \trans{\hyperref[fig:rules:utxo-shelley]{utxo}}{tx}
\var{utxoSt'}\\
}
{
\begin{array}{r}
\var{slot}\\
\var{pp}\\
\var{poolParams}\\
\var{genDelegs}\\
\end{array}
\vdash \var{utxoSt} \trans{utxow}{tx} \varUpdate{\var{utxoSt'}}
}
\end{equation}
\caption{UTxO with witnesses inference rules for Tx}
\label{fig:rules:utxow-babbage}
\end{figure}