diff --git a/circuit/js/src/scaffold.ts b/circuit/js/src/scaffold.ts index 3af4b536..fddc1a8d 100644 --- a/circuit/js/src/scaffold.ts +++ b/circuit/js/src/scaffold.ts @@ -1,13 +1,13 @@ import { CircuitConfig, Halo2LibWasm } from "@axiom-crypto/halo2-lib-js/wasm/web"; -import { keccak256 } from "ethers"; import { base64ToByteArray, byteArrayToBase64, convertToBytes, convertToBytes32 } from "./utils"; -import { concat, encodePacked, zeroHash } from "viem"; +import { concat, zeroHash } from "viem"; import { AxiomCircuitRunner } from "./circuitRunner"; import { AxiomV2Callback, AxiomV2CircuitConstant, AxiomV2ComputeQuery, DataSubquery, + getQuerySchemaHash, } from "@axiom-crypto/tools"; import { AxiomSdkCore, @@ -84,13 +84,10 @@ export abstract class AxiomBaseCircuitScaffold extends BaseCircuitScaffold { getQuerySchema() { const partialVk = this.getPartialVk(); - const vk = convertToBytes32(partialVk); - const packed = encodePacked( - ["uint8", "uint16", "uint8", "bytes32[]"], - [this.config.k, this.resultLen, vk.length, vk as `0x${string}`[]], - ); - const schema = keccak256(packed); - return schema as string; + const vkBytes = convertToBytes32(partialVk); + const onchainVk = this.prependCircuitMetadata(this.config, vkBytes); + const querySchema = getQuerySchemaHash(this.config.k, this.resultLen, onchainVk); + return querySchema; } prependCircuitMetadata(config: CircuitConfig, partialVk: string[]): string[] { diff --git a/circuit/js/test/unit/scaffold.test.ts b/circuit/js/test/unit/scaffold.test.ts index 4edb42a7..07fd5991 100644 --- a/circuit/js/test/unit/scaffold.test.ts +++ b/circuit/js/test/unit/scaffold.test.ts @@ -21,7 +21,9 @@ describe("Scaffold", () => { }; const _artifact = await testCircuit.compile(defaultInputs); const computeQuery = await testCircuit.run(defaultInputs); - + const querySchema = testCircuit.getQuerySchema(); + + expect(querySchema).toEqual("0x21320f4358ce83ec05dcbe1be8cc43002f6ab194fb3d014f9046022aa2bd1784"); expect(computeQuery.vkey[0]).toEqual("0x0001000009000100000004010000010080000000000000000000000000000000"); expect(computeQuery.computeProof.slice(2).slice(0,128)).toEqual(concat([zeroHash, zeroHash]).slice(2)); }, 30000);