Ejemplo n.º 1
0
 def test_verify_native(self):
     """Verify using fast native library"""
     vk = VerifyingKey.from_dict(VK_STATIC)
     proof = Proof.from_dict(PROOF_STATIC)
     wrapper = HashPreimage(native_lib_path('build/src/libhashpreimage'),
                            vk)
     self.assertTrue(wrapper.verify(proof))
Ejemplo n.º 2
0
    def test_proof_gen(self):
        leaves, nullifiers, sks = initMerkleTree(2)
        root, layers = genMerkelTree(tree_depth, leaves)
        signal_variables = sha256(str(1))
        external_nullifier = sha256("nomimatedSpokesPerson" + root +
                                    str(time.time()))
        signal1 = sha256({
            "NomimatedSpokesPersonFor": root,
            "candidate": "Candidate1"
        })
        proof = None

        with open('zksnark_element/vk.json', 'r') as handle:
            vk = VerifyingKey.from_dict(json.load(handle))

        for address, (nullifier, sk) in enumerate(zip(nullifiers, sks)):
            print("Generating witness")
            proof_data, proof_root = genWitness(leaves, nullifier, sk, signal1,
                                                signal_variables,
                                                external_nullifier, address,
                                                tree_depth, 0, PK_FILENAME)

            # Verify proof is correct
            proof = Proof.from_dict(proof_data)
            self.assertTrue(native_verify(vk.to_json(), proof.to_json()))

            # Verify modifying proof results in False state
            proof.input[n] -= 1
            self.assertFalse(native_verify(vk.to_json(), proof.to_json()))
            break
Ejemplo n.º 3
0
 def test_verify_python(self):
     # Verify using sloooow python implementation
     vk = VerifyingKey.from_dict(VK_STATIC)
     proof = Proof.from_dict(PROOF_STATIC)
     self.assertTrue(vk.verify(proof))
Ejemplo n.º 4
0
 def test_verify_native(self):
     """Verify using fast native library"""
     vk = NativeVerifier.from_dict(VK_STATIC)
     proof = Proof.from_dict(PROOF_STATIC)
     dll_path = native_lib_path('build/src/libethsnarks_verify')
     self.assertTrue(vk.verify(proof, dll_path))
Ejemplo n.º 5
0
 def test_verify_native(self):
     """Verify using fast native library"""
     vk = VerifyingKey.from_dict(VK_STATIC)
     proof = Proof.from_dict(PROOF_STATIC)
     self.assertTrue(native_verify(vk.to_json(), proof.to_json()))