<p>I tried to verify an old transaction <a href="https://blockstream.info/tx/6a26d2ecb67f27d1fa5524763b49029d7106e91e3cc05743073461a719776192?expand" rel="nofollow noreferrer"><code>6a26d2ecb67f27d1fa5524763b49029d7106e91e3cc05743073461a719776192</code></a> <code>P2SH</code> multisig input 0 using  <a href="https://github.com/bitcoin/bitcoin/blob/master/doc/shared-libraries.md" rel="nofollow noreferrer">lib bitcoinconsensus</a> and I got <code>SCRIPT_ERR_INVALID_STACK_OPERATION</code>.</p>
<p>Here is the <a href="https://youtu.be/WSpthsV38XQ" rel="nofollow noreferrer">screencap</a> of its</p>
<pre><code>btcdeb --tx=0100000001f6ea284ec7521f8a7d094a6cf4e6873098b90f90725ffd372b343189d7a4089c0100000026255121029b6d2c97b8b7c718c325d7be3ac30f7c9d67651bce0c929f55ee77ce58efcf8451aeffffffff0130570500000000001976a9145a3acbc7bbcc97c5ff16f5909c9d7d3fadb293a888ac00000000 --txin=010000000168781ca236d8e70e4af8285852defabeff61c73db259cbbbebdf7bdac918c234010000004847304402206d186984373e0b781b85f49334cc9a249ffd13a448a5d1732096b011a10063e102206d280df8f4b5e6805f48eb04601ca6d97edd78f2b2d1104dc577e08fd788c78001ffffffff02cce80900000000001976a914fe58bbf690824bdaffb0431a709c27d7bdb6105e88ac801a06000000000017a91419a7d869032368fd1f1e26e5e73a4ad0e474960e8700000000
</code></pre>
<p>giving the same error.</p>
<p>How was this transaction verified by bitcoin core and what do I need to do to verify with lib bitcoinconsensus?</p>

CC BY-SA 4.0
2023-12-07T21:02:17.247Z
This transaction predates the activation of the BIP16 (P2SH) consensus rules on April 1st 2012, so there is no requirement that it is P2SH-valid. I don't know how to inform `btcdeb` that it shouldn't enforce P2SH rules.
Pieter Wuille
CC BY-SA 4.0
2023-12-08T22:32:30.607Z
Apparently `btcdeb --modify-flags="-P2SH" ...` disables BIP16. One can presumably supply `bitcoinconsensus_SCRIPT_FLAGS_VERIFY_P2SH` to [`bitcoinconsensus_verify_script()`](https://github.com/bitcoin/bitcoin/blob/3e691258d8789a4a89cce42e7e71b130491594d7/src/script/bitcoinconsensus.h#L75) as well. My question is how does the core know when to supply this flag (pre- BIP16 transaction) and when not to?
Alec Matusis
CC BY-SA 4.0
2023-12-09T15:35:15.593Z
Bitcoin Core knows when BIP16 (and other softforks) activated, so it sets the relevant flags on blocks for which the rules are active. Specifically, for BIP16 the activation is "buried", which means it's actually enabled for every block, except known exceptions.
Pieter Wuille
CC BY-SA 4.0
2024-06-23T19:27:13.007Z
@PieterWuille Thanks for clarifying. Why are these similar outputs listed [here](https://bitcoin.stackexchange.com/questions/115803/did-the-p2sh-bip-0016-make-some-bitcoin-unspendable) unspendable? Is it because the preimages can't be deserialized?
gelenor
CC BY-SA 4.0
2024-06-23T19:34:50.193Z
@gelenor We can't know for certain whether they are unspendable, but it is very likely. They were created prior to BIP16, so it's unlikely they were created in a way that's compatible with it.
Pieter Wuille
<transaction-verification><consensus><p2sh><verification>
Lib bitcoinconsensus verification returns SCRIPT_ERR_INVALID_STACK_OPERATION on a P2SH multisig output
Alec Matusis
# Lib bitcoinconsensus verification returns SCRIPT_ERR_INVALID_STACK_OPERATION on a P2SH multisig output

(Asked by: username_0 on 2023-12-07)

I tried to verify an old transaction [`6a26d2ecb67f27d1fa5524763b49029d7106e91e3cc05743073461a719776192`](https://blockstream.info/tx/6a26d2ecb67f27d1fa5524763b49029d7106e91e3cc05743073461a719776192?expand) `P2SH` multisig input 0 using [lib bitcoinconsensus](https://github.com/bitcoin/bitcoin/blob/master/doc/shared-libraries.md) and I got `SCRIPT_ERR_INVALID_STACK_OPERATION`.

Here is the [screencap](https://youtu.be/WSpthsV38XQ) of its

```
btcdeb --tx=0100000001f6ea284ec7521f8a7d094a6cf4e6873098b90f90725ffd372b343189d7a4089c0100000026255121029b6d2c97b8b7c718c325d7be3ac30f7c9d67651bce0c929f55ee77ce58efcf8451aeffffffff0130570500000000001976a9145a3acbc7bbcc97c5ff16f5909c9d7d3fadb293a888ac00000000 --txin=010000000168781ca236d8e70e4af8285852defabeff61c73db259cbbbebdf7bdac918c234010000004847304402206d186984373e0b781b85f49334cc9a249ffd13a448a5d1732096b011a10063e102206d280df8f4b5e6805f48eb04601ca6d97edd78f2b2d1104dc577e08fd788c78001ffffffff02cce80900000000001976a914fe58bbf690824bdaffb0431a709c27d7bdb6105e88ac801a06000000000017a91419a7d869032368fd1f1e26e5e73a4ad0e474960e8700000000

```

giving the same error.

How was this transaction verified by bitcoin core and what do I need to do to verify with lib bitcoinconsensus?

**Tags:** transaction-verification, consensus, p2sh, verification

> **Comments:**
> **username_1**: This transaction predates the activation of the BIP16 (P2SH) consensus rules on April 1st 2012, so there is no requirement that it is P2SH-valid. I don't know how to inform `btcdeb` that it shouldn't enforce P2SH rules.  
> **username_0**: Apparently `btcdeb --modify-flags="-P2SH" ...` disables BIP16. One can presumably supply `bitcoinconsensus_SCRIPT_FLAGS_VERIFY_P2SH` to [`bitcoinconsensus_verify_script()`](https://github.com/bitcoin/bitcoin/blob/3e691258d8789a4a89cce42e7e71b130491594d7/src/script/bitcoinconsensus.h#L75) as well. My question is how does the core know when to supply this flag (pre- BIP16 transaction) and when not to?  
> **username_1**: Bitcoin Core knows when BIP16 (and other softforks) activated, so it sets the relevant flags on blocks for which the rules are active. Specifically, for BIP16 the activation is "buried", which means it's actually enabled for every block, except known exceptions.  
> **username_2**: @username_1 Thanks for clarifying. Why are these similar outputs listed [here](https://bitcoin.stackexchange.com/questions/115803/did-the-p2sh-bip-0016-make-some-bitcoin-unspendable) unspendable? Is it because the preimages can't be deserialized?  
> **username_1**: @username_2 We can't know for certain whether they are unspendable, but it is very likely. They were created prior to BIP16, so it's unlikely they were created in a way that's compatible with it.  

---

## 0 answers

