Skip to content

Commit

Permalink
Decrement mutation: Add validator check for parameter changes
Browse files Browse the repository at this point in the history
  • Loading branch information
v0d1ch committed May 7, 2024
1 parent abd6162 commit 8de5beb
Showing 1 changed file with 26 additions and 3 deletions.
29 changes: 26 additions & 3 deletions hydra-plutus/src/Hydra/Contract/Head.hs
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ headValidator oldState input ctx =
checkCollectCom ctx (contestationPeriod, parties, headId)
(Initial{parties, headId}, Abort) ->
checkAbort ctx headId parties
(Open{}, Decrement{}) -> checkDecrement
(Open{parties, contestationPeriod, headId}, Decrement{}) -> checkDecrement ctx parties contestationPeriod headId
(Open{parties, utxoHash = initialUtxoHash, contestationPeriod, headId}, Close{signature}) ->
checkClose ctx parties initialUtxoHash signature contestationPeriod headId
(Closed{parties, snapshotNumber = closedSnapshotNumber, contestationDeadline, contestationPeriod, headId, contesters}, Contest{signature}) ->
Expand Down Expand Up @@ -227,8 +227,31 @@ commitDatum input = do
Nothing -> []
{-# INLINEABLE commitDatum #-}

checkDecrement :: Bool
checkDecrement = True
checkDecrement ::
ScriptContext ->
[Party] ->
ContestationPeriod ->
CurrencySymbol ->
Bool
checkDecrement ctx parties cperiod headPolicyId =
mustNotChangeParameters
where
(_, parties', cperiod', headId') =
case fromBuiltinData @DatumType $ getDatum (headOutputDatum ctx) of
Just
Open
{ utxoHash
, parties = p
, headId
, contestationPeriod
} -> (utxoHash, p, contestationPeriod, headId)
_ -> traceError $(errorCode WrongStateInOutputDatum)

mustNotChangeParameters =
traceIfFalse $(errorCode ChangedParameters) $
headId' == headPolicyId
&& parties' == parties
&& cperiod' == cperiod
{-# INLINEABLE checkDecrement #-}

-- | The close validator must verify that:
Expand Down

0 comments on commit 8de5beb

Please sign in to comment.