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 #40

Merged
merged 11 commits into from
Jul 17, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,5 +37,5 @@ jobs:

- name: Run Foundry tests
run: |
export PROVIDER_URI_11155111=${{ secrets.PROVIDER_URI_11155111 }}
export RPC_URL_11155111=${{ secrets.RPC_URL_11155111 }}
RUST_BACKTRACE=1 forge test -vvv
57 changes: 57 additions & 0 deletions app/index-crosschain.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
import { AxiomCrosschain, BridgeType, UserInput } from '@axiom-crypto/client';
import { circuit, CircuitInputs } from "./axiom/average.circuit";
import { chainIdToPathname } from "./utils";
import dotenv from "dotenv";
dotenv.config();

// Inputs to the circuit
import inputs from './axiom/data/inputs.json';

// Compiled circuit file after running:
// `npx axiom circuit compile app/axiom/average.circuit.ts`
import compiledCircuit from "./axiom/data/compiled.json";

const SOURCE_CHAIN_ID = "11155111";
const TARGET_CHAIN_ID = "84532";
const SOURCE_RPC_URL = process.env[`RPC_URL_${SOURCE_CHAIN_ID}`];
const TARGET_RPC_URL = process.env[`RPC_URL_${TARGET_CHAIN_ID}`];

if (!SOURCE_RPC_URL || !TARGET_RPC_URL) {
console.error(`RPC URLs must be provided for env vars \`RPC_URL_${SOURCE_CHAIN_ID}\` and \`RPC_URL_${TARGET_CHAIN_ID}\`.`);
process.exit(1);
}

const axiomMain = async (input: UserInput<CircuitInputs>) => {
const axiom = new AxiomCrosschain({
circuit,
compiledCircuit,
source: {
chainId: SOURCE_CHAIN_ID,
rpcUrl: SOURCE_RPC_URL,
},
target: {
chainId: TARGET_CHAIN_ID,
rpcUrl: TARGET_RPC_URL,
privateKey: process.env[`PRIVATE_KEY_${TARGET_CHAIN_ID}`] as string,
},
bridgeType: BridgeType.BlockhashOracle,
callback: {
target: "0x19cB3D866B711EeCbCF76C3f2f9eE1212d672430",
},
});
await axiom.init();
const args = await axiom.prove(input);
console.log("ZK proof generated successfully.");

if (!process.env[`PRIVATE_KEY_${TARGET_CHAIN_ID}`]) {
console.log(`No private key provided for env var \`PRIVATE_KEY_${TARGET_CHAIN_ID}\`: Query will not be sent to the blockchain.`);
return;
}

console.log("Sending Query to Axiom on-chain...");
const receipt = await axiom.sendQuery();
console.log("Transaction receipt:", receipt);
console.log(`View your Query on Axiom Explorer: https://explorer.axiom.xyz/v2/${chainIdToPathname(TARGET_CHAIN_ID)}/${chainIdToPathname(SOURCE_CHAIN_ID)}/query/${args.queryId}`);
};

axiomMain(inputs);
8 changes: 4 additions & 4 deletions app/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@ import inputs from './axiom/data/inputs.json';
// `npx axiom circuit compile app/axiom/average.circuit.ts`
import compiledCircuit from "./axiom/data/compiled.json";


const CHAIN_ID = "11155111";
const RPC_URL = process.env[`RPC_URL_${CHAIN_ID}`];

if (!process.env[`PROVIDER_URI_${CHAIN_ID}`]) {
console.error(`No provider URI provided for env var \`PROVIDER_URI_${CHAIN_ID}\`.`);
if (!RPC_URL) {
console.error(`RPC URL must be provided for env var \`RPC_URL_${CHAIN_ID}\`.`);
process.exit(1);
}

Expand All @@ -24,7 +24,7 @@ const axiomMain = async (input: UserInput<CircuitInputs>) => {
circuit: circuit,
compiledCircuit: compiledCircuit,
chainId: CHAIN_ID, // Sepolia
provider: process.env[`PROVIDER_URI_${CHAIN_ID}`] as string,
rpcUrl: process.env[`RPC_URL_${CHAIN_ID}`] as string,
privateKey: process.env[`PRIVATE_KEY_${CHAIN_ID}`] as string,
callback: {
target: "0x4A4e2D8f3fBb3525aD61db7Fc843c9bf097c362e",
Expand Down
21 changes: 11 additions & 10 deletions foundry.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,16 @@ ast = true

# See more config options https://github.com/foundry-rs/foundry/tree/master/config
[rpc_endpoints]
provider = "${PROVIDER_URI_11155111}"
source_provider = "${RPC_URL_11155111}"
target_provider = "${RPC_URL_84532}"

[fmt]
bracket_spacing = true
int_types = "long"
line_length = 120
multiline_func_header = "attributes_first"
number_underscore = "thousands"
quote_style = "double"
single_line_statement_blocks = "multi"
tab_width = 4
wrap_comments = false
bracket_spacing = true
int_types = "long"
line_length = 120
multiline_func_header = "attributes_first"
number_underscore = "thousands"
quote_style = "double"
single_line_statement_blocks = "multi"
tab_width = 4
wrap_comments = false
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"author": "Intrinsic Technologies",
"license": "MIT",
"dependencies": {
"@axiom-crypto/client": "2.0.9",
"@axiom-crypto/client": "2.1.0",
"dotenv": "^16.3.1"
},
"devDependencies": {
Expand Down
Loading
Loading