Skip to content

Instantly share code, notes, and snippets.

@lesstif
Created January 12, 2018 11:29
Show Gist options
  • Save lesstif/e7bcb8185ba624946d9102db9532c8a2 to your computer and use it in GitHub Desktop.
Save lesstif/e7bcb8185ba624946d9102db9532c8a2 to your computer and use it in GitHub Desktop.
비트코인 공격자가 유효하지 않은 거래를 블록에 넣을 확율
package bitcoin;
import static java.lang.Math.exp;
import static java.lang.Math.pow;
public class AttackerSuccessProbability {
public static double AttackerSuccessProbability(double q, int z)
{
// p = probability an honest node finds the next block
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;
}
public static void main(String[] args)
{
// q = probability the attacker finds the next block
double qs[] = {0.1, 0.3, 0.5};
for( int j = 0; j < qs.length; j++) {
double q = qs[j];
System.out.println("q=" + q);
for (int z = 0; z < 10; z++) {
System.out.println(String.format("z=%d, prob=%f", z, AttackerSuccessProbability(q, z)));
}
System.out.println("");
}
}
}
@lesstif
Copy link
Author

lesstif commented Jan 12, 2018

사토시 논문에 있는 C 소스를 자바로 옮김. q 가 0.5 이상일 경우 안정성 훼손

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment