Skip to content

Commit

Permalink
fix: minor issues in gnark TOPRF op
Browse files Browse the repository at this point in the history
  • Loading branch information
adiwajshing committed Nov 20, 2024
1 parent 84218a5 commit 9e8632e
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 8 deletions.
6 changes: 4 additions & 2 deletions js/src/gnark/toprf.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,17 @@ export function makeGnarkOPRFOperator({
const {
proof: { proofJson }
} = await executeGnarkFnAndGetJson(lib.prove, witness)
return { proof: proofJson }
return { proof: Base64.toUint8Array(proofJson) }
},
async groth16Verify(publicSignals, proof, logger) {
const lib = await initGnark(logger)
const pubSignals = serialiseGnarkWitness(algorithm, publicSignals)

const verifyParams = JSON.stringify({
cipher: `${algorithm}-toprf`,
proof: proof,
proof: typeof proof === 'string'
? proof
: Base64.fromUint8Array(proof),
publicSignals: Base64.fromUint8Array(pubSignals),
})
return executeGnarkFn(lib.verify, verifyParams) === 1
Expand Down
4 changes: 1 addition & 3 deletions js/src/gnark/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -138,9 +138,7 @@ export function serialiseGnarkWitness(
input: ZKProofInput | ZKProofInputOPRF | ZKProofPublicSignals | ZKProofPublicSignalsOPRF
) {
const json = generateGnarkWitness(cipher, input)
return strToUint8Array(JSON.stringify(
json
))
return strToUint8Array(JSON.stringify(json))
}

export function generateGnarkWitness(
Expand Down
9 changes: 6 additions & 3 deletions js/src/tests/oprf.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,14 @@ const fetcher = makeLocalFileFetch()
const operator = makeGnarkOPRFOperator({ fetcher, algorithm: 'chacha20' })
const threshold = 1

const POSITIONS = [
0,
10
]

describe('TOPRF circuits Tests', () => {

it('should prove & verify TOPRF', async() => {
it.each(POSITIONS)('should prove & verify TOPRF at pos=%s', async pos => {
const email = 'test@email.com'
const domainSeparator = 'reclaim'

Expand All @@ -36,8 +41,6 @@ describe('TOPRF circuits Tests', () => {

const nullifier = await operator
.finaliseOPRF(keys.publicKey, req, resps)

const pos = 10
const len = email.length

const plaintext = new Uint8Array(Buffer.alloc(64))
Expand Down

0 comments on commit 9e8632e

Please sign in to comment.