Skip to content

Commit

Permalink
devex improvements + testing (#45)
Browse files Browse the repository at this point in the history
Co-authored-by: Yu Jiang Tham <[email protected]>
  • Loading branch information
rpalakkal and ytham authored Dec 14, 2023
1 parent 4f990f5 commit 55846d5
Show file tree
Hide file tree
Showing 48 changed files with 1,298 additions and 1,360 deletions.
47 changes: 47 additions & 0 deletions .github/workflows/halo2-browser-tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
name: halo2-browser Tests

on:
push:
paths:
- "halo2-wasm/**"
- "halo2-lib-js/**"

jobs:
halo2-wasm-tests:
runs-on: ubuntu-latest-64core-256ram
steps:
- uses: actions/checkout@v3
- name: Build halo2-wasm
working-directory: halo2-wasm
run: |
rustup toolchain install nightly-2023-08-12-x86_64-unknown-linux-gnu
rustup component add rust-src --toolchain nightly-2023-08-12-x86_64-unknown-linux-gnu
cargo build --target=x86_64-unknown-linux-gnu --verbose
- name: Test halo2-wasm
working-directory: halo2-wasm
run: cargo test --target=x86_64-unknown-linux-gnu
halo2-lib-js-tests:
runs-on: ubuntu-latest-64core-256ram
steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v4
with:
node-version: 18
- name: Build halo2-wasm
working-directory: halo2-wasm
run: |
rustup toolchain install nightly-2023-08-12-x86_64-unknown-linux-gnu
rustup component add rust-src --toolchain nightly-2023-08-12-x86_64-unknown-linux-gnu
cargo build --target=x86_64-unknown-linux-gnu --verbose
- name: Build halo2-lib-js
working-directory: halo2-lib-js
run: |
npm install
npm add @axiom-crypto/[email protected]
- name: Test halo2-lib-js/halo2-wasm VK equivalence
working-directory: halo2-lib-js
run: npm run test:vk
- name: Test halo2-lib-js constant equivalence
working-directory: halo2-lib-js
run: npm run test:constant

23 changes: 0 additions & 23 deletions .github/workflows/halo2-wasm-tests.yml

This file was deleted.

7 changes: 4 additions & 3 deletions cli/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "halo2-wasm-cli",
"version": "0.1.0",
"name": "@axiom-crypto/halo2-wasm-cli",
"version": "0.1.5",
"description": "Halo2 Javascript library",
"main": "index.js",
"scripts": {
Expand All @@ -18,7 +18,8 @@
"author": "Intrinsic Technologies",
"license": "ISC",
"dependencies": {
"@axiom-crypto/halo2-wasm": "^0.2.3",
"@axiom-crypto/halo2-lib-js": "0.2.13-alpha.1",
"@axiom-crypto/halo2-wasm": "0.2.10",
"commander": "^11.1.0",
"typescript": "^5.2.2"
},
Expand Down
84 changes: 80 additions & 4 deletions cli/pnpm-lock.yaml

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

2 changes: 0 additions & 2 deletions cli/scripts/postTsc.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

const fs = require('fs');
const packageJson = require('../package.json');
const halo2WasmPackageJson = require('../../halo2-wasm/package.json');
const { execSync } = require('child_process');

// Copies a modified version of package.json to the /dist folder
Expand All @@ -11,7 +10,6 @@ function copyPackageJson() {
delete packageJsonCopy.scripts;
delete packageJsonCopy.devDependencies;
delete packageJsonCopy.publishConfig;
packageJsonCopy.dependencies['@axiom-crypto/halo2-wasm'] = halo2WasmPackageJson.version;
packageJsonCopy.bin = {
'halo2-wasm': './index.js',
};
Expand Down
5 changes: 3 additions & 2 deletions cli/src/examples/circuit.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
//@ts-ignore -- to avoid halo2-lib-js being a dependency of the cli
export const circuit = async (halo2Lib: Halo2Lib, inputs: {x: number}) => {
const {add, sub, mul, constant, witness, log, rangeCheck, makePublic, isLessThan} = halo2Lib;
import {add, sub, mul, constant, witness, log, rangeCheck, makePublic, isLessThan} from "@axiom-crypto/halo2-lib-js";

export const circuit = async (inputs: {x: number}) => {
const x = witness(inputs.x);
const a = witness(1);
const b = witness(2);
Expand Down
2 changes: 1 addition & 1 deletion cli/src/examples/run.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ export const run = async (halo2wasm: any, halo2Lib: any, config: any, circuit: a
//@ts-ignore -- to avoid halo2-lib-js being a dependency of the cli
const { Halo2CircuitRunner } = await import("@axiom-crypto/halo2-lib-js");
await Halo2CircuitRunner(halo2wasm, halo2Lib, config).run(circuit, inputs);
}
}
4 changes: 2 additions & 2 deletions cli/src/keygen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ export const keygen = async (path: string, options: { pk: string, vk: string, ci
try {
await scaffold.populateCircuit(circuit.circuit, circuit.inputs);
await scaffold.keygen();
const vk = scaffold.exportVk();
const vk = scaffold.exportVkBuffer();
saveBufferToFile(vk, options.vk, "VK")
const pk = scaffold.exportPk();
const pk = scaffold.exportPkBuffer();
saveBufferToFile(pk, options.pk, "PK")
}
catch (e) {
Expand Down
6 changes: 3 additions & 3 deletions cli/src/scaffold.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,12 @@ export class CircuitScaffold extends ICircuitScaffold {
this.halo2wasm.assignInstances();
}

exportVk() {
exportVkBuffer() {
const vk = this.halo2wasm.getVk();
return Buffer.from(vk);
}

exportPk() {
exportPkBuffer() {
const pk = this.halo2wasm.getPk();
return Buffer.from(pk);
}
Expand All @@ -42,7 +42,7 @@ export class CircuitScaffold extends ICircuitScaffold {
this.halo2wasm.loadPk(pk);
}

exportProof() {
exportProofBuffer() {
const proof = this.halo2wasm.prove();
return Buffer.from(proof);
}
Expand Down
27 changes: 25 additions & 2 deletions cli/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,26 @@ export async function getFunctionFromTs(relativePath: string, shouldCircuitFunct
compilerOptions: { module: ts.ModuleKind.CommonJS }
});
const script = new vm.Script(result.outputText);
const customRequire = (moduleName: string) => {
try {
if (moduleName === "@axiom-crypto/halo2-lib-js") {
return require("@axiom-crypto/halo2-lib-js");
}
else {
const npmRoot = execSync('npm root').toString().trim();
return require(`${npmRoot}/${moduleName}`);
}
} catch (e) {
throw new Error(`Cannot find module '${moduleName}'.\n Try installing it globally with 'npm install -g ${moduleName}'`);
}
};
const context = vm.createContext({
exports: {},
require: customRequire,
module: module,
console: console,
__filename: __filename,
__dirname: __dirname,
});
script.runInContext(context);
if (shouldCircuitFunctionExist && !context.exports.circuit) throw new Error("File does not export a `circuit` function");
Expand Down Expand Up @@ -50,8 +68,13 @@ export async function getRunCircuitFromTs(relativePath: string | undefined) {
const script = new vm.Script(result.outputText);
const customRequire = (moduleName: string) => {
try {
const npmRoot = execSync('npm root -g').toString().trim();
return require(`${npmRoot}/${moduleName}`);
if (moduleName === "@axiom-crypto/halo2-lib-js") {
return require("@axiom-crypto/halo2-lib-js");
}
else {
const npmRoot = execSync('npm root').toString().trim();
return require(`${npmRoot}/${moduleName}`);
}
} catch (e) {
throw new Error(`Cannot find module '${moduleName}'.\n Try installing it globally with 'npm install -g ${moduleName}'`);
}
Expand Down
2 changes: 1 addition & 1 deletion halo2-lib-js/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,4 @@ public/kzg_bn256_19.bin
public/kzg_bn256_20.bin

my.d.ts
src/shared/docs/build.d.ts
src/shared/build.d.ts
10 changes: 6 additions & 4 deletions halo2-lib-js/package.json
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
{
"name": "@axiom-crypto/halo2-lib-js",
"version": "0.2.9",
"version": "0.2.13",
"description": "Halo2 Javascript library",
"main": "index.js",
"scripts": {
"build": "rm -rf ./dist && pnpm build:docs && tsc && node ./scripts/postTsc.js",
"build:docs": "./node_modules/.bin/dts-bundle-generator src/shared/docs/halo2Docs.d.ts -o src/shared/docs/build.d.ts --external-inlines=@axiom-crypto/halo2-wasm && node ./scripts/convertDTs.js"
"build": "rm -rf ./dist && tsc && node ./scripts/postTsc.js && pnpm build:docs",
"build:docs": "./node_modules/.bin/dts-bundle-generator ./dist/halo2lib/functions.d.ts -o src/shared/build.d.ts && node ./scripts/convertDTs.js && rm -rf ./src/shared/build.d.ts",
"test:vk": "./tests/test_vk.sh",
"test:constant": "./tests/test_constant.sh"
},
"keywords": [
"axiom",
Expand All @@ -30,7 +32,7 @@
"typescript": "^5.2.2"
},
"dependencies": {
"@axiom-crypto/halo2-wasm": "0.2.7",
"@axiom-crypto/halo2-wasm": "0.2.10",
"ethers": "^6.8.0",
"prettier": "1.18.2"
},
Expand Down
Loading

0 comments on commit 55846d5

Please sign in to comment.