1
- import { RLNProver , RLNVerifier , WithdrawProver , WithdrawVerifier } from " ../src/circuit-wrapper" ;
2
- import { rlnParams , withdrawParams } from " ./configs" ;
3
- import { fieldFactory , generateMerkleProof } from " ./utils" ;
4
- import poseidon from " poseidon-lite" ;
5
- import { DEFAULT_REGISTRY_TREE_DEPTH } from " ../src/registry" ;
1
+ import { RLNProver , RLNVerifier , WithdrawProver , WithdrawVerifier } from ' ../src/circuit-wrapper' ;
2
+ import { rlnParams , withdrawParams } from ' ./configs' ;
3
+ import { fieldFactory , generateMerkleProof } from ' ./utils' ;
4
+ import poseidon from ' poseidon-lite' ;
5
+ import { DEFAULT_REGISTRY_TREE_DEPTH } from ' ../src/registry' ;
6
6
7
7
// `userMessageLimit` is at most 16 bits
8
8
// Ref: https://github.com/Rate-Limiting-Nullifier/rln-circuits-v2/blob/b40dfa63b7b1248527d7ab417d0d9cf538cad93a/circuits/utils.circom#L36-L37
9
- const LIMIT_BIT_SIZE = 16
9
+ const LIMIT_BIT_SIZE = 16 ;
10
10
11
- describe ( " RLN" , function ( ) {
12
- const rlnIdentifier = fieldFactory ( )
13
- const rlnProver = new RLNProver ( rlnParams . wasmFilePath , rlnParams . finalZkeyPath )
14
- const rlnVerifier = new RLNVerifier ( rlnParams . verificationKey )
15
- const identitySecret = fieldFactory ( )
16
- const identityCommitment = poseidon ( [ identitySecret ] )
17
- const leaves = [ identityCommitment ]
18
- const userMessageLimit = ( BigInt ( 1 ) << BigInt ( LIMIT_BIT_SIZE ) ) - BigInt ( 1 )
19
- const messageId = BigInt ( 0 )
20
- const x = fieldFactory ( )
21
- const epoch = fieldFactory ( )
22
- const treeDepth = DEFAULT_REGISTRY_TREE_DEPTH
11
+ describe ( ' RLN' , function ( ) {
12
+ const rlnIdentifier = fieldFactory ( ) ;
13
+ const rlnProver = new RLNProver ( rlnParams . wasmFilePath , rlnParams . finalZkeyPath ) ;
14
+ const rlnVerifier = new RLNVerifier ( rlnParams . verificationKey ) ;
15
+ const identitySecret = fieldFactory ( ) ;
16
+ const identityCommitment = poseidon ( [ identitySecret ] ) ;
17
+ const leaves = [ identityCommitment ] ;
18
+ const userMessageLimit = ( BigInt ( 1 ) << BigInt ( LIMIT_BIT_SIZE ) ) - BigInt ( 1 ) ;
19
+ const messageId = BigInt ( 0 ) ;
20
+ const x = fieldFactory ( ) ;
21
+ const epoch = fieldFactory ( ) ;
22
+ const treeDepth = DEFAULT_REGISTRY_TREE_DEPTH ;
23
23
24
+ test ( 'should generate valid proof' , async function ( ) {
24
25
const m0 = performance . now ( ) ;
25
26
const merkleProof = generateMerkleProof ( rlnIdentifier , leaves , treeDepth , 0 ) ;
26
27
const m1 = performance . now ( ) ;
27
- const proof = await rlnProver . generateProof ( {
28
- rlnIdentifier,
29
- identitySecret,
30
- userMessageLimit,
31
- messageId,
32
- merkleProof,
33
- x,
28
+ const proof = await rlnProver . generateProof ( {
29
+ rlnIdentifier,
30
+ identitySecret,
31
+ userMessageLimit,
32
+ messageId,
33
+ merkleProof,
34
+ x,
34
35
epoch
35
36
} ) ;
36
37
const m2 = performance . now ( ) ;
@@ -40,17 +41,26 @@ describe("RLN", function () {
40
41
console . log ( `RLN proof generation: ${ m2 - m1 } ms` ) ;
41
42
console . log ( `RLN proof verification: ${ m3 - m2 } ms` ) ;
42
43
expect ( isValid ) . toBeTruthy ( ) ;
43
- } ) ;
44
+ } ) ;
44
45
} ) ;
45
46
46
- describe ( "Withdraw" , function ( ) {
47
- const withdrawProver = new WithdrawProver ( withdrawParams . wasmFilePath , withdrawParams . finalZkeyPath )
48
- const withdrawVerifier = new WithdrawVerifier ( withdrawParams . verificationKey )
47
+ describe ( 'Withdraw' , function ( ) {
48
+ const withdrawProver = new WithdrawProver (
49
+ withdrawParams . wasmFilePath ,
50
+ withdrawParams . finalZkeyPath
51
+ ) ;
52
+ const withdrawVerifier = new WithdrawVerifier ( withdrawParams . verificationKey ) ;
49
53
50
- test ( "should generate valid proof" , async function ( ) {
51
- const identitySecret = fieldFactory ( )
52
- const address = fieldFactory ( )
53
- const proof = await withdrawProver . generateProof ( { identitySecret, address} )
54
- expect ( await withdrawVerifier . verifyProof ( proof ) ) . toBeTruthy ( )
55
- } ) ;
54
+ test ( 'should generate valid proof' , async function ( ) {
55
+ const identitySecret = fieldFactory ( ) ;
56
+ const address = fieldFactory ( ) ;
57
+ const m0 = performance . now ( ) ;
58
+ const proof = await withdrawProver . generateProof ( { identitySecret, address } ) ;
59
+ const m1 = performance . now ( ) ;
60
+ const isValid = await withdrawVerifier . verifyProof ( proof ) ;
61
+ const m2 = performance . now ( ) ;
62
+ console . log ( `Withdraw proof generation: ${ m1 - m0 } ms` ) ;
63
+ console . log ( `Withdraw proof verification: ${ m2 - m1 } ms` ) ;
64
+ expect ( isValid ) . toBeTruthy ( ) ;
65
+ } ) ;
56
66
} ) ;
0 commit comments