Skip to content

Fail on collateral without Plutus script instead of dropping collateral - #1274

Open
palas wants to merge 2 commits into
masterfrom
1261-post-merge-reviews
Open

Fail on collateral without Plutus script instead of dropping collateral#1274
palas wants to merge 2 commits into
masterfrom
1261-post-merge-reviews

Conversation

@palas

@palas palas commented Jul 31, 2026

Copy link
Copy Markdown
Contributor

Context

This is a follow-up PR to address the following two reviews:

How to trust this PR

Look at the two commits independently:

  • The first commit only changes the behaviour in case of collateral provided but not Plutus script to a failure.
  • The second commit should be a pure refactoring, moved code.

Checklist

  • Commit sequence broadly makes sense and commits have useful messages
  • New tests are added if needed and existing tests are updated. See Running tests for more details
  • Self-reviewed the diff
  • Changelog fragment added in .changes/

@palas palas self-assigned this Jul 31, 2026
Copilot AI review requested due to automatic review settings July 31, 2026 01:26

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR changes transaction balancing to fail (rather than silently normalizing) when collateral inputs are provided for a transaction that has no Plutus script witnesses, aligning behavior with ledger semantics and avoiding surprising collateral stripping.

Changes:

  • Introduces a new CollateralWithoutPlutusScripts error and enforces it in both makeTransactionBodyAutoBalance and estimateBalancedTxBody (traditional + experimental).
  • Adds/updates golden coverage for the new error message and adds targeted regression tests for the new failure behavior and related collateral scenarios.
  • Refactors collateral-related tests/utilities into dedicated test modules.

Reviewed changes

Copilot reviewed 12 out of 12 changed files in this pull request and generated no comments.

Show a summary per file
File Description
cardano-api/src/Cardano/Api/Tx/Internal/Fee.hs Adds checkCollateralOnlyWithPlutusScripts and the new CollateralWithoutPlutusScripts constructor + error message; balancing now fails instead of dropping collateral.
cardano-api/src/Cardano/Api/Experimental/Tx/Internal/Fee.hs Applies the same collateral-without-Plutus check to experimental balancing/estimation paths.
cardano-api/test/cardano-api-golden/Test/Golden/ErrorsSpec.hs Registers the new TxBodyErrorCollateralWithoutPlutusScripts golden test case.
cardano-api/test/cardano-api-golden/files/errors/Cardano.Api.Tx.Internal.Fee.TxBodyErrorAutoBalance/TxBodyErrorCollateralWithoutPlutusScripts.txt Adds the golden error-message output for the new collateral error.
cardano-api/test/cardano-api-test/Test/Cardano/Api/Transaction/Collateral.hs Adds traditional-API regression tests asserting failure on collateral-without-Plutus and related collateral behaviors.
cardano-api/test/cardano-api-test/Test/Cardano/Api/Transaction/Utils.hs Extracts shared transaction test utilities from Autobalance into a reusable module.
cardano-api/test/cardano-api-test/Test/Cardano/Api/Transaction/Autobalance.hs Removes collateral-focused tests/utilities moved into dedicated modules.
cardano-api/test/cardano-api-test/Test/Cardano/Api/Experimental/Collateral.hs Adds experimental-API regression tests mirroring the new failure semantics and collateral behaviors.
cardano-api/test/cardano-api-test/Test/Cardano/Api/Experimental/Fee.hs Removes collateral-focused tests now covered by Experimental.Collateral.
cardano-api/test/cardano-api-test/cardano-api-test.hs Wires new collateral test modules into the test runner.
cardano-api/cardano-api.cabal Registers new test modules (Transaction.Collateral, Transaction.Utils, Experimental.Collateral) in the test-suite stanza.
.changes/20260730_cardano_api_collateral_without_plutus_fails.yml Adds a breaking-change changelog fragment describing the behavior/API change.

palas added 2 commits July 31, 2026 03:43
The ledger requires collateral only for transactions that run Plutus
scripts. Since #1265, makeTransactionBodyAutoBalance and
estimateBalancedTxBody (traditional and experimental API) silently
remove the collateral inputs from transactions without Plutus scripts.

Silently dropping parts of the provided transaction is surprising, and
collateral inputs on a transaction without Plutus scripts are most
likely a mistake, so fail with the new CollateralWithoutPlutusScripts
error instead of removing them. The error message points at the fix:
remove the collateral inputs; a transaction that should become invalid
when some UTxO is spent can use a reference input for that purpose.

Requested by @Jimbo4350 in:
#1265 (comment)
Move the collateral tests out of Test.Cardano.Api.Transaction.Autobalance
and Test.Cardano.Api.Experimental.Fee into new modules, split by API
flavor: Test.Cardano.Api.Transaction.Collateral for the traditional API
and Test.Cardano.Api.Experimental.Collateral for the experimental API.
The utilities shared by the two traditional-API test modules move to
Test.Cardano.Api.Transaction.Utils. The tests themselves are unchanged.

Suggested by @carbolymer in:
#1265 (review)
@palas
palas force-pushed the 1261-post-merge-reviews branch from 83c813c to 934e3fc Compare July 31, 2026 02:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants