Ethash-R5

Overview

Ethash-R5 is a modified variant of the Ethash proof-of-work (PoW) algorithm, designed for the R5 blockchain. It builds on Ethereum’s original Ethash but introduces unique enhancements, including a 7-second block time target, a capped token supply, and an adjusted reward structure.

This document provides a technical breakdown of the algorithm, including its dataset mechanics, hashing process, and difficulty adjustments.


Algorithmic Changes in Ethash-R5

The Ethash-R5 algorithm maintains Ethash’s fundamental structure while implementing specific modifications:

  • 7-second block time target enforced by an adjusted difficulty formula.

  • Super Epoch reward model with periodic reductions in miner rewards.

  • Modified uncle block policy: Uncles are valid but not rewarded.

  • Capped supply: No new issuance beyond block 1,290,406,400.

  • Extra sequential mixing rounds for additional security.

  • No support for Ethereum’s Shanghai and Cancun forks.


Key Components

1. Dataset & Cache Growth

Ethash-R5 retains Ethash’s dataset mechanics, where miners generate a dataset (DAG) that assists in the hashing process. However, the growth parameters have been modified:

Parameter

Value

Initial Dataset Size

1 GB (1 << 30)

Dataset Growth Per Epoch

8 MB (1 << 23)

Initial Cache Size

16 MB (1 << 24)

Cache Growth Per Epoch

128 KB (1 << 17)

Epoch Length

30,000 blocks

Mix Width

128 bytes

Hash Length

64 bytes

Hash Words

16 (32-bit words)

Dataset Parents

256

Cache Rounds

3

Accesses Per Loop

64

This dataset/cache size scaling ensures the network remains memory-hard, preventing ASIC dominance while keeping mining accessible for CPU and GPU miners.


2. Dataset & Cache Size Calculation

The dataset and cache sizes are determined by epoch number. Ethash-R5 precomputes values for the first 2,048 epochs, but after this limit, the sizes are calculated dynamically:

Cache Size Calculation

The cache size for an epoch n is computed as:

where:

  • The resulting value is adjusted downward to the nearest prime number.

Dataset Size Calculation

Similarly, the dataset size is calculated as:

  • Like the cache size, this value is also adjusted downward to the nearest prime number.

For blocks beyond epoch 2,048, the dataset and cache sizes are calculated on demand.


3. DAG & Cache Generation

Cache Generation

The cache is a compressed representation of the dataset and is used for dataset lookup during mining.

  1. Initial Seed: The cache is seeded using the Keccak-256 hash of a block’s epoch.

  2. Keccak-512 Hashing: The seed undergoes multiple rounds of Keccak-512 hashing to populate the cache.

  3. Mixing Rounds: Each entry in the cache is XOR-ed with values from random locations in previous cache entries.

  4. Endian Correction: The cache undergoes a byte-swap step if the system is big-endian.

Dataset Generation

The dataset is derived from the cache and follows these steps:

  1. Initial Mix: Each dataset element is initialised using a combination of cache values and its index.

  2. Random Parent Selection: The dataset generation process selects 256 random cache parents.

  3. FNV Hashing: The mix is iteratively FNV-hashed with parent values.

  4. Final Keccak-512: A final Keccak-512 hashing step produces the dataset element.

Note: Unlike the cache, the dataset is not stored permanently—it is regenerated on demand.


4. Hashimoto PoW Function

The core mining process in Ethash-R5 uses the Hashimoto function, a memory-hard PoW function.

Hashimoto Steps

  1. Header + Nonce Hashing:

    • A 40-byte seed is created by concatenating the block header hash and nonce.

    • This seed is hashed using Keccak-512.

  2. Mix Initialisation:

    • The Keccak output is replicated across a 128-byte mix.

  3. Memory Access Loop (64 iterations):

    • At each iteration:

      • A dataset parent is randomly selected.

      • The mix is FNV-hashed with the dataset parent.

  4. Mix Compression:

    • The mix is compressed into a 32-byte digest using FNV hashing.

  5. Extra Sequential Mixing Rounds (R5 Enhancement):

    • The digest undergoes 4 additional FNV-mixing rounds.

    • This increases sequential computation requirements, further reducing ASIC efficiency.

  6. Final Hashing:

    • A final Keccak-256 hash is computed to generate the PoW output.


5. PoW Verification

To verify a submitted proof-of-work, Ethash-R5 follows the steps:

  1. Recompute Seed:

    • The header hash and nonce are hashed together.

  2. Run Hashimoto:

    • The Hashimoto function is executed using the miner’s provided nonce and mix digest.

  3. Compare PoW Target:

    • The final hash must be below the difficulty target for the block to be valid.

Validation is lightweight, requiring only the cache rather than the full dataset.


6. Difficulty Adjustment

Ethash-R5 employs a modified difficulty algorithm designed to maintain a 7-second block time:

  • The difficulty adjusts every block based on the timestamp difference from the previous block.

  • Instead of Ethereum’s factor of 3, the adjustment divides difficulty by 2.

  • This modification ensures the network remains stable at 7-second blocks.


Security Enhancements

Ethash-R5 introduces additional security measures to mitigate ASIC and centralisation risks:

  1. Extra Sequential Mixing:

    • Additional rounds of FNV mixing ensure that PoW computations remain sequential.

  2. Memory-Hard Constraints:

    • The progressive dataset growth prevents fixed-hardware ASICs from gaining long-term advantages.

  3. Strict Epoch Enforcement:

    • Each epoch’s dataset is unique, preventing reuse across epochs.

  4. Supply Cap Enforcement:

    • Once the final issuance block (1,290,406,400) is reached, no more mining rewards are issued.


Go Implementation

Last updated