Hot answers tagged

90 votes
Accepted

Explanation of what an OP_RETURN transaction looks like

Note: I went out and learned about how the OP_RETURN opcode works at the byte level in a bitcoin transaction. I’m writing it here so that others can learn quickly. First, a brief history of why we’re ...
user avatar
  • 2,276
20 votes
Accepted

History behind the scripting language in Bitcoin?

Script was in the first version of Bitcoin. Satoshi developed Bitcoin in private before releasing the fully-usable Bitcoin 0.1, and he said very little about his thought-process, so we'll probably ...
user avatar
  • 8,694
18 votes
Accepted

What is the script assembly and execution in P2TR spend (spend from Taproot)

Before we start I realize your question is only about single-sig scenarios, and you want an answer focused on how validation works. I will address these things, but I think I need to elaborate a bit ...
user avatar
17 votes
Accepted

Is sha-1 used in Bitcoin?

SHA1 was never commonly used in Bitcoin, but it there is at least one notable use of it, a P2SH script created by Peter Todd to allow anyone to pay to an address that could be spent by anyone proving ...
user avatar
16 votes
Accepted

Why does the default miner implementation use pay-to-pubkey?

Pay-to-PubKey (P2PK) and pay-to-PubKey-Hash (P2PKH) were both introduced in the original Bitcoin 0.1 release. P2PK was used by default for mining and payments received using the interactive IP-to-IP ...
user avatar
14 votes
Accepted

The Bitcoin scripting system is purposefully not Turing-complete - why?

As others have said, there is no real need for Bitcoin scripting to be more complex than it is, as its complexity is more than enough for its intended applications; but the main reason is that not ...
user avatar
  • 1,048
14 votes
Accepted

CHECKMULTISIG a worked out example

I expect that CHECKMULTISIG will call the CHECKSIG function and manipulate the stack to run CHECKSIG in a loop until it terminates and either has its M-out-of-N valid sigs or not? That's not really ...
user avatar
  • 28.7k
14 votes
Accepted

Why is OP_SUBSTR disabled? (and OP_LEFT, OP_RIGHT)

I'm afraid that my answer here can't be better than "Ask Satoshi". There was a series of bugs found in Bitcoin's early life, and the response by its creator was to disable a number of scripting ...
user avatar
14 votes
Accepted

What does Bitcoin policy language offer the developer that Miniscript doesn't? What is the difference between Bitcoin policy language and Miniscript?

Both answers by James C. and sanket1729 are very good, but I wanted to give a very high-level answer: Miniscript is an intermediate more structured representation for actual Bitcoin Scripts. It is ...
user avatar
13 votes
Accepted

OP_SHA256 mismatch!

Your conflict is caused because you are hashing different values in the two situations. >>> import hashlib >>> hashlib.sha256("1").hexdigest() '...
user avatar
  • 15k
12 votes

Explanation of what an OP_RETURN transaction looks like

If you want to write OP_RETURNs to the blockchain without getting into the internals of how transactions are built, an easy way is to use our libraries for PHP and Python: https://github.com/...
user avatar
12 votes
Accepted

Bitcoin and Smart Contracts

Bitcoin has a scripting language built into it, which allows the creation of many kinds of smart contracts. Examples are atomic swaps, Lightning payment channels and zero-knowledge contingent payments ...
user avatar
12 votes
Accepted

What are the downsides to enabling potentially suboptimal or unused opcodes in a future soft fork?

Every piece of additional consensus logic has implementation and ongoing maintenance cost which is perpetual and can never be removed without potentially confiscating some user's assets. When Satoshi ...
user avatar
  • 7,479
11 votes

What is relation between scriptSig and scriptPubKey?

I had the same question as well and spent forever trying to understand it and finally cracked it. "The sender (A) only has the Bitcoin Address of the recipient (B), so how does he get the pubKeyHash ...
user avatar
11 votes
Accepted

Is there a maximum size of a scriptSig/scriptPubKey?

10,000 bytes. See Bitcoin Core source code: https://github.com/bitcoin/bitcoin/blob/v0.17.0/src/script/script.h#L31-L32 https://github.com/bitcoin/bitcoin/blob/v0.17.0/src/script/interpreter.cpp#L299-...
user avatar
10 votes

Online Bitcoin Script simulator or debugger?

Highly recommend btcdeb by kallewoof. Among other things, you can step through scripts including verify signatures. It is written in c++ and compiles using autotools. btcdeb Bitcoin Script debugging ...
user avatar
  • 7,060
10 votes

What does Bitcoin policy language offer the developer that Miniscript doesn't? What is the difference between Bitcoin policy language and Miniscript?

Miniscript doesn't compile down to script. It encodes a subset of all Bitcoin script. It is a (very crafty) template language which reduces the Bitcoin script language to specific script expressions ...
user avatar
  • 2,423
10 votes

What does Bitcoin policy language offer the developer that Miniscript doesn't? What is the difference between Bitcoin policy language and Miniscript?

At a high level: The policy is compiled to Miniscript. Miniscript is encoded to Bitcoin Script. (One to One Mapping) Bitcoin Script is decoded back to Miniscript. (One to One Mapping) Policy and ...
user avatar
  • 1,214
10 votes

Is it correct to say that Bitcoin has a virtual machine in the same way as Ethereum does?

"Virtual machine" in this context is really just a fancy word for bytecode interpreter. Bitcoin's script language is certainly far simpler than Ethereum's EVM, and its functionalities are in ...
user avatar
9 votes
Accepted

Which bitcoin script forms should be detected when tracking wallet balance?

These are the scriptPubKey's that are standard, arranged in order of popularity: P2PKH (Pay to public key hash) OP_DUP OP_HASH160 <20 bytes of public key hash> OP_EQUALVERIFY OP_CHECKSIG P2SH ...
user avatar
  • 28.7k
9 votes
Accepted

Why is OP_CHECKLOCKTIMEVERIFY disabled by maximum sequence number?

the purpose of OP_CHECKLOCKTIMEVERIFY is kind of the opposite to the purpose of tx.nLockTime. tx.nLockTime prevents transactions with future dates from entering the blockchain, whereas ...
user avatar
  • 1,693
9 votes
Accepted

PUSHDATA4 unnecessary?

There is currently no real need for an OP_PUSHDATA4, which would allow pushing up to 4GB onto the stack. It was in the original script definition and simply was not disabled when the 520 byte limit ...
user avatar
  • 8,754
9 votes
Accepted

How to tell which part of the previous tx I need to make the hash to sign for an old given tx?

Disclaimer: I am going to assume that you are not completely clueless and that you know what an array is, how to count from 0, and how to match brackets, quotes, and colons so that you can read JSON ...
user avatar
  • 61.4k
9 votes
Accepted

Will BTC script be Turing complete in future?

Turing completeness includes the capability to run programs that might not terminate or that might terminate after a very long time. This would cause the blockchain to stall, hence it is a must to ...
user avatar
  • 9,819
9 votes
Accepted

How does OP_RETURN burn coins?

What does exactly cause the output containing OP_RETURN to be unspendable? Simply the fact that no input can possibly unlock coins which are encumbered with such an OP_RETURN-containing script. ...
user avatar
8 votes
Accepted

What is the alt stack?

Here's where they're defined: case OP_TOALTSTACK: { if (stack.size() < 1) return false; altstack.push_back(stacktop(-1));...
user avatar
  • 28.7k
8 votes
Accepted

What is OP_CODESEPARATOR used for?

Looking at this diagram of OP_CHECKSIG steps and the Bitcoin Script wiki, OP_CODESEPARATOR is used to make OP_CHECKSIG check only part of the scriptPubKey. Essentially, only the script that goes after ...
user avatar
  • 283
8 votes

Where the P2SH script gets written?

The script is maintained by the intended recipient; he is the one responsible to keep it and not to lose it. The nodes do not store any database of the scripts. The script is provided by the spender ...
user avatar
  • 992
8 votes
Accepted

What's the use of not relaying non-standard transactions if anyone can still use them using P2SH?

As you say, there are two separate concerns here: There are some scripts that might cause harm to the network. There are some scripts that might make future upgrades harder. For the case of harm to ...
user avatar
8 votes

nLockTime in Bitcoin Core

I believe you are correct, both about the fact that height-based logic came first and time was added later, and the fact that this is a hard-forking change. A transaction with a locktime > 500000000 ...
user avatar

Only top scored, non community-wiki answers of a minimum length are eligible