kub12

nombre de confirmations

Aug 17th, 2019
134
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.41 KB | None | 0 0
  1. // nombre de confirmations
  2. var z = 6;
  3.  
  4. // medium hashrate
  5. var q = 80;
  6.  
  7. // spend attack (bitcoin)
  8. var v = 10;
  9.  
  10. // maximum authorized delay
  11. var A = 20;
  12.  
  13. // nombre d'attaque
  14. var n = 100;
  15.  
  16. // validation reward for each block validation
  17. var block_reward = 0.5;
  18.  
  19. // Miner's revenue at the end of the attack cycle
  20. var Ri = 0;
  21.  
  22. // Time duration of the attack cycle
  23. var Ti = 0;
  24.  
  25. // pre-mining
  26. var premining = 1;
  27.  
  28. // number of block mined by honest miners
  29. var honest_miners_blocks_validated = 0;
  30.  
  31. // number of block mined by attacker miner
  32. var attacker_blocks_validated = 0;
  33.  
  34. // retard entre la blockchain officiel et la blockchain fork. True si dépassé, false sinon.
  35. var delay_exceeded = A < Math.abs(honest_miners_blocks_validated - attacker_blocks_validated);
  36.  
  37. // nombre d'attaque actuel. True si égal ou dépassé, false sinon
  38. var number_attack_exceeded = Ti >= n;
  39.  
  40. var attacker_block_ahead = attacker_blocks_validated > honest_miners_blocks_validated;
  41.  
  42. // 1 : mined by honest miner - 0 : mined by attacker
  43. var block_mined = function(){
  44. var random = Math.round(Math.random());
  45.  
  46. if (random == 1){
  47. honest_miners_blocks_validated++;
  48. console.log("Honest miner had mined a block !")
  49. }
  50. else {
  51. attacker_blocks_validated++;
  52. console.log("Attacker miner had mined a block !")
  53. }
  54. }
  55.  
  56. var total_rewards = function(){
  57. attacker_blocks_validated * block_reward + v;
  58. }
  59.  
  60. // attack cycle started
  61. console.log("Attack cycle started !")
  62.  
  63. // affectation of the premined block for attacker
  64. //console.log("Affectation of the premined block for attacker.")
  65. //attacker_block_validated += premining;
  66.  
  67. while (!(A < Math.abs(honest_miners_blocks_validated - attacker_blocks_validated)) && !(Ti >= n) && !(attacker_blocks_validated > honest_miners_blocks_validated)) {
  68. block_mined();
  69. Ti++;
  70. }
  71.  
  72. if(A < Math.abs(honest_miners_blocks_validated - attacker_blocks_validated))
  73. console.log("Delay exceeded ! End of the cycle attack")
  74. else if(Ti >= n)
  75. console.log("Number of attack exceeded ! End of the cycle attack")
  76. else if(attacker_blocks_validated > honest_miners_blocks_validated) {
  77. console.log("We have mined more blocks than the official blockchain ! End of the cycle attack. Broadcasting of our fork.")
  78. console.log("Total rewards : " + (attacker_blocks_validated * block_reward + v) + " btc")
  79. console.log("Time of attack cycle : " + Ti)
  80. }
Add Comment
Please, Sign In to add comment