Skip to content

Commit

Permalink
fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
backmeupplz committed Dec 9, 2022
1 parent 3d96336 commit 9112457
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 74 deletions.
3 changes: 3 additions & 0 deletions circuits/FarcasterChecker.circom
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,9 @@ template FarcasterChecker() {
}
nullifierMimc.ins[3 * k] <== sealHubAddress;
nullifierMimc.ins[3 * k + 1] <== 7264817748646751948082916036165286355035506; // "SealCred Farcaster" in decimal
// Export nullifier
signal output nullifier <== nullifierMimc.outs[0];

// Check Merkle proof
var levels = 20;
signal input ownersPathIndices[levels];
Expand Down
13 changes: 9 additions & 4 deletions contracts/FarcasterCheckerVerifier.sol
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ constructor(string memory _version) Versioned(_version) {}
[11502426145685875357967720478366491326865907869902181704031346886834786027007,
21679208693936337484429571887537508926366191105267550375038502782696042114705]
);
vk.IC = new Pairing.G1Point[](13);
vk.IC = new Pairing.G1Point[](14);

vk.IC[0] = Pairing.G1Point(
1434503044639447657000334311173445651634008568660803576836778852249130950821,
Expand Down Expand Up @@ -265,8 +265,13 @@ constructor(string memory _version) Versioned(_version) {}
);

vk.IC[12] = Pairing.G1Point(
5111593695812272099212502134446055786008863304529130214324923748316205985944,
11339237465823366135665077725206968496398034316829346362337713418985461809700
10549756917129790392004877053475664887933370945882852129665952652629414596367,
16956682912816679985995082856195805088437186243060171453701712381735714434613
);

vk.IC[13] = Pairing.G1Point(
6826903940647479368248617835565385833402494717367363313870527014186359467581,
14847588673792356335903374132776998539658979403387290082499866554901593542637
);

}
Expand Down Expand Up @@ -294,7 +299,7 @@ constructor(string memory _version) Versioned(_version) {}
uint[2] memory a,
uint[2][2] memory b,
uint[2] memory c,
uint[12] memory input
uint[13] memory input
) public view returns (bool r) {
Proof memory proof;
proof.A = Pairing.G1Point(a[0], a[1]);
Expand Down
Binary file modified public/FarcasterChecker.wasm
Binary file not shown.
Binary file modified public/FarcasterChecker_final.zkey
Binary file not shown.
11 changes: 8 additions & 3 deletions public/FarcasterChecker_verification_key.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"protocol": "groth16",
"curve": "bn128",
"nPublic": 12,
"nPublic": 13,
"vk_alpha_1": [
"20491192805390485299153009773594534940189261866228447918068658471970481763042",
"9383485363053290200918347156157836566562967994039712273449902621266178545958",
Expand Down Expand Up @@ -141,8 +141,13 @@
"1"
],
[
"5111593695812272099212502134446055786008863304529130214324923748316205985944",
"11339237465823366135665077725206968496398034316829346362337713418985461809700",
"10549756917129790392004877053475664887933370945882852129665952652629414596367",
"16956682912816679985995082856195805088437186243060171453701712381735714434613",
"1"
],
[
"6826903940647479368248617835565385833402494717367363313870527014186359467581",
"14847588673792356335903374132776998539658979403387290082499866554901593542637",
"1"
]
]
Expand Down
82 changes: 15 additions & 67 deletions test/farcasterCircuit.ts
Original file line number Diff line number Diff line change
@@ -1,39 +1,42 @@
import { assert } from 'chai'
import { buildMimcSponge } from 'circomlibjs'
import { utils } from 'ethers'
import { wasm as wasmTester } from 'circom_tester'
import MimcSponge from '../utils/MimcSponge'
import expectAssertFailure from '../utils/expectAssertFailure'
import getFarcasterInputs from '../utils/inputs/getFarcasterInputs'
import padZerosOnLeftHexString from '../utils/padZerosOnLeftHexString'
import wallet from '../utils/wallet'

describe('FarcasterChecker circuit', function () {
before(async function () {
this.circuit = await wasmTester('circuits/FarcasterChecker.circom')
this.baseInputs = await getFarcasterInputs()
this.mimcSponge = await new MimcSponge().prepare()
})

it('should generate the witness successfully and return the correct nullifier', async function () {
const witness = await this.circuit.calculateWitness(this.baseInputs)
await this.circuit.assertOut(witness, {})
// Check the nullifier
const mimc = await buildMimcSponge()
const hash = mimc.multiHash(this.baseInputs.nonce)
assert.equal(
padZerosOnLeftHexString(`0x${mimc.F.toString(hash, 16)}`, 66),
utils.hexlify(witness[11])
)
})
it('should fail because the siblings is invalid', async function () {
const nullifier = this.mimcSponge.hash([
...this.baseInputs.sealHubS,
...this.baseInputs.sealHubU[0],
...this.baseInputs.sealHubU[1],
wallet.address,
'7264817748646751948082916036165286355035506',
])
assert.equal(nullifier, utils.hexlify(witness[12]))
})
it('should fail because the siblings are invalid', async function () {
const inputs = {
...this.baseInputs,
siblings: this.baseInputs.siblings.reverse(),
ownersSiblings: this.baseInputs.ownersSiblings.reverse(),
}
await expectAssertFailure(() => this.circuit.calculateWitness(inputs))
})
it('should fail because the pathIndices is invalid', async function () {
const inputs = {
...this.baseInputs,
pathIndices: new Array(this.baseInputs.siblings.length).fill(7),
pathIndices: new Array(this.baseInputs.ownersPathIndices.length).fill(0),
}
await expectAssertFailure(() => this.circuit.calculateWitness(inputs))
})
Expand Down Expand Up @@ -65,38 +68,6 @@ describe('FarcasterChecker circuit', function () {
}
await expectAssertFailure(() => this.circuit.calculateWitness(inputs))
})
it('should fail because the farcasterPubKeyY is invalid', async function () {
const inputs = {
...this.baseInputs,
farcasterPubKeyY:
'64726898530325568278821246826665888375911357846978084992870462356218868841359',
}
await expectAssertFailure(() => this.circuit.calculateWitness(inputs))
})
it('should fail because the addressPubKeyX is invalid', async function () {
const inputs = {
...this.baseInputs,
addressPubKeyX:
'01900514876892057315890636833479887731419666119278979591965777251527504328920',
}
await expectAssertFailure(() => this.circuit.calculateWitness(inputs))
})
it('should fail because the addressPubKeyY is invalid', async function () {
const inputs = {
...this.baseInputs,
addressPubKeyY:
'01900514876892057315890636833479887731419666119278979591965777251527504328920',
}
await expectAssertFailure(() => this.circuit.calculateWitness(inputs))
})
it('should fail because the addressR8x is invalid', async function () {
const inputs = {
...this.baseInputs,
addressR8x:
'7212099666815118526535189261030936450885444553115640062674935038466053117366',
}
await expectAssertFailure(() => this.circuit.calculateWitness(inputs))
})
it('should fail because the farcasterR8x is invalid', async function () {
const inputs = {
...this.baseInputs,
Expand All @@ -105,14 +76,6 @@ describe('FarcasterChecker circuit', function () {
}
await expectAssertFailure(() => this.circuit.calculateWitness(inputs))
})
it('should fail because the addressR8y is invalid', async function () {
const inputs = {
...this.baseInputs,
addressR8y:
'9964253695754355531317724758616639482828829535308446341320380897334391409050',
}
await expectAssertFailure(() => this.circuit.calculateWitness(inputs))
})
it('should fail because the farcasterR8y is invalid', async function () {
const inputs = {
...this.baseInputs,
Expand All @@ -121,14 +84,6 @@ describe('FarcasterChecker circuit', function () {
}
await expectAssertFailure(() => this.circuit.calculateWitness(inputs))
})
it('should fail because the addressS is invalid', async function () {
const inputs = {
...this.baseInputs,
addressS:
'3950502661897335750133025420259312129467652226207505500353373422799432347',
}
await expectAssertFailure(() => this.circuit.calculateWitness(inputs))
})
it('should fail because the farcasterS is invalid', async function () {
const inputs = {
...this.baseInputs,
Expand All @@ -137,11 +92,4 @@ describe('FarcasterChecker circuit', function () {
}
await expectAssertFailure(() => this.circuit.calculateWitness(inputs))
})
it('should fail because the nonce is invalid', async function () {
const inputs = {
...this.baseInputs,
nonce: this.baseInputs.nonce.reverse(),
}
await expectAssertFailure(() => this.circuit.calculateWitness(inputs))
})
})

0 comments on commit 9112457

Please sign in to comment.