You are totally right BlackHatCoiner but those are 2 different things, one thing is the 51% attack, where the miners can modify confirmed blocks, and the second thing is the double spend where the user modifies the unconfirmed transaction.
That is correct. The miner does not double-spend; it gives the user the option to double-spend. I think, though, that I have clarified it enough, because I mentioned "reversal" alternatively to "double-spend". Whether the miner double-spends or "simply" reverses, the result is that your coins are prone to double-spending.
hosseinimr93 After seeing your algorithm, I tried to do it in C++, but I don't understand why it's getting a minus. I tried with the help of that source, but the answer was a minus.
The reason is probably because you're subtracting from 0 (see the definition of
result and which operations you're doing to it). I cannot see, though, if you're printing result or 1-result.
Here you go. I have commented the important parts.
#include <iostream>
#include <cmath>
using namespace std;
// constant number 'e'
const double Euler = std::exp(1.0);
// factorial of integer x
int fact(int x){
int i, factorial = 1;
for(i = 1; i <= x; i++)
factorial *= i;
return factorial;
}
int main(){
// q = the proportion of hashrate the attacker possesses
// z = the total confirmations
double q = 0.4;
int z = 6;
double p = 1 - q;
double lambda = z*q/p, sum = 0;
int k;
for(k = 0; k <= z; k++){
// build the fraction first
double fraction = pow(lambda, k) * pow(Euler, -lambda);
fraction /= fact(k);
// sum is sum + fraction * (...)
sum += fraction * (1 - pow((q/p), z-k));
}
// print
cout << 1 - sum << endl;
}
Compile with "
g++ -o attack attack.cpp" and run with "
./attack".