IntersectMBO / plutus-apps

The Plutus application platform

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Plutus.Contract.Wallet.export ignores unBalancedTxValidityTimeRange info of UnbalancedTx

etiennejf opened this issue · comments

Summary

Function export defined in Plutus.Contract.Wallet does not update txValidRange of the transaction with unBalancedTxValidityRange before calling mkPartailTx. Script validation may therefore fail when balancing is performed using a local wallet configuration, especially when a restricted txRange is expected. To rectify this bug, export must be parameterized with SlotConfig and txValidRange must be updated as follows before the call to mkPartialTx:

let tx' = unBalancedTxTx { txValidRange = posixTimeRangeToContainedSlotRange slotConfig unBalancedTxValidityTimeRange }
    requiredSigners = fst <$> Map.toList unBalancedTxRequiredSignatories 
in
    ExportTx
        <$> mkPartialTx requiredSigners params networkId tx'
        <*> mkInputs networkId unBalancedTxUtxoIndex
        <*> mkRedeemers unBalancedTxTx

The default slotconfig should be avoided when calling export in Cardano.Wallet.LocalClient and Cardano.Wallet.RemoteClient.

Another more straight forward solution is to directly update txValidRange in mkTxConstraints, but again we need to specify the slotConfig.

This bug may also impact browser-based wallets, especially when exporting a partial tx to be balanced and signed externally.

Steps to reproduce the behavior

  1. A validator script expecting a restricted txValidityRange.
  2. Specify the corresponding off-chain code using Constraints.mustValidateIn
  3. Submit the transaction within a PAB context (e.g., via the invocation of an endpoint) using a local wallet configuration.

Actual Result

The validator script fails during balancing as txValidityRange is unspecified

Expected Result

Validator must evaluate successfully if txValidityRange is properly set.

Describe the approach you would take to fix this

See above.

A current workaround is to call mkTxConstraints and explicitly update txValidityRange of the unBalancedTx (as specified above) before calling submitUnbalancedTx.

System info

plutus-apps commit: 51da951