Skip to content

Commit 61c3f84

Browse files
committed
refactor: extract readNativeHonkProof
1 parent 2966aa0 commit 61c3f84

File tree

2 files changed

+24
-19
lines changed

2 files changed

+24
-19
lines changed

packages/contracts/sdk/NativeUltraHonkBackend.ts

Lines changed: 2 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
11
import type { ProofData } from "@aztec/bb.js";
22
import type { CompiledCircuit } from "@noir-lang/noir_js";
3-
import { chunk } from "lodash-es";
43
import { spawn } from "node:child_process";
54
import fs from "node:fs";
65
import path from "node:path";
7-
import { Hex } from "ox";
8-
import { assert } from "ts-essentials";
6+
import { readNativeHonkProof } from "./utils.js";
97

108
export class NativeUltraHonkBackend {
119
constructor(
@@ -62,22 +60,7 @@ export class NativeUltraHonkBackend {
6260
reject(new Error(`Process exited with code ${code}`));
6361
return;
6462
}
65-
66-
const proof = fs.readFileSync(path.join(proofOutputPath, "proof"));
67-
const publicInputs = fs.readFileSync(
68-
path.join(proofOutputPath, "public_inputs"),
69-
);
70-
assert(
71-
publicInputs.length % 32 === 0,
72-
"publicInputs length must be divisible by 32",
73-
);
74-
resolve({
75-
proof,
76-
// TODO: not sure if this publicInputs decoding is correct
77-
publicInputs: chunk(Array.from(publicInputs), 32).map((x) =>
78-
Hex.fromBytes(Uint8Array.from(x)),
79-
),
80-
});
63+
resolve(readNativeHonkProof(proofOutputPath));
8164
});
8265

8366
bbProcess.on("error", (err) => {

packages/contracts/sdk/utils.ts

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
import type { Fr } from "@aztec/aztec.js";
22
import type { InputMap } from "@noir-lang/noir_js";
33
import { ethers } from "ethers";
4+
import { chunk } from "lodash-es";
5+
import fs from "node:fs";
6+
import path from "node:path";
7+
import { Hex } from "ox";
48
import { assert } from "ts-essentials";
59
import type { NoirAndBackend } from "./sdk.js";
610

@@ -76,3 +80,21 @@ export async function prove(
7680
console.timeEnd(`${name} generateProof`);
7781
return { proof, witness, returnValue, publicInputs };
7882
}
83+
84+
export function readNativeHonkProof(pathToProofDir: string) {
85+
const proof = fs.readFileSync(path.join(pathToProofDir, "proof"));
86+
const publicInputs = fs.readFileSync(
87+
path.join(pathToProofDir, "public_inputs"),
88+
);
89+
assert(
90+
publicInputs.length % 32 === 0,
91+
"publicInputs length must be divisible by 32",
92+
);
93+
return {
94+
proof,
95+
// TODO: not sure if this publicInputs decoding is correct
96+
publicInputs: chunk(Array.from(publicInputs), 32).map((x) =>
97+
Hex.fromBytes(Uint8Array.from(x)),
98+
),
99+
};
100+
}

0 commit comments

Comments
 (0)