-
Notifications
You must be signed in to change notification settings - Fork 0
/
product_decomposition.py
40 lines (29 loc) · 1.23 KB
/
product_decomposition.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
from dataclasses import dataclass
from typing import List
from bls import G1Point, G2Point, gt_eq, is_identity, pairing, G2Generator
from common import pairwise
# A product decomposition proof is capable of proving that one knows the
# product decomposition for a particular number without revealing said decomposition
@dataclass
class ProductDecompositionProof:
running_product: List[G1Point]
witnesses: List[G2Point]
def __init__(self, starting_point: G1Point):
assert is_identity(starting_point) == False
self.running_product = [starting_point]
self.witnesses = []
def current_product(self):
return self.running_product[-1]
def extend(self, product: G1Point, witness: G2Point):
self.running_product.append(product)
self.witnesses.append(witness)
def verify(self) -> bool:
acc_pairs = pairwise(self.running_product)
for pair, witness in zip(acc_pairs, self.witnesses):
prev_running_product = pair[0]
next_running_product = pair[1]
p1 = pairing(next_running_product, G2Generator)
p2 = pairing(prev_running_product, witness)
if gt_eq(p1, p2) == False:
return False
return True