Skip to content

Commit

Permalink
Add ContestUnusedDec redeemer
Browse files Browse the repository at this point in the history
  • Loading branch information
v0d1ch committed Oct 30, 2024
1 parent 530ee4d commit f4c9aae
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 1 deletion.
6 changes: 6 additions & 0 deletions hydra-plutus/src/Hydra/Contract/Head.hs
Original file line number Diff line number Diff line change
Expand Up @@ -542,6 +542,12 @@ checkContest ctx closedDatum redeemer =
parties
(headId, version - 1, snapshotNumber', utxoHash', emptyHash, alreadyDecommittedUTxOHash)
signature
ContestUnusedDec{signature} ->
traceIfFalse $(errorCode FailedContestUnusedDec) $
verifySnapshotSignature
parties
(headId, version - 1, snapshotNumber', utxoHash', emptyHash, deltaUTxOHash')
signature

mustBeWithinContestationPeriod =
case ivTo (txInfoValidRange txInfo) of
Expand Down
5 changes: 5 additions & 0 deletions hydra-plutus/src/Hydra/Contract/HeadState.hs
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,11 @@ data ContestRedeemer
, alreadyDecommittedUTxOHash :: Hash
-- ^ UTxO which was already decommitted ηω
}
| -- | Redeemer to use when the decommit was not yet observed but we closed the Head.
ContestUnusedDec
{ signature :: [Signature]
-- ^ Multi-signature of a snapshot ξ
}
deriving stock (Show, Generic)

PlutusTx.unstableMakeIsData ''ContestRedeemer
Expand Down
19 changes: 18 additions & 1 deletion hydra-tx/test/Hydra/Tx/Contract/Contest/ContestDec.hs
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,9 @@ import Data.Maybe (fromJust)
import Hydra.Contract.Error (toErrorCode)
import Hydra.Contract.HeadError (HeadError (..))
import Hydra.Contract.HeadState qualified as Head
import Hydra.Tx.Crypto (toPlutusSignatures)
import Hydra.Tx.Crypto (MultiSignature, toPlutusSignatures)

import Hydra.Tx (Snapshot)
import Hydra.Tx.Contract.Contest.Healthy (
healthyCloseSnapshotVersion,
healthyContestSnapshotNumber,
Expand All @@ -29,8 +30,11 @@ import Test.QuickCheck.Instances ()

data ContestDecMutation
= ContestUsedDecAlterRedeemerDecommitHash
| ContestUnusedDecAlterRedeemerDecommitHash
| ContestUsedDecAlterDatumDeltaUTxOHash
| ContestUnusedDecAlterDatumDeltaUTxOHash
| ContestUsedDecMutateSnapshotVersion
| ContestUnusedDecMutateSnapshotVersion
deriving stock (Generic, Show, Enum, Bounded)

genContestDecMutation :: (Tx, UTxO) -> Gen SomeMutation
Expand All @@ -44,6 +48,13 @@ genContestDecMutation (tx, _utxo) =
{ signature = toPlutusSignatures (healthySignature healthyContestSnapshotNumber)
, alreadyDecommittedUTxOHash = mempty
}
, SomeMutation (pure $ toErrorCode SignatureVerificationFailed) ContestUnusedDecAlterRedeemerDecommitHash . ChangeHeadRedeemer <$> do
mutatedSignature <- arbitrary :: Gen (MultiSignature (Snapshot Tx))
pure $
Head.Contest
Head.ContestUnusedDec
{ signature = toPlutusSignatures mutatedSignature
}
, SomeMutation (pure $ toErrorCode FailedContestUsedDec) ContestUsedDecAlterRedeemerDecommitHash <$> do
mutatedHash <- arbitrary `suchThat` (/= mempty)
pure $
Expand All @@ -56,9 +67,15 @@ genContestDecMutation (tx, _utxo) =
, SomeMutation (pure $ toErrorCode SignatureVerificationFailed) ContestUsedDecAlterDatumDeltaUTxOHash . ChangeOutput 0 <$> do
mutatedHash <- arbitrary `suchThat` (/= mempty)
pure $ headTxOut & modifyInlineDatum (replaceDeltaUTxOHash mutatedHash)
, SomeMutation (pure $ toErrorCode SignatureVerificationFailed) ContestUnusedDecAlterDatumDeltaUTxOHash . ChangeOutput 0 <$> do
mutatedHash <- arbitrary `suchThat` (/= mempty)
pure $ headTxOut & modifyInlineDatum (replaceDeltaUTxOHash mutatedHash)
, SomeMutation (pure $ toErrorCode MustNotChangeVersion) ContestUsedDecMutateSnapshotVersion <$> do
mutatedSnapshotVersion <- arbitrarySizedNatural `suchThat` (/= healthyCloseSnapshotVersion)
pure $ ChangeOutput 0 $ modifyInlineDatum (replaceSnapshotVersion $ toInteger mutatedSnapshotVersion) headTxOut
, SomeMutation (pure $ toErrorCode MustNotChangeVersion) ContestUnusedDecMutateSnapshotVersion <$> do
mutatedSnapshotVersion <- arbitrarySizedNatural `suchThat` (/= healthyCloseSnapshotVersion)
pure $ ChangeOutput 0 $ modifyInlineDatum (replaceSnapshotVersion $ toInteger mutatedSnapshotVersion) headTxOut
]
where
headTxOut = fromJust $ txOuts' tx !!? 0

0 comments on commit f4c9aae

Please sign in to comment.