Skip to content
This repository has been archived by the owner on Mar 3, 2024. It is now read-only.

Commit

Permalink
Merge pull request #78 from hyperoracle/dev
Browse files Browse the repository at this point in the history
Refactor and Compatibility Updates for zkGraph API
  • Loading branch information
nom4dv3 authored Oct 8, 2023
2 parents dff7f36 + f00ed31 commit aae0163
Show file tree
Hide file tree
Showing 16 changed files with 3,411 additions and 275 deletions.
30 changes: 30 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
name: Release

permissions:
contents: write

on:
push:
tags:
- 'v*'

jobs:
release:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0

- name: Install pnpm
uses: pnpm/action-setup@v2

- name: Set node
uses: actions/setup-node@v3
with:
node-version: 18.x
cache: pnpm

- run: npx changelogithub
env:
GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}}
8 changes: 8 additions & 0 deletions api/compile.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
import fs from "fs";
import path from "path";
import { fileURLToPath } from "url";
import { currentNpmScriptName, logDivider } from "./common/log_utils.js";
import { config } from "../config.js";
import * as zkgapi from "@hyperoracle/zkgraph-api";
Expand All @@ -18,6 +21,11 @@ if (currentNpmScriptName() === "compile-local") {
);
} else if (currentNpmScriptName() === "compile") {
// Compile Remotely
const dirname = path.dirname(fileURLToPath(import.meta.url));
const yamlContent = fs.readFileSync(
path.join(dirname, "../src/zkgraph.yaml"),
"utf8",
);
let isCompilationSuccess = await zkgapi.compile(
config.WasmBinPath,
config.WasmBinPath.replace(/\.wasm/, ".wat"),
Expand Down
9 changes: 7 additions & 2 deletions api/deploy.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
import fs from "fs";
import path from "path";
import { fileURLToPath } from "url";
import { program } from "commander";
import { config } from "../config.js";
import { getTargetNetwork } from "./common/utils.js";
Expand Down Expand Up @@ -37,9 +40,11 @@ if (currentNpmScriptName() === "deploy-local") {
} else if (currentNpmScriptName() === "deploy") {
wasmPath = config.WasmBinPath;
}

const dirname = path.dirname(fileURLToPath(import.meta.url));
const wasm = fs.readFileSync(path.join(dirname, "../", wasmPath));
const wasmUnit8Array = new Uint8Array(wasm);
const deployedVerificationContractAddress = await zkgapi.deploy(
wasmPath,
wasmUnit8Array,
targetNetwork.value,
config.ZkwasmProviderUrl,
config.UserPrivateKey,
Expand Down
17 changes: 14 additions & 3 deletions api/exec.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
import fs from "fs";
import path from "path";
import { fileURLToPath } from "url";
import { program } from "commander";
import { currentNpmScriptName, logDivider } from "./common/log_utils.js";
import { config } from "../config.js";
Expand Down Expand Up @@ -34,16 +37,24 @@ if (currentNpmScriptName() === "exec-local") {

let basePath = import.meta.url + "/../../";

const dirname = path.dirname(fileURLToPath(import.meta.url));

const JsonRpcProviderUrl = loadJsonRpcProviderUrl("src/zkgraph.yaml", true);
const provider = new providers.JsonRpcProvider(JsonRpcProviderUrl);
await validateProvider(provider);

let rawReceiptList = await zkgapi.getRawReceipts(provider, blockid, false);

const wasm = fs.readFileSync(path.join(dirname, "../", wasmPath));
const wasmUnit8Array = new Uint8Array(wasm);
const yamlContent = fs.readFileSync(
path.join(dirname, "../src/zkgraph.yaml"),
"utf8",
);

let state = await zkgapi.executeOnRawReceipts(
basePath,
wasmPath,
"src/zkgraph.yaml",
wasmUnit8Array,
yamlContent,
rawReceiptList,
isLocal,
true,
Expand Down
18 changes: 14 additions & 4 deletions api/prove.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
// usage: node prove.js [--inputgen/test] <blocknum/blockhash> <state> -> wasm input
// TODO: add -o --outfile <file> under inputgen mode
import fs from "fs";
import path from "path";
import { fileURLToPath } from "url";
import { program } from "commander";
import { currentNpmScriptName, logDivider } from "./common/log_utils.js";
import { config } from "../config.js";
Expand Down Expand Up @@ -83,8 +86,16 @@ const blockNumber = parseInt(block.number);
const blockHash = block.hash;
const receiptsRoot = block.receiptsRoot;

const dirname = path.dirname(fileURLToPath(import.meta.url));
const wasm = fs.readFileSync(path.join(dirname, "../", wasmPath));
const wasmUnit8Array = new Uint8Array(wasm);
const yamlContent = fs.readFileSync(
path.join(dirname, "../src/zkgraph.yaml"),
"utf8",
);

let [privateInputStr, publicInputStr] = await zkgapi.proveInputGenOnRawReceipts(
"src/zkgraph.yaml",
yamlContent,
rawReceiptList,
blockNumber,
blockHash,
Expand All @@ -107,8 +118,7 @@ switch (options.inputgen || options.test || options.prove) {
let basePath = import.meta.url + "/../../";

let mock_succ = await zkgapi.proveMock(
basePath,
wasmPath,
wasmUnit8Array,
privateInputStr,
publicInputStr,
);
Expand All @@ -123,7 +133,7 @@ switch (options.inputgen || options.test || options.prove) {
// Prove mode
case options.prove === true:
let result = await zkgapi.prove(
wasmPath,
wasmUnit8Array,
privateInputStr,
publicInputStr,
config.ZkwasmProviderUrl,
Expand Down
11 changes: 10 additions & 1 deletion api/publish.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
// npm run publish 0x0000000000000000000000000000000000000000 Qmcpu8YNbHpjnEpxe5vUkz8TZYzv8oCbiUGj3a66rNngjQ 0.1
import fs from "fs";
import path from "path";
import { fileURLToPath } from "url";
import { program } from "commander";
import { logDivider } from "./common/log_utils.js";
import * as zkgapi from "@hyperoracle/zkgraph-api";
Expand Down Expand Up @@ -35,8 +38,14 @@ bountyRewardPerTrigger *= Math.pow(10, 9);

const JsonRpcProviderUrl = loadJsonRpcProviderUrl("src/zkgraph.yaml", false);

const dirname = path.dirname(fileURLToPath(import.meta.url));
const yamlContent = fs.readFileSync(
path.join(dirname, "../src/zkgraph.yaml"),
"utf8",
);

const publishTxHash = await zkgapi.publish(
"src/zkgraph.yaml",
yamlContent,
JsonRpcProviderUrl,
deployedContractAddress,
ipfsHash,
Expand Down
10 changes: 9 additions & 1 deletion api/setup.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
import fs from "fs";
import path from "path";
import { fileURLToPath } from "url";
import { config } from "../config.js";
import { currentNpmScriptName, logDivider } from "./common/log_utils.js";
import * as zkgapi from "@hyperoracle/zkgraph-api";
Expand Down Expand Up @@ -32,8 +35,13 @@ if (options.circuitSize !== undefined) {
// Log script name
console.log(">> SET UP", "\n");

const dirname = path.dirname(fileURLToPath(import.meta.url));
const wasm = fs.readFileSync(path.join(dirname, "../", wasmPath));
const wasmUnit8Array = new Uint8Array(wasm);

let { md5, taskId, success } = await zkgapi.setup(
wasmPath,
"poc.wasm",
wasmUnit8Array,
cirSz,
config.UserPrivateKey,
config.ZkwasmProviderUrl,
Expand Down
13 changes: 10 additions & 3 deletions api/verify.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
import fs from "fs";
import path from "path";
import { fileURLToPath } from "url";
import { program } from "commander";
import * as zkgapi from "@hyperoracle/zkgraph-api";
import { config } from "../config.js";
import { logDivider } from "./common/log_utils.js";

// npm run verify 64e52295abac08978a0e46cf
// npm run verify 64fee557abfa8fdad38d73f3

program.version("1.0.0");
program.argument("<prove task id>", "Task id of prove task");
Expand All @@ -15,9 +18,13 @@ console.log(">> VERIFY PROOF ONCHAIN", "\n");

// Inputs from command line
const taskId = args[0];

const dirname = path.dirname(fileURLToPath(import.meta.url));
const yamlContent = fs.readFileSync(
path.join(dirname, "../src/zkgraph.yaml"),
"utf8",
);
const verifyResult = await zkgapi.verify(
"src/zkgraph.yaml",
yamlContent,
taskId,
config.ZkwasmProviderUrl,
true,
Expand Down
5 changes: 0 additions & 5 deletions example/hello/zkgraph.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,3 @@ dataSources:
eventHandlers:
- event: "Sync(uint112,uint112)"
handler: handleEvents
dataDestinations:
- kind: ethereum/contract
network: sepolia
destination:
address: "0x0000000000000000000000000000000000000000"
5 changes: 0 additions & 5 deletions example/multiaddr/zkgraph.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,3 @@ dataSources:
eventHandlers:
- event: "SubmissionReceived(int256,uint32,address)"
handler: handleEvents
dataDestinations:
- kind: ethereum/contract
network: sepolia
destination:
address: "0x0000000000000000000000000000000000000000"
5 changes: 0 additions & 5 deletions example/uniswapprice/zkgraph.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,3 @@ dataSources:
eventHandlers:
- event: "Sync(uint112,uint112)"
handler: handleEvents
dataDestinations:
- kind: ethereum/contract
network: sepolia
destination:
address: "0x0000000000000000000000000000000000000000"
11 changes: 11 additions & 0 deletions example/zkauto/mapping.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
//@ts-ignore
import { require } from "@hyperoracle/zkgraph-lib";
import { Bytes, Event, BigInt, ByteArray } from "@hyperoracle/zkgraph-lib";

export function handleEvents(events: Event[]): Bytes {
// run() - keccak256 c0406226a44c49a673ef01611ce55e97850e1c520ac5d22c6854eb2dbaee7040
let tmp = Bytes.fromHexString(
"c0406226a44c49a673ef01611ce55e97850e1c520ac5d22c6854eb2dbaee7040",
);
return Bytes.fromHexString("c0406226").padEnd(32);
}
23 changes: 23 additions & 0 deletions example/zkauto/zkgraph.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
specVersion: 0.0.1
name: ex_hello
description: Demo graph for zkAutomation. Use greeting string as the trigger payload.
repository: https://github.com/hyperoracle/zkgraph
dataSources:
- kind: ethereum/contract
network: sepolia
source:
address: '0x362b63b77448C2ffBC03511FE100fCd3d879795F'
mapping:
kind: ethereum/events
apiVersion: 0.0.1
language: wasm/assemblyscript
file: ./mapping.ts
eventHandlers:
- event: 'eventTriggered(uint256,uint256)'
handler: handleEvents
# dataDestinations field is required for zkAutomation.
dataDestinations:
- kind: ethereum/contract
network: sepolia
destination:
address: '0x362b63b77448C2ffBC03511FE100fCd3d879795F'
Loading

0 comments on commit aae0163

Please sign in to comment.