Exemplo n.º 1
0
    def test_make_proof(self):
        wrapper = Mixer(NATIVE_LIB_PATH, VK_PATH, PK_PATH)
        tree_depth = wrapper.tree_depth

        n_items = 2 << (tree_depth - 1)
        tree = MerkleTree(n_items)
        for n in range(0, 2):
            tree.append(int(FQ.random()))

        wallet_address = int(FQ.random())
        nullifier_secret = int(FQ.random())
        nullifier_hash = mimc_hash([nullifier_secret, nullifier_secret])
        leaf_hash = int(
            get_sha256_hash(to_hex(nullifier_secret), to_hex(wallet_address)),
            16)

        leaf_idx = tree.append(leaf_hash)
        self.assertEqual(leaf_idx, tree.index(leaf_hash))

        # Verify it exists in true
        leaf_proof = tree.proof(leaf_idx)
        self.assertTrue(leaf_proof.verify(tree.root))

        # Generate proof
        snark_proof = wrapper.prove(
            tree.root,
            wallet_address,
            nullifier_hash,
            nullifier_secret,
            # (index)_2 bits reversed, i.e. [LSB, ... , MSB]
            leaf_proof.address,
            leaf_proof.path)

        self.assertTrue(wrapper.verify(snark_proof))
Exemplo n.º 2
0
	def test_make_proof(self):
		n_items = 2<<28
		tree = MerkleTree(n_items)
		for n in range(0, 2):
			tree.append(int(FQ.random()))

		exthash = int(FQ.random())
		secret = int(FQ.random())
		leaf_hash = mimc_hash([secret])
		leaf_idx = tree.append(leaf_hash)
		self.assertEqual(leaf_idx, tree.index(leaf_hash))

		# Verify it exists in true
		leaf_proof = tree.proof(leaf_idx)
		self.assertTrue(leaf_proof.verify(tree.root))

		# Generate proof		
		wrapper = Miximus(NATIVE_LIB_PATH, VK_PATH, PK_PATH)
		tree_depth = wrapper.tree_depth
		snark_proof = wrapper.prove(
			tree.root,
			secret,
			exthash,
			leaf_proof.address,
			leaf_proof.path)

		self.assertTrue(wrapper.verify(snark_proof))
Exemplo n.º 3
0
    def test_make_proof(self):
        n_items = 2 << 28
        tree = MerkleTree(n_items)
        for n in range(0, 2):
            tree.append(random_element())

        exthash = random_element()
        nullifier = random_element()
        spend_preimage = random_element()
        spend_hash_IV = 0
        spend_hash = LongsightL12p5_MP([spend_preimage, nullifier],
                                       spend_hash_IV)
        leaf_hash_IV = 0
        leaf_hash = LongsightL12p5_MP([nullifier, spend_hash], leaf_hash_IV)
        leaf_idx = tree.append(leaf_hash)
        self.assertEqual(leaf_idx, tree.index(leaf_hash))

        # Verify it exists in true
        leaf_proof = tree.proof(leaf_idx)
        self.assertTrue(leaf_proof.verify(tree.root))

        # Generate proof
        wrapper = Miximus(NATIVE_LIB_PATH, VK_PATH, PK_PATH)
        tree_depth = wrapper.tree_depth
        snark_proof = wrapper.prove(tree.root, nullifier, spend_preimage,
                                    exthash, leaf_proof.address,
                                    leaf_proof.path)

        self.assertTrue(wrapper.verify(snark_proof))
Exemplo n.º 4
0
    def test_make_proof(self):
        n_items = 2 << 28
        tree = MerkleTree(n_items)
        for n in range(0, 2):
            tree.append(int(FQ.random()))

            exthash = int(FQ.random())
            prehash = int(FQ.random())
            secret = int(FQ.random())
            msg = int(FQ.random())
            leaf_hash = mimc_hash([secret])
            sig_msg_hash = mimc_hash([msg])
            leaf_idx = tree.append(leaf_hash)
            self.assertEqual(leaf_idx, tree.index(leaf_hash))

        # Verify it exists in true
        leaf_proof = tree.proof(leaf_idx)
        self.assertTrue(leaf_proof.verify(tree.root))
        self.assertTrue(prehash, sig_msg_hash)

        # Generate proof
        wrapper = Ssles(NATIVE_LIB_PATH, VK_PATH, PK_PATH)
        tree_depth = wrapper.tree_depth
        snark_proof = wrapper.prove(tree.root, secret, msg, exthash, prehash,
                                    leaf_proof.address, leaf_proof.path)

        self.assertTrue(wrapper.verify(snark_proof))

        if __name__ == "__main__":
            unittest.main()