@@ -15,6 +15,7 @@ import (
15
15
backend "github.com/consensys/gnark/backend/groth16"
16
16
backend_bn254 "github.com/consensys/gnark/backend/groth16/bn254"
17
17
"github.com/holiman/uint256"
18
+ comet "github.com/unionlabs/cometbls/crypto/bn254"
18
19
"golang.org/x/crypto/sha3"
19
20
)
20
21
@@ -155,26 +156,6 @@ func (zkp ZKP) Verify(trustedValidatorsHash []byte, header ProverLightHeader) er
155
156
return verifyingKey .CommitmentKey .Verify (zkp .ProofCommitment , zkp .ProofCommitmentPoK )
156
157
}
157
158
158
- func hashToField (msg []byte ) fr.Element {
159
- hmac := hmac .New (Hash , []byte (CometblsHMACKey ))
160
- hmac .Write (msg )
161
- modMinusOne := new (big.Int ).Sub (fr .Modulus (), big .NewInt (1 ))
162
- num := new (big.Int ).SetBytes (hmac .Sum (nil ))
163
- num .Mod (num , modMinusOne )
164
- num .Add (num , big .NewInt (1 ))
165
- val , overflow := uint256 .FromBig (num )
166
- if overflow {
167
- panic ("impossible; qed;" )
168
- }
169
- valBytes := val .Bytes32 ()
170
- var element fr.Element
171
- err := element .SetBytesCanonical (valBytes [:])
172
- if err != nil {
173
- panic ("impossible; qed;" )
174
- }
175
- return element
176
- }
177
-
178
159
func commitmentsHash (proofCommitment curve.G1Affine ) fr.Element {
179
160
var buffer [64 ]byte
180
161
@@ -184,7 +165,7 @@ func commitmentsHash(proofCommitment curve.G1Affine) fr.Element {
184
165
y := proofCommitment .Y .Bytes ()
185
166
copy (buffer [32 :64 ], y [:])
186
167
187
- return hashToField (buffer [:])
168
+ return comet . HashToField (buffer [:])
188
169
}
189
170
190
171
func inputsHash (header ProverLightHeader , trustedValidatorsHash []byte ) fr.Element {
@@ -214,4 +195,4 @@ func inputsHash(header ProverLightHeader, trustedValidatorsHash []byte) fr.Eleme
214
195
var e fr.Element
215
196
e .SetBytes (hash [1 :])
216
197
return e
217
- }
198
+ }
0 commit comments