Skip to content

Commit

Permalink
Add failing mutation and start a validator fix
Browse files Browse the repository at this point in the history
  • Loading branch information
v0d1ch committed Feb 6, 2023
1 parent 8db4dae commit 574983b
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
7 changes: 6 additions & 1 deletion hydra-node/test/Hydra/Chain/Direct/Contract/Close.hs
Expand Up @@ -35,7 +35,7 @@ import Hydra.Data.ContestationPeriod (posixFromUTCTime)
import qualified Hydra.Data.ContestationPeriod as OnChain
import qualified Hydra.Data.Party as OnChain
import Hydra.Ledger (hashUTxO)
import Hydra.Ledger.Cardano (genOneUTxOFor, genVerificationKey)
import Hydra.Ledger.Cardano (genOneUTxOFor, genValue, genVerificationKey)
import Hydra.Ledger.Cardano.Evaluate (genValidityBoundsFromContestationPeriod)
import Hydra.Party (Party, deriveParty, partyToChain)
import Hydra.Snapshot (Snapshot (..), SnapshotNumber)
Expand Down Expand Up @@ -220,6 +220,8 @@ data CloseMutation
| MutateHeadId
| -- | Minting or burning of the tokens should not be possible in v_head apart from 'checkAbort' or 'checkFanout'
MutateTokenMintingOrBurning
| -- | See spec: 5.5. rule 6 -> value is preserved
MutateValueInOutput
deriving (Generic, Show, Enum, Bounded)

genCloseMutation :: (Tx, UTxO) -> Gen SomeMutation
Expand Down Expand Up @@ -278,6 +280,9 @@ genCloseMutation (tx, _utxo) =
]
, SomeMutation (Just "minting or burning is forbidden") MutateTokenMintingOrBurning
<$> (changeMintedTokens tx =<< genMintedOrBurnedValue)
, SomeMutation (Just "head value is not preserved") MutateValueInOutput <$> do
newValue <- genValue
pure $ ChangeOutput 0 (headTxOut{txOutValue = newValue})
]
where
genOversizedTransactionValidity = do
Expand Down
9 changes: 9 additions & 0 deletions hydra-plutus/src/Hydra/Contract/Head.hs
Expand Up @@ -275,7 +275,16 @@ checkClose ctx parties initialUtxoHash sig cperiod headPolicyId =
&& mustBeSignedByParticipant ctx headPolicyId
&& hasST headPolicyId outValue
&& mustNotChangeParameters
&& mustPreserveValue
where
mustPreserveValue =
traceIfFalse "head value is not preserved" $
outValue == headOutputValue
headOutputValue =
case txInfoOutputs txInfo of
[headOutput, _] -> txOutValue headOutput
_ -> traceError "does not have exactly two outputs"

hasBoundedValidity =
traceIfFalse "hasBoundedValidity check failed" $
tMax - tMin <= cp
Expand Down

0 comments on commit 574983b

Please sign in to comment.