5
I understand that when I'm doing a transaction, I'm locking those bitcoins to whoever provide the solution to a script that has the hash I posted.
But, where does the hash get written?
I would assume that it is not in the blockchain, since this payment system is done so we can save space. I can imagine that the nodes store a database of hashes of scripts previously written on the blockchain, so when they see a script hash, they can find the correct script for it. Another option was that the recipient would provide the script at the time of the transaction, but then the other nodes would not be able to verify the script's end result, because the script would not be on the blockchain.
Hi araqueto, I've tried to reduce your question's wall-of-text effect to make it more accessible. In the second half of your question you had been asking a bunch more questions, that were based on incorrect speculations about the first question's answer. I felt that they didn't add to your question and removed them. If you are still interested in that part of your question, please post a separate follow-up question. – Murch – 2016-02-21T11:37:01.253