def test_create_petition(self): ## run service checker_service_process = Process( target=petition_contract.run_checker_service) checker_service_process.start() time.sleep(0.1) ## create transaction # init init_transaction = petition.init() token = init_transaction['transaction']['outputs'][0] # initialise petition transaction = petition.create_petition( (token, ), None, None, UUID, options, priv_owner, pub_owner, vvk) ## submit transaction response = requests.post('http://127.0.0.1:5000/' + petition_contract.contract_name + '/create_petition', json=transaction_to_solution(transaction)) self.assertTrue(response.json()['success']) ## stop service checker_service_process.terminate() checker_service_process.join()
def test_create_petition(self): with petition_contract.test_service(): ## create transaction # init init_transaction = petition.init() token = init_transaction['transaction']['outputs'][0] # initialise petition transaction = petition.create_petition( (token,), None, None, UUID, options, sk_owners[0], aggr_pk_owner, t_owners, n_owners, aggr_vk ) ## submit transaction response = requests.post( 'http://127.0.0.1:5000/' + petition_contract.contract_name + '/create_petition', json=transaction_to_solution(transaction) ) self.assertTrue(response.json()['success'])
def test_init(self): with petition_contract.test_service(): ## create transaction transaction = petition.init() ## submit transaction response = requests.post( 'http://127.0.0.1:5000/' + petition_contract.contract_name + '/init', json=transaction_to_solution(transaction) ) self.assertTrue(response.json()['success'])
def test_sign(self): ## run service checker_service_process = Process( target=petition_contract.run_checker_service) checker_service_process.start() time.sleep(0.1) ## create transaction # init init_transaction = petition.init() token = init_transaction['transaction']['outputs'][0] # initialise petition create_petition_transaction = petition.create_petition( (token, ), None, None, UUID, options, priv_owner, pub_owner, vvk) old_petition = create_petition_transaction['transaction']['outputs'][1] old_list = create_petition_transaction['transaction']['outputs'][2] # some crypto # ------------------------------------ (priv_signer, pub_signer) = elgamal_keygen(bp_params) m = priv_signer (cm, c, proof_s) = prepare_blind_sign(bp_params, m, pub_signer) enc_sigs = [ blind_sign(bp_params, ski, cm, c, pub_signer, proof_s) for ski in sk ] (h, enc_epsilon) = zip(*enc_sigs) sigs = [(h[0], elgamal_dec(bp_params, priv_signer, enc)) for enc in enc_epsilon] sig = aggregate_th_sign(bp_params, sigs) sig = randomize(bp_params, sig) (kappa, nu, proof_v) = show_coconut_petition(bp_params, vvk, m, UUID) #print(coconut_petition_verify(bp_params, vvk, kappa, sig, proof_v, UUID, nu)) # ------------------------------------ # add signature to th petition start = time.time() transaction = petition.sign((old_petition, old_list), None, (dumps([1, 0]), ), priv_signer, sig, vvk) end = time.time() print((end - start) * 1000) ## submit transaction response = requests.post('http://127.0.0.1:5000/' + petition_contract.contract_name + '/sign', json=transaction_to_solution(transaction)) self.assertTrue(response.json()['success']) ## stop service checker_service_process.terminate() checker_service_process.join()
def test_sign(self): with petition_contract.test_service(): # create transaction # init init_transaction = petition.init() token = init_transaction['transaction']['outputs'][0] # initialise petition create_petition_transaction = petition.create_petition( (token,), None, None, UUID, options, sk_owners[0], aggr_pk_owner, t_owners, n_owners, aggr_vk ) old_petition = create_petition_transaction['transaction']['outputs'][1] old_list = create_petition_transaction['transaction']['outputs'][2] # some crypto to get the credentials # ------------------------------------ (d, gamma) = elgamal_keygen(bp_params) private_m = [d] Lambda = prepare_blind_sign(bp_params, gamma, private_m) sigs_tilde = [blind_sign(bp_params, ski, gamma, Lambda) for ski in sk] sigs = [unblind(bp_params, sigma_tilde, d) for sigma_tilde in sigs_tilde] sigma = agg_cred(bp_params, sigs) # ------------------------------------ # add signature to th petition transaction = petition.sign( (old_petition, old_list), None, None, d, sigma, aggr_vk, 1 ) ## submit transaction response = requests.post( 'http://127.0.0.1:5000/' + petition_contract.contract_name + '/sign', json=transaction_to_solution(transaction) ) self.assertTrue(response.json()['success'])
def test_init(self): ## run service checker_service_process = Process( target=petition_contract.run_checker_service) checker_service_process.start() time.sleep(0.1) ## create transaction transaction = petition.init() ## submit transaction response = requests.post('http://127.0.0.1:5000/' + petition_contract.contract_name + '/init', json=transaction_to_solution(transaction)) self.assertTrue(response.json()['success']) ## stop service checker_service_process.terminate() checker_service_process.join()
start_time = datetime.now() client = ChainspaceClient() # crypto parameters t, n = 4, 5 # threshold and total number of authorities bp_params = bp_setup() # bp system's parameters (sk, vk, vvk) = ttp_th_keygen(bp_params, t, n) # signers keys # petition parameters UUID = Bn(1234) options = ['YES', 'NO'] pet_params = pet_setup() (priv_owner, pub_owner) = pet_keygen(pet_params) tx_init = petition.init() # pp_object(tx_init) post_transaction(tx_init) # pp_object(init_transaction) petition_token = tx_init['transaction']['outputs'][0] print "\nCreate the petition\n" tx_create_petition = petition_contract.create_petition( (petition_token, ), None, None, UUID, options, priv_owner, pub_owner, vvk) pp_object(tx_create_petition['transaction'])
def test_read(self): with petition_contract.test_service(): # create transaction # init init_transaction = petition.init() token = init_transaction['transaction']['outputs'][0] # initialise petition create_petition_transaction = petition.create_petition( (token,), None, None, UUID, options, sk_owners[0], aggr_pk_owner, t_owners, n_owners, aggr_vk ) old_petition = create_petition_transaction['transaction']['outputs'][1] old_list = create_petition_transaction['transaction']['outputs'][2] # add signature to the petition for i in range(3): # some crypto to get the credentials # ------------------------------------ (d, gamma) = elgamal_keygen(bp_params) private_m = [d] Lambda = prepare_blind_sign(bp_params, gamma, private_m) sigs_tilde = [blind_sign(bp_params, ski, gamma, Lambda) for ski in sk] sigs = [unblind(bp_params, sigma_tilde, d) for sigma_tilde in sigs_tilde] sigma = agg_cred(bp_params, sigs) # ------------------------------------ sign_transaction = petition.sign( (old_petition, old_list), None, None, d, sigma, aggr_vk, 1 # vote ) old_petition = sign_transaction['transaction']['outputs'][0] old_list = sign_transaction['transaction']['outputs'][1] # tally for i in range(t_owners): transaction = petition.tally( (old_petition,), None, None, sk_owners[i], i, t_owners ) old_petition = transaction['transaction']['outputs'][0] # read transaction = petition.read( None, (old_petition,), None ) ## submit transaction response = requests.post( 'http://127.0.0.1:5000/' + petition_contract.contract_name + '/read', json=transaction_to_solution(transaction) ) self.assertTrue(response.json()['success']) print("\n\n==================== OUTCOME ====================\n") print('OUTCOME: ', loads(transaction['transaction']['returns'][0])) print("\n===================================================\n\n")
def main(): petition.contract._populate_empty_checkers() print "operation\t\tmean (ms)\t\tsd (ms)\t\truns" # == init =============== init_tx = petition.init() # == create_petition =============== # gen times = [] for i in range(RUNS): start_time = time.time() petition.create_petition( (init_tx['transaction']['outputs'][0],), None, None, UUID, options, priv_owner, pub_owner, vvk ) end_time = time.time() times.append((end_time-start_time)*1000) mean = numpy.mean(times) sd = numpy.std(times) print "[g] create_petition tx\t{:.10f}\t\t{:.10f}\t{}".format(mean, sd, RUNS) # check create_petition_tx = petition.create_petition( (init_tx['transaction']['outputs'][0],), None, None, UUID, options, priv_owner, pub_owner, vvk ) solution = transaction_to_solution(create_petition_tx) times = [] for i in range(RUNS): start_time = time.time() petition.contract.checkers['create_petition']( solution['inputs'], solution['referenceInputs'], solution['parameters'], solution['outputs'], solution['returns'], solution['dependencies'], ) end_time = time.time() times.append((end_time-start_time)*1000) mean = numpy.mean(times) sd = numpy.std(times) print "[c] create_petition tx\t{:.10f}\t\t{:.10f}\t{}".format(mean, sd, RUNS) # == sign =============== # gen old_petition = create_petition_tx['transaction']['outputs'][1] old_list = create_petition_tx['transaction']['outputs'][2] # some crypto # ------------------------------------ (priv_signer, pub_signer) = elgamal_keygen(bp_params) m = priv_signer (cm, c, proof_s) = prepare_blind_sign(bp_params, m, pub_signer) enc_sigs = [blind_sign(bp_params, ski, cm, c, pub_signer, proof_s) for ski in sk] (h, enc_epsilon) = zip(*enc_sigs) sigs = [(h[0], elgamal_dec(bp_params, priv_signer, enc)) for enc in enc_epsilon] sig = aggregate_th_sign(bp_params, sigs) sig = randomize(bp_params, sig) (kappa, nu, proof_v) = show_coconut_petition(bp_params, vvk, m, UUID) #print(coconut_petition_verify(bp_params, vvk, kappa, sig, proof_v, UUID, nu)) # ------------------------------------ times = [] for i in range(RUNS): start_time = time.time() petition.sign( (old_petition, old_list), None, (dumps([1, 0]),), priv_signer, sig, vvk ) end_time = time.time() times.append((end_time-start_time)*1000) mean = numpy.mean(times) sd = numpy.std(times) print "[g] sign tx\t\t{:.10f}\t\t{:.10f}\t{}".format(mean, sd, RUNS) # check sign_tx = petition.sign( (old_petition, old_list), None, (dumps([1, 0]),), priv_signer, sig, vvk ) solution = transaction_to_solution(sign_tx) times = [] for i in range(RUNS): start_time = time.time() petition.contract.checkers['sign']( solution['inputs'], solution['referenceInputs'], solution['parameters'], solution['outputs'], solution['returns'], solution['dependencies'], ) end_time = time.time() times.append((end_time-start_time)*1000) mean = numpy.mean(times) sd = numpy.std(times) print "[c] sign tx\t\t{:.10f}\t\t{:.10f}\t{}".format(mean, sd, RUNS) '''
sk_owners = [poly_eval(v, i) % o for i in range(1, n_owners + 1)] pk_owners = [xi * g for xi in sk_owners] l = lagrange_basis(range(1, t_owners + 1), o, 0) aggr_pk_owner = ec_sum([l[i] * pk_owners[i] for i in range(t_owners)]) ## coconut parameters t, n = 4, 5 # threshold and total number of authorities bp_params = setup() # bp system's parameters (sk, vk) = ttp_keygen(bp_params, t, n) # signers keys aggr_vk = agg_key(bp_params, vk, threshold=True) #################################################################### # create all transactions #################################################################### # init init_tx = petition.init() token = init_tx['transaction']['outputs'][0] # create_petition create_petition_tx = petition.create_petition( (token, ), None, None, UUID, options, sk_owners[0], aggr_pk_owner, t_owners, n_owners, aggr_vk) old_petition = create_petition_tx['transaction']['outputs'][1] old_list = create_petition_tx['transaction']['outputs'][2] # sign (d, gamma) = elgamal_keygen(bp_params) private_m = [d] Lambda = prepare_blind_sign(bp_params, gamma, private_m) sigs_tilde = [blind_sign(bp_params, ski, gamma, Lambda) for ski in sk] sigs = [unblind(bp_params, sigma_tilde, d) for sigma_tilde in sigs_tilde]