Bitcoin Forum

Bitcoin => Bitcoin Technical Support => Topic started by: ?QuestionMark? on January 12, 2021, 08:58:26 PM



Title: Another segwit question. How is it stored?
Post by: ?QuestionMark? on January 12, 2021, 08:58:26 PM
I know now about segwit that the witness data gets removed from the inputs and for an old node it looks like an everyone can spend output. So the old nodes receive only the <= 1MB block segwit and legacy transactions. It allowes old nodes to operate. And the new ones get the <= 3MB additional segwit data. So where is the witness data stored? Is it in a additional block or a just in a data set like a database?


Title: Re: Another segwit question. How is it stored?
Post by: A-Bolt on January 12, 2021, 09:12:51 PM
So where is the witness data stored?

The witness data is stored in transaction.
From BIP141 (https://github.com/bitcoin/bips/blob/master/bip-0141.mediawiki#transaction-id):
Code:
Legacy tx:
[nVersion][txins][txouts][nLockTime]

SegWit tx:
[nVersion][marker][flag][txins][txouts][witness][nLockTime]



Title: Re: Another segwit question. How is it stored?
Post by: pooya87 on January 13, 2021, 05:12:24 AM
the witness data gets removed from the inputs and for an old node it looks like an everyone can spend output.
It is not possible to remove witness from a transaction just as it is not possible to remove a signature script from a transaction. What you are referring to here is the process of dumbing down the transactions/blocks for old nodes that haven't yet updated to the new features added 4 years ago so that they can accept those blocks and don't fall behind.


Title: Re: Another segwit question. How is it stored?
Post by: ?QuestionMark? on January 13, 2021, 12:05:34 PM
the witness data gets removed from the inputs and for an old node it looks like an everyone can spend output.
It is not possible to remove witness from a transaction just as it is not possible to remove a signature script from a transaction. What you are referring to here is the process of dumbing down the transactions/blocks for old nodes that haven't yet updated to the new features added 4 years ago so that they can accept those blocks and don't fall behind.

Just to be sure.
Theres an extra segwitwitness field in transactions but the scriptSig is empty. Old nodes don't get the segwitwitness in the tx, its dumped down. And the hashed transaction without the witness data is the txid (which prevents changing of sig and txid). Nodes with segwit have have a different hash of tx but the txid is the same?


Title: Re: Another segwit question. How is it stored?
Post by: pooya87 on January 14, 2021, 06:52:22 AM
Just to be sure.
Theres an extra segwitwitness field in transactions but the scriptSig is empty. Old nodes don't get the segwitwitness in the tx, its dumped down. And the hashed transaction without the witness data is the txid (which prevents changing of sig and txid). Nodes with segwit have have a different hash of tx but the txid is the same?
There is a new field called "witness" added to transactions that have at least witness and the signature script content depends on type of the output being spent. For native SegWit inputs version 0 it is empty, for nested SegWit inputs it has to be a special redeem script.
It is simplified for old nodes by removing the witness from transactions.
The transaction ID is calculated using the stripped down version (witness removed) both for backward compatibility and to mitigate some malleability issues.
The transaction ID/hash that is used in inputs is the stripped down hash. The "witness transaction ID/hash" is the hash of the entire transaction with its witnesses and is only used in merkle root computation for commitment in coinbase transaction.