Skip to content

Commit

Permalink
Ensure close transaction does not change contestation period
Browse files Browse the repository at this point in the history
  • Loading branch information
abailly-iohk authored and ch1bo committed Aug 31, 2023
1 parent 07159cf commit 2f45529
Show file tree
Hide file tree
Showing 8 changed files with 24 additions and 14 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ changes.

## [0.13.0] - UNRELEASED

- **BREAKING** Changes to `hydra-plutus` scripts.

- Remove hydra-tools package. Move functionality to generate hydra keys to the
hydra-node executable.

Expand Down
8 changes: 7 additions & 1 deletion hydra-node/test/Hydra/Chain/Direct/Contract/Close.hs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import Hydra.Chain.Direct.Contract.Mutation (
changeHeadOutputDatum,
changeMintedTokens,
replaceContestationDeadline,
replaceContestationPeriod,
replaceContesters,
replaceHeadId,
replaceParties,
Expand All @@ -42,9 +43,9 @@ import Hydra.Ledger (hashUTxO)
import Hydra.Ledger.Cardano (genAddressInEra, genOneUTxOFor, genValue, genVerificationKey)
import Hydra.Ledger.Cardano.Evaluate (genValidityBoundsFromContestationPeriod)
import Hydra.Party (Party, deriveParty, partyToChain)
import Hydra.Snapshot (Snapshot (..), SnapshotNumber)
import Hydra.Plutus.Extras (posixFromUTCTime)
import Hydra.Plutus.Orphans ()
import Hydra.Snapshot (Snapshot (..), SnapshotNumber)
import PlutusLedgerApi.V1.Time (DiffMilliSeconds (..), fromMilliSeconds)
import PlutusLedgerApi.V2 (BuiltinByteString, POSIXTime, PubKeyHash (PubKeyHash), toBuiltin)
import Test.Hydra.Fixture (aliceSk, bobSk, carolSk)
Expand Down Expand Up @@ -284,6 +285,8 @@ data CloseMutation
--
-- Ensures values are preserved between head input and output.
MutateValueInOutput
| -- | Invalidate the tx by changing the contestation period.
MutateContestationPeriod
deriving (Generic, Show, Enum, Bounded)

genCloseMutation :: (Tx, UTxO) -> Gen SomeMutation
Expand Down Expand Up @@ -330,6 +333,9 @@ genCloseMutation (tx, _utxo) =
, SomeMutation (Just $ toErrorCode IncorrectClosedContestationDeadline) MutateContestationDeadline <$> do
mutatedDeadline <- genMutatedDeadline
pure $ ChangeOutput 0 $ changeHeadOutputDatum (replaceContestationDeadline mutatedDeadline) headTxOut
, SomeMutation (Just $ toErrorCode ChangedParameters) MutateContestationPeriod <$> do
mutatedPeriod <- arbitrary
pure $ ChangeOutput 0 $ changeHeadOutputDatum (replaceContestationPeriod mutatedPeriod) headTxOut
, SomeMutation (Just $ toErrorCode InfiniteLowerBound) MutateInfiniteLowerBound . ChangeValidityLowerBound <$> do
pure TxValidityNoLowerBound
, SomeMutation (Just $ toErrorCode InfiniteUpperBound) MutateInfiniteUpperBound . ChangeValidityUpperBound <$> do
Expand Down
10 changes: 5 additions & 5 deletions hydra-plutus/hydra-plutus.cabal
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
cabal-version: 2.2
name: hydra-plutus
version: 0.12.0
version: 0.13.0
synopsis: Hydra Plutus Contracts
author: IOG
copyright: 2022 IOG
Expand Down Expand Up @@ -100,10 +100,10 @@ library
, hydra-cardano-api
, hydra-plutus-extras
, hydra-prelude
, plutus-core >=1.7 && <1.8
, plutus-ledger-api >=1.7 && <1.8
, plutus-tx >=1.7 && <1.8
, plutus-tx-plugin >=1.7 && <1.8
, plutus-core >=1.7 && <1.8
, plutus-ledger-api >=1.7 && <1.8
, plutus-tx >=1.7 && <1.8
, plutus-tx-plugin >=1.7 && <1.8
, QuickCheck
, serialise
, template-haskell
Expand Down
4 changes: 2 additions & 2 deletions hydra-plutus/scripts/mHead.plutus

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion hydra-plutus/scripts/vCommit.plutus
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"type": "PlutusScriptV2",
"description": "hydra-vCommit-0.11.0-439-g9f4198034",
"description": "hydra-vCommit-0.12.0-86-gcd14dca2f",
"cborHex": "59082a59082701000032323232323322323322323232323232222533533223530060052225323233500713300249010343303100323301b225335001101422135002225335333573466e3c0080280640604c04c0044c01800c004cc0408d4004888888888888020c0040184cc00924010343303200323301b225335001101422135002225335333573466e3c0080280640604c0540044c01800c004cc0408d54cd40044c0392410350543800221002222200335300100622222222222200a235001220022253350011012133573800402264646666ae68cdc3800a4004424400446666ae68cdc3801240004244002464c6402e66ae70050054054050d55ce8009baa00232323333573466e1c0052000232323232323322123300100300232323333573466e1c0052000232323232323232323232323232323232323232323232323232323333332222221233333333333300100701200600500400e00d00c00300a0020083302d232323333573466e1c0052000232323233221233001003002303b0023014001357426ae894008d5d0a80089aab9e00323263203c3357380720740746aae74004dd500080619816806805199807bae00e00933300f75c01c0106605aeb8010ccc03dd710008011aba135744a01e6ae854038d5d0a8071aba1500e35742a01c6ae854038d5d0a8071aba1500e35742a01c6ae854038d5d0a8071aba1500e232323333573466e1c0052000232323232323232323333222212333300100500400300232323333573466e1c005200023232323322123300100300230260023300b025001357426ae894008d5d0a80089aab9e00323263203a33573806e0700706aae74004dd50021998073ae00d00332323333573466e1c005200423212223002004357426aae7800c8cccd5cd19b87002480088c8c84888c004010dd70009aba135573c00846666ae68cdc3801a400042444006464c6407866ae700e40e80e80e40e0d55ce8009baa0023300575c0026ae84d5d128029aba1500435742a0086ae85401088c8c8cccd5cd19b87001480008c8c8488c00800cc018004d5d09aab9e00323333573466e1c0092002212200123263203833573806a06c06c06a6aae74004dd500089aba25001135744a00226aae7800c8c98c80bccd5ce0160168169aab9d00137540024666004eb9d68009119118011bab001302b2233335573e002405246466a05266442466002006004600c6aae754004c014d55cf280098021aba200313574200405626ae8940044d5d1280089aba25001135744a00226ae8940044d5d1280089aba25001135744a00226ae8940044d5d1280089aab9e00323263201e3357380360380386aae74004dd500119191999ab9a3370e00290031191909111180200299191999ab9a3370e002900610911111100191919191999ab9a3370e00a900510911111100211999ab9a3370e00c900411919199109111111198008048041bae002375a0026ae84d5d128021aba1500323333573466e1c01d20062323233221222222233002009008375c0046eb8004d5d09aba2500635742a00a46666ae68cdc380424008464646644244444446600c01201060260046eb8004d5d09aba2500835742a00e46666ae68cdc3804a40044646424444444600e01060260026ae84d55cf00591999ab9a3370e014900011919091111111802804180a0009aba135573c018464c6405666ae700a00a40a40a009c0980940904d55cf00289aab9e004135573c0060406aae74004dd50009aba135573c00646666ae68cdc3801240084646424444600400a60100026ae84d55cf00211999ab9a3370e006900111919091111800802980e8009aba135573c00a46666ae68cdc3802240004646424444600600a6eb8004d5d09aab9e00623263202133573803c03e03e03c03a0386aae74004dd50009aba135744a0086ae85400c8c8c8cccd5cd19b87001480088c8c8c8c8c8ccc888488ccc00401401000cdd68019bad002375a0026ae84d5d128019aba1500235742a00426ae8940044d55cf00191999ab9a3370e004900011919091180100198038009aba135573c008464c6403a66ae7006806c06c068d55ce8009baa001232323333573466e1c0052002232321223001003375c0026ae84d55cf00191999ab9a3370e00490001191909118010019bae001357426aae780108c98c8070cd5ce00c80d00d00c9aab9d001375400226aae7800c8c98c8058cd5ce00980a00a1aab9d001375400220222600c921035054350032232323333573466e1c00520002323232323233322212333001004003002375c00660140046eb8004d5d09aba2500335742a0046ae8540084d5d1280089aab9e0032326320143357380220240246aae74004dd50009802119191999ab9a3370e002900011919191991091980080180118090011bae001357426ae894008d5d0a80089aab9e0032326320133357380200220226aae74004dd5000980711299a80088039109a80111299a999ab9a3371e00401a0180162666ae68cdc380099b8148001200200c00b1300600323263200e335738002018601844a66a002200a4426a00444a66a666ae68cdc78010058050048999ab9a3370e002900100500489803001919118011bac001300c2233335573e0024014466a01260086ae84008c00cd5d1001006111801000891001091000a450b48796472614865616456310012200212212233001004003232323333573466e1c005200023232323322123300100300232323333573466e1c0052000232375c0026ae84d55cf00191931900719ab9c00b00c00c35573a0026ea8008dd68009aba135744a0046ae8540044d55cf00191931900419ab9c00500600635573a0026ea80052410350543100120014988c8c00400488cc00cc0080080041"
}
4 changes: 2 additions & 2 deletions hydra-plutus/scripts/vHead.plutus

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion hydra-plutus/scripts/vInitial.plutus
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"type": "PlutusScriptV2",
"description": "hydra-vInitial-0.11.0-439-g9f4198034",
"description": "hydra-vInitial-0.12.0-86-gcd14dca2f",
"cborHex": "5910335910300100003323232332233223232332232323232323232323232323233223232323232323232323232323300b22225335333004375c00664646666ae68cdc3800a4004464642446002006660380360026ae84d55cf00191999ab9a3370e0049000109100111931901199ab9c02b01f02102035573a0026ea8008c8c8cccd5cd19b87001480008c8c8c8c8c8cc8848cc00400c008c8c8cccd5cd19b87001480008c8c8c8c8c8c8c8c8c8c8c8c8c8c8c8c8c8c8c8c8c8c8c8c8c8c8cccccc88888848cccccccccccc00401c04801801401003803403000c028008020cc0f48c8c8cccd5cd19b87001480008c8c8c8cc8848cc00400c008c10c008c050004d5d09aba2500235742a00226aae7800c8c98c8120cd5ce0280220231aab9d00137540020186607a01a01466601eeb8038024ccc03dd70070041981ebae00433300f75c40020046ae84d5d128079aba1500e35742a01c6ae854038d5d0a8071aba1500e35742a01c6ae854038d5d0a8071aba1500e35742a01c6ae8540388c8c8cccd5cd19b87001480008c8c8c8c8c8c8c8c8cccc888848cccc00401401000c008c8c8cccd5cd19b87001480008c8c8c8cc8848cc00400c008c098008cc02c094004d5d09aba2500235742a00226aae7800c8c98c8118cd5ce0270210221aab9d001375400866601ceb803400cc8c8cccd5cd19b87001480108c84888c008010d5d09aab9e00323333573466e1c00920022323212223001004375c0026ae84d55cf00211999ab9a3370e00690001091100191931902419ab9c05004404604504435573a0026ea8008cc015d70009aba135744a00a6ae854010d5d0a8021aba150042232323333573466e1c005200023230453006001357426aae7800c8cccd5cd19b8700248008941108c98c8110cd5ce0260200210209aab9d001375400226ae8940044d5d1280089aab9e00323263203b33573808606e0726aae74004dd500091998013ae75a0024464460046eac004c10488cccd55cf800902091919a8209981e98031aab9d5001300535573ca00260086ae8800c4d5d080101a89aba25001135744a00226ae8940044d5d1280089aba25001135744a00226ae8940044d5d1280089aba25001135744a00226aae7800c8c98c80a8cd5ce0190130141aab9d001375400464646666ae68cdc3800a400c4646424444600800a64646666ae68cdc3800a401842444444400646464646666ae68cdc3802a401442444444400846666ae68cdc38032401046464664424444444660020120106eb8008dd68009aba135744a0086ae85400c8cccd5cd19b87007480188c8c8cc8848888888cc008024020dd70011bae001357426ae894018d5d0a80291999ab9a3370e0109002119191991091111111980300480418098011bae001357426ae894020d5d0a80391999ab9a3370e01290011191909111111180380418098009aba135573c01646666ae68cdc3805240004646424444444600a01060280026ae84d55cf00611931901b99ab9c03f033035034033032031030135573c00a26aae780104d55cf0018161aab9d00137540026ae84d55cf00191999ab9a3370e00490021191909111180100298040009aba135573c00846666ae68cdc3801a40044646424444600200a604a0026ae84d55cf00291999ab9a3370e0089000119190911118018029bae001357426aae780188c98c80b4cd5ce01a8148158150148141aab9d00137540026ae84d5d128021aba15003232323333573466e1c005200223232323232333222122333001005004003375a0066eb4008dd68009aba135744a0066ae854008d5d0a80109aba25001135573c00646666ae68cdc380124000464642446004006600e0026ae84d55cf00211931901499ab9c03102502702635573a0026ea80048c8c8cccd5cd19b87001480088c8c8488c00400cdd70009aba135573c00646666ae68cdc3801240004646424460040066eb8004d5d09aab9e00423263202833573806004804c04a6aae74004dd500089aab9e00323263202233573805403c0406aae74004dd5000880d8980d24810350543500222253350021330094910349303100323302a225335001102622135002225335333573466e3c0080280ac0a84c0300044c01800c004cc054028d40048800884c8c8c8c8cc09ccc068c0392410349303300332233030225335001102d22321350032230030013034225335001130060032213500222323335002253353301f480000045400840d8894cd4cc0800080045400c40dc94cd4cc07c00520001500210361300600333015002001323335530161200101302c3355300c12001235001220013300200a00150043301250023332232322300200130312253350011003221333007220023006002300400130022200123300101302c3301400d00c500332330283301b300f4910349303400301c33027500435500122002330283301b300f490103493134003302235500122001009330283301b300f491034930320033232230020013030225335001102c221533533027005002102f13004001533532330302253350011502822135002225335330290020101302d00113006003001500321533500113020498884d4008894cd400c54cd4cc05c0052002100213024498884c099261302049010349303500323355301a1200120010013550052222222222220043301b300f490103493135003301b23012001301050051533533001009500413019498884d4008894cd400c54ccd40084c08d2410349303900213024490103493130002153353235500a222222222222300d00230332253350011502b22135002225335333573466e3c00801c0d00cc4c0c00044c01800c854cd4cc080c8c88ccccccd5d20009199919ab9a3370e6aae7540052000232323233335573ea0064a06846666aae7d400c940d48cccd55cfa8019281b11999aab9f35744a0084a66a64a66a601c0024260740022a0706ae85401c854cd4c034d5d0a80390a99a98079aba1500721303b123330010040030021503915038150372503703203103002f135744a00226ae8940044d55cf280109baa0022502f02d2502e2502e2502e2502e029322333333357480024a05c4a05c460066eb0008940b8940b80a4c0d488cccd55cf8009181781a9299a991999999aba40012333233573466e1cd55cea800a4000464646666aae7d4008940d48cccd55cfa8011281b11999aab9f35744a0064a66a646666666ae900048ccc8cd5cd19b8735573aa0029000119191999aab9f50022503e233335573ea0044a07e46666aae7cd5d128019299a991999999aba40012333233573466e1cd55cea800a40004646666aae7d4004941188cccd55cf9aba2500225335301d35742a0064260920022a08e4a08e08408226aae7940084dd5001128218209282112821128211282101e9aba1500521533532333333357480024a0864a0864a086460886eb40089410c0f8d5d0a802909821998258010008a8208a8201282001d81d01c89aba25001135573ca00426ea8008940e80e0940e4940e4940e4940e40d0d5d0a80290a99a98071aba1500521303a1233001003002150381503725037032031030135744a00226aae7940084dd500112818817928181281812818128180159aba100221533530043574400642606266a06c0040022a05e2a05c05246666666ae90004940b0940b0940b0940b08c0b4dd7001013800909a8009111981800100089812a4810349313200130244910349313100221301f49888d4004888888888888ccd54c0884800488d40088888d401088cd4008802094cd4ccd5cd19b8f00101703f03e13350403303c005006008100803800a1330183225335001213003001102b3301200b00a3500422350022222222222223333500d25031250312503123303b225335001150332213500222533533035002007130380041300600300d13301732233002001004553015120012533532355003222222222222300d00c302c2253350011502422135002225335330260020071302900413006003210011301d4910349313600135002220023024225335001102022135002225335333573466e3c0092210b4879647261486561645631000250241333573466e1c004cdc0a40009001012812098030019811910891299a800881211099a812980200119aa98030900080200091a8009100091a800911100191299a800880e899ab9c00201c235001222222222222008301e225335001101b223213500322300300130222253350011300600322135002225335333573466e1d200000102302213006003102222333573466e1c00800406806488c8cd54c024480048d400488cc068008cd54c030480048d400488cc074008ccd40048cc0212000001223300900200123300800148000004cc01000c00888cdc0001000911919aa98040900091a800911980c801199a800919aa98060900091a800911980e80118070008009119980300b001000919aa98060900091a800911980e8011aa806800800999800808801801111199aa9803890009119a80f00100099aa98050900091a800911980d8011806000999aa980389000911a80111911801003981191299a800899a8108028021109a80111299a9980600100388040980300180e80099aa98050900091a80091191980e0019800802981191299a80089aa8068019109a80111299a9980600100408911198010050020980300180111118019801000980c9108911299a800880111099802801199aa98038900080280200090911180180208909111800802180b110891299a800880b91099a80c180200119aa98030900080200091803a49034931330022300200130132235001225335002153350011012221300a4901034930370022153350031300a4910349303800221350042253350071356622135002223301a3301437666a00a444466e952000323357406a00a4466e95200032335740600200666ae80cc0108cd40048cdd2a400066ae80c00c004dd881011119ba548008cd5d01ba80033357406ea0008cd5d01ba800137620440046ec40788cd40048cdd2a400066ae80dd48009bb101f23374a900119aba037520026ec407ccd5d019919800ba9233300275246ea000400488c88dd31801000981411299a80089bb201f221350022233574066ec0c020008c01c004c01800c010cd5d02999a801899ba548000dd880d9099ba548010cd5d00009bb101c213374a900119aba037520026ec4070cd5d019800ba9002376203644a66a0024266e95200033574060060026ec40744cdd2a40046ec4070004cc068cc054018008c038cc06402400c8c8c8cccd5cd19b87001480008c8c8c8cc060c8c8cccd5cd19b87001480008c8dd70009aba135573c006464c6402466ae70068038040d55ce8009baa002375a0026ae84d5d128011aba15001135573c006464c6401866ae70050020028d55ce8009baa0012322300237580026024446666aae7c00480488cd4044c010d5d080118019aba20020062300249103493036002326320063357380020042400244666ae68cdc780100080500491299a999ab9a3371e6a004440046a002440040120102666ae68cdc39a801110009a80091000804804080424c42446004006224400244246600200600444a66a0042002200624400424400224400424424466002008006921035054310022123300100300223230010012233003300200200148811ce4c32d6dc83b2917aa7805571f30437ad98b6d20d821d34d459437550001"
}
6 changes: 4 additions & 2 deletions hydra-plutus/src/Hydra/Contract/Head.hs
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,7 @@ checkClose ctx parties initialUtxoHash sig cperiod headPolicyId =
traceIfFalse $(errorCode HasBoundedValidityCheckFailed) $
tMax - tMin <= cp

(closedSnapshotNumber, closedUtxoHash, parties', closedContestationDeadline, headId', contesters') =
(closedSnapshotNumber, closedUtxoHash, parties', closedContestationDeadline, cperiod', headId', contesters') =
-- XXX: fromBuiltinData is super big (and also expensive?)
case fromBuiltinData @DatumType $ getDatum (headOutputDatum ctx) of
Just
Expand All @@ -292,7 +292,8 @@ checkClose ctx parties initialUtxoHash sig cperiod headPolicyId =
, contestationDeadline
, headId
, contesters
} -> (snapshotNumber, utxoHash, p, contestationDeadline, headId, contesters)
, contestationPeriod
} -> (snapshotNumber, utxoHash, p, contestationDeadline, contestationPeriod, headId, contesters)
_ -> traceError $(errorCode WrongStateInOutputDatum)

checkSnapshot
Expand Down Expand Up @@ -321,6 +322,7 @@ checkClose ctx parties initialUtxoHash sig cperiod headPolicyId =
traceIfFalse $(errorCode ChangedParameters) $
headId' == headPolicyId
&& parties' == parties
&& cperiod' == cperiod

mustInitializeContesters =
traceIfFalse $(errorCode ContestersNonEmpty) $
Expand Down

0 comments on commit 2f45529

Please sign in to comment.