Transaction builders accept duplicate TxIns with differing witnesses, producing transactions rejected with ExtraRedeemers
Maintainers usually reply within 2 days
@carbolymer is already working on this.
Since Sep 1, 2026.
Assessment
This issue has not been assessed yet.
Description
Problem
All three transaction builders accept an input list that repeats the same TxIn with two different witnesses, and silently build a transaction the ledger can never accept:
createCompatibleTx(Cardano.Api.Compatible.Tx,witnessableTxIns)- the experimental builder (
Cardano.Api.Experimental.Tx.Internal.BodyContent.New,extractWitnessableTxIns) - the deprecated legacy builder (
Cardano.Api.Tx.Internal.Body,extractWitnessableTxIns)
All three nub the whole (TxIn, witness) pair, so two entries that share a TxIn but differ in witness both survive.
The redeemer pointer machinery then assigns consecutive indices by list position, while the transaction body stores inputs as a Set, which collapses the duplicate to a single slot.
Every spending redeemer after the duplicate points one slot too far.
Impact
This is reachable from cardano-cli today.
--tx-in TXID#0 --tx-in-script-file a.plutus ... --tx-in TXID#0 --tx-in-script-file b.plutus passes the parser, and nothing between optparse and the builders validates uniqueness.
Collateral inputs, by contrast, are already deduplicated with nubOrd in the same code path.
The observable outcome depends on the command:
transaction buildandbuild-estimatefail client side, during execution-unit evaluation, withScriptErrorRedeemerPointsToUnknownScriptHashwrapped in aTxBodyScriptExecutionError.transaction build-rawand the compatible builder serialise the transaction without complaint; it is then rejected at submission withExtraRedeemers(UTXOW, phase 1).- One edge case validates: when the duplicated
TxIncarries one script witness and one key placeholder and sorts last among the distinct inputs, the cardinalities line up, the transaction is accepted, and the other supplied witness is silently ignored. The index-set equality check guarantees the surviving redeemer is the correct one, so a redeemer can never execute against the wrong script.
This is a usability bug: confusing failures, or a silently ignored witness. Funds are not at risk.
Proposed fix
Two options, in order of preference:
- Make duplicates unrepresentable: key the inputs by
TxInin an insertion-ordered map (OMap), the wayTxCertificatesandTxProposalProceduresalready work.
Spending inputs are the only witnessable category still passed around as a plain association list.
Rejecting a duplicate with a different witness then happens at map construction, which is howmkTxVotingProceduresalready treats a duplicate voter ("This would cause ignoring some of the votes"). - Keep the list and validate before constructing the body: add an error constructor per builder error type (for example
CompatibleTxDuplicateTxIn TxIninCompatibleTxError), plus analogous constructors for the experimental and legacy builders.
Either way:
- consider deduplicating or validating at the cardano-cli layer too, mirroring the existing
nubOrdcollateral handling - extend the redeemer pointer property suite (
Test.Cardano.Api.Transaction.Body.Plutus.RedeemerIndex) with duplicate-input cases - pin
compareWitnesseswith a property while in there: the #1288 review flagged that theWitTxCertcomparator returnsLTfor every pair, which degenerates to insertion order under a stable sort. Insertion order happens to be what certificates need, but that should be a tested invariant rather than a coincidence.
Related PRs and issues
Positional indexing has broken once per witnessable category; this issue covers the last one:
- #1288 fixed proposal pointers (indexed by
Ordinstead ofOSetinsertion order) and unwitnessed certificate slots in the legacy builder, and added the ledger-oracle property suite - #1140 (fixes #1138) unified certificate indexing after unwitnessed certificates were mishandled during deduplication
- #1136 fixed
mapScriptWitnessesCertificatessilently dropping key-witnessed certificates - #798: transaction bodies with more than one script witness per purpose failed to validate (cardano-api 10.12)
- #697 centralised the indexing logic that all three builders now share
- IntersectMBO/cardano-cli#297:
MissingRedeemerson Plutus stake delegation, a user-facing symptom from the same pointer machinery - IntersectMBO/cardano-cli#861 added redeemer-to-input mapping to
transaction view, because pointers are opaque to users
Context
Split out of #1282 so the fix can cover the experimental, legacy and compatible APIs together.
Review comment: https://github.com/IntersectMBO/cardano-api/pull/1282#discussion_r3780453761
- Dominant language
- Haskell
- Stars
- 41
- Forks
- 33
- Avg merge
- 3d 3h
- Merged PRs (30d)
- 15
Getting set up
- No Dockerfile or Docker Compose file
- Has a pull request template
- Read the contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from IntersectMBO/cardano-api
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
IntersectMBO/cardano-api#1434 ·
Maintainers usually reply within 2 days
-
`Prelude.maximum: empty list` crash in fee estimation for empty `RequireAnyOf` (`{"type": "any", "scripts": []}`) scriptsPossibly taken @Jimbo4350 claimed this 8 days ago. Openbug
Difficulty 2/5 1-3 hours Newbie friendliness 62/100
IntersectMBO/cardano-api#1424 ·
Maintainers usually reply within 2 days
-
Difficulty 4/5 3-5 days Newbie friendliness 53/100
IntersectMBO/cardano-api#1431 ·
Maintainers usually reply within 2 days
-
type: enhancement
Difficulty 4/5 3-5 days Newbie friendliness 45/100
IntersectMBO/cardano-api#1423 ·
Maintainers usually reply within 2 days
-
Add a dedicated transaction viewing type to the experimental APIPossibly taken @palas claimed this 21 days ago. Opentype: enhancement
IntersectMBO/cardano-api#1416 · 1 assignee ·
Maintainers usually reply within 2 days
All issues in IntersectMBO/cardano-api
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 74/100
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
haskell/bytestring#730 · 1 comment ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 84/100
seal-harness/seal-harness#399 ·
Maintainers usually reply within 1 day
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 65/100
fmidue/codeworld-tasks#124 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 62/100
reflex-frp/reflex#563 ·