示例#1
0
 def test_all(self):
     master_keys, check_keys = equality_test.setup(5)
     test_token = equality_test.gen_token(master_keys, [3, 3, 3, 3, 3], 5)
     identifier = 5
     check1 = equality_test.encrypt(check_keys[0], identifier, 3)
     check2 = equality_test.encrypt(check_keys[1], identifier, 3)
     check3 = equality_test.encrypt(check_keys[2], identifier, 3)
     check4 = equality_test.encrypt(check_keys[3], identifier, 3)
     check5 = equality_test.encrypt(check_keys[4], identifier, 3)
     self.assertTrue(
         equality_test.test(test_token, 5, check1, check2, check3, check4,
                            check5))
示例#2
0
 def non_equal_checks(self):
     master_keys, check_keys = equality_test.setup(5)
     test_token = equality_test.gen_token(master_keys, [3, 3, 3, 3, 3], 5)
     identifier = 5
     check1 = equality_test.encrypt(check_keys[0], identifier, 3)
     check2 = equality_test.encrypt(check_keys[1], identifier, 3)
     check3 = equality_test.encrypt(check_keys[2], identifier,
                                    5)  # check not same as required
     check4 = equality_test.encrypt(check_keys[3], identifier, 3)
     check5 = equality_test.encrypt(check_keys[4], identifier, 3)
     self.assertFalse(
         equality_test.test(test_token, 5, check1, check2, check3, check4,
                            check5))
示例#3
0
    gas_use_deploy = gas_usage(contract_trans, web3)
    gas_max_deploy = max_gas_usage(contract_trans, web3)
    verbose_print("Gas used to deploy n=", n, "contract: ", gas_use_deploy)
    print("Gas used to deploy n=", n, "contract: ", gas_max_deploy, "   maxed")

    compiled = compile_files([contract_file], "--optimized")
    compiledCode = compiled[contract_name]
    contract_instance = web3.eth.contract(contractAddr,
                                          abi=compiledCode['abi'])

    # test contract gas usage
    # generate g1 points
    rand = random.SystemRandom()
    identifier = rand.randint(1, fast_pairing.curve_order)
    checks = [
        equality_test.encrypt(check_keys[x], identifier, 3) for x in range(n)
    ]
    listG1 = []

    for x in range(n):
        listG1.append(checks[x]['g1_mul_prp_add_ident_hash'])

    for x in range(n):
        listG1.append(checks[x]['r_x_mul'])

    listG1.append(checks[0]['hash_ident'])

    # Invert points
    for x in range(len(listG1)):
        if x >= (len(listG1) // 2):
            listG1[x] = fast_pairing.neg(listG1[x])
    verbose = True
    verbose_print = print if verbose else lambda *a, **k: None
    #  1, 2, 3, 4, 5, 10, 15, 20
    print("Number of checks, gas usage (zero-bytes compensated)")
    # [1, 2, 3, 4, 5, 10, 15, 20]
    # 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15
    for n in [6, 7, 8, 9, 10]:
        # Generate values from EqualityTest
        master_keys, check_keys = equality_test.setup(n)
        rand = random.SystemRandom()
        token_accepts = [rand.randint(1, 30) for _ in range(n)]
        test_token = equality_test.gen_token(master_keys, token_accepts, n)

        identifier = 5
        checks = [
            equality_test.encrypt(check_keys[x], identifier, token_accepts[x])
            for x in range(n)
        ]
        listG1 = []
        listG2 = []

        for x in range(n):
            listG1.append(checks[x]['g1_mul_prp_add_ident_hash'])
            listG2.append(test_token[0][x]['u_multiplied'])
            assert fast_pairing.is_on_curve(test_token[0][x]['u_multiplied'],
                                            fast_pairing.b2)

        for x in range(n):
            listG1.append(checks[x]['r_x_mul'])
            listG2.append(test_token[0][x]['alpha_mul_g2_mul_prp'])
            assert fast_pairing.is_on_curve(