# Protocol

## Bitcoin base

Riecoin is based on Bitcoin, in particular Riecoin Core is a fork of Bitcoin Core. For now, most of the Bitcoin protocol is left unchanged, so you can in general use existing Bitcoin documentations or tutorials to learn about the Riecoin protocol, there are plenty of them. Of course, you need to take care of things like the modified chain parameters or the different PoW.

## Riecoin general parameters

Here are general chain parameters, notably values defined in the Riecoin Core's chainparams.cpp source file, as well as some other constants.

• Blocks every 2.5 minutes (150 seconds);
• Base block reward of 50 RIC, halving every 840000 blocks (~4 years);
• Maximum supply: about 84 million RIC;
• Smallest amount: 0.00000001 RIC, or 1 riemann;
• Mainnet: ric (Bech32), R (3C16 = 6010, P2PKH), T[1] (4116 = 6510, P2SH);
• Testnet: tric (Bech32), r (7A16 = 12210, P2PKH), t (7F16 = 12710, P2SH);
• Regtest: rric (Bech32), r (7A16 = 12210, P2PKH), t (7F16 = 12710, P2SH).
• RPC port 28332 (38332 for Testnet, 38443 for Regtest);
• P2P port 28333 (38333 for Testnet, 38444 for Regtest);
• Block limits:
• 2 MB (weight 8M);
• Block rewards can be spent only after 100 confirmations;
• Starting from the second fork, a block's timestamp must be at most 15 s earlier than the previous one, and 15 s later than the current time.
• Protocol version 10070001, magic number (Little Endian) 0xFCBCB2DB (0x0D091105 for Testnet, 0xFABFB5DA for Regtest);
• Signed messages prefix: Riecoin Signed Message:\n.

A Riecoin block header has the following structure (in total, 896 bits, or 112 bytes):

• 32 bits – stores the block version (this includes bits for softfork support signaling);
• 256 bits – stores the hash of the previous block;
• 256 bits – stores the Merkle Root of the block’s transactions;
• 64 bits – stores the block's timestamp;
• 32 bits – stores the difficulty;
• 256 bits – stores the PoW solution (this field is often called nOffset or Nonce).

With Riecoin Core, you can get the raw header of a block using getblockheader <block hash> false. To get the block hash knowing its number, use for example getblockhash 1000000.

## Proof of Work

The Riecoin Proof of Work (PoW) features the central change from Bitcoin. Instead of looking for hashes, Riecoin miners are looking for prime constellations.

To be a good proof of work, solutions should be much harder to find than verify. If the proof of work were just to find a prime number of length ${\displaystyle n}$, checking whether a number is actually prime is not much easier, so this would not be a good PoW. Validating blocks and their transactions would be almost as hard as finding them.

A way to make finding much harder than verifying is to not just look for prime numbers, but prime constellations. A prime constellation of length ${\displaystyle k}$ is a sequence of ${\displaystyle k}$ prime numbers ${\displaystyle (n_{1},n_{2},...,n_{k})}$, ${\displaystyle n_{1}, such that the diameter ${\displaystyle n_{k}-n_{1}}$, is in some sense the least possible[2]. Like we say that Bitcoin has a Sha256 PoW, the Riecoin PoW is called Stella.

Increasing the length makes finding constellations much harder, while verifying that the ${\displaystyle k}$ numbers are indeed prime will not be much more difficult, so we would ideally want to use the largest ${\displaystyle k}$ we can. However, a too large ${\displaystyle k}$ would make mining too hard and force to find much smaller prime numbers, which is something that would also make GPU mining easy. ${\displaystyle k=6}$ was initially chosen, because the known algorithms at this time were too slow for ${\displaystyle k=7}$. Starting from the second hard fork, ${\displaystyle k}$ will be 7.

Read this page to learn about the PoW implementation in detail. You might also take a look at the explanation of the mining algorithm, and the Stella page.