Thanks to visit codestin.com
Credit goes to www.scribd.com

0% found this document useful (0 votes)
39 views43 pages

Slide 7 Blockchain Security 2

The document discusses blockchain security techniques including public-key cryptography, hashing, hashchains, transaction integrity, and securing blockchains. It explains how hashing is used to provide reliability and integrity in blockchains by ensuring no double spending or fraudulent transactions. Elliptic curve cryptography combined with hashing is used to make blockchains immutable and verifiable.

Uploaded by

aniket23012001
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)
39 views43 pages

Slide 7 Blockchain Security 2

The document discusses blockchain security techniques including public-key cryptography, hashing, hashchains, transaction integrity, and securing blockchains. It explains how hashing is used to provide reliability and integrity in blockchains by ensuring no double spending or fraudulent transactions. Elliptic curve cryptography combined with hashing is used to make blockchains immutable and verifiable.

Uploaded by

aniket23012001
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/ 43

Blockchain

Security
Blockchain Security
• Algorithms and Techniques:
• Public-Key Cryptography,
• Hashing,
• Hashchain to Blockchain,
• Transaction Integrity,
• Securing Blockchain,
• Basic consensus mechanisms

11-02-2024 2
Blockchain Security and Hashing
• Blockchain’s reliability and integrity mechanism is very strong.

• It ensures that there is no double spending and no fraudulent


transactions are accepted.

• Hashing is used as an important backbone support to provide a


reliable and secure solution.

11-02-2024 3
Hashing
• What is Hashing ?

• Hashing is the process of transforming an input of any length


into a cryptographic fixed output.
• It uses a mathematical algorithm.
• Example input can be a message, a log file, or a block in the
chain.

11-02-2024 4
Cryptographic Hash Function
• Basic requirements

• Impossible to produce the same hash value for different inputs.

• The same input should always give the same hash value.

• Easy to compute a hash value for any given input.

11-02-2024 5
Cryptographic Hash Function
• Basic requirements

• Impossible to determine input from a hash value.

• Even a 1 bit change in the input value should give a completely


different hash value.

11-02-2024 6
Cryptographic Hash Functions
• Message Digest Functions
• Protect integrity
• Create a message digest or fingerprint of a digital document
• MD4, MD5, SHA
• Message Authentication Codes (MACs)
• Protect both integrity and authenticity
• Produce fingerprints based on both a given document and a secret
key

7
CS 450/650 Lecture 7: Hash Functions Source: Lecture slides of Dr MH Gunes, University of Nevada, Reno
Message Digest Functions
• Checksums → fingerprint of a message
• If message changes, checksum will not match

• Most checksums are good in detecting accidental changes


made to a message
• They are not designed to prevent intentional change in a
message with the same checksum
• But message digests are designed to protect against this possibility

8
CS 450/650 Lecture 7: Hash Functions Source: Lecture slides of Dr MH Gunes, University of Nevada, Reno
One-Way Hash Functions
M H H(M) = h
Example
• M = “Elvis”
• H(M) = (“E” + “L” + “V” + “I” + “S”) mod 26
• H(M) = (5 + 12 + 22 + 9 + 19) mod 26
• H(M) = 67 mod 26
• H(M) = 15

9
CS 450/650 Lecture 7: Hash Functions Source: Lecture slides of Hesham El-Rewini University of North Dakota
Collision
x H H(x)
=

Example
y H H(y)
• x = “Viva”
• Y = “Vegas”
• H(x) = H(y) = 2

10
CS 450/650 Lecture 7: Hash Functions Source: Lecture slides of Dr MH Gunes, University of Nevada, Reno
Collision-Resistant, One-Way Hash Function
• Given M,
• it is easy to compute h
• Given any h,
• it is hard to find any M such that H(M) = h
• Given M1, it is difficult to find M2
• such that H(M1) = H(M2)
• Functions that satisfy these criteria are called message digest.
• They produce a fixed-length digest (fingerprint)
• A message authentication code (MAC) is a key-dependent
message digest function
• MAC(M,k) = h
11
CS 450/650 Lecture 7: Hash Functions Source: Lecture slides of Dr MH Gunes, University of Nevada, Reno
A MAC Based on a Block Cipher

M1 M1 M1

XOR XOR

Encrypt Encrypt … Encrypt MAC

k k k

12
CS 450/650 Lecture 7: Hash Functions Source: Lecture slides of Dr MH Gunes, University of Nevada, Reno
Secure Hash Algorithm (SHA)

• SHA-0 1993
• SHA-1 1995
• SHA-2 2002
• SHA-224, SHA-256, SHA-384, SHA-512

A message 256-bit
composed of SHA-2 message
b bits digest

CS 450/650 Lecture 8: Secure Hash 13


Algorithm Source: Lecture slides of Dr MH Gunes, University of Nevada, Reno
SHA-256
• SHA-256 projects into B²⁵⁶, so the collisions seems to be
unlikely

• No collisions have been reported for SHA-256 till date.

11-02-2024 14
Elliptic Curve Cryptography
• Present blockchains use Elliptic Curve Cryptography (ECC) to secure
its blocks of transactions.

• ECC is also a public key cryptography (PKC) just as RSA or any other
PKC method.

• But a 256 bit key in ECC provides the same security level as a 3072
bit key using RSA. ( lightweight and secure)

• Hashing combined with ECC is used to make the Ethereum


blockchain immutable and verifiable.
11-02-2024 15
Elliptic Curve
Cryptography
• Line joining two points on
the curve will intersect at a
third point ( Think of points
not having the same x-
coordinate).
• Utilize the symmetry of the
curve to find out points on
the opposite side.
11-02-2024 16
Elliptic Curve Cryptography

Public Key: Starting Point


A, Ending Point E

Private Key: Number of


hops from A to E

11-02-2024 17
Hashchain
• A repeated application of a cryptographic hash function to a
given data input.

• This type of hash cryptography is useful in specific security


setups like in a blockchain, when the transactions keep adding
up in the form of blocks.

• By providing a successive chain, hash chains make it harder for


an unauthorized user to hijack a data asset by applying a single
input.
11-02-2024 18
Transaction Integrity
• A secure and unique account address

• Transaction authorization by the sender through digital


signature.

• Verification that the content of the transaction is not modified.

11-02-2024 19
Transaction Integrity…
• Account Address Generation
• First a 256-bit random number is generated. This is the private
key. Kept secure and locked using a passphrase.
• Then an ECC algorithm is applied to the private key, to obtain a
unique public key.
• This makes the private - public key pair.
• Finally, a cryptographic hash function is applied to the public
key to obtain account address.
• The address is only 20 bytes or 160 bits if SHA-1 is applied.

11-02-2024 20
Transaction Integrity…
• For a transaction for transferring assets to be authorized, it has
to be non-repudiable, and unmodifiable.
• First the digital signature is verified and then it is applied to the
transaction.
• The receiver gets the original data, and the secure hash digitally
signed.
• Receiver recomputes the hash of the original data received, and
compares it with the received hash to verify the integrity of the
document.

11-02-2024 21
Transaction Integrity…
• Step 1: Find the hash of the data fields of the transaction.
• Step 2: Encrypt that hash using the private key of the sender of the
transaction.
• Step 3: Add this hash to the transaction.
• Step 4: Verified by the recipient ( others as well) using the public
key of the sender of the transaction by recomputing the hash of the
transaction.
• Then, compare the computed hash, and the hash received as the
digital signature.
• For the complete transaction verification, the timestamp, nonce,
account balances, and sufficiency of fees are also verified.

11-02-2024 22
Securing Blockchain
• Integrity of a block in blockchain is assured through

• Checking that there is no tempering with the block header contents.


• Verifying that there is no tempering with transactions
• efficient computation and hashing of state transition and their
verification.

• In Ethereum, the block hash is the hash of all the elements in the
block header, including the transaction root and state root hashes.
• It is computed by applying a variant of SHA-3 algorithm called
Keccak and all the items of the block header.
11-02-2024 23
Securing Blockchain
• For efficiently detecting tampering or validating the transaction
integrity, Merkle tree structure is used.

• Hashes of transaction in a block are processed in Merkle tree


hash.

• Merkle tree hash is also used for computing the state root
hash, since only the hash of the chained states from block to
block have to be re-computed.

• It is also used for receipt hash root.


11-02-2024 24
Securing Blockchain
• Smart contracts execution results in a state change in the
blockchain.

• Every state change requires state root hash re-computation.

• Merkle tree structure efficiently computes this.

11-02-2024 25
State Change
State change

State change

State change

State change

11-02-2024 26
Block Hash and Security
• Block hash serves two important purposes:
• verification of the integrity of the block and the transactions,
• formation of the chain link by embedding the previous block hash in
the current block header.
• If any node tampers with a block, its hash value changes.
• This results in the mismatch of the hash values and hence the
local chain of the node goes in an invalid state.
• Any future blocks initiated by the node would be rejected by
other miners due to hash mismatch.
• This enforces the immutability of the chain.
11-02-2024 27
Blockchain Security Mechanism

• A combination of hashing and encryption is used for securing


elements of the block chain.

• Private-public key pair and hashing are important concepts in a


trustless decentralized network.

• Third important concept is consensus ( Next class)

11-02-2024 28
References
• Coursera Course on Blockchain Basics by University at Buffalo &
The State University of New York.
• https://medium.com
• https://www.ccn.com
• Lecture slides from the webpage of the book: Cryptography and
Network Security by William Stallings:
http://williamstallings.com/Cryptography/

11-02-2024 29
11-02-2024 30
Step 1: Padding
• Let M be the message to be hashed, and L be its length in bits
where L < 2⁶⁴
• The padded message M = message M plus a right padding,
such that M’ is of length l’, a multiple of 512.
• Every message is padded even if its length is already a multiple
of 512

11-02-2024 Source: https://medium.com 31


Step 1: Padding

Message 1 0…0 Message length

1 bit 64 bits

Multiple of 512

CS 450/650 Lecture 8: Secure Hash 32


Algorithm Source: Lecture slides of Dr MH Gunes, University of Nevada, Reno
Step 2: Block Construction
• The padded M’ is divided into N blocks.
• Each block is of size 512 bits, M¹, M2 , …, Mᴺ
• Each block is expressed as a combination on 16 input blocks of
size 32 bits, M₀ to M₁₅.

11-02-2024 33
Hash Initialization
• The initial hash value H⁰ of length 256 bits (8 input blocks of 32 bits)
is set by taking the first 32 bits of the fractional parts of the square
roots of the first eight prime numbers.
• 𝐻10 = 6𝑎09𝑒667
• 𝐻20 = 𝑏𝑏67𝑎𝑒85
• 𝐻30 = 3𝑐6𝑒𝑓372
• 𝐻40 = 𝑎54𝑓𝑓53𝑎
• 𝐻50 = 510𝑒527𝑓
• 𝐻50 = 9𝑏05688𝑐
• 𝐻60 = 1𝑓83𝑑9𝑎𝑏
• 𝐻70 = 5𝑏𝑒0𝑐𝑑19
11-02-2024 34
Step 3 – Compute Words
• Wj (0<=j<=15) = Mj

• To Compute word Wj (16<=j<=79)

• Wj-3, Wj-8, Wj-14 , Wj-16 are XORed

• The result is circularly left shifted one bit

CS 450/650 Lecture 8: Secure Hash 35


Algorithm Source: Lecture slides of Dr MH Gunes, University of Nevada, Reno
Step 4 – Initialize A,B,C,D,E
• A = H0
• B = H1
• C = H2
• D = H3
• E = H4

CS 450/650 Lecture 8: Secure Hash 36


Algorithm Source: Lecture slides of Dr MH Gunes, University of Nevada, Reno
Initialize 32-bit words
• H0 = 67452301
• H1 = EFCDAB89
• H2 = 98BADCFE
• H3 = 10325476
• H4 = C3D2E1F0

• K0 – K19 = 5A827999
• K20 – K39 = 6ED9EBA1
• K40 – K49 = 8F1BBCDC
• K60 – K79 = CA62C1D6
CS 450/650 Lecture 8: Secure Hash 37
Algorithm Source: Lecture slides of Dr MH Gunes, University of Nevada, Reno
Step 5 – Loop
For j = 0 … 79
TEMP = CircLeShift_5 (A) + fj(B,C,D) + E + Wj + Kj
E = D; D = C;
C = CircLeShift_30(B);
B = A; A = TEMP
Done

+ → addition (ignore overflow)

CS 450/650 Lecture 8: Secure Hash 38


Algorithm
Four functions
• For j = 0 … 19
• fj(B,C,D) = (B AND C) OR ( B AND D) OR (C AND D)

• For j = 20 … 39
• fj(B,C,D) = (B XOR C XOR D)

• For j = 40 … 59
• fj(B,C,D) = (B AND C) OR ((NOT B) AND D)

• For j = 60 … 79
• fj(B,C,D) = (B XOR C XOR D)

CS 450/650 Lecture 8: Secure Hash 39


Algorithm
Step 6 – Final
• H0 = H0 + A
• H1 = H1 + B
• H2 = H2 + C
• H3 = H3 + D
• H4 = H4 + E

CS 450/650 Lecture 8: Secure Hash 40


Algorithm
Done
• Once these steps have been performed on each 512-bit block
(B1, B2, …, Bn) of the padded message,
• the 160-bit message digest is given by

H0 H1 H2 H3 H4

CS 450/650 Lecture 8: Secure Hash 41


Algorithm
SHA
Output Internal Block Max Word
Collisions
size state size size message size Rounds Operations
found
(bits) (bits) (bits) size (bits) (bits)

+, and, or,
SHA-0 160 160 512 264 − 1 32 80 Yes
xor, rot

+, and, or, None


SHA-1 160 160 512 264 − 1 32 80
xor, rot (252 attack)

+, and, or,
256/224 256 512 264 − 1 32 64 None
xor, shr, rot
SHA-2
+, and, or,
512/384 512 1024 2128 − 1 64 80 None
xor, shr, rot

CS 450/650 Lecture 8: Secure Hash 42


Algorithm
References
• Coursera Course on Blockchain Basics by University at Buffalo &
The State University of New York.
• https://medium.com
• https://www.ccn.com
• Lecture slides from the webpage of the book: Cryptography and
Network Security by William Stallings:
http://williamstallings.com/Cryptography/

11-02-2024 43

You might also like