1
1
import { assert } from 'chai'
2
- import { buildMimcSponge } from 'circomlibjs'
3
2
import { utils } from 'ethers'
4
3
import { wasm as wasmTester } from 'circom_tester'
4
+ import MimcSponge from '../utils/MimcSponge'
5
5
import expectAssertFailure from '../utils/expectAssertFailure'
6
6
import getFarcasterInputs from '../utils/inputs/getFarcasterInputs'
7
- import padZerosOnLeftHexString from '../utils/padZerosOnLeftHexString '
7
+ import wallet from '../utils/wallet '
8
8
9
9
describe ( 'FarcasterChecker circuit' , function ( ) {
10
10
before ( async function ( ) {
11
11
this . circuit = await wasmTester ( 'circuits/FarcasterChecker.circom' )
12
12
this . baseInputs = await getFarcasterInputs ( )
13
+ this . mimcSponge = await new MimcSponge ( ) . prepare ( )
13
14
} )
14
15
15
16
it ( 'should generate the witness successfully and return the correct nullifier' , async function ( ) {
16
17
const witness = await this . circuit . calculateWitness ( this . baseInputs )
17
18
await this . circuit . assertOut ( witness , { } )
18
19
// Check the nullifier
19
- const mimc = await buildMimcSponge ( )
20
- const hash = mimc . multiHash ( this . baseInputs . nonce )
21
- assert . equal (
22
- padZerosOnLeftHexString ( `0x${ mimc . F . toString ( hash , 16 ) } ` , 66 ) ,
23
- utils . hexlify ( witness [ 11 ] )
24
- )
25
- } )
26
- it ( 'should fail because the siblings is invalid' , async function ( ) {
20
+ const nullifier = this . mimcSponge . hash ( [
21
+ ...this . baseInputs . sealHubS ,
22
+ ...this . baseInputs . sealHubU [ 0 ] ,
23
+ ...this . baseInputs . sealHubU [ 1 ] ,
24
+ wallet . address ,
25
+ '7264817748646751948082916036165286355035506' ,
26
+ ] )
27
+ assert . equal ( nullifier , utils . hexlify ( witness [ 12 ] ) )
28
+ } )
29
+ it ( 'should fail because the siblings are invalid' , async function ( ) {
27
30
const inputs = {
28
31
...this . baseInputs ,
29
- siblings : this . baseInputs . siblings . reverse ( ) ,
32
+ ownersSiblings : this . baseInputs . ownersSiblings . reverse ( ) ,
30
33
}
31
34
await expectAssertFailure ( ( ) => this . circuit . calculateWitness ( inputs ) )
32
35
} )
33
36
it ( 'should fail because the pathIndices is invalid' , async function ( ) {
34
37
const inputs = {
35
38
...this . baseInputs ,
36
- pathIndices : new Array ( this . baseInputs . siblings . length ) . fill ( 7 ) ,
39
+ pathIndices : new Array ( this . baseInputs . ownersPathIndices . length ) . fill ( 0 ) ,
37
40
}
38
41
await expectAssertFailure ( ( ) => this . circuit . calculateWitness ( inputs ) )
39
42
} )
@@ -65,38 +68,6 @@ describe('FarcasterChecker circuit', function () {
65
68
}
66
69
await expectAssertFailure ( ( ) => this . circuit . calculateWitness ( inputs ) )
67
70
} )
68
- it ( 'should fail because the farcasterPubKeyY is invalid' , async function ( ) {
69
- const inputs = {
70
- ...this . baseInputs ,
71
- farcasterPubKeyY :
72
- '64726898530325568278821246826665888375911357846978084992870462356218868841359' ,
73
- }
74
- await expectAssertFailure ( ( ) => this . circuit . calculateWitness ( inputs ) )
75
- } )
76
- it ( 'should fail because the addressPubKeyX is invalid' , async function ( ) {
77
- const inputs = {
78
- ...this . baseInputs ,
79
- addressPubKeyX :
80
- '01900514876892057315890636833479887731419666119278979591965777251527504328920' ,
81
- }
82
- await expectAssertFailure ( ( ) => this . circuit . calculateWitness ( inputs ) )
83
- } )
84
- it ( 'should fail because the addressPubKeyY is invalid' , async function ( ) {
85
- const inputs = {
86
- ...this . baseInputs ,
87
- addressPubKeyY :
88
- '01900514876892057315890636833479887731419666119278979591965777251527504328920' ,
89
- }
90
- await expectAssertFailure ( ( ) => this . circuit . calculateWitness ( inputs ) )
91
- } )
92
- it ( 'should fail because the addressR8x is invalid' , async function ( ) {
93
- const inputs = {
94
- ...this . baseInputs ,
95
- addressR8x :
96
- '7212099666815118526535189261030936450885444553115640062674935038466053117366' ,
97
- }
98
- await expectAssertFailure ( ( ) => this . circuit . calculateWitness ( inputs ) )
99
- } )
100
71
it ( 'should fail because the farcasterR8x is invalid' , async function ( ) {
101
72
const inputs = {
102
73
...this . baseInputs ,
@@ -105,14 +76,6 @@ describe('FarcasterChecker circuit', function () {
105
76
}
106
77
await expectAssertFailure ( ( ) => this . circuit . calculateWitness ( inputs ) )
107
78
} )
108
- it ( 'should fail because the addressR8y is invalid' , async function ( ) {
109
- const inputs = {
110
- ...this . baseInputs ,
111
- addressR8y :
112
- '9964253695754355531317724758616639482828829535308446341320380897334391409050' ,
113
- }
114
- await expectAssertFailure ( ( ) => this . circuit . calculateWitness ( inputs ) )
115
- } )
116
79
it ( 'should fail because the farcasterR8y is invalid' , async function ( ) {
117
80
const inputs = {
118
81
...this . baseInputs ,
@@ -121,14 +84,6 @@ describe('FarcasterChecker circuit', function () {
121
84
}
122
85
await expectAssertFailure ( ( ) => this . circuit . calculateWitness ( inputs ) )
123
86
} )
124
- it ( 'should fail because the addressS is invalid' , async function ( ) {
125
- const inputs = {
126
- ...this . baseInputs ,
127
- addressS :
128
- '3950502661897335750133025420259312129467652226207505500353373422799432347' ,
129
- }
130
- await expectAssertFailure ( ( ) => this . circuit . calculateWitness ( inputs ) )
131
- } )
132
87
it ( 'should fail because the farcasterS is invalid' , async function ( ) {
133
88
const inputs = {
134
89
...this . baseInputs ,
@@ -137,11 +92,4 @@ describe('FarcasterChecker circuit', function () {
137
92
}
138
93
await expectAssertFailure ( ( ) => this . circuit . calculateWitness ( inputs ) )
139
94
} )
140
- it ( 'should fail because the nonce is invalid' , async function ( ) {
141
- const inputs = {
142
- ...this . baseInputs ,
143
- nonce : this . baseInputs . nonce . reverse ( ) ,
144
- }
145
- await expectAssertFailure ( ( ) => this . circuit . calculateWitness ( inputs ) )
146
- } )
147
95
} )
0 commit comments