Skip to content

Commit cc8b209

Browse files
author
Alex E
committed
[FEAT] Full refactor of gnark circuits which reuse code now,
Removed SecretData from required parameters because it's computed inside circuits
1 parent 9ae6cb4 commit cc8b209

31 files changed

+63
-46
lines changed

bin/gnark/linux-arm64-libprove.so

148 KB
Binary file not shown.

bin/gnark/linux-arm64-libverify.so

0 Bytes
Binary file not shown.

bin/gnark/linux-x86_64-libprove.so

24.1 KB
Binary file not shown.
0 Bytes
Binary file not shown.

gnark/circuits/aesV2_oprf/aes.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,5 @@ func (c *AESTOPRFCircuit) Define(api frontend.API) error {
3333
}
3434
}
3535

36-
c.TOPRF.SecretData = toprf.ExtractSecretElements(api, outBits, c.Bitmask[:], c.Len)
37-
38-
return toprf.VerifyTOPRF(api, &c.TOPRF)
36+
return toprf.VerifyTOPRF(api, &c.TOPRF, toprf.ExtractSecretElements(api, outBits, c.Bitmask[:], c.Len))
3937
}

gnark/circuits/aesV2_oprf/aes128_test.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,7 @@ func TestAES128(t *testing.T) {
2525

2626
secretStr := "00000000001111111111000000000011000000000011111111110000000000" // max 62 bytes
2727
secretBytes := []byte(secretStr)
28-
d, err := toprf.PrepareTestData(secretStr, "reclaim")
29-
assert.NoError(err)
28+
d, _ := toprf.PrepareTestData(secretStr, "reclaim")
3029

3130
pos := 18
3231
Counter := 12345
@@ -79,7 +78,6 @@ func createWitness(d *toprf.Params, bKey []uint8, bNonce []uint8, counter int, c
7978
Out: [aes_v2.BLOCKS * 16]frontend.Variable{},
8079
Len: l,
8180
TOPRF: toprf.Params{
82-
SecretData: [2]frontend.Variable{0, 0}, // will be rewritten inside
8381
Mask: d.Mask,
8482
DomainSeparator: d.DomainSeparator,
8583
Responses: d.Responses,

gnark/circuits/aesV2_oprf/aes256_test.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,7 @@ func TestAES256(t *testing.T) {
2525

2626
secretStr := "00000000001111111111000000000011" // max 62 bytes
2727
secretBytes := []byte(secretStr)
28-
d, err := toprf.PrepareTestData(secretStr, "reclaim")
29-
assert.NoError(err)
28+
d, _ := toprf.PrepareTestData(secretStr, "reclaim")
3029

3130
pos := 30
3231
Counter := 12345
@@ -68,7 +67,6 @@ func createWitness256(d *toprf.Params, bKey []uint8, bNonce []uint8, counter int
6867
Out: [aes_v2.BLOCKS * 16]frontend.Variable{},
6968
Len: l,
7069
TOPRF: toprf.Params{
71-
SecretData: [2]frontend.Variable{0, 0}, // will be rewritten inside
7270
Mask: d.Mask,
7371
DomainSeparator: d.DomainSeparator,
7472
Responses: d.Responses,
Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,5 @@ func (c *ChachaTOPRFCircuit) Define(api frontend.API) error {
3535
}
3636
}
3737

38-
c.TOPRF.SecretData = toprf.ExtractSecretElements(api, outBits, c.Bitmask[:], c.Len)
39-
40-
return toprf.VerifyTOPRF(api, &c.TOPRF)
38+
return toprf.VerifyTOPRF(api, &c.TOPRF, toprf.ExtractSecretElements(api, outBits, c.Bitmask[:], c.Len))
4139
}

gnark/circuits/chachaV3_oprf/chacha_test.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,7 @@ func TestCipher(t *testing.T) {
4141
cipher.SetCounter(uint32(counter))
4242
cipher.XORKeyStream(ciphertext, plaintext)
4343

44-
d, err := toprf.PrepareTestData(secretStr, "reclaim")
45-
assert.NoError(err)
44+
d, _ := toprf.PrepareTestData(secretStr, "reclaim")
4645

4746
witness := createWitness(d, bKey, bNonce, counter, ciphertext, plaintext, pos, len(secretBytes))
4847

@@ -74,7 +73,6 @@ func createWitness(d *toprf.Params, bKey []uint8, bNonce []uint8, counter int, c
7473
witness := ChachaTOPRFCircuit{
7574
Len: len,
7675
TOPRF: toprf.Params{
77-
SecretData: [2]frontend.Variable{0, 0}, // will be rewritten inside
7876
Mask: d.Mask,
7977
DomainSeparator: d.DomainSeparator,
8078
Responses: d.Responses,

gnark/circuits/toprf/testdata.go

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,10 @@ type TestData struct {
2525
Proof *Proof
2626
}
2727

28-
func PrepareTestData(secretData string, domainSeparator string) (*Params, error) {
28+
func PrepareTestData(secretData string, domainSeparator string) (*Params, [2]frontend.Variable) {
2929
req, err := utils.OPRFGenerateRequest([]byte(secretData), domainSeparator)
3030
if err != nil {
31-
return nil, err
31+
panic(err)
3232
}
3333

3434
// server secret
@@ -42,7 +42,7 @@ func PrepareTestData(secretData string, domainSeparator string) (*Params, error)
4242

4343
shares, err := utils.TOPRFCreateShares(nodes, threshold, sk)
4444
if err != nil {
45-
return nil, err
45+
panic(err)
4646
}
4747

4848
idxs := utils.PickRandomIndexes(nodes, threshold)
@@ -60,7 +60,7 @@ func PrepareTestData(secretData string, domainSeparator string) (*Params, error)
6060
var resp *utils.OPRFResponse
6161
resp, err = utils.OPRFEvaluate(shares[idx].PrivateKey, req.MaskedData)
6262
if err != nil {
63-
return nil, err
63+
panic(err)
6464
}
6565

6666
resps[i] = utils.OutPointToInPoint(resp.EvaluatedPoint)
@@ -74,16 +74,15 @@ func PrepareTestData(secretData string, domainSeparator string) (*Params, error)
7474
// without TOPRF
7575
resp, err := utils.OPRFEvaluate(sk, req.MaskedData)
7676
if err != nil {
77-
return nil, err
77+
panic(err)
7878
}
7979

8080
out, err := utils.OPRFFinalize(serverPublic, req, resp)
8181
if err != nil {
82-
return nil, err
82+
panic(err)
8383
}
8484

8585
data := &Params{
86-
SecretData: [2]frontend.Variable{req.SecretElements[0], req.SecretElements[1]},
8786
DomainSeparator: new(big.Int).SetBytes([]byte(domainSeparator)),
8887
Output: out,
8988
Mask: req.Mask,
@@ -95,5 +94,5 @@ func PrepareTestData(secretData string, domainSeparator string) (*Params, error)
9594
copy(data.C[:], cs)
9695
copy(data.R[:], rs)
9796

98-
return data, nil
97+
return data, [2]frontend.Variable{req.SecretElements[0], req.SecretElements[1]}
9998
}

0 commit comments

Comments
 (0)