Open mkoura opened 1 month ago
@CarlosLopezDeLara and I tried the oldest release version of cardano-cli
we easily have access to, it's 8.21 from April 2024, and indeed the error message was better:
Command failed: transaction build-raw Error: Transaction validaton error: Negative quantity (-1) in transaction output: TxOutInAnyEra ConwayEra (TxOut (AddressInEra (ShelleyAddressInEra ShelleyBasedEraConway) (ShelleyAddress Testnet (KeyHashObj (KeyHash "12602a07263315f2f20179fe2baee5b4a8dc4c5a56511d37d033f12e")) StakeRefNull)) (TxOutValueShelleyBased ShelleyBasedEraConway (MaryValue (Coin (-1)) (MultiAsset (fromList [])))) TxOutDatumNone ReferenceScriptNone)
At this time, we were using cardano-api
8.42.0.0.
Alright, here's how it was working in 8.21:
build-raw
was calling API's createAndValidateTransactionBody
createAndValidateTransactionBody
was calling makeShelleyTransactionBody
, that calls validateTxBodyContent
validateTxBodyContent
is doing the positive verification by calling validateTxOuts
.Now, the situation is as follows:
build-raw
calls API's createTransactionBody
.createTransactionBody
doesn't do validation of transaction outputs.And actually @palas caught the issue: https://github.com/IntersectMBO/cardano-cli/pull/853#discussion_r1746086547 :upside_down_face:
So this shows that this issue started appearing in cardano-cli
9.4.0.0
https://github.com/IntersectMBO/cardano-cli/commits/smelc/forbid-negative-transaction-output/ shows a possible solution:
ShelleyBasedEra era
witness to parseTxOutAnyEra
parseTxOutAnyEra
, do some validation (here) by calling validateTxOuts from APIThe problem with that is validateTxOuts
and friends require the TxOut _ _
value to be available already. That's because validateTxOuts
can return errors like TxBodyOutputNegative that print the entire TxOut
when being rendered.
I think requiring the entire TxOut
to be there already when raising error is bad practice, because you aren't supposed to have the big thing ready when validating the small thing. So one way forward would be to change validateTxOuts
to only operate on the things they actually require, so that we can call them during parseTxOutAnyEra
.
[edit] Or directly parse a TxOutValue (even better?)
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.
Description
When building a tx with negative value in txout, we used to have a user friendly error message like "Negative quantity..." returned by
cardano-cli
. Now (in cli budled with node 9.2.0) we get a ledger exception likeSteps to Reproduce