|
8 | 8 | ProofDataForRecursion,
|
9 | 9 | reconstructHonkProof,
|
10 | 10 | reconstructUltraPlonkProof,
|
| 11 | + splitHonkProof, |
11 | 12 | } from '../proof/index.js';
|
12 | 13 |
|
13 | 14 | export class AztecClientBackendError extends Error {
|
@@ -154,10 +155,6 @@ export class UltraPlonkBackend {
|
154 | 155 | }
|
155 | 156 | }
|
156 | 157 |
|
157 |
| -// Buffers are prepended with their size. The size takes 4 bytes. |
158 |
| -const serializedBufferSize = 4; |
159 |
| -const fieldByteSize = 32; |
160 |
| - |
161 | 158 | /**
|
162 | 159 | * Options for the UltraHonkBackend.
|
163 | 160 | */
|
@@ -222,22 +219,8 @@ export class UltraHonkBackend {
|
222 | 219 | // Item at index 1 in VK is the number of public inputs
|
223 | 220 | const numPublicInputs = Number(vkAsFields[1].toString());
|
224 | 221 |
|
225 |
| - |
226 |
| - // Account for the serialized buffer size at start |
227 |
| - // Get the part before and after the public inputs |
228 |
| - const proofStart = proofWithPublicInputs.slice(0, serializedBufferSize); |
229 |
| - const publicInputsSplitIndex = numPublicInputs * fieldByteSize; |
230 |
| - const proofEnd = proofWithPublicInputs.slice(serializedBufferSize + publicInputsSplitIndex); |
231 |
| - |
232 |
| - // Construct the proof without the public inputs |
233 |
| - const proof = new Uint8Array([...proofStart, ...proofEnd]); |
234 |
| - |
235 |
| - // Fetch the number of public inputs out of the proof string |
236 |
| - const publicInputsConcatenated = proofWithPublicInputs.slice( |
237 |
| - serializedBufferSize, |
238 |
| - serializedBufferSize + publicInputsSplitIndex, |
239 |
| - ); |
240 |
| - const publicInputs = deflattenFields(publicInputsConcatenated); |
| 222 | + const { proof, publicInputs: publicInputsBytes } = splitHonkProof(proofWithPublicInputs, numPublicInputs); |
| 223 | + const publicInputs = deflattenFields(publicInputsBytes); |
241 | 224 |
|
242 | 225 | return { proof, publicInputs };
|
243 | 226 | }
|
@@ -265,29 +248,15 @@ export class UltraHonkBackend {
|
265 | 248 | const vk = await writeVKUltraHonk(this.acirUncompressedBytecode, this.circuitOptions.recursive);
|
266 | 249 | const vkAsFields = await this.api.acirVkAsFieldsUltraHonk(new RawBuffer(vk));
|
267 | 250 |
|
268 |
| - // proofWithPublicInputs starts with a four-byte size |
269 |
| - const numSerdeHeaderBytes = 4; |
270 | 251 | // some public inputs are handled specially
|
271 | 252 | const numKZGAccumulatorFieldElements = 16;
|
272 | 253 | const publicInputsSizeIndex = 1; // index into VK for numPublicInputs
|
273 |
| - |
274 | 254 | const numPublicInputs = Number(vkAsFields[publicInputsSizeIndex].toString()) - numKZGAccumulatorFieldElements;
|
275 | 255 |
|
276 |
| - // Construct the proof without the public inputs |
277 |
| - const numPublicInputsBytes = numPublicInputs * fieldByteSize; |
278 |
| - const proofNoPIs = new Uint8Array(proofWithPublicInputs.length - numPublicInputsBytes); |
279 |
| - // copy the elements before the public inputs |
280 |
| - proofNoPIs.set(proofWithPublicInputs.subarray(0, numSerdeHeaderBytes), 0); |
281 |
| - // copy the elements after the public inputs |
282 |
| - proofNoPIs.set(proofWithPublicInputs.subarray(numSerdeHeaderBytes + numPublicInputsBytes), numSerdeHeaderBytes); |
283 |
| - const proof: string[] = deflattenFields(proofNoPIs.slice(numSerdeHeaderBytes)); |
284 |
| - |
285 |
| - // Fetch the number of public inputs out of the proof string |
286 |
| - const publicInputsConcatenated = proofWithPublicInputs.slice( |
287 |
| - serializedBufferSize, |
288 |
| - serializedBufferSize + numPublicInputsBytes, |
289 |
| - ); |
290 |
| - const publicInputs = deflattenFields(publicInputsConcatenated); |
| 256 | + const { proof: proofBytes, publicInputs: publicInputsBytes } = splitHonkProof(proofWithPublicInputs, numPublicInputs); |
| 257 | + |
| 258 | + const publicInputs = deflattenFields(publicInputsBytes); |
| 259 | + const proof = deflattenFields(proofBytes); |
291 | 260 |
|
292 | 261 | return { proof, publicInputs };
|
293 | 262 | }
|
|
0 commit comments