0% found this document useful (0 votes)
3 views50 pages

Lecture 7 - Block

The document discusses blockchain technology, focusing on Bitcoin mining, transaction validation methods like Proof of Work and Proof of Stake, and the UTXO model for tracking unspent transaction outputs. It explains the mechanisms behind transaction verification, the implications of mining difficulty, and the importance of cryptographic protocols like Hashcash. Additionally, it outlines the structure of transactions and the necessary components for implementing a cryptocurrency system.

Uploaded by

sohailyasserr
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views50 pages

Lecture 7 - Block

The document discusses blockchain technology, focusing on Bitcoin mining, transaction validation methods like Proof of Work and Proof of Stake, and the UTXO model for tracking unspent transaction outputs. It explains the mechanisms behind transaction verification, the implications of mining difficulty, and the importance of cryptographic protocols like Hashcash. Additionally, it outlines the structure of transactions and the necessary components for implementing a cryptocurrency system.

Uploaded by

sohailyasserr
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 50

Blockchain and Cryptocurrencies

Bitcoin Mining and UTXOs

Prepared by:
Dr. Hossam Mahmoud Moftah
Faculty of Computers and Artificial Intelligence
Beni-Suef University
Digital Currency – LedgerAlice: 20
Alice: 20 Bob: 11
Bob: 11 Charlie: 5
Charlie: 5 David: 34
David: 34

Bob
Alice: 20
Bob: 11
Alice Charlie: 5
Alice: 20 David: 34
"I am giving 15 Bob: 11
cryptocoins Charlie: 5
David: 34
to Charlie"
Charlie
David

Source: Prof. Tom Austin, San José State University


Digital Currency – LedgerAlice: 5
Alice: 5 Bob: 11
Bob: 11 Charlie: 20
Charlie: 20 David: 34
David: 34

Bob
Alice: 5
Bob: 11
Alice Charlie: 20
Alice: 5 David: 34
Bob: 11
Charlie: 20
David: 34

Charlie
David

Source: Prof. Tom Austin, San José State University


Digital Currency – Ledger
Invalid
transaction!

Bob
Invalid
transaction!
Alice
"I am giving 8
cryptocoins Invalid
to David" transaction!
Charlie
David

Source: Prof. Tom Austin, San José State University


Sybil attack
Invalid
"I am giving VALID! transaction!
8 cryptocoins
to David"
Invalid
transaction
Bob
VALID!
Alice 2
VALID! Charlie

VALID!
Alice
Invalid
transaction!
Alice 3
David
Source: Prof. Tom Austin, San José State University Alice 4
How can we defend against Sybils?
• Know your clients, OR
• Force them to commit some resource
–Proof-of-work
–Proof-of-stake
–Proof-of-storage
–Others?

Source: Prof. Tom Austin, San José State University


Proof of Work vs. Proof of Stake
• Proof of work and proof of stake are the two main
ways cryptocurrency transactions are verified.
• Proof of stake requires participants to put
cryptocurrency as collateral for the opportunity to
successfully approve transactions.
• PoW involves users solving complex puzzles, while
PoS depends on the staking of coins.
• Proof of work is more secure than proof of stake, but
it's slower and consumes more energy.

https://www.businessinsider.com/
https://www.coinbase.com/
Proof of Work vs. Proof of Stake
• Bitcoin, a known cryptocurrency, uses PoW.
• Initially, Ethereum used a competitive proof-of-work
validation process similar to that of Bitcoin. After
several years of development, Ethereum finally
switched to proof-of-stake in 2022, which uses much
less processing power and energy.

https://www.coinbase.com/
https://www.investopedia.com/
Nakamoto Consensus
• Solving PoW puzzle determines "leader"
– i.e., who gets to make a block.
• More profitable to mine than to cheat

Source: Prof. Tom Austin, San José State University


Source: Prof. Tom Austin, San José State University
Source: Prof. Tom Austin, San José State University
Hashcash Protocol
• Hashcash is a cryptographic protocol and proof-of-
work (PoW) system developed by British
cryptographer Dr Adam Back to combat two big
problems: email spam and denial-of-service (DoS)
attacks.
• Uses cryptographic hashes.
• The main idea behind the protocol is to require an
email sender or anyone requesting a service to solve a
mathematical puzzle before being able to send the
email or access the service. It proves you’re not just a
bot or a spammer trying to flood the system.

https://www.binance.com/
Hashcash in Bitcoin
• Target: number of (binary) leading zeroes required for
hash value
• Nonce: random "number used once"
• A hash rate is the rate at which a blockchain network
like Bitcoin generates hashes, or hexadecimal numbers
that are the result of sending transactional data through
hashing algorithms.

Source: Prof. Tom Austin, San José State University


https://www.investopedia.com/
The current Bitcoin hashrate
• The current Bitcoin hashrate is 897.57 EH/s, representing the
global Bitcoin network hashrate with a mining difficulty of
121.51 T (121,507,793,131,898.10) at block height 891,982.

https://www.coinwarz.com/
The current Bitcoin hashrate

https://www.coinwarz.com/
Bitcoin difficulty
• Bitcoin difficulty is a measure of how many hashes (statistically)
must be generated to find a valid solution to solve the next
Bitcoin block and earn the mining reward.
• Bitcoin mining difficulty determines how difficult it will be to
mine the next block and this is why it is referred to as the
difficulty of Bitcoin mining.

https://www.coinwarz.com/
Bitcoin difficulty

https://www.coinwarz.com/
Block height
• The block height of a particular block is defined as the number of
blocks preceding it in the blockchain.
• The very first block on a blockchain is called the genesis block.
It has a block height of zero, as no blocks precede it in the
blockchain. The total height of the blockchain is taken to be the
height of the most recent block, or the highest block, in the
chain.

https://www.investopedia.com/
Proof-of-Work Mining
• Process:
– "Miners" choose a nonce
– If hash(block) meets target, share block
– Otherwise, continue searching
• N = number of leading zeroes required for target
• Work to find valid proof:
– 2N hashes
• Work to verify proof:
– 1 hash

Source: Prof. Tom Austin, San José State University


Sample Block

Source: Prof. Tom Austin, San José State University


Review BlockExplorer
(in class)
Available at https://btc.com/

Source: Prof. Tom Austin, San José State University


How many leading zeroes?

00000000000000000004cf5d4bcee3bec
16c40cc823fb1aeb75c5d9384797c82

Source: Prof. Tom Austin, San José State University


Lab: Proof-of-work
In today's lab, we will review the hash-cash
algorithm used for proof-of-work (PoW) in
Bitcoin.

utils.hash(s+proof)

Source: Prof. Tom Austin, San José State University


UTXO Model

Source: Prof. Tom Austin, San José State University


Two Models of Tracking Balances
• Account-based model
– Track balances for each account
– Simpler
– Used by SpartanGold
• UTXO-based model
– Track unspent coins
– More complex, but (slightly?) better
pseudo-anonymity
– Used by Bitcoin

Source: Prof. Tom Austin, San José State University


What does “UTXO” stand for?

U – Unspent
TX – Transaction
O – Output

Source: Prof. Tom Austin, San José State University


Transaction Chains
• Not the same as blockchains
• Each transaction output can be a future
transaction input.
• Each output can only be spent once
• To know what bitcoins are available you only
need to keep track of the
Unspent Transaction Outputs (UTXOs).

Source: Prof. Tom Austin, San José State University


Transaction Chains

Figure from Mastering Bitcoin

Source: Prof. Tom Austin, San José State University


Transaction Forms

Source: Prof. Tom Austin, San José State University


Common Transactions
Most typical: Alice pays Bob, and keeps the change

Figure from Mastering Bitcoin

Source: Prof. Tom Austin, San José State University


Aggregating Transaction
Alice has many private keys and wants to combine them.

Figure from Mastering Bitcoin

Source: Prof. Tom Austin, San José State University


Distributing Transaction
Alice pays several different people simultaneously.

Figure from Mastering Bitcoin

Source: Prof. Tom Austin, San José State University


HW2: Adding UTXO model to
SpartanGold
• Main change: multiple inputs allowed
• The from, pubKey, and sig fields:
– Single values in standard SpartanGold
– Need to be arrays for the UTXO model
• Some differences from Bitcoin
– We will make transaction fee explicit

Source: Prof. Tom Austin, San José State University


Standard JSON for sample
(parts elided with "…")
transaction
{ from: '4HWTOR8cgvejeMd…',
nonce: 0,
pubKey: '-----BEGIN PUBLIC KEY-----\n' …,
sig: '83adb439…',
fee: 1,
outputs: [
{ amount: 25, address: 'vAy8w7bavN9…' }
],
data: {}
}

Source: Prof. Tom Austin, San José State University


{
SpartanGold: Adding in
Inputs
"from": [
"I3ZtgbDVXVTutleSYHNQ2Hzt9GY5rr4mdRtOs1c+7xw=",
"Y6AhPOu8NsGzfVVlcDjmPpMHkw0mYUKPaPQblMrdxvU="
],
"nonce": 0,
"pubKey": [
"-----BEGIN PUBLIC KEY----- ...",
"-----BEGIN PUBLIC KEY----- ..."
],
"sig": [
"8203f25f23bcc1f5281b1126fa555e2611...",
"d8a0e624e4972053dfbd9fd5d68d3512f5..."
],
...

Source: Prof. Tom Austin, San José State University


{
SpartanGold: Adding in Inputs
"from": [
"I3ZtgbDVXVTutleSYHNQ2Hzt9GY5rr4mdRtOs1c+7xw=",
"Y6AhPOu8NsGzfVVlcDjmPpMHkw0mYUKPaPQblMrdxvU="
],
"nonce": 0,
Outputs
"pubKey": [ (addresses)
"-----BEGIN PUBLIC KEY----- ...", from previous
"-----BEGIN PUBLIC KEY----- ..." transactions
],
"sig": [
"8203f25f23bcc1f5281b1126fa555e2611...",
"d8a0e624e4972053dfbd9fd5d68d3512f5..."
],
...

Source: Prof. Tom Austin, San José State University


{
SpartanGold: Adding in Inputs
"from": [
"I3ZtgbDVXVTutleSYHNQ2Hzt9GY5rr4mdRtOs1c+7xw=",
"Y6AhPOu8NsGzfVVlcDjmPpMHkw0mYUKPaPQblMrdxvU="
],
Not
"nonce": 0,
needed
"pubKey": [
"-----BEGIN PUBLIC KEY----- ...",
"-----BEGIN PUBLIC KEY----- ..."
],
"sig": [
"8203f25f23bcc1f5281b1126fa555e2611...",
"d8a0e624e4972053dfbd9fd5d68d3512f5..."
],
...

Source: Prof. Tom Austin, San José State University


{
SpartanGold: Adding in Inputs
"from": [
"I3ZtgbDVXVTutleSYHNQ2Hzt9GY5rr4mdRtOs1c+7xw=",
"Y6AhPOu8NsGzfVVlcDjmPpMHkw0mYUKPaPQblMrdxvU="
],
"nonce": 0, Public keys
"pubKey": [ matching
previous
"-----BEGIN PUBLIC KEY----- ...",
outputs
"-----BEGIN PUBLIC KEY----- ..."
],
"sig": [
"8203f25f23bcc1f5281b1126fa555e2611...",
"d8a0e624e4972053dfbd9fd5d68d3512f5..."
],
...

Source: Prof. Tom Austin, San José State University


{
SpartanGold: Adding in Inputs
"from": [
"I3ZtgbDVXVTutleSYHNQ2Hzt9GY5rr4mdRtOs1c+7xw=",
"Y6AhPOu8NsGzfVVlcDjmPpMHkw0mYUKPaPQblMrdxvU="
],
"nonce": 0,
"pubKey": [
"-----BEGIN PUBLIC KEY----- ...",
"-----BEGIN PUBLIC KEY----- ..."
],
"sig": [
"8203f25f23bcc1f5281b1126fa555e2611...",
"d8a0e624e4972053dfbd9fd5d68d3512f5..."
],
... Signatures for
previous outputs

Source: Prof. Tom Austin, San José State University


{
SpartanGold: Adding in Inputs
"from": [
"I3ZtgbDVXVTutleSYHNQ2Hzt9GY5rr4mdRtOs1c+7xw=",
"Y6AhPOu8NsGzfVVlcDjmPpMHkw0mYUKPaPQblMrdxvU="
],
"nonce": 0,
Address, key,
"pubKey": [ and signature
"-----BEGIN PUBLIC KEY----- ...", tying back to
"-----BEGIN PUBLIC KEY----- ..." first previous
], output
"sig": [
"8203f25f23bcc1f5281b1126fa555e2611...",
"d8a0e624e4972053dfbd9fd5d68d3512f5..."
],
...

Source: Prof. Tom Austin, San José State University


{
SpartanGold: Adding in Inputs
"from": [
"I3ZtgbDVXVTutleSYHNQ2Hzt9GY5rr4mdRtOs1c+7xw=",
"Y6AhPOu8NsGzfVVlcDjmPpMHkw0mYUKPaPQblMrdxvU="
],
"nonce": 0,
Address, key,
"pubKey": [ and signature
"-----BEGIN PUBLIC KEY----- ...", tying back to
"-----BEGIN PUBLIC KEY----- ..." second previous
], output
"sig": [
"8203f25f23bcc1f5281b1126fa555e2611...",
"d8a0e624e4972053dfbd9fd5d68d3512f5..."
],
...

Source: Prof. Tom Austin, San José State University


...,
SpartanGold: Outputs
"fee": 1,
"outputs": [
{
"amount": 110,
"address":
"j+9fRcMFTVX5hnNzwmL1U8QskUTGSwMehc/nhQGWM5k="
},
{
"amount": 28,
"address":
"XVW5aEtvwVOUyo1+zjjnkFHmkOA1I2t/HBMwj/nQQT0="
}
],
"data": {}
}

Source: Prof. Tom Austin, San José State University


...,
SpartanGold: Outputs
Transaction fee
"fee": 1,
"outputs": [
{
"amount": 110,
"address":
"j+9fRcMFTVX5hnNzwmL1U8QskUTGSwMehc/nhQGWM5k="
},
{
"amount": 28,
"address":
"XVW5aEtvwVOUyo1+zjjnkFHmkOA1I2t/HBMwj/nQQT0="
}
],
"data": {}
}

Source: Prof. Tom Austin, San José State University


...,
SpartanGold: Outputs
Outputs
"fee": 1, (addresses)
"outputs": [ after this round
{
"amount": 110,
"address":
"j+9fRcMFTVX5hnNzwmL1U8QskUTGSwMehc/nhQGWM5k="
},
{
"amount": 28,
"address":
"XVW5aEtvwVOUyo1+zjjnkFHmkOA1I2t/HBMwj/nQQT0="
}
],
"data": {}
}

Source: Prof. Tom Austin, San José State University


...,
SpartanGold: Outputs
"fee": 1,
"outputs": [
{ First UTXO
"amount": 110,
"address":
"j+9fRcMFTVX5hnNzwmL1U8QskUTGSwMehc/nhQGWM5k="
},
{
"amount": 28,
"address":
"XVW5aEtvwVOUyo1+zjjnkFHmkOA1I2t/HBMwj/nQQT0="
}
],
"data": {}
}

Source: Prof. Tom Austin, San José State University


...,
SpartanGold: Outputs
"fee": 1,
NOTE: If you have all UTXOs that
"outputs": [ have not yet been used as a transaction
{ input, you know all available balances.
"amount": 110,
"address":
"j+9fRcMFTVX5hnNzwmL1U8QskUTGSwMehc/nhQGWM5k="
},
{
"amount": 28, Second UTXO
"address":
"XVW5aEtvwVOUyo1+zjjnkFHmkOA1I2t/HBMwj/nQQT0="
}
],
"data": {}
}

Source: Prof. Tom Austin, San José State University


...,
SpartanGold: Outputs
"fee": 1,
"outputs": [
{
"amount": 110,
"address":
"j+9fRcMFTVX5hnNzwmL1U8QskUTGSwMehc/nhQGWM5k="
},
{ Addresses used to
"amount": 28, reference UTXOs as
"address": future inputs
"XVW5aEtvwVOUyo1+zjjnkFHmkOA1I2t/HBMwj/nQQT0="
}
],
"data": {}
}

Source: Prof. Tom Austin, San José State University


Showing transaction chains for
SpartanGold
(in-class)

Source: Prof. Tom Austin, San José State University


HW 2: Review starter code

Source: Prof. Tom Austin, San José State University


Thank you

You might also like