def Verify_Gossip(self, message, ctx=None): pk = message.pk proof = message.proof round = message.round if message.isProposal: if round - len(self.chain.chain)>1: print(f'node {self.id} cant verify coz outdated chain') return False seed =self.get_seed(round) hashstring = seed + block_proposer return vrftool.verify_proof(proof,pk, hashstring) else: if not ctx: return False else: vote_vrfstring = committe_member+str(message.round)+str(message.voteinfo[0]) return vrftool.verify_proof(proof, pk, vote_vrfstring)
def Verify_Sort(self, pk, hash, proof, seed, thresh_num, role, user_total_tokens): #to be implemented return vrftool.verify_proof(proof, pk, (seed + role))
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):