For every input we can have multiple stack items, what do these represent?
As a reference this question is helpful

Are these defined here?
For eg. P2WPKH would have a signature followed by a pubkey, (so two stack items)

1 Answer 1


BIP141 defines requirements for witness stacks as follows:

  • In P2WPKH, the witness stack must consist of exactly 2 items (signature and public key).
  • In P2WSH, the witness stack must have at least one item (witness script), while the remaining items are used as the initial stack for script execution.
  • Are you sure there is a check (requirement) for P2WPKH that exactly 2 elements are in the witness data? Pieter Wuille did not mention that requirement for P2WPKH in his answer.
    – dassd
    Sep 18, 2023 at 20:25
  • Yes. From the specification: "The witness must consist of exactly 2 items (≤ 520 bytes each). The first one a signature, and the second one a public key." Sep 18, 2023 at 20:50
  • In his answer, Pieter interprets P2WPKH as a P2PKH script with the witness stack as the initial stack, with the requirement that the resulting stack must have exactly one element. That implicitly requires that the witness stack has exactly two elements, because any other length will either fail the script or result in more than one item on the resulting stack. Sep 18, 2023 at 21:00
  • Yes, I completely agree with you that there is an implicit check if 2 items are in witness data, because if it is not, the script will not pass. We did not understand. I meant whether there is an explicit check, like for example: witness_data.count == 2. Something similar to how P2WSH has a check to see if the witness data is empty.
    – dassd
    Sep 18, 2023 at 21:53
  • That depends on the implementation, as there are multiple equivalent ways of implementing the specification given in BIP141. Specifically, Bitcoin Core has an explicit check that the stack size is 2 and then feeds it into a P2PKH script. Sep 18, 2023 at 21:59

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.