Skip to main content
9 votes
Accepted

What are the scriptPubKey, scriptSig, redeem script and witness for the various output types?

This was answered during the Bitcoin Core PR review club on July 7th 2021 hosted by Gloria Zhao (who also provided this table). The <public key> in the P2TR (key path) and P2TR (script path) ...
Michael Folkson's user avatar
7 votes
Accepted

What prevents OP_SUCCESS from being used nefariously?

The UTXO's scriptPubKey commits to the script(s) that are permitted for spending, so you can't just pick an OP_SUCCESSx script and spend with that - the coins have to be sent to an address that ...
Pieter Wuille's user avatar
7 votes
Accepted

Why inputs' scriptSig are stripped before the whole transaction being signed?

Because they can't be. The scriptSig values contain the signatures. If they were included in the message being signed, you'd need signatures that sign themselves. That's not possible.
Pieter Wuille's user avatar
6 votes
Accepted

Why is concatenating scriptPubKeys and scriptSigs unsafe?

It was possible (see the infamous "1 RETURN bug") because the RETURN operand used to stop the execution of the Script. So simply pushing 1 in the scriptSig and RETURNing would make the ...
Antoine Poinsot's user avatar
5 votes
Accepted

How do I fix my check-multisig if-else output script?

OP_IF consumes a number from the top of the stack. The OP_IF will evaluate to true if the number is not 0, and to false if the number is 0. H/T for this answer by David Schwartz, and to Pieter ...
Murch's user avatar
  • 77.9k
5 votes
Accepted

What is the maximum number of bytes the coinbase scriptSig (coinbaseaux) can hold?

The maximum is 100 bytes and is checked and defined here: https://github.com/bitcoin/bitcoin/blob/master/src/consensus/tx_verify.cpp#L195
Ava Chow's user avatar
  • 72.2k
5 votes
Accepted

How can the genesis block contain arbitrary data on it if the script is invalid?

For four reasons (each of which individually would be enough): The genesis block is valid by definition. It is never validated. It is just by definition the first block of the chain, and every other ...
Pieter Wuille's user avatar
5 votes
Accepted

Is the scriptSig spending an PayToAnchor output expected to always be empty?

is it expected that the scriptSigs for unlocking those P2A always be empty? Yes. Would a transaction spending one of those with a non-empty scriptSig be considered non-standard? Not just non-...
Pieter Wuille's user avatar
4 votes
Accepted

What prevents anyone from spending utxos from a native segwit address?

Segwit is a soft fork. A supermajority of miners have agreed that they will not include such transactions in their blocks, and will orphan any block that does include such a transaction. If you send ...
Nate Eldredge's user avatar
4 votes

Decoding ScriptSig

This is a 5 input one output multisig transaction. The decoding of the first sigscript ...
pebwindkraft's user avatar
  • 5,116
4 votes
Accepted

Why is the scriptSig formatted this way in the Genesis Block (inside function CreateGenesisBlock)

The scriptSig field of a coinbase transaction is special. It doesn't need any signatures at all, as no coins are being spent. The ability to produce new coins, which that input represents, is inherent ...
Pieter Wuille's user avatar
4 votes
Accepted

Why we need to repalce the ScriptSig with the previous ScriptPubKey when calculate the per input signature hash?

Any data that is included in the sighash must be revealed to the signer. It also means that the signature itself directly commits to that information and so must be truthfully provided to the signer ...
Ava Chow's user avatar
  • 72.2k
4 votes
Accepted

Processing bitcoin reward block's input transaction

This is the scriptSig of a coinbase transaction (the first transaction in every block is special; it doesn't actually spend anything but brings new coins into existence). Coinbase transactions have a ...
Pieter Wuille's user avatar
3 votes
Accepted

how to spend an utxo when the corresponding scriptsig is longer than 256 bytes?

The size is encoded as Compact size. These can be up to 9 bytes long and encode a size of anything between zero to 18446744073709551615 bytes. The rules are (according to serialize.h) : /** * ...
arubi's user avatar
  • 1,864
3 votes
Accepted

Step by step example to redeem a P2SH output required

The issue is, scriptsig contains the actual redeemScript instead of the serialized script as a push. The second error, the redeemscript contains an extraneous 0x00 value that should not be there as ...
arubi's user avatar
  • 1,864
3 votes
Accepted

How do I extract the address from a scriptPubKey?

Yes, to get addresses from scriptPubKeys, you will need to do a pattern match. There are only a small number of address types each with their own fixed scriptPubKey pattern. Keep in mind that not all ...
Ava Chow's user avatar
  • 72.2k
3 votes

What are the scriptPubKey, scriptSig, redeem script and witness for the various output types?

I thought it would be useful to have a text version of the image of a table in Michael Folkson's answer. If only for accessibility reasons. (it initially proved rather too hard to edit into his answer ...
RedGrittyBrick's user avatar
3 votes
Accepted

Where are transaction signatures beside the scriptSig?

Modern transaction, since SegWit, include signatures in a new field: the witness. The witness replaces the scriptSig. You can see in your example how txinwitness contains a public key and a signature ...
Antoine Poinsot's user avatar
3 votes
Accepted

What is prepended to the front of a ScriptSig and ScriptPubKey of a P2PKH transction?

In the serialization format, the input and output script are introduced by announcing the length of the script. So that 0x19 indicates that the length of the scriptPubKey is ...
Murch's user avatar
  • 77.9k
3 votes

HOW TO SPEND P2SH with Redeem Script Hex?, Already make the transaction but still have some error

"scriptsig-not-pushonly" refers to the consensus rule that the scriptSig of a P2SH input must only include push operations (see BIP16). Your scriptSig not only includes opcodes other than ...
Vojtěch Strnad's user avatar
3 votes
Accepted

What fields of a coinbase transaction can be empty?

Would a block be accepted in which the coinbase transaction has an empty input scriptSig field? Is there an example of such? No, for unknown reasons there is a consensus rule that the coinbase input ...
Pieter Wuille's user avatar
3 votes
Accepted

Why do some P2SH spending transactions have data both in the ScriptSig and Witness field?

SegWit introduced a compatibility mode usually called wrapped SegWit or nested SegWit. It allows you to create a P2SH output spendable using SegWit rules, which include the witness discount and ...
Vojtěch Strnad's user avatar
3 votes
Accepted

Effect of byte length of r and s on DER encoded signature

The r and s values are prepended with 0x00 if their highest bit is 1 even when they are shorter than 32 bytes. For example, if the r-value is just 80, it will be serialized as 0080. Additional padding ...
Vojtěch Strnad's user avatar
2 votes
Accepted

Why is using a simple SHA1 in a scriptPubKey to emulate a "password" a security problem?

A simple Google search for eb271cbcc2340d0b0e6212903e29f22e578ff69b will reveal the preimage to you.
Pieter Wuille's user avatar
2 votes
Accepted

What is wrong with my ScriptSig? I get 64: scriptsig-not-pushonly

Your signature is not correct. First of all, its length can't be 74 bytes long. According to the Bitcoin wiki: Signatures are either 73, 72, or 71 bytes long, with probabilities approximately 25%, ...
sr_gi's user avatar
  • 3,260
2 votes

Testnet transaction - OPCODE MISSING OR NOT UNDERSTOOD error

quickly verifying: 410404f89c713f44615ad5fdc16f1ef8628351a1cce79ee96130a0e4a6eb09d05278cef28cb002a6ad2ad53181b01d03f931538488a7a689d83684e54822305205d5ba 41 hex equals 65. So the following string ...
pebwindkraft's user avatar
  • 5,116
2 votes
Accepted

Ho to identify a multisig transaction?

As you have found out correctly, the length field describes the following script length. Then the SigScript follows: ...
pebwindkraft's user avatar
  • 5,116
2 votes

How to create a p2sh transaction with a scriptsig of OP_true?

Here you have an example of a transaction spending from a P2PKH output and creating a P2SH output with an OP_1. And here you have the counterpart, a transaction spending from the first one (with an ...
sr_gi's user avatar
  • 3,260
2 votes

Transactions without signatures?

Transactions do not require a signature to be valid. Signatures are just a way of ensuring that the transaction is not going to be spent by anyone, but just by the person who holds the correct private ...
sr_gi's user avatar
  • 3,260
2 votes
Accepted

How do you create a scriptsig for a new raw tx?

Okay, turns out my research has led me to answer my own question, mainly from here though it did lack a bit of explanation or didn't explain, I think, as clearly as it could. So here's my reading/...
Mine's user avatar
  • 1,416

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