Skip to content

Commit 9112457

Browse files
committed
fix tests
1 parent 3d96336 commit 9112457

File tree

6 files changed

+35
-74
lines changed

6 files changed

+35
-74
lines changed

circuits/FarcasterChecker.circom

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,9 @@ template FarcasterChecker() {
6666
}
6767
nullifierMimc.ins[3 * k] <== sealHubAddress;
6868
nullifierMimc.ins[3 * k + 1] <== 7264817748646751948082916036165286355035506; // "SealCred Farcaster" in decimal
69+
// Export nullifier
70+
signal output nullifier <== nullifierMimc.outs[0];
71+
6972
// Check Merkle proof
7073
var levels = 20;
7174
signal input ownersPathIndices[levels];

contracts/FarcasterCheckerVerifier.sol

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,7 @@ constructor(string memory _version) Versioned(_version) {}
202202
[11502426145685875357967720478366491326865907869902181704031346886834786027007,
203203
21679208693936337484429571887537508926366191105267550375038502782696042114705]
204204
);
205-
vk.IC = new Pairing.G1Point[](13);
205+
vk.IC = new Pairing.G1Point[](14);
206206

207207
vk.IC[0] = Pairing.G1Point(
208208
1434503044639447657000334311173445651634008568660803576836778852249130950821,
@@ -265,8 +265,13 @@ constructor(string memory _version) Versioned(_version) {}
265265
);
266266

267267
vk.IC[12] = Pairing.G1Point(
268-
5111593695812272099212502134446055786008863304529130214324923748316205985944,
269-
11339237465823366135665077725206968496398034316829346362337713418985461809700
268+
10549756917129790392004877053475664887933370945882852129665952652629414596367,
269+
16956682912816679985995082856195805088437186243060171453701712381735714434613
270+
);
271+
272+
vk.IC[13] = Pairing.G1Point(
273+
6826903940647479368248617835565385833402494717367363313870527014186359467581,
274+
14847588673792356335903374132776998539658979403387290082499866554901593542637
270275
);
271276

272277
}
@@ -294,7 +299,7 @@ constructor(string memory _version) Versioned(_version) {}
294299
uint[2] memory a,
295300
uint[2][2] memory b,
296301
uint[2] memory c,
297-
uint[12] memory input
302+
uint[13] memory input
298303
) public view returns (bool r) {
299304
Proof memory proof;
300305
proof.A = Pairing.G1Point(a[0], a[1]);

public/FarcasterChecker.wasm

36 Bytes
Binary file not shown.

public/FarcasterChecker_final.zkey

44 Bytes
Binary file not shown.

public/FarcasterChecker_verification_key.json

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"protocol": "groth16",
33
"curve": "bn128",
4-
"nPublic": 12,
4+
"nPublic": 13,
55
"vk_alpha_1": [
66
"20491192805390485299153009773594534940189261866228447918068658471970481763042",
77
"9383485363053290200918347156157836566562967994039712273449902621266178545958",
@@ -141,8 +141,13 @@
141141
"1"
142142
],
143143
[
144-
"5111593695812272099212502134446055786008863304529130214324923748316205985944",
145-
"11339237465823366135665077725206968496398034316829346362337713418985461809700",
144+
"10549756917129790392004877053475664887933370945882852129665952652629414596367",
145+
"16956682912816679985995082856195805088437186243060171453701712381735714434613",
146+
"1"
147+
],
148+
[
149+
"6826903940647479368248617835565385833402494717367363313870527014186359467581",
150+
"14847588673792356335903374132776998539658979403387290082499866554901593542637",
146151
"1"
147152
]
148153
]

test/farcasterCircuit.ts

Lines changed: 15 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,42 @@
11
import { assert } from 'chai'
2-
import { buildMimcSponge } from 'circomlibjs'
32
import { utils } from 'ethers'
43
import { wasm as wasmTester } from 'circom_tester'
4+
import MimcSponge from '../utils/MimcSponge'
55
import expectAssertFailure from '../utils/expectAssertFailure'
66
import getFarcasterInputs from '../utils/inputs/getFarcasterInputs'
7-
import padZerosOnLeftHexString from '../utils/padZerosOnLeftHexString'
7+
import wallet from '../utils/wallet'
88

99
describe('FarcasterChecker circuit', function () {
1010
before(async function () {
1111
this.circuit = await wasmTester('circuits/FarcasterChecker.circom')
1212
this.baseInputs = await getFarcasterInputs()
13+
this.mimcSponge = await new MimcSponge().prepare()
1314
})
1415

1516
it('should generate the witness successfully and return the correct nullifier', async function () {
1617
const witness = await this.circuit.calculateWitness(this.baseInputs)
1718
await this.circuit.assertOut(witness, {})
1819
// 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 () {
2730
const inputs = {
2831
...this.baseInputs,
29-
siblings: this.baseInputs.siblings.reverse(),
32+
ownersSiblings: this.baseInputs.ownersSiblings.reverse(),
3033
}
3134
await expectAssertFailure(() => this.circuit.calculateWitness(inputs))
3235
})
3336
it('should fail because the pathIndices is invalid', async function () {
3437
const inputs = {
3538
...this.baseInputs,
36-
pathIndices: new Array(this.baseInputs.siblings.length).fill(7),
39+
pathIndices: new Array(this.baseInputs.ownersPathIndices.length).fill(0),
3740
}
3841
await expectAssertFailure(() => this.circuit.calculateWitness(inputs))
3942
})
@@ -65,38 +68,6 @@ describe('FarcasterChecker circuit', function () {
6568
}
6669
await expectAssertFailure(() => this.circuit.calculateWitness(inputs))
6770
})
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-
})
10071
it('should fail because the farcasterR8x is invalid', async function () {
10172
const inputs = {
10273
...this.baseInputs,
@@ -105,14 +76,6 @@ describe('FarcasterChecker circuit', function () {
10576
}
10677
await expectAssertFailure(() => this.circuit.calculateWitness(inputs))
10778
})
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-
})
11679
it('should fail because the farcasterR8y is invalid', async function () {
11780
const inputs = {
11881
...this.baseInputs,
@@ -121,14 +84,6 @@ describe('FarcasterChecker circuit', function () {
12184
}
12285
await expectAssertFailure(() => this.circuit.calculateWitness(inputs))
12386
})
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-
})
13287
it('should fail because the farcasterS is invalid', async function () {
13388
const inputs = {
13489
...this.baseInputs,
@@ -137,11 +92,4 @@ describe('FarcasterChecker circuit', function () {
13792
}
13893
await expectAssertFailure(() => this.circuit.calculateWitness(inputs))
13994
})
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-
})
14795
})

0 commit comments

Comments
 (0)