Skip to content

p2tr script path: invalid script (witness stack last element) #154

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

Open
panicfarm opened this issue Jul 23, 2024 · 3 comments
Open

p2tr script path: invalid script (witness stack last element) #154

panicfarm opened this issue Jul 23, 2024 · 3 comments

Comments

@panicfarm
Copy link

panicfarm commented Jul 23, 2024

I created and successfully mined a regtest network transaction that spent two p2tr script-path outputs. The scripts where 1 of 2 multisigs:

DESCRIPTOR_VOUT0="tr($UNSPENDABLE_BIP341,multi_a(1,0327adc7f1cde671f02a01e39b33754d480a42670f95f951d9fb72f84aee5d7878,021856595019d8211e061b91911357cee2b9e683aa023a2744245fb05b7893a812))"
DESCRIPTOR_VOUT1="tr($UNSPENDABLE_BIP341,multi_a(1,028d8b9b2d93fd38c31005b05bc1c60e95cf5068a665360516685ce65d66819b86,021856595019d8211e061b91911357cee2b9e683aa023a2744245fb05b7893a812))"

The transaction was accepted by the regtest network bitcoin-core 0.25 and successfully mined. Trying to verify it with btcdeb, I got invalid script (witness stack last element) error:

$btcdeb -s 0 --tx=020000000001027eed70a2a6f3fd1ed05972f7cc0aa245033d4e538c5d4928e027e292f262e3ff0000000000fdffffff7eed70a2a6f3fd1ed05972f7cc0aa245033d4e538c5d4928e027e292f262e3ff0100000000fdffffff0100e1f5050000000022512093f6840b7dd8f6abc80d9675b7e28b929519316b5c6be39695f149a085f5b661040040f409bf08c40e63732327150b2581cde3afdfb7e9038f8d47c92a5cfd6c5fd9fc7179695e4db11a4a86dbb113deac1a57e8b113a96e2b3736ff959709cd4bdef7462027adc7f1cde671f02a01e39b33754d480a42670f95f951d9fb72f84aee5d7878ac201856595019d8211e061b91911357cee2b9e683aa023a2744245fb05b7893a812ba519c21c050929b74c1a04954b78b4b6035e97a5e078a5a0f28ec96d547bfee9ace803ac0040040b5769e66e31556e49441fb2a9a39db7c3a20d5782670b43c7d6cf248d7ba87c50ebd9aa65815693f72b83cbc34e80ed4edb3a7ca06e32db6b2384166b0934a7c46208d8b9b2d93fd38c31005b05bc1c60e95cf5068a665360516685ce65d66819b86ac201856595019d8211e061b91911357cee2b9e683aa023a2744245fb05b7893a812ba519c21c050929b74c1a04954b78b4b6035e97a5e078a5a0f28ec96d547bfee9ace803ac000000000 --txin=02000000000103f8b9481805180ead77b0bb773b3b41e045f7288d937633d291928141faf967eb00000000910047304402203ddd89c6e9a680f2922bfcc197f34fb17e2ef601d74a43f6d30767aa52e5ac3d02203994e8f2e6c46de0a87be87c6636f367dec2bc35e1386d574143d39e351bba3a01475121024fddf183fad49c01d1d281f94e9d79ad286f6498347faf4b33bf5ad6bac1d1582103295d76c56065ee78e5a14174da0759f8bbbea5a4017bb38a2aa6842ac0cb56a252aefdfffffff8b9481805180ead77b0bb773b3b41e045f7288d937633d291928141faf967eb0100000000fdffffff3b85bc34f079df21cb1e4467235d9d07d3a5db23297e88f39ec162c624a8ebe60000000000fdffffff0300e1f505000000002251209e08466dc0201e1a4cf77640210dbfd986d99669b7d5b17e664d9f855e5c702c00e1f5050000000022512058da1e1524d3ccde9024fbc3ff89a47c470e0ea7ac54b8859229f32308f18d0800a3e111000000001976a914dba4f00c333269440e726c2138c098089cecf65488ac00030047304402205eebdfa5ca1a8afc86a3ece97e3cbcc7218dc1ded6067dbbcccd1ff94ecc62d50220673f189a048125bb7f0896659320cbfecc0f6b9487839752eade8d03233a1435016951210327adc7f1cde671f02a01e39b33754d480a42670f95f951d9fb72f84aee5d78782102eeb99fe49aa809e22a1fe636f6b4b03199bd69b227d91fc2bb5d9c2188e3eabc21021856595019d8211e061b91911357cee2b9e683aa023a2744245fb05b7893a81253ae0400473044022053622215fbb232eb89e37f2ed78f08f1ec12a764a513261763d505ab9cf4df1702201a6ce9c780c43b1a82913bd4e2817b264da2c9f9bfeaa16c7a42c00d3f878f6b0147304402201d1a484921b85886bc9f5e412ae6c8ea306747f8e4994c8f39a627e1db688b0d02203d9b188e2a90f6f2982025671702b72ce92ade4cdc62e175e502f62f8e346f720147522102eeb99fe49aa809e22a1fe636f6b4b03199bd69b227d91fc2bb5d9c2188e3eabc210351dc2689f37c6eb017e5815cb49e6de435f69c6df1910e817a370880b224a13d52ae00000000
btcdeb 5.0.24 -- type `btcdeb -h` for start up options
LOG: signing segwit taproot
notice: btcdeb has gotten quieter; use --verbose if necessary (this message is temporary)
input tx index = 0; tx input vout = 0; value = 100000000
got witness stack of size 4
34 bytes (v0=P2WSH, v1=taproot/tapscript)
Taproot commitment:
- control  = c050929b74c1a04954b78b4b6035e97a5e078a5a0f28ec96d547bfee9ace803ac0
- program  = 9e08466dc0201e1a4cf77640210dbfd986d99669b7d5b17e664d9f855e5c702c
- script   = 2027adc7f1cde671f02a01e39b33754d480a42670f95f951d9fb72f84aee5d7878ac201856595019d8211e061b91911357cee2b9e683aa023a2744245fb05b7893a812ba519c
- path len = 0
- p        = 50929b74c1a04954b78b4b6035e97a5e078a5a0f28ec96d547bfee9ace803ac0
- q        = 9e08466dc0201e1a4cf77640210dbfd986d99669b7d5b17e664d9f855e5c702c
- k        = 8ce7142d2b807fd784ca36efa908ebb2cce6a5b1a7145d8331242f054665a5ee          (tap leaf hash)
  (TapLeaf(0xc0 || 2027adc7f1cde671f02a01e39b33754d480a42670f95f951d9fb72f84aee5d7878ac201856595019d8211e061b91911357cee2b9e683aa023a2744245fb05b7893a812ba519c))
invalid script (witness stack last element)

I tried to decode the tapscript with bitcoin-cli, and noticed that it was labeled "nonstandard" and that the keys that I put in the descriptors lost their parity prefixes and became x-only keys:

$ bitcoin-cli -regtest decodescript 2027adc7f1cde671f02a01e39b33754d480a42670f95f951d9fb72f84aee5d7878ac201856595019d8211e061b91911357cee2b9e683aa023a2744245fb05b7893a812ba519c
{
  "asm": "27adc7f1cde671f02a01e39b33754d480a42670f95f951d9fb72f84aee5d7878 OP_CHECKSIG 1856595019d8211e061b91911357cee2b9e683aa023a2744245fb05b7893a812 OP_CHECKSIGADD 1 OP_NUMEQUAL",
  "desc": "raw(2027adc7f1cde671f02a01e39b33754d480a42670f95f951d9fb72f84aee5d7878ac201856595019d8211e061b91911357cee2b9e683aa023a2744245fb05b7893a812ba519c)#jhjz42cq",
  "type": "nonstandard"
}

What is the reason for this invalid script (witness stack last element) error, while the transaction was accepted by the core v0.25 and mined successfully?

@kallewoof
Copy link
Contributor

This may be due to btcdeb not being updated to latest core base. I plan to do this but work keeps getting in my way. Plan to get to this ASAP but will take a couple weeks.

@jdlcdl
Copy link

jdlcdl commented Feb 6, 2025

I believe that I'm experiencing a similar issue, however I'm so new to btcdeb that it's likely user error.

Im trying to debug a tapscript spend from earlier this morning on signet.

It's an attempt at a primary-path-spend of a default Liana ExpandingMultisig taproot output.

Running btcdeb in a docker instance:

tx=0200000000010119f605e6cd37dd5d780e15c71d57d4e7c23dea56b64b9378b311addc540bc2cf0000000000fdffffff03701101000000000022512045ed102fa4b1057db7c8c7356bf885a567e25d45d3b119d111dc829a3511c2c4f824010000000000160014c675e0b4b427a33c62147702f6f315497b33fd6cc0d0000000000000160014447fde1e37d97255b5821d2dee816e8f18f6bac90440f0eccd95efadd740fbe18f93a4441b72d9100022ec364e17a23a3ee7ff0a3b6f0c9954da42a58d0834802974e291cfafe3182f18ec25cafac307ec813d2e5ed3401e12c03bf63d41f87a2fd792b77faf816b65f720483d227898f8f41efe696f22a38baf9f24e4bcf210dbbdaefd53d8a2a63bda5600388545177380de988b42aa46203c343e06381b7e7926fdbe54c63ab0040c5c2c8491e2d4bd7238cb9066040a1bac2046023b7872e0027577d8a451389bc5a430e729f2d389a23ecca1237dc3b7f7d6ba529c41c0baf872c3fb5bdb356615e7045ed8306d56e0df10c31fd2f0143192d2dd812183d1742e6161782799d44467ab0dc374b1cb88bc2f719e44bc49f9ea545c9ed255e3920300

txin=0200000000010103dc016b3823bb1d01244ffce1a1117704183ced100b51601b70d694213c88c90000000000fdffffff03400d03000000000022512035d2966e0b441e406248f4ed8a69a6283536a85ec03c974687291948265cee37400d03000000000022002078e59302d5539fe4c7191c10ad246f856f75e80f07a30ad419993579c02e44d773424a0000000000160014b7e7f48e5c3bd445be101eb5835021219ced250c0247304402207768183ffd882c935d403f822b88c625d36687005d36707acd9a6e157f5a0b1c022056ab74972e275df0ddcc6c1bec45eda7a3ad8a73db7a92835a5cf493b31e91730121028ef9b939e3eba3b7ae30c01e1e5b3633195448b264510cccac951055d6910ccbe092030

/tmp/btcdeb # btcdeb --tx=$tx --txin=$txin
btcdeb 5.0.24 -- type `btcdeb -h` for start up options
LOG: signing segwit taproot
notice: btcdeb has gotten quieter; use --verbose if necessary (this message is temporary)
input tx index = 0; tx input vout = 0; value = 200000
got witness stack of size 4
34 bytes (v0=P2WSH, v1=taproot/tapscript)
Taproot commitment:
- control  = c0baf872c3fb5bdb356615e7045ed8306d56e0df10c31fd2f0143192d2dd812183d1742e6161782799d44467ab0dc374b1cb88bc2f719e44bc49f9ea545c9ed255
- program  = 35d2966e0b441e406248f4ed8a69a6283536a85ec03c974687291948265cee37
- script   = 203c343e06381b7e7926fdbe54c63ab0040c5c2c8491e2d4bd7238cb9066040a1bac2046023b7872e0027577d8a451389bc5a430e729f2d389a23ecca1237dc3b7f7d6ba529c
- path len = 1
- p        = baf872c3fb5bdb356615e7045ed8306d56e0df10c31fd2f0143192d2dd812183
- q        = 35d2966e0b441e406248f4ed8a69a6283536a85ec03c974687291948265cee37
- k        = f3d10d8d25c08673e65cbba3680bc92a1e66fe15bff701744deeb349361a708a          (tap leaf hash)
  (TapLeaf(0xc0 || 203c343e06381b7e7926fdbe54c63ab0040c5c2c8491e2d4bd7238cb9066040a1bac2046023b7872e0027577d8a451389bc5a430e729f2d389a23ecca1237dc3b7f7d6ba529c))
invalid script (witness stack last element)

The descriptor does include OP_CHECKSIGADD view on mempool.space so I'll pay attention to pr #151

ADDED: after removing btcdeb docker container, checking out pr151, rebuilding docker and btcdeb: I can now debug the above transaction w/o the above error.

@jdlcdl
Copy link

jdlcdl commented Feb 6, 2025

@panicfarm

What is the reason for this invalid script (witness stack last element) error, while the transaction was accepted by the core v0.25 and mined successfully?

Thank you for sharing this issue so that I could find this. Wondering what your solution was?

If you didn't already have a solution, have you seen pr 151, which addresses OP_CHECKSIGADD.

I had a similar error this morning. I tried pr 151 and was able to fully debug my transaction.

Using the pr 151 build, I tried yours, and I get past the initial load, can step twice but on third step "Invalid Schnorr signature hash type".

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

No branches or pull requests

3 participants