SlideShare a Scribd company logo
1 of 32
Download to read offline
Bitcoin Internals
Who am I?
James Turner
Polyglot programmer
Worked for ebay , BBC, BSkyB
CTO @ magnr.com
2
Topics
• Binary protocols
• Hashing and probability
• Bloom Filters
• Merkle Trees
• P2P networks and CAP theorem
3
What is a binary protocol?
4
What is a binary protocol
A binary protocol is a protocol which is intended or expected to
be read by a machine rather than a human being, as opposed
to a plain text protocol such as IRC, SMTP, or HTTP. Binary
protocols have the advantage of terseness, which translates into
speed of transmission and interpretation.
5https://en.wikipedia.org/wiki/Binary_protocol
Wikipedia says…
NOT a binary protocol
6
Our own binary protocol?
We can define our own “Sandwich” protocol as
1) a 32 bit Integer for number of cheese slices
followed by
2) a 32 bit Integer for number of ham slices
So our binary protocol (assuming Big Endian) for 1,1 sandwich would be:
00000000 00000000 00000000 00000001 00000000 00000000 00000000 00000001
This is a fixed format. There are no variable sized parts.
7https://en.wikipedia.org/wiki/Comparison_of_data_serialization_formats
Binary Protocol Efficiency
Our “Sandwich” protocol uses 8 bytes to transmit the cheese
and ham information.
Compare this to JSON, where we might have
{“cheese”:1,”ham”:1}
This is 20 bytes
In this example, we’re >50% more efficient.
However, sometimes you can’t read a binary protocol, our
terminal output would be “”
8
There are 8 bytes here honestly!
Variable length binary protocol
The “Message” protocol:
1) a 32 bit Integer
followed by
2) a variable number of bytes (chars)
So our binary output for 5”hello” would be
00000000 00000000 00000000 00000101 1101000 1100101 1101100 1101100 1101111
9https://en.wikipedia.org/wiki/Comparison_of_data_serialization_formats
Bitcoin protocol
10https://en.bitcoin.it/wiki/Protocol_documentation#Message_structure
Block
Message Header
What is hashing?
A computational function that takes an arbitrary sized input, and produces a fixed
size output.
e.g. sha256(“hello”) produces
“2cf24dba5fb0a30e26e83b2ac5b9e29e1b161e5c1fa7425e73043362938b9824”
Hashing has certain properties which we find useful:
• It’s extremely hard to reverse, and calculate the original data from the hash.
• If the input data changes even slightly the hash output is completely different.
11
Hashing collision probability
If 2 pieces of input data produce the same output hash, we have a
“collision”.
Given the random nature of hashing, what is the probability that for any 2
pieces of input data we would generate identical hashes?
If the output of the hashing function is a single byte
e.g. 01101011 or 01111111 or 01110001
We can see that there is a 1 in 256 (2^8) chance of getting a collision.
This can be generalised to 1/(2^n) where n is number of bits.
12
Merkle Trees
13
Root Hash 1234
TX1
Hash0 

hash(TX1)
Hash 01

hash(Hash0 , Hash1 )
TX2
Hash1 

hash(TX2)
TX3
Hash2 

hash(TX3)
TX4
Hash3 

hash(TX4)
Data
Hash 23

hash(Hash2 , Hash3 )
Verify a TX using Merkle Trees
14
H 12345678
TX1
H1
H12
DataTX2 TX3 TX4 TX5 TX6 TX7 TX8
H2 H3 H4 H5 H6 H7 H8
H34 H56 H78
H1234 H5678
Verify TX8 exists in block
https://en.bitcoin.it/wiki/Merged_mining_specification#Merkle_Branch
Merkle Blocks
15
Merkle Block Message
https://github.com/bitcoin/bips/blob/master/bip-0037.mediawiki
Bloom Filters
Let’s assume we have 2 hash functions “f” and “g”
f(x) and g(x) produce 2 random outputs
e.g.
f(“hello”) => 123
g(“hello”) => 192
16https://en.wikipedia.org/wiki/Bloom_filter
Bloom Filters
We have an array of bits, let’s say 8 (this will fit a single byte).
such that the empty bitset looks like this:
17https://en.wikipedia.org/wiki/Bloom_filter
Bloom Filters
By performing the modulus (%) of each hash output with 8 (the size of
the bitset) we should get the following:
123 % 8 =3
192 % 8 = 0
We now mark positions 0 and 3 as “1” bits
18https://en.wikipedia.org/wiki/Bloom_filter
Bloom Filters
19https://en.wikipedia.org/wiki/Bloom_filter
f(“hello”) g(“hello”) f(“world”) g(“world”)
Bloom Filters (exists)
20https://en.wikipedia.org/wiki/Bloom_filter
f(“world”) g(“world”) f(“bar”) g(“bar”)
Bloom Filters (false positives)
21https://en.wikipedia.org/wiki/Bloom_filter
f(“foo”) g(“foo”)
Bloom Filters (error rate)
22https://en.wikipedia.org/wiki/Bloom_filter
m bits
k is number of hashing functions
k=2 , hash functions f & g
m=8
m is the number of bits in our bitset
n is the number of items represented
n=1, “hello”
f(“hello”)
probability of a single bit NOT being set is (1 - 1/8)^2 , more generally (1-1/m)^k

as n grows, this becomes (1-1/m)^kn
g(“hello”)
Bloom Filter properties
• Memory compaction (lots of items in a small space)
• Possible existence (and false positives)
• Collision probability determined by number of items/number
of bits
23
Bloom Filters in Bitcoin
24
filteradd, filterload, filterremove
CAP theorem
• Consistency
• Availability
• Partition Tolerance
25
https://en.wikipedia.org/wiki/CAP_theorem
The CAP theorem is a negative result that says you cannot
simultaneously achieve all three goals in the presence of
errors. Hence, you must pick one objective to give up.
http://cacm.acm.org/blogs/blog-cacm/83396-errors-in-database-systems-eventual-consistency-and-the-cap-
theorem/fulltext
CAP theorem in P2P networks
26
A node in the Bitcoin network
Availability
27
X
Available
Available Available
Available
Available
Available
Available
Available
Available
Available
Unavailable
Network: Available
Unavailable
X
Partitioning
28
X
X
Partitioned
TX
TX
TX
Consistency
29
Block 222B
Network: Inconsistent
Block 222B
Block 222B Block 222B
Block 222B
Block 222A Block 222A
Block 222A
Block 222A
Block 222A
Block 222A
Block 222A
Consistency
30
Block 223
Network: Consistent
Block 223
Block 223 Block 223
Block 223
Block 223 Block 223
Block 223
Block 223
Block 223
Block 223
Block 223
Other P2P protocols
• BitTorrent (Distributed Hash Tables)
• Gnutella (Query Routing Tables)
31https://en.wikipedia.org/wiki/List_of_P2P_protocols
Questions?
32

More Related Content

Similar to Bitcoin Internals

Blockchain, cryptography and tokens — NYC Bar presentation
Blockchain, cryptography and tokens — NYC Bar presentationBlockchain, cryptography and tokens — NYC Bar presentation
Blockchain, cryptography and tokens — NYC Bar presentationPaperchain
 
Conference presentation final
Conference presentation finalConference presentation final
Conference presentation finalALYAA AL-BARRAK
 
Sharding in MongoDB 4.2 #what_is_new
 Sharding in MongoDB 4.2 #what_is_new Sharding in MongoDB 4.2 #what_is_new
Sharding in MongoDB 4.2 #what_is_newAntonios Giannopoulos
 
“Technical Intro to Blockhain” by Yurijs Pimenovs from Paybis at CryptoCurren...
“Technical Intro to Blockhain” by Yurijs Pimenovs from Paybis at CryptoCurren...“Technical Intro to Blockhain” by Yurijs Pimenovs from Paybis at CryptoCurren...
“Technical Intro to Blockhain” by Yurijs Pimenovs from Paybis at CryptoCurren...Dace Barone
 
Metadata in the Blockchain: The OP_RETURN Explosion
Metadata in the Blockchain: The OP_RETURN ExplosionMetadata in the Blockchain: The OP_RETURN Explosion
Metadata in the Blockchain: The OP_RETURN ExplosionCoin Sciences Ltd
 
Zn task - defcon russia 20
Zn task  - defcon russia 20Zn task  - defcon russia 20
Zn task - defcon russia 20DefconRussia
 
EthereumBlockchainMarch3 (1).pptx
EthereumBlockchainMarch3 (1).pptxEthereumBlockchainMarch3 (1).pptx
EthereumBlockchainMarch3 (1).pptxWijdenBenothmen1
 
BlockchainHub Graz Meetup #22 - Atomic Swaps - Johannes Zweng
BlockchainHub Graz Meetup #22 - Atomic Swaps - Johannes ZwengBlockchainHub Graz Meetup #22 - Atomic Swaps - Johannes Zweng
BlockchainHub Graz Meetup #22 - Atomic Swaps - Johannes ZwengBlockchainHub Graz
 
"Source Code Abstracts Classification Using CNN", Vadim Markovtsev, Lead Soft...
"Source Code Abstracts Classification Using CNN", Vadim Markovtsev, Lead Soft..."Source Code Abstracts Classification Using CNN", Vadim Markovtsev, Lead Soft...
"Source Code Abstracts Classification Using CNN", Vadim Markovtsev, Lead Soft...Dataconomy Media
 
Efficient Data Storage for Analytics with Apache Parquet 2.0
Efficient Data Storage for Analytics with Apache Parquet 2.0Efficient Data Storage for Analytics with Apache Parquet 2.0
Efficient Data Storage for Analytics with Apache Parquet 2.0Cloudera, Inc.
 
Efficient Data Storage for Analytics with Parquet 2.0 - Hadoop Summit 2014
Efficient Data Storage for Analytics with Parquet 2.0 - Hadoop Summit 2014Efficient Data Storage for Analytics with Parquet 2.0 - Hadoop Summit 2014
Efficient Data Storage for Analytics with Parquet 2.0 - Hadoop Summit 2014Julien Le Dem
 
Crypto & Crpyocurrencies Intro
Crypto & Crpyocurrencies IntroCrypto & Crpyocurrencies Intro
Crypto & Crpyocurrencies IntroTal Shmueli
 
Data streaming algorithms
Data streaming algorithmsData streaming algorithms
Data streaming algorithmsHridyesh Bisht
 
International Journal of Computational Engineering Research(IJCER)
 International Journal of Computational Engineering Research(IJCER)  International Journal of Computational Engineering Research(IJCER)
International Journal of Computational Engineering Research(IJCER) ijceronline
 
Deploy a blockchain web-app with Hyperledger Fabric 1.4 - Concepts & Code
Deploy a blockchain web-app with Hyperledger Fabric 1.4 - Concepts & CodeDeploy a blockchain web-app with Hyperledger Fabric 1.4 - Concepts & Code
Deploy a blockchain web-app with Hyperledger Fabric 1.4 - Concepts & CodeHorea Porutiu
 
Deployablockchainwebappwithhyperledgerfabricpresentation 190820170703
Deployablockchainwebappwithhyperledgerfabricpresentation 190820170703Deployablockchainwebappwithhyperledgerfabricpresentation 190820170703
Deployablockchainwebappwithhyperledgerfabricpresentation 190820170703Nevruz Mesut Sahin
 
Java on arm theory, applications, and workloads [dev5048]
Java on arm  theory, applications, and workloads [dev5048]Java on arm  theory, applications, and workloads [dev5048]
Java on arm theory, applications, and workloads [dev5048]Aleksei Voitylov
 
Dc ch07 : error control and data link control
Dc ch07 : error control and data link controlDc ch07 : error control and data link control
Dc ch07 : error control and data link controlSyaiful Ahdan
 

Similar to Bitcoin Internals (20)

Blockchain, cryptography and tokens — NYC Bar presentation
Blockchain, cryptography and tokens — NYC Bar presentationBlockchain, cryptography and tokens — NYC Bar presentation
Blockchain, cryptography and tokens — NYC Bar presentation
 
Conference presentation final
Conference presentation finalConference presentation final
Conference presentation final
 
Data type
Data typeData type
Data type
 
Sharding in MongoDB 4.2 #what_is_new
 Sharding in MongoDB 4.2 #what_is_new Sharding in MongoDB 4.2 #what_is_new
Sharding in MongoDB 4.2 #what_is_new
 
“Technical Intro to Blockhain” by Yurijs Pimenovs from Paybis at CryptoCurren...
“Technical Intro to Blockhain” by Yurijs Pimenovs from Paybis at CryptoCurren...“Technical Intro to Blockhain” by Yurijs Pimenovs from Paybis at CryptoCurren...
“Technical Intro to Blockhain” by Yurijs Pimenovs from Paybis at CryptoCurren...
 
Metadata in the Blockchain: The OP_RETURN Explosion
Metadata in the Blockchain: The OP_RETURN ExplosionMetadata in the Blockchain: The OP_RETURN Explosion
Metadata in the Blockchain: The OP_RETURN Explosion
 
Zn task - defcon russia 20
Zn task  - defcon russia 20Zn task  - defcon russia 20
Zn task - defcon russia 20
 
EthereumBlockchainMarch3 (1).pptx
EthereumBlockchainMarch3 (1).pptxEthereumBlockchainMarch3 (1).pptx
EthereumBlockchainMarch3 (1).pptx
 
BlockchainHub Graz Meetup #22 - Atomic Swaps - Johannes Zweng
BlockchainHub Graz Meetup #22 - Atomic Swaps - Johannes ZwengBlockchainHub Graz Meetup #22 - Atomic Swaps - Johannes Zweng
BlockchainHub Graz Meetup #22 - Atomic Swaps - Johannes Zweng
 
"Source Code Abstracts Classification Using CNN", Vadim Markovtsev, Lead Soft...
"Source Code Abstracts Classification Using CNN", Vadim Markovtsev, Lead Soft..."Source Code Abstracts Classification Using CNN", Vadim Markovtsev, Lead Soft...
"Source Code Abstracts Classification Using CNN", Vadim Markovtsev, Lead Soft...
 
Efficient Data Storage for Analytics with Apache Parquet 2.0
Efficient Data Storage for Analytics with Apache Parquet 2.0Efficient Data Storage for Analytics with Apache Parquet 2.0
Efficient Data Storage for Analytics with Apache Parquet 2.0
 
Efficient Data Storage for Analytics with Parquet 2.0 - Hadoop Summit 2014
Efficient Data Storage for Analytics with Parquet 2.0 - Hadoop Summit 2014Efficient Data Storage for Analytics with Parquet 2.0 - Hadoop Summit 2014
Efficient Data Storage for Analytics with Parquet 2.0 - Hadoop Summit 2014
 
Crypto & Crpyocurrencies Intro
Crypto & Crpyocurrencies IntroCrypto & Crpyocurrencies Intro
Crypto & Crpyocurrencies Intro
 
Data streaming algorithms
Data streaming algorithmsData streaming algorithms
Data streaming algorithms
 
International Journal of Computational Engineering Research(IJCER)
 International Journal of Computational Engineering Research(IJCER)  International Journal of Computational Engineering Research(IJCER)
International Journal of Computational Engineering Research(IJCER)
 
Deploy a blockchain web-app with Hyperledger Fabric 1.4 - Concepts & Code
Deploy a blockchain web-app with Hyperledger Fabric 1.4 - Concepts & CodeDeploy a blockchain web-app with Hyperledger Fabric 1.4 - Concepts & Code
Deploy a blockchain web-app with Hyperledger Fabric 1.4 - Concepts & Code
 
Deployablockchainwebappwithhyperledgerfabricpresentation 190820170703
Deployablockchainwebappwithhyperledgerfabricpresentation 190820170703Deployablockchainwebappwithhyperledgerfabricpresentation 190820170703
Deployablockchainwebappwithhyperledgerfabricpresentation 190820170703
 
Java on arm theory, applications, and workloads [dev5048]
Java on arm  theory, applications, and workloads [dev5048]Java on arm  theory, applications, and workloads [dev5048]
Java on arm theory, applications, and workloads [dev5048]
 
Dc ch07 : error control and data link control
Dc ch07 : error control and data link controlDc ch07 : error control and data link control
Dc ch07 : error control and data link control
 
Cryptography 202
Cryptography 202Cryptography 202
Cryptography 202
 

Recently uploaded

VIP 7001035870 Find & Meet Hyderabad Call Girls Dilsukhnagar high-profile Cal...
VIP 7001035870 Find & Meet Hyderabad Call Girls Dilsukhnagar high-profile Cal...VIP 7001035870 Find & Meet Hyderabad Call Girls Dilsukhnagar high-profile Cal...
VIP 7001035870 Find & Meet Hyderabad Call Girls Dilsukhnagar high-profile Cal...aditipandeya
 
Top Rated Pune Call Girls Daund ⟟ 6297143586 ⟟ Call Me For Genuine Sex Servi...
Top Rated  Pune Call Girls Daund ⟟ 6297143586 ⟟ Call Me For Genuine Sex Servi...Top Rated  Pune Call Girls Daund ⟟ 6297143586 ⟟ Call Me For Genuine Sex Servi...
Top Rated Pune Call Girls Daund ⟟ 6297143586 ⟟ Call Me For Genuine Sex Servi...Call Girls in Nagpur High Profile
 
Low Rate Young Call Girls in Sector 63 Mamura Noida ✔️☆9289244007✔️☆ Female E...
Low Rate Young Call Girls in Sector 63 Mamura Noida ✔️☆9289244007✔️☆ Female E...Low Rate Young Call Girls in Sector 63 Mamura Noida ✔️☆9289244007✔️☆ Female E...
Low Rate Young Call Girls in Sector 63 Mamura Noida ✔️☆9289244007✔️☆ Female E...SofiyaSharma5
 
Radiant Call girls in Dubai O56338O268 Dubai Call girls
Radiant Call girls in Dubai O56338O268 Dubai Call girlsRadiant Call girls in Dubai O56338O268 Dubai Call girls
Radiant Call girls in Dubai O56338O268 Dubai Call girlsstephieert
 
How is AI changing journalism? (v. April 2024)
How is AI changing journalism? (v. April 2024)How is AI changing journalism? (v. April 2024)
How is AI changing journalism? (v. April 2024)Damian Radcliffe
 
Call Now ☎ 8264348440 !! Call Girls in Shahpur Jat Escort Service Delhi N.C.R.
Call Now ☎ 8264348440 !! Call Girls in Shahpur Jat Escort Service Delhi N.C.R.Call Now ☎ 8264348440 !! Call Girls in Shahpur Jat Escort Service Delhi N.C.R.
Call Now ☎ 8264348440 !! Call Girls in Shahpur Jat Escort Service Delhi N.C.R.soniya singh
 
VIP 7001035870 Find & Meet Hyderabad Call Girls LB Nagar high-profile Call Girl
VIP 7001035870 Find & Meet Hyderabad Call Girls LB Nagar high-profile Call GirlVIP 7001035870 Find & Meet Hyderabad Call Girls LB Nagar high-profile Call Girl
VIP 7001035870 Find & Meet Hyderabad Call Girls LB Nagar high-profile Call Girladitipandeya
 
Moving Beyond Twitter/X and Facebook - Social Media for local news providers
Moving Beyond Twitter/X and Facebook - Social Media for local news providersMoving Beyond Twitter/X and Facebook - Social Media for local news providers
Moving Beyond Twitter/X and Facebook - Social Media for local news providersDamian Radcliffe
 
On Starlink, presented by Geoff Huston at NZNOG 2024
On Starlink, presented by Geoff Huston at NZNOG 2024On Starlink, presented by Geoff Huston at NZNOG 2024
On Starlink, presented by Geoff Huston at NZNOG 2024APNIC
 
'Future Evolution of the Internet' delivered by Geoff Huston at Everything Op...
'Future Evolution of the Internet' delivered by Geoff Huston at Everything Op...'Future Evolution of the Internet' delivered by Geoff Huston at Everything Op...
'Future Evolution of the Internet' delivered by Geoff Huston at Everything Op...APNIC
 
𓀤Call On 7877925207 𓀤 Ahmedguda Call Girls Hot Model With Sexy Bhabi Ready Fo...
𓀤Call On 7877925207 𓀤 Ahmedguda Call Girls Hot Model With Sexy Bhabi Ready Fo...𓀤Call On 7877925207 𓀤 Ahmedguda Call Girls Hot Model With Sexy Bhabi Ready Fo...
𓀤Call On 7877925207 𓀤 Ahmedguda Call Girls Hot Model With Sexy Bhabi Ready Fo...Neha Pandey
 
Call Girls In Defence Colony Delhi 💯Call Us 🔝8264348440🔝
Call Girls In Defence Colony Delhi 💯Call Us 🔝8264348440🔝Call Girls In Defence Colony Delhi 💯Call Us 🔝8264348440🔝
Call Girls In Defence Colony Delhi 💯Call Us 🔝8264348440🔝soniya singh
 
Lucknow ❤CALL GIRL 88759*99948 ❤CALL GIRLS IN Lucknow ESCORT SERVICE❤CALL GIRL
Lucknow ❤CALL GIRL 88759*99948 ❤CALL GIRLS IN Lucknow ESCORT SERVICE❤CALL GIRLLucknow ❤CALL GIRL 88759*99948 ❤CALL GIRLS IN Lucknow ESCORT SERVICE❤CALL GIRL
Lucknow ❤CALL GIRL 88759*99948 ❤CALL GIRLS IN Lucknow ESCORT SERVICE❤CALL GIRLimonikaupta
 
Call Girls In Pratap Nagar Delhi 💯Call Us 🔝8264348440🔝
Call Girls In Pratap Nagar Delhi 💯Call Us 🔝8264348440🔝Call Girls In Pratap Nagar Delhi 💯Call Us 🔝8264348440🔝
Call Girls In Pratap Nagar Delhi 💯Call Us 🔝8264348440🔝soniya singh
 
10.pdfMature Call girls in Dubai +971563133746 Dubai Call girls
10.pdfMature Call girls in Dubai +971563133746 Dubai Call girls10.pdfMature Call girls in Dubai +971563133746 Dubai Call girls
10.pdfMature Call girls in Dubai +971563133746 Dubai Call girlsstephieert
 
SEO Growth Program-Digital optimization Specialist
SEO Growth Program-Digital optimization SpecialistSEO Growth Program-Digital optimization Specialist
SEO Growth Program-Digital optimization SpecialistKHM Anwar
 
Call Girls In Sukhdev Vihar Delhi 💯Call Us 🔝8264348440🔝
Call Girls In Sukhdev Vihar Delhi 💯Call Us 🔝8264348440🔝Call Girls In Sukhdev Vihar Delhi 💯Call Us 🔝8264348440🔝
Call Girls In Sukhdev Vihar Delhi 💯Call Us 🔝8264348440🔝soniya singh
 

Recently uploaded (20)

VIP 7001035870 Find & Meet Hyderabad Call Girls Dilsukhnagar high-profile Cal...
VIP 7001035870 Find & Meet Hyderabad Call Girls Dilsukhnagar high-profile Cal...VIP 7001035870 Find & Meet Hyderabad Call Girls Dilsukhnagar high-profile Cal...
VIP 7001035870 Find & Meet Hyderabad Call Girls Dilsukhnagar high-profile Cal...
 
Call Girls In Noida 📱 9999965857 🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SERVICE
Call Girls In Noida 📱  9999965857  🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SERVICECall Girls In Noida 📱  9999965857  🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SERVICE
Call Girls In Noida 📱 9999965857 🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SERVICE
 
Top Rated Pune Call Girls Daund ⟟ 6297143586 ⟟ Call Me For Genuine Sex Servi...
Top Rated  Pune Call Girls Daund ⟟ 6297143586 ⟟ Call Me For Genuine Sex Servi...Top Rated  Pune Call Girls Daund ⟟ 6297143586 ⟟ Call Me For Genuine Sex Servi...
Top Rated Pune Call Girls Daund ⟟ 6297143586 ⟟ Call Me For Genuine Sex Servi...
 
Low Rate Young Call Girls in Sector 63 Mamura Noida ✔️☆9289244007✔️☆ Female E...
Low Rate Young Call Girls in Sector 63 Mamura Noida ✔️☆9289244007✔️☆ Female E...Low Rate Young Call Girls in Sector 63 Mamura Noida ✔️☆9289244007✔️☆ Female E...
Low Rate Young Call Girls in Sector 63 Mamura Noida ✔️☆9289244007✔️☆ Female E...
 
Radiant Call girls in Dubai O56338O268 Dubai Call girls
Radiant Call girls in Dubai O56338O268 Dubai Call girlsRadiant Call girls in Dubai O56338O268 Dubai Call girls
Radiant Call girls in Dubai O56338O268 Dubai Call girls
 
How is AI changing journalism? (v. April 2024)
How is AI changing journalism? (v. April 2024)How is AI changing journalism? (v. April 2024)
How is AI changing journalism? (v. April 2024)
 
Call Now ☎ 8264348440 !! Call Girls in Shahpur Jat Escort Service Delhi N.C.R.
Call Now ☎ 8264348440 !! Call Girls in Shahpur Jat Escort Service Delhi N.C.R.Call Now ☎ 8264348440 !! Call Girls in Shahpur Jat Escort Service Delhi N.C.R.
Call Now ☎ 8264348440 !! Call Girls in Shahpur Jat Escort Service Delhi N.C.R.
 
VIP 7001035870 Find & Meet Hyderabad Call Girls LB Nagar high-profile Call Girl
VIP 7001035870 Find & Meet Hyderabad Call Girls LB Nagar high-profile Call GirlVIP 7001035870 Find & Meet Hyderabad Call Girls LB Nagar high-profile Call Girl
VIP 7001035870 Find & Meet Hyderabad Call Girls LB Nagar high-profile Call Girl
 
Moving Beyond Twitter/X and Facebook - Social Media for local news providers
Moving Beyond Twitter/X and Facebook - Social Media for local news providersMoving Beyond Twitter/X and Facebook - Social Media for local news providers
Moving Beyond Twitter/X and Facebook - Social Media for local news providers
 
Rohini Sector 22 Call Girls Delhi 9999965857 @Sabina Saikh No Advance
Rohini Sector 22 Call Girls Delhi 9999965857 @Sabina Saikh No AdvanceRohini Sector 22 Call Girls Delhi 9999965857 @Sabina Saikh No Advance
Rohini Sector 22 Call Girls Delhi 9999965857 @Sabina Saikh No Advance
 
On Starlink, presented by Geoff Huston at NZNOG 2024
On Starlink, presented by Geoff Huston at NZNOG 2024On Starlink, presented by Geoff Huston at NZNOG 2024
On Starlink, presented by Geoff Huston at NZNOG 2024
 
'Future Evolution of the Internet' delivered by Geoff Huston at Everything Op...
'Future Evolution of the Internet' delivered by Geoff Huston at Everything Op...'Future Evolution of the Internet' delivered by Geoff Huston at Everything Op...
'Future Evolution of the Internet' delivered by Geoff Huston at Everything Op...
 
𓀤Call On 7877925207 𓀤 Ahmedguda Call Girls Hot Model With Sexy Bhabi Ready Fo...
𓀤Call On 7877925207 𓀤 Ahmedguda Call Girls Hot Model With Sexy Bhabi Ready Fo...𓀤Call On 7877925207 𓀤 Ahmedguda Call Girls Hot Model With Sexy Bhabi Ready Fo...
𓀤Call On 7877925207 𓀤 Ahmedguda Call Girls Hot Model With Sexy Bhabi Ready Fo...
 
Dwarka Sector 26 Call Girls | Delhi | 9999965857 🫦 Vanshika Verma More Our Se...
Dwarka Sector 26 Call Girls | Delhi | 9999965857 🫦 Vanshika Verma More Our Se...Dwarka Sector 26 Call Girls | Delhi | 9999965857 🫦 Vanshika Verma More Our Se...
Dwarka Sector 26 Call Girls | Delhi | 9999965857 🫦 Vanshika Verma More Our Se...
 
Call Girls In Defence Colony Delhi 💯Call Us 🔝8264348440🔝
Call Girls In Defence Colony Delhi 💯Call Us 🔝8264348440🔝Call Girls In Defence Colony Delhi 💯Call Us 🔝8264348440🔝
Call Girls In Defence Colony Delhi 💯Call Us 🔝8264348440🔝
 
Lucknow ❤CALL GIRL 88759*99948 ❤CALL GIRLS IN Lucknow ESCORT SERVICE❤CALL GIRL
Lucknow ❤CALL GIRL 88759*99948 ❤CALL GIRLS IN Lucknow ESCORT SERVICE❤CALL GIRLLucknow ❤CALL GIRL 88759*99948 ❤CALL GIRLS IN Lucknow ESCORT SERVICE❤CALL GIRL
Lucknow ❤CALL GIRL 88759*99948 ❤CALL GIRLS IN Lucknow ESCORT SERVICE❤CALL GIRL
 
Call Girls In Pratap Nagar Delhi 💯Call Us 🔝8264348440🔝
Call Girls In Pratap Nagar Delhi 💯Call Us 🔝8264348440🔝Call Girls In Pratap Nagar Delhi 💯Call Us 🔝8264348440🔝
Call Girls In Pratap Nagar Delhi 💯Call Us 🔝8264348440🔝
 
10.pdfMature Call girls in Dubai +971563133746 Dubai Call girls
10.pdfMature Call girls in Dubai +971563133746 Dubai Call girls10.pdfMature Call girls in Dubai +971563133746 Dubai Call girls
10.pdfMature Call girls in Dubai +971563133746 Dubai Call girls
 
SEO Growth Program-Digital optimization Specialist
SEO Growth Program-Digital optimization SpecialistSEO Growth Program-Digital optimization Specialist
SEO Growth Program-Digital optimization Specialist
 
Call Girls In Sukhdev Vihar Delhi 💯Call Us 🔝8264348440🔝
Call Girls In Sukhdev Vihar Delhi 💯Call Us 🔝8264348440🔝Call Girls In Sukhdev Vihar Delhi 💯Call Us 🔝8264348440🔝
Call Girls In Sukhdev Vihar Delhi 💯Call Us 🔝8264348440🔝
 

Bitcoin Internals

  • 2. Who am I? James Turner Polyglot programmer Worked for ebay , BBC, BSkyB CTO @ magnr.com 2
  • 3. Topics • Binary protocols • Hashing and probability • Bloom Filters • Merkle Trees • P2P networks and CAP theorem 3
  • 4. What is a binary protocol? 4
  • 5. What is a binary protocol A binary protocol is a protocol which is intended or expected to be read by a machine rather than a human being, as opposed to a plain text protocol such as IRC, SMTP, or HTTP. Binary protocols have the advantage of terseness, which translates into speed of transmission and interpretation. 5https://en.wikipedia.org/wiki/Binary_protocol Wikipedia says…
  • 6. NOT a binary protocol 6
  • 7. Our own binary protocol? We can define our own “Sandwich” protocol as 1) a 32 bit Integer for number of cheese slices followed by 2) a 32 bit Integer for number of ham slices So our binary protocol (assuming Big Endian) for 1,1 sandwich would be: 00000000 00000000 00000000 00000001 00000000 00000000 00000000 00000001 This is a fixed format. There are no variable sized parts. 7https://en.wikipedia.org/wiki/Comparison_of_data_serialization_formats
  • 8. Binary Protocol Efficiency Our “Sandwich” protocol uses 8 bytes to transmit the cheese and ham information. Compare this to JSON, where we might have {“cheese”:1,”ham”:1} This is 20 bytes In this example, we’re >50% more efficient. However, sometimes you can’t read a binary protocol, our terminal output would be “” 8 There are 8 bytes here honestly!
  • 9. Variable length binary protocol The “Message” protocol: 1) a 32 bit Integer followed by 2) a variable number of bytes (chars) So our binary output for 5”hello” would be 00000000 00000000 00000000 00000101 1101000 1100101 1101100 1101100 1101111 9https://en.wikipedia.org/wiki/Comparison_of_data_serialization_formats
  • 11. What is hashing? A computational function that takes an arbitrary sized input, and produces a fixed size output. e.g. sha256(“hello”) produces “2cf24dba5fb0a30e26e83b2ac5b9e29e1b161e5c1fa7425e73043362938b9824” Hashing has certain properties which we find useful: • It’s extremely hard to reverse, and calculate the original data from the hash. • If the input data changes even slightly the hash output is completely different. 11
  • 12. Hashing collision probability If 2 pieces of input data produce the same output hash, we have a “collision”. Given the random nature of hashing, what is the probability that for any 2 pieces of input data we would generate identical hashes? If the output of the hashing function is a single byte e.g. 01101011 or 01111111 or 01110001 We can see that there is a 1 in 256 (2^8) chance of getting a collision. This can be generalised to 1/(2^n) where n is number of bits. 12
  • 13. Merkle Trees 13 Root Hash 1234 TX1 Hash0 hash(TX1) Hash 01 hash(Hash0 , Hash1 ) TX2 Hash1 hash(TX2) TX3 Hash2 hash(TX3) TX4 Hash3 hash(TX4) Data Hash 23 hash(Hash2 , Hash3 )
  • 14. Verify a TX using Merkle Trees 14 H 12345678 TX1 H1 H12 DataTX2 TX3 TX4 TX5 TX6 TX7 TX8 H2 H3 H4 H5 H6 H7 H8 H34 H56 H78 H1234 H5678 Verify TX8 exists in block https://en.bitcoin.it/wiki/Merged_mining_specification#Merkle_Branch
  • 15. Merkle Blocks 15 Merkle Block Message https://github.com/bitcoin/bips/blob/master/bip-0037.mediawiki
  • 16. Bloom Filters Let’s assume we have 2 hash functions “f” and “g” f(x) and g(x) produce 2 random outputs e.g. f(“hello”) => 123 g(“hello”) => 192 16https://en.wikipedia.org/wiki/Bloom_filter
  • 17. Bloom Filters We have an array of bits, let’s say 8 (this will fit a single byte). such that the empty bitset looks like this: 17https://en.wikipedia.org/wiki/Bloom_filter
  • 18. Bloom Filters By performing the modulus (%) of each hash output with 8 (the size of the bitset) we should get the following: 123 % 8 =3 192 % 8 = 0 We now mark positions 0 and 3 as “1” bits 18https://en.wikipedia.org/wiki/Bloom_filter
  • 21. Bloom Filters (false positives) 21https://en.wikipedia.org/wiki/Bloom_filter f(“foo”) g(“foo”)
  • 22. Bloom Filters (error rate) 22https://en.wikipedia.org/wiki/Bloom_filter m bits k is number of hashing functions k=2 , hash functions f & g m=8 m is the number of bits in our bitset n is the number of items represented n=1, “hello” f(“hello”) probability of a single bit NOT being set is (1 - 1/8)^2 , more generally (1-1/m)^k as n grows, this becomes (1-1/m)^kn g(“hello”)
  • 23. Bloom Filter properties • Memory compaction (lots of items in a small space) • Possible existence (and false positives) • Collision probability determined by number of items/number of bits 23
  • 24. Bloom Filters in Bitcoin 24 filteradd, filterload, filterremove
  • 25. CAP theorem • Consistency • Availability • Partition Tolerance 25 https://en.wikipedia.org/wiki/CAP_theorem The CAP theorem is a negative result that says you cannot simultaneously achieve all three goals in the presence of errors. Hence, you must pick one objective to give up. http://cacm.acm.org/blogs/blog-cacm/83396-errors-in-database-systems-eventual-consistency-and-the-cap- theorem/fulltext
  • 26. CAP theorem in P2P networks 26 A node in the Bitcoin network
  • 29. Consistency 29 Block 222B Network: Inconsistent Block 222B Block 222B Block 222B Block 222B Block 222A Block 222A Block 222A Block 222A Block 222A Block 222A Block 222A
  • 30. Consistency 30 Block 223 Network: Consistent Block 223 Block 223 Block 223 Block 223 Block 223 Block 223 Block 223 Block 223 Block 223 Block 223 Block 223
  • 31. Other P2P protocols • BitTorrent (Distributed Hash Tables) • Gnutella (Query Routing Tables) 31https://en.wikipedia.org/wiki/List_of_P2P_protocols