示例#1
0
 def test_batch_2_m_1_n_4(self):
     M = 1
     N = 4
     data = [[Scalar(random.randint(0, 2**N - 1)),
              random_scalar()] for i in range(M)]
     proof1 = pybullet.prove(data, N)
     data = [[Scalar(random.randint(0, 2**N - 1)),
              random_scalar()] for i in range(M)]
     proof2 = pybullet.prove(data, N)
     pybullet.verify([proof1, proof2], N)
示例#2
0
 def test_invalid_batch_2_m_1_2_n_4(self):
     M = 1
     N = 4
     data = [[Scalar(random.randint(0,2**N-1)),random_scalar()] for i in range(M)]
     proof1 = pybullet.prove(data,N)
     M = 2
     data = [[Scalar(random.randint(2**N,2**(N+1)-1)),random_scalar()] for i in range(M)]
     proof2 = pybullet.prove(data,N)
     with self.assertRaises(ArithmeticError):
         pybullet.verify([proof1,proof2],N)
示例#3
0
 def test_invalid_value(self):
     M = 1
     N = 4
     data = [[
         Scalar(random.randint(2**N, 2**(N + 1) - 1)),
         random_scalar()
     ]]
     with self.assertRaises(ArithmeticError):
         pybullet.verify([pybullet.prove(data, N)], N)
示例#4
0
    def __init__(self, coins_in, l, dest, v, f):
        # Sanity checks
        for i in l:
            if not i < len(coins_in) or not i >= 0:
                raise IndexError('Spent coin index out of bounds!')
            if coins_in[i].p is None:
                raise ValueError('Spent coin is not recovered!')
        if len(dest) == 0:
            raise ValueError('No output coins specified!')
        if not len(dest) == len(v):
            raise TypeError('Destination/value mismatch!')

        # Generate output coins
        coins_out = []
        r = []  # output coin masks
        for i in range(len(dest)):
            #r.append(random_scalar())
            r.append(Scalar(5))
            coins_out.append(Coin(v[i], dest[i][0], dest[i][1], r[i], i))

        # Generate range proof
        range_proof = pybullet.prove([[v[i], coins_out[i].mask]
                                      for i in range(len(dest))], BITS)

        # Generate balance proof secret, accounting for fee
        d = Scalar(0)
        for i in range(len(l)):
            d += coins_in[l[i]].mask
        for i in range(len(coins_out)):
            d -= coins_out[i].mask

        # Generate spend proof
        spend_proof = spend.prove([coin.P for coin in coins_in],
                                  [coin.C for coin in coins_in], l,
                                  [coins_in[l[i]].v for i in range(len(l))],
                                  [coins_in[l[i]].mask for i in range(len(l))],
                                  [coins_in[l[i]].p for i in range(len(l))], d,
                                  seed, aux1, aux2)

        self.coins_in = coins_in
        self.coins_out = coins_out
        self.range_proof = range_proof
        self.spend_proof = spend_proof
        self.f = f
示例#5
0
 def test_prove_verify_m_2_n_4(self):
     M = 2
     N = 4
     data = [[Scalar(random.randint(0,2**N-1)),random_scalar()] for i in range(M)]
     pybullet.verify([pybullet.prove(data,N)],N)