ScriptCode field in P2SH-P2WPKH BIP-143 Test Vector I'm trying to understand the meaning of scriptCode in the context of spending a P2SH(P2WPKH) UTXO.

I've already read the following answer to a similar question, but it does not fully address my misunderstanding.

After reading BIP141 for P2WPKH nested in BIP16 P2SH, we're told that the structure is:

witness:      &lt;signature&gt; &lt;pubkey&gt;
scriptSig:    &lt;0 &lt;20-byte-key-hash&gt;&gt;
                  (0x160014{20-byte-key-hash})
scriptPubKey: HASH160 &lt;20-byte-script-hash&gt; EQUAL
                  (0xA914{20-byte-script-hash}87)



I noticed that the scriptCode gets committed to the hash to be signed for each input. Can someone explain why 1976a91479091972186c449eb1ded22b78e40d009bdf008988ac (dup hash160 [79091972186c449eb1ded22b78e40d009bdf0089] equalverify checksig) is used as the script code (from my understanding the scriptPubKey or locking script) for a p2sh(p2wpkh) UTXO? That script corresponds to a p2pkh scriptPubKey (surely this is out of context here)?

I understand the sequence of execution as: 


witness &lt;signature&gt; &lt;pubkey&gt; and scriptSig &lt;0 &lt;20-byte-key-hash-compressed-pub-key&gt;&gt; are pushed onto the stack.
Then the scriptPubKey: HASH160 &lt;20-byte-script-hash&gt; EQUAL is executed with redeemScript (&lt;0 &lt;20-byte-key-hash-compressed-pub-key&gt;&gt;) as the arg, eventually resulting in the execution of   CHECKSIG.


Why include a scriptCode that corresponds to a script that is seemingly out of context and not used?

Why is the following true? 

For P2WPKH witness program, the scriptCode is 0x1976a914{20-byte-pubkey-hash}88ac.


It is referenced as prevOutScript in this Javascript library: https://github.com/bitcoinjs/bitcoinjs-lib/blob/master/src/transaction.js#L396
The one that you are referring to is sighashing. There is no good reason to use 1976a91479091972186c449eb1ded22b78e40d009bdf008988ac (dup hash160 [79091972186c449eb1ded22b78e40d009bdf0089] equalverify checksig as the scriptCode in Segwit but to limit the number of changes SegWit makes to the original sighashing. In designing SegWit, only intended changes were made. The hash structure remains the same, and contains all the same data. The sighash flags still have the same effect. The only thing that changes in BIP-143 is that some data is organized under precomputed hashes, and the input amounts go into it.