# NPoS Consensus

StaFi adopts NPoS (Nomination Proof of Stake) as the mechanism for selecting a validator set. NPoS is an improved version of DPoS, which solves the problem of the tendency for centralization of validators. In the NPoS mechanism, there are 2 types of Stakers: nominators and validators. Unlike DPoS, the block reward will be distributed to all incumbent validators, instead of being distributed in proportion to the delegated Staking Tokens. In this way, the nominator will automatically balance the delegation among multiple validators, avoiding Matthew effect. From its day 1, StaFi will provide a limited number of validator positions, say, 60 in the beginning. But now it has has expanded to 200 of them, which will be further expanded as time goes on.

The system encourages FIS holders to engage in the network as nominators. Nominators can nominate up to 16 validators as trusted validator candidates. The validators perform consensus block-producing and guarantee the finality of the chain.

# Ⅰ. How to Staking?

## 1. Make clear which role you want to take on

You can be a nominator or a validator in when you are Staking.

As a nominator, you can nominate 1 or up to 16 validator nominators to earn inflation rewards. You can check The Guideline for a Nominator for more operations needed when the mainnet is landed.

Being a validator node, you must respond 24/7 in order to perform your duty and avoid misbehavior. If you want to become a validator and deeply engage in the maintenance of the network (the rewards will be higher), please check The Guideline for a Validator.

## 2. Nomination Period

Anyone can apply for a validator candidate. The list of candidates is open to all nominators. Each nominator submits a list of candidates it supports. In the next period (lasting several hours), 16 validators with the most FIS support will be selected and made effective. There are no special requirements for FIS holders to become nominators, although we hope that each nominator carefully examine the performance and reputation of the validator.

After the nomination period, 16 validators are selected to perform their tasks.

## 3. Staking Rewards Distribution

In order to explain how to pay rewards to validators and nominators, we need to introduce the concept of a validator pool. We define a validator pool consisting of a validator and nominators who support it. (Note: If a nominator n supports multiple(k) elected validators with his own stakes, then the system will split its stake into s_1, s_2, ..., s_k, which is considered to support v_1, v_2, ..., v_k respectively. The nominator n's share of supporting validator v_i is s_i.

In this case, the reward that the nominator n can obtain is equivalent to the nomination of v_i by k nominators, each with a Stake share of s_i.

The rewarding rule for the validator pool is that the two validator pools receive the same amount of FIS under equal workload, which is not proportional to the amount of FIS they obtained from supporters. In the validator pool, the reward is divided into two parts (the proportion is configurable), one will be paid to the validator, and the rest is paid to the nominator by the ratio of Staking. It should be noted that the nominator reward may contain the validator’s part, because the validator is the nominator of itself by nature, and its own &quot;vote&quot; is voted for itself.

To estimate the number of FIS that a nominator or validator can receive each month, you can check the reward mechanism part below.

If you need to calculate the fiat standard income instead of the token standard income, you must also take inflation rate into consideration. You may check the inflation section.

## 4. The Features of NPoS

We want to highlight two features of NPoS. First, since the incentive for the validator pools are of the same size, the pool with fewer delegates will pay a higher fee for each FIS nominator than the one with more. Therefore, we provide nominators with financial incentives to gradually transfer their delegations to validators with fewer delegates. The reason for this is that we hope that the equity of all validator pools is distributed as evenly as possible to avoid the concentration of power in a small number of validators. Under this mechanism, each and every validator pool will eventually have a similar amount of delegations. Validators with a good reputation may have a higher amount of delegations, but the validator pools will remain balanced.

Let me further explain by an example. To simplify, let’s assume that:

• Those validators have no staked tokens own by themselves.

• They don’t take any commission

• The rewards are 100 FIS

• The minimum amount FIS that needed to be validated is 350.

 A-Validator Pool Nominators（4） Delegation Amount（600） Portion Rewards Jane 100 0.167 16.7 Sam 50 0.083 8.3 Anderson 250 0.417 41.7 Boby 200 0.333 33.3
 B-Validator Pool Nominators（4） Delegation Amount（400） Portion Rewards Alice 100 0.25 25 Peter 100 0.25 25 John 150 0.375 37.5 Kitty 50 0.125 12.5

Both A pool and B pool have 4 nominators, the total delegation is 600 and 400 respectively.

According to the form above, for the same FIS principal, the nominator in Pool B receives more rewards than the nominator in Pool A, because Pool A‘s overall equity is higher. Sam has invested 50 FIS shares in A pool, but he only received a return of 8.3, while Kitty received a return of 12.5 with the same investment.

It should also be noted that when the system imposes Slash penalties for bad behaviors of the validator (for example, the validator is offline, or assumes other’s name, etc.), the number of Slash is a fixed percentage (instead of a fixed number of FIS), which means that the pool with more validators will be Slashed more FIS. Again, this is to provide nominators with financial incentives to adjust their preferences, from supporting the most popular validators to supporting those that they believe are trustworthy but less popular.

The second is that each validator candidate is free to propose its commission ratio needed to cover operating costs. Since the salary of the validator pool is the same, the pool with the lower commission will pay more to the nominator than the one with higher commission. Therefore, each validator can choose to increase their commission ratio to earn more FIS, or reduce their commission ratio to attract more nominators, thus increasing their chances of being elected. We will let the market adjust itself in this regard. In the long run, we expect that all validators are cost-effective and remain competitive, and those with higher credibility will be able to charge a slightly higher commission.

## 5. Validators and Nominators

Since the seats of validators are limited, most people who want to participate in Staking, maintain network security and earn rewards will be nominators. The validator undertakes most complicated work: they produce new block candidates in BABE, vote to reach consensus in GRANDPA, and may assume more responsibilities.

On the other hand, once a nominator Stakes FIS, there is no need to do anything. The nominator's experience is similar to "set and forget it", and the validator will actively provide services for the network by performing key operations.

# 二、Staking-Slash

Slash is a punishment for “illegal” behaviors of SVs in the consensus, for misconducts may cause problems such as system unstability or even system crash. For such problems, the NPoS consensus punishes “illegal” validators by “forfeiting” the Stake. Similar to reward calculations, penalty is calculated during every Era. The types and methods of punishment are as follows.

## 1. Off-line/Unresponsive

If a SV does not produce any block or send heartbeats test in an Era, then it will be judged as offline/unresponsive. When there are many offline/unresponsive nodes, the system will start to confiscate part of Staked tokens (including validators and nominators) as a regulation method. To make the punishment accurate and public, we set the following formula

$min((3*(k-(n/10+1)))/n,1)*0.07$

In the formula, n is the total number of SVs, k is the number of offline SVs. Note that when k-(n / 10 + 1) <0, the penalty is 0. Suppose there are 100 SVs, n = 100

Assuming n = 100,

When k = 1 ~ 11, the ratio of Slash is 0;

When k = 12, the ratio of Slash is 0.03 * 0.07 = 0.0021

When k = 21, the ratio of Slash is 0.3 * 0.07 = 0.021

When k = 31, the ratio of Slash is 0.6 * 0.07 = 0.042

When k = 41, the ratio of Slash is 0.9 * 0.07 = 0.063

When k = 51, the ratio of Slash is 1 * 0.07 = 0.07

In general, the ratio of Slash is from 0 to 7%. When less than 10% of all nodes are offline, a single node will not be slashed if it is offline or not responding. When 1/3 nodes are offline at the same time, the Slash ratio is close to 5 %.

## 2. Double-signing

In order to maintain the security of the system, during both the block-producing phase (Babe consensus) and the voting phase (Grandpa consensus), voting on different chains during a single round, or generating two new blocks in the same block slot will be considered malicious. The penalty formula is as follows

$min((\frac{3k}{n})^2,1)$

In the formula, n is the number of SVs, k is the number of chaotic or invalid voters of SVs.

Suppose n = 100

When k = 1, the ratio of Slash is 0.03 * 0.03 = 0.0009

When k = 10, the ratio of Slash is 0.09

When k = 21, the ratio of Slash is 0.3969

When k = 31, the ratio of Slash is 0.81

When k = 41, the ratio of Slash is 1

When k = 51, the ratio of Slash is 1

In general, the largest Slash ratio is 1, which means that a SV may be slashed 100% of Stake.

Validators can run their nodes on multiple servers in case that one of their nodes fails. It should be noted that if those servers do not coordinate well in terms of managing the signing machine, double-signing may happen unexpectedly.

If a validator is found misbehaved, it will be kicked out from the validator group, and its current reward will be confiscated. More over, they will be immediately regarded as inactive and will lose their nominator position. To become a validator again, they need to re-register, and reacquire nominators.

## 3.Slash Mechanism

One nominator may nominate multiple validators, but it may be Slashed if any one of the validators it nominated misbehaved. Before Slash, Staking FIS was reusable in every epoch. The nominator uses N FIS to consecutively nominate a validator for E epoch. If the validator is Slashed due to misconduct, it does not mean that the nominator will lose N * E FIS, just N.

When a validator has been found to have multiple mischieves before discovered, StaFi will implement Slash according to the highest amount of tokens in a ticket instead of the sum. In this way, validators will hardly possible to lose a huge amount of tokens when being punished. Validators who are found to misbehave will be dropped out to prevent revenges from the validators who got Slashed.

# Ⅲ. Withdrawal

Withdrawal refers to the act of deleting a validator from the active validator set and disqualifying it from candidancy from the next NPoS cycle.

This may be voluntary and initiated by the validator. For example, if there is a problem with the validator's surroundings or the server host, it may withdraw to avoid Slash. When it is a voluntary withdrawal, validators will be kept active in the current epoch, but be moved to an inactive state in that epoch. Validators will not lose their nominators.

Withdrawal may also be used as a punishment measure. In this case, the validator will be immediately disabled in the current epoch and be removed from the validator group in the next epoch.

StaFi allows some validators to be banned, but if there are too many validators disabled, a new validator selection process will be triggered to obtain enough workforce. The decertified validator will need to resubmit the application to regain support from nominators.

# Ⅳ. Rewarding Mechanism

## The Calculation of Rewards

Within each Era, validators will be paid by Era Points they earned. Era points can be obtained in the following ways. In the NPoS design of StaFi, the 3 actions below taken by validators can earn Era Points.

1. block-producing (non-uncle blocks in the relay chain)

2. producing uncle blocks (previously unreferenced uncles)

3. producing orphan blocks (referenced uncle blocks)

In order to guarantee block-producing, each block producer is elected by VRF algorithm. At the same time, the consensus will also elect alternate block producers by Round-Robin algorithm in advance in case that block producers do not perform their duty. In this way, each slot will necessarily be filled up with newly-produced blocks, and the final block is the one confirmed by GRANDPA, the others become uncle blocks, whereas those orphan blocks behind them will be also rewarded, fewer of course.

SVs pay the equivalent amount of work to produce a block, whether it be the final block, an uncle block or an orphan block. Therefore, the reward for a SV for producing a single block remains the same. Meanwhile, in NPoS design, each SV is entitled to equal Voting Power, not matter how much nominated Stake it receives. That is to say, each SV shares the same chance of being elected. Of course, the amount of Stake you own determines whether you are qualified to be elected.

The chance to produce a block is equal to all validators, which means there is no direct relevance between reward distribution and the weight of Stake. While in the PoS version of some projects, the possibility of producing a block is proportionate to the weight of Stake--more Stake will be given more chances to produce, thus more rewards. Judging from the existing projects, there is a tendency that Stake is gathering towards dominating block producers. In many cases, top 10 producers accounts for more than half of all Stake. NPoS can effectively tackle this problem, for the equal chance to produce balances the distribution of Stake, making the system much more decentralized. Currently, NPoS consensu is being tested in Kusama network.

For nominators, the fewer Stake Validators you nominates, the more rewards you can get, and vice versa. The nomination to a certain piece of FIS can obtain more rewards on a SV with fewer nomination. However, that kind of SV may have some risks, such as long-time offline, immature technical capabilities, lack of fame, or be inexperienced in node business. These factored are to be noted by nominators.

In order to better distribute rewards, StaFi records each validator’s rewards in each epoch. At the same, each reward cycle is 1 Era. A SV can claim its rewards when an Era ends, and when it is claimed, the protocol will automatically distribute rewards proportionate to the amount of Stake (It should be noted that if rewards haven’t been claimed within 84 Era, it will be burnt. We strongly recommend a SV to claim in advance.)

The rewards to the completion of producing each kind of block are as follows:

 Type blocks Uncle blocks Orphan blocks Rewards counting 20 2 1

Assuming that the validator is v, the number of blocks generated in an Era e is n, the number of Uncle blocks is s, and the number of orphan blocks is x, then the total reward count r obtained by the validator during e is

$r _e=20n+2s+x$

Assuming that there are 100 validators in a set, that is

$v_1，v_2,v_3……v_{100}$

then during e, the total reward count R of all validators is

Further, it can be deduced that

$R_e=\sum_{v=1}^{100}(20n_v+2s_v+x_v) \quad$

As for how many FIS an Era Point amounts to, it must be decided by the current inflation rate.

## The Distribution of Rewards

StaFi records the reward of each validator in one epoch, 2400 blockes are produced in one epoch, and one block is 6s, so one epoch is 4h. At the same time, StaFi issues rewards with one Era as a cycle, and validators can claim rewards at the end of each Era. An Era is 6 epochs, 24h.

A SV can claim its rewards when an Era ends, and when it is claimed, the protocol will automatically distribute rewards proportionate to the amount of Stake (It should be noted that if rewards haven’t been claimed within 84 Era, it will be burnt. We strongly recommend a SV to claim in

For example, assume that the total rewards for the validators are 10 FIS. They can decide commission validator_payment = 40%. In this case, the validator will receive 4 FIS. Then, the remaining 6 FISs are allocated proportionate to Stakes owned by each validator. If a validator also Staked FIS, a fraction of that 6 FISs will be allocated to that validator. So the Stake of that validator is like a nominator who nominated itself. Rewards can be directed to the Stash account or Controller. Rewards can also go directly back to Stake or not.

## Inflation

The rewards for a SV or a SSV come from system inflation, similar to Coinbase mechanism of Bitcoin. StaFi Protocol will generate new FIS (the process is called Coinstake) every time when a new block is produced, which is used to motivate SVs and SSVs that provides computing and storage resources. Controlling inflation rate is an economic issue. According to historical evolution and a large number of data, the annual inflation rate of PoS projects at this stage is around 5% and 20%.

In StaFi Protocol, there are following aspects that influence inflation rate:

$I=I_{NPoS}-I_{Slash}-I_{Tx-fee}$

Of which:

$I_{NPoS}=I_{SV}+I_{SSV}$

I_NPoS is system consensus rewards. In StaFi, it means both rewards for SV and for SSV. Slash's FIS and transaction fee's FIS, some will be distributed to the reporter, and some will be added to Protocol Treasury,which has a burning mechanism.

I_SV is effected by Staking rate. If we put other factors aside, the higher the Staking rate is, the more secure a system will be, and vice versa. The higher the Staking ratio, the lower the liquidity of the token. In FIS design, the inflation rate will dynamically be adjusted to the proportion of Stake. When the proportion of Stake increases, the system will reduce motivation. Otherwise, the motivation will increase. During the repeated adjustments, StaFi protocol explored an ideal Stake ratio of 50%, that is, when the Stake ratio exceeds 50%, the incentive will no longer increase,and I_SV is between 2.5% and 10%. The motivation curve is as follows. The further issuance ratio is 10% in the first year. If the staking rate is below ideal, the excess rewards will be transferred to Protocol Treasury.

I_SSV is related to service call, including the call for multi-signature service and RPC. During the Staking process, these 2 services need to be called for multiple times. To pay for the services, the system will motivate each call. In the initial setting, the Protocol stipulates a fixed increase of x% as a reward for service calls, and the initial range of x is [1,2].

The rewards for each call will be added up once in a Era. If the reward obtained from the current Era call is less than the system's further issuance during this period, the extras reward will be burnt. If the calling reward exceeds the system's additional issuance in the Era, the FIS reward for multiple-unit-calls will be reduced accordingly. This strategy will be flexible in the first year after after the mainnet is launched, and then be determined by the community through online governance.

I_Slash inflation is not a exact number. Under the premise that most people are honest, StaFi Protocol should not Slash a lot, and the chance of serious accidents is relatively small. In the existing PoS project, there have been several double-signing accidents, but most of them were caused by mistakes of the validator, so I_Slash has little effect on the overall inflation rate.

I_Tx-fee inflation is not a definite figure either. It depends on the usage of StaFi network, especially that of rToken. At the current stage, it cannot be evaluated, it will to some degree, reduce inflation along with the development of rToken.