Okay, I think my confusion was that the parameters are not included in the hash. Thank you.
My pleasure! Btw, the fact that you have to reveal the entire locking script each time you spend from a P2SH is one of the reasons behind the implementation of Taproot on Bitcoin. With Taproot, you're able to only reveal the path you actually use to spend the bitcoins, not all of them.
reply
How complex can the scripts get??
reply
The locking script complexity is only limited by the fees you are willing to pay to spend from it.
reply