So the problem is with the signature script, right?
No, your signature script is actually fine. The problem is the missing witness items, there needs to be 2 items a public key and an ECDSA signature.
The signature script of the transaction in the blockchain at that time is: 255121029b6d2c97b8b7c718c325d7be3ac30f7c9d67651bce0c929f55ee77ce58efcf8451ae
My created script is: 160014404c836c0ecbc42d1b20b999814319b17327100f
Now the first difference is that mine is shorter.
The size is not important, what the script is "translated" into is. I'll explain below.
My assumption was that the OP_HASH160 of this script is compared with the one in the PK script.
I have therefore recorded the content of the Scriptest as an irrellevant.
It is but only on first step.
Your statement is now that the content of the SigScript is decisive and leads to a statement as to whether it has to be signed with a Witness-TX or not. is that correct?
Basically this is what happens:
1. We take the pubkey script from the UTXO (the inputs of the transaction we are evaluating)
2. Evaluate what type this pubkey script has
2.A. If it is not any special types then move to signature script, run that then run pubkey script then move to last step to see if tx is valid (top stack element has to be true)
2.B. If it is a witness script (OP_NUM
) then the signature script must be empty and there must be a witness corresponding to this input, continue evaluation based on that (compare the hash, evaluate witnesses, etc).
2.C. If it is P2SH then the signature script must be all data pushes and at least 1 is needed (the last one is interpreted as redeem script). Some initial checks are done (running signature script then pubkey script) Then we start evaluating that redeem script:
2.C.A. If it is not any special type then just execute the script and move to last step
2.C.B. If it is a special type (ie. witness scripts) then continue evaluation based on that type.
In case of your transaction we take the pubkey script
a914be8755917b4c5b783d11ed205c277f9a2788785387
and see that the type is P2SH so we take a look at the signature script
160014404c836c0ecbc42d1b20b999814319b17327100f
It is a single push. So far everything is OK. Signature script is executed then top stack element is stored somewhere before pubkey script is executed. Stack is checked to see if it is true (essentially checking to see if the HASH160 was correct as you asked above).
Finally that stack element that was stored is evaluated as a script called redeem script.
0014404c836c0ecbc42d1b20b999814319b17327100f
Evaluating this shows that the type is P2WPKH so the evaluation continues by looking for 2 witness items and fails here because your transaction doesn't have any.