Skip to content
This repository has been archived by the owner on Dec 2, 2024. It is now read-only.

Adjusting unbalanced transaction doesn't work in certain cases #143

Closed
jankun4 opened this issue Nov 25, 2021 · 3 comments
Closed

Adjusting unbalanced transaction doesn't work in certain cases #143

jankun4 opened this issue Nov 25, 2021 · 3 comments
Labels
bug Something isn't working investigating we're looking into this

Comments

@jankun4
Copy link

jankun4 commented Nov 25, 2021

Summary

Let's say we want to submit 2 transactions:

  1. Create an UTxO containing some amount of custom coin
  2. Consume previous UTxO and create another one with some amount of custom coin

By using adjustUnbalancedTx we can successfully perform transaction 1. After submitting it, there is a UTxO at the script address with the specified amount of our custom coin and 2 Ada. However, we cannot successfully perform transaction 2. If we try we will get ValueContainsLessThanMinAda exception. What is strange is that we can consume this UTxO without problems if we don't create a new UTxO in the same transaction. The problem also doesn't occur if UTxO made by transaction 1 contains 2Ada + collateral amount (3047 Lovelace) + 1 Lovelace (2003048 Lovelace in total).

By analyzing the error message, it seems like transaction 2 correctly adjusts txOuptut that goes to the script. However, one of the txOutputs that go back to the wallet contains only the custom coin stored in the first UTxO and 0 Ada.

Steps to reproduce

  1. git clone https://github.com/jankun4/minimum-ada-bug.git
  2. cd minimum-ada-bug
  3. nix-shell
  4. cabal run plutus-starter -- 0 put - UTxO from transaction 1 has 2Ada (by using adjustUnbalancedTx) and transaction 2 creates new UTxO
  5. or cabal run plutus-starter -- 0 -- UTxO from transaction 1 has 2 Ada and transaction 2 doesn't create a new UTxO
  6. or cabal run plutus-starter -- 2003048 put -- UTxO from transaction 1 has 2,003048Ada and transaction 2 creates new UTxO

Expected behavior

  1. cabal run plutus-starter -- 0 put
Slot 00000: TxnValidate 2e2145642d234060d2210ac267fe516a6a3af42b8ee2310b982007a3bccb7cbe
Slot 00000: SlotAdd Slot 1
Slot 00001: 00000000-0000-4000-8000-000000000000 {Contract instance for wallet 872cb83b5ee40eb23bfdab1772660c822a48d491}:
  Contract instance started
Slot 00001: 00000000-0000-4000-8000-000000000000 {Contract instance for wallet 872cb83b5ee40eb23bfdab1772660c822a48d491}:
  Receive endpoint call on 'start' for Object (fromList [("contents",Array [Object (fromList [("getEndpointDescription",String "start")]),Object (fromList [("unEndpointValue",Array [Number 0.0,Bool True])])]),("tag",String "ExposeEndpointResp")])
Slot 00001: W872cb83: handleUnbalancedTransactions start
Slot 00001: W872cb83: handleUnbalancedTransactions end (irregular)
Slot 00001: W872cb83: Balancing an unbalanced transaction:
            Tx:
              Tx f907085085d7fef6e6e0489a5195ec70be36f536e934882ab54347db02326d21:
                {inputs:
                collateral inputs:
                outputs:
                  - Value (Map [(,Map [("",2000000)]),(ff,Map [("some coin",100)])]) addressed to
                    ScriptCredential: 61d582a9a8ac05793a48e925ab90f5becf361b7618a76574790d04a0 (no staking credential)
                mint: Value (Map [])
                fee: Value (Map [])
                mps:
                signatures:
                validity range: Interval {ivFrom = LowerBound NegInf True, ivTo = UpperBound PosInf True}
                data:
                  <>}
            Requires signatures:
            Utxo index:
            Validity range:
              (-∞ , +∞)
Slot 00001: W872cb83: No outputs added
Slot 00001: W872cb83: Adding inputs for Value (Map [(,Map [("",2000000)]),(ff,Map [("some coin",100)])])
Slot 00001: W872cb83: No collateral inputs added
Slot 00001: W872cb83: No outputs added
Slot 00001: W872cb83: Adding inputs for Value (Map [(,Map [("",2000010)]),(ff,Map [("some coin",100)])])
Slot 00001: W872cb83: Adding collateral inputs for Value (Map [(,Map [("",10)])])
Slot 00001: W872cb83: Finished balancing. b4ee67fa44dccc0e0bd113ccb2547b8d2f94940d0310ddad69fb19315820c5eb
Slot 00001: W872cb83: handlePendingTransactions start
Slot 00001: W872cb83: handlePendingTransactions end (irregular)
Slot 00001: W872cb83: Submitting tx: b4ee67fa44dccc0e0bd113ccb2547b8d2f94940d0310ddad69fb19315820c5eb
Slot 00001: W872cb83: TxSubmit: b4ee67fa44dccc0e0bd113ccb2547b8d2f94940d0310ddad69fb19315820c5eb
Slot 00001: W872cb83: handleCurrentSlot start
Slot 00001: W872cb83: handleCurrentSlot end (irregular)
Slot 00001: W872cb83: handleSlotNotifications start
Slot 00001: W872cb83: handleSlotNotifications end (irregular)
Slot 00001: W872cb83: target slot: Slot 2; current slot: Slot 1
Slot 00001: W872cb83: handleSlotNotifications start
Slot 00001: W872cb83: handleSlotNotifications end (irregular)
Slot 00001: W872cb83: target slot: Slot 2; current slot: Slot 1
Slot 00001: TxnValidate b4ee67fa44dccc0e0bd113ccb2547b8d2f94940d0310ddad69fb19315820c5eb
Slot 00001: SlotAdd Slot 2
Slot 00002: W872cb83: handleSlotNotifications start
Slot 00002: W872cb83: handleSlotNotifications end (irregular)
Slot 00002: W872cb83: target slot: Slot 2; current slot: Slot 2
Slot 00002: W872cb83: handleChainIndexQueries start
Slot 00002: W872cb83: handleChainIndexQueries end (irregular)
Slot 00002: W872cb83: handleChainIndexQueries start
Slot 00002: W872cb83: handleChainIndexQueries end (irregular)
Slot 00002: W872cb83: handleUnbalancedTransactions start
Slot 00002: W872cb83: handleUnbalancedTransactions end (irregular)
Slot 00002: W872cb83: Balancing an unbalanced transaction:
            Tx:
              Tx bfe5e2745d0f96bd8c02418d046f7cdd9950bf1ed15a7adcb003f99887b3ca3e:
                {inputs:
                   - b4ee67fa44dccc0e0bd113ccb2547b8d2f94940d0310ddad69fb19315820c5eb!1
                     <>
                collateral inputs:
                outputs:
                  - Value (Map [(,Map [("",2000000)]),(ee,Map [("some other coin",200)])]) addressed to
                    ScriptCredential: 61d582a9a8ac05793a48e925ab90f5becf361b7618a76574790d04a0 (no staking credential)
                mint: Value (Map [])
                fee: Value (Map [])
                mps:
                signatures:
                validity range: Interval {ivFrom = LowerBound NegInf True, ivTo = UpperBound PosInf True}
                data:
                  <>}
            Requires signatures:
            Utxo index:
              ( b4ee67fa44dccc0e0bd113ccb2547b8d2f94940d0310ddad69fb19315820c5eb!1
              , - Value (Map [(,Map [("",2000000)]),(ff,Map [("some coin",100)])]) addressed to
                  61d582a9a8ac05793a48e925ab90f5becf361b7618a76574790d04a0 )
            Validity range:
              (-∞ , +∞)
Slot 00002: W872cb83: Adding public key output for Value (Map [(ff,Map [("some coin",100)])])
Slot 00002: W872cb83: Adding inputs for Value (Map [(ee,Map [("some other coin",200)])])
Slot 00002: W872cb83: No collateral inputs added
Slot 00002: W872cb83: Validation error: Phase2 f62e05cd13783cc94a047f33b69e6abef4e08321d909c271f7f9e37cab1edbd0: ValueContainsLessThanMinAda (Tx {txInputs = fromList [TxIn {txInRef = TxOutRef {txOutRefId = b4ee67fa44dccc0e0bd113ccb2547b8d2f94940d0310ddad69fb19315820c5eb, txOutRefIdx = 0}, txInType = Just ConsumePublicKeyAddress},TxIn {txInRef = TxOutRef {txOutRefId = b4ee67fa44dccc0e0bd113ccb2547b8d2f94940d0310ddad69fb19315820c5eb, txOutRefIdx = 1}, txInType = Just (ConsumeScriptAddress Validator { <script> } (Redeemer {getRedeemer = Constr 0 []}) (Datum {getDatum = Constr 0 []}))}], txCollateral = fromList [], txOutputs = [TxOut {txOutAddress = Address {addressCredential = PubKeyCredential a2c20c77887ace1cd986193e4e75babd8993cfd56995cd5cfce609c2, addressStakingCredential = Nothing}, txOutValue = Value (Map [(,Map [("",97999990)]),(ee,Map [("some other coin",99999800)]),(ff,Map [("some coin",99999900)])]), txOutDatumHash = Nothing},TxOut {txOutAddress = Address {addressCredential = PubKeyCredential a2c20c77887ace1cd986193e4e75babd8993cfd56995cd5cfce609c2, addressStakingCredential = Nothing}, txOutValue = Value (Map [(ff,Map [("some coin",100)])]), txOutDatumHash = Nothing},TxOut {txOutAddress = Address {addressCredential = ScriptCredential 61d582a9a8ac05793a48e925ab90f5becf361b7618a76574790d04a0, addressStakingCredential = Nothing}, txOutValue = Value (Map [(,Map [("",2000000)]),(ee,Map [("some other coin",200)])]), txOutDatumHash = Just 923918e403bf43c34b4ef6b48eb2ee04babed17320d8d1b9ff9ad086e86f44ec}], txMint = Value (Map []), txFee = Value (Map []), txValidRange = Interval {ivFrom = LowerBound NegInf True, ivTo = UpperBound PosInf True}, txMintScripts = fromList [], txSignatures = fromList [(8d9de88fbf445b7f6c3875a14daba94caee2ffcbc9ac211c95aba0a2f5711853,61ad66bbb90d0859b991d0cc217a4b1c66f741b77f9ba7fafd6c7bc3cc31b2e8bb35ff1c0d85fd2ddb72f2d882305614e9ab709663704d0f588d289973e5f50c)], txRedeemers = fromList [], txData = fromList [(923918e403bf43c34b4ef6b48eb2ee04babed17320d8d1b9ff9ad086e86f44ec,Datum {getDatum = Constr 0 []})]}) (Lovelace {getLovelace = 2000000})
Slot 00002: *** CONTRACT STOPPED WITH ERROR: "\"WalletError (ValidationError (ValueContainsLessThanMinAda (Tx {txInputs = fromList [TxIn {txInRef = TxOutRef {txOutRefId = b4ee67fa44dccc0e0bd113ccb2547b8d2f94940d0310ddad69fb19315820c5eb, txOutRefIdx = 0}, txInType = Just ConsumePublicKeyAddress},TxIn {txInRef = TxOutRef {txOutRefId = b4ee67fa44dccc0e0bd113ccb2547b8d2f94940d0310ddad69fb19315820c5eb, txOutRefIdx = 1}, txInType = Just (ConsumeScriptAddress Validator { <script> } (Redeemer {getRedeemer = Constr 0 []}) (Datum {getDatum = Constr 0 []}))}], txCollateral = fromList [], txOutputs = [TxOut {txOutAddress = Address {addressCredential = PubKeyCredential a2c20c77887ace1cd986193e4e75babd8993cfd56995cd5cfce609c2, addressStakingCredential = Nothing}, txOutValue = Value (Map [(,Map [(\\\"\\\",97999990)]),(ee,Map [(\\\"some other coin\\\",99999800)]),(ff,Map [(\\\"some coin\\\",99999900)])]), txOutDatumHash = Nothing},TxOut {txOutAddress = Address {addressCredential = PubKeyCredential a2c20c77887ace1cd986193e4e75babd8993cfd56995cd5cfce609c2, addressStakingCredential = Nothing}, txOutValue = Value (Map [(ff,Map [(\\\"some coin\\\",100)])]), txOutDatumHash = Nothing},TxOut {txOutAddress = Address {addressCredential = ScriptCredential 61d582a9a8ac05793a48e925ab90f5becf361b7618a76574790d04a0, addressStakingCredential = Nothing}, txOutValue = Value (Map [(,Map [(\\\"\\\",2000000)]),(ee,Map [(\\\"some other coin\\\",200)])]), txOutDatumHash = Just 923918e403bf43c34b4ef6b48eb2ee04babed17320d8d1b9ff9ad086e86f44ec}], txMint = Value (Map []), txFee = Value (Map []), txValidRange = Interval {ivFrom = LowerBound NegInf True, ivTo = UpperBound PosInf True}, txMintScripts = fromList [], txSignatures = fromList [(8d9de88fbf445b7f6c3875a14daba94caee2ffcbc9ac211c95aba0a2f5711853,61ad66bbb90d0859b991d0cc217a4b1c66f741b77f9ba7fafd6c7bc3cc31b2e8bb35ff1c0d85fd2ddb72f2d882305614e9ab709663704d0f588d289973e5f50c)], txRedeemers = fromList [], txData = fromList [(923918e403bf43c34b4ef6b48eb2ee04babed17320d8d1b9ff9ad086e86f44ec,Datum {getDatum = Constr 0 []})]}) (Lovelace {getLovelace = 2000000})))\""
Slot 00002: SlotAdd Slot 3
Final balances
Wallet 5f5a4f5f465580a5500b9a9cede7f4e014a37ea8: 
    {, ""}: 100000000
    {ff, "some coin"}: 100000000
    {ee, "some other coin"}: 100000000
Wallet 7ce812d7a4770bbf58004067665c3a48f28ddd58: 
    {, ""}: 100000000
    {ff, "some coin"}: 100000000
    {ee, "some other coin"}: 100000000
Wallet 872cb83b5ee40eb23bfdab1772660c822a48d491: 
    {, ""}: 97999990
    {ff, "some coin"}: 99999900
    {ee, "some other coin"}: 100000000
Wallet c30efb78b4e272685c1f9f0c93787fd4b6743154: 
    {, ""}: 100000000
    {ff, "some coin"}: 100000000
    {ee, "some other coin"}: 100000000
Script 61d582a9a8ac05793a48e925ab90f5becf361b7618a76574790d04a0: 
    {ff, "some coin"}: 100
    {, ""}: 2000000
  1. cabal run plutus-starter -- 0
Slot 00000: TxnValidate 2e2145642d234060d2210ac267fe516a6a3af42b8ee2310b982007a3bccb7cbe
Slot 00000: SlotAdd Slot 1
Slot 00001: 00000000-0000-4000-8000-000000000000 {Contract instance for wallet 872cb83b5ee40eb23bfdab1772660c822a48d491}:
  Contract instance started
Slot 00001: 00000000-0000-4000-8000-000000000000 {Contract instance for wallet 872cb83b5ee40eb23bfdab1772660c822a48d491}:
  Receive endpoint call on 'start' for Object (fromList [("contents",Array [Object (fromList [("getEndpointDescription",String "start")]),Object (fromList [("unEndpointValue",Array [Number 0.0,Bool False])])]),("tag",String "ExposeEndpointResp")])
Slot 00001: W872cb83: handleUnbalancedTransactions start
Slot 00001: W872cb83: handleUnbalancedTransactions end (irregular)
Slot 00001: W872cb83: Balancing an unbalanced transaction:
            Tx:
              Tx f907085085d7fef6e6e0489a5195ec70be36f536e934882ab54347db02326d21:
                {inputs:
                collateral inputs:
                outputs:
                  - Value (Map [(,Map [("",2000000)]),(ff,Map [("some coin",100)])]) addressed to
                    ScriptCredential: 61d582a9a8ac05793a48e925ab90f5becf361b7618a76574790d04a0 (no staking credential)
                mint: Value (Map [])
                fee: Value (Map [])
                mps:
                signatures:
                validity range: Interval {ivFrom = LowerBound NegInf True, ivTo = UpperBound PosInf True}
                data:
                  <>}
            Requires signatures:
            Utxo index:
            Validity range:
              (-∞ , +∞)
Slot 00001: W872cb83: No outputs added
Slot 00001: W872cb83: Adding inputs for Value (Map [(,Map [("",2000000)]),(ff,Map [("some coin",100)])])
Slot 00001: W872cb83: No collateral inputs added
Slot 00001: W872cb83: No outputs added
Slot 00001: W872cb83: Adding inputs for Value (Map [(,Map [("",2000010)]),(ff,Map [("some coin",100)])])
Slot 00001: W872cb83: Adding collateral inputs for Value (Map [(,Map [("",10)])])
Slot 00001: W872cb83: Finished balancing. b4ee67fa44dccc0e0bd113ccb2547b8d2f94940d0310ddad69fb19315820c5eb
Slot 00001: W872cb83: handlePendingTransactions start
Slot 00001: W872cb83: handlePendingTransactions end (irregular)
Slot 00001: W872cb83: Submitting tx: b4ee67fa44dccc0e0bd113ccb2547b8d2f94940d0310ddad69fb19315820c5eb
Slot 00001: W872cb83: TxSubmit: b4ee67fa44dccc0e0bd113ccb2547b8d2f94940d0310ddad69fb19315820c5eb
Slot 00001: W872cb83: handleCurrentSlot start
Slot 00001: W872cb83: handleCurrentSlot end (irregular)
Slot 00001: W872cb83: handleSlotNotifications start
Slot 00001: W872cb83: handleSlotNotifications end (irregular)
Slot 00001: W872cb83: target slot: Slot 2; current slot: Slot 1
Slot 00001: W872cb83: handleSlotNotifications start
Slot 00001: W872cb83: handleSlotNotifications end (irregular)
Slot 00001: W872cb83: target slot: Slot 2; current slot: Slot 1
Slot 00001: TxnValidate b4ee67fa44dccc0e0bd113ccb2547b8d2f94940d0310ddad69fb19315820c5eb
Slot 00001: SlotAdd Slot 2
Slot 00002: W872cb83: handleSlotNotifications start
Slot 00002: W872cb83: handleSlotNotifications end (irregular)
Slot 00002: W872cb83: target slot: Slot 2; current slot: Slot 2
Slot 00002: W872cb83: handleChainIndexQueries start
Slot 00002: W872cb83: handleChainIndexQueries end (irregular)
Slot 00002: W872cb83: handleChainIndexQueries start
Slot 00002: W872cb83: handleChainIndexQueries end (irregular)
Slot 00002: W872cb83: handleUnbalancedTransactions start
Slot 00002: W872cb83: handleUnbalancedTransactions end (irregular)
Slot 00002: W872cb83: Balancing an unbalanced transaction:
            Tx:
              Tx ac5f99a416d2cfc70344ccd458e980e19b6b61a46b825c860e2f6e401369ef90:
                {inputs:
                   - b4ee67fa44dccc0e0bd113ccb2547b8d2f94940d0310ddad69fb19315820c5eb!1
                     <>
                collateral inputs:
                outputs:
                mint: Value (Map [])
                fee: Value (Map [])
                mps:
                signatures:
                validity range: Interval {ivFrom = LowerBound NegInf True, ivTo = UpperBound PosInf True}
                data:}
            Requires signatures:
            Utxo index:
              ( b4ee67fa44dccc0e0bd113ccb2547b8d2f94940d0310ddad69fb19315820c5eb!1
              , - Value (Map [(,Map [("",2000000)]),(ff,Map [("some coin",100)])]) addressed to
                  61d582a9a8ac05793a48e925ab90f5becf361b7618a76574790d04a0 )
            Validity range:
              (-∞ , +∞)
Slot 00002: W872cb83: Adding public key output for Value (Map [(,Map [("",2000000)]),(ff,Map [("some coin",100)])])
Slot 00002: W872cb83: No inputs added
Slot 00002: W872cb83: No collateral inputs added
Slot 00002: W872cb83: Adding public key output for Value (Map [(,Map [("",2000000)]),(ff,Map [("some coin",100)])])
Slot 00002: W872cb83: Adding inputs for Value (Map [(,Map [("",3047)])])
Slot 00002: W872cb83: Adding collateral inputs for Value (Map [(,Map [("",3047)])])
Slot 00002: W872cb83: Finished balancing. 98e34964ada6cf47d4530cdf61a1ce8e5d248bd94e34da11372478f5d91cb802
Slot 00002: W872cb83: handlePendingTransactions start
Slot 00002: W872cb83: handlePendingTransactions end (irregular)
Slot 00002: W872cb83: Submitting tx: 98e34964ada6cf47d4530cdf61a1ce8e5d248bd94e34da11372478f5d91cb802
Slot 00002: W872cb83: TxSubmit: 98e34964ada6cf47d4530cdf61a1ce8e5d248bd94e34da11372478f5d91cb802
Slot 00002: 00000000-0000-4000-8000-000000000000 {Contract instance for wallet 872cb83b5ee40eb23bfdab1772660c822a48d491}:
  Contract instance stopped (no errors)
Slot 00002: TxnValidate 98e34964ada6cf47d4530cdf61a1ce8e5d248bd94e34da11372478f5d91cb802
Slot 00002: SlotAdd Slot 3
Final balances
Wallet 5f5a4f5f465580a5500b9a9cede7f4e014a37ea8: 
    {, ""}: 100000000
    {ff, "some coin"}: 100000000
    {ee, "some other coin"}: 100000000
Wallet 7ce812d7a4770bbf58004067665c3a48f28ddd58: 
    {, ""}: 100000000
    {ff, "some coin"}: 100000000
    {ee, "some other coin"}: 100000000
Wallet 872cb83b5ee40eb23bfdab1772660c822a48d491: 
    {ff, "some coin"}: 100000000
    {, ""}: 99996943
    {ee, "some other coin"}: 100000000
Wallet c30efb78b4e272685c1f9f0c93787fd4b6743154: 
    {, ""}: 100000000
    {ff, "some coin"}: 100000000
    {ee, "some other coin"}: 100000000
  1. cabal run plutus-starter -- 2003048 put
Slot 00000: TxnValidate 2e2145642d234060d2210ac267fe516a6a3af42b8ee2310b982007a3bccb7cbe
Slot 00000: SlotAdd Slot 1
Slot 00001: 00000000-0000-4000-8000-000000000000 {Contract instance for wallet 872cb83b5ee40eb23bfdab1772660c822a48d491}:
  Contract instance started
Slot 00001: 00000000-0000-4000-8000-000000000000 {Contract instance for wallet 872cb83b5ee40eb23bfdab1772660c822a48d491}:
  Receive endpoint call on 'start' for Object (fromList [("contents",Array [Object (fromList [("getEndpointDescription",String "start")]),Object (fromList [("unEndpointValue",Array [Number 2003048.0,Bool True])])]),("tag",String "ExposeEndpointResp")])
Slot 00001: W872cb83: handleUnbalancedTransactions start
Slot 00001: W872cb83: handleUnbalancedTransactions end (irregular)
Slot 00001: W872cb83: Balancing an unbalanced transaction:
            Tx:
              Tx a81a6453ca29fa01c4a488bad4d821dbe2a1d9af64518473ab3005bc1d82e1ed:
                {inputs:
                collateral inputs:
                outputs:
                  - Value (Map [(,Map [("",2003048)]),(ff,Map [("some coin",100)])]) addressed to
                    ScriptCredential: 61d582a9a8ac05793a48e925ab90f5becf361b7618a76574790d04a0 (no staking credential)
                mint: Value (Map [])
                fee: Value (Map [])
                mps:
                signatures:
                validity range: Interval {ivFrom = LowerBound NegInf True, ivTo = UpperBound PosInf True}
                data:
                  <>}
            Requires signatures:
            Utxo index:
            Validity range:
              (-∞ , +∞)
Slot 00001: W872cb83: No outputs added
Slot 00001: W872cb83: Adding inputs for Value (Map [(,Map [("",2003048)]),(ff,Map [("some coin",100)])])
Slot 00001: W872cb83: No collateral inputs added
Slot 00001: W872cb83: No outputs added
Slot 00001: W872cb83: Adding inputs for Value (Map [(,Map [("",2003058)]),(ff,Map [("some coin",100)])])
Slot 00001: W872cb83: Adding collateral inputs for Value (Map [(,Map [("",10)])])
Slot 00001: W872cb83: Finished balancing. 74d7066592027041b3768270803838e71b4b1e9e0afe312f3ff0ffa3b68a1ab0
Slot 00001: W872cb83: handlePendingTransactions start
Slot 00001: W872cb83: handlePendingTransactions end (irregular)
Slot 00001: W872cb83: Submitting tx: 74d7066592027041b3768270803838e71b4b1e9e0afe312f3ff0ffa3b68a1ab0
Slot 00001: W872cb83: TxSubmit: 74d7066592027041b3768270803838e71b4b1e9e0afe312f3ff0ffa3b68a1ab0
Slot 00001: W872cb83: handleCurrentSlot start
Slot 00001: W872cb83: handleCurrentSlot end (irregular)
Slot 00001: W872cb83: handleSlotNotifications start
Slot 00001: W872cb83: handleSlotNotifications end (irregular)
Slot 00001: W872cb83: target slot: Slot 2; current slot: Slot 1
Slot 00001: W872cb83: handleSlotNotifications start
Slot 00001: W872cb83: handleSlotNotifications end (irregular)
Slot 00001: W872cb83: target slot: Slot 2; current slot: Slot 1
Slot 00001: TxnValidate 74d7066592027041b3768270803838e71b4b1e9e0afe312f3ff0ffa3b68a1ab0
Slot 00001: SlotAdd Slot 2
Slot 00002: W872cb83: handleSlotNotifications start
Slot 00002: W872cb83: handleSlotNotifications end (irregular)
Slot 00002: W872cb83: target slot: Slot 2; current slot: Slot 2
Slot 00002: W872cb83: handleChainIndexQueries start
Slot 00002: W872cb83: handleChainIndexQueries end (irregular)
Slot 00002: W872cb83: handleChainIndexQueries start
Slot 00002: W872cb83: handleChainIndexQueries end (irregular)
Slot 00002: W872cb83: handleUnbalancedTransactions start
Slot 00002: W872cb83: handleUnbalancedTransactions end (irregular)
Slot 00002: W872cb83: Balancing an unbalanced transaction:
            Tx:
              Tx 4fe2fdfc3adf04a054670c6d34ed32ee75be4b71efa98054ecfdb4679a62561b:
                {inputs:
                   - 74d7066592027041b3768270803838e71b4b1e9e0afe312f3ff0ffa3b68a1ab0!1
                     <>
                collateral inputs:
                outputs:
                  - Value (Map [(,Map [("",2000000)]),(ee,Map [("some other coin",200)])]) addressed to
                    ScriptCredential: 61d582a9a8ac05793a48e925ab90f5becf361b7618a76574790d04a0 (no staking credential)
                mint: Value (Map [])
                fee: Value (Map [])
                mps:
                signatures:
                validity range: Interval {ivFrom = LowerBound NegInf True, ivTo = UpperBound PosInf True}
                data:
                  <>}
            Requires signatures:
            Utxo index:
              ( 74d7066592027041b3768270803838e71b4b1e9e0afe312f3ff0ffa3b68a1ab0!1
              , - Value (Map [(,Map [("",2003048)]),(ff,Map [("some coin",100)])]) addressed to
                  61d582a9a8ac05793a48e925ab90f5becf361b7618a76574790d04a0 )
            Validity range:
              (-∞ , +∞)
Slot 00002: W872cb83: Adding public key output for Value (Map [(,Map [("",2000000)]),(ff,Map [("some coin",100)])])
Slot 00002: W872cb83: Adding inputs for Value (Map [(,Map [("",1996952)]),(ee,Map [("some other coin",200)])])
Slot 00002: W872cb83: No collateral inputs added
Slot 00002: W872cb83: Adding public key output for Value (Map [(,Map [("",2000000)]),(ff,Map [("some coin",100)])])
Slot 00002: W872cb83: Adding inputs for Value (Map [(,Map [("",1999999)]),(ee,Map [("some other coin",200)])])
Slot 00002: W872cb83: Adding collateral inputs for Value (Map [(,Map [("",3047)])])
Slot 00002: W872cb83: Finished balancing. 1c3b65aaec088c424b04ef9bd92c0d207eb5bb719d73db0a325a81d7b8bfccb2
Slot 00002: W872cb83: handlePendingTransactions start
Slot 00002: W872cb83: handlePendingTransactions end (irregular)
Slot 00002: W872cb83: Submitting tx: 1c3b65aaec088c424b04ef9bd92c0d207eb5bb719d73db0a325a81d7b8bfccb2
Slot 00002: W872cb83: TxSubmit: 1c3b65aaec088c424b04ef9bd92c0d207eb5bb719d73db0a325a81d7b8bfccb2
Slot 00002: 00000000-0000-4000-8000-000000000000 {Contract instance for wallet 872cb83b5ee40eb23bfdab1772660c822a48d491}:
  Contract instance stopped (no errors)
Slot 00002: TxnValidate 1c3b65aaec088c424b04ef9bd92c0d207eb5bb719d73db0a325a81d7b8bfccb2
Slot 00002: SlotAdd Slot 3
Final balances
Wallet 5f5a4f5f465580a5500b9a9cede7f4e014a37ea8: 
    {, ""}: 100000000
    {ff, "some coin"}: 100000000
    {ee, "some other coin"}: 100000000
Wallet 7ce812d7a4770bbf58004067665c3a48f28ddd58: 
    {, ""}: 100000000
    {ff, "some coin"}: 100000000
    {ee, "some other coin"}: 100000000
Wallet 872cb83b5ee40eb23bfdab1772660c822a48d491: 
    {ff, "some coin"}: 100000000
    {, ""}: 97996943
    {ee, "some other coin"}: 99999800
Wallet c30efb78b4e272685c1f9f0c93787fd4b6743154: 
    {, ""}: 100000000
    {ff, "some coin"}: 100000000
    {ee, "some other coin"}: 100000000
Script 61d582a9a8ac05793a48e925ab90f5becf361b7618a76574790d04a0: 
    {ee, "some other coin"}: 200
    {, ""}: 2000000
@jankun4 jankun4 added the bug Something isn't working label Nov 25, 2021
@cstml
Copy link

cstml commented Nov 29, 2021

The behaviour seems to:

  • always leave 2ada locked in any eUTXO.
  • when trying to balance/spend this eUTXO, the constraint will fail if it attempts to spend/balance the eutxo, without it containing enough Ada to pay both fees and create another other eUTXOs each with a minimum of 2ada ~> this is what you see happening above.

I've edited your first example here: jankun4/minimum-ada-bug#1

here's the trace.

Slot 00000: TxnValidate 746ad844cba625225bd3d72fca4608d67b5ab8b1cae15a2345cb27a6241a2af4
Slot 00000: SlotAdd Slot 1
Slot 00001: 00000000-0000-4000-8000-000000000000 {Contract instance for wallet 872cb83b5ee40eb23bfdab1772660c822a48d491}:
  Contract instance started
Slot 00001: 00000000-0000-4000-8000-000000000000 {Contract instance for wallet 872cb83b5ee40eb23bfdab1772660c822a48d491}:
  Receive endpoint call on 'start' for Object (fromList [("contents",Array [Object (fromList [("getEndpointDescription",String "start")]),Object (fromList [("unEndpointValue",Array [Number 0.0,Bool True])])]),("tag",String "ExposeEndpointResp")])
Slot 00001: W872cb83: handleUnbalancedTransactions start
Slot 00001: W872cb83: handleUnbalancedTransactions end (irregular)
Slot 00001: W872cb83: Balancing an unbalanced transaction:
            Tx:
              Tx d4d63ee931e30153480dcfecd657dae8eff2b7bfdda393eb5aaae80a5ec3c75e:
                {inputs:
                collateral inputs:
                outputs:
                  - Value (Map [(,Map [("",4000000)]),(ff,Map [("some coin",100)])]) addressed to
                    ScriptCredential: 61d582a9a8ac05793a48e925ab90f5becf361b7618a76574790d04a0 (no staking credential)
                mint: Value (Map [])
                fee: Value (Map [])
                mps:
                signatures:
                validity range: Interval {ivFrom = LowerBound NegInf True, ivTo = UpperBound PosInf True}
                data:
                  <>}
            Requires signatures:
            Utxo index:
            Validity range:
              (-∞ , +∞)
Slot 00001: W872cb83: No outputs added
Slot 00001: W872cb83: Adding inputs for Value (Map [(,Map [("",4000000)]),(ff,Map [("some coin",100)])])
Slot 00001: W872cb83: No collateral inputs added
Slot 00001: W872cb83: No outputs added
Slot 00001: W872cb83: Adding inputs for Value (Map [(,Map [("",4000010)]),(ff,Map [("some coin",100)])])
Slot 00001: W872cb83: Adding collateral inputs for Value (Map [(,Map [("",10)])])
Slot 00001: W872cb83: Finished balancing. 306221d5fbcfde1f4c4df3fc468f17c9b15f5f8380d1bc65fff01fc1504d7d63
Slot 00001: W872cb83: handlePendingTransactions start
Slot 00001: W872cb83: handlePendingTransactions end (irregular)
Slot 00001: W872cb83: Submitting tx: 306221d5fbcfde1f4c4df3fc468f17c9b15f5f8380d1bc65fff01fc1504d7d63
Slot 00001: W872cb83: TxSubmit: 306221d5fbcfde1f4c4df3fc468f17c9b15f5f8380d1bc65fff01fc1504d7d63
Slot 00001: W872cb83: handleCurrentSlot start
Slot 00001: W872cb83: handleCurrentSlot end (irregular)
Slot 00001: W872cb83: handleSlotNotifications start
Slot 00001: W872cb83: handleSlotNotifications end (irregular)
Slot 00001: W872cb83: target slot: Slot 2; current slot: Slot 1
Slot 00001: W872cb83: handleSlotNotifications start
Slot 00001: W872cb83: handleSlotNotifications end (irregular)
Slot 00001: W872cb83: target slot: Slot 2; current slot: Slot 1
Slot 00001: TxnValidate 306221d5fbcfde1f4c4df3fc468f17c9b15f5f8380d1bc65fff01fc1504d7d63
Slot 00001: SlotAdd Slot 2
Slot 00002: W872cb83: handleSlotNotifications start
Slot 00002: W872cb83: handleSlotNotifications end (irregular)
Slot 00002: W872cb83: target slot: Slot 2; current slot: Slot 2
Slot 00002: W872cb83: handleChainIndexQueries start
Slot 00002: W872cb83: handleChainIndexQueries end (irregular)
Slot 00002: W872cb83: handleChainIndexQueries start
Slot 00002: W872cb83: handleChainIndexQueries end (irregular)
Slot 00002: W872cb83: handleUnbalancedTransactions start
Slot 00002: W872cb83: handleUnbalancedTransactions end (irregular)
Slot 00002: W872cb83: Balancing an unbalanced transaction:
            Tx:
              Tx 40d987fde6975cc9878c197e31c6c47764ccfb4e975b948a9277c4a53d77a53b:
                {inputs:
                   - 306221d5fbcfde1f4c4df3fc468f17c9b15f5f8380d1bc65fff01fc1504d7d63!1
                     <>
                collateral inputs:
                outputs:
                  - Value (Map [(,Map [("",2000000)]),(ee,Map [("some other coin",100)])]) addressed to
                    ScriptCredential: 61d582a9a8ac05793a48e925ab90f5becf361b7618a76574790d04a0 (no staking credential)
                mint: Value (Map [])
                fee: Value (Map [])
                mps:
                signatures:
                validity range: Interval {ivFrom = LowerBound NegInf True, ivTo = UpperBound PosInf True}
                data:
                  <>}
            Requires signatures:
            Utxo index:
              ( 306221d5fbcfde1f4c4df3fc468f17c9b15f5f8380d1bc65fff01fc1504d7d63!1
              , - Value (Map [(,Map [("",4000000)]),(ff,Map [("some coin",100)])]) addressed to
                  61d582a9a8ac05793a48e925ab90f5becf361b7618a76574790d04a0 )
            Validity range:
              (-∞ , +∞)
Slot 00002: W872cb83: Adding public key output for Value (Map [(,Map [("",2000000)]),(ff,Map [("some coin",100)])])
Slot 00002: W872cb83: Adding inputs for Value (Map [(ee,Map [("some other coin",100)])])
Slot 00002: W872cb83: No collateral inputs added
Slot 00002: W872cb83: Adding public key output for Value (Map [(,Map [("",2000000)]),(ff,Map [("some coin",100)])])
Slot 00002: W872cb83: Adding inputs for Value (Map [(,Map [("",3047)]),(ee,Map [("some other coin",100)])])
Slot 00002: W872cb83: Adding collateral inputs for Value (Map [(,Map [("",3047)])])
Slot 00002: W872cb83: Finished balancing. a1f45ccb8995c3faa1a615d0a515c694556e0146b987322f985f8fff35d6c256
Slot 00002: W872cb83: handlePendingTransactions start
Slot 00002: W872cb83: handlePendingTransactions end (irregular)
Slot 00002: W872cb83: Submitting tx: a1f45ccb8995c3faa1a615d0a515c694556e0146b987322f985f8fff35d6c256
Slot 00002: W872cb83: TxSubmit: a1f45ccb8995c3faa1a615d0a515c694556e0146b987322f985f8fff35d6c256
Slot 00002: 00000000-0000-4000-8000-000000000000 {Contract instance for wallet 872cb83b5ee40eb23bfdab1772660c822a48d491}:
  Contract instance stopped (no errors)
Slot 00002: TxnValidate a1f45ccb8995c3faa1a615d0a515c694556e0146b987322f985f8fff35d6c256
Slot 00002: SlotAdd Slot 3
Slot 00003: SlotAdd Slot 4
Slot 00004: SlotAdd Slot 5
Final balances
Wallet 872cb83b5ee40eb23bfdab1772660c822a48d491: 
    {ff, "some coin"}: 100000000
    {, ""}: 97996943
    {ee, "some other coin"}: 99999900
Script 61d582a9a8ac05793a48e925ab90f5becf361b7618a76574790d04a0: 
    {ee, "some other coin"}: 100
    {, ""}: 2000000

@VictorCMiraldo
Copy link

We are having some trouble with this new feature too. Might be worth contributing our 2cents in here.

I believe that adjustUnbalancedTx should not alter the transaction, instead, it should have been checkUnbalancedTx, and it should refuse to change the transaction in any way. The reason for this is that when a user generates a transaction from a set of constraints, the user expects the generated tx to satisfy these constraints. Take the following pseudo-plutus example:

submitTxConstraints (PaysScript (someDatum, mempty))

That will submit a transaction with no outputs, because adjustUnbalancedTx filters out outputs containing value 0.

Another one,

submitTxConstraints (PaysScript (someDatum, 1))

Now it will submit a tx, but it will alter the value to 2_000_000 lovelace; which also does not satisfy the constraint and might incur a large cognitive overhead on contract developers; now the developer has to keep track that out of the 2m lovelace in that datum, only 1 actually "belongs" to the script. I would find it better if submitTxConstraints crashed with some error stating that my tx wants to create outputs containing less than the minimum amount of ada. this would mean that its the users responsibility to ensure that that minimum value is present, but the user is sure that when submitTxConstraints succeeds, it sent a transaction that does satisfy the expected constraints.

@sjoerdvisscher
Copy link
Contributor

This issue is fixed by #229.

The filtering of outputs with a datum but with 0 value is gone.

submitTxConstraints does not automatically adjust a transaction, you have to call adjustUnbalancedTx yourself.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Something isn't working investigating we're looking into this
Projects
None yet
Development

No branches or pull requests

5 participants