TTTT
TTTT
TTTT
Cryptocurrency
Module 4
Topics
• Hash Functions
– Puzzle friendly hash
– Collision resistant hash
– Hash Pointers
– Digital signatures
– PublicKey Crypto
• Verifiable random functions
– Zero knowledge systems
• Bitcoin Blockchain Crypto
– Eliptic curve crypto
– SHA256
Hash Functions
• Hash functions are a type of algorithm that are used in cryptocurrency
• Used to encrypt data and ensure the integrity of a blockchain
• Hash functions take an input, like a key, and convert it into a fixed-
length output, or hash value.
• The output is usually a string of letters and numbers.
• Hash functions are essential to cryptocurrency because they make it
difficult to reverse the process and figure out the original data from the
hash.
• This is because even a small change to the input data will result in a
significantly different hash value.
Hash usage in Cryptocurrencies
• Hash functions are used in cryptocurrency to:
• Secure data: Ensure that data in a blockchain's
blocks is not altered
• Authenticate transactions: Pass transaction
information anonymously
• Bitcoin uses the SHA-256 hashing function,
which produces a 256-bit output from any
input.
Hash usage in Cryptocurrencies
• Data Integrity: Hash functions ensure the integrity of data. In cryptocurrencies, every transaction and
block of transactions is hashed. If any data is altered, the hash value changes, making it easy to detect
tampering or corruption. This is vital for maintaining the accuracy and trustworthiness of the
blockchain.
• Proof of Work: Many cryptocurrencies, such as Bitcoin, use hash functions as part of the Proof of
Work (PoW) mechanism. Miners must solve a computationally difficult problem that involves finding a
hash that meets certain criteria (e.g., a hash with a certain number of leading zeros). This process
requires substantial computational power, which secures the network against attacks and prevents
double-spending.
• Block Creation and Chain Security: Each block in a blockchain contains the hash of the previous block.
This creates a chain of blocks where each block is linked to its predecessor. If someone tries to alter
the data in a previous block, it would change the hash of that block and disrupt the entire chain,
making it apparent that tampering has occurred. This chaining makes the blockchain highly secure and
resistant to modifications.
• Address Generation: Hash functions are used to generate cryptocurrency addresses. For example, in
Bitcoin, a user's public key is hashed to produce a shorter, more manageable address. This process
enhances privacy and security by obscuring the actual public key.
• Efficient Verification: Hash functions allow for quick verification of data. For instance, when a new
block is added to the blockchain, nodes can quickly verify the block's hash to ensure it meets the
network's consensus rules without having to inspect all transaction details manually.
Hash usage in Cryptocurrencies
• Typical hash functions take inputs of variable
lengths to return outputs of a fixed length.
• A cryptographic hash function combines the
message-passing capabilities of hash functions
with security properties.
• Hash functions are algorithms that determine
how information is encrypted.
• Not all cryptocurrencies use SHA 256.
Puzzle Friendly Hash
• A hash function is considered puzzle-friendly if it's
difficult to find an input that produces a specific
output.
• This property is used in Bitcoin mining, where the
miner must find a specific number that, when
combined with block data, produces a hash that
falls within a certain range.
• The first miner to solve the puzzle is rewarded
with Bitcoin and the ability to add the transaction
to the blockchain.
Properties of Cryptographic hash functions
• Collision-free: No two different inputs should map to the same
output.
• Hidden: It's difficult to guess the input value for a hash function
from its output.
• Transaction Setup:
• Prover: The sender of the transaction creates a zk-SNARK proof. This proof
demonstrates that they possess the required private keys and that the transaction
adheres to the rules (e.g., no double-spending) without revealing the transaction
details.
• Verification: The proof is sent along with the encrypted transaction data to the
network. The zk-SNARK proof enables nodes to verify the correctness of the
transaction without seeing the details, such as sender, recipient, or amount.
• Proof Generation:
• The prover generates a zk-SNARK proof using the transaction information, including
encrypted amounts and addresses. This proof attests to the fact that the transaction is
valid under the blockchain’s rules without disclosing any details about the transaction.
• Proof Verification:
• Verifiers: Nodes in the Zcash network use the zk-SNARK proof to verify that the
transaction is valid. They can confirm that the proof corresponds to a legitimate
transaction without learning any specifics about the transaction.
Blockchain
• A blockchain is a computer file for storing data.
• It’s an open, distributed ledger (database), which means the data
contained within the blockchain is distributed (duplicated) across many
computers and is therefore decentralised.
• This decentralisation is one of the things that makes blockchain so
transformative.
• Unlike in a traditional, centralised database – where records are
processed by one central administrator (say, a company or government) –
the entire blockchain is transparent and data is verified by user consensus.
• Despite this transparency, blockchains are incredibly secure. That’s
because there’s no one central point of attack for hackers to target.
• Blockchain is the technology that underpins Bitcoin and it was developed
specifically for Bitcoin.
Bitcoin
• Bitcoin is a decentralised digital currency, or peer-to-
peer electronic payment system, where users can
anonymously transfer bitcoins without the interference
of a third-party authority (like a bank or government).
• Bitcoin is just one example of a cryptocurrency,
though; other cryptocurrency networks are also
powered by blockchain technology.
• So although Bitcoin uses blockchain technology to
trade digital currency, blockchain is more than just
Bitcoin.
Bitcoin Blockchain
• The Bitcoin blockchain collects transaction
information and enters it into a 4MB file called a
block (other blockchains use different size blocks).
• Once it is full, certain information is run through
an encryption algorithm, which creates a
hexadecimal number called the block header hash.
• Anyone can download a copy of the blockchain,
and it can be inspected to trace the path of
bitcoins from one bitcoin transaction to another.
Bitcoin blockchain
• Bitcoin is a cryptocurrency, while blockchain is a distributed
database.
• Bitcoin is powered by blockchain technology,
but blockchain has found many uses beyond Bitcoin.
• Bitcoin promotes anonymity, while blockchain is
about transparency.
• To be applied in certain sectors (particularly banking),
blockchain has to meet strict Know Your Customer rules.
• Bitcoin transfers currency between users, while blockchain
can be used to transfer all sorts of things, including
information or property ownership rights.
Eliptic Curve Cryptography
• ECC, as the name implies, is an asymmetric encryption algorithm that
employs the algebraic architecture of elliptic curves with finite fields.
• Elliptic Curve Cryptography (ECC) is an encryption technology comparable
to RSA that enables public-key encryption.
• While RSA’s security is dependent on huge prime numbers, ECC leverages
the mathematical theory of elliptic curves to achieve the same level of
security with considerably smaller keys.
• Victor Miller and Neal Koblitz separately proposed elliptic curve ciphers in
the mid-1980s. On a high level, they are analogs of actual public
cryptosystems in which modular arithmetic is substituted by elliptic curve
operations.
• The security of elliptic curve cryptosystems, like that of all public-key
cryptosystems, is based on tough mathematical issues at the core. Given
two elliptic curve points G and Y, where Y = kG.
Components of ECC
• ECC keys:
• Private key: ECC cryptography’s private key creation is as
simple as safely producing a random integer in a specific
range, making it highly quick. Any integer in the field
represents a valid ECC private key.
• Public keys: Public keys within ECC are EC points, which are
pairs of integer coordinates x, and y that lie on a curve.
• Because of its unique features, EC points can be compressed
to a single coordinate + 1 bit (odd or even). As a result, the
compressed public key corresponds to a 256-bit ECC.
Components of ECC
• Generator Point:
• ECC cryptosystems establish a special pre-defined EC point called
generator point G (base point) for elliptic curves over finite
fields, which can generate any other position in its subgroup
over the elliptic curve by multiplying G from some integer in the
range [0…r].
• The number r is referred to as the “ordering” of the cyclic
subgroup.
• Elliptic curve subgroups typically contain numerous generator
points, but cryptologists carefully select one of them to generate
the entire group (or subgroup), and is excellent for performance
optimizations in calculations. This is the “G” generator.
ECC Digital Signature Algorithms
• Digital signature algorithms:
• Elliptic Curve Digital Signature Algorithm. (ECDSA): ECDSA, or Elliptic Curve Digital
Signature Algorithm, is a more highly complicated public-key cryptography encryption
algorithm.
• Elliptic curve cryptography is a type of public key cryptography that uses the algebraic
structure of elliptic curves with finite fields as its foundation.
• Elliptic curve cryptography is primarily used to generate pseudo-random numbers,
digital signatures, and other data.
• Edwards-curve Digital Signature Algorithm (EdDSA): The Edwards-curve Digital
Signature Algorithm (EdDSA) was proposed as a replacement for the Elliptic Curve
Digital Signature Algorithm for performing fast public-key digital signatures (ECDSA).
• Its primary benefits for embedded devices are higher performance and simple, secure
implementations.
• During a signature, no branch or lookup operations based on the secret values are
performed.
• Many side-channel attacks are foiled by these properties.
ECC encryption algorithms
• Elliptic Curve Integrated Encryption Scheme (ECIES): ECIES is a public-key
authenticated encryption scheme that uses a KDF (key-derivation function) to
generate a separate Medium Access Control key and symmetric encryption
key from the ECDH shared secret.
• Because the ECIES algorithm incorporates a symmetric cipher, it can encrypt
any amount of data.
• In practice, ECIES is used by standards such as Intelligent Transportation
Systems.
• EC-based ElGamal Elliptic Curve Cryptography: ElGamal Elliptic Curve
Cryptography is the public key cryptography equivalent of ElGamal encryption
schemes that employ the Elliptic Curve Discrete Logarithm Problem.
• ElGamal is an asymmetric encryption algorithm that is used to send messages
securely over long distances.
• Unfortunately, if the encrypted message is short enough, the algorithm is
vulnerable to a Man in the Middle attack.
ECC key agreement algorithm
• Elliptic-curve Diffie–Hellman (ECDH): Elliptic-curve
Diffie-Hellman (ECDH) is a key agreement protocol
that enables two parties to establish a shared secret
over an insecure channel, each with an elliptic-
curve public-private key pair.
• This shared secret can be used directly as a key or
to generate another key.
• Following that, the key, or the derived key, can be
used to encrypt subsequent communications with a
symmetric-key cipher.
Application of ECC
• Elliptic Curve Digital Signature Algorithm (ECDSA): ECC is
one of the most widely utilized digital signature
implementation approaches in cryptocurrencies
• In order to sign transactions, both Bitcoin and Ethereum use
the field inverse multiplication, but also arithmetic
multiplication, inverse function, and modular operation.
• Blockchain application: The cryptocurrency Bitcoin
blockchain employs elliptic curve cryptography. Ethereum
2.0 makes heavy use of elliptic curve pairs with BLS
signatures, as stated in the IETF proposed BLS specification,
to cryptographically ensure that a specific Eth2 validator has
really verified a specific transaction.
ECC and RSA comparison
Parameters ECC RSA
Working ECC is a cryptography technique that works just on RSA cryptography algorithm is primarily based on
algorithm a mathematical model of elliptic curves. the prime factorization approach.
Encryption The encryption process takes less time in ECC. The encryption process takes more time in RSA.
process
Decryption The decryption process takes more time. Decryption is faster than ECC.
process
ECC is much safer than RSA and is currently in the
Security process of adapting.
RSA is heading toward the end of its tenure.
SHA256
• SHA-256, or Secure Hash Algorithm 256-bit, is a
cryptographic hash function used in blockchain
technology for a variety of purposes
• Secure Hash Algorithm 256-bit, also known as SHA-256,
is a cryptographic hash function that converts text of
any length to an almost-unique alphanumeric string of
256 bits. The output is known as a hash value or hash.
• Creating digital signatures, Cryptocurrency mining,
Verifying data integrity, and Creating private and public
key pairs.
Application of SHA 256 in blockchain
• Cryptographic hashes
• Cryptographic hashes are unique and irreversible, and are deterministic, meaning
that identical data will always create the same hash.
• Collision minimization
• SHA-256 minimizes collisions, which is when different data produces the same
hash.
• Bitcoin encryption
• SHA-256 was first used in Bitcoin's encryption when the network launched in
2009.
• Other blockchain projects
• SHA-256 is used in many other blockchain projects, including Bitcoin Cash and
Bitcoin Satoshi's Vision.
• Digital currency security
• As of August 2024, the SHA-256 mining algorithm protects over $1.2 trillion in
digital currencies.
SHA256 Key properties
• Uniqueness
• When the SHA-256 hash function is used, distinct inputs will always produce unique
hash values. Even a small variation in the input will result in a vastly different hash
value.
• This is known as the ‘avalanche effect’. Furthermore, the hash value will always be
256 bits long, no matter the size of the input.
• InputHash value
• m
62c66a7a5dd70c3146618063c344e531e6d4b59e379808443ce962b3abd63c5a
• me 2744ccd10c7533bd736ad890f9dd5cab2adb27b07d500b9493f29cdc420cb2e0
• meandyou
cf7af6b1be152c4f427a3b5beb444e85eeadfb9e062ed420fb9b9a10ccfbadf7
SHA256 Key properties
• irreversibility
• Hash values created using SHA-256 are computationally infeasible to reverse
engineer, meaning you cannot obtain the original input data from the hash
value.
• This ensures that the data remains protected even if the hash value is publicly
available, which makes sharing files publicly easy without worrying about a
bad actor decrypting them.
• Deterministic
• SHA-256 will always produce the same hash value for a particular input.
• This property ensures consistency in the hashing process allowing verification
of data across remote systems.
• Check the deterministic property of the SHA-256 hash function by verifying the
input and output of “m”, “me” and “meandyou” mentioned above on various
online hash generators like OnlineWebToolKit and Movable Type Scripts.
Usecase in Bitcoin Blockchain
• SHA-256 forms a critical component of major
blockchain protocols like Bitcoin and Bitcoin
SV. SHA-256 enables the proof-of-work (PoW)
consensus algorithm on the Bitcoin
blockchain.
• The cryptographic hash function is used to
verify transactions on the blockchain protocol.