What exactly are secp256k1, ECDSA and Keccak256 ?

A short overview of the cryptographic concepts used in go-ethereum based chains

Flavius Burca
#blockchain
#cryptography

These concepts are used all over Ethereum-based chains and are fairly common among Solidity and dApp developers as well. But what exactly are they and how do they word behind the scenes ?

secp256k1

In mathematics, the secp256k1 is a type of curve, more exactly a Koblitz curve, defined by the following mathematical equation:

#[ Y^2 = X^3+7 ]#

Koblitz curves are a special class of elliptic curves that enable efficient computation. This property makes it attractive for use in cryptocurrencies, where computational efficiency is essential for practical implementation on a large scale. Also, the 256-bit key size used in secp256k1 results in relatively small public keys and signatures, which is beneficial for storage and transmission efficiency, especially in the blockchain space.

You will see all over the Internet a graphic representation of the secp256k1 curve like this:

A graph of the secp256k1's elliptic curve over real numbers


While this is made just to give you an image, it has nothing to do with the actual secp256k1 curve and is meant just to give you an image. The drawing is not correct because the secp256k1 curve is not designed to work with in the real number field #[ \mathbb{R} ]#. The curve is designed to work over a Galois finite prime field #[ Z_{2^{256}-2^{32}-977} ]#. which means the X and Y coordinates are 256-bit integers modulo a large number. Curves using such coordinates do not have any concept of continuous lines.

I've tried to plot this curve over a similar but much smaller field, Z28+1 where coordinates extend from -128 to 128 and it looks like this:

y² = x³ + 7 over Z257, -128 through 128
A graph of the secp256k1's elliptic curve over the field Z28+1

Even though it may not make sense geometrically anymore, it still has all properties you need. A line (which means, a group of points with equation #[ ay + bx + c = 0 ]#) that intersects 2 points of the curve, will intersect a third. Tangent again has no geometric interpretation anymore, but you can still symbolically compute a derivative of the equation in a given point, which will have the property of intersecting the curve in a second point.

You can find an online tool here https://cdn.rawgit.com/andreacorbellini/ecc/920b29a/interactive/modk-add.html which will help you to plot the graph and do addition or scalar multiplication on an Elliptic Curve.

enter image description here
To conclude, secp256k1 is a Koblitz Elliptic Curve over a Galois finite prime number field.

ECDSA (Elliptic Curve Digital Signature Algorithm)

ECDSA is an algorithm used to sign transactions with secp256k1 as the underlying curve. A private key is randomly generated as a 256-bit integer to create a new key pair. The corresponding public key is then derived by multiplying the private key by the secp256k1 base point G (a predefined point on the curve). The result is another point on the curve, which serves as the public key.

When a user wants to send a cryptocurrency transaction, they must sign it with their private key. The signing process uses the ECDSA algorithm with secp256k1 as the underlying curve. The resulting digital signature proves that the private key holder authorized the transaction without revealing the private key itself.

To ensure the validity of a transaction, other network participants must verify the digital signature. This process involves using the public key associated with the signer's address and the ECDSA algorithm with secp256k1 as the underlying curve. If the signature is valid, it confirms that the transaction was indeed authorized by the owner of the private key, ensuring the integrity and authenticity of the transaction.

The public key is also used to generate Ethereum addresses by doing a Keccak-256 hash on the public key and discarding the first 12 bytes. The remaining 20 bytes are the address.

Keccak-256

Keccak-256 is a cryptographic hash function that can convert information into an unreadable hash. It's part of the SHA-3 family and is widely used in the Ethereum ecosystem. Kekkak-256 is stronger than SHA256 and  it yields a singular 32-byte hash from any number of inputs. This cryptographic hash function can only be used in one direction and cannot be reversed.

Here is a nice online tool to generate Kekkak-256 hashes: https://emn178.github.io/online-tools/keccak_256.html