<p>Any input spending a non-segwit script type must not have a witness. If it does, the transaction is invalid.</p>
<p>P2SH-P2WSH and P2SH-P2WPKH are the exceptions: if the script type is P2SH <em>and</em> the redeemScript is P2WSH or P2WPKH, then a witness is allowed, and is verified according to the P2WSH and P2WPKH verification rules.</p>

CC BY-SA 4.0
2024-03-21T18:49:14.060Z
how is it determined when p2wsh is nested with p2sh or p2wpkh is nested with p2sh?
lladane
CC BY-SA 4.0
2024-03-22T16:27:54.233Z
It is determined during script evaluation. When a P2SH is evaluated and the redeemScript pulled out as part of that, the redeemScript is inspected to see if it is P2WPKH or P2WSH.
Ava Chow
CC BY-SA 4.0
2024-03-21T15:10:30.753Z
2024-03-21T15:10:30.753Z
Ava Chow
<p>What will it mean if the tranasaction input contains both signature script and witness, in case of scriptpubkey_type of p2sh or p2pkh, will it be invalid or valid ? As we use witness for SegWit Transactions.</p>

<transactions><segregated-witness><input-script><witness-data>
Transaction Validation
lladane
# Transaction Validation

(Asked by: username_0 on 2024-03-21)

What will it mean if the tranasaction input contains both signature script and witness, in case of scriptpubkey\_type of p2sh or p2pkh, will it be invalid or valid ? As we use witness for SegWit Transactions.

**Tags:** transactions, segregated-witness, input-script, witness-data


---

## 1 answers

### Answer by username_1 on 2024-03-21. Score: 1 | Accepted answer

Any input spending a non-segwit script type must not have a witness. If it does, the transaction is invalid.

P2SH-P2WSH and P2SH-P2WPKH are the exceptions: if the script type is P2SH *and* the redeemScript is P2WSH or P2WPKH, then a witness is allowed, and is verified according to the P2WSH and P2WPKH verification rules.

> **Comments:**
> **username_0**: how is it determined when p2wsh is nested with p2sh or p2wpkh is nested with p2sh?  
> **username_1**: It is determined during script evaluation. When a P2SH is evaluated and the redeemScript pulled out as part of that, the redeemScript is inspected to see if it is P2WPKH or P2WSH.  

---

