spacebudz / lucid

Lucid is a library, which allows you to create Cardano transactions and off-chain code for your Plutus contracts in JavaScript, Deno and Node.js.
https://lucid.spacebudz.io
MIT License
336 stars 133 forks source link

Wallet from seed doesn't sign transaction spending only UTXOs locked with enterprise address #216

Open infrmtcs opened 10 months ago

infrmtcs commented 10 months ago

This issue happens with wallet from seed. On signTx call, an UTXO query is made to check if any of the inputs is locked by the payment pub key hash. However, instead of querying by payment credential, the function only queries by base address (assuming that addressType is unset). Therefore the library refuses to sign the transaction even if it's a valid signer.

https://github.com/spacebudz/lucid/blob/0c8fec09e6d1da12eb01eb41783e1638dc33e525/src/lucid/lucid.ts#L501

Reproduce case:

84a700828258203de86f6adcecc045aa8f8f6f15ce8484cecb390fd5001b9d6c11ba1314ed0560008258209f66a1a7302491af89bdd7b9ad465cc7458e1673e8594b009b3e2489c7c242c1000182825839003cb26a37d8854084f09b27353018e3d1ed6313ef804c023f022528ab9e05ee95b33033a4b017718e77d7a1226e8092d0db9828754ff9b79a821a001215e2a1581cdfbdf85e9ed4506dbcecaa96efe600e863d41072027327be0ed11f6ba145744d454c441a00b71b00825839003cb26a37d8854084f09b27353018e3d1ed6313ef804c023f022528ab9e05ee95b33033a4b017718e77d7a1226e8092d0db9828754ff9b79a1a00479e7b021a0002b3b1031a019561310d818258209f66a1a7302491af89bdd7b9ad465cc7458e1673e8594b009b3e2489c7c242c10010825839003cb26a37d8854084f09b27353018e3d1ed6313ef804c023f022528ab9e05ee95b33033a4b017718e77d7a1226e8092d0db9828754ff9b79a1a00483db6111a00040d8aa0f5f6

Viewed by cardano-cli:

auxiliary scripts: null
certificates: null
collateral inputs:
- 9f66a1a7302491af89bdd7b9ad465cc7458e1673e8594b009b3e2489c7c242c1#0
era: Babbage
fee: 177073 Lovelace
inputs:
- 3de86f6adcecc045aa8f8f6f15ce8484cecb390fd5001b9d6c11ba1314ed0560#0
- 9f66a1a7302491af89bdd7b9ad465cc7458e1673e8594b009b3e2489c7c242c1#0
metadata: null
mint: null
outputs:
- address: addr_test1qq7ty63hmzz5pp8snvnn2vqcu0g76ccna7qycq3lqgjj32u7qhhftvesxwjtq9m33ema0gfzd6qf95xmnq582nlek7dquf3z5j
  address era: Shelley
  amount:
    lovelace: 1185250
    policy dfbdf85e9ed4506dbcecaa96efe600e863d41072027327be0ed11f6b:
      asset 744d454c44 (tMELD): 12000000
  datum: null
  network: Testnet
  payment credential key hash: 3cb26a37d8854084f09b27353018e3d1ed6313ef804c023f022528ab
  reference script: null
  stake reference:
    stake credential key hash: 9e05ee95b33033a4b017718e77d7a1226e8092d0db9828754ff9b79a
- address: addr_test1qq7ty63hmzz5pp8snvnn2vqcu0g76ccna7qycq3lqgjj32u7qhhftvesxwjtq9m33ema0gfzd6qf95xmnq582nlek7dquf3z5j
  address era: Shelley
  amount:
    lovelace: 4693627
  datum: null
  network: Testnet
  payment credential key hash: 3cb26a37d8854084f09b27353018e3d1ed6313ef804c023f022528ab
  reference script: null
  stake reference:
    stake credential key hash: 9e05ee95b33033a4b017718e77d7a1226e8092d0db9828754ff9b79a
reference inputs: []
required signers (payment key hashes needed for scripts): null
return collateral:
  address: addr_test1qq7ty63hmzz5pp8snvnn2vqcu0g76ccna7qycq3lqgjj32u7qhhftvesxwjtq9m33ema0gfzd6qf95xmnq582nlek7dquf3z5j
  address era: Shelley
  amount:
    lovelace: 4734390
  datum: null
  network: Testnet
  payment credential key hash: 3cb26a37d8854084f09b27353018e3d1ed6313ef804c023f022528ab
  reference script: null
  stake reference:
    stake credential key hash: 9e05ee95b33033a4b017718e77d7a1226e8092d0db9828754ff9b79a
total collateral: 265610
update proposal: null
validity range:
  lower bound: null
  upper bound: 26566961
withdrawals: null
witnesses: []

In this example on preview testnet, all UTXOs share the same payment credential. Because the library doesn't sign, error is thrown on transaction submission:

ShelleyTxValidationError ShelleyBasedEraBabbage (ApplyTxError [UtxowFailure (FromAlonzoUtxowFail (WrappedShelleyEraFailure (MissingVKeyWitnessesUTXOW (WitHashes (fromList [KeyHash \"3cb26a37d8854084f09b27353018e3d1ed6313ef804c023f022528ab\"])))))])
infrmtcs commented 10 months ago

Here is my attempt to fix this: https://github.com/spacebudz/lucid/pull/217