Title: Total confusion about Scriptpubkey, Standard and non standard Transactions Post by: Felicity_Tide on June 12, 2024, 05:10:52 AM So lately, I have been finding it difficult to understand the relationship between ScriptPubKey and standard transactions. When I try to relate the ideal meanings of both terms, there seem to be some similarities.
ScriptPubKey is a script that contains steps on how Bitcoin can be spent. In other words, we can say that it helps to control how one can spend Bitcoin. Standard transactions from my perspective are transactions that meet all the necessary criteria, including confirmation and validation. There seem to be several(types) attributes tied to both of them, which are: 1. P2PK 2. P2PKH 3. P2SH 4. P2MS 5. P2TR 6. P2WKH 7. P2WSH I am quite familiar with few of the types listed above, such as P2PK, which means paying(pay) to public key. P2PKH, which means paying(pay) to public key hash(same as paying to an address. P2SH, which means paying(pay) to script hash. P2WKH, which means paying(pay) to witness key hash, and P2WSH, which means paying(pay) to witness script hash. Aside from that, I also observed that there is a phrase "non standard transactions", which sounds like the opposite of "standard transactions". I tried to find a straightforward article to give me a better explanation of its meaning which I couldn't get, but had to reason from an ideal perspective which is: non standard transactions are transactions that might not meet the necessary criteria. There are speculations that such transactions end up in the block, which I don't understand because the phrase says "non standard". My questions: 1. Is there any proper definition for ScriptPubKey, standard and non standard transactions?. 2. Do ScriptPubKey and standard transactions mean the same thing?. 3. How do P2TR and P2MS work?. 4. Is it possible for a transaction to be non standard and still be valid?. 5. Can you explain the last paragraph above?. This thread is basically to seek answers to my questions and confusion, which means, only the reply section is likely to be %100 accuracy. I am 100% open to correction as I still see myself as a learner. Pardon any of my error and share your personal opinion. You might want to also DOYR after reading this. Mod, please move the thread if it doesn't fit or contain enough technical matters Title: Re: Total confusion about Scriptpubkey, Standard and non standard Transactions Post by: vjudeu on June 12, 2024, 07:32:38 AM Quote Is there any proper definition for ScriptPubKey, standard and non standard transactions? https://github.com/bitcoin/bitcoin/blob/master/src/policy/policy.cpp#L70Quote Code: bool IsStandard(const CScript& scriptPubKey, const std::optional<unsigned>& max_datacarrier_bytes, TxoutType& whichType) Quote Do ScriptPubKey and standard transactions mean the same thing? No. When you have "scriptPubKey", then it is just a field, expressed as "const CScript& scriptPubKey", which contains raw bytes of the Script. But "IsStandard()" is a function, taking "scriptPubKey" as one of arguments, and it can return "bool" saying "true" if a transaction is standard, or "false" if it is not.Quote How do P2TR and P2MS work? https://github.com/bitcoin/bitcoin/blob/master/src/script/solver.cpp#L140Quote Code: TxoutType Solver(const CScript& scriptPubKey, std::vector<std::vector<unsigned char>>& vSolutionsRet) Quote Is it possible for a transaction to be non standard and still be valid? Of course. Non-standard and invalid are two different things.Quote Can you explain the last paragraph above? Non-standard transaction, which is valid: https://mempool.space/testnet4/tx/09096e1e6fb31f33f3de40b9a1d76908e565e9646e5aed4e0813e0a2a799fc4cTitle: Re: Total confusion about Scriptpubkey, Standard and non standard Transactions Post by: Findingnemo on June 12, 2024, 07:53:42 AM Aside from that, I also observed that there is a phrase "non standard transactions", which sounds like the opposite of "standard transactions". I tried to find a straightforward article to give me a better explanation of its meaning which I couldn't get, but had to reason from an ideal perspective which is: non standard transactions are transactions that might not meet the necessary criteria. 5. Can you explain the last paragraph above?. Non standard transaction is something that doesn't follow Bitcoin's protocol rules which are Code: Check syntactic correctness Any transaction that doesn't meet these criteria can be classified as a non-standard transaction and it was supposed to be rejected by the nodes and so the miners but not necessary, there are examples that nonstandard transactions were mined. Recently there was one pool that accepted a non-standard transaction and was successfully mined but it came with a bounty. Here's the user's/pool's post: https://bitcointalk.org/index.php?topic=5192454.msg55842508#msg55842508 (https://bitcointalk.org/index.php?topic=5192454.msg55842508#msg55842508) As the name suggests it's highly rare though. Title: Re: Total confusion about Scriptpubkey, Standard and non standard Transactions Post by: ABCbits on June 12, 2024, 09:58:48 AM Aside from that, I also observed that there is a phrase "non standard transactions", which sounds like the opposite of "standard transactions". I tried to find a straightforward article to give me a better explanation of its meaning which I couldn't get, but had to reason from an ideal perspective which is: non standard transactions are transactions that might not meet the necessary criteria. 5. Can you explain the last paragraph above?. Non standard transaction is something that doesn't follow Bitcoin's protocol rules which are Code: Check syntactic correctness Do you write it yourself or find it elsewhere? While i don't remember all rules, i recall transaction considered as non-standard if the size is higher than 100 vKB or 400000 weight unit. Title: Re: Total confusion about Scriptpubkey, Standard and non standard Transactions Post by: vjudeu on June 12, 2024, 10:08:44 AM Quote Do you write it yourself or find it elsewhere? Let's see: https://en.bitcoin.it/wiki/Protocol_rules#%22tx%22_messagesTitle: Re: Total confusion about Scriptpubkey, Standard and non standard Transactions Post by: Felicity_Tide on June 12, 2024, 10:53:40 AM https://github.com/bitcoin/bitcoin/blob/master/src/policy/policy.cpp#L70 Code: bool IsStandard(const CScript& scriptPubKey, const std::optional<unsigned>& max_datacarrier_bytes, TxoutType& whichType) No. When you have "scriptPubKey", then it is just a field, expressed as "const CScript& scriptPubKey", which contains raw bytes of the Script. But "IsStandard()" is a function, taking "scriptPubKey" as one of arguments, and it can return "bool" saying "true" if a transaction is standard, or "false" if it is not. NOTED Code: if (whichType == TxoutType::NONSTANDARD) { With the basic knowledge I have in C++, I was able to remember some syntax here, so reading wasn't that difficult. But the last line of code Is a little bit confusing Code: else if (whichType == TxoutType::NULL_DATA Does the NULL_DATA represents txoutput(data) with zero value entry? . Quote How do P2TR and P2MS work? https://github.com/bitcoin/bitcoin/blob/master/src/script/solver.cpp#L140Code: TxoutType Solver(const CScript& scriptPubKey, std::vector<std::vector<unsigned char>>& vSolutionsRet) This part was a little bit complex to understand, but with list of switch statements written above the code, I will assume that they were all threated in the main code. Code: std::string GetTxnOutputType(TxoutType t) Non standard transaction is something that doesn't follow Bitcoin's protocol rules which are Code: ~ Any transaction that doesn't meet these criteria can be classified as a non-standard transaction and it was supposed to be rejected by the nodes and so the miners but not necessary, there are examples that nonstandard transactions were mined. As the name suggests it's highly rare though. Noted. Have just bookmarked the rules for future referencing. While i don't remember all rules, i recall transaction considered as non-standard if the size is higher than 100 vKB or 400000 weight unit. Noted. Should probably add this to the rules also. Title: Re: Total confusion about Scriptpubkey, Standard and non standard Transactions Post by: nc50lc on June 12, 2024, 11:40:05 AM Non standard transaction is something that doesn't follow Bitcoin's protocol rules which are The term "non-standard" do not apply to transactions that have broken the Bitcoin "protocol".-snip- As the name suggests it's highly rare though. Those that broken the protocol have no chance to be included to a block because if ever included by a miner, the block itself will be invalid. The provided example (the quote of my post) is something that didn't comply with the majority of the nodes' "policy" instead. So the miner that included the transaction to his block still managed to add it to the blockchain since it is still valid in the protocol. The policy related to that "Uncompressed SegWit" incident is in (SCRIPT_VERIFY_WITNESS_PUBKEYTYPE):
Title: Re: Total confusion about Scriptpubkey, Standard and non standard Transactions Post by: vjudeu on June 12, 2024, 12:28:23 PM Quote Does the NULL_DATA represents txoutput(data) with zero value entry? https://github.com/bitcoin/bitcoin/blob/master/src/script/solver.h#L22Quote Code: enum class TxoutType { Quote This part was a little bit complex to understand https://github.com/bitcoin/bitcoin/blob/master/src/script/solver.cpp#L164Quote Code: if (witnessversion == 1 && witnessprogram.size() == WITNESS_V1_TAPROOT_SIZE) { https://github.com/bitcoin/bitcoin/blob/master/src/script/solver.cpp#L196 Quote Code: int required; Title: Re: Total confusion about Scriptpubkey, Standard and non standard Transactions Post by: pooya87 on June 13, 2024, 04:55:48 AM A non-standard transaction is a valid transaction that we prefer not to have included in a block. It can have different reasons as well.
For example it is perfectly valid to create a P2WPKH output using an uncompressed public key but it is considered non-standard and rejected. The reason is because uncompressed pubkeys are bigger and using them would be inefficient usage of block space. So they are "discouraged" by being counted as non-standard. They weren't made invalid because after all an uncompressed public key is still a valid public key. Another example would be the limits on OP_RETURN size which is to prevent abuse so that people don't turn bitcoin blockchain into cloud storage. So the size of such outputs are limited to 80 bytes. Another example is limits on other fields such as transaction version (ver >3 or <1 are non-standard) that is to preserve them for possible future usage. It is easier to just add the (if ver == x) line in the code if there has never been any tx version = x than it is to add exception cases that skip the previous txs with version = x. Title: Re: Total confusion about Scriptpubkey, Standard and non standard Transactions Post by: NotATether on June 13, 2024, 06:09:47 AM The scriptpubkey field contains what you might consider to be a scripting language, and the opcodes that are inside take one parameter, the "stack", which is either in the scriptsig or in the witness data depending on whether the transaction format is segwit or legacy. The stack has a bunch of values on it which the code in the scriptpubkey "pops" (in stack nomenclature, removing the top value) and it can also "push" (add values to the top) its own data to it.
The purpose of the scriptpubkey is to keep the bitcoins in place until someone unlocks them by putting a stack that makes the script return a "1" (just a single 1 on the stack) inside a transaction - along with the UTXO being spent, of course. If it returns anything else then it is considered a failure and the transaction is invalid. Title: Re: Total confusion about Scriptpubkey, Standard and non standard Transactions Post by: Felicity_Tide on June 13, 2024, 02:31:20 PM A non-standard transaction is a valid transaction that we prefer not to have included in a block. It can have different reasons as well. For example it is perfectly valid to create a P2WPKH output using an uncompressed public key but it is considered non-standard and rejected. The reason is because uncompressed pubkeys are bigger and using them would be inefficient usage of block space. So they are "discouraged" by being counted as non-standard. They weren't made invalid because after all an uncompressed public key is still a valid public key. The choice of not including a non-standard transaction in the block, was it a general community agreement?. Because I read an article which am not too sure of the authenticity, that says : Non-standard transactions are submitted to a miner directly rather than dropping them in the mempool waiting for approval. The article specified that this transactions are hard to get approval especially when they are seated at the mempool. I am not really sure of how certain transactions are given to miners directly because it sounds strange to me. Please clarify me on this, so I don't learn something wrong. The scriptpubkey field contains what you might consider to be a scripting language, and the opcodes that are inside take one parameter, the "stack", which is either in the scriptsig or in the witness data depending on whether the transaction format is segwit or legacy. The stack has a bunch of values on it which the code in the scriptpubkey "pops" (in stack nomenclature, removing the top value) and it can also "push" (add values to the top) its own data to it. The purpose of the scriptpubkey is to keep the bitcoins in place until someone unlocks them by putting a stack that makes the script return a "1" (just a single 1 on the stack) inside a transaction - along with the UTXO being spent, of course. If it returns anything else then it is considered a failure and the transaction is invalid. Noted So, for more clarity, does this mean that the ScriptPubKey acts as a locking script, while the other two (ScriptSig and ScriptWitness) act as unlocking scripts for SegWit and Legacy individually?. Title: Re: Total confusion about Scriptpubkey, Standard and non standard Transactions Post by: pooya87 on June 13, 2024, 03:27:49 PM The choice of not including a non-standard transaction in the block, was it a general community agreement?. Because I read an article which am not too sure of the authenticity, that says : Non-standard transactions are submitted to a miner directly rather than dropping them in the mempool waiting for approval. The article specified that this transactions are hard to get approval especially when they are seated at the mempool. I am not really sure of how certain transactions are given to miners directly because it sounds strange to me. When you want to spend coins, you create a transaction then broadcast it to the network by sending it to a handful other full nodes. The Bitcoin Network is a web of these interconnected nodes. Your transaction would propagate throughout the network as each node relays it to other nodes, eventually reaching majority of node including the nodes used by miners. Then the miner can select some of transactions from its own node and mine the block, hence confirming your tx.Please clarify me on this, so I don't learn something wrong. Each full node has its own mempool that stores the valid transactions they receive. They criteria to enter their mempool is consensus rules and they can also choose to enforce standard rules. Since the majority of full nodes are running bitcoin core, majority of the network is enforcing all standard rules by default. This means when you broadcast a non-standard transaction, majority of full nodes reject it so it won't propagate and the chances of it reaching a miner is small. This is why the only way to get your non-standard tx confirmed is to first find a miner that accepts non-standard transactions (miners run the same software and usually reject such txs as well) and then directly send your tx to their node. |