IS4302 Lecture 2 Fall 2024
IS4302 Lecture 2 Fall 2024
IS4302
Blockchain and Distributed
Ledger Technologies
Week 2
• Ethereum basics
2
The shared ledger is maintained without a central
authority (“bank”)
Network
4
Consensus algorithm
• Forking:
5
The first person to confirm a new change to the
ledger shares it
Maintainers certify transactions (changes) to the
ledger
Maintainers switch to confirmed ledger and start working on
next version (with transactions from the following 10-minute
cycle)
Proof-of-work system
12
Double spending attack
13
Security
14
Privacy
• The traditional banking model achieves a level of privacy
by limiting access to information to the parties involved
and the trusted third party.
• The necessity to announce all transactions publicly
precludes this method.
• Privacy can still be maintained by breaking the flow of
information in another place: by keeping public keys
anonymous.
• The public can see that someone is sending an amount to
someone else.
• But not knowing who they personally are.
• Similar to the level of information released by stock
exchange 15
Privacy
16
Privacy
17
My summary of blockchain in its original form
• Key ideas
• Distributed power of writing the ledger to avoid trust on
centralized authority.
• “chain” structure to ensure the security of the distributed
ledger.
• Key assumptions
• The majority of the nodes will work honestly on writing
the ledger.
• The nodes will publicize the nonce once they found it for
a block.
18
Overview
• Ethereum basics
19
Overview
• Ethereum basics
• Ethereum vs. Bitcoin
• Proof of Work vs. Proof of Stake
• Smart Contracts
20
Key differences between Bitcoin & Ethereum
21
https://youtu.be/owFY_z5fF-Y
Key differences between Bitcoin & Ethereum
22
UTXO vs Account-based
• What is UTXO?
• “Unspent transaction”
• Each UTXO represents an currently ‘unspent’ note of a
defined value
• Each UTXO can only spent only ONCE
• A transaction takes in unspent UTXO, and generate new ones
• Sum of inputs and outputs is same
23
UTXO model (Bitcoin)
24
UTXO model (Bitcoin)
25
UTXO model (Bitcoin)
26
UTXO model (Bitcoin)
27
UTXO vs Account-based
28
Ethereum model (Ethereum)
29
Ethereum model (Ethereum)
30
Ethereum model (Ethereum)
31
UTXO vs Account-based
32
Overview
• Ethereum basics
• Ethereum vs. Bitcoin
• Proof of Work vs. Proof of Stake
• Smart Contracts
37
Ethereum 2.0
38
Proof of Work (PoW) in Blockchain
39
Proof of Work (PoW) in Blockchain
40
Proof of Work (PoW) in Blockchain
41
Proof of Work (PoW) in Blockchain
42
Proof of Work (PoW) in Blockchain
https://digiconomist.net/bitcoin-energy-consumption
43
Proof of Work (PoW) in Blockchain
44
Mining pools/Significant miners
• Lower Volatility
• Miners form pools to smooth their income
stream.
• Economics of Scale
• Large mining factories are much more cost
effective than a single CPU/GPU.
45
Proof of Work (PoW) in Blockchain
https://chainbulletin.com/bitcoin-mining-map/
46
Proof of Stake (PoS) in Blockchain
47
Proof of Stake (PoS) in Blockchain
• Staking
• You “lock up” a certain amount of tokens and run
a node that validates transactions
48
Proof of Stake (PoS) in Blockchain
• Choosing a Validator
• The blockchain chooses semi-randomly which
“validator node” gets chosen to validate the
transactions in a block and paid a reward
49
Proof of Stake (PoS) in Blockchain
• Choosing a Validator
• The more crypto that is staked, the higher the
chances you will be chosen as a validator
50
Proof of Stake (PoS) in Blockchain
• Validating
• Your computer checks that the signatures are correct and
double spending hasn’t happened
• Other nodes on the network check that the validation is
correct
• If you validate truthfully, you collect the transaction fees. If
you “lie,” your stake is forfeit.
51
Advantages of PoS
• Decentralized
• In PoW mining pools cause centralization, there are
“economies of scale”
• In PoS rewards scale linearly with size of stake
52
Weakness of PoS
• Forking
• If the blockchain “splits” a validator node can have it’s
same stake on both branches and keep validating both
instead of forcing a convergence
53
Proof-of-Authority (Permissioned Chains)
54
Overview
• Ethereum basics
• Ethereum vs. Bitcoin
• Proof of Work vs. Proof of Stake
• Smart Contracts
55
Smart contracts in Ethereum
56
Smart Contract Use Cases
• Finance:
• Insurance, crowd-funding,
cross-border payments,
real-world asset
tokenization
• Games:
• Betting markets, In-game
assets
• Business
• Supply chain tracking,
automatic royalties, voting
57
Overview
• Ethereum basics
58
Solidity – basic structure
• pragma
• Defines solidity version
• Contract / Library
• Features:
• Class Inheritance
• functions
• visibility/scope
• Strongly typed
• Aspect oriented
• Language reference:
https://docs.soliditylang.org/en/v0.8.11/ 60
Solidity – basic structure
Reader.sol
ReadWriter.sol
61
Solidity – basic structure
62
Solidity – basic data types
• bool – boolean
• enum <name> { <member names> … }
• example: enum direction { left, right, up,
down }
• int, uint, int8, uint8, int16, uint16 … uint256
• signed (int) and unsigned (uint) integers (with size, defaults to
256)
• int = int256, uint = uint256
• int8 => 1 byte signed integer
• address – holds a 20 byte address
• contract
• Bytes1 .. Bytes32 – fixed size byte array
• String 63
Solidity – complex data types
• bytes – dynamic array of bytes
• <type>[ ] – dynamic array
• Ex: uint[ ] numberArray;
• mapping( <key type> => <value type> )
hash map of <key type> to <value type>
• Ex: mapping(address => uint) balance;
• struct <name> { <member types> }
• Ex:
struct record {
uint id;
address addr;
}
64
Solidity – storage scope
contract ReadWriter {
function foo() {
uint temp;
}
}
65
Solidity – storage scope
contract ReadWriter {
uint data;
}
66
Solidity – storage scope
67
Solidity – language syntax
68
Solidity – function syntax
69
Solidity –visibility
70
Solidity – function modifier
71
Solidity – function modifier using _
72
Solidity – some special functions & variables
74
Solidity – Library re-use
76
Solidity - events
Definition:
event <name> (<parameters>)
send event:
emit <name> (<parameters>)
77
Solidity – events (example)
78
It should print details similar to as following −
79
Thank you!
80