I don’t understand how the OP_PUSH works – where does it push from and does it push it onto the top of the stack? I thought script operations read from the top of the stack so I’d read the top item and push it back onto the stack which does nothing?
As I understand it, the script is separate from the stack. The script is read left to right and it’s instructions operate on the stack.
So you start with your program pointer at far left of script and with an empty stack.
Then script instructions 0100 (
OP_PUSH1 0x00) would push the value
0x00 from the script onto the top of the stack. The stack would then contain
0x00 and the program pointer would point to the right of the
0x00 in the script.
As Buruk pointed out, your script is incorrect and wouldn’t function as you intend.
I believe you need a locking script
OP_PUSH1 0x03 OP_PUSH1 0x05 OP_ADD OP_NUMEQUAL
with an unlocking script of
0108 ... 01030105939C
OP-PUSH1 0x08 ... OP_PUSH1 0x03 OP_PUSH1 0x05 OP_ADD OP_NUMEQUAL
which we can work through step by step thus:
||interpretation of highlighted opcode
||stack after opcode executed
||05 03 08
- script is like machine-code
- interpretation is like assembly language
- top of stack is to left