Skip to content

Commit

Permalink
Merge branch 'main' into feat/cli
Browse files Browse the repository at this point in the history
  • Loading branch information
rpalakkal authored Oct 28, 2023
2 parents 94cd64a + 722488a commit 8737bac
Showing 3 changed files with 25 additions and 23 deletions.
6 changes: 3 additions & 3 deletions halo2-lib-js/src/halo2lib/functions.ts
Original file line number Diff line number Diff line change
@@ -27,7 +27,7 @@ export class Halo2Lib {
return maxPaddedNumBits.toString()
}

private getPaddedNumBits(numBits: string) {
private getValidatedNumBits(numBits: string) {
if(Number(numBits) > Number(this._MAX_BITS)) throw new Error(`Number of bits must be less than ${this._MAX_BITS}`);
return numBits;
}
@@ -286,7 +286,7 @@ export class Halo2Lib {
checkLessThan = (a: CircuitValue, b: CircuitValue, c: string = this._MAX_BITS) => {
this.rangeCheck(a, convertInput(c));
this.rangeCheck(b, convertInput(c));
this. _halo2lib.check_less_than(a.cell(), b.cell(), this.getPaddedNumBits(c));
this. _halo2lib.check_less_than(a.cell(), b.cell(), this.getValidatedNumBits(c));
}

/**
@@ -300,7 +300,7 @@ export class Halo2Lib {
isLessThan = (a: CircuitValue, b: CircuitValue, c: string = this._MAX_BITS) => {
this.rangeCheck(a, convertInput(c));
this.rangeCheck(b, convertInput(c));
return this.Cell(this. _halo2lib.is_less_than(a.cell(), b.cell(), this.getPaddedNumBits(c)));
return this.Cell(this. _halo2lib.is_less_than(a.cell(), b.cell(), this.getValidatedNumBits(c)));
}

/**
38 changes: 20 additions & 18 deletions halo2-repl/app/page.tsx
Original file line number Diff line number Diff line change
@@ -33,6 +33,7 @@ function App() {
const router = useRouter();
const [circuitVk, setCircuitVk] = useState<Uint8Array | null>(null);
const [proof, setProof] = useState<Uint8Array | null>(null);
const [shouldRestartWorker, setShouldRestartWorker] = useState(true);
const logsEndRef = useRef<HTMLDivElement>(null)

const [initialSizesHorizontal, setInitialSizesHorizontal] = useState([70, 30])
@@ -99,14 +100,17 @@ function App() {
}, []);

useEffect(() => {
const setupWorker = async () => {
const worker = new Worker(new URL("./worker", import.meta.url));
const Halo2Circuit = wrap<typeof Halo2Repl>(worker);
workerApi.current = await new Halo2Circuit();
workerApi.current.setup(navigator.hardwareConcurrency);
if (shouldRestartWorker) {
const setupWorker = async () => {
const worker = new Worker(new URL("./worker", import.meta.url));
const Halo2Circuit = wrap<typeof Halo2Repl>(worker);
workerApi.current = await new Halo2Circuit();
workerApi.current.setup(navigator.hardwareConcurrency);
}
setupWorker();
setShouldRestartWorker(false);
}
setupWorker();
}, []);
}, [shouldRestartWorker]);

const getGithubAccessToken = async () => {
const code = searchParams.get("code");
@@ -163,22 +167,20 @@ function App() {
await cb();
}
catch (e: any) {
if (e.message === "unreachable") {
appendError("halo2-wasm error: please check developer console for more information.")
}
else if (e.message === "Cannot read properties of undefined (reading 'halo2wasm_new')") {
appendLogs("Please wait. Still loading halo2-wasm.")
if (shouldRestartWorker || e.message === "Cannot read properties of undefined (reading 'config')") {
appendError("Please wait. Still loading halo2-wasm.");
}
else if (e.message === "Cannot read properties of undefined (reading 'prove_snark')") {
appendError("Must run key generation before proof generation.")
}
else if (e.message === "undefined is not an object (evaluating 'this.halo2wasm.config')") {
appendLogs("Please wait. Still loading halo2-wasm.")
else if (e.message === "unreachable") {
setShouldRestartWorker(true);
workerApi.current = undefined;
appendError("halo2-wasm error: please check developer console for more information.")
}
else {
setShouldRestartWorker(true);
workerApi.current = undefined;
appendError(e.message);
}

console.error(e);
}
await workerApi.current?.stopConsoleCapture();
}
4 changes: 2 additions & 2 deletions halo2-wasm/template/build.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/bin/bash
set -e

rm -r pkg
rm -rf pkg

TARGET=$1

@@ -20,4 +20,4 @@ mv pkg/halo2_wasm_template.d.ts pkg/index.d.ts

if [ "$TARGET" == "nodejs" ]; then
sed -i '' "s/require('env')/{memory: new WebAssembly.Memory({initial: 100,maximum: 65536,shared: true,})}/g" pkg/index.js
fi
fi

0 comments on commit 8737bac

Please sign in to comment.