Example #1
0
	def __init__(self, env, id,  honest, manual_committee_size=2):
		self.env = env
		self.id = id
		self.chain=BlockChain()
		self.gossip_pipes = Links(self.env)
		#store peer AlgoNode for shuffling
		self.peers=list()
		self.pipe = simpy.Store(self.env)
		self.sk = vrftool.new_sk()
		self.pk= vrftool.get_pk(self.sk)
		self.proposers = 100

		self.manual_committee_size = manual_committee_size
		self.block_candidates = dict()
		#buffer structure: round:messages
		self.blocks_and_proof=dict()
		#record incoming msg
		self.message_buffer=dict()
		#store votes for each step
		self.vote_buffer = dict()
		#store voters and their votes for each round an step
		self.voters = dict()
		self.request = list()
		self.unprocessed_msg = list()
		self.waiting_block=dict()
		self.waiting_reply = False
		self.Tenative = False
		#set node type honest or malicious
		if honest:
			self.honest = True
		else:
			self.honest = False
Example #2
0
    def __init__(self, env, id, honest, manual_committee_size=2000):
        self.env = env
        self.id = id
        self.chain = BlockChain()
        self.hashchain = dict()
        #store peer AlgoNode for shuffling
        self.peers = list()

        self.sk = vrftool.new_sk()
        self.pk = vrftool.get_pk(self.sk)

        #sortition parameters
        self.proposers = 26
        self.manual_committee_size = manual_committee_size

        self.Pipes = []
        self.Gossiped_Msg = []

        self.Max_Priority_Proposal = dict()
        self.block_candidates = dict()
        #buffer structure: round:messages
        self.Block_Proposals_Msg = dict()
        self.Vote_Msg = dict()
        self.voters = dict()
        self.vote_buffer = dict()
        self.wblock = dict()
        self.waiting_block = False
        self.SortForC = dict()
        self.SortForB = dict()
        self.Tenative = False
        self.ReductionTime = 0
        self.BBAtime = 0
        self.height = max(self.chain.chain.keys())
        self.counttime = 0
        self.Round_start_time = dict()
        #set node type honest or malicious
        if honest:
            self.honest = True
        else:
            self.honest = False
Example #3
0
        indexes_of_j = []
        return j, indexes_of_j
    return j, indexes_of_j


def get_bond(j, user_total, prob):
    sum = 0
    while j >= 0:
        sum += ss.binom.pmf(j, user_total, prob)

        j -= 1
    return sum


ms = '0x9d'
sk = vrftool.new_sk()
p = vrftool.get_proof(sk, ms)
h = vrftool.get_hash(p)
j, indexes_of_j = subuser(5, 26 / 100000000, h)

algolist = [vrftool.new_sk() for i in range(50000)]
hash = [vrftool.get_hash(vrftool.get_proof(sk, ms)) for sk in algolist]
start = time.time()
count = 0
times = 0
c = 10
while c > 0:
    for h in hash:
        times += 1
        weight = random.randint(1, 500)
        print(f'counting for {h} with weight{weight}')
Example #4
0
import vrftool
import math
import binascii
newsk = vrftool.new_sk()
print(newsk)
newpk=vrftool.get_pk(newsk)
print(newpk)
ms = '0x9d'
newproof = vrftool.get_proof(newsk,ms)
print(newproof)
newhash = vrftool.get_hash(newproof)
print(newhash)

flag = vrftool.verify_proof(newproof,newpk,ms,newhash)
print(flag)

hash = newhash.decode('utf-8')
print(hash)
val = bin(int(hash,16))
total = pow(2,len(val))
num = int(val,2)
print(num)
print(total)
hashres = num/total
user_total_tokens=5
total = 100

prob = 0.2

#factorial function
def factorial(num):
Example #5
0
import vrftool
import math
from utils import bino_bond
import random
subusers = 200
total_tokens = 10000
thresh = 2 / 3
prob = subusers / total_tokens
nodes = [vrftool.new_sk() for x in range(100)]
ms = '0x9d'
proofs = [vrftool.get_proof(node, ms) for node in nodes]
hash = [vrftool.get_hash(proof) for proof in proofs]
p = vrftool.get_proof(nodes[0], ms)
h = vrftool.get_hash(p)
print('vrfproof length', len(p))
print('vrfhash lenthg', len(h), h)
user_tokens = [100 for x in range(100)]


def subusers(user_total_tokens, probs, hash):
    print(hash)
    bonds = bino_bond(user_total_tokens, probs)
    js = 0
    hash = hash.decode('utf-8')
    val = bin(int(hash, 16))

    total = pow(2, 512)
    num = int(val, 2)
    hashprob = num / total
    print(hashprob)
    flag = True