cardano-scaling / hydra

Implementation of the Hydra Head protocol
https://hydra.family/head-protocol/
Apache License 2.0
276 stars 84 forks source link

Blueprint field in the commit endpoint drops withdraw redeemers #1643

Open Micrograx opened 1 week ago

Micrograx commented 1 week ago

Context & versions

Hydra-node: 0.19.0 Cardano-node: 9.1.0 Cardano-cli 9.2.1.0

Steps to reproduce

  1. Init a hydra head
  2. Build a transaction that runs a withdraw validator
  3. Build the request json file
  4. Send the request to the commit endpoint

Actual behavior

The response transaction will fail to submit because the withdraw redeemer will be missing from the tx redeemers.

Expected behavior

The response transaction should maintain the withdraw redeemer in the list of redeemers

Workaround

Adding the redeemer manually and adjusting the execution units of the hydra redeemer, then recalculating the script integrity hash in the tx body (Field 11. You can easily get the correct value by trying to submit the edited transaction and copying it from the error message) and signing the tx again allows you to submit the tx and proceed with the commit procedure.

Details:

Example request json:

{
  "blueprintTx": {
    "type": "Unwitnessed Tx ConwayEra",
    "description": "Ledger Cddl Format",
    "cborHex": "84a600d90102818258200b95bec9255a426435e6aa7ff9749d76ee4c6d815acb47f10142db889b0edce4030dd90102818258200b95bec9255a426435e6aa7ff9749d76ee4c6d815acb47f10142db889b0edce4030180020005a1581df039c520d0627aafa728f7e4dd10142b77c257813c36f57e2cb88f72a5000b58208673547ffac99f8abd688e01cae8e519003ffa64027cbb81dee872db7dea8840a206d901028152510100003222253330044a229309b2b2b9a105a182030082455370656e64820101f5f6"
  },
  "utxo": {
    "0b95bec9255a426435e6aa7ff9749d76ee4c6d815acb47f10142db889b0edce4#3": {
      "address": "addr_test1vqmy4j8vnxswhg9xdk2k2c7grt7a85g09qkl5yewk0ynx6gc7svs5",
      "datum": null,
      "datumhash": null,
      "inlineDatum": null,
      "referenceScript": null,
      "value": {
        "lovelace": 2000000
      }
    }
  }
}

This transaction was built using this cardano-cli command:

cardano-cli conway transaction build-raw \
    --fee 0 \
    --protocol-params-file ../protocol-parameters-conway.json \
    --out-file ./tmp/blueprint-with-withdraw.json \
    --tx-in "0b95bec9255a426435e6aa7ff9749d76ee4c6d815acb47f10142db889b0edce4#3" \
    --withdrawal stake_test17quu2gxsvfa2lfeg7ljd6yq59dmuy4up8sm02l3vhz8h9fg4g0qp2+0 \
    --withdrawal-script-file ../scripts/always_true.script \
    --withdrawal-redeemer-value \"Spend\" \
    --withdrawal-execution-units "(1,1)" \
    --tx-in-collateral "0b95bec9255a426435e6aa7ff9749d76ee4c6d815acb47f10142db889b0edce4#3" \

and the used script was:

{
  "type": "PlutusScriptV2",
  "description": "Generated by Aiken",
  "cborHex": "52510100003222253330044a229309b2b2b9a1"
}

response from hydra node:

{
  "cborHex":"84a900d90102838258200b95bec9255a426435e6aa7ff9749d76ee4c6d815acb47f10142db889b0edce4038258201aad94968099364023402e923f8c0b3eb77e09318e2aa842549dfc06818f7b60018258201aad94968099364023402e923f8c0b3eb77e09318e2aa842549dfc06818f7b60020dd90102818258201aad94968099364023402e923f8c0b3eb77e09318e2aa842549dfc06818f7b600212d901028182582003f8deb122fbbd98af8eb58ef56feda37728ec957d39586b78198a0cf624412a000182a300581d702043a9f1a685bcf491413a5f139ee42e335157c8c6bc8d9e4018669d01821a00323f48a1581cbe892d28edc7721df96501db771c91d370ce240fe4ec22e27d7ded28a1581c998635d31e13c650f446ad4764f89e162d4ab0a1f54df1702253248d01028201d81858b3d8799f5820baf8ad0d117f123e56ff9b42c09d102aab133ca270eb68a6ff334f5ea18052b39fd8799fd8799fd8799f58200b95bec9255a426435e6aa7ff9749d76ee4c6d815acb47f10142db889b0edce4ff03ff583cd8799fd8799fd8799f581c364ac8ec99a0eba0a66d956563c81afdd3d10f282dfa132eb3c93369ffd87a80ffa140a1401a001e8480d87980d87a80ffffff581cbe892d28edc7721df96501db771c91d370ce240fe4ec22e27d7ded28ff82581d60998635d31e13c650f446ad4764f89e162d4ab0a1f54df1702253248d1a01b7696b021a001b5f8105a1581df039c520d0627aafa728f7e4dd10142b77c257813c36f57e2cb88f72a5000ed9010281581c998635d31e13c650f446ad4764f89e162d4ab0a1f54df1702253248d0b58206e6ddd3a4c65640c4f6a239a8c12fc3315863e21ab3d2098d7cfc3b6b1fddc5a07582012e5af821e4510d6651e57185b4dae19e8bd72bf90a8c1e6cd053606cbc46514a300d90102818258204bce0643e5a9c5763f3cf438d5a3598bcd766a336b6f6b5a81957a7ad64e19c15840c3e33be2fc4995c0b2411b077c58a63311216c164cce0bff59b68329308faa0f2918d690707261d8312f6cde38c9aaa8e75279b77bcc8dccbce347b69aa17a0b06d901028152510100003222253330044a229309b2b2b9a105a182000182d87a9f9fd8799fd8799f58200b95bec9255a426435e6aa7ff9749d76ee4c6d815acb47f10142db889b0edce4ff03ffffff821a00d59f801b00000002540be400f5d90103a100a119d90370487964726156312f436f6d6d69745478",
  "description":"Ledger Cddl Format",
  "txId":"fa63d92e585241b63d54b7cad3e30106bc8e2b88786ac12551e10fdd76959183",
  "type":"Witnessed Tx ConwayEra"
}
ch1bo commented 1 week ago

Good catch!

My hypothesis for why this would be failing is that we don't handle it when balancing the commit transaction here (or at some other location - we usually test only with spending redeemers).

@Micrograx Is this to use the the "withrdraw 0" trick or are you actually wanting to withdraw rewards in your application?

Micrograx commented 1 week ago

Yes, we are planing to use the “withdraw 0” trick in our application to submit a collection of script UTxOs in the most efficient way possible.