# The Stella PoW

This page will explain the Riecoinβs PoW from a cryptocurrency/economic point of view and is meant for Riecoin miners, developers, and pool operators. It will explain useful tools like how to compute earning estimations or mining power, either for integrating the Riecoin's PoW or just to learn more about Riecoin mining. An example of application of this page is this mining calculator. If you look for the more mathematical aspect of Riecoin mining, read this page. If you are rather looking for low level things like how the PoW results are encoded, read this page.

**Stella** refers to the PoW type like we say that Bitcoin is Sha256, or Litecoin is Scrypt. In the case of Riecoin, it does not actually refer to the actual algorithm used by miners, but rather to what they are trying to find, prime con**stella**tions. Old implementations may also have referred Stella as "PrimesR".

## Riecoin PoW

As a reminder, a **prime constellation of length $k$** is a sequence of $k$ prime numbers $({n}_{1},{n}_{2},...,{n}_{k})$, ${n}_{1}<{n}_{2}<...<{n}_{k}$, such that the diameter ${n}_{k}\beta \x88\x92{n}_{1}$, is in some sense the least possible.

The important parameters are:

- The
**constellation length**$k$: 7 (5 in Testnet); - The
**Difficulty**$D$, which correspond to the size of the prime numbers, which is about ${2}^{D}$.

While looking for them, miners first generate **candidates** at a rate of $c$ candidates/s. Then they check if the candidates are prime constellations. In practice, it can be stated that every of these candidates have a probability $\frac{1}{r}$ to be a prime number, $\frac{1}{{r}^{2}}$ to be a 2-tuples, etc. $r$ is the **ratio** of the rate of found $i$ to $(i+1)$-tuples for $i\beta \x88\x88\{0;1;...;k\beta \x88\x921\}$ (a candidate whose ${n}_{1}$ is not prime is a 0-tuple). It does not depend on the $i$ but is proportional to the Difficulty, and may also change depending on the miner settings.

In other words, the occurrences of $i$-tuples can be modeled as a Poisson Process of intensity $\frac{1}{{r}^{i}}$.

## Solo mining

### Process

The mining process in solo mining is straightforward. A miner will generate the candidates, then check if ${n}_{1}$ is prime for one of them. If not, the miner discards it and checks the next one, else it continues and checks ${n}_{2}$, and so on. If the ${n}_{i}$ is prime for all the $i$, a prime constellation was found and a block can be submitted to the Riecoin network.

### Earnings estimation

Computing the earnings only requires $c$ and $r$, which can be obtained easily: count the number of candidates and prime numbers (in the sense how many times ${n}_{1}$ was prime) found during some time and do elementary arithmetics.

$\frac{c}{{r}^{k}}$ gives a good estimation of the block rate (in blocks/second), so $86400\frac{c}{{r}^{k}}$ will give the average blocks found every day. Multiplying this by the block reward (currently 25 RIC) will yield the earnings in RIC/day.

$\frac{{r}^{k}}{c}$ gives the average time to find a block in seconds, and a miner will have 50% chance to find a block within $\mathrm{log}\beta \x81\u2018(2)\frac{{r}^{k}}{c}$.

### Normalization

One issue with just having a block rate is that it cannot be used if the difficulty varies. For the same mining power, if $D$ increases, $c$ will be lower and $r$ higher, and there will be less blocks found (but because there is more mining power in the network, the network's average time between blocks will remain the same).

To handle this, these two assumptions can be used:

- $r$ is proportional to $D$, which is close to the reality.
- $c$ is inversely proportional to ${D}^{2.3}$. In reality, the power is something around 2.2-2.6 according to empirical observations (see rieMiner Benchmarks), increasing when $D$ is higher, but it is not easy to derive a precise formula for this so we are just taking 2.3.

Using them allows to normalize various metrics. For example, $(\frac{D}{{D}^{\beta \x80\xb2}}{)}^{k+2.3}\frac{c}{{r}^{k}}$ gives a good estimation of the block rate for a reference difficulty $D\text{'}$ using the candidates/s and ratio metrics at difficulty $D$. Or, $(\frac{D}{{D}^{\beta \x80\xb2}}{)}^{2.3}c$ estimates the candidates/s as if we were mining at difficulty $D\text{'}$ from metrics for $D$.

The Riecoin Core's `getnetworkminingpower`

command uses ${D}^{\beta \x80\xb2}=600$ to provide a normalized number that corresponds to how many times the current network's mining power is larger than the power needed to find a block of difficulty 600 every 150 s.

## Pooled mining

### Shares

In pooled mining, the point is to avoid long periods between blocks for a miner by making them find and submit *shares* instead. The conditions to meet for a share are much weaker versions of the ones for a block, so finding shares is much easier, but one of them will eventually also be a block. Pools then reward miners based on the submitted shares.

Usually, the conditions for a share are the same as the ones for a block, but with a lower difficulty. This clearly cannot be done for Stella. Instead of lowering the difficulty and submitting shares with smaller prime numbers, an idea would be reduce the tuple length. However, looking for shorter tuples is easier than looking for full $k$-tuples and submit shorter tuples (the sieving process is shorter and there are less numbers to test), making mining more profitable for those who just want to find shares, which is not an acceptable solution.

The currently widely implemented condition for a share is as follows:

- Among the $k$ numbers, $k\beta \x88\x922$ must be prime
- The first two numbers must be prime.

The first condition forces miners to look for actual $k$-tuples. A miner will have to test the different numbers until either enough are prime or the current candidate cannot longer be a share. There is one issue, it can happen to check numbers in hopes that it is a share, despite knowing that the candidate will never be a part of a block, reducing pooled mining's general performance. The second condition renders the impact of this issue negligible.

The **share prime count** is the number of prime numbers, but is equal to 0 if the second condition is not true.

### Earnings estimation

At the miner's side, the process is such that $c$ and $r$ can be obtained in the same way as in solo mining, so calculating the earnings can be done as explained above.

At a pool's side, only the share rate metric can be known (let $s$ be the rate in shares/s), and some combinatorics is required if the operator wishes to show the earning estimations to miners. To do so, the first step is to derive the probability $P$ of a candidate to be a share.

A candidate must first have ${n}_{1}$ and ${n}_{2}$ that are prime numbers. This has $\frac{1}{{r}^{2}}$ probability of occurring (see below for the ratio estimation). Then, we still need at least $k\beta \x88\x924$ numbers to be prime among the remaining $k\beta \x88\x922$ numbers ${n}_{3}$ to ${n}_{k}$. The probability of having exactly $m$ additional prime numbers can be calculated by using the Binomial Distribution, ${P}_{k\beta \x88\x922,m}=(\genfrac{}{}{0ex}{}{k\beta \x88\x922}{m})(\frac{1}{r}{)}^{m}(1\beta \x88\x92\frac{1}{r}{)}^{k\beta \x88\x922\beta \x88\x92m}$. $(\genfrac{}{}{0ex}{}{n}{k})=\frac{n!}{k!(n\beta \x88\x92k)!}$ is the Binomial Coefficient.

With this and basic probability rules, we can now calculate

- $P=\frac{1}{{r}^{2}}({P}_{k\beta \x88\x922,k\beta \x88\x924}+{P}_{k\beta \x88\x922,k\beta \x88\x923}+{P}_{k\beta \x88\x922,k\beta \x88\x922})$

- For 7-tuples (Mainnet): $P=\frac{1}{{r}^{2}}({P}_{5,3}+{P}_{5,4}+{P}_{5,5})=\frac{1}{{r}^{2}}(10(\frac{1}{r}{)}^{3}(1\beta \x88\x92\frac{1}{r}{)}^{2}+5(\frac{1}{r}{)}^{4}(1\beta \x88\x92\frac{1}{r})+(\frac{1}{r}{)}^{5})$
- For 5-tuples (Testnet): $P=\frac{1}{{r}^{2}}({P}_{3,1}+{P}_{3,2}+{P}_{3,3})=\frac{1}{{r}^{2}}(3(\frac{1}{r})(1\beta \x88\x92\frac{1}{r}{)}^{2}+3(\frac{1}{r}{)}^{2}(1\beta \x88\x92\frac{1}{r})+(\frac{1}{r}{)}^{3})$

There is no way to get the ratio $r$, but you can estimate it with $r\beta \x89\x880.0181116D$.

Finally, we have $c=\frac{s}{P}$ and the earnings can be calculated like above.

Note that the share rate is probably relatively low, so the accuracy of the earnings estimation will also be low.

### Normalization

Again, it is the same as solo mining at the miner's side. For the pool's side, you can calculate $c$ and $r$ like explained and apply the tricks exposed in the solo mining section.

Pools should use a normalized metric in order to compare their mining power in an other way than just looking at the distribution of the latest 1000 Riecoin blocks or so. A suggested option is to compute the mining power as a factor of the power needed to find a block at difficulty 600 every 150 s, which can be approximated with

- $\frac{150s}{P{r}^{k}}(\frac{D}{600}{)}^{k+2.3}$

Dividing this value by the Riecoin Core's `getnetworkminingpower`

result will approximate the pool's contribution to the entire Riecoin network mining power.