@@ -10,6 +10,7 @@ import (
10
10
"math/big"
11
11
"time"
12
12
13
+ comet "github.com/unionlabs/cometbls/crypto/bn254"
13
14
curve "github.com/consensys/gnark-crypto/ecc/bn254"
14
15
"github.com/consensys/gnark-crypto/ecc/bn254/fr"
15
16
backend "github.com/consensys/gnark/backend/groth16"
@@ -155,25 +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
159
178
160
func commitmentsHash (proofCommitment curve.G1Affine ) fr.Element {
179
161
var buffer [64 ]byte
@@ -184,7 +166,7 @@ func commitmentsHash(proofCommitment curve.G1Affine) fr.Element {
184
166
y := proofCommitment .Y .Bytes ()
185
167
copy (buffer [32 :64 ], y [:])
186
168
187
- return hashToField (buffer [:])
169
+ return comet . HashToField (buffer [:])
188
170
}
189
171
190
172
func inputsHash (header ProverLightHeader , trustedValidatorsHash []byte ) fr.Element {
@@ -214,4 +196,4 @@ func inputsHash(header ProverLightHeader, trustedValidatorsHash []byte) fr.Eleme
214
196
var e fr.Element
215
197
e .SetBytes (hash [1 :])
216
198
return e
217
- }
199
+ }
0 commit comments