Script Execution

We now describe the process of script execution in Bitcoin.

In order to validate a new transaction, the input (signature script) and the output of the former transaction (pubkey script) are concatenated. Once concatenated, the script is executed according to the scripting language. During execution, constants, denoted by <..> are pushed onto the stack, and opcodes execute their respective actions by taking into account the topmost stack value.

In Figure 3.4, we depict an example of the validation of transaction 2 that spends a former output of transaction 1. The output and input script are concatenated (signature script first and then the PubKey script). In a first step, the two constants are pushed onto the stack. Subsequently, OP_DUP duplicates the topmost stack value, in this case. The next opcode OP-HASH160 hashes the and saves it as on the stack. Again, a constant is pushed onto the stack and OP_EQUALVERIFY verifies whether the two topmost stack elements are equal. If they are equal, they are removed from the stack and the last opcode opxhecksig verifies whether the public key on the stack () matches the signature (). If the

Script execution for a P2PKH transaction

Figure 3.4 Script execution for a P2PKH transaction.

signature is valid, the script returns true, meaning that the input of transaction 2 is allowed to spent the output 1 of transaction 1.

< Prev   CONTENTS   Source   Next >