For the complete documentation index, see llms.txt. This page is also available as Markdown.

Applied Cryptography

Hashing, digital signatures and elliptic curves


"Without cryptography, Bitcoin would literally be impossible." — Hal Finney (Bitcointalk, 2009)


1. Introduction

Bitcoin is, in essence, an economic system backed by mathematics. It does not rely on institutions, authorities or interpersonal trust: it relies on cryptographic functions that guarantee:

  • irreversibility

  • non-counterfeiting

  • public verifiability

  • digital ownership

  • attack resistance

This chapter covers the three fundamental cryptographic pillars:

  1. Hash functions (SHA-256, RIPEMD-160)

  2. Digital signatures (ECDSA)

  3. Elliptic curves (secp256k1)

Each one plays a specific role within Bitcoin's design.


2. Cryptographic hashing in Bitcoin

2.1. What is a hash?

A cryptographic hash function is a transformation:

H:0,1∗→0,1nH: {0,1}^* \rightarrow {0,1}^n

with the following properties:

  • Preimage resistance

  • Second-preimage resistance

  • Collision resistance

  • Determinism

  • Efficiency

Bitcoin primarily uses:

  • SHA-256

  • RIPEMD-160

And occasionally combinations like SHA-256(SHA-256(x)) (double SHA-256).


2.2. Key properties applied to Bitcoin's design

1. Collision resistance

Makes it impossible to find two different messages that produce the same hash.

This is essential for:

  • ensuring block integrity

  • preventing malicious reorganizations

  • guaranteeing transaction uniqueness

2. One-wayness

It is not possible to recover the original information from a hash.

It facilitates:

  • addressing without revealing public keys

  • resistance to future-spend attacks

  • protection against preimage collisions


2.3. Hashing in the system's different components

Component
Hash algorithm
Purpose

Block header

SHA-256d

To prove PoW

Merkle tree

SHA-256d

To aggregate transactions

Bitcoin address

SHA-256 + RIPEMD-160

To create short identifiers


3. Merkle trees: compression and verifiability

The transactions within each block are organized into a Merkle tree.

3.1. Formal definition

A Merkle tree is a binary structure where:

Hl1=SHA256d(tx1)H_{l1} = SHA256d(tx1) Hl2=SHA256d(tx2)H_{l2} = SHA256d(tx2) H0=SHA256d(Hl1∣Hl1)H_0 = SHA256d(H_{l1} | H_{l1}) Hl3=SHA256d(tx3)H_{l3} = SHA256d(tx3) Hl4=SHA256d(tx4)H_{l4} = SHA256d(tx4) H1=SHA256d(Hl3∣Hl4)H_1 = SHA256d(H_{l3} | H_{l4}) Root=SHA256d(H0∣H1)Root = SHA256d(H_{0} | H_{1})

3.2. Advantages

  • They provide efficient proofs of inclusion (Merkle proofs)

  • They enable lightweight nodes (SPV)

  • They reduce the need for storage

These proofs are fundamental for mobile devices and light clients.


4. Digital signatures (ECDSA)

4.1. What are they for?

Bitcoin uses digital signatures to verify:

  • that the owner of a private key authorized a transaction

  • that the transaction was not modified

  • that the signature is publicly valid

4.2. Mathematical basis

If:

  • dd = private key

  • Q=dGQ = dG = public key (point on curve)

then the signature (r, s) satisfies:

r=(kG)xmod  nr = (kG)_x \mod n

s=k−1(H(m)+dr)mod  ns = k^{-1}(H(m) + dr) \mod n

where:

  • kk = random number per signature

  • GG = generator point

  • nn = order of the elliptic group


4.3. Security

ECDSA is secure as long as:

k sea uˊnico y aleatoriok \text{ sea único y aleatorio}

If reused, the private key can be derived:

d=s1k−H(m1)rmod  nd = \frac{s_1k - H(m_1)}{r} \mod n

This has caused hacks in defective implementations in the past.


5. Elliptic curves: the algebraic foundation

Bitcoin uses the elliptic curve secp256k1.

5.1. Mathematical definition

It is the curve:

y2=x3+7y^2 = x^3 + 7

over the finite field:

Fp,p=2256−232−977\mathbb{F}_p, \quad p = 2^{256} - 2^{32} - 977

5.2. Properties

  • non-random curve (unlike NIST curves)

  • efficient operations

  • proven security

  • resistant to state manipulation (according to many cryptographers)

5.3. Point multiplication

The fundamental operation is:

Q=dG Q = dG

where:

  • dd = 256-bit number

  • GG = generator point

  • QQ = public key

It is easy to compute QQ, but practically impossible to compute dd.

This is based on the difficulty of the Elliptic Curve Discrete Logarithm Problem (ECDLP).


6. Bitcoin addresses: from the hash to the Base58Check representation

6.1. Full generation process

Clave puˊblica=Q\text{Clave pública} = Q

hash160(Q)=RIPEMD160(SHA256(Q))\text{hash160}(Q) = \text{RIPEMD160}(\text{SHA256}(Q))

Add version: 00+hash16000 + hash160

Calculate checksum: SHA256d(00+hash160)\text{SHA256d}(00 + hash160)

Encode in Base58Check.


6.2. Simplified example in pseudocode

7. Cryptographic security against modern attacks

7.1. Quantum attacks

Bitcoin partially resists quantum attacks:

Function
Quantum risk
Impact

SHA-256

Low

Grover reduces security by 50%

ECDSA

Medium

Shor could derive public keys

Current mitigation:

  • public keys not exposed until spent

  • future possibility of changing algorithm

7.2. Collision attacks

SHA-256 has no known collisions.

A collision implies:

H(x)=H(y)H(x)=H(y)

with x≠yx \neq y

The probability is astronomically low (≈2−256\approx 2^{-256} ).

7.3. Implementation attacks

The most common attacks:

  • poor randomness generation

  • defective wallets

  • side-channel attacks

  • compromised hardware

Bitcoin as a protocol is secure; implementations may not be.

8. Cryptography applied on the blockchain

Bitcoin uses cryptography to secure:

Component
Mechanism

Block integrity

SHA-256d hash

Transaction integrity

Merkle Root

Digital ownership

ECDSA

Double-spend prevention

PoW

Pseudonymous identities

Hash160

Initial block zeros

PoW target

9. Chapter conclusion

Cryptography in Bitcoin is not decorative. It is the source of:

  • security

  • decentralization

  • mathematical trust

  • irreversibility

  • censorship resistance

  • digital ownership

Bitcoin does not work because "everyone agrees" on its validity. It works because mathematics do not take bribes.


Bitcoin does not use cryptography to "hide" data. It uses cryptography to guarantee economic rules without intermediaries.


Last updated

Was this helpful?