Skip to content

Commit

Permalink
Merge branch 'refs/heads/master' into feature/memory-size-option
Browse files Browse the repository at this point in the history
# Conflicts:
#	build/main.cjs
#	js/witness_calculator.js
  • Loading branch information
OBrezhniev committed Sep 7, 2024
2 parents 65078a3 + 494730a commit 30bcddf
Show file tree
Hide file tree
Showing 4 changed files with 96 additions and 7 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Continuous Integration
name: JS Witness calc tests
on:
push:
branches:
Expand Down
77 changes: 77 additions & 0 deletions .github/workflows/integration-test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
name: Snarkjs Integration Test
on:
push:
branches:
- master
pull_request:

jobs:
test:
name: Test
runs-on: ${{ matrix.os }}

strategy:
fail-fast: false
matrix:
os: [ubuntu-latest]
node-version: ["18", "20", "22"]

steps:
- name: Checkout project
uses: actions/checkout@v4
with:
path: circom_runtime

- name: Checkout project
uses: actions/checkout@v4
with:
repository: iden3/snarkjs
path: snarkjs

- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node-version }}
check-latest: true
cache: 'npm'
cache-dependency-path: snarkjs/package-lock.json

- name: Install circom_runtime dependencies
run: npm ci
working-directory: circom_runtime

- name: Build circom_runtime
run: npm run build
working-directory: circom_runtime

- name: Install circom_runtime to snarkjs as a link
run: npm install ../circom_runtime
working-directory: snarkjs

- name: Install snarkjs dependencies
run: npm ci
working-directory: snarkjs

- name: Build snarkjs
run: npm run build
working-directory: snarkjs

- name: Run snarkjs tests
run: npm test
working-directory: snarkjs

- name: Install smart_contract_tests dependencies
working-directory: snarkjs/smart_contract_tests
run: npm ci

- name: Run smart_contract_tests
working-directory: snarkjs/smart_contract_tests
run: npm test

- name: Install browser dependencies
working-directory: snarkjs/browser_tests
run: npm ci

- name: Run browser tests
working-directory: snarkjs/browser_tests
run: npm test
12 changes: 9 additions & 3 deletions build/main.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -95,11 +95,13 @@ async function builder(code, options) {
// If we can't look up the patch version, assume the lowest
let patchVersion = 0;

let codeIsWebAssemblyInstance = false;

// If code is already prepared WebAssembly.Instance, we use it directly
if (code instanceof WebAssembly.Instance) {
instance = code;
codeIsWebAssemblyInstance = true;
} else {

let memorySize = 32767;

if (options.memorySize) {
Expand Down Expand Up @@ -259,9 +261,13 @@ async function builder(code, options) {
// We explicitly check for major version 2 in case there's a circom v3 in the future
if (majorVersion === 2) {
wc = new WitnessCalculatorCircom2(instance, sanityCheck);
} else {
// TODO: Maybe we want to check for the explicit version 1 before choosing this?
} else if (majorVersion === 1) {
if (codeIsWebAssemblyInstance) {
throw new Error('Loading code from WebAssembly instance is not supported for circom version 1');
}
wc = new WitnessCalculatorCircom1(memory, instance, sanityCheck);
} else {
throw new Error(`Unsupported circom version: ${majorVersion}`);
}
return wc;

Expand Down
12 changes: 9 additions & 3 deletions js/witness_calculator.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,13 @@ export default async function builder(code, options) {
// If we can't look up the patch version, assume the lowest
let patchVersion = 0;

let codeIsWebAssemblyInstance = false;

// If code is already prepared WebAssembly.Instance, we use it directly
if (code instanceof WebAssembly.Instance) {
instance = code;
codeIsWebAssemblyInstance = true;
} else {

let memorySize = 32767;

if (options.memorySize) {
Expand Down Expand Up @@ -199,9 +201,13 @@ export default async function builder(code, options) {
// We explicitly check for major version 2 in case there's a circom v3 in the future
if (majorVersion === 2) {
wc = new WitnessCalculatorCircom2(instance, sanityCheck);
} else {
// TODO: Maybe we want to check for the explicit version 1 before choosing this?
} else if (majorVersion === 1) {
if (codeIsWebAssemblyInstance) {
throw new Error('Loading code from WebAssembly instance is not supported for circom version 1');
}
wc = new WitnessCalculatorCircom1(memory, instance, sanityCheck);
} else {
throw new Error(`Unsupported circom version: ${majorVersion}`);
}
return wc;

Expand Down

0 comments on commit 30bcddf

Please sign in to comment.