Skip to content

Instantly share code, notes, and snippets.

@bwbush
Last active December 22, 2023 16:51
Show Gist options
  • Save bwbush/eb372f077a444021e9ede95699e442b5 to your computer and use it in GitHub Desktop.
Save bwbush/eb372f077a444021e9ede95699e442b5 to your computer and use it in GitHub Desktop.
PLT-9055
Display the source blob
Display the rendered blob
Raw
{
"cells": [
{
"cell_type": "markdown",
"id": "18274614-ee5b-446a-aab7-9aad2bac57e0",
"metadata": {},
"source": [
"# PLT-9055 Attack surface of proposed Marlowe `asData` validator\n",
"\n",
"We use the contract below to test the behavior of Marlowe's semantics validator with respect to corrupted `Datum`.\n",
"\n",
"![Test contract](PLT-9055.png)\n",
"\n",
"We compare the production validator, which does not use `asData`, versus the proposed validator, which does use `asData`. An `INotify` action is applied in each case.\n",
"\n",
"| Case | Production Validator | Proposed Validator |\n",
"|----------------------------------------------------------|----------------------|--------------------|\n",
"| 1 & 5. Uncorrupted | validates | validates |\n",
"| 2 & 6. Corrupted input `Datum` only | rejects | rejects |\n",
"| 3 & 7. Corrupted input and output `Datum` at nested root | rejects | reject |\n",
"| 4 & 8. Corrupted input and output `Datum` netsted deeply | rejects | validates\\* |\n",
"\n",
"\\*Note that the proposed validator would detect the corruption in later transactions involving the corrupt data.\n",
"\n",
"This behavior ensures that there is always a viable execution path, so funds are not locked."
]
},
{
"cell_type": "markdown",
"id": "ed47f8b7-fbe8-4d31-983e-3de0aa0e0976",
"metadata": {},
"source": [
"## Set up environment"
]
},
{
"cell_type": "code",
"execution_count": 1,
"id": "dee4f549-c0ca-4f8d-be20-2a69373928ed",
"metadata": {
"tags": []
},
"outputs": [],
"source": [
"export PATH=/run/wrappers/bin:/home/bbush/.nix-profile/bin:/nix/var/nix/profiles/default/bin:/run/current-system/sw/bin:$PATH\n",
"\n",
"CARDANO_CLI=/extra/iohk/bin/cardano-cli\n",
"MARLOWE_CLI=/extra/iohk/marlowe-cardano.PLT-9055/dist-newstyle/build/x86_64-linux/ghc-9.2.8/marlowe-cli-0.2.0.0/x/marlowe-cli/build/marlowe-cli/marlowe-cli\n",
"MARLOWE_VAL=/extra/iohk/marlowe-plutus.PLT-7581/dist-newstyle/build/x86_64-linux/ghc-9.2.8/marlowe-plutus-0.1.2.0/x/marlowe-validators/build/marlowe-validators/marlowe-validators\n",
"\n",
"export CARDANO_NODE_SOCKET_PATH=/extra/iohk/networks/preprod/node.socket\n",
"export CARDANO_TESTNET_MAGIC=1\n",
"MAGIC=(--testnet-magic $CARDANO_TESTNET_MAGIC)\n",
"\n",
"SLOT_LENGTH=$($MARLOWE_CLI util slotting | jq -r '.scSlotLength')\n",
"SLOT_ZEROTIME=$($MARLOWE_CLI util slotting | jq -r '.scSlotZeroTime')\n",
"\n",
"PAYMENT_SKEY=/extra/iohk/networks/treasury/payment.skey\n",
"PAYMENT_ADDR=$(cat ${PAYMENT_SKEY%%.skey}.testnet.address)"
]
},
{
"cell_type": "markdown",
"id": "7c6fab56-c5e0-435a-b316-bbefefd7416a",
"metadata": {},
"source": [
"## Fixed inputs to transactions"
]
},
{
"cell_type": "markdown",
"id": "0833cd48-0f7d-4caf-9d08-531f84f179d7",
"metadata": {
"tags": []
},
"source": [
"### The initial contract"
]
},
{
"cell_type": "code",
"execution_count": 2,
"id": "1145297d-9943-4c88-81fe-bf8479ca16bd",
"metadata": {
"tags": []
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"{\"timeout\":2000000000000,\"timeout_continuation\":{\"timeout\":2000000000001,\"timeout_continuation\":\"close\",\"when\":[{\"case\":{\"notify_if\":true},\"then\":\"close\"}]},\"when\":[{\"case\":{\"notify_if\":true},\"then\":{\"timeout\":2000000000001,\"timeout_continuation\":\"close\",\"when\":[{\"case\":{\"notify_if\":true},\"then\":\"close\"}]}}]}\n"
]
}
],
"source": [
"yaml2json << EOI > contract-1.json\n",
"when:\n",
"- case:\n",
" notify_if: true\n",
" then:\n",
" timeout: 2000000000001\n",
" timeout_continuation: close\n",
" when:\n",
" - case:\n",
" notify_if: true\n",
" then: close # This is line 50 in the datum.\n",
"timeout: 2000000000000 # The timeout is far in the future, so only the first notify is feasible.\n",
"timeout_continuation:\n",
" when:\n",
" - case:\n",
" notify_if: true\n",
" then: close # This is line 68 in the datum.\n",
" timeout: 2000000000001\n",
" timeout_continuation: close\n",
"EOI\n",
"cat contract-1.json"
]
},
{
"cell_type": "markdown",
"id": "c3833e30-bf77-4176-ba76-dd8ae8fb3e34",
"metadata": {},
"source": [
"### Contract after applying the input"
]
},
{
"cell_type": "code",
"execution_count": 3,
"id": "69fcc3c3-4ddc-44fd-8a46-e06e07f106b4",
"metadata": {
"tags": []
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"timeout: 2000000000001\n",
"timeout_continuation: close\n",
"when:\n",
"- case:\n",
" notify_if: true\n",
" then: close\n"
]
}
],
"source": [
"jq '.when[0].then' contract-1.json > contract-2.json\n",
"json2yaml contract-2.json"
]
},
{
"cell_type": "markdown",
"id": "4f4fffad-4f7e-4a89-b45f-61381cc37e8b",
"metadata": {},
"source": [
"### The initial state"
]
},
{
"cell_type": "code",
"execution_count": 4,
"id": "7291183b-c442-44d1-a1aa-5c8745115b39",
"metadata": {
"tags": []
},
"outputs": [],
"source": [
"ADA=1000000\n",
"INITIAL_LOVELACE=$((2 * ADA))"
]
},
{
"cell_type": "code",
"execution_count": 5,
"id": "e55cd016-d2a3-457c-8e1c-24c63ebd981d",
"metadata": {
"tags": []
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"{\"accounts\":[[[{\"address\":\"addr_test1vq9prvx8ufwutkwxx9cmmuuajaqmjqwujqlp9d8pvg6gupczgtm9j\"},{\"currency_symbol\":\"\",\"token_name\":\"\"}],2000000]],\"boundValues\":[],\"choices\":[],\"minTime\":1}\n"
]
}
],
"source": [
"yaml2json << EOI > state-1.json\n",
"accounts:\n",
"- - - address: $PAYMENT_ADDR\n",
" - currency_symbol: ''\n",
" token_name: ''\n",
" - $INITIAL_LOVELACE\n",
"boundValues: []\n",
"choices: []\n",
"minTime: 1\n",
"EOI\n",
"cat state-1.json"
]
},
{
"cell_type": "markdown",
"id": "0fac70e0-4895-4361-89f7-78bc3ae1b14a",
"metadata": {},
"source": [
"### The redeemer"
]
},
{
"cell_type": "code",
"execution_count": 6,
"id": "060f3ca3-49b2-4124-8672-b2b63cb88620",
"metadata": {
"tags": []
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"list:\n",
"- constructor: 0\n",
" fields:\n",
" - constructor: 2\n",
" fields: []\n"
]
}
],
"source": [
"$MARLOWE_CLI input notify | $MARLOWE_CLI contract redeemer --input-file /dev/stdin > redeemer-2.json\n",
"json2yaml redeemer-2.json"
]
},
{
"cell_type": "markdown",
"id": "eb0f4a4d-64d7-4ddf-aaee-dab5bb159402",
"metadata": {},
"source": [
"## Functions for building and executing the transactions"
]
},
{
"cell_type": "markdown",
"id": "8fe3282a-0011-4800-b00f-a71e6040bcce",
"metadata": {},
"source": [
"### Compute the Marlowe semantics validator's address"
]
},
{
"cell_type": "code",
"execution_count": 7,
"id": "68f7148f-0ff5-4b3f-8300-ea05421cd412",
"metadata": {
"tags": []
},
"outputs": [],
"source": [
"function marlowe_address {\n",
" $CARDANO_CLI address build \"${MAGIC[@]}\" --payment-script-file \"$1\"\n",
"}"
]
},
{
"cell_type": "markdown",
"id": "de5da606-783d-4cfd-8be4-e1c72baef3f7",
"metadata": {},
"source": [
"### Select a pure-lovelace UTxO"
]
},
{
"cell_type": "code",
"execution_count": 8,
"id": "b51bc684-9269-4ff2-98a6-c5d55012a3bb",
"metadata": {
"tags": []
},
"outputs": [],
"source": [
"function select_utxo {\n",
"\n",
"$MARLOWE_CLI util select \\\n",
" \"${MAGIC[@]}\" \\\n",
" --lovelace-only $((10 * ADA)) \\\n",
" \"$PAYMENT_ADDR\" \\\n",
"| sed -e 's/^TxIn \"\\(.*\\)\" (TxIx \\(.*\\))$/\\1#\\2/;2,$d'\n",
"\n",
"}"
]
},
{
"cell_type": "markdown",
"id": "021335cf-d947-4493-ac9d-ab536e8b742f",
"metadata": {},
"source": [
"### Build the creation transaction"
]
},
{
"cell_type": "code",
"execution_count": 9,
"id": "e0d04b7e-de03-4c6a-88f0-4ae42e227def",
"metadata": {
"tags": []
},
"outputs": [],
"source": [
"function build_creation {\n",
"\n",
"$CARDANO_CLI transaction build \\\n",
" --babbage-era \\\n",
" \"${MAGIC[@]}\" \\\n",
" --tx-in \"$(select_utxo)\" \\\n",
" --tx-out \"$1+$INITIAL_LOVELACE\" \\\n",
" --tx-out-datum-embed-file \"$2\" \\\n",
" --change-address \"$PAYMENT_ADDR\" \\\n",
" --out-file \"$3\"\n",
"\n",
"}"
]
},
{
"cell_type": "markdown",
"id": "c1a2370b-d0a9-41a4-a06c-9d10398e236d",
"metadata": {},
"source": [
"### Get the validity interval"
]
},
{
"cell_type": "code",
"execution_count": 10,
"id": "d68f0c30-a428-443c-b541-e7d7122bcc52",
"metadata": {
"tags": []
},
"outputs": [],
"source": [
"function invalid_before {\n",
"\n",
"$CARDANO_CLI query tip \"${MAGIC[@]}\" | jq -r '(.slot - 60)'\n",
"\n",
"}"
]
},
{
"cell_type": "code",
"execution_count": 11,
"id": "2d0a7ead-68b5-4476-89da-42e8b76c792a",
"metadata": {
"tags": []
},
"outputs": [],
"source": [
"function invalid_hereafter {\n",
"\n",
"$CARDANO_CLI query tip \"${MAGIC[@]}\" | jq -r '(.slot + 300)'\n",
"\n",
"}"
]
},
{
"cell_type": "markdown",
"id": "53de089a-d7a1-4054-bdac-b33027c676eb",
"metadata": {},
"source": [
"### Compute the state after applying input"
]
},
{
"cell_type": "code",
"execution_count": 12,
"id": "de982b8c-c849-4557-83ce-79b4f7bdd67d",
"metadata": {
"tags": []
},
"outputs": [],
"source": [
"function next_state {\n",
"\n",
"yaml2json << EOI > $2\n",
"accounts:\n",
"- - - address: $PAYMENT_ADDR\n",
" - currency_symbol: ''\n",
" token_name: ''\n",
" - $INITIAL_LOVELACE\n",
"boundValues: []\n",
"choices: []\n",
"minTime: $((SLOT_ZEROTIME + SLOT_LENGTH * $1))\n",
"EOI\n",
"\n",
"}"
]
},
{
"cell_type": "markdown",
"id": "028ec7ed-5579-49d6-a0eb-a5f1a89d7a5d",
"metadata": {},
"source": [
"### Build the input application"
]
},
{
"cell_type": "code",
"execution_count": 13,
"id": "20cf6470-184b-4ac0-993b-f25cc78757a8",
"metadata": {
"tags": []
},
"outputs": [],
"source": [
"function apply_input {\n",
"\n",
"$CARDANO_CLI transaction build \\\n",
" --babbage-era \\\n",
" \"${MAGIC[@]}\" \\\n",
" --tx-in-collateral \"$(select_utxo)\" \\\n",
" --tx-in \"$(select_utxo)\" \\\n",
" --tx-in \"$1\" \\\n",
" --tx-in-script-file $3 \\\n",
" --tx-in-datum-file $4 \\\n",
" --tx-in-redeemer-file redeemer-2.json \\\n",
" --tx-out \"$2+$INITIAL_LOVELACE\" \\\n",
" --tx-out-datum-embed-file $5 \\\n",
" --invalid-before \"$6\" \\\n",
" --invalid-hereafter \"$7\" \\\n",
" --change-address \"$PAYMENT_ADDR\" \\\n",
" --out-file \"$8\"\n",
"\n",
"}"
]
},
{
"cell_type": "markdown",
"id": "88979f7f-fbae-4f92-aeac-d8c7caa39045",
"metadata": {},
"source": [
"### Sign a transaction"
]
},
{
"cell_type": "code",
"execution_count": 14,
"id": "8d17f994-a3fe-4f0b-b207-cd0f9cc2ae34",
"metadata": {
"tags": []
},
"outputs": [],
"source": [
"function sign_tx {\n",
"$CARDANO_CLI transaction sign \\\n",
" \"${MAGIC[@]}\" \\\n",
" --signing-key-file \"$PAYMENT_SKEY\" \\\n",
" --tx-body-file \"$1\" \\\n",
" --out-file \"$2\"\n",
"$CARDANO_CLI transaction txid --tx-file \"$2\"\n",
"}"
]
},
{
"cell_type": "markdown",
"id": "9a197e12-9bae-43c3-ac3e-b1eb7ac30095",
"metadata": {},
"source": [
"### Submit a transaction"
]
},
{
"cell_type": "code",
"execution_count": 15,
"id": "70d0efa4-0c96-43d1-b85c-555e9410c697",
"metadata": {
"tags": []
},
"outputs": [],
"source": [
"function submit_tx {\n",
"\n",
"$CARDANO_CLI transaction submit \\\n",
" \"${MAGIC[@]}\" \\\n",
" --tx-file \"$1\"\n",
" \n",
"while [[ \"$($CARDANO_CLI query utxo \"${MAGIC[@]}\" --tx-in \"$($CARDANO_CLI transaction txid --tx-file \"$1\")#0\" --out-file /dev/stdout | jq -r length)\" == \"0\" ]]\n",
"do\n",
" sleep 10s\n",
"done\n",
"\n",
"}"
]
},
{
"cell_type": "markdown",
"id": "d418bbd5-305a-47ae-9210-457645485978",
"metadata": {},
"source": [
"## Test cases"
]
},
{
"cell_type": "markdown",
"id": "42825c1c-64ff-44b6-9f90-a2240f02d639",
"metadata": {
"tags": []
},
"source": [
"### 1. Production validator with no data corruption"
]
},
{
"cell_type": "markdown",
"id": "830d6d2e-7e10-4fa4-96ef-4fad70d8cefd",
"metadata": {},
"source": [
"#### Generate the validator"
]
},
{
"cell_type": "code",
"execution_count": 16,
"id": "7091f46a-2364-43e2-b7c8-1ec15a5a06df",
"metadata": {
"tags": []
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"\n",
"Semantics:\n",
" Validator hash: 6027a8010c555a4dd6b08882b899f4b3167c6e4524047132202dd984\n",
" Validator file: /extra/iohk/jupyter/PLT-9055/marlowe-semantics.plutus\n",
" Measurements file: /extra/iohk/jupyter/PLT-9055/out/marlowe-semantics.tsv\n",
"\n",
"Role payout:\n",
" Validator hash: fdade3b86107bc715037b468574dd8d3f884a0da8c9956086b9a1a51\n",
" Validator file: /extra/iohk/jupyter/PLT-9055/marlowe-rolepayout.plutus\n",
" Measurements file: /extra/iohk/jupyter/PLT-9055/out/marlowe-rolepayout.tsv\n",
"\n",
"Open roles:\n",
" Validator hash: d46f26cc0a9d9cf2578daa7c9b8e7733f05557cc44d2ed2774ab7962\n",
" Validator file: /extra/iohk/jupyter/PLT-9055/marlowe-openroles.plutus\n",
" Measurements file: /extra/iohk/jupyter/PLT-9055/out/marlowe-openroles.tsv\n"
]
}
],
"source": [
"nix run 'github:input-output-hk/marlowe-plutus/45e1da07a6152b2c0220d9f333f2f2a1b7c48d20#marlowe-validators' 2> /dev/null"
]
},
{
"cell_type": "code",
"execution_count": 17,
"id": "747f97d2-328f-449c-a362-6d88a1b2ceb5",
"metadata": {
"tags": []
},
"outputs": [],
"source": [
"mv marlowe-semantics.plutus production.plutus"
]
},
{
"cell_type": "code",
"execution_count": 18,
"id": "b24a5dbe-277f-4f97-8665-1fb80b0c1cab",
"metadata": {
"tags": []
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"PRODUCTION_ADDR = addr_test1wpsz02qpp3245nwkkzyg9wye7je3vlrwg5jqgufjyqkanpqef22lm\n"
]
}
],
"source": [
"PRODUCTION_ADDR=$(marlowe_address production.plutus)\n",
"echo \"PRODUCTION_ADDR = $PRODUCTION_ADDR\""
]
},
{
"cell_type": "markdown",
"id": "982e8240-0a4c-44ca-893a-14f11aabd787",
"metadata": {},
"source": [
"#### Create the contract"
]
},
{
"cell_type": "code",
"execution_count": 19,
"id": "bb3c9c41-1b79-4312-9c09-5e6a9fd75d47",
"metadata": {
"tags": []
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"ac22144cc5312f9e3ec2c14415630902055797d83a9d3fd55e8ef912d2df8a5e\n"
]
}
],
"source": [
"$MARLOWE_CLI contract datum \\\n",
" --contract-file contract-1.json \\\n",
" --state-file state-1.json \\\n",
" --out-file test1-datum-1.json"
]
},
{
"cell_type": "code",
"execution_count": 20,
"id": "acac7abe-7390-4e8b-a771-7bbce152461e",
"metadata": {
"tags": []
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Estimated transaction fee: Lovelace 176589\n"
]
}
],
"source": [
"build_creation \"$PRODUCTION_ADDR\" test1-datum-1.json test1-tx-1.unsigned"
]
},
{
"cell_type": "code",
"execution_count": 21,
"id": "7b5eaa90-4fb4-4726-ba4d-187bceb40340",
"metadata": {
"tags": []
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"TEST1_TX_1 = eba0a8510e80af7a78a2e9a131321d114ffe6b5dbe9a3e73c2f93a783d9aacad\n"
]
}
],
"source": [
"TEST1_TX_1=$(sign_tx test1-tx-1.unsigned test1-tx-1.signed)\n",
"echo \"TEST1_TX_1 = $TEST1_TX_1\""
]
},
{
"cell_type": "code",
"execution_count": 22,
"id": "992f8252-e5f2-41a1-8b7d-bc6f3948a423",
"metadata": {
"tags": []
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Transaction successfully submitted.\n"
]
}
],
"source": [
"submit_tx test1-tx-1.signed"
]
},
{
"cell_type": "markdown",
"id": "9c5254ff-f48b-431b-89bd-c939a6341711",
"metadata": {},
"source": [
"#### Apply the input"
]
},
{
"cell_type": "markdown",
"id": "d2a91e9e-df71-4c2b-9433-9f7e2961bc34",
"metadata": {},
"source": [
"##### New datum"
]
},
{
"cell_type": "code",
"execution_count": 23,
"id": "652249a7-90c4-4503-a303-b7edc6b0e8ad",
"metadata": {
"tags": []
},
"outputs": [],
"source": [
"INVALID_BEFORE=$(invalid_before)\n",
"INVALID_HEREAFTER=$(invalid_hereafter)"
]
},
{
"cell_type": "code",
"execution_count": 24,
"id": "9150990c-a02b-4341-a87f-6d8ab4a56874",
"metadata": {
"tags": []
},
"outputs": [],
"source": [
"next_state \"$INVALID_BEFORE\" test1-state-2.json"
]
},
{
"cell_type": "code",
"execution_count": 25,
"id": "86ba506b-6508-42de-b70d-4f9f52c46731",
"metadata": {
"tags": []
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"9d9122481fd0b68b6b935e525249f600f086cf28749377b342308fd07f9c278d\n"
]
}
],
"source": [
"$MARLOWE_CLI contract datum \\\n",
" --contract-file contract-2.json \\\n",
" --state-file test1-state-2.json \\\n",
" --out-file test1-datum-2.json"
]
},
{
"cell_type": "markdown",
"id": "3e960f00-b386-4799-8949-aa4e7d754026",
"metadata": {},
"source": [
"##### The transaction is validated, as it should be."
]
},
{
"cell_type": "code",
"execution_count": 26,
"id": "61c6320e-e468-4d88-8294-43063fcc8877",
"metadata": {
"tags": []
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Estimated transaction fee: Lovelace 868162\n"
]
}
],
"source": [
"apply_input \"$TEST1_TX_1#0\" \"$PRODUCTION_ADDR\" production.plutus test1-datum-1.json test1-datum-2.json \"$INVALID_BEFORE\" \"$INVALID_HEREAFTER\" test1-tx-2.unsigned || false"
]
},
{
"cell_type": "code",
"execution_count": 27,
"id": "27181050-0eb2-44d4-aa63-82b9053668e5",
"metadata": {
"tags": []
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"TEST1_TX_2 = c75c2fb8af26e579be807ae5477aee9a1faec5e7cf2d3d0e7172b2441a10806d\n"
]
}
],
"source": [
"TEST1_TX_2=$(sign_tx test1-tx-2.unsigned test1-tx-2.signed)\n",
"echo \"TEST1_TX_2 = $TEST1_TX_2\""
]
},
{
"cell_type": "code",
"execution_count": 28,
"id": "92748020-a2c2-4a71-9ffb-0982f1648a72",
"metadata": {
"tags": []
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Transaction successfully submitted.\n"
]
}
],
"source": [
"submit_tx test1-tx-2.signed"
]
},
{
"cell_type": "markdown",
"id": "9cd801fb-5674-4225-99c1-0cdafd261cd4",
"metadata": {},
"source": [
"### 2. Production validator with data corruption only in input datum"
]
},
{
"cell_type": "markdown",
"id": "b1171656-60f7-4e23-ac54-f91b7ae319e0",
"metadata": {},
"source": [
"#### Create the contract"
]
},
{
"cell_type": "code",
"execution_count": 29,
"id": "aa302ccf-31d8-4b7a-8a1f-e46e99b9c2d7",
"metadata": {
"tags": []
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"ac22144cc5312f9e3ec2c14415630902055797d83a9d3fd55e8ef912d2df8a5e\n"
]
}
],
"source": [
"$MARLOWE_CLI contract datum \\\n",
" --contract-file contract-1.json \\\n",
" --state-file state-1.json \\\n",
" --out-file test2-datum-1-good.json"
]
},
{
"cell_type": "markdown",
"id": "02ff7736-0a1a-4015-b817-cf8e592dcd81",
"metadata": {},
"source": [
"##### Change the fourth `Close` in the blockly diagram to garbage (i.e., `Constr 0 []` becomes `Constr 1000 []`)."
]
},
{
"cell_type": "code",
"execution_count": 30,
"id": "237b45e9-4290-4bfb-8669-ce4d9bbe9a39",
"metadata": {
"tags": []
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
" 1\tconstructor: 0\n",
" 2\tfields:\n",
" 3\t- constructor: 0\n",
" 4\t fields:\n",
" 5\t - bytes: ''\n",
" 6\t- constructor: 0\n",
" 7\t fields:\n",
" 8\t - map:\n",
" 9\t - k:\n",
" 10\t constructor: 0\n",
" 11\t fields:\n",
" 12\t - constructor: 0\n",
" 13\t fields:\n",
" 14\t - constructor: 0\n",
" 15\t fields: []\n",
" 16\t - constructor: 0\n",
" 17\t fields:\n",
" 18\t - constructor: 0\n",
" 19\t fields:\n",
" 20\t - bytes: 0a11b0c7e25dc5d9c63171bdf39d9741b901dc903e12b4e162348e07\n",
" 21\t - constructor: 1\n",
" 22\t fields: []\n",
" 23\t - constructor: 0\n",
" 24\t fields:\n",
" 25\t - bytes: ''\n",
" 26\t - bytes: ''\n",
" 27\t v:\n",
" 28\t int: 2000000\n",
" 29\t - map: []\n",
" 30\t - map: []\n",
" 31\t - int: 1\n",
" 32\t- constructor: 3\n",
" 33\t fields:\n",
" 34\t - list:\n",
" 35\t - constructor: 0\n",
" 36\t fields:\n",
" 37\t - constructor: 2\n",
" 38\t fields:\n",
" 39\t - constructor: 9\n",
" 40\t fields: []\n",
" 41\t - constructor: 3\n",
" 42\t fields:\n",
" 43\t - list:\n",
" 44\t - constructor: 0\n",
" 45\t fields:\n",
" 46\t - constructor: 2\n",
" 47\t fields:\n",
" 48\t - constructor: 9\n",
" 49\t fields: []\n",
" 50\t - constructor: 0\n",
" 51\t fields: []\n",
" 52\t - int: 2000000000001\n",
" 53\t - constructor: 0\n",
" 54\t fields: []\n",
" 55\t - int: 2000000000000\n",
" 56\t - constructor: 3\n",
" 57\t fields:\n",
" 58\t - list:\n",
" 59\t - constructor: 0\n",
" 60\t fields:\n",
" 61\t - constructor: 2\n",
" 62\t fields:\n",
" 63\t - constructor: 9\n",
" 64\t fields: []\n",
" 65\t - constructor: 0\n",
" 66\t fields: []\n",
" 67\t - int: 2000000000001\n",
" 68\t - constructor: 1000\n",
" 69\t fields: []\n"
]
}
],
"source": [
"json2yaml test2-datum-1-good.json | sed -e '68s/0/1000/' | yaml2json > test2-datum-1-bad.json\n",
"json2yaml test2-datum-1-bad.json | nl"
]
},
{
"cell_type": "code",
"execution_count": 31,
"id": "cf659c18-0793-4784-87ee-b00b9b3cf272",
"metadata": {
"tags": []
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Estimated transaction fee: Lovelace 176765\n"
]
}
],
"source": [
"build_creation \"$PRODUCTION_ADDR\" test2-datum-1-bad.json test2-tx-1.unsigned"
]
},
{
"cell_type": "code",
"execution_count": 32,
"id": "ffecdd4f-8883-417c-9142-d8fbd8c486a2",
"metadata": {
"tags": []
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"TEST2_TX_1 = cb3e2bafc16b5892915f03e84c6508b1305905e3e84f57a2fb79367a3ebdb22c\n"
]
}
],
"source": [
"TEST2_TX_1=$(sign_tx test2-tx-1.unsigned test2-tx-1.signed)\n",
"echo \"TEST2_TX_1 = $TEST2_TX_1\""
]
},
{
"cell_type": "code",
"execution_count": 33,
"id": "92960086-3de7-4068-8417-34c56e5cb1ba",
"metadata": {
"tags": []
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Transaction successfully submitted.\n"
]
}
],
"source": [
"submit_tx test2-tx-1.signed"
]
},
{
"cell_type": "markdown",
"id": "d9aff276-1ea0-4277-b8a9-d52dcdb999ee",
"metadata": {},
"source": [
"#### Apply the input"
]
},
{
"cell_type": "markdown",
"id": "1cc14d7a-4ce4-4c24-9bdc-189dc374f4ea",
"metadata": {},
"source": [
"##### New datum"
]
},
{
"cell_type": "code",
"execution_count": 34,
"id": "cf04181c-abb5-4df1-b5bf-43deba36d622",
"metadata": {
"tags": []
},
"outputs": [],
"source": [
"INVALID_BEFORE=$(invalid_before)\n",
"INVALID_HEREAFTER=$(invalid_hereafter)"
]
},
{
"cell_type": "code",
"execution_count": 35,
"id": "a22e7ab9-d78b-4aed-8351-de6ebd299820",
"metadata": {
"tags": []
},
"outputs": [],
"source": [
"next_state \"$INVALID_BEFORE\" test2-state-2.json"
]
},
{
"cell_type": "code",
"execution_count": 36,
"id": "41e74b0f-21fe-4f0e-b690-be44fa01a98c",
"metadata": {
"tags": []
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"70189afbb98f66f05baee7bb2ec4de18788638def17fb4f1c5f55b22a54b1f86\n"
]
}
],
"source": [
"$MARLOWE_CLI contract datum \\\n",
" --contract-file contract-2.json \\\n",
" --state-file test2-state-2.json \\\n",
" --out-file test2-datum-2.json"
]
},
{
"cell_type": "markdown",
"id": "c89b8cc8-a72d-4f3b-9cc8-98ee7e29aa55",
"metadata": {},
"source": [
"##### The transaction is rejected, as it should be."
]
},
{
"cell_type": "code",
"execution_count": 37,
"id": "386a50a7-057b-4440-a85e-940828023edc",
"metadata": {
"tags": []
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Command failed: transaction build Error: The following scripts have execution failures:\n",
"the script for transaction input 0 (in ascending order of the TxIds) failed with: \n",
"The Plutus script evaluation failed: An error has occurred: User error:\n",
"The machine terminated because of an error, either from a built-in function or from an explicit use of 'error'.\n",
"Script debugging logs: \n",
"\n"
]
}
],
"source": [
"apply_input \"$TEST2_TX_1#0\" \"$PRODUCTION_ADDR\" production.plutus test2-datum-1-bad.json test2-datum-2.json \"$INVALID_BEFORE\" \"$INVALID_HEREAFTER\" test2-tx-2.unsigned || true"
]
},
{
"cell_type": "markdown",
"id": "1c6587c8-25bd-4a01-900b-8234556a052f",
"metadata": {},
"source": [
"### 3. Production validator with data corruption in input and output datum at nested root"
]
},
{
"cell_type": "markdown",
"id": "14a1cd12-0c6c-482a-8d20-45bde8e32660",
"metadata": {},
"source": [
"#### Create the contract"
]
},
{
"cell_type": "code",
"execution_count": 38,
"id": "fe058e49-89ae-4f40-9f9b-436b0d5834fb",
"metadata": {
"tags": []
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"ac22144cc5312f9e3ec2c14415630902055797d83a9d3fd55e8ef912d2df8a5e\n"
]
}
],
"source": [
"$MARLOWE_CLI contract datum \\\n",
" --contract-file contract-1.json \\\n",
" --state-file state-1.json \\\n",
" --out-file test3-datum-1-good.json"
]
},
{
"cell_type": "markdown",
"id": "7f1e4d95-e77c-41f6-9742-17c3030ff645",
"metadata": {},
"source": [
"##### Change the second `Close` in the blockly diagram to garbage (i.e., `Constr 0 []` becomes `Constr 1000 []`)."
]
},
{
"cell_type": "code",
"execution_count": 39,
"id": "e6db6705-c7d9-4777-8dec-501064fb4b98",
"metadata": {
"tags": []
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
" 1\tconstructor: 0\n",
" 2\tfields:\n",
" 3\t- constructor: 0\n",
" 4\t fields:\n",
" 5\t - bytes: ''\n",
" 6\t- constructor: 0\n",
" 7\t fields:\n",
" 8\t - map:\n",
" 9\t - k:\n",
" 10\t constructor: 0\n",
" 11\t fields:\n",
" 12\t - constructor: 0\n",
" 13\t fields:\n",
" 14\t - constructor: 0\n",
" 15\t fields: []\n",
" 16\t - constructor: 0\n",
" 17\t fields:\n",
" 18\t - constructor: 0\n",
" 19\t fields:\n",
" 20\t - bytes: 0a11b0c7e25dc5d9c63171bdf39d9741b901dc903e12b4e162348e07\n",
" 21\t - constructor: 1\n",
" 22\t fields: []\n",
" 23\t - constructor: 0\n",
" 24\t fields:\n",
" 25\t - bytes: ''\n",
" 26\t - bytes: ''\n",
" 27\t v:\n",
" 28\t int: 2000000\n",
" 29\t - map: []\n",
" 30\t - map: []\n",
" 31\t - int: 1\n",
" 32\t- constructor: 3\n",
" 33\t fields:\n",
" 34\t - list:\n",
" 35\t - constructor: 0\n",
" 36\t fields:\n",
" 37\t - constructor: 2\n",
" 38\t fields:\n",
" 39\t - constructor: 9\n",
" 40\t fields: []\n",
" 41\t - constructor: 3\n",
" 42\t fields:\n",
" 43\t - list:\n",
" 44\t - constructor: 0\n",
" 45\t fields:\n",
" 46\t - constructor: 2\n",
" 47\t fields:\n",
" 48\t - constructor: 9\n",
" 49\t fields: []\n",
" 50\t - constructor: 0\n",
" 51\t fields: []\n",
" 52\t - int: 2000000000001\n",
" 53\t - constructor: 1000\n",
" 54\t fields: []\n",
" 55\t - int: 2000000000000\n",
" 56\t - constructor: 3\n",
" 57\t fields:\n",
" 58\t - list:\n",
" 59\t - constructor: 0\n",
" 60\t fields:\n",
" 61\t - constructor: 2\n",
" 62\t fields:\n",
" 63\t - constructor: 9\n",
" 64\t fields: []\n",
" 65\t - constructor: 0\n",
" 66\t fields: []\n",
" 67\t - int: 2000000000001\n",
" 68\t - constructor: 0\n",
" 69\t fields: []\n"
]
}
],
"source": [
"json2yaml test3-datum-1-good.json | sed -e '53s/0/1000/' | yaml2json > test3-datum-1-bad.json\n",
"json2yaml test3-datum-1-bad.json | nl"
]
},
{
"cell_type": "code",
"execution_count": 40,
"id": "8b5f87a8-e33a-4e4e-a7c9-977f224f3f18",
"metadata": {
"tags": []
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Estimated transaction fee: Lovelace 176765\n"
]
}
],
"source": [
"build_creation \"$PRODUCTION_ADDR\" test3-datum-1-bad.json test3-tx-1.unsigned"
]
},
{
"cell_type": "code",
"execution_count": 41,
"id": "ed127e52-3ac5-4a94-8bf5-c76d5dc4a809",
"metadata": {
"tags": []
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"TEST3_TX_1 = 487eefafd6b9e8f8f218da6eac2ee9ffeb5f4e3fee320a43a2d6344aa482d555\n"
]
}
],
"source": [
"TEST3_TX_1=$(sign_tx test3-tx-1.unsigned test3-tx-1.signed)\n",
"echo \"TEST3_TX_1 = $TEST3_TX_1\""
]
},
{
"cell_type": "code",
"execution_count": 42,
"id": "e9aed238-cf49-4b1c-a9fb-38b625675a09",
"metadata": {
"tags": []
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Transaction successfully submitted.\n"
]
}
],
"source": [
"submit_tx test3-tx-1.signed"
]
},
{
"cell_type": "markdown",
"id": "69e583a1-8991-4f8c-8c4b-bde1987014eb",
"metadata": {},
"source": [
"#### Apply the input"
]
},
{
"cell_type": "markdown",
"id": "1bbbc6f5-5eee-42d5-be54-8837bb4e26da",
"metadata": {},
"source": [
"##### New datum"
]
},
{
"cell_type": "code",
"execution_count": 43,
"id": "cc7bd5dc-618f-4fdf-b77a-5701e1c22260",
"metadata": {
"tags": []
},
"outputs": [],
"source": [
"INVALID_BEFORE=$(invalid_before)\n",
"INVALID_HEREAFTER=$(invalid_hereafter)"
]
},
{
"cell_type": "code",
"execution_count": 44,
"id": "8947c5f0-a944-42aa-a799-47f50b2e3241",
"metadata": {
"tags": []
},
"outputs": [],
"source": [
"next_state \"$INVALID_BEFORE\" test3-state-2.json"
]
},
{
"cell_type": "code",
"execution_count": 45,
"id": "735adaea-6bec-4529-a529-4120db04d808",
"metadata": {
"tags": []
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"db27c70c170d3b4940822cfd4d76b366da18a27df396f7640b6a61361c2bbeb5\n"
]
}
],
"source": [
"$MARLOWE_CLI contract datum \\\n",
" --contract-file contract-2.json \\\n",
" --state-file test3-state-2.json \\\n",
" --out-file test3-datum-2-good.json"
]
},
{
"cell_type": "code",
"execution_count": 46,
"id": "ef73a848-d673-43ed-94bd-d29e14abc294",
"metadata": {
"tags": []
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
" 1\tconstructor: 0\n",
" 2\tfields:\n",
" 3\t- constructor: 0\n",
" 4\t fields:\n",
" 5\t - bytes: ''\n",
" 6\t- constructor: 0\n",
" 7\t fields:\n",
" 8\t - map:\n",
" 9\t - k:\n",
" 10\t constructor: 0\n",
" 11\t fields:\n",
" 12\t - constructor: 0\n",
" 13\t fields:\n",
" 14\t - constructor: 0\n",
" 15\t fields: []\n",
" 16\t - constructor: 0\n",
" 17\t fields:\n",
" 18\t - constructor: 0\n",
" 19\t fields:\n",
" 20\t - bytes: 0a11b0c7e25dc5d9c63171bdf39d9741b901dc903e12b4e162348e07\n",
" 21\t - constructor: 1\n",
" 22\t fields: []\n",
" 23\t - constructor: 0\n",
" 24\t fields:\n",
" 25\t - bytes: ''\n",
" 26\t - bytes: ''\n",
" 27\t v:\n",
" 28\t int: 2000000\n",
" 29\t - map: []\n",
" 30\t - map: []\n",
" 31\t - int: 1703263516000\n",
" 32\t- constructor: 3\n",
" 33\t fields:\n",
" 34\t - list:\n",
" 35\t - constructor: 0\n",
" 36\t fields:\n",
" 37\t - constructor: 2\n",
" 38\t fields:\n",
" 39\t - constructor: 9\n",
" 40\t fields: []\n",
" 41\t - constructor: 0\n",
" 42\t fields: []\n",
" 43\t - int: 2000000000001\n",
" 44\t - constructor: 1000\n",
" 45\t fields: []\n"
]
}
],
"source": [
"json2yaml test3-datum-2-good.json | sed -e '44s/0/1000/' | yaml2json > test3-datum-2-bad.json\n",
"json2yaml test3-datum-2-bad.json | nl"
]
},
{
"cell_type": "markdown",
"id": "42afb89a-1dad-410c-a55b-889680a804e2",
"metadata": {},
"source": [
"##### The transaction is rejected, as it should be."
]
},
{
"cell_type": "code",
"execution_count": 47,
"id": "3067f095-722b-4af6-a166-ae53f9d02519",
"metadata": {
"tags": []
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Command failed: transaction build Error: The following scripts have execution failures:\n",
"the script for transaction input 0 (in ascending order of the TxIds) failed with: \n",
"The Plutus script evaluation failed: An error has occurred: User error:\n",
"The machine terminated because of an error, either from a built-in function or from an explicit use of 'error'.\n",
"Script debugging logs: \n",
"\n"
]
}
],
"source": [
"apply_input \"$TEST3_TX_1#0\" \"$PRODUCTION_ADDR\" production.plutus test3-datum-1-bad.json test3-datum-2-bad.json \"$INVALID_BEFORE\" \"$INVALID_HEREAFTER\" test3-tx-2.unsigned || true"
]
},
{
"cell_type": "markdown",
"id": "31498697-c848-4cca-bfb1-55becf522615",
"metadata": {},
"source": [
"### 4. Production validator with data corruption in input and output datum nested deeply"
]
},
{
"cell_type": "markdown",
"id": "bb67250c-f67f-4f46-aebb-679ed8a4351f",
"metadata": {},
"source": [
"#### Create the contract"
]
},
{
"cell_type": "code",
"execution_count": 48,
"id": "5d3198a8-8f8a-4c2c-976c-699a1b2891ab",
"metadata": {
"tags": []
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"ac22144cc5312f9e3ec2c14415630902055797d83a9d3fd55e8ef912d2df8a5e\n"
]
}
],
"source": [
"$MARLOWE_CLI contract datum \\\n",
" --contract-file contract-1.json \\\n",
" --state-file state-1.json \\\n",
" --out-file test4-datum-1-good.json"
]
},
{
"cell_type": "markdown",
"id": "f7dacf65-5f0b-4dcf-9fba-4e02677cd6c3",
"metadata": {},
"source": [
"##### Change the first `Close` in the blockly diagram to garbage (i.e., `Constr 0 []` becomes `Constr 1000 []`)."
]
},
{
"cell_type": "code",
"execution_count": 49,
"id": "261ab651-9529-460d-b6fd-80578aac95da",
"metadata": {
"tags": []
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
" 1\tconstructor: 0\n",
" 2\tfields:\n",
" 3\t- constructor: 0\n",
" 4\t fields:\n",
" 5\t - bytes: ''\n",
" 6\t- constructor: 0\n",
" 7\t fields:\n",
" 8\t - map:\n",
" 9\t - k:\n",
" 10\t constructor: 0\n",
" 11\t fields:\n",
" 12\t - constructor: 0\n",
" 13\t fields:\n",
" 14\t - constructor: 0\n",
" 15\t fields: []\n",
" 16\t - constructor: 0\n",
" 17\t fields:\n",
" 18\t - constructor: 0\n",
" 19\t fields:\n",
" 20\t - bytes: 0a11b0c7e25dc5d9c63171bdf39d9741b901dc903e12b4e162348e07\n",
" 21\t - constructor: 1\n",
" 22\t fields: []\n",
" 23\t - constructor: 0\n",
" 24\t fields:\n",
" 25\t - bytes: ''\n",
" 26\t - bytes: ''\n",
" 27\t v:\n",
" 28\t int: 2000000\n",
" 29\t - map: []\n",
" 30\t - map: []\n",
" 31\t - int: 1\n",
" 32\t- constructor: 3\n",
" 33\t fields:\n",
" 34\t - list:\n",
" 35\t - constructor: 0\n",
" 36\t fields:\n",
" 37\t - constructor: 2\n",
" 38\t fields:\n",
" 39\t - constructor: 9\n",
" 40\t fields: []\n",
" 41\t - constructor: 3\n",
" 42\t fields:\n",
" 43\t - list:\n",
" 44\t - constructor: 0\n",
" 45\t fields:\n",
" 46\t - constructor: 2\n",
" 47\t fields:\n",
" 48\t - constructor: 9\n",
" 49\t fields: []\n",
" 50\t - constructor: 1000\n",
" 51\t fields: []\n",
" 52\t - int: 2000000000001\n",
" 53\t - constructor: 0\n",
" 54\t fields: []\n",
" 55\t - int: 2000000000000\n",
" 56\t - constructor: 3\n",
" 57\t fields:\n",
" 58\t - list:\n",
" 59\t - constructor: 0\n",
" 60\t fields:\n",
" 61\t - constructor: 2\n",
" 62\t fields:\n",
" 63\t - constructor: 9\n",
" 64\t fields: []\n",
" 65\t - constructor: 0\n",
" 66\t fields: []\n",
" 67\t - int: 2000000000001\n",
" 68\t - constructor: 0\n",
" 69\t fields: []\n"
]
}
],
"source": [
"json2yaml test4-datum-1-good.json | sed -e '50s/0/1000/' | yaml2json > test4-datum-1-bad.json\n",
"json2yaml test4-datum-1-bad.json | nl"
]
},
{
"cell_type": "code",
"execution_count": 50,
"id": "c7ee7070-3ad7-4274-b58a-27bbd8b3e170",
"metadata": {
"tags": []
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Estimated transaction fee: Lovelace 176765\n"
]
}
],
"source": [
"build_creation \"$PRODUCTION_ADDR\" test4-datum-1-bad.json test4-tx-1.unsigned"
]
},
{
"cell_type": "code",
"execution_count": 51,
"id": "f2ede41d-0f98-4159-897c-6c1f217946fe",
"metadata": {
"tags": []
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"TEST4_TX_1 = e091c1f6daef16789312ac02a15ed3b920369c157610ec54dd0b443ad1d1c568\n"
]
}
],
"source": [
"TEST4_TX_1=$(sign_tx test4-tx-1.unsigned test4-tx-1.signed)\n",
"echo \"TEST4_TX_1 = $TEST4_TX_1\""
]
},
{
"cell_type": "code",
"execution_count": 52,
"id": "a5b1f042-6d6b-45e6-a504-29d78560029d",
"metadata": {
"tags": []
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Transaction successfully submitted.\n"
]
}
],
"source": [
"submit_tx test4-tx-1.signed"
]
},
{
"cell_type": "markdown",
"id": "0b7fa691-45dc-40fa-9c02-ee66bb4eef41",
"metadata": {},
"source": [
"#### Apply the input"
]
},
{
"cell_type": "markdown",
"id": "856b845c-2da5-4f3e-928e-3675c57cb57d",
"metadata": {},
"source": [
"##### New datum"
]
},
{
"cell_type": "code",
"execution_count": 53,
"id": "463e375c-5100-4db7-ae7f-8d6669cc0085",
"metadata": {
"tags": []
},
"outputs": [],
"source": [
"INVALID_BEFORE=$(invalid_before)\n",
"INVALID_HEREAFTER=$(invalid_hereafter)"
]
},
{
"cell_type": "code",
"execution_count": 54,
"id": "38e048e7-3541-400e-bd84-f6884224a857",
"metadata": {
"tags": []
},
"outputs": [],
"source": [
"next_state \"$INVALID_BEFORE\" test4-state-2.json"
]
},
{
"cell_type": "code",
"execution_count": 55,
"id": "170637e2-6d8f-408c-b5d5-f82b26a0348f",
"metadata": {
"tags": []
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"a1526ec93707cbc07a3f4b8ed09ae4e37e3de563c553689e7ae195b8b7371d79\n"
]
}
],
"source": [
"$MARLOWE_CLI contract datum \\\n",
" --contract-file contract-2.json \\\n",
" --state-file test4-state-2.json \\\n",
" --out-file test4-datum-2-good.json"
]
},
{
"cell_type": "code",
"execution_count": 56,
"id": "dddac357-4b80-489c-bd56-d88ccab80c52",
"metadata": {
"tags": []
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
" 1\tconstructor: 0\n",
" 2\tfields:\n",
" 3\t- constructor: 0\n",
" 4\t fields:\n",
" 5\t - bytes: ''\n",
" 6\t- constructor: 0\n",
" 7\t fields:\n",
" 8\t - map:\n",
" 9\t - k:\n",
" 10\t constructor: 0\n",
" 11\t fields:\n",
" 12\t - constructor: 0\n",
" 13\t fields:\n",
" 14\t - constructor: 0\n",
" 15\t fields: []\n",
" 16\t - constructor: 0\n",
" 17\t fields:\n",
" 18\t - constructor: 0\n",
" 19\t fields:\n",
" 20\t - bytes: 0a11b0c7e25dc5d9c63171bdf39d9741b901dc903e12b4e162348e07\n",
" 21\t - constructor: 1\n",
" 22\t fields: []\n",
" 23\t - constructor: 0\n",
" 24\t fields:\n",
" 25\t - bytes: ''\n",
" 26\t - bytes: ''\n",
" 27\t v:\n",
" 28\t int: 2000000\n",
" 29\t - map: []\n",
" 30\t - map: []\n",
" 31\t - int: 1703263532000\n",
" 32\t- constructor: 3\n",
" 33\t fields:\n",
" 34\t - list:\n",
" 35\t - constructor: 0\n",
" 36\t fields:\n",
" 37\t - constructor: 2\n",
" 38\t fields:\n",
" 39\t - constructor: 9\n",
" 40\t fields: []\n",
" 41\t - constructor: 1000\n",
" 42\t fields: []\n",
" 43\t - int: 2000000000001\n",
" 44\t - constructor: 0\n",
" 45\t fields: []\n"
]
}
],
"source": [
"json2yaml test4-datum-2-good.json | sed -e '41s/0/1000/' | yaml2json > test4-datum-2-bad.json\n",
"json2yaml test4-datum-2-bad.json | nl"
]
},
{
"cell_type": "markdown",
"id": "7f9ab5ca-81c2-416d-8f5f-811f6a1e1470",
"metadata": {},
"source": [
"##### The transaction is rejected, as it should be."
]
},
{
"cell_type": "code",
"execution_count": 57,
"id": "44f0ae00-93ed-4bff-bb1a-01062991ada0",
"metadata": {
"tags": []
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Command failed: transaction build Error: The following scripts have execution failures:\n",
"the script for transaction input 0 (in ascending order of the TxIds) failed with: \n",
"The Plutus script evaluation failed: An error has occurred: User error:\n",
"The machine terminated because of an error, either from a built-in function or from an explicit use of 'error'.\n",
"Script debugging logs: \n",
"\n"
]
}
],
"source": [
"apply_input \"$TEST4_TX_1#0\" \"$PRODUCTION_ADDR\" production.plutus test4-datum-1-bad.json test4-datum-2-bad.json \"$INVALID_BEFORE\" \"$INVALID_HEREAFTER\" test4-tx-2.unsigned || true"
]
},
{
"cell_type": "markdown",
"id": "80faa925-bceb-4a67-a3c5-ebe52c24a4ad",
"metadata": {
"tags": []
},
"source": [
"### 5. Proposed validator with no data corruption"
]
},
{
"cell_type": "markdown",
"id": "dc36fb1e-7c63-46d9-ad69-0691e6d7ffcf",
"metadata": {},
"source": [
"#### Generate the validator"
]
},
{
"cell_type": "code",
"execution_count": 58,
"id": "c81114a2-e700-410e-b03b-00e799e6ed1e",
"metadata": {
"tags": []
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"\n",
"Semantics:\n",
" Validator hash: 377325ad84a55ba0282d844dff2d5f0f18c33fd4a28a0a9d73c6f60d\n",
" Validator file: /extra/iohk/jupyter/PLT-9055/marlowe-semantics.plutus\n",
" Measurements file: /extra/iohk/jupyter/PLT-9055/out/marlowe-semantics.tsv\n",
"\n",
"Role payout:\n",
" Validator hash: fcb8885eb5e4f9a5cfca3c75e8c7280e482af32dcdf2d13e47d05d27\n",
" Validator file: /extra/iohk/jupyter/PLT-9055/marlowe-rolepayout.plutus\n",
" Measurements file: /extra/iohk/jupyter/PLT-9055/out/marlowe-rolepayout.tsv\n",
"\n",
"Open roles:\n",
" Validator hash: 2722e12a53dfb4fe3742b8a2c0534bd16b0b5ae492a3d76554bbe8a5\n",
" Validator file: /extra/iohk/jupyter/PLT-9055/open-role.plutus\n",
" Measurements file: /extra/iohk/jupyter/PLT-9055/out/open-role.tsv\n"
]
}
],
"source": [
"nix run 'github:input-output-hk/marlowe-plutus/46d2adfe53ecf20a926bd2e2701b5d0e18c2123b#marlowe-validators' 2> /dev/null"
]
},
{
"cell_type": "code",
"execution_count": 59,
"id": "0083ef67-79d9-4a33-92f4-6a52d2a99ddf",
"metadata": {
"tags": []
},
"outputs": [],
"source": [
"mv marlowe-semantics.plutus proposed.plutus"
]
},
{
"cell_type": "code",
"execution_count": 60,
"id": "3f3ac33a-5890-480b-874f-3e3039567dd6",
"metadata": {
"tags": []
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"PROPOSED_ADDR = addr_test1wqmhxfddsjj4hgpg9kzymledtu833sel6j3g5z5aw0r0vrg03kpfs\n"
]
}
],
"source": [
"PROPOSED_ADDR=$(marlowe_address proposed.plutus)\n",
"echo \"PROPOSED_ADDR = $PROPOSED_ADDR\""
]
},
{
"cell_type": "markdown",
"id": "eca0c457-e98d-4375-bc2e-41b9a9acb25e",
"metadata": {},
"source": [
"#### Create the contract"
]
},
{
"cell_type": "code",
"execution_count": 61,
"id": "35d3fa5d-d777-4f11-b57d-b760d56e7853",
"metadata": {
"tags": []
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"ac22144cc5312f9e3ec2c14415630902055797d83a9d3fd55e8ef912d2df8a5e\n"
]
}
],
"source": [
"$MARLOWE_CLI contract datum \\\n",
" --contract-file contract-1.json \\\n",
" --state-file state-1.json \\\n",
" --out-file test5-datum-1.json"
]
},
{
"cell_type": "code",
"execution_count": 62,
"id": "0619151e-20c9-43c2-a1f6-449202763db9",
"metadata": {
"tags": []
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Estimated transaction fee: Lovelace 176589\n"
]
}
],
"source": [
"build_creation \"$PROPOSED_ADDR\" test5-datum-1.json test5-tx-1.unsigned"
]
},
{
"cell_type": "code",
"execution_count": 63,
"id": "d63ece57-c31c-4e28-a333-7077b668c4f6",
"metadata": {
"tags": []
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"TEST5_TX_1 = 6bfff834546dc6242ee5265c06f140e6efa524d6c97cc17f57997274fee363f0\n"
]
}
],
"source": [
"TEST5_TX_1=$(sign_tx test5-tx-1.unsigned test5-tx-1.signed)\n",
"echo \"TEST5_TX_1 = $TEST5_TX_1\""
]
},
{
"cell_type": "code",
"execution_count": 64,
"id": "0aa57702-cb86-4e8c-a400-27e54451edb2",
"metadata": {
"tags": []
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Transaction successfully submitted.\n"
]
}
],
"source": [
"submit_tx test5-tx-1.signed"
]
},
{
"cell_type": "markdown",
"id": "043e250f-38c8-4fc8-8927-ab15718d88d5",
"metadata": {},
"source": [
"#### Apply the input"
]
},
{
"cell_type": "markdown",
"id": "5698a7c4-c1cc-48a0-8066-354b2de3488e",
"metadata": {},
"source": [
"##### New datum"
]
},
{
"cell_type": "code",
"execution_count": 65,
"id": "566f5acf-b2f9-447e-801e-7fe886de15da",
"metadata": {
"tags": []
},
"outputs": [],
"source": [
"INVALID_BEFORE=$(invalid_before)\n",
"INVALID_HEREAFTER=$(invalid_hereafter)"
]
},
{
"cell_type": "code",
"execution_count": 66,
"id": "495df078-ab40-43c7-8ca0-ec7ab01971e3",
"metadata": {
"tags": []
},
"outputs": [],
"source": [
"next_state \"$INVALID_BEFORE\" test5-state-2.json"
]
},
{
"cell_type": "code",
"execution_count": 67,
"id": "2e47bb45-52d6-4dc0-9046-3781ea6f0e19",
"metadata": {
"tags": []
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"7b7a6d68c87f6c79f383ea48ddb8f6c65aa5f83149c48522632a9d94ce874045\n"
]
}
],
"source": [
"$MARLOWE_CLI contract datum \\\n",
" --contract-file contract-2.json \\\n",
" --state-file test5-state-2.json \\\n",
" --out-file test5-datum-2.json"
]
},
{
"cell_type": "markdown",
"id": "c0002b48-736e-4aef-bb9c-e11528f558a6",
"metadata": {},
"source": [
"##### The transaction is validated, as it should be."
]
},
{
"cell_type": "code",
"execution_count": 68,
"id": "f356fea8-5d09-4900-a051-b06998886056",
"metadata": {
"tags": []
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Estimated transaction fee: Lovelace 877671\n"
]
}
],
"source": [
"apply_input \"$TEST5_TX_1#0\" \"$PROPOSED_ADDR\" proposed.plutus test5-datum-1.json test5-datum-2.json \"$INVALID_BEFORE\" \"$INVALID_HEREAFTER\" test5-tx-2.unsigned || false"
]
},
{
"cell_type": "code",
"execution_count": 69,
"id": "fb5a1235-529d-4473-9077-9b796f794165",
"metadata": {
"tags": []
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"TEST5_TX_2 = cca136f2ac06766676cf8171e2eb7dea2331465003b4a9cf22ab7c4d987f5984\n"
]
}
],
"source": [
"TEST5_TX_2=$(sign_tx test5-tx-2.unsigned test5-tx-2.signed)\n",
"echo \"TEST5_TX_2 = $TEST5_TX_2\""
]
},
{
"cell_type": "code",
"execution_count": 70,
"id": "5376d5fc-f58f-411f-8441-d4483d4871fc",
"metadata": {
"tags": []
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Transaction successfully submitted.\n"
]
}
],
"source": [
"submit_tx test5-tx-2.signed"
]
},
{
"cell_type": "markdown",
"id": "fe2428b3-6c0e-4d23-bcfc-343ad488223e",
"metadata": {},
"source": [
"### 6. Proposed validator with data corruption only in input datum"
]
},
{
"cell_type": "markdown",
"id": "b2610ac0-9c12-431b-bbb1-c0f9aeacf275",
"metadata": {},
"source": [
"#### Create the contract"
]
},
{
"cell_type": "code",
"execution_count": 71,
"id": "d3bb1381-9cda-4917-b9db-88c41aad10e9",
"metadata": {
"tags": []
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"ac22144cc5312f9e3ec2c14415630902055797d83a9d3fd55e8ef912d2df8a5e\n"
]
}
],
"source": [
"$MARLOWE_CLI contract datum \\\n",
" --contract-file contract-1.json \\\n",
" --state-file state-1.json \\\n",
" --out-file test6-datum-1-good.json"
]
},
{
"cell_type": "markdown",
"id": "e1fe1bb0-99e1-4b7a-a52d-640d9ac153c3",
"metadata": {},
"source": [
"##### Change the fourth `Close` in the blockly diagram to garbage (i.e., `Constr 0 []` becomes `Constr 1000 []`)."
]
},
{
"cell_type": "code",
"execution_count": 72,
"id": "6f9b2a63-d751-45bc-9176-f283274f753c",
"metadata": {
"tags": []
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
" 1\tconstructor: 0\n",
" 2\tfields:\n",
" 3\t- constructor: 0\n",
" 4\t fields:\n",
" 5\t - bytes: ''\n",
" 6\t- constructor: 0\n",
" 7\t fields:\n",
" 8\t - map:\n",
" 9\t - k:\n",
" 10\t constructor: 0\n",
" 11\t fields:\n",
" 12\t - constructor: 0\n",
" 13\t fields:\n",
" 14\t - constructor: 0\n",
" 15\t fields: []\n",
" 16\t - constructor: 0\n",
" 17\t fields:\n",
" 18\t - constructor: 0\n",
" 19\t fields:\n",
" 20\t - bytes: 0a11b0c7e25dc5d9c63171bdf39d9741b901dc903e12b4e162348e07\n",
" 21\t - constructor: 1\n",
" 22\t fields: []\n",
" 23\t - constructor: 0\n",
" 24\t fields:\n",
" 25\t - bytes: ''\n",
" 26\t - bytes: ''\n",
" 27\t v:\n",
" 28\t int: 2000000\n",
" 29\t - map: []\n",
" 30\t - map: []\n",
" 31\t - int: 1\n",
" 32\t- constructor: 3\n",
" 33\t fields:\n",
" 34\t - list:\n",
" 35\t - constructor: 0\n",
" 36\t fields:\n",
" 37\t - constructor: 2\n",
" 38\t fields:\n",
" 39\t - constructor: 9\n",
" 40\t fields: []\n",
" 41\t - constructor: 3\n",
" 42\t fields:\n",
" 43\t - list:\n",
" 44\t - constructor: 0\n",
" 45\t fields:\n",
" 46\t - constructor: 2\n",
" 47\t fields:\n",
" 48\t - constructor: 9\n",
" 49\t fields: []\n",
" 50\t - constructor: 0\n",
" 51\t fields: []\n",
" 52\t - int: 2000000000001\n",
" 53\t - constructor: 0\n",
" 54\t fields: []\n",
" 55\t - int: 2000000000000\n",
" 56\t - constructor: 3\n",
" 57\t fields:\n",
" 58\t - list:\n",
" 59\t - constructor: 0\n",
" 60\t fields:\n",
" 61\t - constructor: 2\n",
" 62\t fields:\n",
" 63\t - constructor: 9\n",
" 64\t fields: []\n",
" 65\t - constructor: 0\n",
" 66\t fields: []\n",
" 67\t - int: 2000000000001\n",
" 68\t - constructor: 1000\n",
" 69\t fields: []\n"
]
}
],
"source": [
"json2yaml test6-datum-1-good.json | sed -e '68s/0/1000/' | yaml2json > test6-datum-1-bad.json\n",
"json2yaml test6-datum-1-bad.json | nl"
]
},
{
"cell_type": "code",
"execution_count": 73,
"id": "1ed88288-b34c-4216-974f-3a4689fcf744",
"metadata": {
"tags": []
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Estimated transaction fee: Lovelace 176765\n"
]
}
],
"source": [
"build_creation \"$PROPOSED_ADDR\" test6-datum-1-bad.json test6-tx-1.unsigned"
]
},
{
"cell_type": "code",
"execution_count": 74,
"id": "072b3cb8-f6ad-408d-aaf7-f926bf48020f",
"metadata": {
"tags": []
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"TEST6_TX_1 = 5554f73eb622487a575fec75223158210cf9044d769aba2a554a7a45709b0482\n"
]
}
],
"source": [
"TEST6_TX_1=$(sign_tx test6-tx-1.unsigned test6-tx-1.signed)\n",
"echo \"TEST6_TX_1 = $TEST6_TX_1\""
]
},
{
"cell_type": "code",
"execution_count": 75,
"id": "e5f9fb0a-f2c8-4d64-b227-518c36da89d5",
"metadata": {
"tags": []
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Transaction successfully submitted.\n"
]
}
],
"source": [
"submit_tx test6-tx-1.signed"
]
},
{
"cell_type": "markdown",
"id": "f3a13352-27a0-4fce-9aff-a6dd09855a74",
"metadata": {},
"source": [
"#### Apply the input"
]
},
{
"cell_type": "markdown",
"id": "b1b8b6e8-2d6f-4651-9252-99635a049e42",
"metadata": {},
"source": [
"##### New datum"
]
},
{
"cell_type": "code",
"execution_count": 76,
"id": "0720e258-d011-4f94-8444-43c89a718efe",
"metadata": {
"tags": []
},
"outputs": [],
"source": [
"INVALID_BEFORE=$(invalid_before)\n",
"INVALID_HEREAFTER=$(invalid_hereafter)"
]
},
{
"cell_type": "code",
"execution_count": 77,
"id": "d0c16fce-3e07-4f33-987e-9d92bcb817f5",
"metadata": {
"tags": []
},
"outputs": [],
"source": [
"next_state \"$INVALID_BEFORE\" test6-state-2.json"
]
},
{
"cell_type": "code",
"execution_count": 78,
"id": "7e45f6ad-3920-48ca-baea-7de91cb23836",
"metadata": {
"tags": []
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"931f926f1c9d41815790b73e9c7fdea706714924e224a611578737b01ed686dc\n"
]
}
],
"source": [
"$MARLOWE_CLI contract datum \\\n",
" --contract-file contract-2.json \\\n",
" --state-file test6-state-2.json \\\n",
" --out-file test6-datum-2.json"
]
},
{
"cell_type": "markdown",
"id": "ff5e1e7a-85cc-467b-86cf-d1b7fb0780b8",
"metadata": {},
"source": [
"##### The transaction is rejected, as it should be."
]
},
{
"cell_type": "code",
"execution_count": 79,
"id": "4347ee39-8abe-4712-984c-a6eea5862e6a",
"metadata": {
"tags": []
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Command failed: transaction build Error: The following scripts have execution failures:\n",
"the script for transaction input 0 (in ascending order of the TxIds) failed with: \n",
"The Plutus script evaluation failed: An error has occurred: User error:\n",
"The machine terminated because of an error, either from a built-in function or from an explicit use of 'error'.\n",
"Script debugging logs: PT1\n",
"\n",
"\n"
]
}
],
"source": [
"apply_input \"$TEST6_TX_1#0\" \"$PROPOSED_ADDR\" proposed.plutus test6-datum-1-bad.json test6-datum-2.json \"$INVALID_BEFORE\" \"$INVALID_HEREAFTER\" test6-tx-2.unsigned || true"
]
},
{
"cell_type": "markdown",
"id": "f9c3e3fc-7e35-41b5-adfa-a31292b225b6",
"metadata": {},
"source": [
"### 7. Proposed validator with data corruption in input and output datum nested at root"
]
},
{
"cell_type": "markdown",
"id": "d2f7ca2f-ced2-46a2-8d2c-15c976cd672a",
"metadata": {},
"source": [
"#### Create the contract"
]
},
{
"cell_type": "code",
"execution_count": 80,
"id": "be12be1e-6efd-4b23-8948-e328bda33da9",
"metadata": {
"tags": []
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"ac22144cc5312f9e3ec2c14415630902055797d83a9d3fd55e8ef912d2df8a5e\n"
]
}
],
"source": [
"$MARLOWE_CLI contract datum \\\n",
" --contract-file contract-1.json \\\n",
" --state-file state-1.json \\\n",
" --out-file test7-datum-1-good.json"
]
},
{
"cell_type": "markdown",
"id": "5bebb3a2-b3db-44a1-b1e7-a8ebb58fb8cc",
"metadata": {},
"source": [
"##### Change the second `Close` in the blockly diagram to garbage (i.e., `Constr 0 []` becomes `Constr 1000 []`)."
]
},
{
"cell_type": "code",
"execution_count": 81,
"id": "445ee9de-d170-42bd-b2a9-462fe4176e59",
"metadata": {
"tags": []
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
" 1\tconstructor: 0\n",
" 2\tfields:\n",
" 3\t- constructor: 0\n",
" 4\t fields:\n",
" 5\t - bytes: ''\n",
" 6\t- constructor: 0\n",
" 7\t fields:\n",
" 8\t - map:\n",
" 9\t - k:\n",
" 10\t constructor: 0\n",
" 11\t fields:\n",
" 12\t - constructor: 0\n",
" 13\t fields:\n",
" 14\t - constructor: 0\n",
" 15\t fields: []\n",
" 16\t - constructor: 0\n",
" 17\t fields:\n",
" 18\t - constructor: 0\n",
" 19\t fields:\n",
" 20\t - bytes: 0a11b0c7e25dc5d9c63171bdf39d9741b901dc903e12b4e162348e07\n",
" 21\t - constructor: 1\n",
" 22\t fields: []\n",
" 23\t - constructor: 0\n",
" 24\t fields:\n",
" 25\t - bytes: ''\n",
" 26\t - bytes: ''\n",
" 27\t v:\n",
" 28\t int: 2000000\n",
" 29\t - map: []\n",
" 30\t - map: []\n",
" 31\t - int: 1\n",
" 32\t- constructor: 3\n",
" 33\t fields:\n",
" 34\t - list:\n",
" 35\t - constructor: 0\n",
" 36\t fields:\n",
" 37\t - constructor: 2\n",
" 38\t fields:\n",
" 39\t - constructor: 9\n",
" 40\t fields: []\n",
" 41\t - constructor: 3\n",
" 42\t fields:\n",
" 43\t - list:\n",
" 44\t - constructor: 0\n",
" 45\t fields:\n",
" 46\t - constructor: 2\n",
" 47\t fields:\n",
" 48\t - constructor: 9\n",
" 49\t fields: []\n",
" 50\t - constructor: 0\n",
" 51\t fields: []\n",
" 52\t - int: 2000000000001\n",
" 53\t - constructor: 1000\n",
" 54\t fields: []\n",
" 55\t - int: 2000000000000\n",
" 56\t - constructor: 3\n",
" 57\t fields:\n",
" 58\t - list:\n",
" 59\t - constructor: 0\n",
" 60\t fields:\n",
" 61\t - constructor: 2\n",
" 62\t fields:\n",
" 63\t - constructor: 9\n",
" 64\t fields: []\n",
" 65\t - constructor: 0\n",
" 66\t fields: []\n",
" 67\t - int: 2000000000001\n",
" 68\t - constructor: 0\n",
" 69\t fields: []\n"
]
}
],
"source": [
"json2yaml test7-datum-1-good.json | sed -e '53s/0/1000/' | yaml2json > test7-datum-1-bad.json\n",
"json2yaml test7-datum-1-bad.json | nl"
]
},
{
"cell_type": "code",
"execution_count": 82,
"id": "bdfcb1f8-e58e-4954-9f02-95605d6ee231",
"metadata": {
"tags": []
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Estimated transaction fee: Lovelace 176765\n"
]
}
],
"source": [
"build_creation \"$PROPOSED_ADDR\" test7-datum-1-bad.json test7-tx-1.unsigned"
]
},
{
"cell_type": "code",
"execution_count": 83,
"id": "a2d25ac3-ccab-4cf4-9320-304eab4ddd5c",
"metadata": {
"tags": []
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"TEST7_TX_1 = 523d5bc03d121433448a78eee52e4e4c4b1ff0215e27966618dcb88c35c3dba3\n"
]
}
],
"source": [
"TEST7_TX_1=$(sign_tx test7-tx-1.unsigned test7-tx-1.signed)\n",
"echo \"TEST7_TX_1 = $TEST7_TX_1\""
]
},
{
"cell_type": "code",
"execution_count": 84,
"id": "1dc0c13e-95e4-4e52-ac31-650e95e1add0",
"metadata": {
"tags": []
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Transaction successfully submitted.\n"
]
}
],
"source": [
"submit_tx test7-tx-1.signed"
]
},
{
"cell_type": "markdown",
"id": "91b681f9-a8aa-400c-a208-e169b2a82b93",
"metadata": {},
"source": [
"#### Apply the input"
]
},
{
"cell_type": "markdown",
"id": "20d7d795-db72-4cde-bcb8-0177dced4b3d",
"metadata": {},
"source": [
"##### New datum"
]
},
{
"cell_type": "code",
"execution_count": 85,
"id": "f207114c-5d35-48db-a1d4-3ff2de0ba67d",
"metadata": {
"tags": []
},
"outputs": [],
"source": [
"INVALID_BEFORE=$(invalid_before)\n",
"INVALID_HEREAFTER=$(invalid_hereafter)"
]
},
{
"cell_type": "code",
"execution_count": 86,
"id": "effaabf6-2fd0-48f7-a536-2c82890750ce",
"metadata": {
"tags": []
},
"outputs": [],
"source": [
"next_state \"$INVALID_BEFORE\" test7-state-2.json"
]
},
{
"cell_type": "code",
"execution_count": 87,
"id": "514d7bc0-9c8c-4f4b-b396-f130de18a5f7",
"metadata": {
"tags": []
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"b72a536733c23210cbc11bbd8257138254a30134fcb2075d9399187a0c1cbbab\n"
]
}
],
"source": [
"$MARLOWE_CLI contract datum \\\n",
" --contract-file contract-2.json \\\n",
" --state-file test7-state-2.json \\\n",
" --out-file test7-datum-2-good.json"
]
},
{
"cell_type": "code",
"execution_count": 88,
"id": "b84f0d21-6685-4a3c-ab31-1bd45be900f5",
"metadata": {
"tags": []
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
" 1\tconstructor: 0\n",
" 2\tfields:\n",
" 3\t- constructor: 0\n",
" 4\t fields:\n",
" 5\t - bytes: ''\n",
" 6\t- constructor: 0\n",
" 7\t fields:\n",
" 8\t - map:\n",
" 9\t - k:\n",
" 10\t constructor: 0\n",
" 11\t fields:\n",
" 12\t - constructor: 0\n",
" 13\t fields:\n",
" 14\t - constructor: 0\n",
" 15\t fields: []\n",
" 16\t - constructor: 0\n",
" 17\t fields:\n",
" 18\t - constructor: 0\n",
" 19\t fields:\n",
" 20\t - bytes: 0a11b0c7e25dc5d9c63171bdf39d9741b901dc903e12b4e162348e07\n",
" 21\t - constructor: 1\n",
" 22\t fields: []\n",
" 23\t - constructor: 0\n",
" 24\t fields:\n",
" 25\t - bytes: ''\n",
" 26\t - bytes: ''\n",
" 27\t v:\n",
" 28\t int: 2000000\n",
" 29\t - map: []\n",
" 30\t - map: []\n",
" 31\t - int: 1703263742000\n",
" 32\t- constructor: 3\n",
" 33\t fields:\n",
" 34\t - list:\n",
" 35\t - constructor: 0\n",
" 36\t fields:\n",
" 37\t - constructor: 2\n",
" 38\t fields:\n",
" 39\t - constructor: 9\n",
" 40\t fields: []\n",
" 41\t - constructor: 0\n",
" 42\t fields: []\n",
" 43\t - int: 2000000000001\n",
" 44\t - constructor: 1000\n",
" 45\t fields: []\n"
]
}
],
"source": [
"json2yaml test7-datum-2-good.json | sed -e '44s/0/1000/' | yaml2json > test7-datum-2-bad.json\n",
"json2yaml test7-datum-2-bad.json | nl"
]
},
{
"cell_type": "markdown",
"id": "4ec2edf0-723c-4eee-b044-c04893caeaff",
"metadata": {},
"source": [
"##### The transaction is rejected, as it should be."
]
},
{
"cell_type": "code",
"execution_count": 89,
"id": "219f4dc0-c54f-4152-b576-f165d509c595",
"metadata": {
"tags": []
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Command failed: transaction build Error: The following scripts have execution failures:\n",
"the script for transaction input 0 (in ascending order of the TxIds) failed with: \n",
"The Plutus script evaluation failed: An error has occurred: User error:\n",
"The machine terminated because of an error, either from a built-in function or from an explicit use of 'error'.\n",
"Script debugging logs: PT1\n",
"\n",
"\n"
]
}
],
"source": [
"apply_input \"$TEST7_TX_1#0\" \"$PROPOSED_ADDR\" proposed.plutus test7-datum-1-bad.json test7-datum-2-bad.json \"$INVALID_BEFORE\" \"$INVALID_HEREAFTER\" test7-tx-2.unsigned || true"
]
},
{
"cell_type": "markdown",
"id": "dab6a5cb-d151-4f3d-bf6b-07ece4f33fc5",
"metadata": {},
"source": [
"### 8. Proposed validator with data corruption in input and output datum deeply nested"
]
},
{
"cell_type": "markdown",
"id": "d4333c5b-e9ae-4b3f-8c22-40a76510e62e",
"metadata": {},
"source": [
"#### Create the contract"
]
},
{
"cell_type": "code",
"execution_count": 90,
"id": "93be634b-41c5-42ee-b3a9-a087dcf3db21",
"metadata": {
"tags": []
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"ac22144cc5312f9e3ec2c14415630902055797d83a9d3fd55e8ef912d2df8a5e\n"
]
}
],
"source": [
"$MARLOWE_CLI contract datum \\\n",
" --contract-file contract-1.json \\\n",
" --state-file state-1.json \\\n",
" --out-file test8-datum-1-good.json"
]
},
{
"cell_type": "markdown",
"id": "e07bb15a-0545-4650-9f41-683cd219e48c",
"metadata": {},
"source": [
"##### Change the first `Close` in the blockly diagram to garbage (i.e., `Constr 0 []` becomes `Constr 1000 []`)."
]
},
{
"cell_type": "code",
"execution_count": 91,
"id": "fba6b9dc-8b53-4342-89a8-50b4b787656f",
"metadata": {
"tags": []
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
" 1\tconstructor: 0\n",
" 2\tfields:\n",
" 3\t- constructor: 0\n",
" 4\t fields:\n",
" 5\t - bytes: ''\n",
" 6\t- constructor: 0\n",
" 7\t fields:\n",
" 8\t - map:\n",
" 9\t - k:\n",
" 10\t constructor: 0\n",
" 11\t fields:\n",
" 12\t - constructor: 0\n",
" 13\t fields:\n",
" 14\t - constructor: 0\n",
" 15\t fields: []\n",
" 16\t - constructor: 0\n",
" 17\t fields:\n",
" 18\t - constructor: 0\n",
" 19\t fields:\n",
" 20\t - bytes: 0a11b0c7e25dc5d9c63171bdf39d9741b901dc903e12b4e162348e07\n",
" 21\t - constructor: 1\n",
" 22\t fields: []\n",
" 23\t - constructor: 0\n",
" 24\t fields:\n",
" 25\t - bytes: ''\n",
" 26\t - bytes: ''\n",
" 27\t v:\n",
" 28\t int: 2000000\n",
" 29\t - map: []\n",
" 30\t - map: []\n",
" 31\t - int: 1\n",
" 32\t- constructor: 3\n",
" 33\t fields:\n",
" 34\t - list:\n",
" 35\t - constructor: 0\n",
" 36\t fields:\n",
" 37\t - constructor: 2\n",
" 38\t fields:\n",
" 39\t - constructor: 9\n",
" 40\t fields: []\n",
" 41\t - constructor: 3\n",
" 42\t fields:\n",
" 43\t - list:\n",
" 44\t - constructor: 0\n",
" 45\t fields:\n",
" 46\t - constructor: 2\n",
" 47\t fields:\n",
" 48\t - constructor: 9\n",
" 49\t fields: []\n",
" 50\t - constructor: 1000\n",
" 51\t fields: []\n",
" 52\t - int: 2000000000001\n",
" 53\t - constructor: 0\n",
" 54\t fields: []\n",
" 55\t - int: 2000000000000\n",
" 56\t - constructor: 3\n",
" 57\t fields:\n",
" 58\t - list:\n",
" 59\t - constructor: 0\n",
" 60\t fields:\n",
" 61\t - constructor: 2\n",
" 62\t fields:\n",
" 63\t - constructor: 9\n",
" 64\t fields: []\n",
" 65\t - constructor: 0\n",
" 66\t fields: []\n",
" 67\t - int: 2000000000001\n",
" 68\t - constructor: 0\n",
" 69\t fields: []\n"
]
}
],
"source": [
"json2yaml test8-datum-1-good.json | sed -e '50s/0/1000/' | yaml2json > test8-datum-1-bad.json\n",
"json2yaml test8-datum-1-bad.json | nl"
]
},
{
"cell_type": "code",
"execution_count": 92,
"id": "b8d93ebc-64c7-41c8-9459-121ad32c00ac",
"metadata": {
"tags": []
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Estimated transaction fee: Lovelace 176765\n"
]
}
],
"source": [
"build_creation \"$PROPOSED_ADDR\" test8-datum-1-bad.json test8-tx-1.unsigned"
]
},
{
"cell_type": "code",
"execution_count": 93,
"id": "9135058f-b56c-4d0e-bc70-120a1d5d4cb9",
"metadata": {
"tags": []
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"TEST8_TX_1 = 4af9f9cc8678f1b6c082ba9599fde987d5e2bc4b6188d77726a3e826f6e6b770\n"
]
}
],
"source": [
"TEST8_TX_1=$(sign_tx test8-tx-1.unsigned test8-tx-1.signed)\n",
"echo \"TEST8_TX_1 = $TEST8_TX_1\""
]
},
{
"cell_type": "code",
"execution_count": 94,
"id": "a4949cd6-66b6-47fc-8c98-a7ce499a52d5",
"metadata": {
"tags": []
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Transaction successfully submitted.\n"
]
}
],
"source": [
"submit_tx test8-tx-1.signed"
]
},
{
"cell_type": "markdown",
"id": "784f69b5-41eb-4544-82cf-d10665e3b9ab",
"metadata": {},
"source": [
"#### Apply the input"
]
},
{
"cell_type": "markdown",
"id": "a06e80dd-3ef2-43b7-9620-0714306d437a",
"metadata": {},
"source": [
"##### New datum"
]
},
{
"cell_type": "code",
"execution_count": 95,
"id": "061a5c02-4024-4e23-8cc3-8a19ee898d00",
"metadata": {
"tags": []
},
"outputs": [],
"source": [
"INVALID_BEFORE=$(invalid_before)\n",
"INVALID_HEREAFTER=$(invalid_hereafter)"
]
},
{
"cell_type": "code",
"execution_count": 96,
"id": "1c5a5b03-8a47-4ba0-88a8-d81d7afac3df",
"metadata": {
"tags": []
},
"outputs": [],
"source": [
"next_state \"$INVALID_BEFORE\" test8-state-2.json"
]
},
{
"cell_type": "code",
"execution_count": 97,
"id": "2b2c6564-b80d-4cae-aa8a-b4d77f348cfa",
"metadata": {
"tags": []
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"40df2b4afd421f3ee5ec5d3a83de115d27268d1b1023cb6f580354d176a4da51\n"
]
}
],
"source": [
"$MARLOWE_CLI contract datum \\\n",
" --contract-file contract-2.json \\\n",
" --state-file test8-state-2.json \\\n",
" --out-file test8-datum-2-good.json"
]
},
{
"cell_type": "code",
"execution_count": 98,
"id": "7614fbd2-f8d8-4017-a5bd-267a888f3fd7",
"metadata": {
"tags": []
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
" 1\tconstructor: 0\n",
" 2\tfields:\n",
" 3\t- constructor: 0\n",
" 4\t fields:\n",
" 5\t - bytes: ''\n",
" 6\t- constructor: 0\n",
" 7\t fields:\n",
" 8\t - map:\n",
" 9\t - k:\n",
" 10\t constructor: 0\n",
" 11\t fields:\n",
" 12\t - constructor: 0\n",
" 13\t fields:\n",
" 14\t - constructor: 0\n",
" 15\t fields: []\n",
" 16\t - constructor: 0\n",
" 17\t fields:\n",
" 18\t - constructor: 0\n",
" 19\t fields:\n",
" 20\t - bytes: 0a11b0c7e25dc5d9c63171bdf39d9741b901dc903e12b4e162348e07\n",
" 21\t - constructor: 1\n",
" 22\t fields: []\n",
" 23\t - constructor: 0\n",
" 24\t fields:\n",
" 25\t - bytes: ''\n",
" 26\t - bytes: ''\n",
" 27\t v:\n",
" 28\t int: 2000000\n",
" 29\t - map: []\n",
" 30\t - map: []\n",
" 31\t - int: 1703263759000\n",
" 32\t- constructor: 3\n",
" 33\t fields:\n",
" 34\t - list:\n",
" 35\t - constructor: 0\n",
" 36\t fields:\n",
" 37\t - constructor: 2\n",
" 38\t fields:\n",
" 39\t - constructor: 9\n",
" 40\t fields: []\n",
" 41\t - constructor: 1000\n",
" 42\t fields: []\n",
" 43\t - int: 2000000000001\n",
" 44\t - constructor: 0\n",
" 45\t fields: []\n"
]
}
],
"source": [
"json2yaml test8-datum-2-good.json | sed -e '41s/0/1000/' | yaml2json > test8-datum-2-bad.json\n",
"json2yaml test8-datum-2-bad.json | nl"
]
},
{
"cell_type": "markdown",
"id": "1ea8fbc3-c2f2-4df7-a1a3-62db260833cc",
"metadata": {},
"source": [
"##### The transaction is validated, even though a later part of the contract is corrupted."
]
},
{
"cell_type": "code",
"execution_count": 99,
"id": "6327bc57-0549-4c21-afbf-63b3dfd5aa92",
"metadata": {
"tags": []
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Estimated transaction fee: Lovelace 878598\n"
]
}
],
"source": [
"apply_input \"$TEST8_TX_1#0\" \"$PROPOSED_ADDR\" proposed.plutus test8-datum-1-bad.json test8-datum-2-bad.json \"$INVALID_BEFORE\" \"$INVALID_HEREAFTER\" test8-tx-2.unsigned || false"
]
},
{
"cell_type": "code",
"execution_count": 100,
"id": "5c28f8d4-2ab7-4d9f-9288-3c6a616d0a0d",
"metadata": {
"tags": []
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"TEST8_TX_2 = 54198396ed817bf34f195946d0d640a1d3ec592c3c3bc3eca8f19625d9051b5a\n"
]
}
],
"source": [
"TEST8_TX_2=$(sign_tx test8-tx-2.unsigned test8-tx-2.signed)\n",
"echo \"TEST8_TX_2 = $TEST8_TX_2\""
]
},
{
"cell_type": "code",
"execution_count": 101,
"id": "6e194943-c09c-452e-9d02-919e9d7f4d23",
"metadata": {
"tags": []
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Transaction successfully submitted.\n"
]
}
],
"source": [
"submit_tx test8-tx-2.signed"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "bash-minimal kernel",
"language": "bash",
"name": "bash-minimal"
},
"language_info": {
"codemirror_mode": "shell",
"file_extension": ".sh",
"mimetype": "text/x-sh",
"name": "bash"
}
},
"nbformat": 4,
"nbformat_minor": 5
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment