Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

No need to check quantity, PT distribution when minting tokens #712

Closed
wants to merge 8 commits into from
3 changes: 2 additions & 1 deletion hydra-node/src/Hydra/Chain/Direct/Tx.hs
Original file line number Diff line number Diff line change
Expand Up @@ -636,8 +636,9 @@ observeInitTx networkId cardanoKeys expectedCP party tx = do

assetNames headAssetName =
[ assetName
| (AssetId _ assetName, _) <- txMintAssets tx
| (AssetId _ assetName, assetQuantity) <- txMintAssets tx
, assetName /= headAssetName
, assetQuantity == 1
]

data CommitObservation = CommitObservation
Expand Down
23 changes: 23 additions & 0 deletions hydra-node/test/Hydra/Chain/Direct/StateSpec.hs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import qualified Cardano.Api.UTxO as UTxO
import Cardano.Binary (serialize)
import qualified Data.ByteString.Lazy as LBS
import Data.List (intersect)
import qualified Data.List as List
import qualified Data.Map as Map
import qualified Data.Set as Set
import Hydra.Cardano.Api (
Expand Down Expand Up @@ -48,6 +49,7 @@ import Hydra.Chain.Direct.State (
genContestTx,
genFanoutTx,
genHydraContext,
genHydraContextFor,
genInitTx,
genStInitial,
getContestationDeadline,
Expand Down Expand Up @@ -139,6 +141,27 @@ spec = parallel $ do
let tx = initialize cctxA (ctxHeadParameters ctxA) seedInput
in isNothing (observeInit cctxB tx)

prop "is not observed if wrong number of PT tokens distributed" $
forAll (genHydraContextFor maximumNumberOfParties) $ \ctx ->
forAll (pickChainContext ctx) $
\cctx ->
forAll genTxIn $ \seedInput ->
let wrongCctx =
ChainContext
{ networkId = networkId cctx
, -- Here we use wrong cardano-keys to build the tx
-- as they are used to generate the PT tokens to be minted
peerVerificationKeys = List.head (peerVerificationKeys cctx) : peerVerificationKeys cctx
, ownVerificationKey = ownVerificationKey cctx
, ownParty = ownParty cctx
, scriptRegistry = scriptRegistry cctx
, contestationPeriod = contestationPeriod cctx
}
headParameters = ctxHeadParameters ctx
tx = initialize wrongCctx headParameters seedInput
in isNothing (observeInit cctx tx)
& counterexample "observeInit returned Observation"

describe "commit" $ do
propBelowSizeLimit maxTxSize forAllCommit
propIsValid forAllCommit
Expand Down
5 changes: 3 additions & 2 deletions hydra-plutus/src/Hydra/Contract/HeadTokens.hs
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,11 @@ validate initialValidator headValidator seedInput action context =
validateTokensMinting :: ValidatorHash -> ValidatorHash -> TxOutRef -> ScriptContext -> Bool
validateTokensMinting initialValidator headValidator seedInput context =
traceIfFalse "minted wrong" $
participationTokensAreDistributed currency initialValidator txInfo nParties
seedInputIsConsumed
-- TODO remove below checks and Init mutations
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this will be addressed once the off-chain logic is tested.

this is also needed to be removed in order to generate valid cluster specs.

&& participationTokensAreDistributed currency initialValidator txInfo nParties
&& checkQuantities
&& assetNamesInPolicy == nParties + 1
&& seedInputIsConsumed
where
currency = ownCurrencySymbol context

Expand Down