Formular

We use

poly(r)%ppoly(r) \% p

as the lottery result, where poly()poly() is a polynomial evaluation, rr is a random u256 integer, and pp is a large prime number. The basic theory behind this setting is that this modulus result will generate loops when rr increases from 00 to 225612^{256}− 1.

To see why, let’s consider the following polynomial:

f(x)=anxn+an1xn1+...+a0f(x) = a_nx^n + a_{n−1}x^{n−1} + ... + a_0

If we want to find a looping range i, i.e.,

f(x+i)=f(x)  (modp)    x0,1,...,22561f(x+i)=f(x) \space \space (\mod p)\space \space \space \space \forall x \in 0,1,...,2^{256}-1

which means

g(x)=f(x+i)f(x)=0  (modp)    x0,1,...,22561g(x)=f(x+i)−f(x)=0 \space\space (\mod p)\space \space \space \space \forall x \in 0,1,...,2^{256}-1

Equivalently, this means all the coefficients of g(x)g(x) should be 00. Denote the coefficients of g(x)g(x)as {bn,bn1,...,b0{b_n, b_n−1, ..., b_0}}. It is easy to see that is for all is i\forall i≥ 0, bib_iis divisible by ii. So if we set i=pi = p, all bib_i will be 00. Therefore, pp will be a looping range of f(x)f(x). Specially, if a0=0a_0 = 0, we will have f(0)=0f(0) = 0. Therefore, if there is no 00 in f(1),f(2),...,f(p1)f(1),f(2),...,f(p−1), then pp will be the minimal looping range of f(x)f(x).

The next step is to choose a prime pp such that pp is the minimal looping range, and the smallest probability 1/p(f(0)=01/p (f(0) = 0 is the only 00 in this range) is approximately the smallest required probability. Afterwards, the remaining task is to calculate all the probabilities of the lottery results and aggregate the ranges such that each range of results satisfies the required probabilities.

Last updated