0% found this document useful (0 votes)
6 views

week2

Uploaded by

mzmindykkyan
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views

week2

Uploaded by

mzmindykkyan
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 117

CSIT6000Q-Blockchain &

Smart Contracts
Week – 2
Pritom Rajkhowa
Quick Recap from Last Week
What is a hash function?
• CHOP & MIX

Plan Text
Plan Text
What is Hashing or Hash Function?
Hash Function

SHA256("Some Message or File")=

Hash or Digest
Qualities of Hash Functions
• Unique Hash Values: It should be impossible to generate same output
for different output.

• Speed of Hash : It is need to be quick to produce result.

• Secure : It need to be secure. It need to almost impossible to


determine input based on output. And slight change in input lead to
big change in Digest.
Different Type of Hashing Algorithm

https://emn178.github.io/online-tools/
https://www.tools4noobs.com/online_tools/hash/
HASH BASED MESSAGE
AUTHENTICATION CODE(HMAC)

Plan Text
Plan Text

Shared Key
Data Integrity
Hashing is used to provide Integrity
• Sender calculate Digest from the message
• Sender sent message and Digest
• Receiver calculate Digest from received message
• Receiver compare both Digest
o If both match, then message is integral
o If both donot match, then message is compomise
Data Integrity
Hashing is used to provide Integrity
• Both parties establish mutual private key
• Sender combained the message + private key to generate the digest
• Receiver verifies by calculating the message + private key
o Message is not definatly modified in transit Intergrtiy
o Sender must have identical key Authenatication
USER PASSWORD
SYMMETRIC ENCRYPTION
Public Key Encryption
Digital Signature
Digital Signature
Ledger

Bob paid Alice $20

Alice paid Eve $220

Eve paid Bob $50


Protocol
• Anyone can add line in Ledger.
• Settle up all with real money.
Ledger

Bob paid Alice $20

Alice paid Eve $220

Eve paid Bob $50

Eve paid Bob $50

Eve paid Bob $50


Protocol
• Anyone can add line in Ledger.
• Settle up all with real money.
• Only Sign transaction are valid.
Ledger

Bob paid Alice $20

Alice paid Eve $220

Eve paid Bob $50

Eve paid Bob $50


Protocol
• Anyone can add line in Ledger.
• Settle up all with real money.
• Only Sign transaction are valid.
Ledger

Bob paid Alice $20

Alice paid Eve $220

Eve paid Bob $50

Eve paid Bob $50


Ledger

Bob paid Alice $20

Alice paid Eve $220

Alice paid Eve $220

Alice paid Eve $220


Ledger

1. Bob paid Alice $20

2. Alice paid Eve $220

3. Alice paid Eve $220

4. Alice paid Eve $220


Protocol
• Anyone can add line in Ledger.
• Only Sign transaction are valid.
• No Overspending.
Ledger

1. Bob get $100

2. Alice get $100

3. Eve get $100

4. Eve paid Bob $50

5. Eve paid Bob $50

6. Eve paid Bob $20

INVALID
Eve's Balan
ce
Ledger

$100 ​+
1. Bob get $100 $50 ​-
$0 ​-
2. Alice get $100
Overdrawn
3. Eve get $100

4. Eve paid Bob $150

5. Eve paid Bob $50

6. Eve paid Bob $20

INVALID
Ledger This is the step
that detached
real money from
1. Bob get $100 this process

2. Alice get $100

3. Eve get $100

4. Eve paid Bob $150

5. Eve paid Bob $50

6. Eve paid Bob $20

INVALID
Ledger

1. Bob paid Alice LD20

2. Alice paid Eve LD100

3. Bob paid Eve LD120


Ledger

1. Bob paid Alice LD20

2. Alice paid Eve LD220

3. Bob paid Eve LD100


Currency Transaction
Decentralize Centralize

LD
The problem of the Byzantine Generals

“It is not sufficient that everyone knows X. We also need everyone to know that everyone knows X, and that everyone knows
that everyone knows that everyone knows X — which, as in the Byzantine Generals’ problem, is the classic hard problem of
distributed data processing.”
- James A. Donald

Prior to Bitcoin, this problem was considered perhaps impossible to


solve. Computer scientists declared in 1982 that the generals’
problem can at most be reduced to a “commander and lieutenant”
problem, in which all lieutenants must act in accordance with the
commander’s orders, as long as they are loyal. They have shown that
the problem can only have a solution if more than two-thirds of the
generals are loyal.
COORDINATED ATTACK
UNCOORDINATED ATTACK
1. Bob paid Alice LD20

1. Bob paid Alice LD20


1. Bob paid Alice LD20
Protocol
• Anyone can add line in Ledger.
• Only Sign transaction are valid.
• No Overspending.

What to add
here?
Computation Work

Main Tool : Cryptographic Hash Function


Block No #

Nonce

1. Bob paid Alice LD20


2. Alice paid Eve LD220
3. Bob paid Eve $100

0000DF2E57FB432A

000082BAE315474D
Hash is a number ALL POSSIBLE HASH VALUES

Largest

6D7CD92FDFD7E920
= 7889419446888425760

0000DF2E57FB432A
= 0000245390137574186

00000082BAE31547
= 000000561481192775

smallest
Hash is a number ALL POSSIBLE HASH VALUES

Largest

6D7CD92FDFD7E920
= 7889419446888425760

0000DF2E57FB432A
= 0000245390137574186

00000082BAE31547
= 000000561481192775
TARGET
smallest
Hash is a number ALL POSSIBLE HASH VALUES

Largest

6D7CD92FDFD7E920
= 7889419446888425760

0000DF2E57FB432A
= 0000245390137574186

00000082BAE31547
= 000000561481192775
TARGET
Express Target with leading zeros smallest
Hash is a number ALL POSSIBLE HASH VALUES

Largest

6D7CD92FDFD7E920
= 7889419446888425760

0000DF2E57FB432A
= 0000245390137574186

00000082BAE31547
= 000000561481192775
TARGET
Express Target with leading zeros smallest
Largest

Block No # Nonce 23

Nonce Nonce 21

1. Bob paid Alice LD20


2. Alice paid Eve LD220

3. Bob paid Eve $100 Nonce 2367


Nonce 5323

0000DF2E57FB432A
000082BAE315474D
TARGET
Nonce 12

smallest
Probability 1 / 230 ≈ 1/ 1,000,000,000

Ledger
30 Zero
1. Bob paid Alice LD20

2. Alice paid Eve LD220

3. Bob paid Eve $100

1786498 SHA256
Computation Work
Bob paid Alice LD50 Alice paid Bob LD20
Bob paid Alice LD20
{Signature} {Signature} {Signature}

Bob paid Eve LD20 Eve paid Alice LD30 Alice paid Eve LD100
{Signature} {Signature} {Signature}

Proof of Work Proof of Work Proof of Work

Blocks
Bob paid Alice LD50 Alice paid Bob LD20
Bob paid Alice LD20
{Signature} {Signature} {Signature}

Bob paid Eve LD20 Eve paid Alice LD30 Alice paid Eve LD100
{Signature} {Signature} {Signature}

85665780 81224567 78567901

Blocks
Bob paid Alice LD50 Alice paid Bob LD20
Bob paid Alice LD20
{Signature} {Signature} {Signature}

Bob paid Eve LD20 Eve paid Alice LD30 Alice paid Eve LD100
{Signature} {Signature} {Signature}

85665780 81224567 78567901

SHA256 SHA256 SHA256


MUST START WITH 60 ZEROS

SHA256

Transaction

85665780
Bob paid Alice LD50 Alice paid Bob LD20
Bob paid Alice LD20
{Signature} {Signature} {Signature}

Bob paid Eve LD20 Eve paid Alice LD30 Alice paid Eve LD100
{Signature} {Signature} {Signature}

85665780 81224567 78567901

SHA256 SHA256 SHA256


Previous Hash Previous Hash Previous Hash

Bob paid Alice LD50 Alice paid Bob LD20


Bob paid Alice LD20
{Signature} {Signature} {Signature}

Bob paid Eve LD20 Eve paid Alice LD30 Alice paid Eve LD100
{Signature} {Signature} {Signature}

85665780 78567901
81224567

LEDGER

BLOCK CHAIN
Immutable Ledger

Traditional Ledger
Block Creator 1

Block Creator 2

Block Creator 3
Bob paid Alice LD20
{Signature}

Bob paid Eve LD20


Block Creator 1 {Signature}

Eve paid Alice LD30


{Signature}

Block Creator 2

Block Creator 3
Previous Hash

Bob paid Alice LD20


{Signature}

Bob paid Eve LD20


Block Creator 1 {Signature}

Eve paid Alice LD30


{Signature}

7567454092

Block Creator 2
SHA256

Block Creator 3
Block Creator 1

Block Creator 2

Block Creator 3
Previous Hash

Reword LD10

Bob paid Alice LD20


{Signature}

Bob paid Eve LD20


Block Creator 1 {Signature}

Eve paid Alice LD30


{Signature}

7567454092

Block Creator 2
SHA256

Block Creator 3
Conflicting Transaction
TRUST CENTRAL
AUTHORITY
COMPUTATION
WORK
Eve want to fraud
Bob with fake
transaction

Transaction

85665780
Eve want to fraud
Bob with fake
transaction

Transaction

85665780
Ethereum
Publish in 2014
Smart Contract
• Written using EVM

• Can also store data

• Written in high level language


How it work
• Class containing field and method.

• Compile Solidity to EVM bytecode.

• Sending EVM bytecode to Network.

• Send transaction invoke methods.


Gas
• Gas is a unit of computation.

• Price of Gas expressed as Ether.

• Paid by sender of transaction.


NETWORK

Current Block Reword 6.25 bitcoins 2.097 Eth

Block Time 10 min 14 second

Market Cap BTC 537.93B ETH 208.28B


Mining Centralization
• Bitcoin mining exploited by ASICs

• ASICs creates mining centralization.

• Ethereum target to use GPU to


reduce centralization.
Ethereum Scaling Challenge
• Throughput is 16 TPS.

• Congestion during peak network activity.

• Developing scaling technique like sharding, Proof of


stack and state channel.
1. Address 1. Address

2. Private Key 2. Private Key

3. Balance 3. Balance
1. Address
2. Private Key
1. Address
3. Balance
2. Private Key
3. Balance

1. Address 1. Address

2. Private Key 2. Private Key

3. Balance 3. Balance
1. Address 1. Address
2. Private Key 2. Private Key
3. Balance
3. Balance

1. Address 1. Address

2. Private Key 2. Private Key

3. Balance 3. Balance
1. Address 1. Address 1. Address
2. Private Key 2. Private Key 2. Private Key
3. Balance 3. Balance 3. Balance
dAPP
9

3 3
3
9

4 2.5
1.5
9

3 3
3
X
Natural Disasters
Data
I need 10% of all collected sum.
I can also gain profit from
currency exchange
The Remix Editor
The Remix Editor
The Remix Editor
The Remix Editor
The Remix Editor
The Remix Editor
The Remix Editor
The Remix Editor
The Remix Editor
The Remix Editor
The Remix Editor
The Remix Editor
The Remix Editor
The Remix Editor
The Remix Editor
The Remix Editor
The Remix Editor
Solidity supports three types of
variables.
• State Variables − Variables whose values are permanently stored in a
contract storage.
• Local Variables − Variables whose values are present till function is
executing.
• Global Variables − Special variables exists in the global namespace
used to get information about the blockchain.
Solidity : A Deep Dive into its
Mechanism
Ethereum Virtual Machine (EVM)
First, click the Create New File icon in the File Explorers
tab. The icon looks like a page of paper with a corner
folded over. Name the new file FirstContract.sol. Use
the .sol extension to show that the file contains Solidity
code.
• The first line shows the license under which somebody may use and distribute the
software. The code in the above example uses the GPL version 3.0. You can replace this
with any other license like the MIT license.

• The second line shows a pragma directive that tells the compiler to use any Solidity
version from 0.8.1 to 0.9.0 but not including 0.9.0. That is, >= 0.8.1 to < 0.9.0.

• There are usually minor changes, or patches, within the x.y.Z versions. Breaking changes
are normally present in x.Y.z versions. This is why the pragma directive doesn't include
the 0.9.0 version in the above code.
• Solidity is an object-oriented language. The contract keyword on line four is
similar in use to the class keyword in other object-oriented languages.
• Contracts can contain functions, state variables, and other advanced types.
The contract FirstContract contains an unsigned integer (unit) called var1.
• The two functions named set() and get() are setter and getter functions,
respectively, for the variable var1. You can define a function with the
keyword function followed by the function name and parentheses.
• In the parentheses, you can declare the parameters which your function will
take. You should write them in a similar way to variable definitions: state the
data type followed by the parameter name.
• that the definitions of the set() and get() functions contain the
keyword public. This declares that any other contract can call them.

You might also like