-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
85 lines (74 loc) · 1.83 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
package main
import (
"time"
"github.com/consensys/gnark-crypto/ecc"
"github.com/consensys/gnark/backend/groth16"
"github.com/consensys/gnark/frontend"
"github.com/consensys/gnark/frontend/cs/r1cs"
rln "github.com/rymnc/gnark-rln/rln"
)
func main() {
identityPathIndex := [20]frontend.Variable{
1,
1,
1,
0,
1,
0,
1,
0,
1,
0,
1,
0,
0,
0,
0,
0,
1,
1,
1,
0,
}
cs, err := frontend.Compile(ecc.BN254.ScalarField(), r1cs.NewBuilder, &rln.RlnCircuit{})
if err != nil {
panic(err)
}
pk, vk, err := groth16.Setup(cs)
if err != nil {
panic(err)
}
assignment := &rln.RlnCircuit{
X: frontend.Variable(rln.GetBn254X()),
ExternalNullifier: frontend.Variable(rln.GetBn254ExternalNullifier()),
IdentitySecret: frontend.Variable(rln.GetBn254IdentitySecret()),
MessageId: frontend.Variable(1),
UserMessageLimit: frontend.Variable(100),
PathElements: rln.GetBn254PathElements(),
IdentityPathIndex: identityPathIndex,
Y: frontend.Variable(rln.GetBn254Y()),
Root: frontend.Variable(rln.GetBn254Root()),
Nullifier: frontend.Variable(rln.GetBn254Nullifier()),
}
witness, _ := frontend.NewWitness(assignment, ecc.BN254.ScalarField())
startTime := time.Now().UnixMilli()
proof, err := groth16.Prove(cs, pk, witness)
endTime := time.Now().UnixMilli()
elapsed := endTime - startTime
print("Proving time: ", elapsed, "ms.\n")
if err != nil {
panic(err)
}
verifyWitness, err := frontend.NewWitness(assignment, ecc.BN254.ScalarField(), frontend.PublicOnly())
if err != nil {
panic(err)
}
startTime = time.Now().UnixMilli()
err = groth16.Verify(proof, vk, verifyWitness)
endTime = time.Now().UnixMilli()
elapsed = endTime - startTime
print("Verification time: ", elapsed, "ms.\n")
if err != nil {
print(err.Error())
}
}