Skip to content

Historical page retained for compatibility. It may contain superseded assumptions, incomplete plans, or outdated links and is not current canonical content. See the Archive for context.

Cryptographic and Mathematical Primitives

  • original material: 2023-02-04 to 2023-02-05
  • consolidated: 2026-08-09
  • archive status: historical reference

Overview

Here we review cryptographic and mathematic primitives

For each primitive we review

  • Cryptographic Primitive
  • Applications
  • Implementations (codebases)
  • Zero Knowledge relationships/improvements

This consolidated archive page brings the previously separate primitive pages into one document while preserving their original material and references.

Reference implementations and primitive families

Overview

Cryptographic and Mathematic Primitives

Reference Implementations

general primitives Hash functions

SHA-2

difference between sha256 and kecakk256

encryption Random number generators Serialization/DeSerialization Threading
  • prysm: contains generic containers that are protected either by Mutexes or atomics underneath the hood.
zero knowledge
  • hash functions
    • Poseidon: A New Hash Function for Zero-Knowledge Proof Systems (video)

References

  • Bloom Filter Wikipedia: A Bloom filter is a space-efficient probabilistic data structure, conceived by Burton Howard Bloom in 1970, that is used to test whether an element is a member of a set.
  • Bloom Filters Explainer: The bloom filter essentially consists of a bit vector of length m, represented by the central column.
  • Bloomfilter Lesson 11 - Blockchain Academy: Blockchain Introduction Technical – Beginner to Intermediate Lesson 11 – Bloomfilter.
  • Cuckoo Hashing: a simple dictionary with worst case constant lookup time, equaling the theoretical performance of the classic dynamic perfect hashing scheme of Dietzfelbinger et al.
  • Cukoo Hashing Visualization: Visualization of Cukoo Hashing an elegant method for resolving collisions in hash tables.
  • Fast Fourier Transforms: Vitaliks explaniner on Fast Fourier Transforms. Trigger warning: specialized mathematical topic, with special thanks to Karl Floersch for feedback.
  • Merkle Trees/Merkle Proofs Lesson 10 - Blockchain Academy: Blockchain Introduction Technical – Beginner to Intermediate Lesson 10 – Merkle Trees/Merkle Proofs.

Signature schemes in consensus protocols

Overview

Both sides of the bridge need to verify what happened on the other side. To do that, the verification logic is often encapsulated inside a light client, manifested as a smart contract on the chain which the verification needs to be executed. The light client needs to follow consensus and signature verification mechanisms based on the signing algorithm and the elliptical curve used on the other side. For example, if chain A has 21 validators signing each block using ECDSA algorithm on secp256k1 curves, then chain A's light client, executed on chain B, must extract the signatures from the block headers presented to the light client, and follow the ECDSA signature verification algorithm to verify the content of the block header indeeds produces the 21 signatures contained in the block header, given the public keys of the 21 validators.

Here, we present a reference table for these signature schemes and how they are used in the consensus protocols of different blockchains. We limit our initial scope to Ethereum, Polygon, Avalanche, BSC, Harmony, Cosmos, and Polkadot only (and their undelying technologies). Note that we are only looking at how signatures are used in consensus, not elsewhere in the blockchain stack, as all these protocols use ECDSA on secp256k1 for accounts in EVM interactions.

AlgorithmCurveProtocolCodeNote
ECDSAsecp256k1PolygonlibModified Tendermint validator signature scheme
BSClib usageDerived from Clique, then improved
BLSBN254EthereumEVMAdded by EIP-196,197; Mainly for use in smart contracts, such as zk-snark verification. See explainer
BLS12-381Ethereumprysm lighthouseSee PoS design and explainer
Harmonylib usageSee design and protocol review
RSAN/AAvalancheverification generationUses X.509 certificate which potentially allows many algorithms; Moving towards BLS12-381 and added implementations recently
EdDSACurve25519IBClib usageUsed by all chains in Cosmos network, including Cosmos Hub
SchnorrCurve25519SubstratelibSee also brief intro from Polkadot

Resources

Algorithms

ECDSA
BLS
EdDSA

Curves

secp256k1
BLS12-381
BN254

Usage in ZKP

Signing Implementations

The Standard Curve Database is a good starting point for existing signing algorithms. Base implementations such as golang crypto and rust crypto provide good reference codebases.


Light clients

Overview

References


Fraud proofs

Overview

Following is an excerpt from Fraud and Data Availability Proofs

Invalid Blocks in Light Clients 1.

Light clients, also known as Simple Payment Verification (SPV) clients, are nodes which only download a small portion of the data in a blockchain, and use indirect means to verify that a given chain is valid. Instead of validating blocks, they assume that the chain favoured by the blockchain’s consensus algorithm only contains valid blocks, and that the majority of block producers are honest. By allowing such clients to receive fraud proofs generated by fully validating nodes that show that a block violates the protocol rules, and combining this with probabilistic sampling techniques to verify that all of the data in a block actually is available to be downloaded so that fraud can be detected, we can eliminate the honest-majority assumption for block validity, and instead make much weaker assumptions about a minimum number of honest nodes that rebroadcast data. Fraud and data availability proofs are key to enabling on-chain scaling of blockchains while maintaining a strong assurance that on-chain data is available and valid. We present, implement, and evaluate a fraud and data availability proof system.

Here is an overview of how NEAR bridge uses this in an optimistic approach

The leading NEAR Ethereum Bridge today Near Rainbow Bridge uses an optimistic approach. Following is an excerpt from NearOnEthClient 2.

we adopt the optimistic 3 approach where NearOnEthClient verifies everything in the NEAR header except the signatures. Then anyone can challenge a signature in a submitted header within a 4-hour challenge window. The challenge requires verification of a single Ed25519 signature which would cost about 500k Ethereum gas (expensive, but possible).

Footnotes


Fast Fourier transforms

Overview

References


Weak subjectivity

Overview

Following is an excerpt from Analysis on Weak Subjectivity in Ethereum 2.0 1 .

Weak subjectivity 4 is a social-consensus-driven approach for solving the fun- damental “nothing-at-stake” problem of proof-of-stake protocols. In particular, it addresses the problem in the presence of long-range forks, while the slash- ing mechanism handles the case of short-range forks. Specifically, the current weak subjectivity mechanism deals with the following two types of long-range attacks 5

Exploiting retired validators: Adversaries can create and reveal a new chain branching from a certain block on the canonical chain, after 2/3 of validators who were active for the block have exited. Note that such validators can still justify and finalize conflicting blocks at earlier slots without being slashed after they have exited.

Exploiting diverging validator sets: Adversaries can build a new chain until the validator set for the new chain is sufficiently different from that of the canonical chain. The larger the difference between the two validator sets, the lower the accountable safety tolerance. For example, if the intersection of the two sets is smaller than 2/3 of each set, then it is possible to have conflicting blocks to be finalized without any validators violating the slashing conditions.

It is unknown whether this mechanism can deal with other types of long-range attacks, if any, in general.

The current weak subjectivity mechanism employs a social consensus layer in parallel to maintain sufficiently many checkpoints (called weak subjectivity check- points) so that there exist no conflicting finalized blocks that are descendants of the latest weak subjectivity checkpoint. In other words, the purpose of the latest weak subjectivity checkpoints is to deterministically identify the unique canonical chain even in the presence of conflicting finalized blocks caused by the long-range attacks.

References

Articles and guides

Documentation

  • Ethereum Docs: WEAK SUBJECTIVITY: This refers to a chain that can progress objectively after some initial seed of information is retrieved socially.

  • Teku Docs: Weak Subjectivity: The weak subjectivity period refers to how far behind the chain head a node can be before 1/3 of validators may have exited since the node was last in sync.

Implementations

Footnotes

Footnotes

  1. Fraud and Data Availability Proofs

    Invalid Blocks in Light Clients: Fraud and data availability proofs are key to enabling on-chain scaling of blockchains while maintaining a strong assurance that on-chain data is available and valid. 2

  2. NEAR: ETH-NEAR Rainbow Bridge: a bridge, called Rainbow Bridge, to connect the Ethereum and NEAR blockchains.

  3. Optimistic Contracts: contracts that accept all information as fact until proven to be non-factual. This allows for a reduction in the cost of verifying data, as on-chain verification would only be necessary when one is sure that the data is false.

  4. Proof of Stake: How I Learned to Love Weak Subjectivity:

  5. It is unknown whether this mechanism can deal with other types of long-range attacks, if any, in general