1

I'm experiment with building SegWit transactions manually, and I've written a non-standard simple script just for testing. No signing or anything, just your usual "add two numbers, check equality" script. However, when attempting to broadcast it, I get an error.

I already sent the coins to the script, now I'm just trying to spend from it.

Here is my input:

{
  "txid": "174692a9b447d62043b90059c83237b0526bc09551aa39839a1d4fafc29252b7",
  "hash": "27afb30315f82dd64815ef259b7f4075359d42390f549b9a05132d11cf0d5670",
  "version": 2,
  "size": 205,
  "vsize": 154,
  "weight": 616,
  "locktime": 206,
  "vin": [
    {
      "txid": "1e025a8b1af84f4b7f0724b89ed0fc3b0ee6f2e8d1c0b635827edf6f60a0ff9e",
      "vout": 0,
      "scriptSig": {
        "asm": "",
        "hex": ""
      },
      "txinwitness": [
        "2b8aac44cbfe12c56ddfd1ff2a0021c6f9b4e76b0325b44a647365ae9e695044029f6f7eb409baee56803e80e47a643711703795c955a8bdc5a0abc5761902fe"
      ],
      "sequence": 4294967293
    }
  ],
  "vout": [
    {
      "value": 1.00000000,
      "n": 0,
      "scriptPubKey": {
        "asm": "0 8b88aeecc8810057147ae75bb5fef0b88e74cdd69877a0b0d9119cbc0a13bd18",
        "desc": "addr(bcrt1q3wy2amxgsyq9w9r6uadmtlhshz88fnwknpm6pvxezxwtczsnh5vq8ynwca)#88xz032h",
        "hex": "00208b88aeecc8810057147ae75bb5fef0b88e74cdd69877a0b0d9119cbc0a13bd18",
        "address": "bcrt1q3wy2amxgsyq9w9r6uadmtlhshz88fnwknpm6pvxezxwtczsnh5vq8ynwca",
        "type": "witness_v0_scripthash"
      }
    },
    {
      "value": 46.99952700,
      "n": 1,
      "scriptPubKey": {
        "asm": "1 ab0af65a053979dfd08b9673405900f185b6d45edea4dddd5dec9b7ec2eba5fc",
        "desc": "rawtr(ab0af65a053979dfd08b9673405900f185b6d45edea4dddd5dec9b7ec2eba5fc)#utsgce08",
        "hex": "5120ab0af65a053979dfd08b9673405900f185b6d45edea4dddd5dec9b7ec2eba5fc",
        "address": "bcrt1p4v90vks989ual5ytjee5qkgq7xzmd4z7m6jdmh2aajdhasht5h7qx008qn",
        "type": "witness_v1_taproot"
      }
    }
  ]
}

Vout 0 is the output of interest here.

Here is my decoded transaction when I attempt to spend it:

{
  "txid": "0110d9fd63ec46c2b47bc589d2f032d10f288912e4d82c88c8aaa1dfed251909",
  "hash": "08881deca20dc914f14a03d5caf97bd4b7c717ef9047b1a6f70f5deb44eb8545",
  "version": 1,
  "size": 96,
  "vsize": 86,
  "weight": 342,
  "locktime": 0,
  "vin": [
    {
      "txid": "174692a9b447d62043b90059c83237b0526bc09551aa39839a1d4fafc29252b7",
      "vout": 0,
      "scriptSig": {
        "asm": "",
        "hex": ""
      },
      "txinwitness": [
        "63000000",
        "5193016487"
      ],
      "sequence": 0
    }
  ],
  "vout": [
    {
      "value": 0.50000000,
      "n": 0,
      "scriptPubKey": {
        "asm": "0 43620bf89a7acd30cc09914e023cdce377e70828",
        "desc": "addr(bcrt1qgd3qh7y60txnpnqfj98qy0xuudm7wzpgz5c02y)#thrxqf0c",
        "hex": "001443620bf89a7acd30cc09914e023cdce377e70828",
        "address": "bcrt1qgd3qh7y60txnpnqfj98qy0xuudm7wzpgz5c02y",
        "type": "witness_v0_keyhash"
      }
    }
  ]
}

The witness script (5193016487) is 1 OP_ADD 100 OP_EQUAL. The witness stack also has 99 (63000000).

Why do I get this verify error when I attempt to broadcast it?

error code: -26
error message:
non-mandatory-script-verify-flag (unknown error)

2 Answers 2

1

You need to encode the number 99 (0x63000000) as a single byte (0x63) because

  • OP_ADD returns the result in the fewest bytes sufficient to store the value and because
  • OP_EQUAL takes the length of its operands into account. For example it considers 0x63 to be not equal to 0x6300.

I played around with a script debugger to check the length of the value returned by OP_ADD and the effect of operand lengths on OP_EQUAL.


Related

0

Finally got it. Turns out I needed to encode the number on the witness stack as a single byte. 63 instead of 63000000.

I don't suppose anyone can explain why that is necessary?

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.