The following is from the Bitcoin whitepaper. The goal was to calculate the probability (P) an attacker could get lucky and override z number of blocks with q is the percentage of the network in control.
I'm interested in moving backwards from this and calculating the percentage of the network the attacker would have to control in order to roll back x blocks given some probability of success P.
Is this possible or am I thinking about this weird?
How would I represent solving for q instead of p in code?
Converting to C code...
#include <math.h>
double AttackerSuccessProbability(double q, int z)
{
double p = 1.0 - q;
double lambda = z * (q / p);
double sum = 1.0;
int i, k;
for (k = 0; k <= z; k++) {
double poisson = exp(-lambda);
for (i = 1; i <= k; i++) {
poisson *= lambda / i;
sum -= poisson * (1 - pow(q / p, z - k));
}
return sum;
}
}