Skip to content

Commit 76db203

Browse files
committed
fix: potential oprf raw text leak
1 parent 10a8c2b commit 76db203

File tree

5 files changed

+15
-7
lines changed

5 files changed

+15
-7
lines changed

js/src/gnark/utils.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ export function generateGnarkWitness(
154154
key: 'key' in input
155155
? Base64.fromUint8Array(input.key)
156156
: undefined,
157-
ciphertext: 'out' in input
157+
ciphertext: 'out' in input && input.out?.length
158158
? Base64.fromUint8Array(input.out)
159159
: undefined,
160160
blocks: input.noncesAndCounters.map(n => ({

js/src/tests/lib.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -142,8 +142,8 @@ for(const { zkEngine, algorithm } of TEST_MATRIX) {
142142
operator
143143
})
144144
// fill output with 0s
145-
for(let i = 0;i < proof.plaintext.length;i++) {
146-
proof.plaintext[i] = 0
145+
for(let i = 0;i < proof.plaintext!.length;i++) {
146+
proof.plaintext![i] = 0
147147
}
148148

149149
await assert.rejects(

js/src/tests/oprf.test.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import assert from 'assert'
12
import { describe, it } from 'node:test'
23
import { CONFIG } from '../config.ts'
34
import { makeLocalFileFetch } from '../file-fetch.ts'
@@ -98,6 +99,7 @@ for(const { engine, algorithm } of OPRF_TEST_MATRIX) {
9899
mask: req.mask,
99100
toprf,
100101
})
102+
assert.ok(!proof.plaintext)
101103

102104
await verifyProof({
103105
proof,

js/src/types.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,9 @@ export type Proof = {
1616
/**
1717
* the plaintext obtained as an output
1818
* of the ZK circuit
19+
* Will be `undefined` if proving with TOPRF
1920
*/
20-
plaintext: Uint8Array
21+
plaintext: Uint8Array | undefined
2122
}
2223

2324
export type FileFetch = {
@@ -85,7 +86,7 @@ export type GetPublicSignalsOpts = {
8586
algorithm: EncryptionAlgorithm
8687
publicInput: PublicInput
8788
} & ({
88-
plaintext: Uint8Array
89+
plaintext: Uint8Array | undefined
8990
} | {
9091
key: Uint8Array
9192
})

js/src/zk.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import { ceilToBlockSizeMultiple, getBlockSizeBytes, getCounterForByteOffset, sp
1212
export async function generateProof(opts: GenerateProofOpts): Promise<Proof> {
1313
const { algorithm, operator, logger } = opts
1414
const { witness, plaintextArray } = await generateZkWitness(opts)
15+
1516
let wtnsSerialised: Uint8Array
1617
if('mask' in opts) {
1718
wtnsSerialised = await operator.generateWitness({
@@ -26,7 +27,11 @@ export async function generateProof(opts: GenerateProofOpts): Promise<Proof> {
2627

2728
const { proof } = await operator.groth16Prove(wtnsSerialised, logger)
2829

29-
return { algorithm, proofData: proof, plaintext: plaintextArray }
30+
return {
31+
algorithm,
32+
proofData: proof,
33+
plaintext: 'mask' in opts ? undefined : plaintextArray
34+
}
3035
}
3136

3237
/**
@@ -132,7 +137,7 @@ export async function getPublicSignals(
132137
const pubSigs: ZKProofPublicSignals = {
133138
noncesAndCounters,
134139
in: concatenateUint8Arrays(ciphertextBlocks),
135-
out: 'plaintext' in opts
140+
out: 'plaintext' in opts && opts.plaintext
136141
? opts.plaintext
137142
: concatenateUint8Arrays(plaintextBlocks),
138143
}

0 commit comments

Comments
 (0)