Take the 2-minute tour ×
Bitcoin Stack Exchange is a question and answer site for Bitcoin crypto-currency enthusiasts. It's 100% free, no registration required.

I'm trying to understand how a script works but am having trouble reading a script (the output of one Tx... and the input of a second Tx) and figuring out how the computer (bitcoin-qt) knows which input in the script is data and which is a command.

Please correct my assumption:

  • The script is read left to right and is the concatenation of the output of a preceding Transaction to the input of a consuming Transaction

  • A script output can have only one corresponding transaction script that consumes it.

  • There are several script commands and several are disabled in the current version of the client

  • The script can not rely on outside information (stock ticker) but can rely on an Oracle for these dependencies.

  • The script commands that are "commands" require certain data to be on the stack in order to function correctly

  • There are "standard scripts" (but I'm unclear if this means non-standard scripts may never get incorporated into a block)

  • If the concatenated evaluation of a preceding Tx Output and a subsequent Tx Input evaluates to true, then the transaction is valid.

Question

  1. Can anyone tell me if those thoughts about scripts are correct?
  2. How does the forth like processor know the difference between data on the stack and commands on the stack?
  3. Does the processor think everything is just data until it hits data that matches a known "function"
share|improve this question

1 Answer 1

up vote 3 down vote accepted

The script is read left to right and is the concatenation of the output of a preceding Transaction to the input of a consuming Transaction

Basically, though the scripts are not actually concatenated. The scriptSig is run, and then the scriptPubKey is run on the resulting stack. This distinction is occasionally important.

A script output can have only one corresponding transaction script that consumes it.

There are many possible scriptSigs that could "solve" any scriptPubKey, but each output can only be spent once in a valid block chain.

but I'm unclear if this means non-standard scripts may never get incorporated into a block

They can get into blocks, though miners using the standard client will never add them to their blocks.

How does the forth like processor know the difference between data on the stack and commands on the stack?

Data is preceded by bytes 1 through 78, the pushdata ops.

share|improve this answer
    
Actually, in very old versions of the code, the txin script was concatenated with the txout script (with an OP_CODESEPARATOR between them). This resulted in the OP_RETURN flaw (where the txin script could basically just be "return true"), so it was changed to two separate executions. –  Pieter Wuille Jan 1 '13 at 18:06

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.