# Fixed-Point Arithmetic for Rate Computation

To compute base reward rate, base exchange rate, validator-specific exchange rates, and total validator voting power, we need to carefully perform arithmetic to avoid issues with precision and rounding. We use explicitly specified fixed-precision arithmetic for this, with a precision of 8 digits. This allows outputs to fit in a u64, with all products fitting in the output and plenty of headroom for additions.

All integer values should be interpreted as unsigned 64-bit integers, with the
exception of the validator’s commission rate, which is a `u16`

specified in
terms of basis points (one one-hundredth of a percent, or in other words, an
implicit denominator of $10_{4}$). All integer values, with the exception of the
validator’s commission rate, have an implicit denominator of $10_{8}$.

Throughout this spec *representations* are referred to as $x$, where
$x=x⋅10_{8}$, and the *value* represented by representations is
$x=x⋅10_{−8}$.

As an example, let’s take a starting value $x$ represented in our scheme (so, $x⋅10_{8}$) and compute its product with $y$, also represented by our fixed point scheme, so $y⋅10_{8}$. The product $xy$ is computed as

$⌊10_{8}(x10_{8})(y10_{8}) ⌋=⌊10_{8}xy ⌋$

Since both $x$ and $y$ are both representations and both have a factor of
$10_{8}$, computing their product includes an extra factor of 10^8 which we
divide out. All representations are `u64`

in our scheme, and any fixed-point
number or product of fixed point numbers with 8 digits fits well within 64
bits.

### Summary of Notation

- $r_{e}$: the fixed-point representation of the base rate at epoch $e$.
- $psi(e)$: the fixed-point representation of the base exchange rate at epoch $e$.
- $s_{i,e}$: the funding rate of the validator’s funding stream at index $i$ and epoch $e$, in basis points.
- $c_{v,e}$: the sum of the validator’s commission rates, in basis points.
- $r_{v,e}$: the fixed-point representation of the validator-specific reward rate for validator $v$ at epoch $e$.
- $psi_{v}(e)$: the fixed-point representation of the validator-specific exchange rate for validator $v$ at epoch $e$.
- $y_{v}$: the sum of the tokens in the validator’s delegation pool.
- $iota_{v}(e)$: the validator’s voting power for validator $v$ at epoch $e$.

## Base Reward Rate

The base reward is an input to the protocol, and the exact details of how this base rate $r_{e}$ is determined is not yet decided. For now, we can assume it is derived from the block header.

## Base Exchange Rate

The base exchange rate, $ψ(e)$, can be safely computed as follows:

$psi(e)=⌊10_{8}psi(e−1)⋅(10_{8}+r_{e}) ⌋$

## Commission Rate from Funding Streams

To compute the validator’s commission rate from its set of funding streams, compute $c_{v,e}=i∑ s_{i,e}$ where $s_{i,e}$ is the rate of validator $v$’s $i$-th funding stream at epoch $e$.

## Validator Reward Rate

To compute the validator’s base reward rate, we compute the following:

$r_{v,e}=⌊10_{8}(10_{8}−(c_{v,e}⋅10_{4}))r_{e} ⌋$

## Validator Exchange Rate

To compute the validator’s exchange rate, we use the same formula as for the base exchange rate, but substitute the validator-specific reward rate in place of the base reward rate:

$psi_{v}(e)=⌊10_{8}psi_{v}(e−1)⋅(10_{8}+r_{v,e}) ⌋$

## Validator Voting Power

Finally, to compute the validator’s voting power, take:

$iota_{v}(e)=⌊y_{v}⋅psi(e)psi_{v}(e) ⌋$