Bech32 (starts with bc1) and P2SH (starts with 3) can both be used for segwit transactions. I know bech32 is supposed to create smaller transactions, but I'd like to know how much smaller (than P2SH). How do transactions coming from a normal single-key address compare?
2 Answers
bech32 produces smaller transactions than P2SH segwit transactions.
- one extra byte per output to create P2SH outputs than to create bech32 utxos (P2SH uses
OP_HASH160
andOP_EQUAL
in addition to a 20 byte hash in its script, whereas bech32 just uses a fixed00
byte in addition to a 20 byte hash), and - 23 extra bytes per input to spend from P2SH utxos than from bech32 utxos (P2SH has to produce the script that was hashed when spending in the sigscript, which takes 23 bytes to encode - bech32 has no non-witness sigscript at all).
Basically P2SH requires a script hash, native SegWit doesn't, and everything else is much the same. Native SegWit provides the script when the output is created, and P2SH provides it when the output is spent.
If you want to know how much you saved (or can save) in each transaction, Blockstream explorer provides nice feature, where you can see the savings. For example for this transaction, can save extra 16% on fees
-
-
bitcoincore.org/en/segwit_wallet_dev/… says "Comparing with the P2SH versions, the transaction vsize of native versions is smaller in most cases". Feb 26, 2018 at 14:47
-
1
They are both just an encoding. The resulting tx could be exactly identical. In real life however people use bech32 just fur native segwit transactions, while p2sh is used as a wrapper around segwit. the tx is actually a tiny bit smaller when using p2sh.
-
2Oh really? P2SH is actually smaller? What's the advantage of bech32 then? I don't quite understand what "native" means in the context of "native segwit". By the way, do you have sources where we could read more about this / verify your answer?– B TDec 26, 2017 at 23:24
-
1The best source is always the actual source. bech32 have been proposed in bip173 which you can find here: github.com/bitcoin/bips/blob/master/bip-0173.mediawiki It also has a section on how bech32 is better than different encodings. For the size there is no definite source without specifying what exactly you want to compare. bech32 is an encoding, p2sh is a type of transaction. For my comparison I assumed that bech32 is equivalent to native segwit.– bluesDec 31, 2017 at 23:56
-
1This answer is false in multiple ways: 1. It's not just a different encoding, wrapped segwit and native segwit outputs are different output types. When funds are sent to a wrapped segwit address, they can only be spent in a wrapped segwit input, and vice versa for native segwit. 2. Wrapped segwit and native segwit transactions cannot be identical, even though they can have equivalent effect (at different fee costs). 3. Wrapped segwit transactions use more blockspace, than native segwit transactions.– Murch ♦Apr 10, 2021 at 18:19