Emurgo / cardano-serialization-lib

This is a library, written in Rust, for serialization & deserialization of data structures used in Cardano's Haskell implementation of Alonzo along with useful utility functions.
Other
231 stars 125 forks source link

PPViewHashesDontMatch when attempting to receive an NFT locked to a smart contract. #601

Closed yoh1019 closed 1 year ago

yoh1019 commented 1 year ago

I tried to send a transaction that receives an NFT locked to a smart contract and was unable to send it with the following error failed to submit tx: AxiosError: Request failed with status code 400. error details: "transaction submit error ShelleyTxValidationError ShelleyBasedEraBabbage (ApplyTxError [UtxowFailure (FromAlonzoUtxowFail (PPViewHashesDontMatch (SJust (SafeHash \"44578482edc5ccb278921278163278a0184cdeb92a3a68bcbf4d5a3003622b61\")) (SJust (SafeHash \"590ee4faabbcc7c5a1571e282d185a6cd266c0c670a0dcfb51c2696237704261\"))))])"

After checking, I realized that the cost_model in ProtocolParameter is incorrect. Therefore, we obtained the latest ProtocolParameter from blockfrost's api and used it.

Before fix

  const costModelsAll = cardanoWasm.TxBuilderConstants.plutus_vasil_cost_models();  
  const costModels = cardanoWasm.Costmdls.new();
  costModels.insert(
  cardanoWasm.Language.new_plutus_v1(),
  costModelsAll.get(cardanoWasm.Language.new_plutus_v1())  
);`

After fix

use PlutusV1 value obtained from blockfrost

 const costModelValue = [205665, 812, 1, 1, 1000, 571, 0, 1, 1000, 24177, 4, 1, 1000, 32,
        117366, 10475, 4, 23000, 100, 23000, 100, 23000, 100, 23000, 100, 23000, 100,
        23000, 100, 100, 100, 23000, 100, 19537, 32, 175354, 32, 46417, 4, 221973, 511,
        0, 1, 89141, 32, 497525, 14068, 4, 2, 196500, 453240, 220, 0, 1, 1, 1000, 28662,
        4, 2, 245000, 216773, 62, 1, 1060367, 12586, 1, 208512, 421, 1, 187000, 1000,
        52998, 1, 80436, 32, 43249, 32, 1000, 32, 80556, 1, 57667, 4, 1000, 10, 197145,
        156, 1, 197145, 156, 1, 204924, 473, 1, 208896, 511, 1, 52467, 32, 64832, 32,
        65493, 32, 22558, 32, 16563, 32, 76511, 32, 196500, 453240, 220, 0, 1, 1, 69522,
        11687, 0, 1, 60091, 32, 196500, 453240, 220, 0, 1, 1, 196500, 453240, 220, 0, 1,
        1, 806990, 30482, 4, 1927926, 82523, 4, 265318, 0, 4, 0, 85931, 32, 205665, 812,
        1, 1, 41182, 32, 212342, 32, 31220, 32, 32696, 32, 43357, 32, 32247, 32, 38314,
        32, 57996947, 18975, 10];

  const costModel = cardanoWasm.CostModel.new();
  costModelValue.forEach((x, i) => costModel.set(i, cardanoWasm.Int.new_i32(x)));

  const costModels = cardanoWasm.Costmdls.new();
  costModels.insert(
      cardanoWasm.Language.new_plutus_v1(),
       costModel
   );

With this fix, transactions are now sent correctly. I always get an error when I use the library CostModel as I did before the fix. Is my fix correct?

lisicky commented 1 year ago

Thanks @yoh1019 ! Fix on the way