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

The build command calculates insufficient Plutus script cost for two certificates #1023

Open
mkoura opened this issue Jan 16, 2025 · 5 comments · May be fixed by #1028
Open

The build command calculates insufficient Plutus script cost for two certificates #1023

mkoura opened this issue Jan 16, 2025 · 5 comments · May be fixed by #1028

Comments

@mkoura
Copy link
Contributor

mkoura commented Jan 16, 2025

Description

In a situation where two certificates with Plutus script are used in single tx, the build command computes lower cost than is needed, and tx submit fails. I can observe this behavior in a test that registers Plutus stake address and delegate it to a pool in single tx.

I can build the tx using build-raw and submit it successfully.

The build command:

cardano-cli conway transaction build \
--certificate-file "test_delegate_deregister[script_file-build-plutus_v2]_ci0_wvc_addr0_stake_reg.cert" \
--certificate-script-file cardano_node_tests/tests/data/plutus/v2/stake-script.plutus \
--certificate-redeemer-file cardano_node_tests/tests/data/plutus/42.redeemer \
--certificate-file "test_delegate_deregister[script_file-build-plutus_v2]_ci0_wvc_addr0_stake_deleg.cert" \
--certificate-script-file cardano_node_tests/tests/data/plutus/v2/stake-script.plutus \
--certificate-redeemer-file cardano_node_tests/tests/data/plutus/42.redeemer \
--tx-in-collateral "33336bf4d21a09196256345cd738e301626b53db4cbdb79bb566b3185afd0185#0" \
--tx-in "33336bf4d21a09196256345cd738e301626b53db4cbdb79bb566b3185afd0185#3" \
--change-address addr_test1yp9ex2dj99plru9w8ukmplsenlxzvz0hgdy5l2c2upss5auu36w607q78j5sfp0n96l0exqn0j9vyc9qw2sqcj40zskskzmsj7 \
--witness-override 1 \
--out-file "test_delegate_deregister[script_file-build-plutus_v2]_ci0_wvc_reg_deleg_tx.body" \
--testnet-magic 42

Tx submit fails with (shortened error):

The plutus evaluation error is: CekError An error has occurred:\nThe machine terminated part way through evaluation due to overspending the budget.\nThe budget when the machine terminated was:\n({cpu: -570964\n| mem: 28})\nNegative numbers indicate the overspent budget; note that this only indicates the budget that was needed for the next step, not to run the program to completion.

The scripts cost reported by transaction build:

[{'executionUnits': {'memory': 613680, 'steps': 196655766},
  'lovelaceCost': 49589,
  'scriptHash': '9c8e9da7f81e3ca90485f32ebefc98137c8ac260a072a00c4aaf142d'},
 {'executionUnits': {'memory': 616152, 'steps': 197801730},
  'lovelaceCost': 49814,
  'scriptHash': '9c8e9da7f81e3ca90485f32ebefc98137c8ac260a072a00c4aaf142d'}]

The reported cost is the same for cardano-cli version where I can observe the issue, and for the last release where the issue was not present.

I can reproduce it with cardano-cli that has #986 merged.

Steps to Reproduce

  1. build the tx using transaction build
  2. submit the tx
  3. see the error

Additional Context

Files used to build the tx and full error message: issue_delegation_plutus.tar.gz

@CarlosLopezDeLara
Copy link
Contributor

CarlosLopezDeLara commented Jan 17, 2025

I compared 10.2.0.0 tagged version

cardano-cli 10.2.0.0 - linux-x86_64 - ghc-9.10
git rev 6385b7412f6fbe15429b505886c39f6fc842ad3a

and the version from #986

cardano-cli 10.2.0.0 - linux-x86_64 - ghc-9.10
git rev 2b860665dc9da29e09935d8eb6b6eed0ed6d09b1

The issue is reproducible.
Built the with both versions and using --calculate-plutus-script-cost, I got the exact same execution units

❯ diff tx.cost.10.2 tx.cost.2b8606 -s 
Files tx.cost.10.2 and tx.cost.2b8606 are identical
❯ cat tx.cost.10.2
[
    {
        "executionUnits": {
            "memory": 618612,
            "steps": 198565008
        },
        "lovelaceCost": 50011,
        "scriptHash": "9c8e9da7f81e3ca90485f32ebefc98137c8ac260a072a00c4aaf142d"
    },
    {
        "executionUnits": {
            "memory": 621084,
            "steps": 199710972
        },
        "lovelaceCost": 50236,
        "scriptHash": "9c8e9da7f81e3ca90485f32ebefc98137c8ac260a072a00c4aaf142d"
    }
]

The script would run twice in this transaction, therefore 2 budgets. The first one slightly cheaper. Not sure about the reason.

However, when creating the transaction bodies., there is a difference in the calculated execution units. After using debug transaction view, looks like 10.2.0.0 in reality uses the greater exec units calculation and 2b8606 uses the smaller ones. (not enough)

❯ cat view.tx.body.10.2 | grep -A2 "execution units"
                "execution units": {
                    "memory": 621084,
                    "steps": 199710972 
--
                "execution units": {
                    "memory": 621084,
                    "steps": 199710972

❯ cat view.tx.body.2b8606 | grep -A2 "execution units"
                "execution units": {
                    "memory": 618612,
                    "steps": 198565008
--
                "execution units": {
                    "memory": 618612,
                    "steps": 198565008

@carbolymer
Copy link
Contributor

carbolymer commented Jan 17, 2025

The certificates are missing in the attached files and reproduction steps are incomplete

@CarlosLopezDeLara
Copy link
Contributor

CarlosLopezDeLara commented Jan 18, 2025

The certificates are missing in the attached files and reproduction steps are incomplete

Yes noticed that, so I generated the certificates myself with:

cardano-cli conway stake-address registration-certificate --stake-script-file stake-script.plutus --key-reg-deposit-amt 2000000 --out-file keyreg.cert

cardano-cli conway stake-address stake-delegation-certificate --stake-script-file stake-script.plutus --cold-verification-key-file cold1.vkey --out-file deleg.cert

followed by

cardano-cli conway transaction build \
--certificate-file "keyreg.cert" \
--certificate-script-file stake-script.plutus \
--certificate-redeemer-file 42.redeemer \
--certificate-file "deleg.cert" \
--certificate-script-file stake-script.plutus \
--certificate-redeemer-file 42.redeemer \
--tx-in-collateral "d417089eaa75a53ac614d244471a34e9caf4bd132a464dd1997af0c874e74983#0" \
--tx-in "d417089eaa75a53ac614d244471a34e9caf4bd132a464dd1997af0c874e74983#0" \ 
--change-address $(cat ../../example/utxo-keys/payment1.addr) \
--witness-override 1 \
--out-file "tx.body"

@carbolymer
Copy link
Contributor

@carbolymer
Copy link
Contributor

@CarlosLopezDeLara thanks for the extra information, that's helpful. Thanks to it, I'm able to reproduce the error in:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
3 participants