Questions tagged [script]

A simple, stack-based, Forth-like programming language using "opcodes" to express spending conditions.

Script is used to define how funds may be spent. A script consists of two parts. In a transaction output funds are assigned to a locking script, the scriptPubKey. The corresponding transaction input provides a method for initializing a stack as input to the scriptPubKey, the scriptSig. In segwit output types, the witness encodes the stack directly. The set of commands in Script are referred to as "opcodes".

There are a number of standard scripts and scripts which are defined by an address. These include Pay-to-Public-Key-Hash, Pay-to-Script-Hash, Pay-to-Witness-Public-key-hash, and Pay-to-Witness-Script-Hash.

This tag should be used for questions regarding scripts and opcodes used in transactions.

639 questions
24
votes
1 answer

How do Scripts work?

Bitcoin protocol supports scripts. How do they work? How are those implemented? What are their intended usages? When are they planned to be used?
ripper234
  • 26,550
  • 30
  • 111
  • 246
23
votes
10 answers

Online Bitcoin Script simulator or debugger?

Is there an online simulator that would allow me to step through, debug, or simulate the execution of a Bitcoin script?
Geremia
  • 4,626
  • 5
  • 38
  • 75
14
votes
2 answers

Is sha-1 used in Bitcoin?

The Bitcoin scripting language has OP_SHA1 as one of its opcodes. However, I'm not able to find any usage of this opcode (it is not used in any standard scripts nor in any other procedures such as block hashing). So my question is: is sha-1 used…
cpsola
  • 1,538
  • 10
  • 27
12
votes
1 answer

What is the alt stack?

I noticed in the bitcoin wiki script page (https://en.bitcoin.it/wiki/Script) that there were two opcodes named: OP_TOALTSTACK OP_FROMALTSTACK It looks like there is another stack that can be used separately as a data store, simply pushing and…
morsecoder
  • 14,168
  • 2
  • 42
  • 94
11
votes
1 answer

How is the Output script formed?

I read about Input and output scripts on the wiki here: https://en.bitcoin.it/wiki/Transactions Let's say, I use my Bitcoin - QT Program, I go to "Send Coins" tab, enter a Bitcoin Address, BTC amount and then click Send. Is the output script…
Neon Flash
  • 1,053
  • 2
  • 10
  • 11
10
votes
3 answers

Why is Script needed?

As I see it, the script feature is one of the most complicated features in the entire protocol. It features $ cat src/script.h|grep '^ *OP_'|wc -l 118 instructions, and requires a stack to calculate. The most important limitation, it makes it…
7
votes
1 answer

PUSHDATA4 unnecessary?

Any data push greater than 520 bytes in a Bitcoin transaction is not allowed (https://github.com/bitcoin/bitcoin/blob/v0.10.0rc3/src/script/script.h#L18). The opcode OP_PUSHDATA4 specifies, that the next four bytes contain the number of following…
Bjarne Magnussen
  • 937
  • 5
  • 16
7
votes
1 answer

Are these two scripts equivalent?

I wonder whether OP_DEPTH 0 OP_EQUAL has the exact same behavior as OP_DEPTH OP_NOT which is 1 if no items 0 if any number of items I'm asking because the first script is used and I'm not sure if there is any justification for that. It's very…
MCCCS
  • 10,206
  • 5
  • 27
  • 56
6
votes
3 answers

Can I use single address for all my transactions?

Can I always use single public key (addr1) for all my transactions and when I spend every time protect it with different scripts / keys (key2, key3, etc.), so that spending requires at least two keys ('key1', and 'key-n') but addr1 remains the same…
vi.su.
  • 1,852
  • 5
  • 23
  • 41
6
votes
1 answer

In Bitcoin scripting, can you have an IF within an IF?

In bitcoin, you can create a script like this: OP_1 OP_IF OP_RETURN OP_ENDIF But could you place another if statement inside the first? OP_1 OP_IF OP_1 OP_IF OP_RETURN OP_ENDIF OP_ENDIF I grant that this is a bit of a silly example (given that the…
Nick ODell
  • 29,396
  • 11
  • 72
  • 130
6
votes
1 answer

How to get address from scriptSig?

I'm looking for a way to get address from scriptSig. I want to know input address. Can you share how to do it? I prefer PHP library but any ways would be appreciated. e.g. I use bitwasp, a PHP library. I can see a scriptSig ("483...767") in vin. I…
zono
  • 1,935
  • 1
  • 20
  • 35
6
votes
4 answers

What's the point of having a stack-based scripting language, if only a few standard forms are allowed?

What is the purpose of a stackmachine if only some standard script forms are allowed? And why are some scripts allowed and perfectly fine in mined blocks but rejected by clients if found in transactions; what's the point of that? The more I read…
wischi
  • 161
  • 3
6
votes
1 answer

How to denote script in P2SH transaction?

From the bitcoin developer page, the format of the scripts used in P2SH transactions are as follows: Pubkey script: OP_HASH160 OP_EQUAL Redeem script: OP_CHECKMULTISIG Signature…
morsecoder
  • 14,168
  • 2
  • 42
  • 94
5
votes
1 answer

Is a script spendable if multiple items are left on the stack?

Is a script spendable if the top item left on the stack evaluates to "TRUE", and that is the only item left in the stack? In other words, is it okay for multiple items to be left on the stack? For example, A scriptPubKey + scriptSig is spenable if…
inersha
  • 3,063
  • 1
  • 17
  • 41
5
votes
1 answer

OP_SHA256 mismatch!

I am new to bitcoin. When I use this online 'Script Execution' site, to calculate the SHA256 hash of 1, I get 4bf5122f344554c53bde2ebb8cd2b7e3d1600ad631c385a5d7cce23c7785459a but using any other online calculator you get a different result…
1
2 3 4 5