Closed jonathangenlambda closed 7 months ago
HI @jonathangenlambda ! The steps should be in that order:
All redeemer, scripts, datums should be added before calc_script_data_hash
. Otherwise script_data_hash will be incorrect. If you change script related witnesses after building the tx and calc_script_data_hash
your script_data_hash will be incorrect.
Hi @lisicky , thanks for your support!
I am doing the steps now in the order you specified and have switchted to build_tx. To be more specific I do this:
const txWithoutWitnesses = txBuilder.build_tx();
const txBody = txWithoutWitnesses.body();
const txId = CSL.hash_transaction(txBody);
const witnesses = CSL.TransactionWitnessSet.new();
// add wallet witness
bip32PrivateKeys.forEach((k) => {
const skey = CSL.PrivateKey.from_bech32(k.to_bech32());
const vkeyWitnesses = CSL.Vkeywitnesses.new();
const vkeyWitness = CSL.make_vkey_witness(txId, skey);
vkeyWitnesses.add(vkeyWitness);
witnesses.set_vkeys(vkeyWitnesses);
});
// NOTE: if we forget to add these, despite signing will fail submission with NoRedeemer and MissingRedeemers
const redeemers = CSL.Redeemers.new();
redeemers.add(psScriptRedeemer);
witnesses.set_redeemers(redeemers);
// create the finalized transaction with witnesses
const txFinal = CSL.Transaction.new(
txBody,
witnesses,
auxData
);
const hashTxInitial = txBody.script_data_hash();
const hashTxFinal = txFinal.body().script_data_hash();
console.log(hashTxInitial.to_hex());
console.log(hashTxFinal.to_hex());
However no luck, I get the same error:
Submitting TX failed due to error: ShelleyTxValidationError ShelleyBasedEraBabbage (ApplyTxError [UtxowFailure (AlonzoInBabbageUtxowPredFailure (PPViewHashesDontMatch (SJust (SafeHash "c1b930ae86f70cbf19e4b78b1749bf2dbbfc75be16e1455d09565990dffc63bd")) (SJust (SafeHash "1f493f11378b3808b70d06f2da7a770a05694b37bec21c276083cc33bbc6172d"))))])
In both console.log cases I get c1b930ae86f70cbf19e4b78b1749bf2dbbfc75be16e1455d09565990dffc63bd
When I tried to compute the hash myself before calc_script_data_hash, then I get a different hash 089c09bd42ee1b83e42bbdbc77a7ebd97eaead77ad5c36f56f9583ec677a6914
:
const redeemers = CSL.Redeemers.new()
redeemers.add(psScriptRedeemer);
const plutusWitnessHash = CSL.hash_script_data(redeemers, CSL.TxBuilderConstants.plutus_vasil_cost_models())
console.log(plutusWitnessHash.to_hex());
So I had another thought: I am running this stuff on my own local testnet, where I have changed the protocol parameter slotLength - but I didn't touch the cost models. Could this be the origin of this error?
Then again I am constructing and submitting other TXs such as creating a reference script and also locking assets in a UTxO at this reference script, using CSL successfully to my local testnet without these errors.
@jonathangenlambda do you add a redeemer after building the tx? Basically it is better if you add all script related witnesses (scripts, datums, redeemers) by transaction builder before you build the tx otherwise you will have headache with script_data_hash
, fee calculation, and transaction body hash. If you calculate script_data_hash
by CSL.hash_script_data you need to put list of cost models that is used in the tx. (example: if your tx spend UTXO with plutus v2, you need use cost model of plutus v2 only).
Hi @jonathangenlambda ! Do you still have the issue ?
@lisicky thanks for your reply - we are doing what you described in your previous post, that is: adding all scripts, datums and redeemers before building the TX, so after we built the TX we change nothing. We are still working on this issue.
@jonathangenlambda Could you share your the last code if it still produces PPViewHashesDontMatch ? Which CSL version do you use ?
Sorry for the delay - we are using now a different approach, so didn't pursue this issue longer.
I am trying to spend a UTxO with an InlineDatum sitting at a ReferenceScript. Effectively I want to create a new UTxO at the same ReferenceScript with the same InlineDatum, but with changed assets locked into it. However, I am running into:
Here is the code I am using to construct the TX (shortened to the essential parts):
According to https://github.com/Emurgo/cardano-serialization-lib/issues/482 I should be using
calc_script_data_hash
however when I am using it beforeadd_change_if_needed
then I getPPViewHashesDontMatch
with 2 hashes not matching:If I use it after
add_change_if_needed
then I getPPViewHashesDontMatch
with 2 hashes not matching as well asFeeTooSmallUTxO
:I have a working version of this TX construction using
cardano-api
and am doing exactly the same, so I have no idea why this fails. I honestly also have no idea why I have to callcalc_script_data_hash
, this is not necessary incardano-api
TX construction.Any help is really appreciated!