IntersectMBO / cardano-api

Cardano API
Apache License 2.0
24 stars 23 forks source link

[BUG] - makeTransactionBodyAutoBalance underestimates execution units when the change has native tokens #302

Closed fallen-icarus closed 4 months ago

fallen-icarus commented 1 year ago

Internal/External External

Area Other cardano-cli transaction build

This issue involves makeTransactionBodyAutoBalance found in cardano-api which is why I am opening the issue here.

Summary This is a duplicate of this bug submitted to the cardano-node repo. The TLDR is that whenever plutus scripts are used in a transaction where the change output contains native tokens, the makeTransactionBodyAutoBalance function will underestimate the execution units for the scripts present.

I believe the issue is that when makeTransactionBodyAutoBalance creates the first intermediate transaction here to submit for execution unit estimations, it only includes a dummy value of lovelace for the change output in the temporary transaction. The native tokens that will ultimately be present in the change output are simply missing from this intermediate transaction - they are not present anywhere in the outputs. This results in a transaction that is smaller in size than it ultimately will be once the native tokens are added to the change output. Currently, makeTransactionBodyAutoBalance only adds the native tokens for the second intermediate transaction here. This has now changed the overall size of the transaction which means the previously calculated script execution budgets are inaccurate. The first intermediate transaction also needs to include any native tokens that will go to the change output in order to better reflect the ultimate size of the transaction.

Steps to reproduce Steps to reproduce the behavior:

  1. Create a UTxO with native assets locked at a plutus script address.
  2. Spend the above UTxO and have cardano-cli transaction build automatically calculate the change output which should contain the native asset.

Expected behavior cardano-cli transaction build should properly balance the transaction and properly estimate the necessary script execution budgets.

System info (please complete the following information):

github-actions[bot] commented 11 months ago

This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 120 days.

github-actions[bot] commented 8 months ago

This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 120 days.

github-actions[bot] commented 4 months ago

This issue was closed because it has been stalled for 120 days with no activity. Remove stale label or comment or this will be closed in 60 days.