``` 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54``` ```#!/usr/bin/python #This script was written by Darren Tapp and optimized by thephez from decimal import Decimal from math import log from math import factorial as fac from math import log1p from math import exp def binom(x, y): try: binom = fac(x) // fac(y) // fac(x - y) except ValueError: binom = 0 return binom ###This function takes inputs and outputs the probability #of sucess in one trial #pcalc is short for probability calculation def pcalc(masternodes,quorumsize,attacksuccess,Byznodes): SampleSpace = binom(masternodes,quorumsize) pctemp=0 for x in range(attacksuccess, quorumsize+1): pctemp = pctemp + binom(Byznodes,x)*binom(masternodes-Byznodes,quorumsize-x) #at this junctiure the answer is pctemp/SampleSpace #but that will produce an overflow error. We use logarithims to #calculate this value return 10 ** (log(pctemp,10)- log(SampleSpace,10)) def DekaYear(probability): trials = 2*365*10 return 1-exp(trials * log1p(-probability)) #Control of Quorum Byz = 2473 print pcalc(5000,400,240,Byz) print DekaYear(pcalc(5000,400,240,Byz)) #Withold Chainlock Byz = 1515 print pcalc(5000,400,161,Byz) print DekaYear(pcalc(5000,400,161,Byz)) ```