<p>In signing with the second party, the multisig script that is your witness script got messed up.</p>
<p>In both the initial PSBT and the first signing, we see that the witness script is</p>
<pre><code>522102dbbedff721dcdc7737c0e931c0473db3aadf4690f01dd5fc6da65188e21ecffd2102f4e91f49be47c24571e100c501cc50e9c499e744a25e51e2153d26b85660595252ae
</code></pre>
<p>which is decoded as</p>
<pre><code>2 02dbbedff721dcdc7737c0e931c0473db3aadf4690f01dd5fc6da65188e21ecffd 02f4e91f49be47c24571e100c501cc50e9c499e744a25e51e2153d26b856605952 2 OP_CHECKMULTISIG
</code></pre>
<p>This script has a sha256 of <code>4b29bdce823c1afde68cc26012e49a913fc005a629748afbea7285d7ac281b7c</code> which matches the hash given in the redeem script of the input, and the redeem script has a hash of <code>4d3a0d4465e19bb387df92f5e052f24370718117</code> which matches the hash in the output script of the output being spent. This is all correct.</p>
<p>But when we look at the final transaction, the script for some reason is changed to</p>
<pre><code>522102f4e91f49be47c24571e100c501cc50e9c499e744a25e51e2153d26b8566059522102dbbedff721dcdc7737c0e931c0473db3aadf4690f01dd5fc6da65188e21ecffd52ae
</code></pre>
<p>which is obviously different from the witness script originally. It's sha256 is <code>64b235d9fd37f2d68cb6edf19a25cc7765ef9c7299e3b448c86196cecd60feb0</code> which doesn't match the hash in the redeem script, so the script interpreter fails here.</p>
<p>This script is decoded as</p>
<pre><code>2 02f4e91f49be47c24571e100c501cc50e9c499e744a25e51e2153d26b856605952 02dbbedff721dcdc7737c0e931c0473db3aadf4690f01dd5fc6da65188e21ecffd 2 OP_CHECKMULTISIG
</code></pre>
<p>Looking at these two scripts, we can see the second one has the keys flipped around. For some reason, the software you used to finalize the PSBT changed the positioning of the keys in the script, which has resulted in the final transaction failing.</p>

CC BY-SA 4.0
2023-02-12T02:18:48.583Z
2023-02-12T02:18:48.583Z
Ava Chow
<p>I'm trying to generate a 2-of-2 multisig transaction as a PSBT so that both parties can easily sign their transaction. I'm doing this all on btc testnet as a p2sh p2wsh transaction</p>
<p>When initially generating my PSBT, I get the following</p>
<pre><code>70736274ff010052010000000118c739a0c061b892aefb3b2d93f9bca72c564ece339bf221946bddbd4c5b64390100000000ffffffff01bced0600000000001600146f01b2a5c8028a29f9631b6d494535fbd907e37a000000000001042200204b29bdce823c1afde68cc26012e49a913fc005a629748afbea7285d7ac281b7c010547522102dbbedff721dcdc7737c0e931c0473db3aadf4690f01dd5fc6da65188e21ecffd2102f4e91f49be47c24571e100c501cc50e9c499e744a25e51e2153d26b85660595252ae0000  
</code></pre>
<p>After signing it with the first party's electrum wallet, i get</p>
<pre><code>70736274ff010052010000000118c739a0c061b892aefb3b2d93f9bca72c564ece339bf221946bddbd4c5b64390100000000ffffffff01bced0600000000001600146f01b2a5c8028a29f9631b6d494535fbd907e37a0000000000220202f4e91f49be47c24571e100c501cc50e9c499e744a25e51e2153d26b85660595247304402207bdd58e7e837818b1bac12ee6615e48775c0354e3e0d22dd8ccf2d8afa0280bd022038f94ad49b245145e676a69d0af0233f0188b2b4bc88faec310de51f42cc18670101042200204b29bdce823c1afde68cc26012e49a913fc005a629748afbea7285d7ac281b7c010547522102dbbedff721dcdc7737c0e931c0473db3aadf4690f01dd5fc6da65188e21ecffd2102f4e91f49be47c24571e100c501cc50e9c499e744a25e51e2153d26b85660595252ae0000
</code></pre>
<p>Finally after signing it with the second party</p>
<pre><code>0100000000010118c739a0c061b892aefb3b2d93f9bca72c564ece339bf221946bddbd4c5b643901000000232200204b29bdce823c1afde68cc26012e49a913fc005a629748afbea7285d7ac281b7cffffffff01bced0600000000001600146f01b2a5c8028a29f9631b6d494535fbd907e37a040047304402207bdd58e7e837818b1bac12ee6615e48775c0354e3e0d22dd8ccf2d8afa0280bd022038f94ad49b245145e676a69d0af0233f0188b2b4bc88faec310de51f42cc18670147304402202d567c1419632774faf1ee6d49849fd2842e4b0017dc0643a68753384e937e8b02204d0bf0da935129e1bf5babb68a4d9d60a9b9939211961ccc93e2827349d8601d0147522102f4e91f49be47c24571e100c501cc50e9c499e744a25e51e2153d26b8566059522102dbbedff721dcdc7737c0e931c0473db3aadf4690f01dd5fc6da65188e21ecffd52ae00000000
</code></pre>
<p>When I attempt to broadcast this transaction, I get &quot;sendrawtransaction RPC error: {&quot;code&quot;:-26,&quot;message&quot;:&quot;non-mandatory-script-verify-flag (Witness program hash mismatch)&quot;}&quot;.
I've double checked to make sure I am signing with the correct keys and the amounts are correct so I'm lost on how to fix this. Any help is appreciated :)</p>

<electrum><segregated-witness><multi-signature><testnet><bip174-psbt>
How to resolve error when trying to sign and broadcast PSBT transaction via electrum - (Witness program hash mismatch code -26)?
btctestdev11
# How to resolve error when trying to sign and broadcast PSBT transaction via electrum - (Witness program hash mismatch code -26)?

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

I'm trying to generate a 2-of-2 multisig transaction as a PSBT so that both parties can easily sign their transaction. I'm doing this all on btc testnet as a p2sh p2wsh transaction

When initially generating my PSBT, I get the following

```
70736274ff010052010000000118c739a0c061b892aefb3b2d93f9bca72c564ece339bf221946bddbd4c5b64390100000000ffffffff01bced0600000000001600146f01b2a5c8028a29f9631b6d494535fbd907e37a000000000001042200204b29bdce823c1afde68cc26012e49a913fc005a629748afbea7285d7ac281b7c010547522102dbbedff721dcdc7737c0e931c0473db3aadf4690f01dd5fc6da65188e21ecffd2102f4e91f49be47c24571e100c501cc50e9c499e744a25e51e2153d26b85660595252ae0000  

```

After signing it with the first party's electrum wallet, i get

```
70736274ff010052010000000118c739a0c061b892aefb3b2d93f9bca72c564ece339bf221946bddbd4c5b64390100000000ffffffff01bced0600000000001600146f01b2a5c8028a29f9631b6d494535fbd907e37a0000000000220202f4e91f49be47c24571e100c501cc50e9c499e744a25e51e2153d26b85660595247304402207bdd58e7e837818b1bac12ee6615e48775c0354e3e0d22dd8ccf2d8afa0280bd022038f94ad49b245145e676a69d0af0233f0188b2b4bc88faec310de51f42cc18670101042200204b29bdce823c1afde68cc26012e49a913fc005a629748afbea7285d7ac281b7c010547522102dbbedff721dcdc7737c0e931c0473db3aadf4690f01dd5fc6da65188e21ecffd2102f4e91f49be47c24571e100c501cc50e9c499e744a25e51e2153d26b85660595252ae0000

```

Finally after signing it with the second party

```
0100000000010118c739a0c061b892aefb3b2d93f9bca72c564ece339bf221946bddbd4c5b643901000000232200204b29bdce823c1afde68cc26012e49a913fc005a629748afbea7285d7ac281b7cffffffff01bced0600000000001600146f01b2a5c8028a29f9631b6d494535fbd907e37a040047304402207bdd58e7e837818b1bac12ee6615e48775c0354e3e0d22dd8ccf2d8afa0280bd022038f94ad49b245145e676a69d0af0233f0188b2b4bc88faec310de51f42cc18670147304402202d567c1419632774faf1ee6d49849fd2842e4b0017dc0643a68753384e937e8b02204d0bf0da935129e1bf5babb68a4d9d60a9b9939211961ccc93e2827349d8601d0147522102f4e91f49be47c24571e100c501cc50e9c499e744a25e51e2153d26b8566059522102dbbedff721dcdc7737c0e931c0473db3aadf4690f01dd5fc6da65188e21ecffd52ae00000000

```

When I attempt to broadcast this transaction, I get "sendrawtransaction RPC error: {"code":-26,"message":"non-mandatory-script-verify-flag (Witness program hash mismatch)"}".
I've double checked to make sure I am signing with the correct keys and the amounts are correct so I'm lost on how to fix this. Any help is appreciated :)

**Tags:** electrum, segregated-witness, multi-signature, testnet, bip174-psbt


---

## 1 answers

### Answer by username_1 on 2023-02-12. Score: 5

In signing with the second party, the multisig script that is your witness script got messed up.

In both the initial PSBT and the first signing, we see that the witness script is

```
522102dbbedff721dcdc7737c0e931c0473db3aadf4690f01dd5fc6da65188e21ecffd2102f4e91f49be47c24571e100c501cc50e9c499e744a25e51e2153d26b85660595252ae

```

which is decoded as

```
2 02dbbedff721dcdc7737c0e931c0473db3aadf4690f01dd5fc6da65188e21ecffd 02f4e91f49be47c24571e100c501cc50e9c499e744a25e51e2153d26b856605952 2 OP_CHECKMULTISIG

```

This script has a sha256 of `4b29bdce823c1afde68cc26012e49a913fc005a629748afbea7285d7ac281b7c` which matches the hash given in the redeem script of the input, and the redeem script has a hash of `4d3a0d4465e19bb387df92f5e052f24370718117` which matches the hash in the output script of the output being spent. This is all correct.

But when we look at the final transaction, the script for some reason is changed to

```
522102f4e91f49be47c24571e100c501cc50e9c499e744a25e51e2153d26b8566059522102dbbedff721dcdc7737c0e931c0473db3aadf4690f01dd5fc6da65188e21ecffd52ae

```

which is obviously different from the witness script originally. It's sha256 is `64b235d9fd37f2d68cb6edf19a25cc7765ef9c7299e3b448c86196cecd60feb0` which doesn't match the hash in the redeem script, so the script interpreter fails here.

This script is decoded as

```
2 02f4e91f49be47c24571e100c501cc50e9c499e744a25e51e2153d26b856605952 02dbbedff721dcdc7737c0e931c0473db3aadf4690f01dd5fc6da65188e21ecffd 2 OP_CHECKMULTISIG

```

Looking at these two scripts, we can see the second one has the keys flipped around. For some reason, the software you used to finalize the PSBT changed the positioning of the keys in the script, which has resulted in the final transaction failing.


---

