Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // nombre de confirmations
- var z = 6;
- // medium hashrate
- var q = 80;
- // spend attack (bitcoin)
- var v = 10;
- // maximum authorized delay
- var A = 20;
- // nombre d'attaque
- var n = 100;
- // validation reward for each block validation
- var block_reward = 0.5;
- // Miner's revenue at the end of the attack cycle
- var Ri = 0;
- // Time duration of the attack cycle
- var Ti = 0;
- // pre-mining
- var premining = 1;
- // number of block mined by honest miners
- var honest_miners_blocks_validated = 0;
- // number of block mined by attacker miner
- var attacker_blocks_validated = 0;
- // retard entre la blockchain officiel et la blockchain fork. True si dépassé, false sinon.
- var delay_exceeded = A < Math.abs(honest_miners_blocks_validated - attacker_blocks_validated);
- // nombre d'attaque actuel. True si égal ou dépassé, false sinon
- var number_attack_exceeded = Ti >= n;
- var attacker_block_ahead = attacker_blocks_validated > honest_miners_blocks_validated;
- // 1 : mined by honest miner - 0 : mined by attacker
- var block_mined = function(){
- var random = Math.round(Math.random());
- if (random == 1){
- honest_miners_blocks_validated++;
- console.log("Honest miner had mined a block !")
- }
- else {
- attacker_blocks_validated++;
- console.log("Attacker miner had mined a block !")
- }
- }
- var total_rewards = function(){
- attacker_blocks_validated * block_reward + v;
- }
- // attack cycle started
- console.log("Attack cycle started !")
- // affectation of the premined block for attacker
- //console.log("Affectation of the premined block for attacker.")
- //attacker_block_validated += premining;
- while (!(A < Math.abs(honest_miners_blocks_validated - attacker_blocks_validated)) && !(Ti >= n) && !(attacker_blocks_validated > honest_miners_blocks_validated)) {
- block_mined();
- Ti++;
- }
- if(A < Math.abs(honest_miners_blocks_validated - attacker_blocks_validated))
- console.log("Delay exceeded ! End of the cycle attack")
- else if(Ti >= n)
- console.log("Number of attack exceeded ! End of the cycle attack")
- else if(attacker_blocks_validated > honest_miners_blocks_validated) {
- console.log("We have mined more blocks than the official blockchain ! End of the cycle attack. Broadcasting of our fork.")
- console.log("Total rewards : " + (attacker_blocks_validated * block_reward + v) + " btc")
- console.log("Time of attack cycle : " + Ti)
- }
Add Comment
Please, Sign In to add comment