What is Segwit? Segregated Witness Explained Simply - YouTube

Channel: 99Bitcoins

[11]
What is Segwit?
[12]
Will it truly allow for Bitcoin to scale for mass adoption?
[16]
And how does it even work?
[18]
Well stick around,
[19]
in this episode of Crypto whiteboard Tuesday
[21]
we’ll answer these questions and more.
[29]
Hi, I’m Nate Martin from 99Bitcoins.com
[32]
and welcome to Crypto Whiteboard Tuesday
[34]
where we take complex cryptocurrency topics,
[37]
break them down
[37]
and translate them into plain English.
[39]
Before we begin, don’t forget to subscribe to the channel
[42]
and click the bell so you’ll immediately get notified
[45]
when a new video comes out.
[47]
Today’s topic is Segregated Witness, or Segwit for short.
[51]
Segwit is an upgrade to the Bitcoin network
[53]
that was activated in August of 2017.
[56]
It was first introduced by Developer Pieter Wiulle
[58]
at the Scaling Bitcoin conference in December 2015.
[62]
Segwit aims to solve several issues:
[64]
one of which is Bitcoin’s scalability.
[67]
Bitcoin transactions are written on a Blockchain,
[69]
an immutable ledger
[70]
on which transactions are bundled together into blocks
[73]
that are chained one to the other, in order to determine their order.
[77]
A new block is created roughly every 10 minutes.
[79]
Additionally,
[80]
Bitcoin’s protocol limits the capacity of a block to 1mb,
[84]
which limits a Bitcoin block to around 2700 transactions on average.
[88]
This creates a problem
[89]
when a lot of people are trying to send Bitcoins simultaneously
[93]
as the queue of transactions waiting to enter the blockchain
[95]
gets longer and longer..
[97]
While Visa can process 1,700 transactions per second,
[100]
Bitcoin can process only 4,
[102]
not nearly a scale that could handle mass adoption.
[105]
In order for Bitcoin to truly become usable on a worldwide scale,
[109]
it needs to find a way to increase its transaction capacity.
[112]
Another issue Segwit addresses is transaction malleability.
[116]
Every Bitcoin transaction has 3 parts -
[119]
who sent it (also known as input), who receives it (output),
[123]
and a digital signature
[124]
that verifies that the sender is eligible to send the coins.
[128]
It turns out that Bitcoin’s code allows digital signatures to be altered
[132]
while a transaction is still waiting to get confirmed.
[135]
The signature alteration can be done in such a way that
[138]
if you run a mathematical check on it, it is still valid according to the network.
[142]
But if you run a hashing algorithm on it,
[144]
it gives a different result.
[146]
Let me explain with an example:
[149]
For the sake of simplicity
[150]
let’s say that the signature value was “3”,
[153]
but instead of “3” I change it to “03” or “3+7-7”.
[158]
While mathematically, the values are all the same,
[160]
so it’s still a valid signature,
[162]
if I hash these different versions I will get different results,
[165]
since hashing depends on how you write the value
[168]
and not just the value itself.
[170]
Since the hash is the transaction’s id in the blockchain,
[173]
this means I can effectively change any unconfirmed transaction’s id
[177]
to a different id and it will still be valid.
[181]
Creating a new transaction id for an existing transaction
[183]
can be problematic for a number of reasons:
[186]
First, if you want to build second layer solutions
[188]
on top of the Bitcoin network, like the Lightning Network,
[191]
you need to make sure no one can alter the first layer
[194]
since the one relies on the other.
[196]
If you want to learn more about the Lightning Network
[198]
make sure to catch our episode about it as well.
[201]
Second, altering transaction ids can cause issues
[204]
if you’re spending or accepting unconfirmed funds.
[207]
Let’s go through another example:
[209]
Alice pays Bob in transaction X which is currently unconfirmed.
[213]
Bob uses these unconfirmed funds
[215]
to pay for a product online from Charlie (transaction Y).
[219]
Meanwhile, Charlie sends Bob his product
[221]
before waiting for confirmation on transaction Y.
[224]
After receiving his product,
[226]
Bob does some technical tinkering, and maliciously changes,
[229]
or malleates, Alice’s payment
[231]
so that her transaction, X gets confirmed
[234]
but with a different transaction id.
[236]
Transaction Y, which is what Bob sent to Charlie,
[238]
is now invalid
[240]
since it relies on transaction X’s original transaction id
[244]
that now no longer exists.
[246]
So Charlie won’t get paid
[247]
even though he’s already delivered the goods to Bob.
[251]
Bad Bob...
[253]
While scalability and malleability
[255]
are the two most burning issues that Segwit addresses,
[258]
there are a variety of other technical issues
[260]
that Segwit tackles
[261]
that don’t necessarily affect the end user directly.
[264]
Now that you know what Segwit is,
[266]
let’s talk a bit about how it actually works.
[268]
Segregated Witness is a proposed change
[270]
to how blocks are structured.
[272]
Non segwit blocks, also known as legacy blocks,
[275]
have a total of 1mb space for all of the block data:
[278]
inputs, outputs, signatures and additional scripts.
[281]
Segwit blocks, on the other hand,
[283]
are in fact large 4mb blocks that consist of a base transaction block
[287]
and an extended block.
[289]
So contrary to popular opinion, Segwit is indeed a block size increase.
[295]
Segwit blocks move the digital signature
[297]
and other data known as “the witness” outside of the base transaction block.
[301]
The witness data will still be transmitted,
[303]
but it is placed inside the extended block.
[305]
So the base transaction block includes the information about the sender
[308]
and the receiver
[309]
and the witness data is left blank and doesn’t take up any more space.
[314]
This allows for more transactions to fit inside
[316]
the 1mb base transaction block.
[318]
The extended block (the additional 3mb)
[320]
include all of the witness data that isn’t mandatory
[323]
in the base transaction block.
[325]
The new block format Segwit introduces
[327]
achieves two major goals:
[328]
First, it moves the digital signature outside of the base transaction block.
[333]
This way,
[333]
if someone changes the signature on the transaction,
[335]
it won’t affect the transaction id.
[338]
This in effect solves the transaction malleability issue....
[341]
you know...Bob.
[344]
Second, it shrinks down the base transaction data.
[347]
Since the witness data takes up to 65% of the transaction size,
[351]
moving it outside of the base transaction block
[353]
allows more transactions to fit inside that 1mb block.
[357]
I know what you’re probably thinking.
[359]
If Segwit is in fact a block size increase,
[361]
why not just increase the block size to 4mb in the first place?
[365]
Why all of this hassle and block size debate
[367]
if the end result is in fact bigger blocks.
[370]
The answer is really quite simple -
[372]
developers wanted to avoid a contentious hard fork
[375]
in the Bitcoin network.
[377]
You see, Bitcoin’s protocol specifically states that
[379]
blocks can’t exceed 1mb.
[382]
So, developers had to find a solution
[384]
that will allow the network to accept both Segwit and Non Segwit blocks
[388]
if a hard fork were to be avoided.
[390]
The solution of a 1mb block with an “extension” of another 3mb
[394]
is something that is still acceptable under the existing protocol.
[398]
Legacy nodes receive only the 1mb base transaction block
[402]
without the extended block.
[403]
They still consider them valid.
[405]
Segwit nodes receive both the base and extended block
[408]
(up to 4mb in total)
[410]
and can validate the transactions in full.
[413]
This backwards compatibility is also known as a soft fork.
[417]
This approach is a lot less risky
[418]
since it doesn’t require nodes to update their software to support Segwit.
[423]
It means that even if it takes years for all of the nodes to upgrade,
[426]
the network will still function.
[429]
Now let’s move on to how Segwit blocks are measured by miners.
[434]
While legacy blocks are measured in size,
[436]
Segwit blocks are measured in weight.
[438]
Block Weight is a new concept introduced in Segwit,
[441]
and it’s calculated on a per-transaction basis.
[445]
Each transaction has a “weight” which is defined this way:
[449]
The size of your Base Tx
[451]
(meaning that which doesn’t include the witness data) *3
[454]
+ the Full Tx size, that = your transaction weight.
[460]
Legacy transactions
[461]
don’t have the ability to strip away the witness data from the base transaction,
[465]
so their weight will always be 4 times the tx size.
[469]
For example, a legacy TX of 1000 bytes
[472]
will have a weight of 1000*3 + 1000 = 4000.
[478]
Segwit transactions, on the other hand,
[480]
are going to have a weight of less than 4 times the tx size.
[483]
For example,
[484]
a 1200 byte Segwit transaction comprised of 400 bytes of witness data
[489]
will have a weight of
[490]
(1200 (the total transaction size)-400 (the size of the witness data))
[496]
leaving the base transaction size of 800, times 3,
[499]
making 2400,
[501]
add the total transaction size of 1200, and that = 3600.
[507]
In short,
[508]
the larger the size of the witness data, the lighter the tx weight will be.
[512]
This incentivizes miners to prefer ‘lighter’ Segwit transactions
[516]
over ‘heavier’ ones,
[518]
since they can fit more of them inside a base transaction block,
[521]
which increases the potential miner’s fee,
[523]
should that block be accepted and confirmed.
[526]
While in theory Segwit transactions can create a block up to 4mb in size,
[530]
in practice the average block size that includes Segwit transactions
[534]
is around 2mb.
[536]
Today, almost 50% of all Bitcoin transactions
[539]
are Segwit transactions.
[540]
Since legacy transactions are larger in size,
[543]
they require higher network fees to get confirmed faster.
[546]
And finally,
[547]
Segwit addresses start with a “3” while legacy addresses start with a “1”.
[552]
Thanks to its advantages,
[553]
more and more popular wallets and exchanges support Segwit.
[557]
Ledger, TREZOR, Electrum, Exodus and Coinomi
[560]
are just some of the major wallet brands
[562]
that have already adopted Segwit.
[565]
It’s important to note that if you have a legacy wallet
[567]
and you want to move to a Segwit wallet
[569]
you will need to create a brand new Segwit wallet
[572]
and move all of your funds to its address.
[574]
There’s no way to just upgrade your existing legacy wallet
[577]
to work with Segwit.
[579]
Segwit is the first of many upgrades
[581]
that will gradually allow for Bitcoin to scale for mass adoption.
[585]
It’s a fundamental change that will allow further developments
[587]
down the road
[588]
like the Lightning Network, Schnorr Signatures and more.
[591]
As more and more wallets adopt Segwit,
[593]
it will soon become the standard for any Bitcoin transaction.
[597]
Well, that’s it for today’s episode of Crypto Whiteboard Tuesday.
[600]
Hopefully by now you understand what Segwit is -
[603]
An upgrade to the Bitcoin protocol
[605]
that Segregates the witness data from the base transaction data,
[609]
hence achieving a smaller transaction size,
[612]
securing transactions from malleability issues and more.
[615]
You may still have some questions.
[616]
If so, just leave them in the comment section below.
[619]
And if you’re watching this video on YouTube,
[621]
and enjoy what you’ve seen,
[622]
don’t forget to hit the like button.
[624]
Then make sure to subscribe to the channel
[626]
and click that bell so that you’ll be notified
[627]
as soon as we post new episodes.
[630]
Thanks for watching me here at the Whiteboard.
[632]
For 99bitcoins.com, I’m Nate Martin,
[634]
and I’ll see you
in a bit.