@@ -6,6 +6,7 @@ module Bulletproofs.InnerProductProof.Prover (
6
6
7
7
import Protolude
8
8
9
+ import Control.Exception (assert )
9
10
import qualified Data.List as L
10
11
import qualified Data.Map as Map
11
12
@@ -47,17 +48,13 @@ generateProof'
47
48
= case (ls, rs) of
48
49
([] , [] ) -> InnerProductProof [] [] 0 0
49
50
([l], [r]) -> InnerProductProof (reverse lCommits) (reverse rCommits) l r
50
- _ -> if | not checkLGs -> panic " Error in: l' * Gs' == l * Gs + x^2 * A_L + x^(-2) * A_R"
51
- | not checkRHs -> panic " Error in: r' * Hs' == r * Hs + x^2 * B_L + x^(-2) * B_R"
52
- | not checkLBs -> panic " Error in: l' * r' == l * r + x^2 * (lsLeft * rsRight) + x^-2 * (lsRight * rsLeft)"
53
- | not checkC -> panic " Error in: C == zG + aG + bH'"
54
- | not checkC' -> panic " Error in: C' = C + x^2 L + x^-2 R == z'G + a'G + b'H'"
55
- | otherwise -> generateProof'
56
- InnerProductBase { bGs = gs'', bHs = hs'', bH = bH }
57
- commitmentLR'
58
- InnerProductWitness { ls = ls', rs = rs' }
59
- (lCommit: lCommits)
60
- (rCommit: rCommits)
51
+ _ -> assert (checkLGs && checkRHs && checkLBs && checkC && checkC')
52
+ $ generateProof'
53
+ InnerProductBase { bGs = gs'', bHs = hs'', bH = bH }
54
+ commitmentLR'
55
+ InnerProductWitness { ls = ls', rs = rs' }
56
+ (lCommit: lCommits)
57
+ (rCommit: rCommits)
61
58
where
62
59
n' = fromIntegral $ length ls
63
60
nPrime = n' `div` 2
@@ -70,15 +67,15 @@ generateProof'
70
67
cL = dot lsLeft rsRight
71
68
cR = dot lsRight rsLeft
72
69
73
- lCommit = foldl' addP Crypto. PointO ( zipWith mulP lsLeft gsRight)
70
+ lCommit = sumExps lsLeft gsRight
74
71
`addP`
75
- foldl' addP Crypto. PointO ( zipWith mulP rsRight hsLeft)
72
+ sumExps rsRight hsLeft
76
73
`addP`
77
74
(cL `mulP` bH)
78
75
79
- rCommit = foldl' addP Crypto. PointO ( zipWith mulP lsRight gsLeft)
76
+ rCommit = sumExps lsRight gsLeft
80
77
`addP`
81
- foldl' addP Crypto. PointO ( zipWith mulP rsLeft hsRight)
78
+ sumExps rsLeft hsRight
82
79
`addP`
83
80
(cR `mulP` bH)
84
81
@@ -88,8 +85,8 @@ generateProof'
88
85
xs = replicate nPrime x
89
86
xsInv = replicate nPrime xInv
90
87
91
- gs'' = zipWith addP ( zipWith mulP xsInv gsLeft) (zipWith mulP xs gsRight)
92
- hs'' = zipWith addP ( zipWith mulP xs hsLeft) (zipWith mulP xsInv hsRight)
88
+ gs'' = zipWith ( \ (exp0, pt0) (exp1, pt1) -> addTwoMulP exp0 pt0 exp1 pt1) ( zip xsInv gsLeft) (zip xs gsRight)
89
+ hs'' = zipWith ( \ (exp0, pt0) (exp1, pt1) -> addTwoMulP exp0 pt0 exp1 pt1) ( zip xs hsLeft) (zip xsInv hsRight)
93
90
94
91
ls' = ((*) x <$> lsLeft) ^+^ ((*) xInv <$> lsRight)
95
92
rs' = ((*) xInv <$> rsLeft) ^+^ ((*) x <$> rsRight)
@@ -105,25 +102,25 @@ generateProof'
105
102
-- Checks
106
103
-----------------------------
107
104
108
- aL' = foldl' addP Crypto. PointO ( zipWith mulP lsLeft gsRight)
109
- aR' = foldl' addP Crypto. PointO ( zipWith mulP lsRight gsLeft)
105
+ aL' = sumExps lsLeft gsRight
106
+ aR' = sumExps lsRight gsLeft
110
107
111
- bL' = foldl' addP Crypto. PointO ( zipWith mulP rsLeft hsRight)
112
- bR' = foldl' addP Crypto. PointO ( zipWith mulP rsRight hsLeft)
108
+ bL' = sumExps rsLeft hsRight
109
+ bR' = sumExps rsRight hsLeft
113
110
114
111
z = dot ls rs
115
112
z' = dot ls' rs'
116
113
117
- lGs = foldl' addP Crypto. PointO ( zipWith mulP ls bGs)
118
- rHs = foldl' addP Crypto. PointO ( zipWith mulP rs bHs)
114
+ lGs = sumExps ls bGs
115
+ rHs = sumExps rs bHs
119
116
120
- lGs' = foldl' addP Crypto. PointO ( zipWith mulP ls' gs'')
121
- rHs' = foldl' addP Crypto. PointO ( zipWith mulP rs' hs'')
117
+ lGs' = sumExps ls' gs''
118
+ rHs' = sumExps rs' hs''
122
119
123
120
checkLGs
124
121
= lGs'
125
122
==
126
- foldl' addP Crypto. PointO ( zipWith mulP ls bGs)
123
+ sumExps ls bGs
127
124
`addP`
128
125
(fSquare x `mulP` aL')
129
126
`addP`
@@ -132,7 +129,7 @@ generateProof'
132
129
checkRHs
133
130
= rHs'
134
131
==
135
- foldl' addP Crypto. PointO ( zipWith mulP rs bHs)
132
+ sumExps rs bHs
136
133
`addP`
137
134
(fSquare x `mulP` bR')
138
135
`addP`
@@ -160,5 +157,3 @@ generateProof'
160
157
lGs'
161
158
`addP`
162
159
rHs'
163
-
164
-
0 commit comments