Created
January 12, 2018 11:29
-
-
Save lesstif/e7bcb8185ba624946d9102db9532c8a2 to your computer and use it in GitHub Desktop.
비트코인 공격자가 유효하지 않은 거래를 블록에 넣을 확율
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(""); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
사토시 논문에 있는 C 소스를 자바로 옮김. q 가 0.5 이상일 경우 안정성 훼손