BIP 141 uses the term "witness program" extensively without, apparently, adhering to a consistent definition.
From the heading "Witness Program":
A scriptPubKey (or redeemScript as defined in BIP16/P2SH) that consists of a 1-byte push opcode (for 0 to 16) followed by a data push between 2 and 40 bytes gets a new special meaning. The value of the first push is called the "version byte". The following byte vector pushed is called the "witness program". [my emphasis]
https://github.com/bitcoin/bips/blob/master/bip-0141.mediawiki#witness-program
In other words, a "witness program" is a byte sequence 2 to 40 bytes in length. In P2WPKH authentication, the witness program is the 20-byte hash value of a public key. In P2WSH authentication, the witness program is the 32-byte hash value of the serialize "witness script" (last element of witness data).
At least, this is what I gather from reading the definition under the heading.
However, BIP 141 makes other references to "witness program" that seem to suggest something else. For example:
- "In addition, opcodes within the witness program are counted identical to as previously within the P2SH check script."
- "The P2WPKH witness program is then executed as described in the previous example."
Also, headings seem to suggest that "witness program" means something else:
- "P2WPKH witness program" (describes a new authentication template) https://github.com/bitcoin/bips/blob/master/bip-0141.mediawiki#p2wpkh-witness-program
- "P2WSH witness program" (describes a new authentication template) https://github.com/bitcoin/bips/blob/master/bip-0141.mediawiki#p2wsh-witness-program
What is a precise definition for the term "witness program?"