Skip to content

Commit

Permalink
Merge v2.0.6 (#74)
Browse files Browse the repository at this point in the history
Co-authored-by: Roshan <[email protected]>
Co-authored-by: Yu Jiang Tham <>
  • Loading branch information
ytham and rpalakkal authored Mar 12, 2024
1 parent 85cc387 commit 08e2fc1
Show file tree
Hide file tree
Showing 40 changed files with 358 additions and 1,164 deletions.
42 changes: 39 additions & 3 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,12 @@ on:
- rc
pull_request:

env:
PRIVATE_KEY_SEPOLIA: ${{ secrets.PRIVATE_KEY_SEPOLIA }}
PROVIDER_URI_SEPOLIA: ${{ secrets.PROVIDER_URI_SEPOLIA }}
PROVIDER_URI_GOERLI: ${{ secrets.PROVIDER_URI_GOERLI }}
PINATA_JWT: ${{ secrets.PINATA_JWT }}

jobs:
circuit-js:
name: JS Circuit Tests
Expand Down Expand Up @@ -37,13 +43,44 @@ jobs:
- name: Run Unit Tests
working-directory: ./circuit
run: |
export PROVIDER_URI_GOERLI=${{ secrets.PROVIDER_URI_GOERLI }}
export PROVIDER_URI_SEPOLIA=${{ secrets.PROVIDER_URI_SEPOLIA }}
ANVIL_PRIVATE_KEY=0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80
export PRIVATE_KEY=$ANVIL_PRIVATE_KEY # just needs to be in the correct format, no tx is sent in unit tests
export PRIVATE_KEY_GOERLI=$ANVIL_PRIVATE_KEY
pnpm test
client-tests:
name: Client Tests
runs-on: ubuntu-latest

steps:
- name: Checkout Code
uses: actions/checkout@v3

- name: Setup pnpm
uses: pnpm/action-setup@v3
with:
version: 8

- name: "Install Node.js"
uses: "actions/setup-node@v4"
with:
node-version: "20.x"
cache: "pnpm"
registry-url: "https://registry.npmjs.org"
cache-dependency-path: client/pnpm-lock.yaml

- name: Set all packages to local and build
working-directory: ./
run: pnpm local

- name: Run Unit Tests (Client)
working-directory: ./client
run: pnpm test test/unit

- name: Run Integration Tests (Client)
working-directory: ./client
run: pnpm test test/integration

harness:
name: Harness Tests
runs-on: ubuntu-latest
Expand Down Expand Up @@ -72,7 +109,6 @@ jobs:
- name: Run Integration Tests (Sepolia)
working-directory: ./harness
run: |
export PROVIDER_URI_SEPOLIA=${{ secrets.PROVIDER_URI_SEPOLIA }}
ANVIL_PRIVATE_KEY=0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80
export PRIVATE_KEY=$ANVIL_PRIVATE_KEY # just needs to be in the correct format, no tx is sent in unit tests
export PRIVATE_KEY_SEPOLIA=$ANVIL_PRIVATE_KEY
Expand Down
2 changes: 1 addition & 1 deletion circuit/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@axiom-crypto/circuit",
"version": "2.0.5",
"version": "2.0.6",
"author": "Intrinsic Technologies",
"license": "MIT",
"description": "Client SDK to write custom queries for Axiom, the ZK Coprocessor for Ethereum.",
Expand Down
5 changes: 4 additions & 1 deletion circuit/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
export * from "./subquery";
export * from "./circuitRunner";
export * from "./encoder";
export { RawInput as UserInput } from './types';
export {
RawInput as UserInput,
AxiomV2CircuitCapacity,
} from './types';
export { DEFAULT_CAPACITY } from './constants';
export { CircuitValue, CircuitValue256 } from "@axiom-crypto/halo2-lib-js";
export * from "@axiom-crypto/halo2-lib-js/halo2lib/functions";
42 changes: 26 additions & 16 deletions circuit/src/scaffold.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,13 @@ export abstract class AxiomBaseCircuitScaffold<T> extends BaseCircuitScaffold {
this.provider = inputs.provider;
this.config = inputs.config ?? DEFAULT_CIRCUIT_CONFIG;
this.capacity = inputs.capacity ?? DEFAULT_CAPACITY;
if (
this.capacity?.maxOutputs !== DEFAULT_CAPACITY.maxOutputs ||
this.capacity?.maxSubqueries !== DEFAULT_CAPACITY.maxSubqueries
) {
console.warn("Using a non-default capacity for the circuit will result in a query that cannot be fulfilled on-chain.");
}

this.dataQuery = [];
this.axiom = new AxiomSdkCore({
providerUri: inputs.provider,
Expand Down Expand Up @@ -79,15 +86,22 @@ export abstract class AxiomBaseCircuitScaffold<T> extends BaseCircuitScaffold {
return { ...this.results };
}

async loadSaved(input: { config: AxiomV2CircuitConfig; vk: string }) {
this.config = input.config.config;
this.capacity = input.config.capacity;
async loadSaved(input: {
vk: string;
config: CircuitConfig;
capacity?: AxiomV2CircuitCapacity;
}) {
this.config = input.config;
this.capacity = input.capacity ?? DEFAULT_CAPACITY;
await this.loadParamsAndVk(base64ToByteArray(input.vk));
}

loadSavedMock(input: { config: AxiomV2CircuitConfig }) {
this.config = input.config.config;
this.capacity = input.config.capacity;
loadSavedMock(input: {
config: CircuitConfig;
capacity?: AxiomV2CircuitCapacity;
}) {
this.config = input.config;
this.capacity = input.capacity ?? DEFAULT_CAPACITY;
}

circuitConfig(): AxiomV2CircuitConfig {
Expand Down Expand Up @@ -150,13 +164,11 @@ export abstract class AxiomBaseCircuitScaffold<T> extends BaseCircuitScaffold {
const vk = this.getHalo2Vk();
const encoder = new TextEncoder();
const inputSchema = encoder.encode(this.inputSchema);
const axiomConfig: AxiomV2CircuitConfig = {
config,
capacity: this.capacity
}

return {
vk: byteArrayToBase64(vk),
config: axiomConfig,
config,
capacity: this.capacity ?? DEFAULT_CAPACITY,
querySchema: this.getQuerySchema(),
inputSchema: byteArrayToBase64(inputSchema),
};
Expand All @@ -178,13 +190,11 @@ export abstract class AxiomBaseCircuitScaffold<T> extends BaseCircuitScaffold {
const vk = this.getMockVk().map(e => e.slice(2)).join('');
const encoder = new TextEncoder();
const inputSchema = encoder.encode(this.inputSchema);
const axiomConfig: AxiomV2CircuitConfig = {
config,
capacity: this.capacity
}

return {
vk,
config: axiomConfig,
config,
capacity: this.capacity ?? DEFAULT_CAPACITY,
querySchema: DEADBEEF_BYTES32,
inputSchema: byteArrayToBase64(inputSchema),
};
Expand Down
4 changes: 2 additions & 2 deletions client/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@axiom-crypto/client",
"version": "2.0.5",
"version": "2.0.6",
"author": "Intrinsic Technologies",
"license": "MIT",
"description": "Client SDK to write custom queries for Axiom, the ZK Coprocessor for Ethereum.",
Expand All @@ -24,7 +24,7 @@
"crypto"
],
"dependencies": {
"@axiom-crypto/circuit": "2.0.5",
"@axiom-crypto/circuit": "link:../circuit/dist",
"@axiom-crypto/core": "2.3.7",
"chalk": "^4.1.2",
"commander": "^11.1.0",
Expand Down
62 changes: 5 additions & 57 deletions client/pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

19 changes: 10 additions & 9 deletions client/src/axiom/axiom.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@ import {
AxiomV2CompiledCircuit,
AxiomV2SendQueryArgs,
} from "../types";
import { AxiomV2CircuitCapacity, RawInput } from "@axiom-crypto/circuit/types";
import { DEFAULT_CAPACITY } from "@axiom-crypto/circuit/constants";
import { RawInput } from "@axiom-crypto/circuit/types";
import { AxiomV2CircuitCapacity, DEFAULT_CAPACITY } from "@axiom-crypto/circuit";
import { convertChainIdToViemChain } from "./utils";
import { TransactionReceipt, WalletClient, createPublicClient, createWalletClient, http, zeroAddress, zeroHash } from "viem";
import { privateKeyToAccount } from 'viem/accounts'
import { AxiomV2Callback, AxiomV2ComputeQuery } from "@axiom-crypto/core";
import { AxiomV2Callback } from "@axiom-crypto/core";
import { ClientConstants } from "../constants";

export class Axiom<T> {
Expand All @@ -26,6 +26,7 @@ export class Axiom<T> {
constructor(config: AxiomV2ClientConfig<T>) {
this.config = config;
this.compiledCircuit = config.compiledCircuit;
this.capacity = config.capacity ?? DEFAULT_CAPACITY;
this.callback = {
target: config.callback.target,
extraData: config.callback.extraData ?? "0x",
Expand Down Expand Up @@ -54,10 +55,8 @@ export class Axiom<T> {

async init() {
await this.axiomCircuit.loadSaved({
config: {
config: this.compiledCircuit.config,
capacity: this.capacity ?? DEFAULT_CAPACITY,
},
config: this.compiledCircuit.config,
capacity: this.capacity ?? DEFAULT_CAPACITY,
vk: this.compiledCircuit.vk,
});
}
Expand All @@ -83,7 +82,7 @@ export class Axiom<T> {
}
}

async prove(input: RawInput<T>): Promise<any> {
async prove(input: RawInput<T>): Promise<AxiomV2SendQueryArgs> {
await this.axiomCircuit.run(input);
return await this.buildSendQueryArgs();
}
Expand Down Expand Up @@ -159,18 +158,20 @@ export class Axiom<T> {
if (this.walletClient === undefined) {
throw new Error("Setting `privateKey` in the `Axiom` constructor is required to get sendQuery args");
}
const clientOptions = {
const clientOptions: AxiomV2ClientOptions = {
...this.options,
callbackGasLimit: this.options?.callbackGasLimit ?? ClientConstants.CALLBACK_GAS_LIMIT,
refundee: this.options?.refundee ?? this.walletClient?.account?.address,
ipfsClient: this.config.ipfsClient,
};

this.sendQueryArgs = await this.axiomCircuit.getSendQueryArgs({
callbackTarget: this.callback.target,
callbackExtraData: this.callback.extraData ?? "0x",
callerAddress: this.walletClient?.account?.address,
options: clientOptions,
});

return this.sendQueryArgs;
}
}
4 changes: 2 additions & 2 deletions client/src/lib/address.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,9 +79,9 @@ export function getAxiomV2QueryAddress(
}

if (!mock) {
return axiomV2QueryAddresses[chainId][targetChainId];
return axiomV2QueryAddresses?.[chainId]?.[targetChainId] ?? "";
} else {
return axiomV2QueryAddressesMock[chainId][targetChainId];
return axiomV2QueryAddressesMock?.[chainId]?.[targetChainId] ?? "";
}
}

Expand Down
4 changes: 2 additions & 2 deletions client/src/lib/index.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
export * from './abi';
export * from './address';
export * from "./abi";
export * from "./address";
1 change: 1 addition & 0 deletions client/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ export interface AxiomV2CompiledCircuit {
querySchema: string;
inputSchema: string;
circuit: string;
capacity?: AxiomV2CircuitCapacity;
}

export interface AxiomV2ClientOptions extends AxiomV2QueryOptions {
Expand Down
2 changes: 1 addition & 1 deletion client/src/version.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// This is an autogenerated file. It should match the version number in package.json.
// Do not modify this file directly.

export const CLIENT_VERSION = "2.0.5";
export const CLIENT_VERSION = "2.0.6";
Loading

0 comments on commit 08e2fc1

Please sign in to comment.