Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: crosschain integration #23

Merged
merged 16 commits into from
Jul 17, 2024
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 31 additions & 9 deletions build/axiom-std-cli-build.js
Original file line number Diff line number Diff line change
Expand Up @@ -161,15 +161,15 @@ var require_compile = __commonJS({
var utils_12 = require("@axiom-crypto/circuit/cliHandler/utils");
var utils_22 = require_utils();
var viem_12 = require("viem");
var compile = async (circuitPath, providerUri2, options) => {
var compile = async (circuitPath, rpcUrl2, options) => {
const { restoreConsole: restoreConsole2, getCaptures: getCaptures2 } = (0, utils_22.redirectConsole)();
let circuitFunction = "circuit";
const f = await (0, utils_12.getFunctionFromTs)(circuitPath, circuitFunction);
const provider2 = (0, utils_12.getProvider)(providerUri2);
const rpcUrlOrCache2 = (0, utils_12.getRpcUrl)(rpcUrl2);
const circuit2 = new js_12.AxiomBaseCircuit({
f: f.circuit,
mock: true,
provider: provider2,
rpcUrl: rpcUrlOrCache2,
shouldTime: false,
inputSchema: f.inputSchema
});
Expand Down Expand Up @@ -217,18 +217,19 @@ var require_prove = __commonJS({
var viem_1 = require("viem");
var client_1 = require("@axiom-crypto/client");
var utils_3 = require("@axiom-crypto/client/axiom/utils");
var prove = async (compiledJson, inputs, providerUri, sourceChainId, callbackTarget, callbackExtraData, refundAddress, maxFeePerGas, callbackGasLimit, caller) => {
var address_1 = require("@axiom-crypto/client/lib/address");
var prove = async (compiledJson, inputs, rpcUrl, sourceChainId, callbackTarget, callbackExtraData, refundAddress, maxFeePerGas, callbackGasLimit, caller, targetChainId, bridgeId, broadcaster, blockhashOracle) => {
const { restoreConsole, getCaptures } = (0, utils_2.redirectConsole)();
const decoder = new TextDecoder();
const provider = (0, utils_1.getProvider)(providerUri);
const rpcUrlOrCache = (0, utils_1.getRpcUrl)(rpcUrl);
let compiled = JSON.parse(compiledJson);
const decodedArray = Buffer.from(compiled.circuit, "base64");
const raw = decoder.decode(decodedArray);
const AXIOM_CLIENT_IMPORT = require("@axiom-crypto/client");
const circuit = new js_1.AxiomBaseCircuit({
f: eval(raw),
mock: true,
provider,
rpcUrl: rpcUrlOrCache,
shouldTime: false,
inputSchema: compiled.inputSchema
});
Expand All @@ -246,9 +247,30 @@ var require_prove = __commonJS({
computeResults,
dataQuery
};
let axiomV2QueryAddress;
if (blockhashOracle) {
if (broadcaster) {
throw new Error("Cannot use both broadcaster and blockhash oracle");
}
if (!targetChainId) {
throw new Error("`targetChainId` is required for blockhash oracle bridge type");
}
axiomV2QueryAddress = (0, address_1.getAxiomV2QueryBlockhashOracleAddress)(sourceChainId, targetChainId);
} else if (broadcaster) {
if (!targetChainId) {
throw new Error("`targetChainId` is required for broadcaster bridge type");
}
if (!bridgeId) {
throw new Error("`bridgeId` is required for broadcaster bridge type");
}
axiomV2QueryAddress = (0, address_1.getAxiomV2QueryBroadcasterAddress)(sourceChainId, targetChainId, bridgeId);
} else {
axiomV2QueryAddress = (0, address_1.getAxiomV2QueryAddress)(sourceChainId);
}
let build = await (0, client_1.buildSendQuery)({
chainId: sourceChainId,
providerUri: provider,
rpcUrl: rpcUrlOrCache,
axiomV2QueryAddress,
dataQuery: res.dataQuery,
computeQuery: res.computeQuery,
callback: {
Expand Down Expand Up @@ -295,6 +317,6 @@ var compile_1 = require_compile();
var prove_1 = require_prove();
var program = new commander_1.Command("axiom-std");
program.name("axiom-std").usage("axiom-std CLI");
program.command("readCircuit").description("Read and compile a circuit").argument("<circuitPath>", "path to the typescript circuit file").argument("<providerUri>", "provider to use").option("-q, --override-query-schema <suffix>", "query schema").action(compile_1.compile);
program.command("prove").description("Prove a circuit").argument("<compiledJson>", "compiled json string").argument("<inputs>", "inputs to the circuit").argument("<providerUri>", "provider to use").argument("<sourceChainId>", "source chain id").argument("<callbackTarget>", "callback target").argument("<callbackExtraData>", "callback extra data").argument("<refundAddress>", "refund address").argument("<maxFeePerGas>", "max fee per gas").argument("<callbackGasLimit>", "callback gas limit").argument("<caller>", "caller").action(prove_1.prove);
program.command("readCircuit").description("Read and compile a circuit").argument("<circuitPath>", "path to the typescript circuit file").argument("<rpcUrl>", "JSON-RPC provider to use").option("-q, --override-query-schema <suffix>", "query schema").action(compile_1.compile);
program.command("prove").description("Prove a circuit and generate query results").argument("<compiledJson>", "compiled json string").argument("<inputs>", "inputs to the circuit").argument("<rpcUrl>", "JSON-RPC provider to use").argument("<sourceChainId>", "source chain id").argument("<callbackTarget>", "callback target").argument("<callbackExtraData>", "callback extra data").argument("<refundAddress>", "refund address").argument("<maxFeePerGas>", "max fee per gas").argument("<callbackGasLimit>", "callback gas limit").argument("<caller>", "caller").option("-t, --targetChainId [targetChainId]", "target chain id").option("-b, --bridgeId [bridgeId]", "bridge id", parseInt).option("-br, --broadcaster", "Use crosschain broadcaster").option("-bo, --blockhashOracle", "Use crosschain blockhash oracle").action(prove_1.prove);
program.parseAsync(process.argv);
10 changes: 7 additions & 3 deletions cli/axiom-std-cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,22 +9,26 @@ program.name("axiom-std").usage("axiom-std CLI");
program.command("readCircuit")
.description("Read and compile a circuit")
.argument("<circuitPath>", "path to the typescript circuit file")
.argument("<providerUri>", "provider to use")
.argument("<rpcUrl>", "JSON-RPC provider to use")
.option("-q, --override-query-schema <suffix>", "query schema")
.action(compile);

program.command("prove")
.description("Prove a circuit")
.description("Prove a circuit and generate query results")
.argument("<compiledJson>", "compiled json string")
.argument("<inputs>", "inputs to the circuit")
.argument("<providerUri>", "provider to use")
.argument("<rpcUrl>", "JSON-RPC provider to use")
.argument("<sourceChainId>", "source chain id")
.argument("<callbackTarget>", "callback target")
.argument("<callbackExtraData>", "callback extra data")
.argument("<refundAddress>", "refund address")
.argument("<maxFeePerGas>", "max fee per gas")
.argument("<callbackGasLimit>", "callback gas limit")
.argument("<caller>", "caller")
.option("-t, --targetChainId [targetChainId]", "target chain id")
.option("-b, --bridgeId [bridgeId]", "bridge id", parseInt)
.option("-br, --broadcaster", "Use crosschain broadcaster")
.option("-bo, --blockhashOracle", "Use crosschain blockhash oracle")
.action(prove);

program.parseAsync(process.argv);
8 changes: 4 additions & 4 deletions cli/compile.ts
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
import { AxiomBaseCircuit } from "@axiom-crypto/circuit/js";
import { getFunctionFromTs, getProvider } from "@axiom-crypto/circuit/cliHandler/utils";
import { getFunctionFromTs, getRpcUrl } from "@axiom-crypto/circuit/cliHandler/utils";
import { redirectConsole } from "./utils";
import { encodeAbiParameters, parseAbiParameters } from "viem";

export const compile = async (
circuitPath: string,
providerUri: string,
rpcUrl: string,
options: { overrideQuerySchema?: string }
) => {
const { restoreConsole, getCaptures } = redirectConsole();
let circuitFunction = "circuit";
const f = await getFunctionFromTs(circuitPath, circuitFunction);
const provider = getProvider(providerUri);
const rpcUrlOrCache = getRpcUrl(rpcUrl);
const circuit = new AxiomBaseCircuit({
f: f.circuit,
mock: true,
provider,
rpcUrl: rpcUrlOrCache,
shouldTime: false,
inputSchema: f.inputSchema,
})
Expand Down
41 changes: 36 additions & 5 deletions cli/prove.ts
Original file line number Diff line number Diff line change
@@ -1,26 +1,35 @@
import { AxiomBaseCircuit } from "@axiom-crypto/circuit/js";
import { getProvider } from "@axiom-crypto/circuit/cliHandler/utils";
import { getRpcUrl } from "@axiom-crypto/circuit/cliHandler/utils";
import { getInputs, redirectConsole } from './utils';
import { encodeAbiParameters, parseAbiParameters } from 'viem';
import { buildSendQuery } from "@axiom-crypto/client";
import { argsArrToObj } from '@axiom-crypto/client/axiom/utils';
import {
getAxiomV2QueryAddress,
getAxiomV2QueryBroadcasterAddress,
getAxiomV2QueryBlockhashOracleAddress
} from '@axiom-crypto/client/lib/address';

export const prove = async (
compiledJson: string,
inputs: string,
providerUri: string,
rpcUrl: string,
sourceChainId: string,
callbackTarget: string,
callbackExtraData: string,
refundAddress: string,
maxFeePerGas: string,
callbackGasLimit: string,
caller: string,
targetChainId?: string,
yi-sun marked this conversation as resolved.
Show resolved Hide resolved
bridgeId?: number,
broadcaster?: boolean,
blockhashOracle?: boolean,
) => {
const { restoreConsole, getCaptures } = redirectConsole();
const decoder = new TextDecoder();

const provider = getProvider(providerUri);
const rpcUrlOrCache = getRpcUrl(rpcUrl);
let compiled = JSON.parse(compiledJson);

const decodedArray = Buffer.from(compiled.circuit, 'base64');
Expand All @@ -30,7 +39,7 @@ export const prove = async (
const circuit = new AxiomBaseCircuit({
f: eval(raw),
mock: true,
provider,
rpcUrl: rpcUrlOrCache,
shouldTime: false,
inputSchema: compiled.inputSchema,
})
Expand All @@ -53,9 +62,31 @@ export const prove = async (
dataQuery,
}

let axiomV2QueryAddress;
if (blockhashOracle) {
if (broadcaster) {
throw new Error("Cannot use both broadcaster and blockhash oracle");
}
if (!targetChainId) {
throw new Error("`targetChainId` is required for blockhash oracle bridge type");
}
axiomV2QueryAddress = getAxiomV2QueryBlockhashOracleAddress(sourceChainId, targetChainId);
yi-sun marked this conversation as resolved.
Show resolved Hide resolved
} else if (broadcaster) {
if (!targetChainId) {
throw new Error("`targetChainId` is required for broadcaster bridge type");
}
if (!bridgeId) {
throw new Error("`bridgeId` is required for broadcaster bridge type");
}
axiomV2QueryAddress = getAxiomV2QueryBroadcasterAddress(sourceChainId, targetChainId, bridgeId);
yi-sun marked this conversation as resolved.
Show resolved Hide resolved
} else {
axiomV2QueryAddress = getAxiomV2QueryAddress(sourceChainId);
}

let build = await buildSendQuery({
chainId: sourceChainId,
providerUri: provider,
rpcUrl: rpcUrlOrCache,
axiomV2QueryAddress,
dataQuery: res.dataQuery,
computeQuery: res.computeQuery,
callback: {
yi-sun marked this conversation as resolved.
Show resolved Hide resolved
Expand Down
Loading
Loading