Skip to content

Commit

Permalink
Merge branch 'master' into fix/remove-redundant-console
Browse files Browse the repository at this point in the history
  • Loading branch information
OBrezhniev authored Aug 1, 2024
2 parents 40e2e28 + 522d483 commit fd7fa50
Show file tree
Hide file tree
Showing 24 changed files with 5,378 additions and 21,584 deletions.
41 changes: 8 additions & 33 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
name: Continuous Integration
on: [push, pull_request]
on:
push:
branches:
- main
pull_request:

jobs:
test:
Expand All @@ -11,7 +15,7 @@ jobs:
fail-fast: false
matrix:
os: [ubuntu-latest, macos-latest, windows-latest]
node-version: ["14", "16", "18"]
node-version: ["18", "20"]

steps:
- name: Checkout project
Expand Down Expand Up @@ -39,8 +43,7 @@ jobs:
fail-fast: false
matrix:
os: [ubuntu-latest]
# Pinning to 18.15 and dropped 20 due to https://github.com/NomicFoundation/hardhat/issues/3877
node-version: ["16", "18.15.0"]
node-version: ["18", "20"]

steps:
- name: Checkout project
Expand All @@ -64,34 +67,6 @@ jobs:
working-directory: smart_contract_tests
run: npm test

testv12:
name: Testv12
runs-on: ${{ matrix.os }}
timeout-minutes: 30

strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, macos-latest, windows-latest]
node-version: ["12"]

steps:
- name: Checkout project
uses: actions/checkout@v2

- name: Setup Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node-version }}
check-latest: true
cache: "npm"

- name: Install dependencies
run: npm ci

- name: Run tests
run: npm run testv12

test-browser:
name: Test browser
runs-on: ${{ matrix.os }}
Expand All @@ -101,7 +76,7 @@ jobs:
fail-fast: false
matrix:
os: [ubuntu-latest]
node-version: ["18"]
node-version: ["18", "20"]

steps:
- name: Checkout project
Expand Down
9 changes: 6 additions & 3 deletions .github/workflows/tutorial.yml
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
name: Check snarkjs tutorial

on: [push, pull_request]
on:
push:
branches:
- main
pull_request:

jobs:
test:
runs-on: ubuntu-latest
strategy:
matrix:
node-version: [12.x, 14.x]
node-version: ["18", "20"]

steps:
- uses: actions/checkout@v2
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ The low-level cryptography is performed directly in `wasm`, and uses worker thre
## Preliminaries

### Install node
First off, make sure you have a recent version of `Node.js` installed. While any version after `v12` should work fine, we recommend you install `v16` or later.
First off, make sure you have a recent LTS version of Node.js installed. Non-LTS and versions prior to v18 are not guaranteed to work.

If you’re not sure which version of Node you have installed, you can run:

Expand Down
10 changes: 5 additions & 5 deletions browser_tests/package-lock.json

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

2 changes: 1 addition & 1 deletion browser_tests/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
},
"devDependencies": {
"puppeteer": "20.2.0",
"ffjavascript": "^0.2.62",
"ffjavascript": "^0.3.0",
"st": "3.0.0"
}
}
41 changes: 31 additions & 10 deletions build/browser.esm.js
Original file line number Diff line number Diff line change
Expand Up @@ -3330,6 +3330,13 @@ function flatArray(a) {
}
}

// Ref https://github.com/iden3/circom/commit/ec6388cf6eb62463539cb4c40cc3ceae9826de19
function normalize(n, prime) {
let res = BigInt(n) % prime;
if (res < 0) res += prime;
return res
}

function fnvHash(str) {
const uint64_max = BigInt(2) ** BigInt(64);
let hash = BigInt("0xCBF29CE484222325");
Expand Down Expand Up @@ -3739,7 +3746,7 @@ class WitnessCalculatorCircom2 {
this.n32 = this.instance.exports.getFieldNumLen32();

this.instance.exports.getRawPrime();
const arr = new Array(this.n32);
const arr = new Uint32Array(this.n32);
for (let i=0; i<this.n32; i++) {
arr[this.n32-1-i] = this.instance.exports.readSharedRWMemory(i);
}
Expand All @@ -3764,18 +3771,32 @@ class WitnessCalculatorCircom2 {
const hMSB = parseInt(h.slice(0,8), 16);
const hLSB = parseInt(h.slice(8,16), 16);
const fArr = flatArray(input[k]);
// Slight deviation from https://github.com/iden3/circom/blob/v2.1.6/code_producers/src/wasm_elements/common/witness_calculator.js
// because I don't know when this exported function was added
if (typeof this.instance.exports.getInputSignalSize === 'function') {
let signalSize = this.instance.exports.getInputSignalSize(hMSB, hLSB);
if (signalSize < 0){
throw new Error(`Signal ${k} not found\n`);
}
if (fArr.length < signalSize) {
throw new Error(`Not enough values for input signal ${k}\n`);
}
if (fArr.length > signalSize) {
throw new Error(`Too many values for input signal ${k}\n`);
}
}
for (let i=0; i<fArr.length; i++) {
const arrFr = toArray32(fArr[i],this.n32);
for (let j=0; j<this.n32; j++) {
this.instance.exports.writeSharedRWMemory(j,arrFr[this.n32-1-j]);
}
try {
const arrFr = toArray32(normalize(fArr[i],this.prime),this.n32);
for (let j=0; j<this.n32; j++) {
this.instance.exports.writeSharedRWMemory(j,arrFr[this.n32-1-j]);
}
try {
this.instance.exports.setInputSignal(hMSB, hLSB,i);
input_counter++;
} catch (err) {
// console.log(`After adding signal ${i} of ${k}`)
input_counter++;
} catch (err) {
// console.log(`After adding signal ${i} of ${k}`)
throw new Error(err);
}
}
}

});
Expand Down
Loading

0 comments on commit fd7fa50

Please sign in to comment.