Skip to content

Commit

Permalink
Decrement on-chain: Check value in the Head is preserved
Browse files Browse the repository at this point in the history
Add this check in the specfication too.
  • Loading branch information
v0d1ch committed Mar 11, 2024
1 parent c4ec54a commit 8fd1bf8
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
13 changes: 12 additions & 1 deletion hydra-plutus/src/Hydra/Contract/Head.hs
Original file line number Diff line number Diff line change
Expand Up @@ -241,10 +241,21 @@ checkDecrement ctx@ScriptContext{scriptContextTxInfo = txInfo} prevParties prevS
&& checkSnapshot
&& checkSnapshotSignature
&& mustBeSignedByParticipant ctx prevHeadId
&& mustPreserveValue
where
mustPreserveValue =
traceIfFalse $(errorCode HeadValueIsNotPreserved) $
headInValue === headOutValue
-- NOTE: head output + whatever is decommitted needs to be equal to the head input.
headOutValue = txOutValue $ head $ txInfoOutputs txInfo <> decommitOutputs

headInValue = maybe mempty (txOutValue . txInInfoResolved) $ findOwnInput ctx

decommitOutputs = tail (txInfoOutputs txInfo)

-- NOTE: we always assume Head output is the first one so we pick all other
-- outputs of a decommit tx to calculate the expected hash.
decommitUtxoHash = hashTxOuts $ tail (txInfoOutputs txInfo)
decommitUtxoHash = hashTxOuts decommitOutputs
(nextUtxoHash, nextParties, nextSnapshotNumber, nextCperiod, nextHeadId) =
case fromBuiltinData @DatumType $ getDatum (headOutputDatum ctx) of
Just
Expand Down
1 change: 1 addition & 0 deletions spec/onchain.tex
Original file line number Diff line number Diff line change
Expand Up @@ -314,6 +314,7 @@ \subsection{Decrement Transaction}\label{sec:increment-tx}
\]
\item Transaction is signed by a participant $\exists \{\cid \mapsto \keyHash_{i} \mapsto 1\} \in \valHead' \Rightarrow \keyHash_{i} \in \txKeys$.
\todo{Need a constraint on the value in the head?}
\item Value in the head is preserved $\valHead' = \valHead$.
\end{menumerate}

\begin{figure}[h] \centering
Expand Down

0 comments on commit 8fd1bf8

Please sign in to comment.