Пример #1
0
        def test_add_element(self):
                n, A0, S = setup()

                x0 = secrets.randbelow(pow(2, 256))
                x1 = secrets.randbelow(pow(2, 256))

                # first addition
                A1 = add(A0, S, x0, n)
                nonce = S[x0]

                proof = prove_membership(A0, S, x0, n)
                self.assertEqual(len(S), 1)
                self.assertEqual(A0, proof)
                self.assertTrue(verify_membership(A1, x0, nonce, proof, n))

                # second addition
                A2 = add(A1, S, x1, n)
                nonce = S[x1]

                proof = prove_membership(A0, S, x1, n)
                self.assertEqual(len(S), 2)
                self.assertEqual(A1, proof)
                self.assertTrue(verify_membership(A2, x1, nonce, proof, n))

                # delete
                A1_new = delete(A0, A2, S, x0, n)
                proof = prove_membership(A0, S, x1, n)
                proof_none = prove_membership(A0, S, x0, n)
                self.assertEqual(len(S), 1)
                self.assertEqual(proof_none, None)
                self.assertTrue(verify_membership(A1_new, x1, nonce, proof, n))
Пример #2
0
def test_mem_witness_up_on_delete(total_utxo_set_size_for_accumulator,
                                  delete_element_index):

    if delete_element_index >= total_utxo_set_size_for_accumulator:
        print("delete element index should smaller than total_utxo_set_size")

    print("total_utxo_set_size_for_accumulator =",
          total_utxo_set_size_for_accumulator)

    print("--> initialize and fill up accumulator state")
    n, A0, S, order = setup()
    elements_for_accumulator = create_random_list(
        total_utxo_set_size_for_accumulator)
    tik = time.time()
    A_post, _ = batch_add(A0, S, elements_for_accumulator, n)
    tok = time.time()
    print("<--   Done.", tok - tik)

    print("--> generate other element proof")
    tik = time.time()
    other_element_proofs = {}
    for i in range(len(elements_for_accumulator)):
        if i != delete_element_index:
            other_element_proofs[
                elements_for_accumulator[i]] = prove_membership(
                    A0, S, elements_for_accumulator[i], n)
    tok = time.time()
    print("<-- Done.", tok - tik)

    print("--> delete element and generate A_del accumulator value.")
    tik = time.time()
    delete_element = elements_for_accumulator[delete_element_index]
    A_del = delete(A0, A_post, S, delete_element, n)
    tok = time.time()
    print("<-- Done.", tok - tik)

    print("--> update proof on delete element")
    update_proofs = {}

    tik = time.time()
    for x, proof in other_element_proofs.items():
        update_proofs[x] = acc_del_mem_witness_update(x, proof, delete_element,
                                                      A_del, n)
    tok = time.time()
    print("<-- Done.", tok - tik)

    print("--> verify updated proof on delete element")
    tik = time.time()
    result = []
    for x, proof in update_proofs.items():
        result.append(verify_membership(A_del, x, S[x], proof, n))
    tok = time.time()
    print("<-- Done.", tok - tik)

    print("verify results:")
    print(result)
Пример #3
0
def test_witness_update_on_del_add(total_utxo_set_size_for_accumulator,
                                   delete_element_size, add_element_size):

    if delete_element_size >= total_utxo_set_size_for_accumulator:
        print("delete element size should smaller than total_utxo_set_size")

    print("total_utxo_set_size_for_accumulator =",
          total_utxo_set_size_for_accumulator)

    print("--> initialize and fill up accumulator state")
    n, A0, S = setup()
    elements_for_accumulator = create_random_list(
        total_utxo_set_size_for_accumulator)
    tik = time.time()
    A_post, _ = batch_add(A0, S, elements_for_accumulator, n)
    tok = time.time()
    print("<--   Done.", tok - tik)

    print("--> generate the last element proof")
    tik = time.time()
    last_element = elements_for_accumulator[-1]
    last_element_proof = prove_membership(A0, S, elements_for_accumulator[-1],
                                          n)
    tok = time.time()
    print("<-- Done.", tok - tik)

    print("--> delete elements")
    delete_elements = []
    for i in range(delete_element_size):
        delete_elements.append(elements_for_accumulator[i])
    A_post_del = batch_delete(A0, S, delete_elements, n)
    print("<--  Done.")

    print("--> witness update on batch delete")
    tik = time.time()
    new_proof_del = acc_batch_del_mem_witness_update(last_element,
                                                     last_element_proof,
                                                     delete_elements,
                                                     A_post_del, n)
    tok = time.time()
    print("<-- Done.", tok - tik)

    print("--> verify new proof")
    result = verify_membership(A_post_del, last_element, S[last_element],
                               new_proof_del, n)
    print("Done")
    print(result)

    elements_for_add = create_random_list(add_element_size)
    print("--> witness update on batch add")
    tik = time.time()
    acc_batch_add_witness_update(S, last_element, new_proof_del,
                                 elements_for_add, n)
    tok = time.time()
    print("<-- Done.", tok - tik)
Пример #4
0
        def test_create_all_membership_witnesses(self):
                n, A0, S = setup()

                elements_list = create_list(3)

                A1, nipoe = batch_add(A0, S, elements_list, n)
                witnesses = create_all_membership_witnesses(A0, S, n)

                elements_list = list(S.keys())  # this specific order is important
                for i, witness in enumerate(witnesses):
                        self.assertTrue(verify_membership(A1, elements_list[i], S[elements_list[i]], witness, n))
Пример #5
0
        def test_agg_mem_witnesses(self):
                n, A0, S = setup()

                elements_list = create_list(3)

                A1, nipoe = batch_add(A0, S, elements_list, n)
                witnesses = create_all_membership_witnesses(A0, S, n)

                elements_list = list(S.keys())  # this specific order is important
                for i, witness in enumerate(witnesses):
                        self.assertTrue(verify_membership(A1, elements_list[i], S[elements_list[i]], witness, n))

                nonces_list = [S[x] for x in elements_list]
                agg_wit, nipoe = aggregate_membership_witnesses(A1, witnesses, elements_list, nonces_list, n)

                is_valid = batch_verify_membership_with_NIPoE(nipoe[0], nipoe[1], agg_wit, elements_list, nonces_list, A1, n)
                self.assertTrue(is_valid)