@aztec/bb.js 0.81.0 → 0.82.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,3 +1,5 @@
1
+ import { numToUInt32BE } from "../serialize/serialize.js";
2
+
1
3
  /**
2
4
  * @description
3
5
  * The representation of a proof
@@ -20,24 +22,19 @@ export type ProofDataForRecursion = {
20
22
  proof: string[];
21
23
  };
22
24
 
23
- // Buffers are prepended with their size. The size takes 4 bytes.
24
- const serializedBufferSize = 4;
25
+ // Honk proofs start with 4 bytes for the size of the proof in fields
26
+ const metadataOffset = 4;
25
27
  const fieldByteSize = 32;
26
28
 
27
29
  export function splitHonkProof(
28
30
  proofWithPublicInputs: Uint8Array,
29
31
  numPublicInputs: number,
30
32
  ): { publicInputs: Uint8Array; proof: Uint8Array } {
31
- // Account for the serialized buffer size at start
32
- // Get the part before and after the public inputs
33
- const proofStart = proofWithPublicInputs.slice(0, serializedBufferSize);
34
- const publicInputsSplitIndex = numPublicInputs * fieldByteSize;
35
- const proofEnd = proofWithPublicInputs.slice(serializedBufferSize + publicInputsSplitIndex);
36
- // Construct the proof without the public inputs
37
- const proof = new Uint8Array([...proofStart, ...proofEnd]);
33
+ // Remove the metadata (proof size in fields)
34
+ const proofWithPI = proofWithPublicInputs.slice(metadataOffset);
38
35
 
39
- // Fetch the number of public inputs out of the proof string
40
- const publicInputs = proofWithPublicInputs.slice(serializedBufferSize, serializedBufferSize + publicInputsSplitIndex);
36
+ const publicInputs = proofWithPI.slice(0, numPublicInputs * fieldByteSize);
37
+ const proof = proofWithPI.slice(numPublicInputs * fieldByteSize);
41
38
 
42
39
  return {
43
40
  proof,
@@ -46,12 +43,10 @@ export function splitHonkProof(
46
43
  }
47
44
 
48
45
  export function reconstructHonkProof(publicInputs: Uint8Array, proof: Uint8Array): Uint8Array {
49
- const proofStart = proof.slice(0, serializedBufferSize);
50
- const proofEnd = proof.slice(serializedBufferSize);
51
-
52
- // Concatenate publicInputs and proof
53
- const proofWithPublicInputs = Uint8Array.from([...proofStart, ...publicInputs, ...proofEnd]);
46
+ // Append proofWithPublicInputs size in fields
47
+ const proofSize = numToUInt32BE((publicInputs.length + proof.length) / fieldByteSize);
54
48
 
49
+ const proofWithPublicInputs = Uint8Array.from([...proofSize, ...publicInputs, ...proof]);
55
50
  return proofWithPublicInputs;
56
51
  }
57
52