Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: update hash script data #351

Merged

Conversation

hadelive
Copy link
Contributor

No description provided.

@rooooooooob
Copy link
Contributor

Is there a source on the change? Is this the case for old scripts?

@rooooooooob
Copy link
Contributor

I guess this is related to the change in redeemer structure from always being a flat array to also being a map, does the node assume if it's empty it uses the map structure then? The cddl seems to allow it being an array still (at least until the next era after conway). What happens if in the tx you use the empty legacy flat map structure?

redeemer_key = [ tag: redeemer_tag, index: uint ]

redeemer_val = [ data: plutus_data, ex_units: ex_units ]

legacy_redeemer = [ tag: redeemer_tag, index: uint, data: plutus_data, ex_units: ex_units ]

; Flat Array support is included for backwards compatibility and will be removed in the next era.
; It is recommended for tools to adopt using a Map instead of Array going forward.
redeemers =
  ; @name LegacyFlatFormat @doc This format will be deprecated in the next era
  [ + legacy_redeemer ] /
  ; @name MapFormat @doc New map format. Use this when possibe.
  { + redeemer_key => redeemer_val }

@hadelive
Copy link
Contributor Author

hadelive commented Aug 29, 2024

Currently, I encounter a PPViewHashesDontMatch issue when submitting the transaction with asHash datum in Preprod.
Here is part of the discussion.
https://discord.com/channels/946071061567529010/1028315283649220628/1278396541765423175

@rooooooooob
Copy link
Contributor

@hadelive I can't seem to access that channel. You don't have access to any text channels, or there are none in this server.

My point was does this mismatch always happen? Does it matter if your datums/redeemers are encoded differently in the tx? You can have an empty list be either one of those (empty list or empty map), or are they just missing entirely? Our API for the script data hash calc requires a list for redeemers (unlike datums). In the previous cbor spec for the data hash it used to say how to handle this exactly when there were none, as the old comments said. Is there anywhere we can refer to for the new behavior?

Does this apply to spending old (v1/v2) scripts?

@hadelive
Copy link
Contributor Author

@solidsnakedev
Copy link

here's one example

{
  "body": {
    "inputs": [
      {
        "transaction_id": "8e3d9138777c56c6e3fc1ce9083b13f91f5ce45da8ad7e80d4215b524af2bf8a",
        "index": 1
      }
    ],
    "outputs": [
      {
        "AlonzoFormatTxOut": {
          "address": "addr_test1qz0ugv82ruadcg8whwqnkfjfapwfxn49hsfa0dlmu2eyu5zsvjm8zc6dzn9c64p7w8wcadph53l0k3askg5g9pnvggxsvy935c",
          "amount": {
            "coin": 1327480,
            "multiasset": {
              "ef6ed47a6917a3cbbeb46561e8853da969343794d66128598a34af2c": {
                "4275726e61626c65546f6b656e32": 1
              }
            }
          },
          "datum_hash": "923918e403bf43c34b4ef6b48eb2ee04babed17320d8d1b9ff9ad086e86f44ec"
        }
      },
      {
        "AlonzoFormatTxOut": {
          "address": "addr_test1qz0ugv82ruadcg8whwqnkfjfapwfxn49hsfa0dlmu2eyu5zsvjm8zc6dzn9c64p7w8wcadph53l0k3askg5g9pnvggxsvy935c",
          "amount": {
            "coin": 6193203350,
            "multiasset": {
              "22691d3d969ecf5802226290c2fb98e2bc08522d5b726c1f5f400105": {
                "54657374": 21
              },
              "cac67dd80f706e084b2aac605288b2ff793475ea43b2313e1ed384ab": {
                "54657374": 13,
                "4275726e61626c65546f6b656e506c75747573": 1,
                "accbfb633f637e3bb1abee40c9539d1effd742cd2716b3b1db9de3aaf3f37794": 1
              },
              "ef6ed47a6917a3cbbeb46561e8853da969343794d66128598a34af2c": {
                "4275726e61626c65546f6b656e32": 3
              }
            }
          },
          "datum_hash": null
        }
      }
    ],
    "fee": 202461,
    "ttl": null,
    "certs": null,
    "withdrawals": null,
    "auxiliary_data_hash": null,
    "validity_interval_start": null,
    "mint": {
      "ef6ed47a6917a3cbbeb46561e8853da969343794d66128598a34af2c": {
        "4275726e61626c65546f6b656e32": 3
      }
    },
    "script_data_hash": "2f50ea2546f8ce020ca45bfcf2abeb02ff18af2283466f888ae489184b3d2d39",
    "collateral_inputs": [
      {
        "transaction_id": "8e3d9138777c56c6e3fc1ce9083b13f91f5ce45da8ad7e80d4215b524af2bf8a",
        "index": 1
      }
    ],
    "required_signers": null,
    "network_id": null,
    "collateral_return": {
      "AlonzoFormatTxOut": {
        "address": "addr_test1qz0ugv82ruadcg8whwqnkfjfapwfxn49hsfa0dlmu2eyu5zsvjm8zc6dzn9c64p7w8wcadph53l0k3askg5g9pnvggxsvy935c",
        "amount": {
          "coin": 6189733291,
          "multiasset": {
            "22691d3d969ecf5802226290c2fb98e2bc08522d5b726c1f5f400105": {
              "54657374": 21
            },
            "cac67dd80f706e084b2aac605288b2ff793475ea43b2313e1ed384ab": {
              "54657374": 13,
              "4275726e61626c65546f6b656e506c75747573": 1,
              "accbfb633f637e3bb1abee40c9539d1effd742cd2716b3b1db9de3aaf3f37794": 1
            },
            "ef6ed47a6917a3cbbeb46561e8853da969343794d66128598a34af2c": {
              "4275726e61626c65546f6b656e32": 1
            }
          }
        },
        "datum_hash": null
      }
    },
    "total_collateral": 5000000,
    "reference_inputs": null,
    "voting_procedures": null,
    "proposal_procedures": null,
    "current_treasury_value": null,
    "donation": null
  },
  "witness_set": {
    "vkeywitnesses": null,
    "native_scripts": [
      {
        "ScriptAll": {
          "native_scripts": [
            {
              "ScriptPubkey": {
                "ed25519_key_hash": "9fc430ea1f3adc20eebb813b2649e85c934ea5bc13d7b7fbe2b24e50"
              }
            }
          ]
        }
      }
    ],
    "bootstrap_witnesses": null,
    "plutus_v1_scripts": null,
    "plutus_datums": [
      {
        "constructor": 0,
        "fields": []
      }
    ],
    "redeemers": null,
    "plutus_v2_scripts": null,
    "plutus_v3_scripts": null
  },
  "is_valid": true,
  "auxiliary_data": null
}

cbor

84a800818258208e3d9138777c56c6e3fc1ce9083b13f91f5ce45da8ad7e80d4215b524af2bf8a010182835839009fc430ea1f3adc20eebb813b2649e85c934ea5bc13d7b7fbe2b24e505064b671634d14cb8d543e71dd8eb437a47efb47b0b22882866c420d821a00144178a1581cef6ed47a6917a3cbbeb46561e8853da969343794d66128598a34af2ca14e4275726e61626c65546f6b656e32015820923918e403bf43c34b4ef6b48eb2ee04babed17320d8d1b9ff9ad086e86f44ec825839009fc430ea1f3adc20eebb813b2649e85c934ea5bc13d7b7fbe2b24e505064b671634d14cb8d543e71dd8eb437a47efb47b0b22882866c420d821b000000017124c896a3581c22691d3d969ecf5802226290c2fb98e2bc08522d5b726c1f5f400105a1445465737415581ccac67dd80f706e084b2aac605288b2ff793475ea43b2313e1ed384aba3534275726e61626c65546f6b656e506c757475730144546573740d5820accbfb633f637e3bb1abee40c9539d1effd742cd2716b3b1db9de3aaf3f3779401581cef6ed47a6917a3cbbeb46561e8853da969343794d66128598a34af2ca14e4275726e61626c65546f6b656e3203021a000316dd09a1581cef6ed47a6917a3cbbeb46561e8853da969343794d66128598a34af2ca14e4275726e61626c65546f6b656e32030b58202f50ea2546f8ce020ca45bfcf2abeb02ff18af2283466f888ae489184b3d2d390d818258208e3d9138777c56c6e3fc1ce9083b13f91f5ce45da8ad7e80d4215b524af2bf8a0110825839009fc430ea1f3adc20eebb813b2649e85c934ea5bc13d7b7fbe2b24e505064b671634d14cb8d543e71dd8eb437a47efb47b0b22882866c420d821b0000000170efd5aba3581c22691d3d969ecf5802226290c2fb98e2bc08522d5b726c1f5f400105a1445465737415581ccac67dd80f706e084b2aac605288b2ff793475ea43b2313e1ed384aba3534275726e61626c65546f6b656e506c757475730144546573740d5820accbfb633f637e3bb1abee40c9539d1effd742cd2716b3b1db9de3aaf3f3779401581cef6ed47a6917a3cbbeb46561e8853da969343794d66128598a34af2ca14e4275726e61626c65546f6b656e3201111a004c4b40a201818201818200581c9fc430ea1f3adc20eebb813b2649e85c934ea5bc13d7b7fbe2b24e500481d87980f5f6

The error we get when paying to an address with datumhash

TxSubmitError: Error: {\"contents\":{\"contents\":{\"contents\":{\"era\":\"ShelleyBasedEraConway\",\"error\":[\"ConwayUtxowFailure (PPViewHashesDontMatch (SJust (SafeHash \"2f50ea2546f8ce020ca45bfcf2abeb02ff18af2283466f888ae489184b3d2d39\")) (SJust (SafeHash \"244926529564c04ffdea89005076a6b6aac5e4a2f38182cd48bfbc734b3be296\")))\",\"ConwayUtxowFailure (UtxoFailure (ValueNotConservedUTxO (MaryValue (Coin 0) (MultiAsset (fromList [(PolicyID {policyID = ScriptHash \"ef6ed47a6917a3cbbeb46561e8853da969343794d66128598a34af2c\"},fromList [(\"4275726e61626c65546f6b656e32\",3)])]))) (MaryValue (Coin 6194733291) (MultiAsset (fromList [(PolicyID {policyID = ScriptHash \"22691d3d969ecf5802226290c2fb98e2bc08522d5b726c1f5f400105\"},fromList [(\"54657374\",21)]),(PolicyID {policyID = ScriptHash \"cac67dd80f706e084b2aac605288b2ff793475ea43b2313e1ed384ab\"},fromList [(\"4275726e61626c65546f6b656e506c75747573\",1),(\"54657374\",13),(\"accbfb633f637e3bb1abee40c9539d1effd742cd2716b3b1db9de3aaf3f37794\",1)]),(PolicyID {policyID = ScriptHash \"ef6ed47a6917a3cbbeb46561e8853da969343794d66128598a34af2c\"},fromList [(\"4275726e61626c65546f6b656e32\",4)])])))))\",\"ConwayUtxowFailure (UtxoFailure (BadInputsUTxO (fromList [TxIn (TxId {unTxId = SafeHash \"8e3d9138777c56c6e3fc1ce9083b13f91f5ce45da8ad7e80d4215b524af2bf8a\"}) (TxIx {unTxIx = 1})])))\"],\"kind\":\"ShelleyTxValidationError\"},\"tag\":\"TxValidationErrorInCardanoMode\"},\"tag\":\"TxCmdTxSubmitValidationError\"},\"tag\":\"TxSubmitFail\"}

@hadelive
Copy link
Contributor Author

@rooooooooob btw, could you check the WASM output? It doesn't reflect the changes made in the Rust code.

@oskin1
Copy link
Contributor

oskin1 commented Sep 1, 2024

+1 for this patch, it fixed ConwayUtxowFailure PPViewHashesDontMatch for us.

Copy link
Contributor

@rooooooooob rooooooooob left a comment

Choose a reason for hiding this comment

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

Looks like there's some clarification here: IntersectMBO/cardano-ledger#4554

;     [ A0 | datums | A0 ]
;     corresponding to a CBOR empty map and an empty map for language view.
;     This empty redeeemer case has changed from the previous eras, since default
;     representation for redeemers has been changed to a map. Also whenever redeemers are
;     supplied either as a map or as an array they must contain at least one element,
;     therefore there is no way to override this behavior by providing a custom
;     representation for empty redeemers.

so it looks like which Redeemers variant is used will not be an issue here as you can't provide one yourself that is empty

@rooooooooob
Copy link
Contributor

could you check the WASM output? It doesn't reflect the changes made in the Rust code.

I'm not sure what you mean. For hash_script_data()? Did you re-run the wasm build scripts? The WASM code directly calls the rust code.

@hadelive
Copy link
Contributor Author

hadelive commented Sep 2, 2024

I run npm run js:publish-nodejs:prod to publish our fork.
Could you give me your discord handle?

@hadelive
Copy link
Contributor Author

hadelive commented Sep 2, 2024

I'm not sure what you mean. For hash_script_data()? Did you re-run the wasm build scripts? The WASM code directly calls the rust code.

Yes, it's quite strange. I also tried using set_script_data_hash, but the hash wasn't updated

@solidsnakedev
Copy link

solidsnakedev commented Sep 2, 2024

could you check the WASM output? It doesn't reflect the changes made in the Rust code.

I'm not sure what you mean. For hash_script_data()? Did you re-run the wasm build scripts? The WASM code directly calls the rust code.

The wasm library doesn’t work as the rust library , we tried publishing as npm package but it doesn’t work

@rooooooooob
Copy link
Contributor

I just set up a local WASM project with my locally built CML as a dependency and using this PR's changes I was able to get the new hash from WASM.

npm run js:publish-browser:prod was what I used to build it for WASM.

This was directly calling calc_script_data_hash(). The TX builder shouldn't be any different though since that is a direct API over the rust code too. All our WASM code is usually just 1-liners to call the rust one, sometimes with some conversion when the types need it (lots of .into()s/.clone()s/.map()s)

Could you give me your discord handle?

rooooooooob_

I'm going to merge this PR.

@rooooooooob rooooooooob merged commit 8805b20 into dcSpark:develop Sep 3, 2024
1 check passed
@hadelive hadelive deleted the update-hash-script-data branch September 3, 2024 06:18
@hadelive
Copy link
Contributor Author

hadelive commented Sep 3, 2024

rooooooooob_

thanks, friend request sent.

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.

4 participants