Whereas there are widespread patterns that can be utilized to find out the output sort from the enter that spends it, the one surefire approach to know the output sort is to examine the output itself. Since that info shouldn’t be offered by the spending transaction, it’s not potential to make this willpower definitively.
Nevertheless, as I discussed, there are some widespread patterns. Inputs that spend Segwit v0 keyhash outputs can solely look a sure means. Such inputs may have no scriptSig and may have a witness stack containing two gadgets. The final stack merchandise might be a public key, identifiable by its size of both 33 bytes or 64 bytes, and have a number one byte of one among 0x02, 0x03, or 0x04. The second merchandise in that stack might be a signature that follows DER strictly.
For Segwit v1 Taproot outputs, the witness stacks can range relying on the spending methodology. If it’s a keypath spend, then there might be just one merchandise and it is going to be a signature that’s 64 or 65 bytes lengthy. There aren’t any encoding guidelines that place mounted bytes, so that’s all you should have.
Taproot script path spends are way more difficult. They may have a minimum of 2 witness stack parts. The final factor is the management block and might be 33 + 32m bytes lengthy, the place m is an integer between 0 and 128 inclusive. The management block’s first byte is the leaf model, which is presently solely 0xc0. The next 32 bytes are the Taproot inside pubkey, adopted by 32 byte hashes for the branches Taproot merkle tree, adopted by the 32 byte merkle root. The second to final factor within the stack would be the tapscript. The TapLeaf hash of this script might be mixed with the branches given within the management block so as to calculate the merkle root. The entire remaining stack gadgets depend upon the script.
Whereas inputs that spend v0 keyhash and v1 taproot outputs will appear like this, they aren’t essentially unique. It’s theoretically potential to have v0 scripthash spends that look an identical to those patterns. It’s potential that future segwit variations may have enter stacks that look an identical. It is also potential that somebody can spend a presently undefined segwit model and supply enter stacks that look an identical to those. Figuring out the output sort primarily based on the enter knowledge shouldn’t be assured to be right.
