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

Unable to spend UTXO with datum to pkh #295

Closed
t4ccer opened this issue Feb 3, 2022 · 1 comment · Fixed by #308
Closed

Unable to spend UTXO with datum to pkh #295

t4ccer opened this issue Feb 3, 2022 · 1 comment · Fixed by #308
Labels
bug Something isn't working

Comments

@t4ccer
Copy link

t4ccer commented Feb 3, 2022

Summary

It is impossible to spend UTXO with attached datum to pkh due to matchInputOutput function that returns InOutTypeMismatch error.

Steps to reproduce the behavior

Try to spend UTXO with datum to pkh. Example:

import PlutusTx.Prelude
import Prelude qualified as Hask

import Control.Monad (void, forever)
import Plutus.Trace.Emulator (EmulatorTrace, activateContractWallet, callEndpoint, runEmulatorTraceIO)
import Plutus.Trace.Emulator qualified as Trace
import Wallet.Emulator (Wallet, mockWalletPaymentPubKeyHash, fromWalletNumber, WalletNumber (WalletNumber))
import Ledger.Address (PaymentPubKeyHash)
import qualified Ledger.Constraints as Constraints
import qualified Plutus.Contract as Contract
import Ledger.Typed.Scripts (Any)
import Plutus.V1.Ledger.Api (Datum(Datum), toBuiltinData)
import Plutus.V1.Ledger.Ada (lovelaceValueOf)
import Data.Text (Text)

type AppSchema = Contract.Endpoint "example" (Integer, PaymentPubKeyHash)

example :: (Integer, PaymentPubKeyHash) -> Contract.Contract () s Text ()
example (v, pkh) = do
  let datum = Datum $ toBuiltinData ()
      tx = Constraints.mustPayWithDatumToPubKey pkh datum (lovelaceValueOf v)
  void $ Contract.submitTxConstraintsWith @Any Hask.mempty tx

endpoints :: Contract.Contract () AppSchema Text ()
endpoints = forever . Contract.selectList $ [Contract.endpoint @"example" example]

walletFromNumber :: Integer -> Wallet
walletFromNumber = fromWalletNumber . WalletNumber

w1, w2, w3 :: Wallet
w1 = walletFromNumber 1
w2 = walletFromNumber 2
w3 = walletFromNumber 3

testTrace :: EmulatorTrace ()
testTrace = do
  h1 <- activateContractWallet w1 endpoints
  h2 <- activateContractWallet w2 endpoints 
  -- First transaction
  callEndpoint @"example" h1 (50_000_000, mockWalletPaymentPubKeyHash w2)
  void $ Trace.waitNSlots 1
  -- Second transaction
  callEndpoint @"example" h2 (125_000_000, mockWalletPaymentPubKeyHash w3)
  void $ Trace.waitNSlots 1

main :: Hask.IO ()
main = runEmulatorTraceIO testTrace

Actual Result

First transaction succeeds, but the second one that tries to spend UTXO with attached datum fails with InOutTypeMismatch error, and funds are not send as desired. Emulator trace:

Slot 00000: TxnValidate 98d5fbcefe21113b3f0390c1441e075b8a870cc5a8fa2a56dcde1d8247e41715
Slot 00000: SlotAdd Slot 1
Slot 00001: W1bc5f27: InsertionSuccess: New tip is Tip(slot= Slot 1, blockId= BlockId(1033bd6bfb9d90108db08880ad32a58980ae8dafd14c6217d7f83db6fae6f70c), blockNo= 0). UTxO state was added to the end.
Slot 00001: W3a47782: InsertionSuccess: New tip is Tip(slot= Slot 1, blockId= BlockId(1033bd6bfb9d90108db08880ad32a58980ae8dafd14c6217d7f83db6fae6f70c), blockNo= 0). UTxO state was added to the end.
Slot 00001: W4e76ce6: InsertionSuccess: New tip is Tip(slot= Slot 1, blockId= BlockId(1033bd6bfb9d90108db08880ad32a58980ae8dafd14c6217d7f83db6fae6f70c), blockNo= 0). UTxO state was added to the end.
Slot 00001: W5f5a4f5: InsertionSuccess: New tip is Tip(slot= Slot 1, blockId= BlockId(1033bd6bfb9d90108db08880ad32a58980ae8dafd14c6217d7f83db6fae6f70c), blockNo= 0). UTxO state was added to the end.
Slot 00001: W7ce812d: InsertionSuccess: New tip is Tip(slot= Slot 1, blockId= BlockId(1033bd6bfb9d90108db08880ad32a58980ae8dafd14c6217d7f83db6fae6f70c), blockNo= 0). UTxO state was added to the end.
Slot 00001: W872cb83: InsertionSuccess: New tip is Tip(slot= Slot 1, blockId= BlockId(1033bd6bfb9d90108db08880ad32a58980ae8dafd14c6217d7f83db6fae6f70c), blockNo= 0). UTxO state was added to the end.
Slot 00001: Wbdf8dbc: InsertionSuccess: New tip is Tip(slot= Slot 1, blockId= BlockId(1033bd6bfb9d90108db08880ad32a58980ae8dafd14c6217d7f83db6fae6f70c), blockNo= 0). UTxO state was added to the end.
Slot 00001: Wc19599f: InsertionSuccess: New tip is Tip(slot= Slot 1, blockId= BlockId(1033bd6bfb9d90108db08880ad32a58980ae8dafd14c6217d7f83db6fae6f70c), blockNo= 0). UTxO state was added to the end.
Slot 00001: Wc30efb7: InsertionSuccess: New tip is Tip(slot= Slot 1, blockId= BlockId(1033bd6bfb9d90108db08880ad32a58980ae8dafd14c6217d7f83db6fae6f70c), blockNo= 0). UTxO state was added to the end.
Slot 00001: Wd3eddd0: InsertionSuccess: New tip is Tip(slot= Slot 1, blockId= BlockId(1033bd6bfb9d90108db08880ad32a58980ae8dafd14c6217d7f83db6fae6f70c), blockNo= 0). UTxO state was added to the end.
Slot 00001: 00000000-0000-4000-8000-000000000000 {Wallet W872c}:
  Contract instance started
Slot 00001: 00000000-0000-4000-8000-000000000001 {Wallet W7ce8}:
  Contract instance started
Slot 00001: 00000000-0000-4000-8000-000000000000 {Wallet W872c}:
  Receive endpoint call on 'example' for Object (fromList [("contents",Array [Object (fromList [("getEndpointDescription",String "example")]),Object (fromList [("unEndpointValue",Array [Number 5.0e7,Object (fromList [("unPaymentPubKeyHash",Object (fromList [("getPubKeyHash",String "80a4f45b56b88d1139da23bc4c3c75ec6d32943c087f250b86193ca7")]))])])])]),("tag",String "ExposeEndpointResp")])
Slot 00001: 00000000-0000-4000-8000-000000000000 {Wallet W872c}:
  Contract log: Object (fromList [("mkTxLogLookups",Object (fromList [("slMPS",Array []),("slOtherData",Array []),("slOtherScripts",Array []),("slOwnPaymentPubKeyHash",Null),("slOwnStakePubKeyHash",Null),("slPaymentPubKeyHashes",Array []),("slTxOutputs",Array []),("slTypedValidator",Null)])),("mkTxLogResult",Object (fromList [("Right",Object (fromList [("unBalancedTxRequiredSignatories",Array []),("unBalancedTxTx",Object (fromList [("txCollateral",Array []),("txData",Array [Array [String "923918e403bf43c34b4ef6b48eb2ee04babed17320d8d1b9ff9ad086e86f44ec",String "d87980"]]),("txFee",Object (fromList [("getValue",Array [])])),("txInputs",Array []),("txMint",Object (fromList [("getValue",Array [])])),("txMintScripts",Array []),("txOutputs",Array [Object (fromList [("txOutAddress",Object (fromList [("addressCredential",Object (fromList [("contents",Object (fromList [("getPubKeyHash",String "80a4f45b56b88d1139da23bc4c3c75ec6d32943c087f250b86193ca7")])),("tag",String "PubKeyCredential")])),("addressStakingCredential",Null)])),("txOutDatumHash",String "923918e403bf43c34b4ef6b48eb2ee04babed17320d8d1b9ff9ad086e86f44ec"),("txOutValue",Object (fromList [("getValue",Array [Array [Object (fromList [("unCurrencySymbol",String "")]),Array [Array [Object (fromList [("unTokenName",String "")]),Number 5.0e7]]]])]))])]),("txRedeemers",Array []),("txSignatures",Array []),("txValidRange",Object (fromList [("ivFrom",Array [Object (fromList [("tag",String "NegInf")]),Bool True]),("ivTo",Array [Object (fromList [("tag",String "PosInf")]),Bool True])]))])),("unBalancedTxUtxoIndex",Array []),("unBalancedTxValidityTimeRange",Object (fromList [("ivFrom",Array [Object (fromList [("tag",String "NegInf")]),Bool True]),("ivTo",Array [Object (fromList [("tag",String "PosInf")]),Bool True])]))]))])),("mkTxLogTxConstraints",Object (fromList [("txConstraints",Array [Object (fromList [("contents",Array [Object (fromList [("unPaymentPubKeyHash",Object (fromList [("getPubKeyHash",String "80a4f45b56b88d1139da23bc4c3c75ec6d32943c087f250b86193ca7")]))]),Null,String "d87980",Object (fromList [("getValue",Array [Array [Object (fromList [("unCurrencySymbol",String "")]),Array [Array [Object (fromList [("unTokenName",String "")]),Number 5.0e7]]]])])]),("tag",String "MustPayToPubKeyAddress")])]),("txOwnInputs",Array []),("txOwnOutputs",Array [])]))])
Slot 00001: W872cb83: TxSubmit: 04287644ea4c70227ef42256ed2cfdd95e2b884dd6d84e823f44ce8b41d75327
Slot 00001: TxnValidate 04287644ea4c70227ef42256ed2cfdd95e2b884dd6d84e823f44ce8b41d75327
Slot 00001: SlotAdd Slot 2
Slot 00002: W1bc5f27: InsertionSuccess: New tip is Tip(slot= Slot 2, blockId= BlockId(ba478af07712323bd0b026dfc30af87d699069a8be7ec1ca28aeece5807d5c21), blockNo= 1). UTxO state was added to the end.
Slot 00002: W3a47782: InsertionSuccess: New tip is Tip(slot= Slot 2, blockId= BlockId(ba478af07712323bd0b026dfc30af87d699069a8be7ec1ca28aeece5807d5c21), blockNo= 1). UTxO state was added to the end.
Slot 00002: W4e76ce6: InsertionSuccess: New tip is Tip(slot= Slot 2, blockId= BlockId(ba478af07712323bd0b026dfc30af87d699069a8be7ec1ca28aeece5807d5c21), blockNo= 1). UTxO state was added to the end.
Slot 00002: W5f5a4f5: InsertionSuccess: New tip is Tip(slot= Slot 2, blockId= BlockId(ba478af07712323bd0b026dfc30af87d699069a8be7ec1ca28aeece5807d5c21), blockNo= 1). UTxO state was added to the end.
Slot 00002: W7ce812d: InsertionSuccess: New tip is Tip(slot= Slot 2, blockId= BlockId(ba478af07712323bd0b026dfc30af87d699069a8be7ec1ca28aeece5807d5c21), blockNo= 1). UTxO state was added to the end.
Slot 00002: W872cb83: InsertionSuccess: New tip is Tip(slot= Slot 2, blockId= BlockId(ba478af07712323bd0b026dfc30af87d699069a8be7ec1ca28aeece5807d5c21), blockNo= 1). UTxO state was added to the end.
Slot 00002: Wbdf8dbc: InsertionSuccess: New tip is Tip(slot= Slot 2, blockId= BlockId(ba478af07712323bd0b026dfc30af87d699069a8be7ec1ca28aeece5807d5c21), blockNo= 1). UTxO state was added to the end.
Slot 00002: Wc19599f: InsertionSuccess: New tip is Tip(slot= Slot 2, blockId= BlockId(ba478af07712323bd0b026dfc30af87d699069a8be7ec1ca28aeece5807d5c21), blockNo= 1). UTxO state was added to the end.
Slot 00002: Wc30efb7: InsertionSuccess: New tip is Tip(slot= Slot 2, blockId= BlockId(ba478af07712323bd0b026dfc30af87d699069a8be7ec1ca28aeece5807d5c21), blockNo= 1). UTxO state was added to the end.
Slot 00002: Wd3eddd0: InsertionSuccess: New tip is Tip(slot= Slot 2, blockId= BlockId(ba478af07712323bd0b026dfc30af87d699069a8be7ec1ca28aeece5807d5c21), blockNo= 1). UTxO state was added to the end.
Slot 00002: 00000000-0000-4000-8000-000000000001 {Wallet W7ce8}:
  Receive endpoint call on 'example' for Object (fromList [("contents",Array [Object (fromList [("getEndpointDescription",String "example")]),Object (fromList [("unEndpointValue",Array [Number 1.25e8,Object (fromList [("unPaymentPubKeyHash",Object (fromList [("getPubKeyHash",String "2e0ad60c3207248cecd47dbde3d752e0aad141d6b8f81ac2c6eca27c")]))])])])]),("tag",String "ExposeEndpointResp")])
Slot 00002: 00000000-0000-4000-8000-000000000001 {Wallet W7ce8}:
  Contract log: Object (fromList [("mkTxLogLookups",Object (fromList [("slMPS",Array []),("slOtherData",Array []),("slOtherScripts",Array []),("slOwnPaymentPubKeyHash",Null),("slOwnStakePubKeyHash",Null),("slPaymentPubKeyHashes",Array []),("slTxOutputs",Array []),("slTypedValidator",Null)])),("mkTxLogResult",Object (fromList [("Right",Object (fromList [("unBalancedTxRequiredSignatories",Array []),("unBalancedTxTx",Object (fromList [("txCollateral",Array []),("txData",Array [Array [String "923918e403bf43c34b4ef6b48eb2ee04babed17320d8d1b9ff9ad086e86f44ec",String "d87980"]]),("txFee",Object (fromList [("getValue",Array [])])),("txInputs",Array []),("txMint",Object (fromList [("getValue",Array [])])),("txMintScripts",Array []),("txOutputs",Array [Object (fromList [("txOutAddress",Object (fromList [("addressCredential",Object (fromList [("contents",Object (fromList [("getPubKeyHash",String "2e0ad60c3207248cecd47dbde3d752e0aad141d6b8f81ac2c6eca27c")])),("tag",String "PubKeyCredential")])),("addressStakingCredential",Null)])),("txOutDatumHash",String "923918e403bf43c34b4ef6b48eb2ee04babed17320d8d1b9ff9ad086e86f44ec"),("txOutValue",Object (fromList [("getValue",Array [Array [Object (fromList [("unCurrencySymbol",String "")]),Array [Array [Object (fromList [("unTokenName",String "")]),Number 1.25e8]]]])]))])]),("txRedeemers",Array []),("txSignatures",Array []),("txValidRange",Object (fromList [("ivFrom",Array [Object (fromList [("tag",String "NegInf")]),Bool True]),("ivTo",Array [Object (fromList [("tag",String "PosInf")]),Bool True])]))])),("unBalancedTxUtxoIndex",Array []),("unBalancedTxValidityTimeRange",Object (fromList [("ivFrom",Array [Object (fromList [("tag",String "NegInf")]),Bool True]),("ivTo",Array [Object (fromList [("tag",String "PosInf")]),Bool True])]))]))])),("mkTxLogTxConstraints",Object (fromList [("txConstraints",Array [Object (fromList [("contents",Array [Object (fromList [("unPaymentPubKeyHash",Object (fromList [("getPubKeyHash",String "2e0ad60c3207248cecd47dbde3d752e0aad141d6b8f81ac2c6eca27c")]))]),Null,String "d87980",Object (fromList [("getValue",Array [Array [Object (fromList [("unCurrencySymbol",String "")]),Array [Array [Object (fromList [("unTokenName",String "")]),Number 1.25e8]]]])])]),("tag",String "MustPayToPubKeyAddress")])]),("txOwnInputs",Array []),("txOwnOutputs",Array [])]))])
Slot 00002: W7ce812d: TxSubmit: b591a6ee1306536af18f4ee12b1c6db8ad74726b41333d6983ff028dd92f872f
Slot 00002: TxnValidationFail Phase2 b591a6ee1306536af18f4ee12b1c6db8ad74726b41333d6983ff028dd92f872f: InOutTypeMismatch (TxIn {txInRef = TxOutRef {txOutRefId = 04287644ea4c70227ef42256ed2cfdd95e2b884dd6d84e823f44ce8b41d75327, txOutRefIdx = 1}, txInType = Just ConsumePublicKeyAddress}) (TxOut {txOutAddress = Address {addressCredential = PubKeyCredential 80a4f45b56b88d1139da23bc4c3c75ec6d32943c087f250b86193ca7, addressStakingCredential = Nothing}, txOutValue = Value (Map [(,Map [("",50000000)])]), txOutDatumHash = Just 923918e403bf43c34b4ef6b48eb2ee04babed17320d8d1b9ff9ad086e86f44ec})
Slot 00002: SlotAdd Slot 3
Slot 00003: W1bc5f27: InsertionSuccess: New tip is Tip(slot= Slot 3, blockId= BlockId(06e611ae324e8867379e58884f2a03625b76a596e41a088474a6dfc6e6f4aeec), blockNo= 2). UTxO state was added to the end.
Slot 00003: W3a47782: InsertionSuccess: New tip is Tip(slot= Slot 3, blockId= BlockId(06e611ae324e8867379e58884f2a03625b76a596e41a088474a6dfc6e6f4aeec), blockNo= 2). UTxO state was added to the end.
Slot 00003: W4e76ce6: InsertionSuccess: New tip is Tip(slot= Slot 3, blockId= BlockId(06e611ae324e8867379e58884f2a03625b76a596e41a088474a6dfc6e6f4aeec), blockNo= 2). UTxO state was added to the end.
Slot 00003: W5f5a4f5: InsertionSuccess: New tip is Tip(slot= Slot 3, blockId= BlockId(06e611ae324e8867379e58884f2a03625b76a596e41a088474a6dfc6e6f4aeec), blockNo= 2). UTxO state was added to the end.
Slot 00003: W7ce812d: InsertionSuccess: New tip is Tip(slot= Slot 3, blockId= BlockId(06e611ae324e8867379e58884f2a03625b76a596e41a088474a6dfc6e6f4aeec), blockNo= 2). UTxO state was added to the end.
Slot 00003: W872cb83: InsertionSuccess: New tip is Tip(slot= Slot 3, blockId= BlockId(06e611ae324e8867379e58884f2a03625b76a596e41a088474a6dfc6e6f4aeec), blockNo= 2). UTxO state was added to the end.
Slot 00003: Wbdf8dbc: InsertionSuccess: New tip is Tip(slot= Slot 3, blockId= BlockId(06e611ae324e8867379e58884f2a03625b76a596e41a088474a6dfc6e6f4aeec), blockNo= 2). UTxO state was added to the end.
Slot 00003: Wc19599f: InsertionSuccess: New tip is Tip(slot= Slot 3, blockId= BlockId(06e611ae324e8867379e58884f2a03625b76a596e41a088474a6dfc6e6f4aeec), blockNo= 2). UTxO state was added to the end.
Slot 00003: Wc30efb7: InsertionSuccess: New tip is Tip(slot= Slot 3, blockId= BlockId(06e611ae324e8867379e58884f2a03625b76a596e41a088474a6dfc6e6f4aeec), blockNo= 2). UTxO state was added to the end.
Slot 00003: Wd3eddd0: InsertionSuccess: New tip is Tip(slot= Slot 3, blockId= BlockId(06e611ae324e8867379e58884f2a03625b76a596e41a088474a6dfc6e6f4aeec), blockNo= 2). UTxO state was added to the end.
Slot 00003: SlotAdd Slot 4
Slot 00004: W1bc5f27: InsertionSuccess: New tip is Tip(slot= Slot 4, blockId= BlockId(76be8b528d0075f7aae98d6fa57a6d3c83ae480a8469e668d7b0af968995ac71), blockNo= 3). UTxO state was added to the end.
Slot 00004: W3a47782: InsertionSuccess: New tip is Tip(slot= Slot 4, blockId= BlockId(76be8b528d0075f7aae98d6fa57a6d3c83ae480a8469e668d7b0af968995ac71), blockNo= 3). UTxO state was added to the end.
Slot 00004: W4e76ce6: InsertionSuccess: New tip is Tip(slot= Slot 4, blockId= BlockId(76be8b528d0075f7aae98d6fa57a6d3c83ae480a8469e668d7b0af968995ac71), blockNo= 3). UTxO state was added to the end.
Slot 00004: W5f5a4f5: InsertionSuccess: New tip is Tip(slot= Slot 4, blockId= BlockId(76be8b528d0075f7aae98d6fa57a6d3c83ae480a8469e668d7b0af968995ac71), blockNo= 3). UTxO state was added to the end.
Slot 00004: W7ce812d: InsertionSuccess: New tip is Tip(slot= Slot 4, blockId= BlockId(76be8b528d0075f7aae98d6fa57a6d3c83ae480a8469e668d7b0af968995ac71), blockNo= 3). UTxO state was added to the end.
Slot 00004: W872cb83: InsertionSuccess: New tip is Tip(slot= Slot 4, blockId= BlockId(76be8b528d0075f7aae98d6fa57a6d3c83ae480a8469e668d7b0af968995ac71), blockNo= 3). UTxO state was added to the end.
Slot 00004: Wbdf8dbc: InsertionSuccess: New tip is Tip(slot= Slot 4, blockId= BlockId(76be8b528d0075f7aae98d6fa57a6d3c83ae480a8469e668d7b0af968995ac71), blockNo= 3). UTxO state was added to the end.
Slot 00004: Wc19599f: InsertionSuccess: New tip is Tip(slot= Slot 4, blockId= BlockId(76be8b528d0075f7aae98d6fa57a6d3c83ae480a8469e668d7b0af968995ac71), blockNo= 3). UTxO state was added to the end.
Slot 00004: Wc30efb7: InsertionSuccess: New tip is Tip(slot= Slot 4, blockId= BlockId(76be8b528d0075f7aae98d6fa57a6d3c83ae480a8469e668d7b0af968995ac71), blockNo= 3). UTxO state was added to the end.
Slot 00004: Wd3eddd0: InsertionSuccess: New tip is Tip(slot= Slot 4, blockId= BlockId(76be8b528d0075f7aae98d6fa57a6d3c83ae480a8469e668d7b0af968995ac71), blockNo= 3). UTxO state was added to the end.
Final balances
Wallet 1bc5f27d7b4e20083977418e839e429d00cc87f3:
    {, ""}: 100000000
Wallet 3a4778247ad35117d7c3150d194da389f3148f4a:
    {, ""}: 100000000
Wallet 4e76ce6b3f12c6cc5a6a2545f6770d2bcb360648:
    {, ""}: 100000000
Wallet 5f5a4f5f465580a5500b9a9cede7f4e014a37ea8:
    {, ""}: 100000000
Wallet 7ce812d7a4770bbf58004067665c3a48f28ddd58:
    {, ""}: 100000000
Wallet 872cb83b5ee40eb23bfdab1772660c822a48d491:
    {, ""}: 49999990
Wallet bdf8dbca0cadeb365480c6ec29ec746a2b85274f:
    {, ""}: 100000000
Wallet c19599f22890ced15c6a87222302109e83b78bdf:
    {, ""}: 100000000
Wallet c30efb78b4e272685c1f9f0c93787fd4b6743154:
    {, ""}: 100000000
Wallet d3eddd0d37989746b029a0e050386bc425363901:
    {, ""}: 100000000

Expected Result

Both transactions succeed

Describe the approach you would take to fix this

One of the possible fixes is to change pattern matching in matchInputOutput like it is done here: t4ccer@0d3ad30

System info

OS: NixOS
plutus: cc72a56eafb02333c96f662581b57504f8f8992f
plutus-apps: 62efdd2bfab3e076d40e07f8f4d7864a7f2ccc91

@t4ccer t4ccer added the bug Something isn't working label Feb 3, 2022
ghost pushed a commit that referenced this issue Feb 9, 2022
@ghost ghost closed this as completed in #308 Feb 10, 2022
ghost pushed a commit that referenced this issue Feb 10, 2022
@ghost
Copy link

ghost commented Feb 10, 2022

Thanks for reporting!

This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant