Skip to content

Commit

Permalink
fix: query schema calculation (#38)
Browse files Browse the repository at this point in the history
* fix: query schema calculation

* fix: use axiom-tools query schema
  • Loading branch information
rpalakkal authored Jan 19, 2024
1 parent 1fac5ea commit b15d18b
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 10 deletions.
15 changes: 6 additions & 9 deletions circuit/js/src/scaffold.ts
Original file line number Diff line number Diff line change
@@ -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,
Expand Down Expand Up @@ -84,13 +84,10 @@ export abstract class AxiomBaseCircuitScaffold<T> 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[] {
Expand Down
4 changes: 3 additions & 1 deletion circuit/js/test/unit/scaffold.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit b15d18b

Please sign in to comment.