示例#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))
示例#2
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))
示例#3
0
import unittest

from ethsnarks.mimc import mimc_hash
from ethsnarks.field import FQ
from ethsnarks.utils import native_lib_path
from ethsnarks.merkletree import MerkleTree

from mixer import Mixer
from hashlib import sha256

NATIVE_LIB_PATH = native_lib_path('../.build/libmixer')
VK_PATH = '../.keys/mixer.vk.json'
PK_PATH = '../.keys/mixer.pk.raw'


def to_hex(intValue):
    return "{0:#0{1}x}".format(intValue, 66)


def get_sha256_hash(left, right):
    binput = bytes.fromhex(left[2:] + right[2:])
    output = sha256(binput).hexdigest()
    list_output = list(output)
    list_output[0] = '0'
    return '0x' + "".join(list_output)


class TestMixer(unittest.TestCase):
    def test_make_proof(self):
        wrapper = Mixer(NATIVE_LIB_PATH, VK_PATH, PK_PATH)
        tree_depth = wrapper.tree_depth
示例#4
0
import unittest
from binascii import hexlify
from hashlib import sha256
from os import urandom

from ethsnarks.mod.hashpreimage import HashPreimage
from ethsnarks.utils import libsnark2python, native_lib_path


VK_FILENAME = '.keys/hpi.vk.json'
PK_FILENAME = '.keys/hpi.pk.raw'
SO_FILENAME = native_lib_path('build/src/libhashpreimage')


class HashPreimageTests(unittest.TestCase):
    def test_prove_verify(self):
        hpi = HashPreimage(SO_FILENAME, VK_FILENAME, PK_FILENAME)
        preimage = urandom(64)
        proof = hpi.prove(preimage)

        # Verify the proof input matches the expected value
        postimage = sha256(preimage).digest()
        inputs = libsnark2python(proof.input)
        self.assertEqual(inputs[0], '0x' + hexlify(postimage).decode('ascii'))

        # Ensure proof verifies
        self.assertTrue(hpi.verify(proof))

        # TODO: flip a bit in the proof input, verify it doesn't verify
        proof.input[0] -= 1
        self.assertFalse(hpi.verify(proof))
import unittest
from binascii import hexlify
from hashlib import sha256
from os import urandom

from hashpreimage import HashPreimage
from ethsnarks.utils import libsnark2python, native_lib_path

VK_FILENAME = '../.keys/hashpreimage.vk.json'
PK_FILENAME = '../.keys/hashpreimage.pk.raw'
SO_FILENAME = native_lib_path('../.build/libhashpreimage')


class HashPreimageTests(unittest.TestCase):
    def test_prove_verify(self):
        hpi = HashPreimage(SO_FILENAME, VK_FILENAME, PK_FILENAME)
        preimage = urandom(64)
        proof = hpi.prove(preimage)

        # Verify the proof input matches the expected value
        postimage = sha256(preimage).digest()
        inputs = libsnark2python(proof.input)
        self.assertEqual(inputs[0], '0x' + hexlify(postimage).decode('ascii'))

        # Ensure proof verifies
        self.assertTrue(hpi.verify(proof))

        # TODO: flip a bit in the proof input, verify it doesn't verify
        proof.input[0] -= 1
        self.assertFalse(hpi.verify(proof))
示例#6
0
import unittest

from ethsnarks.longsight import random_element, LongsightL12p5_MP
from ethsnarks.utils import native_lib_path
from ethsnarks.mod.miximus import Miximus
from ethsnarks.merkletree import MerkleTree

NATIVE_LIB_PATH = native_lib_path('build/src/libmiximus')
VK_PATH = 'zksnark_element/miximus.vk.json'
PK_PATH = 'zksnark_element/miximus.pk.raw'


class TestMiximus(unittest.TestCase):
    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
示例#7
0
import hashlib
import unittest

from ethsnarks.field import FQ
from ethsnarks.mimc import mimc_encrypt
from ethsnarks.utils import native_lib_path
from ethsnarks.merkletree2 import merkle_root
from contingent import Contingent

NATIVE_LIB_PATH = native_lib_path('../.build/libcontingent')
VK_PATH = '../.keys/contingent.vk.json'
PK_PATH = '../.keys/contingent.pk.raw'
PROOF_PATH = '../.keys/contingent.proof.json'


class TestContingent(unittest.TestCase):
    def test_make_proof(self):
        num_blocks = 32

        wrapper = Contingent(NATIVE_LIB_PATH, num_blocks)

        # Generate proving and verification keys
        result = wrapper.genkeys(PK_PATH, VK_PATH)
        self.assertTrue(result == 0)

        print('Keygen done!')

        plaintext = [int(FQ.random()) for n in range(0, num_blocks)]
        plaintext_root = merkle_root(plaintext)
        key = int(FQ.random())
        key_bytes = key.to_bytes(32, 'little')
示例#8
0
import unittest

from ethsnarks.field import FQ
from ethsnarks.mimc import mimc_hash
from ethsnarks.utils import native_lib_path
from ethsnarks.merkletree import MerkleTree
from ssles import Ssles

NATIVE_LIB_PATH = native_lib_path('../.build/libssles')
VK_PATH = '../.keys/ssles.vk.json'
PK_PATH = '../.keys/ssles.pk.raw'


class TestSsles(unittest.TestCase):
    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)