Skip to content

Commit a7f17bc

Browse files
author
Alex E
committed
[FEAT] better test
1 parent 6dbf451 commit a7f17bc

File tree

2 files changed

+34
-4
lines changed

2 files changed

+34
-4
lines changed

gnark/libraries/core_test.go

Lines changed: 34 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import (
99
aes_v2 "gnark-symmetric-crypto/circuits/aesV2"
1010
"gnark-symmetric-crypto/circuits/toprf"
1111
prover "gnark-symmetric-crypto/libraries/prover/impl"
12+
oprf2 "gnark-symmetric-crypto/libraries/prover/oprf"
1213
verifier "gnark-symmetric-crypto/libraries/verifier/impl"
1314
"gnark-symmetric-crypto/libraries/verifier/oprf"
1415
"gnark-symmetric-crypto/utils"
@@ -308,7 +309,28 @@ func TestFullChaCha20OPRF(t *testing.T) {
308309
assert.NoError(err)
309310
}
310311

311-
out, err := utils.TOPRFFinalize(idxs, elements, req.SecretElements, req.Mask)
312+
finReq := &oprf2.InputTOPRFFinalizeParams{
313+
ServerPublicKey: shares.PublicKey,
314+
Request: &oprf2.OPRFRequest{
315+
Mask: req.Mask.Bytes(),
316+
MaskedData: req.MaskedData.Marshal(),
317+
SecretElements: [][]byte{req.SecretElements[0].Bytes(), req.SecretElements[1].Bytes()},
318+
},
319+
Responses: []*oprf2.OPRFResponse{
320+
{
321+
Index: responses[0].Index,
322+
PublicKeyShare: responses[0].PublicKeyShare,
323+
Evaluated: responses[0].Evaluated,
324+
C: responses[0].C,
325+
R: responses[0].R,
326+
},
327+
},
328+
}
329+
330+
finReqJSON, _ := json.Marshal(finReq)
331+
finResp := oprf2.TOPRFFinalize(finReqJSON)
332+
var out *oprf2.OutputOPRFResponseParams
333+
err = json.Unmarshal(finResp, &out)
312334
assert.NoError(err)
313335

314336
inputParams := &prover.InputParams{
@@ -322,7 +344,7 @@ func TestFullChaCha20OPRF(t *testing.T) {
322344
Len: uint32(len([]byte(email))),
323345
Mask: req.Mask.Bytes(),
324346
DomainSeparator: []byte(domainSeparator),
325-
Output: out.Bytes(),
347+
Output: out.Output,
326348
Responses: responses,
327349
},
328350
}
@@ -355,7 +377,7 @@ func TestFullChaCha20OPRF(t *testing.T) {
355377
Pos: pos,
356378
Len: uint32(len([]byte(email))),
357379
DomainSeparator: []byte(domainSeparator),
358-
Output: out.Bytes(),
380+
Output: out.Output,
359381
Responses: verifyResponses,
360382
},
361383
}
@@ -713,6 +735,15 @@ func Benchmark_ProveChachaOPRF(b *testing.B) {
713735
b.ReportAllocs()
714736
}
715737

738+
func BenchmarkTOPRFFinalize(b *testing.B) {
739+
b.ResetTimer()
740+
b.ReportAllocs()
741+
params := []byte(`{"serverPublicKey":"1AsWETKEjyyP/KKc8VXeASqo67rPp4ghI+ckN4P+hpY=","request":{"mask":"ExSgc7SIf8Sdp79pAWLapP4Dy4f2/pBra1EUflkxxA==","maskedData":"Lhz/ZIkMjs/LjDmPKZ3+HcO7PEW3+9g7oEuPNVs0o60=","secretElements":["bW9jLmxpYW1lQHRzZXQ=",""]},"responses":[{"index":1,"publicKeyShare":"1AsWETKEjyyP/KKc8VXeASqo67rPp4ghI+ckN4P+hpY=","evaluated":"+6zvgjZXtSYawia63IQoLM9pHa2Mru5W0iz7nfG1+ho=","c":"DeuKN5pxLeBZmshi2qgyb71gGBwY0o/UzGVYuHxvFI0=","r":"D3d9qGrXgMCannDhD99V7EkIpy/hhpCm/kzvhvp+3A=="}]}`)
742+
for i := 0; i < b.N; i++ {
743+
oprf2.TOPRFFinalize(params)
744+
}
745+
}
746+
716747
func fetchFile(keyName string) ([]byte, error) {
717748
f, err := os.ReadFile("../../resources/gnark/" + keyName)
718749
if err != nil {

gnark/libraries/prover/impl/library.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,6 @@ func InitAlgorithm(algorithmID uint8, provingKey []byte, r1csData []byte) (res b
9797
proverParams.initLock.Lock()
9898
defer proverParams.initLock.Unlock()
9999
if proverParams.initDone {
100-
fmt.Println("Algorithm already initialized", alg)
101100
return true
102101
}
103102

0 commit comments

Comments
 (0)