Compare commits

...

16 Commits

Author SHA1 Message Date
Jordi Baylina
8fc6e3f1c6 0.5.12 2020-07-02 06:00:10 +02:00
Jordi Baylina
c32d303d27 deps 2020-07-02 05:59:00 +02:00
Jordi Baylina
744d3b241c deps and verbos 2020-07-02 05:33:31 +02:00
Jordi Baylina
1a5f7d1a2b 0.5.11 2020-04-27 12:03:38 +02:00
Jordi Baylina
434e7ac498 deps 2020-04-27 12:03:29 +02:00
Jordi Baylina
99afb4312e Fix negative short composition 2020-04-27 11:57:32 +02:00
Jordi Baylina
67ec7c5d5b 0.5.10 2020-04-19 19:29:06 +02:00
Jordi Baylina
a76f3b5988 deps 2020-04-19 19:28:57 +02:00
Jordi Baylina
bc9d395e70 0.5.9 2020-04-19 18:38:19 +02:00
Jordi Baylina
7fc457ac90 fastfile 2020-04-19 18:38:10 +02:00
Jordi Baylina
8c4980c3f9 0.5.8 2020-04-18 20:53:21 +02:00
Jordi Baylina
767ca60008 Use native big int 2020-04-18 20:53:13 +02:00
Jordi Baylina
f25842f67c 0.5.7 2020-04-07 13:02:51 +02:00
Jordi Baylina
92399017df FIX: c tester in linux 2020-04-07 13:02:39 +02:00
Jordi Baylina
1463685b11 Merge pull request #57 from iden3/feature/c-tester-linux
add `-pthread` for linux g++ command
2020-04-07 13:00:51 +02:00
krlosMata
b107a11432 add -pthread for linux 2020-04-07 11:51:48 +02:00
20 changed files with 511 additions and 697 deletions

View File

@@ -8,7 +8,7 @@ This tutorial will guide you in creating your first zero-knowledge SNARK circuit
If you don't have it installed yet, you need to install `Node.js`. If you don't have it installed yet, you need to install `Node.js`.
The last stable version of `Node.js` (or 8.12.0) works just fine, but if you install the latest current version `Node.js` (10.12.0) you will see a significant increase in performance. This is because last versions of node includes Big Integer Libraries nativelly. The `snarkjs` library makes use of this feature if available, and this improves the performance x10 (!). You should install at least version 10 of node. It's important to note here that the latests versions of javascript, includes big integer support and web assembly compilers that make the code run fast.
### 1.2 Install **circom** and **snarkjs** ### 1.2 Install **circom** and **snarkjs**

13
cli.js
View File

@@ -23,7 +23,7 @@
const fs = require("fs"); const fs = require("fs");
const path = require("path"); const path = require("path");
const bigInt = require("big-integer"); const Scalar = require("ffjavascript").Scalar;
const compiler = require("./src/compiler"); const compiler = require("./src/compiler");
@@ -82,7 +82,6 @@ const options = {};
options.reduceConstraints = !argv.fast; options.reduceConstraints = !argv.fast;
options.verbose = argv.verbose || false; options.verbose = argv.verbose || false;
options.sanityCheck = argv.sanitycheck; options.sanityCheck = argv.sanitycheck;
options.prime = argv.prime || bigInt("21888242871839275222246405745257275088548364400416034343698204186575808495617");
if (argv.csource) { if (argv.csource) {
options.cSourceWriteStream = fs.createWriteStream(cSourceName); options.cSourceWriteStream = fs.createWriteStream(cSourceName);
@@ -102,6 +101,16 @@ if (argv.sym) {
if (argv.newThreadTemplates) { if (argv.newThreadTemplates) {
options.newThreadTemplates = new RegExp(argv.newThreadTemplates); options.newThreadTemplates = new RegExp(argv.newThreadTemplates);
} }
if (!argv.prime) {
options.prime = Scalar.fromString("21888242871839275222246405745257275088548364400416034343698204186575808495617");
} else if (["BLS12-381", "BLS12381"]. indexOf(argv.prime.toUpperCase()) >=0) {
options.prime = Scalar.fromString("73eda753299d7d483339d80809a1d80553bda402fffe5bfeffffffff00000001",16);
} else if (["BN-128", "BN128", "BN254", "BN-254"]. indexOf(argv.prime.toUpperCase()) >=0) {
options.prime = Scalar.fromString("21888242871839275222246405745257275088548364400416034343698204186575808495617");
} else {
options.prime = Scalar.fromString(argv.prime);
}
compiler(fullFileName, options).then( () => { compiler(fullFileName, options).then( () => {
let cSourceDone = false; let cSourceDone = false;

379
package-lock.json generated
View File

@@ -1,31 +1,31 @@
{ {
"name": "circom", "name": "circom",
"version": "0.5.6", "version": "0.5.12",
"lockfileVersion": 1, "lockfileVersion": 1,
"requires": true, "requires": true,
"dependencies": { "dependencies": {
"@babel/code-frame": { "@babel/code-frame": {
"version": "7.8.3", "version": "7.10.4",
"resolved": "https://registry.npmjs.org/@babel/code-frame/-/code-frame-7.8.3.tgz", "resolved": "https://registry.npmjs.org/@babel/code-frame/-/code-frame-7.10.4.tgz",
"integrity": "sha512-a9gxpmdXtZEInkCSHUJDLHZVBgb1QS0jhss4cPP93EW7s+uC5bikET2twEF3KV+7rDblJcmNvTR7VJejqd2C2g==", "integrity": "sha512-vG6SvB6oYEhvgisZNFRmRCUkLz11c7rp+tbNTynGqc6mS1d5ATd/sGyV6W0KZZnXRKMTzZDRgQT3Ou9jhpAfUg==",
"dev": true, "dev": true,
"requires": { "requires": {
"@babel/highlight": "^7.8.3" "@babel/highlight": "^7.10.4"
} }
}, },
"@babel/helper-validator-identifier": { "@babel/helper-validator-identifier": {
"version": "7.9.0", "version": "7.10.4",
"resolved": "https://registry.npmjs.org/@babel/helper-validator-identifier/-/helper-validator-identifier-7.9.0.tgz", "resolved": "https://registry.npmjs.org/@babel/helper-validator-identifier/-/helper-validator-identifier-7.10.4.tgz",
"integrity": "sha512-6G8bQKjOh+of4PV/ThDm/rRqlU7+IGoJuofpagU5GlEl29Vv0RGqqt86ZGRV8ZuSOY3o+8yXl5y782SMcG7SHw==", "integrity": "sha512-3U9y+43hz7ZM+rzG24Qe2mufW5KhvFg/NhnNph+i9mgCtdTCtMJuI1TMkrIUiK7Ix4PYlRF9I5dhqaLYA/ADXw==",
"dev": true "dev": true
}, },
"@babel/highlight": { "@babel/highlight": {
"version": "7.9.0", "version": "7.10.4",
"resolved": "https://registry.npmjs.org/@babel/highlight/-/highlight-7.9.0.tgz", "resolved": "https://registry.npmjs.org/@babel/highlight/-/highlight-7.10.4.tgz",
"integrity": "sha512-lJZPilxX7Op3Nv/2cvFdnlepPXDxi29wxteT57Q965oc5R9v86ztx0jfxVrTcBk8C2kcPkkDa2Z4T3ZsPPVWsQ==", "integrity": "sha512-i6rgnR/YgPEQzZZnbTHHuZdlE8qyoBNalD6F+q4vAFlcMEcqmkoG+mPqJYJCo63qPf74+Y1UZsl3l6f7/RIkmA==",
"dev": true, "dev": true,
"requires": { "requires": {
"@babel/helper-validator-identifier": "^7.9.0", "@babel/helper-validator-identifier": "^7.10.4",
"chalk": "^2.0.0", "chalk": "^2.0.0",
"js-tokens": "^4.0.0" "js-tokens": "^4.0.0"
} }
@@ -48,9 +48,9 @@
"dev": true "dev": true
}, },
"acorn": { "acorn": {
"version": "7.1.1", "version": "7.3.1",
"resolved": "https://registry.npmjs.org/acorn/-/acorn-7.1.1.tgz", "resolved": "https://registry.npmjs.org/acorn/-/acorn-7.3.1.tgz",
"integrity": "sha512-add7dgA5ppRPxCFJoAGfMDi7PIBXq1RtGo7BhbLaxwrXPOmw8gq48Y9ozT01hUKy9byMjlR20EJhu5zlkErEkg==", "integrity": "sha512-tLc0wSnatxAQHVHUapaHdz72pi9KUyHjq5KyHjGg9Y8Ifdc79pTh2XvI6I1/chZbnM7QtNKzh66ooDogPZSleA==",
"dev": true "dev": true
}, },
"acorn-jsx": { "acorn-jsx": {
@@ -60,9 +60,9 @@
"dev": true "dev": true
}, },
"ajv": { "ajv": {
"version": "6.12.0", "version": "6.12.2",
"resolved": "https://registry.npmjs.org/ajv/-/ajv-6.12.0.tgz", "resolved": "https://registry.npmjs.org/ajv/-/ajv-6.12.2.tgz",
"integrity": "sha512-D6gFiFA0RRLyUbvijN74DWAjXSFxWKaWP7mldxkVhyhAV3+SWA9HEJPHQ2c9soIeTFJqcSdFDGFgdqs1iUU2Hw==", "integrity": "sha512-k+V+hzjm5q/Mr8ef/1Y9goCmlsK4I6Sm74teeyGvFk1XrOsbsKLjEdrvny42CZ+a8sXbk8KWpY/bDwS+FLL2UQ==",
"dev": true, "dev": true,
"requires": { "requires": {
"fast-deep-equal": "^3.1.1", "fast-deep-equal": "^3.1.1",
@@ -101,12 +101,11 @@
"integrity": "sha512-bY6fj56OUQ0hU1KjFNDQuJFezqKdrAyFdIevADiqrWHwSlbmBNMHp5ak2f40Pm8JTFyM2mqxkG6ngkHO11f/lg==" "integrity": "sha512-bY6fj56OUQ0hU1KjFNDQuJFezqKdrAyFdIevADiqrWHwSlbmBNMHp5ak2f40Pm8JTFyM2mqxkG6ngkHO11f/lg=="
}, },
"ansi-styles": { "ansi-styles": {
"version": "4.2.1", "version": "3.2.1",
"resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-4.2.1.tgz", "resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-3.2.1.tgz",
"integrity": "sha512-9VGjrMsG1vePxcSweQsN20KY/c4zN0h9fLjqAbwbPfahM3t+NL+M9HC8xeXG2I8pX5NoamTGNuomEUFI7fcUjA==", "integrity": "sha512-VT0ZI6kZRdTh8YyJw3SMbYm/u+NqfsAxEpWO0Pf9sq8/e94WxxOpPKx9FR1FlyCtOVDNOQ+8ntlqFxiRc+r5qA==",
"requires": { "requires": {
"@types/color-name": "^1.1.1", "color-convert": "^1.9.0"
"color-convert": "^2.0.1"
} }
}, },
"argparse": { "argparse": {
@@ -129,6 +128,11 @@
"integrity": "sha512-+Ryf6g3BKoRc7jfp7ad8tM4TtMiaWvbF/1/sQcZPkkS7ag3D5nMBCe2UfOTONtAkaG0tO0ij3C5Lwmf1EiyjHg==", "integrity": "sha512-+Ryf6g3BKoRc7jfp7ad8tM4TtMiaWvbF/1/sQcZPkkS7ag3D5nMBCe2UfOTONtAkaG0tO0ij3C5Lwmf1EiyjHg==",
"dev": true "dev": true
}, },
"async": {
"version": "0.9.2",
"resolved": "https://registry.npmjs.org/async/-/async-0.9.2.tgz",
"integrity": "sha1-rqdNXmHB+JlhO/ZL2mbUx48v0X0="
},
"balanced-match": { "balanced-match": {
"version": "1.0.0", "version": "1.0.0",
"resolved": "https://registry.npmjs.org/balanced-match/-/balanced-match-1.0.0.tgz", "resolved": "https://registry.npmjs.org/balanced-match/-/balanced-match-1.0.0.tgz",
@@ -176,37 +180,10 @@
"version": "2.4.2", "version": "2.4.2",
"resolved": "https://registry.npmjs.org/chalk/-/chalk-2.4.2.tgz", "resolved": "https://registry.npmjs.org/chalk/-/chalk-2.4.2.tgz",
"integrity": "sha512-Mti+f9lpJNcwF4tWV8/OrTTtF1gZi+f8FqlyAdouralcFWFQWF2+NgCHShjkCb+IFBLq9buZwE1xckQU4peSuQ==", "integrity": "sha512-Mti+f9lpJNcwF4tWV8/OrTTtF1gZi+f8FqlyAdouralcFWFQWF2+NgCHShjkCb+IFBLq9buZwE1xckQU4peSuQ==",
"dev": true,
"requires": { "requires": {
"ansi-styles": "^3.2.1", "ansi-styles": "^3.2.1",
"escape-string-regexp": "^1.0.5", "escape-string-regexp": "^1.0.5",
"supports-color": "^5.3.0" "supports-color": "^5.3.0"
},
"dependencies": {
"ansi-styles": {
"version": "3.2.1",
"resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-3.2.1.tgz",
"integrity": "sha512-VT0ZI6kZRdTh8YyJw3SMbYm/u+NqfsAxEpWO0Pf9sq8/e94WxxOpPKx9FR1FlyCtOVDNOQ+8ntlqFxiRc+r5qA==",
"dev": true,
"requires": {
"color-convert": "^1.9.0"
}
},
"color-convert": {
"version": "1.9.3",
"resolved": "https://registry.npmjs.org/color-convert/-/color-convert-1.9.3.tgz",
"integrity": "sha512-QfAUtd+vFdAtFQcC8CCyYt1fYWxSqAiK2cSD6zDB8N3cpsEBAvRxp9zOGg6G/SHHJYAT88/az/IuDGALsNVbGg==",
"dev": true,
"requires": {
"color-name": "1.1.3"
}
},
"color-name": {
"version": "1.1.3",
"resolved": "https://registry.npmjs.org/color-name/-/color-name-1.1.3.tgz",
"integrity": "sha1-p9BVi9icQveV3UIyj3QIMcpTvCU=",
"dev": true
}
} }
}, },
"chardet": { "chardet": {
@@ -221,12 +198,22 @@
"integrity": "sha1-V00xLt2Iu13YkS6Sht1sCu1KrII=" "integrity": "sha1-V00xLt2Iu13YkS6Sht1sCu1KrII="
}, },
"circom_runtime": { "circom_runtime": {
"version": "0.0.3", "version": "0.0.6",
"resolved": "https://registry.npmjs.org/circom_runtime/-/circom_runtime-0.0.3.tgz", "resolved": "https://registry.npmjs.org/circom_runtime/-/circom_runtime-0.0.6.tgz",
"integrity": "sha512-z4ypbs9cTQn7+2FHZNTnccMj6kQCcKT2agYqCrm2kdLBJh9LDoxU1JVu5mSnVuOtgc7BclQ7r0xclG0zP2rxhw==", "integrity": "sha512-o0T5MuWzxnxinWG3+CygS/kZouoP+z5ZrufUwqKJy3gsVFJhkbqMpfKmcBGjhExB3uatA7cKyOiRAOLOz5+t5w==",
"requires": { "requires": {
"big-integer": "^1.6.48", "ffjavascript": "0.1.0",
"fnv-plus": "^1.3.1" "fnv-plus": "^1.3.1"
},
"dependencies": {
"ffjavascript": {
"version": "0.1.0",
"resolved": "https://registry.npmjs.org/ffjavascript/-/ffjavascript-0.1.0.tgz",
"integrity": "sha512-dmKlUasSfvUcxBm8nCSKl2x7EFJsXA7OVP8XLFA03T2+6mAc3IiVLC2ambEVOcMOhyhl0vJfVZjM9f9d38D1rw==",
"requires": {
"big-integer": "^1.6.48"
}
}
} }
}, },
"cjson": { "cjson": {
@@ -248,9 +235,9 @@
} }
}, },
"cli-width": { "cli-width": {
"version": "2.2.0", "version": "2.2.1",
"resolved": "https://registry.npmjs.org/cli-width/-/cli-width-2.2.0.tgz", "resolved": "https://registry.npmjs.org/cli-width/-/cli-width-2.2.1.tgz",
"integrity": "sha1-/xnt6Kml5XkyQUewwR8PvLq+1jk=", "integrity": "sha512-GRMWDxpOB6Dgk2E5Uo+3eEBvtOOlimMmpbFiKuLFnQzYDavtLFY3K5ona41jgN/WdRZtG7utuVSVTL4HbZHGkw==",
"dev": true "dev": true
}, },
"cliui": { "cliui": {
@@ -264,17 +251,17 @@
} }
}, },
"color-convert": { "color-convert": {
"version": "2.0.1", "version": "1.9.3",
"resolved": "https://registry.npmjs.org/color-convert/-/color-convert-2.0.1.tgz", "resolved": "https://registry.npmjs.org/color-convert/-/color-convert-1.9.3.tgz",
"integrity": "sha512-RRECPsj7iu/xb5oKYcsFHSppFNnsj/52OVTRKb4zP5onXwVF3zVmmToNcOfGC+CRDpfK/U584fMg38ZHCaElKQ==", "integrity": "sha512-QfAUtd+vFdAtFQcC8CCyYt1fYWxSqAiK2cSD6zDB8N3cpsEBAvRxp9zOGg6G/SHHJYAT88/az/IuDGALsNVbGg==",
"requires": { "requires": {
"color-name": "~1.1.4" "color-name": "1.1.3"
} }
}, },
"color-name": { "color-name": {
"version": "1.1.4", "version": "1.1.3",
"resolved": "https://registry.npmjs.org/color-name/-/color-name-1.1.4.tgz", "resolved": "https://registry.npmjs.org/color-name/-/color-name-1.1.3.tgz",
"integrity": "sha512-dOy+3AuW3a2wNbZHIuMZpTcgjGuLU/uBL/ubcZF9OXbDo8ff4O8yVp5Bf0efS8uEoYo5q4Fx7dY9OgQGXgAsQA==" "integrity": "sha1-p9BVi9icQveV3UIyj3QIMcpTvCU="
}, },
"colors": { "colors": {
"version": "0.5.1", "version": "0.5.1",
@@ -352,9 +339,12 @@
"dev": true "dev": true
}, },
"ejs": { "ejs": {
"version": "3.0.1", "version": "3.1.3",
"resolved": "https://registry.npmjs.org/ejs/-/ejs-3.0.1.tgz", "resolved": "https://registry.npmjs.org/ejs/-/ejs-3.1.3.tgz",
"integrity": "sha512-cuIMtJwxvzumSAkqaaoGY/L6Fc/t6YvoP9/VIaK0V/CyqKLEQ8sqODmYfy/cjXEdZ9+OOL8TecbJu+1RsofGDw==" "integrity": "sha512-wmtrUGyfSC23GC/B1SMv2ogAUgbQEtDmTIhfqielrG5ExIM9TP4UoYdi90jLF1aTcsWCJNEO0UrgKzP0y3nTSg==",
"requires": {
"jake": "^10.6.1"
}
}, },
"emoji-regex": { "emoji-regex": {
"version": "8.0.0", "version": "8.0.0",
@@ -364,8 +354,7 @@
"escape-string-regexp": { "escape-string-regexp": {
"version": "1.0.5", "version": "1.0.5",
"resolved": "https://registry.npmjs.org/escape-string-regexp/-/escape-string-regexp-1.0.5.tgz", "resolved": "https://registry.npmjs.org/escape-string-regexp/-/escape-string-regexp-1.0.5.tgz",
"integrity": "sha1-G2HAViGQqN/2rjuyzwIAyhMLhtQ=", "integrity": "sha1-G2HAViGQqN/2rjuyzwIAyhMLhtQ="
"dev": true
}, },
"escodegen": { "escodegen": {
"version": "1.3.3", "version": "1.3.3",
@@ -462,9 +451,9 @@
} }
}, },
"eslint-scope": { "eslint-scope": {
"version": "5.0.0", "version": "5.1.0",
"resolved": "https://registry.npmjs.org/eslint-scope/-/eslint-scope-5.0.0.tgz", "resolved": "https://registry.npmjs.org/eslint-scope/-/eslint-scope-5.1.0.tgz",
"integrity": "sha512-oYrhJW7S0bxAFDvWqzvMPRm6pcgcnWc4QnofCAqRTRfQC0JcwenzGglTtsLyIuuWFfkqDG9vz67cnttSd53djw==", "integrity": "sha512-iiGRvtxWqgtx5m8EyQUJihBloE4EnYeGE/bz1wSPwJE6tZuJUtHlhqDM4Xj2ukE8Dyy1+HCZ4hE0fzIVMzb58w==",
"dev": true, "dev": true,
"requires": { "requires": {
"esrecurse": "^4.1.0", "esrecurse": "^4.1.0",
@@ -481,9 +470,9 @@
} }
}, },
"eslint-visitor-keys": { "eslint-visitor-keys": {
"version": "1.1.0", "version": "1.3.0",
"resolved": "https://registry.npmjs.org/eslint-visitor-keys/-/eslint-visitor-keys-1.1.0.tgz", "resolved": "https://registry.npmjs.org/eslint-visitor-keys/-/eslint-visitor-keys-1.3.0.tgz",
"integrity": "sha512-8y9YjtM1JBJU/A9Kc+SbaOV4y29sSWckBwMHa+FGtVj5gN/sbnKDf6xJUl+8g7FAij9LVaP8C24DUiH/f/2Z9A==", "integrity": "sha512-6J72N8UNa462wa/KFODt/PJ3IU60SDpC3QXC1Hjc1BXXpfL2C9R5+AU7jhe0F6GREqVMh4Juu+NY7xn+6dipUQ==",
"dev": true "dev": true
}, },
"espree": { "espree": {
@@ -504,18 +493,18 @@
"dev": true "dev": true
}, },
"esquery": { "esquery": {
"version": "1.2.0", "version": "1.3.1",
"resolved": "https://registry.npmjs.org/esquery/-/esquery-1.2.0.tgz", "resolved": "https://registry.npmjs.org/esquery/-/esquery-1.3.1.tgz",
"integrity": "sha512-weltsSqdeWIX9G2qQZz7KlTRJdkkOCTPgLYJUz1Hacf48R4YOwGPHO3+ORfWedqJKbq5WQmsgK90n+pFLIKt/Q==", "integrity": "sha512-olpvt9QG0vniUBZspVRN6lwB7hOZoTRtT+jzR+tS4ffYx2mzbw+z0XCOk44aaLYKApNX5nMm+E+P6o25ip/DHQ==",
"dev": true, "dev": true,
"requires": { "requires": {
"estraverse": "^5.0.0" "estraverse": "^5.1.0"
}, },
"dependencies": { "dependencies": {
"estraverse": { "estraverse": {
"version": "5.0.0", "version": "5.1.0",
"resolved": "https://registry.npmjs.org/estraverse/-/estraverse-5.0.0.tgz", "resolved": "https://registry.npmjs.org/estraverse/-/estraverse-5.1.0.tgz",
"integrity": "sha512-j3acdrMzqrxmJTNj5dbr1YbjacrYgAxVMeF0gK16E3j494mOe7xygM/ZLIguEQ0ETwAg2hlJCtHRGav+y0Ny5A==", "integrity": "sha512-FyohXK+R0vE+y1nHLoBM7ZTyqRpqAlhdZHCWIWEviFLiGB8b04H6bQs8G+XTthacvT8VuwvteiP7RJSxMs8UEw==",
"dev": true "dev": true
} }
} }
@@ -564,9 +553,9 @@
} }
}, },
"fast-deep-equal": { "fast-deep-equal": {
"version": "3.1.1", "version": "3.1.3",
"resolved": "https://registry.npmjs.org/fast-deep-equal/-/fast-deep-equal-3.1.1.tgz", "resolved": "https://registry.npmjs.org/fast-deep-equal/-/fast-deep-equal-3.1.3.tgz",
"integrity": "sha512-8UEa58QDLauDNfpbrX55Q9jrGHThw2ZMdOky5Gl1CDtVeJDPVrG4Jxx1N8jw2gkWaff5UUuX1KJd+9zGe2B+ZA==", "integrity": "sha512-f3qQ9oQy9j2AhBe/H9VC91wLmKBCCU/gDOnKNAYG5hswO7BLKj09Hc5HYNz9cGI++xlpDCIgDaitVs03ATR84Q==",
"dev": true "dev": true
}, },
"fast-json-stable-stringify": { "fast-json-stable-stringify": {
@@ -581,6 +570,11 @@
"integrity": "sha1-PYpcZog6FqMMqGQ+hR8Zuqd5eRc=", "integrity": "sha1-PYpcZog6FqMMqGQ+hR8Zuqd5eRc=",
"dev": true "dev": true
}, },
"fastfile": {
"version": "0.0.2",
"resolved": "https://registry.npmjs.org/fastfile/-/fastfile-0.0.2.tgz",
"integrity": "sha512-rS9vpAM4DS+xacKSH0MVCqr/Y5SiIAiunJTYSuq1H9nfRpkP37ewgnjH3FztziKBUQB2xPYS/WxEEjHl+pA5Fg=="
},
"ffiasm": { "ffiasm": {
"version": "0.0.2", "version": "0.0.2",
"resolved": "https://registry.npmjs.org/ffiasm/-/ffiasm-0.0.2.tgz", "resolved": "https://registry.npmjs.org/ffiasm/-/ffiasm-0.0.2.tgz",
@@ -592,17 +586,17 @@
} }
}, },
"ffjavascript": { "ffjavascript": {
"version": "0.0.5", "version": "0.1.2",
"resolved": "https://registry.npmjs.org/ffjavascript/-/ffjavascript-0.0.5.tgz", "resolved": "https://registry.npmjs.org/ffjavascript/-/ffjavascript-0.1.2.tgz",
"integrity": "sha512-7je6PydOWLDUj3vU8JeCUgeezg4yrG/6qjlukQNuPHeeavnM4REcrN9LA2+xtqIMIPdx/wdUkPMQpixsz+CdIw==", "integrity": "sha512-zB1dhgBjJlvyk2VQIQzFSpUJmanYQYDR/Fo1KhZnaNW5chMFJT55qz0dx1LMKrAklBbidKzz2/C7dgibxQF94g==",
"requires": { "requires": {
"big-integer": "^1.6.48" "big-integer": "^1.6.48"
} }
}, },
"ffwasm": { "ffwasm": {
"version": "0.0.6", "version": "0.0.7",
"resolved": "https://registry.npmjs.org/ffwasm/-/ffwasm-0.0.6.tgz", "resolved": "https://registry.npmjs.org/ffwasm/-/ffwasm-0.0.7.tgz",
"integrity": "sha512-bEBKYANozdyZBCGE6XLg4s/CaJRZdFGQgbthy7EZ4OhNCIpycgklS5mlf88Bw4fXSddlU1V9iYXI4JwfGO3BhQ==", "integrity": "sha512-17cTLzv7HHAKqZbX8MvHxjSrR0yDdn1sh4TVsTbAvO9e6klhFicnyoVXc/sCuViV/M8g65sCmVrAmoPCZp1YkQ==",
"requires": { "requires": {
"big-integer": "^1.6.48", "big-integer": "^1.6.48",
"wasmbuilder": "0.0.10" "wasmbuilder": "0.0.10"
@@ -626,6 +620,14 @@
"flat-cache": "^2.0.1" "flat-cache": "^2.0.1"
} }
}, },
"filelist": {
"version": "1.0.1",
"resolved": "https://registry.npmjs.org/filelist/-/filelist-1.0.1.tgz",
"integrity": "sha512-8zSK6Nu0DQIC08mUC46sWGXi+q3GGpKydAG36k+JDba6VRpkevvOWUW5a/PhShij4+vHT9M+ghgG7eM+a9JDUQ==",
"requires": {
"minimatch": "^3.0.4"
}
},
"find-up": { "find-up": {
"version": "4.1.0", "version": "4.1.0",
"resolved": "https://registry.npmjs.org/find-up/-/find-up-4.1.0.tgz", "resolved": "https://registry.npmjs.org/find-up/-/find-up-4.1.0.tgz",
@@ -658,9 +660,9 @@
} }
}, },
"flatted": { "flatted": {
"version": "2.0.1", "version": "2.0.2",
"resolved": "https://registry.npmjs.org/flatted/-/flatted-2.0.1.tgz", "resolved": "https://registry.npmjs.org/flatted/-/flatted-2.0.2.tgz",
"integrity": "sha512-a1hQMktqW9Nmqr5aktAux3JMNqaucxGcjtjWnZLHX7yyPCmlSV3M54nGYbqT8K+0GhF3NBgmJCc3ma+WOgX8Jg==", "integrity": "sha512-r5wGx7YeOwNWNlCA0wQ86zKyDLMQr+/RB8xy74M4hTphfmjlijTSSXGuH8rnvKZnfT9i+75zmd8jcKdMR4O6jA==",
"dev": true "dev": true
}, },
"fnv-plus": { "fnv-plus": {
@@ -723,8 +725,7 @@
"has-flag": { "has-flag": {
"version": "3.0.0", "version": "3.0.0",
"resolved": "https://registry.npmjs.org/has-flag/-/has-flag-3.0.0.tgz", "resolved": "https://registry.npmjs.org/has-flag/-/has-flag-3.0.0.tgz",
"integrity": "sha1-tdRU3CGZriJWmfNGfloH87lVuv0=", "integrity": "sha1-tdRU3CGZriJWmfNGfloH87lVuv0="
"dev": true
}, },
"iconv-lite": { "iconv-lite": {
"version": "0.4.24", "version": "0.4.24",
@@ -772,9 +773,9 @@
"integrity": "sha512-k/vGaX4/Yla3WzyMCvTQOXYeIHvqOKtnqBduzTHpzpQZzAskKMhZ2K+EnBiSM9zGSoIFeMpXKxa4dYeZIQqewQ==" "integrity": "sha512-k/vGaX4/Yla3WzyMCvTQOXYeIHvqOKtnqBduzTHpzpQZzAskKMhZ2K+EnBiSM9zGSoIFeMpXKxa4dYeZIQqewQ=="
}, },
"inquirer": { "inquirer": {
"version": "7.1.0", "version": "7.2.0",
"resolved": "https://registry.npmjs.org/inquirer/-/inquirer-7.1.0.tgz", "resolved": "https://registry.npmjs.org/inquirer/-/inquirer-7.2.0.tgz",
"integrity": "sha512-5fJMWEmikSYu0nv/flMc475MhGbB7TSPd/2IpFV4I4rMklboCH2rQjYY5kKiYGHqUF9gvaambupcJFFG9dvReg==", "integrity": "sha512-E0c4rPwr9ByePfNlTIB8z51kK1s2n6jrHuJeEHENl/sbq2G/S1auvibgEwNR4uSyiU+PiYHqSwsgGiXjG8p5ZQ==",
"dev": true, "dev": true,
"requires": { "requires": {
"ansi-escapes": "^4.2.1", "ansi-escapes": "^4.2.1",
@@ -792,6 +793,16 @@
"through": "^2.3.6" "through": "^2.3.6"
}, },
"dependencies": { "dependencies": {
"ansi-styles": {
"version": "4.2.1",
"resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-4.2.1.tgz",
"integrity": "sha512-9VGjrMsG1vePxcSweQsN20KY/c4zN0h9fLjqAbwbPfahM3t+NL+M9HC8xeXG2I8pX5NoamTGNuomEUFI7fcUjA==",
"dev": true,
"requires": {
"@types/color-name": "^1.1.1",
"color-convert": "^2.0.1"
}
},
"chalk": { "chalk": {
"version": "3.0.0", "version": "3.0.0",
"resolved": "https://registry.npmjs.org/chalk/-/chalk-3.0.0.tgz", "resolved": "https://registry.npmjs.org/chalk/-/chalk-3.0.0.tgz",
@@ -802,6 +813,21 @@
"supports-color": "^7.1.0" "supports-color": "^7.1.0"
} }
}, },
"color-convert": {
"version": "2.0.1",
"resolved": "https://registry.npmjs.org/color-convert/-/color-convert-2.0.1.tgz",
"integrity": "sha512-RRECPsj7iu/xb5oKYcsFHSppFNnsj/52OVTRKb4zP5onXwVF3zVmmToNcOfGC+CRDpfK/U584fMg38ZHCaElKQ==",
"dev": true,
"requires": {
"color-name": "~1.1.4"
}
},
"color-name": {
"version": "1.1.4",
"resolved": "https://registry.npmjs.org/color-name/-/color-name-1.1.4.tgz",
"integrity": "sha512-dOy+3AuW3a2wNbZHIuMZpTcgjGuLU/uBL/ubcZF9OXbDo8ff4O8yVp5Bf0efS8uEoYo5q4Fx7dY9OgQGXgAsQA==",
"dev": true
},
"has-flag": { "has-flag": {
"version": "4.0.0", "version": "4.0.0",
"resolved": "https://registry.npmjs.org/has-flag/-/has-flag-4.0.0.tgz", "resolved": "https://registry.npmjs.org/has-flag/-/has-flag-4.0.0.tgz",
@@ -839,18 +865,23 @@
"is-extglob": "^2.1.1" "is-extglob": "^2.1.1"
} }
}, },
"is-promise": {
"version": "2.1.0",
"resolved": "https://registry.npmjs.org/is-promise/-/is-promise-2.1.0.tgz",
"integrity": "sha1-eaKp7OfwlugPNtKy87wWwf9L8/o=",
"dev": true
},
"isexe": { "isexe": {
"version": "2.0.0", "version": "2.0.0",
"resolved": "https://registry.npmjs.org/isexe/-/isexe-2.0.0.tgz", "resolved": "https://registry.npmjs.org/isexe/-/isexe-2.0.0.tgz",
"integrity": "sha1-6PvzdNxVb/iUehDcsFctYz8s+hA=", "integrity": "sha1-6PvzdNxVb/iUehDcsFctYz8s+hA=",
"dev": true "dev": true
}, },
"jake": {
"version": "10.8.2",
"resolved": "https://registry.npmjs.org/jake/-/jake-10.8.2.tgz",
"integrity": "sha512-eLpKyrfG3mzvGE2Du8VoPbeSkRry093+tyNjdYaBbJS9v17knImYGNXQCUV0gLxQtF82m3E8iRb/wdSQZLoq7A==",
"requires": {
"async": "0.9.x",
"chalk": "^2.4.2",
"filelist": "^1.0.1",
"minimatch": "^3.0.4"
}
},
"jison": { "jison": {
"version": "0.4.18", "version": "0.4.18",
"resolved": "https://registry.npmjs.org/jison/-/jison-0.4.18.tgz", "resolved": "https://registry.npmjs.org/jison/-/jison-0.4.18.tgz",
@@ -892,9 +923,9 @@
"dev": true "dev": true
}, },
"js-yaml": { "js-yaml": {
"version": "3.13.1", "version": "3.14.0",
"resolved": "https://registry.npmjs.org/js-yaml/-/js-yaml-3.13.1.tgz", "resolved": "https://registry.npmjs.org/js-yaml/-/js-yaml-3.14.0.tgz",
"integrity": "sha512-YfbcO7jXDdyj0DGxYVSlSeQNHbD7XPWvrVWeVUujrQEoZzWJIRrCPoyk6kL6IAjAG2IolMK4T0hNUe0HOUs5Jw==", "integrity": "sha512-/4IbIeHcD9VMHFqDR/gQ7EdZdLimOvW2DdcxFjdyyZ9NsbS+ccrXqVWDtab/lRl5AlUqmpBx8EhPaWR+OtY17A==",
"dev": true, "dev": true,
"requires": { "requires": {
"argparse": "^1.0.7", "argparse": "^1.0.7",
@@ -974,9 +1005,9 @@
"dev": true "dev": true
}, },
"mkdirp": { "mkdirp": {
"version": "0.5.4", "version": "0.5.5",
"resolved": "https://registry.npmjs.org/mkdirp/-/mkdirp-0.5.4.tgz", "resolved": "https://registry.npmjs.org/mkdirp/-/mkdirp-0.5.5.tgz",
"integrity": "sha512-iG9AK/dJLtJ0XNgTuDbSyNS3zECqDlAhnQW4CsNxBG3LQJBbHmRX1egw39DmtOdCAqY+dKXV+sgPgilNWUKMVw==", "integrity": "sha512-NKmAlESf6jMGym1++R0Ra7wvhV+wFW63FaSOFPwRahvea0gMUcGUhVeAg/0BC0wiv9ih5NYPB1Wn1UEI1/L+xQ==",
"dev": true, "dev": true,
"requires": { "requires": {
"minimist": "^1.2.5" "minimist": "^1.2.5"
@@ -1054,9 +1085,9 @@
"dev": true "dev": true
}, },
"p-limit": { "p-limit": {
"version": "2.2.2", "version": "2.3.0",
"resolved": "https://registry.npmjs.org/p-limit/-/p-limit-2.2.2.tgz", "resolved": "https://registry.npmjs.org/p-limit/-/p-limit-2.3.0.tgz",
"integrity": "sha512-WGR+xHecKTr7EbUEhyLSh5Dube9JtdiG78ufaeLxTgpudf/20KqyMioIUZJAezlTIi6evxuoUs9YXc11cU+yzQ==", "integrity": "sha512-//88mFWSJx8lxCzwdAABTJL2MyWB12+eIY7MDL2SqLmAkeKU9qxRvWuSyTjm3FUmpBEMuFfckAIqEaVGUDxb6w==",
"requires": { "requires": {
"p-try": "^2.0.0" "p-try": "^2.0.0"
} }
@@ -1123,11 +1154,27 @@
"dev": true "dev": true
}, },
"r1csfile": { "r1csfile": {
"version": "0.0.3", "version": "0.0.5",
"resolved": "https://registry.npmjs.org/r1csfile/-/r1csfile-0.0.3.tgz", "resolved": "https://registry.npmjs.org/r1csfile/-/r1csfile-0.0.5.tgz",
"integrity": "sha512-TNrodnbHw5yAMv2gj0Ezf22XS3q8zGEjdPHZLBmJauIPFxm6QmyzxlB92yZ5WNkjEtJiS7p1hvkO9/RsJXRDjw==", "integrity": "sha512-B+BdKPb/WUTp4N/3X4d1Spgx9Ojx5tFVejGZRJxpTtzq34mC8Vi/czWfiPj85V8kud31lCfYcZ16z7+czvM0Sw==",
"requires": { "requires": {
"big-integer": "^1.6.48" "fastfile": "0.0.1",
"ffjavascript": "0.1.0"
},
"dependencies": {
"fastfile": {
"version": "0.0.1",
"resolved": "https://registry.npmjs.org/fastfile/-/fastfile-0.0.1.tgz",
"integrity": "sha512-Fk8PWafGWGEUw7oPq/dJen92ASxknCEy4ZC8n4VEvSwCp/jcReyEmVoWsRIWTf+IvAp2MzvFi54vOPeK2LQZtQ=="
},
"ffjavascript": {
"version": "0.1.0",
"resolved": "https://registry.npmjs.org/ffjavascript/-/ffjavascript-0.1.0.tgz",
"integrity": "sha512-dmKlUasSfvUcxBm8nCSKl2x7EFJsXA7OVP8XLFA03T2+6mAc3IiVLC2ambEVOcMOhyhl0vJfVZjM9f9d38D1rw==",
"requires": {
"big-integer": "^1.6.48"
}
}
} }
}, },
"regexpp": { "regexpp": {
@@ -1171,18 +1218,15 @@
} }
}, },
"run-async": { "run-async": {
"version": "2.4.0", "version": "2.4.1",
"resolved": "https://registry.npmjs.org/run-async/-/run-async-2.4.0.tgz", "resolved": "https://registry.npmjs.org/run-async/-/run-async-2.4.1.tgz",
"integrity": "sha512-xJTbh/d7Lm7SBhc1tNvTpeCHaEzoyxPrqNlvSdMfBTYwaY++UJFyXUOxAtsRUXjlqOfj8luNaR9vjCh4KeV+pg==", "integrity": "sha512-tvVnVv01b8c1RrA6Ep7JkStj85Guv/YrMcwqYQnwjsAS2cTmmPGBBjAjpCW7RrSodNSoE2/qg9O4bceNvUuDgQ==",
"dev": true, "dev": true
"requires": {
"is-promise": "^2.1.0"
}
}, },
"rxjs": { "rxjs": {
"version": "6.5.4", "version": "6.6.0",
"resolved": "https://registry.npmjs.org/rxjs/-/rxjs-6.5.4.tgz", "resolved": "https://registry.npmjs.org/rxjs/-/rxjs-6.6.0.tgz",
"integrity": "sha512-naMQXcgEo3csAEGvw/NydRA0fuS2nDZJiw1YUWFKU7aPPAPGZEsD4Iimit96qwCieH6y614MCLYwdkrWx7z/7Q==", "integrity": "sha512-3HMA8z/Oz61DUHe+SdOiQyzIf4tOx5oQHmMir7IZEu6TMqCLHT4LRcmNaUS0NwOz8VLvmmBduMsoaUvMaIiqzg==",
"dev": true, "dev": true,
"requires": { "requires": {
"tslib": "^1.9.0" "tslib": "^1.9.0"
@@ -1237,30 +1281,6 @@
"is-fullwidth-code-point": "^2.0.0" "is-fullwidth-code-point": "^2.0.0"
}, },
"dependencies": { "dependencies": {
"ansi-styles": {
"version": "3.2.1",
"resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-3.2.1.tgz",
"integrity": "sha512-VT0ZI6kZRdTh8YyJw3SMbYm/u+NqfsAxEpWO0Pf9sq8/e94WxxOpPKx9FR1FlyCtOVDNOQ+8ntlqFxiRc+r5qA==",
"dev": true,
"requires": {
"color-convert": "^1.9.0"
}
},
"color-convert": {
"version": "1.9.3",
"resolved": "https://registry.npmjs.org/color-convert/-/color-convert-1.9.3.tgz",
"integrity": "sha512-QfAUtd+vFdAtFQcC8CCyYt1fYWxSqAiK2cSD6zDB8N3cpsEBAvRxp9zOGg6G/SHHJYAT88/az/IuDGALsNVbGg==",
"dev": true,
"requires": {
"color-name": "1.1.3"
}
},
"color-name": {
"version": "1.1.3",
"resolved": "https://registry.npmjs.org/color-name/-/color-name-1.1.3.tgz",
"integrity": "sha1-p9BVi9icQveV3UIyj3QIMcpTvCU=",
"dev": true
},
"is-fullwidth-code-point": { "is-fullwidth-code-point": {
"version": "2.0.0", "version": "2.0.0",
"resolved": "https://registry.npmjs.org/is-fullwidth-code-point/-/is-fullwidth-code-point-2.0.0.tgz", "resolved": "https://registry.npmjs.org/is-fullwidth-code-point/-/is-fullwidth-code-point-2.0.0.tgz",
@@ -1304,16 +1324,15 @@
} }
}, },
"strip-json-comments": { "strip-json-comments": {
"version": "3.0.1", "version": "3.1.0",
"resolved": "https://registry.npmjs.org/strip-json-comments/-/strip-json-comments-3.0.1.tgz", "resolved": "https://registry.npmjs.org/strip-json-comments/-/strip-json-comments-3.1.0.tgz",
"integrity": "sha512-VTyMAUfdm047mwKl+u79WIdrZxtFtn+nBxHeb844XBQ9uMNTuTHdx2hc5RiAJYqwTj3wc/xe5HLSdJSkJ+WfZw==", "integrity": "sha512-e6/d0eBu7gHtdCqFt0xJr642LdToM5/cN4Qb9DbHjVx1CP5RyeM+zH7pbecEmDv/lBqb0QH+6Uqq75rxFPkM0w==",
"dev": true "dev": true
}, },
"supports-color": { "supports-color": {
"version": "5.5.0", "version": "5.5.0",
"resolved": "https://registry.npmjs.org/supports-color/-/supports-color-5.5.0.tgz", "resolved": "https://registry.npmjs.org/supports-color/-/supports-color-5.5.0.tgz",
"integrity": "sha512-QjVjwdXIt408MIiAqCX4oUKsgU2EqAGzs2Ppkm4aQYbjm+ZEWEcW4SfFNTr4uMNZma0ey4f5lgLrkB0aX0QMow==", "integrity": "sha512-QjVjwdXIt408MIiAqCX4oUKsgU2EqAGzs2Ppkm4aQYbjm+ZEWEcW4SfFNTr4uMNZma0ey4f5lgLrkB0aX0QMow==",
"dev": true,
"requires": { "requires": {
"has-flag": "^3.0.0" "has-flag": "^3.0.0"
} }
@@ -1391,17 +1410,17 @@
} }
}, },
"tmp-promise": { "tmp-promise": {
"version": "2.0.2", "version": "2.1.1",
"resolved": "https://registry.npmjs.org/tmp-promise/-/tmp-promise-2.0.2.tgz", "resolved": "https://registry.npmjs.org/tmp-promise/-/tmp-promise-2.1.1.tgz",
"integrity": "sha512-zl71nFWjPKW2KXs+73gEk8RmqvtAeXPxhWDkTUoa3MSMkjq3I+9OeknjF178MQoMYsdqL730hfzvNfEkePxq9Q==", "integrity": "sha512-Z048AOz/w9b6lCbJUpevIJpRpUztENl8zdv1bmAKVHimfqRFl92ROkmT9rp7TVBnrEw2gtMTol/2Cp2S2kJa4Q==",
"requires": { "requires": {
"tmp": "0.1.0" "tmp": "0.1.0"
} }
}, },
"tslib": { "tslib": {
"version": "1.11.1", "version": "1.13.0",
"resolved": "https://registry.npmjs.org/tslib/-/tslib-1.11.1.tgz", "resolved": "https://registry.npmjs.org/tslib/-/tslib-1.13.0.tgz",
"integrity": "sha512-aZW88SY8kQbU7gpV19lN24LtXh/yD4ZZg6qieAJDDg+YBsJcSmLGK9QpnUjAKVG/xefmvJGd1WUmfpT/g6AJGA==", "integrity": "sha512-i/6DQjL8Xf3be4K/E6Wgpekn5Qasl1usyw++dAA35Ue5orEn65VIxOA+YvNNl9HV3qv70T7CNwjODHZrLwvd1Q==",
"dev": true "dev": true
}, },
"type-check": { "type-check": {
@@ -1440,9 +1459,9 @@
} }
}, },
"v8-compile-cache": { "v8-compile-cache": {
"version": "2.1.0", "version": "2.1.1",
"resolved": "https://registry.npmjs.org/v8-compile-cache/-/v8-compile-cache-2.1.0.tgz", "resolved": "https://registry.npmjs.org/v8-compile-cache/-/v8-compile-cache-2.1.1.tgz",
"integrity": "sha512-usZBT3PW+LOjM25wbqIlZwPeJV+3OSz3M1k1Ws8snlW39dZyYL9lOGC5FgPVHfk0jKmjiDV8Z0mIbVQPiwFs7g==", "integrity": "sha512-8OQ9CL+VWyt3JStj7HX7/ciTL2V3Rl1Wf5OL+SNTm0yK1KvtReVulksyeRnCANHHuUxHlQig+JJDlUhBt1NQDQ==",
"dev": true "dev": true
}, },
"wasmbuilder": { "wasmbuilder": {
@@ -1481,6 +1500,30 @@
"ansi-styles": "^4.0.0", "ansi-styles": "^4.0.0",
"string-width": "^4.1.0", "string-width": "^4.1.0",
"strip-ansi": "^6.0.0" "strip-ansi": "^6.0.0"
},
"dependencies": {
"ansi-styles": {
"version": "4.2.1",
"resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-4.2.1.tgz",
"integrity": "sha512-9VGjrMsG1vePxcSweQsN20KY/c4zN0h9fLjqAbwbPfahM3t+NL+M9HC8xeXG2I8pX5NoamTGNuomEUFI7fcUjA==",
"requires": {
"@types/color-name": "^1.1.1",
"color-convert": "^2.0.1"
}
},
"color-convert": {
"version": "2.0.1",
"resolved": "https://registry.npmjs.org/color-convert/-/color-convert-2.0.1.tgz",
"integrity": "sha512-RRECPsj7iu/xb5oKYcsFHSppFNnsj/52OVTRKb4zP5onXwVF3zVmmToNcOfGC+CRDpfK/U584fMg38ZHCaElKQ==",
"requires": {
"color-name": "~1.1.4"
}
},
"color-name": {
"version": "1.1.4",
"resolved": "https://registry.npmjs.org/color-name/-/color-name-1.1.4.tgz",
"integrity": "sha512-dOy+3AuW3a2wNbZHIuMZpTcgjGuLU/uBL/ubcZF9OXbDo8ff4O8yVp5Bf0efS8uEoYo5q4Fx7dY9OgQGXgAsQA=="
}
} }
}, },
"wrappy": { "wrappy": {
@@ -1521,9 +1564,9 @@
} }
}, },
"yargs-parser": { "yargs-parser": {
"version": "18.1.2", "version": "18.1.3",
"resolved": "https://registry.npmjs.org/yargs-parser/-/yargs-parser-18.1.2.tgz", "resolved": "https://registry.npmjs.org/yargs-parser/-/yargs-parser-18.1.3.tgz",
"integrity": "sha512-hlIPNR3IzC1YuL1c2UwwDKpXlNFBqD1Fswwh1khz5+d8Cq/8yc/Mn0i+rQXduu8hcrFKvO7Eryk+09NecTQAAQ==", "integrity": "sha512-o50j0JeToy/4K6OZcaQmW6lyXXKhq7csREXcDwk2omFPJEwUNOVtJKvmDr9EI1fAJZUyZcRF7kxGBWmRXudrCQ==",
"requires": { "requires": {
"camelcase": "^5.0.0", "camelcase": "^5.0.0",
"decamelize": "^1.2.0" "decamelize": "^1.2.0"

View File

@@ -1,6 +1,6 @@
{ {
"name": "circom", "name": "circom",
"version": "0.5.6", "version": "0.5.12",
"description": "Language to generate logic circuits", "description": "Language to generate logic circuits",
"main": "index.js", "main": "index.js",
"directories": { "directories": {
@@ -29,14 +29,14 @@
"url": "https://github.com/iden3/circom.git" "url": "https://github.com/iden3/circom.git"
}, },
"dependencies": { "dependencies": {
"big-integer": "^1.6.32",
"chai": "^4.2.0", "chai": "^4.2.0",
"circom_runtime": "0.0.3", "circom_runtime": "0.0.6",
"fastfile": "0.0.2",
"ffiasm": "0.0.2", "ffiasm": "0.0.2",
"ffjavascript": "0.0.5", "ffjavascript": "0.1.2",
"ffwasm": "0.0.6", "ffwasm": "0.0.7",
"fnv-plus": "^1.3.1", "fnv-plus": "^1.3.1",
"r1csfile": "0.0.3", "r1csfile": "0.0.5",
"tmp-promise": "^2.0.2", "tmp-promise": "^2.0.2",
"wasmbuilder": "0.0.10" "wasmbuilder": "0.0.10"
}, },

View File

@@ -132,10 +132,8 @@ include { return 'include'; }
%{ %{
const bigInt = require('big-integer'); const Scalar = require('ffjavascript').Scalar;
const util = require('util'); const util = require('util');
const __P__ = new bigInt("21888242871839275222246405745257275088548364400416034343698204186575808495617");
const __MASK__ = new bigInt(2).pow(253).minus(1);
function setLines(dst, first, last) { function setLines(dst, first, last) {
last = last || first; last = last || first;
@@ -266,20 +264,12 @@ identifierList
ifStatment ifStatment
: 'if' '(' expression ')' statment 'else' statment : 'if' '(' expression ')' statment 'else' statment
{ {
if ($3.type == "NUMBER") { $$ = { type: "IF", condition: $3, then: $5, else: $7 };
$$ = !$3.value.eq(0) ? $5 : $7;
} else {
$$ = { type: "IF", condition: $3, then: $5, else: $7 };
}
setLines($$, @1, @7); setLines($$, @1, @7);
} }
| 'if' '(' expression ')' statment | 'if' '(' expression ')' statment
{ {
if ($3.type == "NUMBER") { $$ = { type: "IF", condition: $3, then: $5 };
$$ = !$3.value.eq(0) ? $5 : { type: "NUMBER", value: bigInt(0) };
} else {
$$ = { type: "IF", condition: $3, then: $5 };
}
setLines($$, @1, @5); setLines($$, @1, @5);
} }
; ;
@@ -451,11 +441,7 @@ e17
} }
| e17 '?' e17 ':' e17 %prec TERCOND | e17 '?' e17 ':' e17 %prec TERCOND
{ {
if ($1.type == "NUMBER") { $$ = { type: "OP", op: "?", values: [$1, $3, $5] };
$$ = !$1.value.eq(0) ? $3 : $5;
} else {
$$ = { type: "OP", op: "?", values: [$1, $3, $5] };
}
setLines($$, @1, @5); setLines($$, @1, @5);
} }
| e16 %prec EMPTY | e16 %prec EMPTY
@@ -478,11 +464,7 @@ e16
e15 e15
: e15 '||' e14 : e15 '||' e14
{ {
if (($1.type == "NUMBER") && ($3.type == "NUMBER")) { $$ = { type: "OP", op: "||", values: [$1, $3] };
$$ = { type: "NUMBER", value: !$1.value.eq(0) || !$3.value.eq(0) ? bigInt(1) : bigInt(0) };
} else {
$$ = { type: "OP", op: "||", values: [$1, $3] };
}
setLines($$, @1, @3); setLines($$, @1, @3);
} }
| e14 %prec EMPTY | e14 %prec EMPTY
@@ -494,11 +476,7 @@ e15
e14 e14
: e14 '&&' e13 : e14 '&&' e13
{ {
if (($1.type == "NUMBER") && ($3.type == "NUMBER")) { $$ = { type: "OP", op: "&&", values: [$1, $3] };
$$ = { type: "NUMBER", value: !$1.value.eq(0) && !$3.value.eq(0) ? bigInt(1) : bigInt(0) };
} else {
$$ = { type: "OP", op: "&&", values: [$1, $3] };
}
setLines($$, @1, @3); setLines($$, @1, @3);
} }
| e13 %prec EMPTY | e13 %prec EMPTY
@@ -510,11 +488,7 @@ e14
e13 e13
: e13 '|' e12 : e13 '|' e12
{ {
if (($1.type == "NUMBER") && ($3.type == "NUMBER")) { $$ = { type: "OP", op: "|", values: [$1, $3] };
$$ = { type: "NUMBER", value: $1.value.or($3.value).and(__MASK__) };
} else {
$$ = { type: "OP", op: "|", values: [$1, $3] };
}
setLines($$, @1, @3); setLines($$, @1, @3);
} }
| e12 %prec EMPTY | e12 %prec EMPTY
@@ -527,11 +501,7 @@ e13
e12 e12
: e12 '^' e11 : e12 '^' e11
{ {
if (($1.type == "NUMBER") && ($3.type == "NUMBER")) { $$ = { type: "OP", op: "^", values: [$1, $3] };
$$ = { type: "NUMBER", value: $1.value.xor($3.value).and(__MASK__) };
} else {
$$ = { type: "OP", op: "^", values: [$1, $3] };
}
setLines($$, @1, @3); setLines($$, @1, @3);
} }
| e11 %prec EMPTY | e11 %prec EMPTY
@@ -543,11 +513,7 @@ e12
e11 e11
: e11 '&' e10 : e11 '&' e10
{ {
if (($1.type == "NUMBER") && ($3.type == "NUMBER")) { $$ = { type: "OP", op: "&", values: [$1, $3] };
$$ = { type: "NUMBER", value: $1.value.and($3.value).and(__MASK__) };
} else {
$$ = { type: "OP", op: "&", values: [$1, $3] };
}
setLines($$, @1, @3); setLines($$, @1, @3);
} }
| e10 %prec EMPTY | e10 %prec EMPTY
@@ -562,20 +528,12 @@ e11
e10 e10
: e10 '==' e9 : e10 '==' e9
{ {
if (($1.type == "NUMBER") && ($3.type == "NUMBER")) { $$ = { type: "OP", op: "==", values: [$1, $3] };
$$ = { type: "NUMBER", value: $1.value.equals($3.value) ? bigInt(1) : bigInt(0) };
} else {
$$ = { type: "OP", op: "==", values: [$1, $3] };
}
setLines($$, @1, @3); setLines($$, @1, @3);
} }
| e10 '!=' e9 | e10 '!=' e9
{ {
if (($1.type == "NUMBER") && ($3.type == "NUMBER")) { $$ = { type: "OP", op: "!=", values: [$1, $3] };
$$ = { type: "NUMBER", value: $1.value.eq($3.value) ? bigInt(0) : bigInt(1) };
} else {
$$ = { type: "OP", op: "!=", values: [$1, $3] };
}
setLines($$, @1, @3); setLines($$, @1, @3);
} }
| e9 %prec EMPTY | e9 %prec EMPTY
@@ -587,38 +545,22 @@ e10
e9 e9
: e9 '<=' e7 : e9 '<=' e7
{ {
if (($1.type == "NUMBER") && ($3.type == "NUMBER")) { $$ = { type: "OP", op: "<=", values: [$1, $3] };
$$ = { type: "NUMBER", value: $1.value.lesserOrEquals($3.value) ? bigInt(1) : bigInt(0) };
} else {
$$ = { type: "OP", op: "<=", values: [$1, $3] };
}
setLines($$, @1, @3); setLines($$, @1, @3);
} }
| e9 '>=' e7 | e9 '>=' e7
{ {
if (($1.type == "NUMBER") && ($3.type == "NUMBER")) { $$ = { type: "OP", op: ">=", values: [$1, $3] };
$$ = { type: "NUMBER", value: $1.value.greaterOrEquals($3.value) ? bigInt(1) : bigInt(0) };
} else {
$$ = { type: "OP", op: ">=", values: [$1, $3] };
}
setLines($$, @1, @3); setLines($$, @1, @3);
} }
| e9 '<' e7 | e9 '<' e7
{ {
if (($1.type == "NUMBER") && ($3.type == "NUMBER")) { $$ = { type: "OP", op: "<", values: [$1, $3] };
$$ = { type: "NUMBER", value: $1.value.lesser($3.value) ? bigInt(1) : bigInt(0) };
} else {
$$ = { type: "OP", op: "<", values: [$1, $3] };
}
setLines($$, @1, @3); setLines($$, @1, @3);
} }
| e9 '>' e7 | e9 '>' e7
{ {
if (($1.type == "NUMBER") && ($3.type == "NUMBER")) { $$ = { type: "OP", op: ">", values: [$1, $3] };
$$ = { type: "NUMBER", value: $1.value.greater($3.value) ? bigInt(1) : bigInt(0) };
} else {
$$ = { type: "OP", op: ">", values: [$1, $3] };
}
setLines($$, @1, @3); setLines($$, @1, @3);
} }
| e7 %prec EMPTY | e7 %prec EMPTY
@@ -630,22 +572,12 @@ e9
e7 e7
: e7 '<<' e6 : e7 '<<' e6
{ {
if (($1.type == "NUMBER") && ($3.type == "NUMBER")) { $$ = { type: "OP", op: "<<", values: [$1, $3] };
let v = $3.value.greater(256) ? 256 : $3.value.value;
$$ = { type: "NUMBER", value: $1.value.shiftLeft(v).and(__MASK__) };
} else {
$$ = { type: "OP", op: "<<", values: [$1, $3] };
}
setLines($$, @1, @3); setLines($$, @1, @3);
} }
| e7 '>>' e6 | e7 '>>' e6
{ {
if (($1.type == "NUMBER") && ($3.type == "NUMBER")) { $$ = { type: "OP", op: ">>", values: [$1, $3] };
let v = $3.value.greater(256) ? 256 : $3.value.value;
$$ = {type: "NUMBER", value: $1.value.shiftRight(v).and(__MASK__) };
} else {
$$ = { type: "OP", op: ">>", values: [$1, $3] };
}
setLines($$, @1, @3); setLines($$, @1, @3);
} }
| e6 %prec EMPTY | e6 %prec EMPTY
@@ -657,20 +589,12 @@ e7
e6 e6
: e6 '+' e5 : e6 '+' e5
{ {
if (($1.type == "NUMBER") && ($3.type == "NUMBER")) { $$ = { type: "OP", op: "+", values: [$1, $3] };
$$ = { type: "NUMBER", value: ($1.value.plus($3.value)).mod(__P__) };
} else {
$$ = { type: "OP", op: "+", values: [$1, $3] };
}
setLines($$, @1, @3); setLines($$, @1, @3);
} }
| e6 '-' e5 | e6 '-' e5
{ {
if (($1.type == "NUMBER") && ($3.type == "NUMBER")) { $$ = { type: "OP", op: "-", values: [$1, $3] };
$$ = { type: "NUMBER", value: ($1.value.plus(__P__).minus($3.value)).mod(__P__) };
} else {
$$ = { type: "OP", op: "-", values: [$1, $3] };
}
setLines($$, @1, @3); setLines($$, @1, @3);
} }
| e5 %prec EMPTY | e5 %prec EMPTY
@@ -683,38 +607,22 @@ e6
e5 e5
: e5 '*' e4 : e5 '*' e4
{ {
if (($1.type == "NUMBER") && ($3.type == "NUMBER")) { $$ = { type: "OP", op: "*", values: [$1, $3] };
$$ = { type: "NUMBER", value: ($1.value.times($3.value)).mod(__P__) };
} else {
$$ = { type: "OP", op: "*", values: [$1, $3] };
}
setLines($$, @1, @3); setLines($$, @1, @3);
} }
| e5 '/' e4 | e5 '/' e4
{ {
if (($1.type == "NUMBER") && ($3.type == "NUMBER")) { $$ = { type: "OP", op: "/", values: [$1, $3] };
$$ = { type: "NUMBER", value: ($1.value.times($3.value.modInv(__P__))).mod(__P__) };
} else {
$$ = { type: "OP", op: "/", values: [$1, $3] };
}
setLines($$, @1, @3); setLines($$, @1, @3);
} }
| e5 '\\' e4 | e5 '\\' e4
{ {
if (($1.type == "NUMBER") && ($3.type == "NUMBER")) { $$ = { type: "OP", op: "\\", values: [$1, $3] };
$$ = { type: "NUMBER", value: ($1.value.divide($3.value)) };
} else {
$$ = { type: "OP", op: "\\", values: [$1, $3] };
}
setLines($$, @1, @3); setLines($$, @1, @3);
} }
| e5 '%' e4 | e5 '%' e4
{ {
if (($1.type == "NUMBER") && ($3.type == "NUMBER")) { $$ = { type: "OP", op: "%", values: [$1, $3] };
$$ = { type: "NUMBER", value: $1.value.mod($3.value) };
} else {
$$ = { type: "OP", op: "%", values: [$1, $3] };
}
setLines($$, @1, @3); setLines($$, @1, @3);
} }
| e4 %prec EMPTY | e4 %prec EMPTY
@@ -726,11 +634,7 @@ e5
e4 e4
: e4 '**' e3 : e4 '**' e3
{ {
if (($1.type == "NUMBER") && ($3.type == "NUMBER")) { $$ = { type: "OP", op: "**", values: [$1, $3] };
$$ = { type: "NUMBER", value: $1.value.modPow($3.value, __P__) };
} else {
$$ = { type: "OP", op: "**", values: [$1, $3] };
}
setLines($$, @1, @3); setLines($$, @1, @3);
} }
| e3 %prec EMPTY | e3 %prec EMPTY
@@ -758,29 +662,17 @@ e3
} }
| '-' e3 %prec UMINUS | '-' e3 %prec UMINUS
{ {
if ($2.type == "NUMBER") { $$ = { type: "OP", op: "UMINUS", values: [$2] };
$$ = { type: "NUMBER", value: __P__.minus($2.value).mod(__P__) };
} else {
$$ = { type: "OP", op: "UMINUS", values: [$2] };
}
setLines($$, @1, @2); setLines($$, @1, @2);
} }
| '!' e3 | '!' e3
{ {
if ($2.type == "NUMBER") { $$ = { type: "OP", op: "!", values: [$2] };
$$ = { type: "NUMBER", value: $2.value.eq(0) ? bigInt(1) : bigInt(0) };
} else {
$$ = { type: "OP", op: "!", values: [$2] };
}
setLines($$, @1, @2); setLines($$, @1, @2);
} }
| '~' e3 | '~' e3
{ {
if ($2.type == "NUMBER") { $$ = { type: "OP", op: "~", values: [$2] };
$$ = { type: "NUMBER", value: $2.value.xor(__MASK__) };
} else {
$$ = { type: "OP", op: "~", values: [$2] };
}
setLines($$, @1, @2); setLines($$, @1, @2);
} }
| e2 %prec EMPTY | e2 %prec EMPTY
@@ -817,12 +709,12 @@ e0
} }
| DECNUMBER | DECNUMBER
{ {
$$ = {type: "NUMBER", value: bigInt($1).mod(__P__) } $$ = {type: "NUMBER", value: Scalar.fromString($1) }
setLines($$, @1); setLines($$, @1);
} }
| HEXNUMBER | HEXNUMBER
{ {
$$ = {type: "NUMBER", value: bigInt($1.substr(2).toUpperCase(), 16).mod(__P__) } $$ = {type: "NUMBER", value: Scalar.fromString($1.substr(2).toUpperCase(), 16) }
setLines($$, @1); setLines($$, @1);
} }
| '(' expression ')' %prec EMPTY | '(' expression ')' %prec EMPTY

View File

@@ -146,21 +146,13 @@ case 20:
break; break;
case 21: case 21:
if ($$[$0-4].type == "NUMBER") { this.$ = { type: "IF", condition: $$[$0-4], then: $$[$0-2], else: $$[$0] };
this.$ = !$$[$0-4].value.eq(0) ? $$[$0-2] : $$[$0];
} else {
this.$ = { type: "IF", condition: $$[$0-4], then: $$[$0-2], else: $$[$0] };
}
setLines(this.$, _$[$0-6], _$[$0]); setLines(this.$, _$[$0-6], _$[$0]);
break; break;
case 22: case 22:
if ($$[$0-2].type == "NUMBER") { this.$ = { type: "IF", condition: $$[$0-2], then: $$[$0] };
this.$ = !$$[$0-2].value.eq(0) ? $$[$0] : { type: "NUMBER", value: bigInt(0) };
} else {
this.$ = { type: "IF", condition: $$[$0-2], then: $$[$0] };
}
setLines(this.$, _$[$0-4], _$[$0]); setLines(this.$, _$[$0-4], _$[$0]);
break; break;
@@ -321,11 +313,7 @@ case 50:
break; break;
case 51: case 51:
if ($$[$0-4].type == "NUMBER") { this.$ = { type: "OP", op: "?", values: [$$[$0-4], $$[$0-2], $$[$0]] };
this.$ = !$$[$0-4].value.eq(0) ? $$[$0-2] : $$[$0];
} else {
this.$ = { type: "OP", op: "?", values: [$$[$0-4], $$[$0-2], $$[$0]] };
}
setLines(this.$, _$[$0-4], _$[$0]); setLines(this.$, _$[$0-4], _$[$0]);
break; break;
@@ -336,71 +324,43 @@ case 52: case 53: case 54: case 56: case 58: case 60:
break; break;
case 55: case 55:
if (($$[$0-2].type == "NUMBER") && ($$[$0].type == "NUMBER")) { this.$ = { type: "OP", op: "||", values: [$$[$0-2], $$[$0]] };
this.$ = { type: "NUMBER", value: !$$[$0-2].value.eq(0) || !$$[$0].value.eq(0) ? bigInt(1) : bigInt(0) };
} else {
this.$ = { type: "OP", op: "||", values: [$$[$0-2], $$[$0]] };
}
setLines(this.$, _$[$0-2], _$[$0]); setLines(this.$, _$[$0-2], _$[$0]);
break; break;
case 57: case 57:
if (($$[$0-2].type == "NUMBER") && ($$[$0].type == "NUMBER")) { this.$ = { type: "OP", op: "&&", values: [$$[$0-2], $$[$0]] };
this.$ = { type: "NUMBER", value: !$$[$0-2].value.eq(0) && !$$[$0].value.eq(0) ? bigInt(1) : bigInt(0) };
} else {
this.$ = { type: "OP", op: "&&", values: [$$[$0-2], $$[$0]] };
}
setLines(this.$, _$[$0-2], _$[$0]); setLines(this.$, _$[$0-2], _$[$0]);
break; break;
case 59: case 59:
if (($$[$0-2].type == "NUMBER") && ($$[$0].type == "NUMBER")) { this.$ = { type: "OP", op: "|", values: [$$[$0-2], $$[$0]] };
this.$ = { type: "NUMBER", value: $$[$0-2].value.or($$[$0].value).and(__MASK__) };
} else {
this.$ = { type: "OP", op: "|", values: [$$[$0-2], $$[$0]] };
}
setLines(this.$, _$[$0-2], _$[$0]); setLines(this.$, _$[$0-2], _$[$0]);
break; break;
case 61: case 61:
if (($$[$0-2].type == "NUMBER") && ($$[$0].type == "NUMBER")) { this.$ = { type: "OP", op: "^", values: [$$[$0-2], $$[$0]] };
this.$ = { type: "NUMBER", value: $$[$0-2].value.xor($$[$0].value).and(__MASK__) };
} else {
this.$ = { type: "OP", op: "^", values: [$$[$0-2], $$[$0]] };
}
setLines(this.$, _$[$0-2], _$[$0]); setLines(this.$, _$[$0-2], _$[$0]);
break; break;
case 63: case 63:
if (($$[$0-2].type == "NUMBER") && ($$[$0].type == "NUMBER")) { this.$ = { type: "OP", op: "&", values: [$$[$0-2], $$[$0]] };
this.$ = { type: "NUMBER", value: $$[$0-2].value.and($$[$0].value).and(__MASK__) };
} else {
this.$ = { type: "OP", op: "&", values: [$$[$0-2], $$[$0]] };
}
setLines(this.$, _$[$0-2], _$[$0]); setLines(this.$, _$[$0-2], _$[$0]);
break; break;
case 65: case 65:
if (($$[$0-2].type == "NUMBER") && ($$[$0].type == "NUMBER")) { this.$ = { type: "OP", op: "==", values: [$$[$0-2], $$[$0]] };
this.$ = { type: "NUMBER", value: $$[$0-2].value.equals($$[$0].value) ? bigInt(1) : bigInt(0) };
} else {
this.$ = { type: "OP", op: "==", values: [$$[$0-2], $$[$0]] };
}
setLines(this.$, _$[$0-2], _$[$0]); setLines(this.$, _$[$0-2], _$[$0]);
break; break;
case 66: case 66:
if (($$[$0-2].type == "NUMBER") && ($$[$0].type == "NUMBER")) { this.$ = { type: "OP", op: "!=", values: [$$[$0-2], $$[$0]] };
this.$ = { type: "NUMBER", value: $$[$0-2].value.eq($$[$0].value) ? bigInt(0) : bigInt(1) };
} else {
this.$ = { type: "OP", op: "!=", values: [$$[$0-2], $$[$0]] };
}
setLines(this.$, _$[$0-2], _$[$0]); setLines(this.$, _$[$0-2], _$[$0]);
break; break;
@@ -411,63 +371,37 @@ case 67: case 72:
break; break;
case 68: case 68:
if (($$[$0-2].type == "NUMBER") && ($$[$0].type == "NUMBER")) { this.$ = { type: "OP", op: "<=", values: [$$[$0-2], $$[$0]] };
this.$ = { type: "NUMBER", value: $$[$0-2].value.lesserOrEquals($$[$0].value) ? bigInt(1) : bigInt(0) };
} else {
this.$ = { type: "OP", op: "<=", values: [$$[$0-2], $$[$0]] };
}
setLines(this.$, _$[$0-2], _$[$0]); setLines(this.$, _$[$0-2], _$[$0]);
break; break;
case 69: case 69:
if (($$[$0-2].type == "NUMBER") && ($$[$0].type == "NUMBER")) { this.$ = { type: "OP", op: ">=", values: [$$[$0-2], $$[$0]] };
this.$ = { type: "NUMBER", value: $$[$0-2].value.greaterOrEquals($$[$0].value) ? bigInt(1) : bigInt(0) };
} else {
this.$ = { type: "OP", op: ">=", values: [$$[$0-2], $$[$0]] };
}
setLines(this.$, _$[$0-2], _$[$0]); setLines(this.$, _$[$0-2], _$[$0]);
break; break;
case 70: case 70:
if (($$[$0-2].type == "NUMBER") && ($$[$0].type == "NUMBER")) { this.$ = { type: "OP", op: "<", values: [$$[$0-2], $$[$0]] };
this.$ = { type: "NUMBER", value: $$[$0-2].value.lesser($$[$0].value) ? bigInt(1) : bigInt(0) };
} else {
this.$ = { type: "OP", op: "<", values: [$$[$0-2], $$[$0]] };
}
setLines(this.$, _$[$0-2], _$[$0]); setLines(this.$, _$[$0-2], _$[$0]);
break; break;
case 71: case 71:
if (($$[$0-2].type == "NUMBER") && ($$[$0].type == "NUMBER")) { this.$ = { type: "OP", op: ">", values: [$$[$0-2], $$[$0]] };
this.$ = { type: "NUMBER", value: $$[$0-2].value.greater($$[$0].value) ? bigInt(1) : bigInt(0) };
} else {
this.$ = { type: "OP", op: ">", values: [$$[$0-2], $$[$0]] };
}
setLines(this.$, _$[$0-2], _$[$0]); setLines(this.$, _$[$0-2], _$[$0]);
break; break;
case 73: case 73:
if (($$[$0-2].type == "NUMBER") && ($$[$0].type == "NUMBER")) { this.$ = { type: "OP", op: "<<", values: [$$[$0-2], $$[$0]] };
let v = $$[$0].value.greater(256) ? 256 : $$[$0].value.value;
this.$ = { type: "NUMBER", value: $$[$0-2].value.shiftLeft(v).and(__MASK__) };
} else {
this.$ = { type: "OP", op: "<<", values: [$$[$0-2], $$[$0]] };
}
setLines(this.$, _$[$0-2], _$[$0]); setLines(this.$, _$[$0-2], _$[$0]);
break; break;
case 74: case 74:
if (($$[$0-2].type == "NUMBER") && ($$[$0].type == "NUMBER")) { this.$ = { type: "OP", op: ">>", values: [$$[$0-2], $$[$0]] };
let v = $$[$0].value.greater(256) ? 256 : $$[$0].value.value;
this.$ = {type: "NUMBER", value: $$[$0-2].value.shiftRight(v).and(__MASK__) };
} else {
this.$ = { type: "OP", op: ">>", values: [$$[$0-2], $$[$0]] };
}
setLines(this.$, _$[$0-2], _$[$0]); setLines(this.$, _$[$0-2], _$[$0]);
break; break;
@@ -478,71 +412,43 @@ case 75:
break; break;
case 76: case 76:
if (($$[$0-2].type == "NUMBER") && ($$[$0].type == "NUMBER")) { this.$ = { type: "OP", op: "+", values: [$$[$0-2], $$[$0]] };
this.$ = { type: "NUMBER", value: ($$[$0-2].value.plus($$[$0].value)).mod(__P__) };
} else {
this.$ = { type: "OP", op: "+", values: [$$[$0-2], $$[$0]] };
}
setLines(this.$, _$[$0-2], _$[$0]); setLines(this.$, _$[$0-2], _$[$0]);
break; break;
case 77: case 77:
if (($$[$0-2].type == "NUMBER") && ($$[$0].type == "NUMBER")) { this.$ = { type: "OP", op: "-", values: [$$[$0-2], $$[$0]] };
this.$ = { type: "NUMBER", value: ($$[$0-2].value.plus(__P__).minus($$[$0].value)).mod(__P__) };
} else {
this.$ = { type: "OP", op: "-", values: [$$[$0-2], $$[$0]] };
}
setLines(this.$, _$[$0-2], _$[$0]); setLines(this.$, _$[$0-2], _$[$0]);
break; break;
case 79: case 79:
if (($$[$0-2].type == "NUMBER") && ($$[$0].type == "NUMBER")) { this.$ = { type: "OP", op: "*", values: [$$[$0-2], $$[$0]] };
this.$ = { type: "NUMBER", value: ($$[$0-2].value.times($$[$0].value)).mod(__P__) };
} else {
this.$ = { type: "OP", op: "*", values: [$$[$0-2], $$[$0]] };
}
setLines(this.$, _$[$0-2], _$[$0]); setLines(this.$, _$[$0-2], _$[$0]);
break; break;
case 80: case 80:
if (($$[$0-2].type == "NUMBER") && ($$[$0].type == "NUMBER")) { this.$ = { type: "OP", op: "/", values: [$$[$0-2], $$[$0]] };
this.$ = { type: "NUMBER", value: ($$[$0-2].value.times($$[$0].value.modInv(__P__))).mod(__P__) };
} else {
this.$ = { type: "OP", op: "/", values: [$$[$0-2], $$[$0]] };
}
setLines(this.$, _$[$0-2], _$[$0]); setLines(this.$, _$[$0-2], _$[$0]);
break; break;
case 81: case 81:
if (($$[$0-2].type == "NUMBER") && ($$[$0].type == "NUMBER")) { this.$ = { type: "OP", op: "\\", values: [$$[$0-2], $$[$0]] };
this.$ = { type: "NUMBER", value: ($$[$0-2].value.divide($$[$0].value)) };
} else {
this.$ = { type: "OP", op: "\\", values: [$$[$0-2], $$[$0]] };
}
setLines(this.$, _$[$0-2], _$[$0]); setLines(this.$, _$[$0-2], _$[$0]);
break; break;
case 82: case 82:
if (($$[$0-2].type == "NUMBER") && ($$[$0].type == "NUMBER")) { this.$ = { type: "OP", op: "%", values: [$$[$0-2], $$[$0]] };
this.$ = { type: "NUMBER", value: $$[$0-2].value.mod($$[$0].value) };
} else {
this.$ = { type: "OP", op: "%", values: [$$[$0-2], $$[$0]] };
}
setLines(this.$, _$[$0-2], _$[$0]); setLines(this.$, _$[$0-2], _$[$0]);
break; break;
case 84: case 84:
if (($$[$0-2].type == "NUMBER") && ($$[$0].type == "NUMBER")) { this.$ = { type: "OP", op: "**", values: [$$[$0-2], $$[$0]] };
this.$ = { type: "NUMBER", value: $$[$0-2].value.modPow($$[$0].value, __P__) };
} else {
this.$ = { type: "OP", op: "**", values: [$$[$0-2], $$[$0]] };
}
setLines(this.$, _$[$0-2], _$[$0]); setLines(this.$, _$[$0-2], _$[$0]);
break; break;
@@ -566,31 +472,19 @@ case 88:
break; break;
case 89: case 89:
if ($$[$0].type == "NUMBER") { this.$ = { type: "OP", op: "UMINUS", values: [$$[$0]] };
this.$ = { type: "NUMBER", value: __P__.minus($$[$0].value).mod(__P__) };
} else {
this.$ = { type: "OP", op: "UMINUS", values: [$$[$0]] };
}
setLines(this.$, _$[$0-1], _$[$0]); setLines(this.$, _$[$0-1], _$[$0]);
break; break;
case 90: case 90:
if ($$[$0].type == "NUMBER") { this.$ = { type: "OP", op: "!", values: [$$[$0]] };
this.$ = { type: "NUMBER", value: $$[$0].value.eq(0) ? bigInt(1) : bigInt(0) };
} else {
this.$ = { type: "OP", op: "!", values: [$$[$0]] };
}
setLines(this.$, _$[$0-1], _$[$0]); setLines(this.$, _$[$0-1], _$[$0]);
break; break;
case 91: case 91:
if ($$[$0].type == "NUMBER") { this.$ = { type: "OP", op: "~", values: [$$[$0]] };
this.$ = { type: "NUMBER", value: $$[$0].value.xor(__MASK__) };
} else {
this.$ = { type: "OP", op: "~", values: [$$[$0]] };
}
setLines(this.$, _$[$0-1], _$[$0]); setLines(this.$, _$[$0-1], _$[$0]);
break; break;
@@ -613,13 +507,13 @@ case 97: case 102: case 103:
break; break;
case 98: case 98:
this.$ = {type: "NUMBER", value: bigInt($$[$0]).mod(__P__) } this.$ = {type: "NUMBER", value: Scalar.fromString($$[$0]) }
setLines(this.$, _$[$0]); setLines(this.$, _$[$0]);
break; break;
case 99: case 99:
this.$ = {type: "NUMBER", value: bigInt($$[$0].substr(2).toUpperCase(), 16).mod(__P__) } this.$ = {type: "NUMBER", value: Scalar.fromString($$[$0].substr(2).toUpperCase(), 16) }
setLines(this.$, _$[$0]); setLines(this.$, _$[$0]);
break; break;
@@ -866,10 +760,8 @@ parse: function parse(input) {
return true; return true;
}}; }};
const bigInt = require('big-integer'); const Scalar = require('ffjavascript').Scalar;
const util = require('util'); const util = require('util');
const __P__ = new bigInt("21888242871839275222246405745257275088548364400416034343698204186575808495617");
const __MASK__ = new bigInt(2).pow(253).minus(1);
function setLines(dst, first, last) { function setLines(dst, first, last) {
last = last || first; last = last || first;
@@ -1365,7 +1257,7 @@ case 77: console.log("INVALID: " + yy_.yytext); return 'INVALID'
break; break;
} }
}, },
rules: [/^(?:\s+)/,/^(?:\/\*([^*]|[\r\n]|(\*+([^*\/]|[\r\n])))*\*+\/)/,/^(?:\/\/.*)/,/^(?:var\b)/,/^(?:signal\b)/,/^(?:private\b)/,/^(?:input\b)/,/^(?:output\b)/,/^(?:linearCombination\b)/,/^(?:component\b)/,/^(?:template\b)/,/^(?:function\b)/,/^(?:if\b)/,/^(?:else\b)/,/^(?:for\b)/,/^(?:while\b)/,/^(?:compute\b)/,/^(?:do\b)/,/^(?:return\b)/,/^(?:include\b)/,/^(?:0x[0-9A-Fa-f]*)/,/^(?:[0-9]+)/,/^(?:[a-zA-Z][a-zA-Z$_0-9]*)/,/^(?:"[^"]+")/,/^(?:==>)/,/^(?:<==)/,/^(?:-->)/,/^(?:<--)/,/^(?:===)/,/^(?:>>=)/,/^(?:<<=)/,/^(?:&&)/,/^(?:\|\|)/,/^(?:==)/,/^(?:<=)/,/^(?:>=)/,/^(?:!=)/,/^(?:>>)/,/^(?:<<)/,/^(?:\*\*)/,/^(?:\+\+)/,/^(?:--)/,/^(?:\+=)/,/^(?:-=)/,/^(?:\*=)/,/^(?:\/=)/,/^(?:%=)/,/^(?:\|=)/,/^(?:&=)/,/^(?:\^=)/,/^(?:=)/,/^(?:\+)/,/^(?:-)/,/^(?:\*)/,/^(?:\/)/,/^(?:\\)/,/^(?:%)/,/^(?:\^)/,/^(?:&)/,/^(?:\|)/,/^(?:!)/,/^(?:~)/,/^(?:<)/,/^(?:>)/,/^(?:!)/,/^(?:\?)/,/^(?::)/,/^(?:\()/,/^(?:\))/,/^(?:\[)/,/^(?:\])/,/^(?:\{)/,/^(?:\})/,/^(?:;)/,/^(?:,)/,/^(?:\.)/,/^(?:$)/,/^(?:.)/], rules: [/^(?:\s+)/,/^(?:\/\*([^*]|[\r\n]|(\*+([^*/]|[\r\n])))*\*+\/)/,/^(?:\/\/.*)/,/^(?:var\b)/,/^(?:signal\b)/,/^(?:private\b)/,/^(?:input\b)/,/^(?:output\b)/,/^(?:linearCombination\b)/,/^(?:component\b)/,/^(?:template\b)/,/^(?:function\b)/,/^(?:if\b)/,/^(?:else\b)/,/^(?:for\b)/,/^(?:while\b)/,/^(?:compute\b)/,/^(?:do\b)/,/^(?:return\b)/,/^(?:include\b)/,/^(?:0x[0-9A-Fa-f]*)/,/^(?:[0-9]+)/,/^(?:[a-zA-Z][a-zA-Z$_0-9]*)/,/^(?:"[^"]+")/,/^(?:==>)/,/^(?:<==)/,/^(?:-->)/,/^(?:<--)/,/^(?:===)/,/^(?:>>=)/,/^(?:<<=)/,/^(?:&&)/,/^(?:\|\|)/,/^(?:==)/,/^(?:<=)/,/^(?:>=)/,/^(?:!=)/,/^(?:>>)/,/^(?:<<)/,/^(?:\*\*)/,/^(?:\+\+)/,/^(?:--)/,/^(?:\+=)/,/^(?:-=)/,/^(?:\*=)/,/^(?:\/=)/,/^(?:%=)/,/^(?:\|=)/,/^(?:&=)/,/^(?:\^=)/,/^(?:=)/,/^(?:\+)/,/^(?:-)/,/^(?:\*)/,/^(?:\/)/,/^(?:\\)/,/^(?:%)/,/^(?:\^)/,/^(?:&)/,/^(?:\|)/,/^(?:!)/,/^(?:~)/,/^(?:<)/,/^(?:>)/,/^(?:!)/,/^(?:\?)/,/^(?::)/,/^(?:\()/,/^(?:\))/,/^(?:\[)/,/^(?:\])/,/^(?:\{)/,/^(?:\})/,/^(?:;)/,/^(?:,)/,/^(?:\.)/,/^(?:$)/,/^(?:.)/],
conditions: {"INITIAL":{"rules":[0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63,64,65,66,67,68,69,70,71,72,73,74,75,76,77],"inclusive":true}} conditions: {"INITIAL":{"rules":[0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63,64,65,66,67,68,69,70,71,72,73,74,75,76,77],"inclusive":true}}
}); });
return lexer; return lexer;

View File

@@ -1,7 +1,8 @@
const streamFromMultiArray = require("../../src/streamfromarray_txt.js"); const streamFromMultiArray = require("../../src/streamfromarray_txt.js");
const bigInt = require("big-integer");
const utils = require("../../src/utils"); const utils = require("../../src/utils");
const assert = require("assert"); const assert = require("assert");
const Scalar = require("ffjavascript").Scalar;
const F1Field = require("ffjavascript").F1Field;
function ref2src(c) { function ref2src(c) {
if ((c[0] == "R")||(c[0] == "RI")) { if ((c[0] == "R")||(c[0] == "RI")) {
@@ -340,7 +341,9 @@ class FunctionBuilderC {
} }
class BuilderC { class BuilderC {
constructor() { constructor(p) {
this.F = new F1Field(p);
this.hashMaps={}; this.hashMaps={};
this.componentEntriesTables={}; this.componentEntriesTables={};
this.sizes ={}; this.sizes ={};
@@ -348,7 +351,6 @@ class BuilderC {
this.functions = []; this.functions = [];
this.components = []; this.components = [];
this.usedConstants = {}; this.usedConstants = {};
} }
setHeader(header) { setHeader(header) {
@@ -369,9 +371,9 @@ class BuilderC {
} }
addConstant(c) { addConstant(c) {
c = bigInt(c); c = this.F.e(c);
const cS = c.toString(); const cS = c.toString();
if (this.usedConstants[cS]) return this.usedConstants[cS]; if (typeof this.usedConstants[cS] != "undefined") return this.usedConstants[cS];
this.constants.push(c); this.constants.push(c);
this.usedConstants[cS] = this.constants.length - 1; this.usedConstants[cS] = this.constants.length - 1;
return this.constants.length - 1; return this.constants.length - 1;
@@ -471,8 +473,6 @@ class BuilderC {
_buildConstants(code) { _buildConstants(code) {
const self = this; const self = this;
const n64 = Math.floor((self.header.P.bitLength() - 1) / 64)+1;
const R = bigInt.one.shiftLeft(n64*64);
code.push("// Constants"); code.push("// Constants");
code.push(`FrElement _constants[${self.constants.length}] = {`); code.push(`FrElement _constants[${self.constants.length}] = {`);
@@ -482,12 +482,19 @@ class BuilderC {
code.push("};"); code.push("};");
function number2Code(n) { function number2Code(n) {
if (n.lt(bigInt("80000000", 16)) ) { const minShort = self.F.neg(self.F.e("80000000"));
return addShortMontgomeryPositive(n); const maxShort = self.F.e("7FFFFFFF", 16);
}
if (n.geq(self.header.P.minus(bigInt("80000000", 16))) ) { if ( (self.F.geq(n, minShort))
return addShortMontgomeryNegative(n); &&(self.F.leq(n, maxShort)))
{
if (self.F.geq(n, self.F.zero)) {
return addShortMontgomeryPositive(n);
} else {
return addShortMontgomeryNegative(n);
}
} }
return addLongMontgomery(n); return addLongMontgomery(n);
@@ -497,7 +504,7 @@ class BuilderC {
function addShortMontgomeryNegative(a) { function addShortMontgomeryNegative(a) {
const b = a.minus(self.header.P); const b = -Scalar.toNumber(self.F.neg(a));
return `${b.toString()}, 0x40000000, { ${getLongString(toMontgomery(a))} }`; return `${b.toString()}, 0x40000000, { ${getLongString(toMontgomery(a))} }`;
} }
@@ -506,25 +513,31 @@ class BuilderC {
} }
function getLongString(a) { function getLongString(a) {
let r = bigInt(a);
let S = ""; let S = "";
let i = 0; const arr = Scalar.toArray(a, 0x100000000);
while (!r.isZero()) { for (let i=0; i<self.F.n64*2; i+=2) {
if (S!= "") S = S+","; const idx = arr.length-2-i;
S += "0x" + r.and(bigInt("FFFFFFFFFFFFFFFF", 16)).toString(16) + "LL";
i++; if (i>0) S = S + ",";
r = r.shiftRight(64);
} if ( idx >=0) {
while (i<n64) { let msb = arr[idx].toString(16);
if (S!= "") S = S+","; while (msb.length<8) msb = "0" + msb;
S += "0LL";
i++; let lsb = arr[idx+1].toString(16);
while (lsb.length<8) lsb = "0" + lsb;
S += "0x" + msb + lsb + "LL";
} else {
S += "0LL";
}
} }
return S; return S;
} }
function toMontgomery(a) { function toMontgomery(a) {
return a.times(R).mod(self.header.P); return self.F.mul(a, self.F.R);
} }
} }

View File

@@ -8,12 +8,14 @@ const compiler = require("../../src/compiler");
const util = require("util"); const util = require("util");
const exec = util.promisify(require("child_process").exec); const exec = util.promisify(require("child_process").exec);
const bigInt = require("big-integer"); const Scalar = require("ffjavascript").Scalar;
const utils = require("../../src/utils"); const utils = require("../../src/utils");
const loadR1cs = require("r1csfile").load; const loadR1cs = require("r1csfile").load;
const ZqField = require("ffjavascript").ZqField; const ZqField = require("ffjavascript").ZqField;
const buildZqField = require("ffiasm").buildZqField; const buildZqField = require("ffiasm").buildZqField;
const {stringifyBigInts, unstringifyBigInts } = require("ffjavascript").utils;
module.exports = c_tester; module.exports = c_tester;
@@ -31,7 +33,7 @@ async function c_tester(circomFile, _options) {
options.symWriteStream = fs.createWriteStream(path.join(dir.path, baseName + ".sym")); options.symWriteStream = fs.createWriteStream(path.join(dir.path, baseName + ".sym"));
options.r1csFileName = path.join(dir.path, baseName + ".r1cs"); options.r1csFileName = path.join(dir.path, baseName + ".r1cs");
options.p = options.p || bigInt("21888242871839275222246405745257275088548364400416034343698204186575808495617"); options.p = options.p || Scalar.fromString("21888242871839275222246405745257275088548364400416034343698204186575808495617");
await compiler(circomFile, options); await compiler(circomFile, options);
const source = await buildZqField(options.p, "Fr"); const source = await buildZqField(options.p, "Fr");
@@ -42,11 +44,14 @@ async function c_tester(circomFile, _options) {
await fs.promises.writeFile(path.join(dir.path, "fr.h"), source.h, "utf8"); await fs.promises.writeFile(path.join(dir.path, "fr.h"), source.h, "utf8");
await fs.promises.writeFile(path.join(dir.path, "fr.c"), source.c, "utf8"); await fs.promises.writeFile(path.join(dir.path, "fr.c"), source.c, "utf8");
let pThread = "";
if (process.platform === "darwin") { if (process.platform === "darwin") {
await exec("nasm -fmacho64 --prefix _ " + await exec("nasm -fmacho64 --prefix _ " +
` ${path.join(dir.path, "fr.asm")}` ` ${path.join(dir.path, "fr.asm")}`
); );
} else if (process.platform === "linux") { } else if (process.platform === "linux") {
pThread = "-pthread";
await exec("nasm -felf64 " + await exec("nasm -felf64 " +
` ${path.join(dir.path, "fr.asm")}` ` ${path.join(dir.path, "fr.asm")}`
); );
@@ -54,7 +59,7 @@ async function c_tester(circomFile, _options) {
const cdir = path.join(path.dirname(require.resolve("circom_runtime")), "c"); const cdir = path.join(path.dirname(require.resolve("circom_runtime")), "c");
await exec("g++" + await exec("g++" + ` ${pThread}` +
` ${path.join(cdir, "main.cpp")}` + ` ${path.join(cdir, "main.cpp")}` +
` ${path.join(cdir, "calcwit.cpp")}` + ` ${path.join(cdir, "calcwit.cpp")}` +
` ${path.join(cdir, "utils.cpp")}` + ` ${path.join(cdir, "utils.cpp")}` +
@@ -84,7 +89,7 @@ class CTester {
async calculateWitness(input) { async calculateWitness(input) {
await fs.promises.writeFile( await fs.promises.writeFile(
path.join(this.dir.path, "in.json"), path.join(this.dir.path, "in.json"),
JSON.stringify(utils.stringifyBigInts(input), null, 1) JSON.stringify(stringifyBigInts(input), null, 1)
); );
const r = await exec(`${path.join(this.dir.path, this.baseName)}` + const r = await exec(`${path.join(this.dir.path, this.baseName)}` +
` ${path.join(this.dir.path, "in.json")}` + ` ${path.join(this.dir.path, "in.json")}` +
@@ -97,7 +102,7 @@ class CTester {
path.join(this.dir.path, "out.json") path.join(this.dir.path, "out.json")
); );
const res = utils.unstringifyBigInts(JSON.parse(resStr)); const res = unstringifyBigInts(JSON.parse(resStr));
return res; return res;
} }
@@ -124,7 +129,7 @@ class CTester {
const self = this; const self = this;
if (this.constraints) return; if (this.constraints) return;
const r1cs = await loadR1cs(path.join(this.dir.path, this.baseName + ".r1cs"),true, false); const r1cs = await loadR1cs(path.join(this.dir.path, this.baseName + ".r1cs"),true, false);
self.field = new ZqField(r1cs.prime); self.F = new ZqField(r1cs.prime);
self.nVars = r1cs.nVars; self.nVars = r1cs.nVars;
self.constraints = r1cs.constraints; self.constraints = r1cs.constraints;
} }
@@ -149,8 +154,8 @@ class CTester {
if (typeof self.symbols[prefix] == "undefined") { if (typeof self.symbols[prefix] == "undefined") {
assert(false, "Output variable not defined: "+ prefix); assert(false, "Output variable not defined: "+ prefix);
} }
const ba = bigInt(actualOut[self.symbols[prefix].varIdx]).toString(); const ba = actualOut[self.symbols[prefix].varIdx].toString();
const be = bigInt(eOut).toString(); const be = eOut.toString();
assert.strictEqual(ba, be, prefix); assert.strictEqual(ba, be, prefix);
} }
} }
@@ -180,7 +185,7 @@ class CTester {
} }
function checkConstraint(constraint) { function checkConstraint(constraint) {
const F = self.field; const F = self.F;
const a = evalLC(constraint[0]); const a = evalLC(constraint[0]);
const b = evalLC(constraint[1]); const b = evalLC(constraint[1]);
const c = evalLC(constraint[2]); const c = evalLC(constraint[2]);
@@ -189,7 +194,7 @@ class CTester {
} }
function evalLC(lc) { function evalLC(lc) {
const F = self.field; const F = self.F;
let v = F.zero; let v = F.zero;
for (let w in lc) { for (let w in lc) {
v = F.add( v = F.add(

View File

@@ -728,12 +728,9 @@ module.exports = function buildRuntime(module, builder) {
c.setLocal( c.setLocal(
"pSrc", "pSrc",
c.i32_add( c.call(
c.i32_const(builder.pSignals), "getPWitness",
c.i32_mul( c.getLocal("i"),
c.getLocal("i"),
c.i32_const(builder.sizeFr)
)
) )
), ),
@@ -745,7 +742,7 @@ module.exports = function buildRuntime(module, builder) {
c.setLocal( c.setLocal(
"pDst", "pDst",
c.i32_add( c.i32_add(
c.i32_const(builder.pSignals), c.i32_const(builder.pOutput),
c.i32_mul( c.i32_mul(
c.getLocal("i"), c.getLocal("i"),
c.i32_const(builder.sizeFr-8) c.i32_const(builder.sizeFr-8)
@@ -770,7 +767,7 @@ module.exports = function buildRuntime(module, builder) {
c.br(0) c.br(0)
)), )),
c.i32_const(builder.pSignals) c.i32_const(builder.pOutput)
); );
} }
@@ -804,6 +801,7 @@ module.exports = function buildRuntime(module, builder) {
buildWasmFf(module, "Fr", builder.header.P); buildWasmFf(module, "Fr", builder.header.P);
builder.pSignals=module.alloc(builder.header.NSignals*builder.sizeFr); builder.pSignals=module.alloc(builder.header.NSignals*builder.sizeFr);
builder.pOutput=module.alloc(builder.header.NVars*(builder.sizeFr-8));
builder.pInputSignalsToTrigger=module.alloc(builder.header.NComponents*4); builder.pInputSignalsToTrigger=module.alloc(builder.header.NComponents*4);
builder.pSignalsAssigned=module.alloc(builder.header.NSignals*4); builder.pSignalsAssigned=module.alloc(builder.header.NSignals*4);

View File

@@ -1,10 +1,11 @@
const streamFromArrayTxt = require("../../src/streamfromarray_txt"); const streamFromArrayTxt = require("../../src/streamfromarray_txt");
const streamFromArrayBin = require("../../src/streamfromarray_bin"); const streamFromArrayBin = require("../../src/streamfromarray_bin");
const bigInt = require("big-integer");
const assert = require("assert"); const assert = require("assert");
const ModuleBuilder = require("wasmbuilder").ModuleBuilder; const ModuleBuilder = require("wasmbuilder").ModuleBuilder;
const ModuleBuilderWat = require("wasmbuilder").ModuleBuilderWat; const ModuleBuilderWat = require("wasmbuilder").ModuleBuilderWat;
const buildRuntime = require("./build_runtime"); const buildRuntime = require("./build_runtime");
const Scalar = require("ffjavascript").Scalar;
const F1Field = require("ffjavascript").F1Field;
const errs = require("./errs"); const errs = require("./errs");
@@ -689,7 +690,8 @@ class FunctionBuilderWasm {
} }
class BuilderWasm { class BuilderWasm {
constructor() { constructor(p) {
this.F = new F1Field(p);
this.hashMaps={}; this.hashMaps={};
this.componentEntriesTables={}; this.componentEntriesTables={};
this.sizes ={}; this.sizes ={};
@@ -701,8 +703,8 @@ class BuilderWasm {
this.TYPE_SIGNAL = 1; this.TYPE_SIGNAL = 1;
this.TYPE_COMPONENT = 2; this.TYPE_COMPONENT = 2;
this.addConstant(bigInt(0)); // constants[0] = 0; this.addConstant(Scalar.fromString("0")); // constants[0] = 0;
this.addConstant(bigInt(1)); // constants[1] = 1; this.addConstant(Scalar.fromString("1")); // constants[1] = 1;
this.offsetComponentNInputSignals = 12; this.offsetComponentNInputSignals = 12;
this.sizeofComponent = 20; this.sizeofComponent = 20;
@@ -710,7 +712,8 @@ class BuilderWasm {
setHeader(header) { setHeader(header) {
this.header=header; this.header=header;
this.n64 = Math.floor((this.header.P.bitLength() - 1) / 64)+1;
this.n64 = Math.floor((Scalar.bitLength(this.header.P) - 1) / 64)+1;
this.sizeFr = this.n64*8 + 8; this.sizeFr = this.n64*8 + 8;
} }
@@ -728,9 +731,9 @@ class BuilderWasm {
} }
addConstant(c) { addConstant(c) {
c = bigInt(c); c = this.F.e(c);
const cS = c.toString(); const cS = c.toString();
if (this.usedConstants[cS]) return this.usedConstants[cS]; if (typeof this.usedConstants[cS] != "undefined") return this.usedConstants[cS];
this.constants.push(c); this.constants.push(c);
this.usedConstants[cS] = this.constants.length - 1; this.usedConstants[cS] = this.constants.length - 1;
return this.constants.length - 1; return this.constants.length - 1;
@@ -842,7 +845,6 @@ class BuilderWasm {
_buildConstants(module) { _buildConstants(module) {
const self = this; const self = this;
const R = bigInt.one.shiftLeft(this.n64*64);
const bytes = []; const bytes = [];
for (let i=0; i<self.constants.length; i++) { for (let i=0; i<self.constants.length; i++) {
@@ -852,19 +854,27 @@ class BuilderWasm {
const fBytes = [].concat(...bytes); const fBytes = [].concat(...bytes);
this.pConstants = module.alloc(fBytes); this.pConstants = module.alloc(fBytes);
function Fr2Bytes(n) { function Fr2Bytes(n) {
if (n.lt(bigInt("80000000", 16)) ) { const minShort = self.F.neg(self.F.e("80000000"));
return shortMontgomeryPositive(n); const maxShort = self.F.e("7FFFFFFF", 16);
}
if (n.geq(self.header.P.minus(bigInt("80000000", 16))) ) { if ( (self.F.geq(n, minShort))
return shortMontgomeryNegative(n); &&(self.F.leq(n, maxShort)))
{
if (self.F.geq(n, self.F.zero)) {
return shortMontgomeryPositive(n);
} else {
return shortMontgomeryNegative(n);
}
} }
return longMontgomery(n); return longMontgomery(n);
function shortMontgomeryPositive(a) { function shortMontgomeryPositive(a) {
return [ return [
...intToBytes32(parseInt(a)), ...intToBytes32(Scalar.toNumber(a)),
...intToBytes32(0x40000000), ...intToBytes32(0x40000000),
...long(toMontgomery(a)) ...long(toMontgomery(a))
]; ];
@@ -872,9 +882,9 @@ class BuilderWasm {
function shortMontgomeryNegative(a) { function shortMontgomeryNegative(a) {
const b = a.minus(self.header.P); const b = -Scalar.toNumber(self.F.neg(a));
return [ return [
...intToBytes32(parseInt(b)), ...intToBytes32(b),
...intToBytes32(0x40000000), ...intToBytes32(0x40000000),
...long(toMontgomery(a)) ...long(toMontgomery(a))
]; ];
@@ -889,27 +899,24 @@ class BuilderWasm {
} }
function long(a) { function long(a) {
const bytes = []; const bytes = [];
let r = bigInt(a); const arr = Scalar.toArray(a, 0x100000000);
let S = ""; for (let i=0; i<self.F.n64*2; i++) {
let i = 0; const idx = arr.length-1-i;
while (!r.isZero()) {
S = ("0000000000000000" + r.and(bigInt("FFFFFFFFFFFFFFFF", 16)).toString(16)).substr(-16); if ( idx >=0) {
bytes.push(hexToBytesR(S)); bytes.push(...intToBytes32(arr[idx]));
i++; } else {
r = r.shiftRight(64); bytes.push(...intToBytes32(0));
} }
while (i<self.n64) {
bytes.push(hexToBytesR("0000000000000000"));
i++;
} }
const fBytes = [].concat(...bytes); return bytes;
return fBytes;
} }
function toMontgomery(a) { function toMontgomery(a) {
return a.times(R).mod(self.header.P); return self.F.mul(a, self.F.R);
} }
} }

View File

@@ -6,7 +6,6 @@ var tmp = require("tmp-promise");
const path = require("path"); const path = require("path");
const compiler = require("../../src/compiler"); const compiler = require("../../src/compiler");
const bigInt = require("big-integer");
const utils = require("../../src/utils"); const utils = require("../../src/utils");
const loadR1cs = require("r1csfile").load; const loadR1cs = require("r1csfile").load;
const ZqField = require("ffjavascript").ZqField; const ZqField = require("ffjavascript").ZqField;
@@ -82,7 +81,7 @@ class WasmTester {
const self = this; const self = this;
if (this.constraints) return; if (this.constraints) return;
const r1cs = await loadR1cs(path.join(this.dir.path, this.baseName + ".r1cs"),true, false); const r1cs = await loadR1cs(path.join(this.dir.path, this.baseName + ".r1cs"),true, false);
self.field = new ZqField(r1cs.prime); self.F = new ZqField(r1cs.prime);
self.nVars = r1cs.nVars; self.nVars = r1cs.nVars;
self.constraints = r1cs.constraints; self.constraints = r1cs.constraints;
} }
@@ -107,8 +106,8 @@ class WasmTester {
if (typeof self.symbols[prefix] == "undefined") { if (typeof self.symbols[prefix] == "undefined") {
assert(false, "Output variable not defined: "+ prefix); assert(false, "Output variable not defined: "+ prefix);
} }
const ba = bigInt(actualOut[self.symbols[prefix].varIdx]).toString(); const ba = actualOut[self.symbols[prefix].varIdx].toString();
const be = bigInt(eOut).toString(); const be = eOut.toString();
assert.strictEqual(ba, be, prefix); assert.strictEqual(ba, be, prefix);
} }
} }
@@ -138,16 +137,16 @@ class WasmTester {
} }
function checkConstraint(constraint) { function checkConstraint(constraint) {
const F = self.field; const F = self.F;
const a = evalLC(constraint[0]); const a = evalLC(constraint[0]);
const b = evalLC(constraint[1]); const b = evalLC(constraint[1]);
const c = evalLC(constraint[2]); const c = evalLC(constraint[2]);
assert (F.sub(F.mul(a,b), c).isZero(), "Constraint doesn't match"); assert (F.isZero(F.sub(F.mul(a,b), c)), "Constraint doesn't match");
} }
function evalLC(lc) { function evalLC(lc) {
const F = self.field; const F = self.F;
let v = F.zero; let v = F.zero;
for (let w in lc) { for (let w in lc) {
v = F.add( v = F.add(

View File

@@ -18,7 +18,6 @@
*/ */
const assert = require("assert"); const assert = require("assert");
const bigInt = require("big-integer");
const utils = require("./utils"); const utils = require("./utils");
const gen = require("./gencode").gen; const gen = require("./gencode").gen;
const createRefs = require("./gencode").createRefs; const createRefs = require("./gencode").createRefs;
@@ -35,8 +34,8 @@ function build(ctx) {
ctx.definedSizes = {}; ctx.definedSizes = {};
ctx.addSizes = addSizes; ctx.addSizes = addSizes;
ctx.addConstant = addConstant; ctx.addConstant = addConstant;
ctx.addConstant(bigInt.zero); ctx.addConstant(ctx.F.zero);
ctx.addConstant(bigInt.one); ctx.addConstant(ctx.F.one);
buildHeader(ctx); buildHeader(ctx);
buildEntryTables(ctx); buildEntryTables(ctx);
@@ -209,7 +208,7 @@ function buildHeader(ctx) {
NInputs: ctx.components[ ctx.getComponentIdx("main") ].nInSignals, NInputs: ctx.components[ ctx.getComponentIdx("main") ].nInSignals,
NOutputs: ctx.totals[ ctx.stOUTPUT ], NOutputs: ctx.totals[ ctx.stOUTPUT ],
NVars: ctx.totals[ctx.stONE] + ctx.totals[ctx.stOUTPUT] + ctx.totals[ctx.stPUBINPUT] + ctx.totals[ctx.stPRVINPUT] + ctx.totals[ctx.stINTERNAL], NVars: ctx.totals[ctx.stONE] + ctx.totals[ctx.stOUTPUT] + ctx.totals[ctx.stPUBINPUT] + ctx.totals[ctx.stPRVINPUT] + ctx.totals[ctx.stINTERNAL],
P: ctx.field.p P: ctx.F.p
}); });
} }
@@ -391,7 +390,7 @@ function hashComponentCall(ctx, cIdx) {
// TODO: At the moment generate a diferent function for each instance of the component // TODO: At the moment generate a diferent function for each instance of the component
const constParams = []; const constParams = [];
for (let p in ctx.components[cIdx].params) { for (let p in ctx.components[cIdx].params) {
constParams.push(p + "=" + value2str(ctx.components[cIdx].params[p])); constParams.push(p + "=" + value2str(ctx.F, ctx.components[cIdx].params[p]));
} }
for (let n in ctx.components[cIdx].names.o) { for (let n in ctx.components[cIdx].names.o) {
@@ -399,7 +398,7 @@ function hashComponentCall(ctx, cIdx) {
if ((entry.type == "S")&&(ctx.signals[entry.offset].o & ctx.IN)) { if ((entry.type == "S")&&(ctx.signals[entry.offset].o & ctx.IN)) {
travelSizes(n, entry.offset, entry.sizes, (prefix, offset) => { travelSizes(n, entry.offset, entry.sizes, (prefix, offset) => {
if (utils.isDefined(ctx.signals[offset].v)) { if (utils.isDefined(ctx.signals[offset].v)) {
constParams.push(prefix + "=" + bigInt(ctx.signals[offset].value)); constParams.push(prefix + "=" + ctx.F.e(ctx.signals[offset].v));
} }
}); });
} }
@@ -433,7 +432,7 @@ function hashFunctionCall(ctx, name, paramValues) {
const constParams = []; const constParams = [];
for (let i=0; i<ctx.functions[name].params.length; i++) { for (let i=0; i<ctx.functions[name].params.length; i++) {
if (!paramValues[i].used) { if (!paramValues[i].used) {
constParams.push(ctx.functions[name].params[i] + utils.accSizes2Str(paramValues[i].sizes) + "=" + value2str(paramValues[i].value)); constParams.push(ctx.functions[name].params[i] + utils.accSizes2Str(paramValues[i].sizes) + "=" + value2str(ctx.F, paramValues[i].value));
} }
} }
let instanceDef = name; let instanceDef = name;
@@ -447,16 +446,16 @@ function hashFunctionCall(ctx, name, paramValues) {
return {h, instanceDef}; return {h, instanceDef};
} }
function value2str(v) { function value2str(F, v) {
if (Array.isArray(v)) { if (Array.isArray(v)) {
let S="["; let S="[";
for (let i=0; i<v.length; i++) { for (let i=0; i<v.length; i++) {
if (i>0) S+=","; if (i>0) S+=",";
S+=value2str(v[i]); S+=value2str(F, v[i]);
} }
S+="]"; S+="]";
return S; return S;
} else { } else {
return bigInt(v).toString(); return F.toString(F.e(v));
} }
} }

View File

@@ -17,15 +17,13 @@
along with circom. If not, see <https://www.gnu.org/licenses/>. along with circom. If not, see <https://www.gnu.org/licenses/>.
*/ */
const bigInt = require("big-integer"); const Scalar = require("ffjavascript").Scalar;
const __P__ = bigInt("21888242871839275222246405745257275088548364400416034343698204186575808495617");
const sONE = 0; const sONE = 0;
const build = require("./build"); const build = require("./build");
const BuilderC = require("../ports/c/builder.js"); const BuilderC = require("../ports/c/builder.js");
const BuilderWasm = require("../ports/wasm/builder.js"); const BuilderWasm = require("../ports/wasm/builder.js");
const constructionPhase = require("./construction_phase"); const constructionPhase = require("./construction_phase");
const Ctx = require("./ctx"); const Ctx = require("./ctx");
const ZqField = require("ffjavascript").ZqField;
const utils = require("./utils"); const utils = require("./utils");
const buildR1cs = require("./r1csfile").buildR1cs; const buildR1cs = require("./r1csfile").buildR1cs;
const BigArray = require("./bigarray"); const BigArray = require("./bigarray");
@@ -34,15 +32,14 @@ const buildSyms = require("./buildsyms");
module.exports = compile; module.exports = compile;
async function compile(srcFile, options) { async function compile(srcFile, options) {
options.p = options.p || __P__; options.prime = options.prime || Scalar.fromString("21888242871839275222246405745257275088548364400416034343698204186575808495617");
if (!options) { if (!options) {
options = {}; options = {};
} }
if (typeof options.reduceConstraints === "undefined") { if (typeof options.reduceConstraints === "undefined") {
options.reduceConstraints = true; options.reduceConstraints = true;
} }
const ctx = new Ctx(); const ctx = new Ctx(options.prime);
ctx.field = new ZqField(options.p);
ctx.verbose= options.verbose || false; ctx.verbose= options.verbose || false;
ctx.mainComponent = options.mainComponent || "main"; ctx.mainComponent = options.mainComponent || "main";
ctx.newThreadTemplates = options.newThreadTemplates; ctx.newThreadTemplates = options.newThreadTemplates;
@@ -85,7 +82,8 @@ async function compile(srcFile, options) {
} }
if (options.cSourceWriteStream) { if (options.cSourceWriteStream) {
ctx.builder = new BuilderC(); if (ctx.verbose) console.log("Generating c...");
ctx.builder = new BuilderC(options.prime);
build(ctx); build(ctx);
const rdStream = ctx.builder.build(); const rdStream = ctx.builder.build();
rdStream.pipe(options.cSourceWriteStream); rdStream.pipe(options.cSourceWriteStream);
@@ -94,7 +92,8 @@ async function compile(srcFile, options) {
} }
if ((options.wasmWriteStream)||(options.watWriteStream)) { if ((options.wasmWriteStream)||(options.watWriteStream)) {
ctx.builder = new BuilderWasm(); if (ctx.verbose) console.log("Generating wasm...");
ctx.builder = new BuilderWasm(options.prime);
build(ctx); build(ctx);
if (options.wasmWriteStream) { if (options.wasmWriteStream) {
const rdStream = ctx.builder.build("wasm"); const rdStream = ctx.builder.build("wasm");
@@ -299,11 +298,11 @@ function reduceConstrains(ctx) {
t: "LC", t: "LC",
coefs: {} coefs: {}
}; };
const invCoef = c.c.coefs[isolatedSignal].modInv(__P__); const invCoef = ctx.F.inv(c.c.coefs[isolatedSignal]);
for (const s in c.c.coefs) { for (const s in c.c.coefs) {
if (s != isolatedSignal) { if (s != isolatedSignal) {
const v = __P__.minus(c.c.coefs[s]).times(invCoef).mod(__P__); const v = ctx.F.mul( ctx.F.neg(c.c.coefs[s]), invCoef);
if (!v.isZero()) { if (!ctx.F.isZero(v)) {
isolatedSignalEquivalence.coefs[s] = v; isolatedSignalEquivalence.coefs[s] = v;
} }
} }
@@ -395,9 +394,9 @@ function reduceConstrains(ctx) {
function isConstant(l) { function isConstant(l) {
for (let k in l.coefs) { for (let k in l.coefs) {
if ((k != sONE) && (!l.coefs[k].isZero())) return false; if ((k != sONE) && (!ctx.F.isZero(l.coefs[k]))) return false;
} }
if (!l.coefs[sONE] || l.coefs[sONE].isZero()) return false; if (!l.coefs[sONE] || ctx.F.isZero(l.coefs[sONE])) return false;
return true; return true;
} }

View File

@@ -49,10 +49,11 @@ const assert = require("assert");
const iterateAST = require("./iterateast"); const iterateAST = require("./iterateast");
const utils = require("./utils"); const utils = require("./utils");
const bigInt = require("big-integer");
const LCAlgebra = require("./lcalgebra"); const LCAlgebra = require("./lcalgebra");
const parser = require("../parser/jaz.js").parser; const parser = require("../parser/jaz.js").parser;
const Scalar = require("ffjavascript").Scalar;
const {stringifyBigInts} = require("ffjavascript").utils;
/* TODO: Add lines information /* TODO: Add lines information
@@ -79,7 +80,7 @@ function constructionPhase(ctx, srcFile) {
assert(ctx.ast.type == "BLOCK"); assert(ctx.ast.type == "BLOCK");
ctx.lc = new LCAlgebra(ctx.field); ctx.lc = new LCAlgebra(ctx.F);
ctx.filePath= fullFilePath; ctx.filePath= fullFilePath;
ctx.fileName= fullFileName; ctx.fileName= fullFileName;
ctx.includedFiles = {}; ctx.includedFiles = {};
@@ -218,7 +219,7 @@ function execNumber(ctx, ast) {
s:[1,0], s:[1,0],
v: [{ v: [{
t: "N", t: "N",
v: bigInt(ast.value) v: ctx.F.e(ast.value)
}] }]
}; };
} }
@@ -253,7 +254,7 @@ function execDeclareComponent(ctx, ast) {
const size = val(ctx, sizeRef); const size = val(ctx, sizeRef);
if (size.t != "N") return ctx.throwError( ast.name.selectors[i], "expected a number"); if (size.t != "N") return ctx.throwError( ast.name.selectors[i], "expected a number");
sizes.push( size.v.toJSNumber() ); sizes.push( Scalar.toNumber(size.v) );
} }
let cIdx = ctx.addComponent(ast.name.name, sizes); let cIdx = ctx.addComponent(ast.name.name, sizes);
@@ -277,7 +278,7 @@ function execDeclareSignal(ctx, ast) {
if (ctx.error) return; if (ctx.error) return;
if (size.s[0] != 1) return ctx.throwError(ast, "Size cannot be an array"); if (size.s[0] != 1) return ctx.throwError(ast, "Size cannot be an array");
if (size.v[0].t != "N") return ctx.throwError(ast, "Size must be declared in construction time"); if (size.v[0].t != "N") return ctx.throwError(ast, "Size must be declared in construction time");
sizes.push( size.v[0].v.toJSNumber() ); sizes.push( Scalar.toNumber(size.v[0].v) );
} }
let sIdx = ctx.addSignal(ast.name.name, sizes); let sIdx = ctx.addSignal(ast.name.name, sizes);
@@ -322,7 +323,7 @@ function execDeclareVariable(ctx, ast) {
if (ctx.error) return; if (ctx.error) return;
if (size.s[0] != 1) return ctx.throwError(ast, "Size cannot be an array"); if (size.s[0] != 1) return ctx.throwError(ast, "Size cannot be an array");
if (size.v[0].t != "N") return ctx.throwError(ast, "Size must be declared in construction time"); if (size.v[0].t != "N") return ctx.throwError(ast, "Size must be declared in construction time");
sizes.push( size.v[0].v.toJSNumber() ); sizes.push( Scalar.toNumber(size.v[0].v) );
} }
const v = ctx.refs[ast.refId]; const v = ctx.refs[ast.refId];
@@ -353,7 +354,7 @@ function execAssignement(ctx, ast) {
if (sel.s[0] != 1) return ctx.throwError(ast, "Selector cannot be an array"); if (sel.s[0] != 1) return ctx.throwError(ast, "Selector cannot be an array");
if (sel.v[0].t != "N") return {t: "NQ"}; if (sel.v[0].t != "N") return {t: "NQ"};
leftSels.push( sel.v[0].v.toJSNumber() ); leftSels.push( Scalar.toNumber(sel.v[0].v) );
} }
} }
@@ -380,7 +381,7 @@ function execAssignement(ctx, ast) {
} else if (right.t == "S") { } else if (right.t == "S") {
for (let i=0; i<right.s[0]; i++) { for (let i=0; i<right.s[0]; i++) {
left.v[o+i]={t: "LC", coefs: {}}; left.v[o+i]={t: "LC", coefs: {}};
left.v[o+i].coefs[right.sIdx+i] = ctx.field.one; left.v[o+i].coefs[right.sIdx+i] = ctx.F.one;
} }
} }
} else if ( left.t == "S") { } else if ( left.t == "S") {
@@ -561,14 +562,14 @@ function execFunctionCall(ctx, ast) {
if (ev.v) { if (ev.v) {
console.log(ev.v.toString()); console.log(ev.v.toString());
} else { } else {
console.log(JSON.stringify(ev)); console.log(JSON.stringify(stringifyBigInts(ev)));
} }
return; return;
} }
if (ast.name == "assert") { if (ast.name == "assert") {
const v = exec(ctx, ast.params[0]); const v = exec(ctx, ast.params[0]);
const ev = val(ctx, v, ast); const ev = val(ctx, v, ast);
if (ev.isZero()) return ctx.throwError(ast, "Assertion failed"); if (ctx.F.isZero(ev)) return ctx.throwError(ast, "Assertion failed");
} }
const fnc = ctx.functions[ast.name]; const fnc = ctx.functions[ast.name];
@@ -634,7 +635,7 @@ function execVariable(ctx, ast) {
if (ctx.error) return; if (ctx.error) return;
if (sel.s[0] != 1) return ctx.throwError(ast, "Variable selector cannot be an array"); if (sel.s[0] != 1) return ctx.throwError(ast, "Variable selector cannot be an array");
if (sel.v[0].t != "N") return NQVAL; if (sel.v[0].t != "N") return NQVAL;
sels.push(sel.v[0].v.toJSNumber()); sels.push(Scalar.toNumber(sel.v[0].v));
} }
let o = 0; let o = 0;
@@ -682,7 +683,7 @@ function execPin(ctx, ast) {
if (sel.s[0] != 1) return ctx.throwError(ast, "Component selector cannot be an array"); if (sel.s[0] != 1) return ctx.throwError(ast, "Component selector cannot be an array");
if (sel.v[0].t != "N") return NQVAL; if (sel.v[0].t != "N") return NQVAL;
selsC.push(sel.v[0].v.toJSNumber()); selsC.push(Scalar.toNumber(sel.v[0].v));
} }
const cIdx = ctx.getComponentIdx(ast.component.name, selsC); const cIdx = ctx.getComponentIdx(ast.component.name, selsC);
@@ -694,7 +695,7 @@ function execPin(ctx, ast) {
if (ctx.error) return; if (ctx.error) return;
if (sel.s[0] != 1) return ctx.throwError(ast, "Signal selector cannot be an array"); if (sel.s[0] != 1) return ctx.throwError(ast, "Signal selector cannot be an array");
if (sel.v[0].t != "N") return NQVAL; if (sel.v[0].t != "N") return NQVAL;
selsP.push(sel.v[0].v.toJSNumber()); selsP.push(Scalar.toNumber(sel.v[0].v));
} }
const sIdx = ctx.components[cIdx].names.getSignalIdx(ast.pin.name, selsP); const sIdx = ctx.components[cIdx].names.getSignalIdx(ast.pin.name, selsP);
@@ -741,7 +742,7 @@ function execLoop(ctx, ast) {
return; return;
} }
while ((!v.v[0].v.isZero())&&(!ctx.returnValue)) { while ((! ctx.F.isZero(v.v[0].v))&&(!ctx.returnValue)) {
exec(ctx, ast.body); exec(ctx, ast.body);
if (ctx.error) return; if (ctx.error) return;
@@ -784,7 +785,7 @@ function execIf(ctx, ast) {
return; return;
} }
if (!v.v[0].v.isZero()) { if (!ctx.F.isZero(v.v[0].v)) {
exec(ctx, ast.then); exec(ctx, ast.then);
} else { } else {
if (ast.else) { if (ast.else) {
@@ -811,7 +812,7 @@ function execTerCon(ctx, ast) {
return NQVAL; return NQVAL;
} }
if (!v.v[0].v.isZero()) { if (!ctx.F.isZero(v.v[0].v)) {
return exec(ctx, ast.values[1]); return exec(ctx, ast.values[1]);
} else { } else {
return exec(ctx, ast.values[2]); return exec(ctx, ast.values[2]);
@@ -850,7 +851,7 @@ function execOpOp(ctx, ast, op, lr) {
if (sel.s[0] != 1) return ctx.throwError(ast, "Selector cannot be an array"); if (sel.s[0] != 1) return ctx.throwError(ast, "Selector cannot be an array");
if (sel.v[0].t != "N") return {t: "NQ"}; if (sel.v[0].t != "N") return {t: "NQ"};
leftSels.push( sel.v[0].v.toJSNumber() ); leftSels.push( Scalar.toNumber(sel.v[0].v) );
} }
} }
if (!left.s) return ctx.throwError(ast, "variable. not defined yet"); if (!left.s) return ctx.throwError(ast, "variable. not defined yet");
@@ -870,7 +871,7 @@ function execOpOp(ctx, ast, op, lr) {
if (ctx.error) return; if (ctx.error) return;
right = val(ctx, rightRef); right = val(ctx, rightRef);
} else { } else {
right = {t:"N", v: ctx.field.one}; right = {t:"N", v: ctx.F.one};
} }
if (!right) return ctx.throwError(ast, "adding a no number"); if (!right) return ctx.throwError(ast, "adding a no number");
@@ -907,7 +908,7 @@ function val(ctx, a, ast) {
}; };
let sIdx = a.sIdx; let sIdx = a.sIdx;
while (ctx.signals[sIdx].e >= 0) sIdx = ctx.signals[sIdx].e; while (ctx.signals[sIdx].e >= 0) sIdx = ctx.signals[sIdx].e;
res.coefs[sIdx] = ctx.field.one; res.coefs[sIdx] = ctx.F.one;
return res; return res;
} else { } else {
ctx.throwError(ast, "Invalid type: " + a.t); ctx.throwError(ast, "Invalid type: " + a.t);
@@ -979,7 +980,7 @@ function execArray(ctx, ast) {
} else if (e.t == "S") { } else if (e.t == "S") {
for (let j=0; j<e.v.length;j++) { for (let j=0; j<e.v.length;j++) {
const sv = {t: "LC", coefs: {}}; const sv = {t: "LC", coefs: {}};
sv.coefs[e.sIdx+j] = ctx.field.one; sv.coefs[e.sIdx+j] = ctx.F.one;
res.v.push(sv); res.v.push(sv);
} }
} else { } else {

View File

@@ -1,6 +1,5 @@
const bigInt = require("big-integer");
const BigArray = require("./bigarray.js"); const BigArray = require("./bigarray.js");
const F1Field = require("ffjavascript").F1Field;
class TableName { class TableName {
constructor (ctx) { constructor (ctx) {
@@ -86,7 +85,9 @@ class TableName {
module.exports = class Ctx { module.exports = class Ctx {
constructor() { constructor(p) {
this.F = new F1Field(p);
this.stONE = 1; this.stONE = 1;
this.stOUTPUT = 2; this.stOUTPUT = 2;
@@ -121,7 +122,7 @@ module.exports = class Ctx {
const oneIdx = this.addSignal("one"); const oneIdx = this.addSignal("one");
this.signals[oneIdx] = { this.signals[oneIdx] = {
v: bigInt(1), v: this.F.one,
o: this.ONE, o: this.ONE,
e: -1, e: -1,
}; };

View File

@@ -1,7 +1,7 @@
const bigInt = require("big-integer");
const utils = require("./utils"); const utils = require("./utils");
const assert = require("assert"); const assert = require("assert");
const iterateAST = require("./iterateast"); const iterateAST = require("./iterateast");
const Scalar = require("ffjavascript").Scalar;
module.exports.gen = gen; module.exports.gen = gen;
module.exports.newRef = newRef; module.exports.newRef = newRef;
@@ -300,7 +300,7 @@ function genDeclareVariable(ctx, ast) {
const size = ctx.refs[sizeRef]; const size = ctx.refs[sizeRef];
if (size.sizes[0] != 1) return ctx.throwError(ast, "A selector cannot be an array"); if (size.sizes[0] != 1) return ctx.throwError(ast, "A selector cannot be an array");
if (size.used) return ctx.throwError(ast, "Variable size variables not allowed"); if (size.used) return ctx.throwError(ast, "Variable size variables not allowed");
sizes.push(size.value[0]); sizes.push(Scalar.toNumber(size.value[0]));
} }
sizes = utils.accSizes(sizes); sizes = utils.accSizes(sizes);
} else { } else {
@@ -320,7 +320,7 @@ function genDeclareVariable(ctx, ast) {
} }
function genNumber(ctx, ast) { function genNumber(ctx, ast) {
return newRef(ctx, "BIGINT", "_num", bigInt(ast.value)); return newRef(ctx, "BIGINT", "_num", ctx.F.e(ast.value));
} }
@@ -950,7 +950,7 @@ function genLoop(ctx, ast) {
ctx.codeBuilder.assign(loopCond.label, ["R", cond.label], ["V", 0]); ctx.codeBuilder.assign(loopCond.label, ["R", cond.label], ["V", 0]);
} else { } else {
if (!utils.isDefined(cond.value)) return ctx.throwError(ast, "condition value not assigned"); if (!utils.isDefined(cond.value)) return ctx.throwError(ast, "condition value not assigned");
if (cond.value[0].isZero()) end=true; if (ctx.F.isZero(cond.value[0])) end=true;
} }
@@ -993,7 +993,7 @@ function genLoop(ctx, ast) {
} else { } else {
oldCodeBuilder.concat(ctx.codeBuilder); oldCodeBuilder.concat(ctx.codeBuilder);
ctx.codeBuilder = oldCodeBuilder; ctx.codeBuilder = oldCodeBuilder;
if (cond2.value[0].isZero()) end=true; if (ctx.F.isZero(cond2.value[0])) end=true;
} }
} else { } else {
ctx.codeBuilder.assign(loopCond.label, ["R", cond2.label], ["V", 0]); ctx.codeBuilder.assign(loopCond.label, ["R", cond2.label], ["V", 0]);
@@ -1042,7 +1042,7 @@ function genIf(ctx, ast) {
} else { } else {
if (!utils.isDefined(cond.value)) return ctx.throwError(ast, "condition value not assigned"); if (!utils.isDefined(cond.value)) return ctx.throwError(ast, "condition value not assigned");
if (!cond.value[0].isZero()) { if (!ctx.F.isZero(cond.value[0])) {
gen(ctx, ast.then); gen(ctx, ast.then);
} else { } else {
if (ast.else) { if (ast.else) {
@@ -1109,9 +1109,9 @@ function genOpOp(ctx, ast, op, lr) {
const res = ctx.refs[resRef]; const res = ctx.refs[resRef];
if (veval.used) { if (veval.used) {
instantiateRef(ctx, resRef); instantiateRef(ctx, resRef);
ctx.codeBuilder.fieldOp(res.label, op, [["R", veval.label], ["C", ctx.addConstant(bigInt.one)]]); ctx.codeBuilder.fieldOp(res.label, op, [["R", veval.label], ["C", ctx.addConstant(ctx.F.one)]]);
} else { } else {
res.value = [ctx.field[op](veval.value[0], bigInt(1))]; res.value = [ctx.F[op](veval.value[0], ctx.F.one)];
} }
genVarAssignment(ctx, ast, vRef, ast.values[0].selectors, resRef); genVarAssignment(ctx, ast, vRef, ast.values[0].selectors, resRef);
if (lr == "RIGHT") { if (lr == "RIGHT") {
@@ -1157,10 +1157,10 @@ function genOp(ctx, ast, op, nOps, adjustBool) {
} else { } else {
const params = []; const params = [];
for (let i=0; i<nOps; i++) { for (let i=0; i<nOps; i++) {
params.push(vals[i].value[0]); params.push(ctx.F.e(vals[i].value[0]));
} }
rRef = newRef(ctx, "BIGINT", "_tmp", adjustBool ? (ctx.field[op](...params)?bigInt.one:bigInt.zero) : ctx.field[op](...params)); rRef = newRef(ctx, "BIGINT", "_tmp", adjustBool ? (ctx.F[op](...params)?ctx.F.one:ctx.F.zero) : ctx.F[op](...params));
} }
return rRef; return rRef;
} }
@@ -1242,7 +1242,7 @@ function genTerCon(ctx, ast) {
} else { } else {
if (!utils.isDefined(cond.value)) return ctx.throwError(ast, "condition value not assigned"); if (!utils.isDefined(cond.value)) return ctx.throwError(ast, "condition value not assigned");
if (!cond.value[0].isZero()) { if (!ctx.F.isZero(cond.value[0])) {
return gen(ctx, ast.values[1]); return gen(ctx, ast.values[1]);
} else { } else {
return gen(ctx, ast.values[2]); return gen(ctx, ast.values[2]);

View File

@@ -76,14 +76,13 @@ QEX QEX NQ NQ NQ
NQ NQ NQ NQ NQ NQ NQ NQ NQ NQ
*/ */
const bigInt = require("big-integer");
const utils = require("./utils"); const utils = require("./utils");
const sONE = 0; const sONE = 0;
class LCAlgebra { class LCAlgebra {
constructor (aField) { constructor (aField) {
const self = this; const self = this;
this.field= aField; this.F= aField;
[ [
["idiv",2], ["idiv",2],
["mod",2], ["mod",2],
@@ -118,7 +117,7 @@ class LCAlgebra {
} }
return { return {
t: "N", t: "N",
v: adjustBool ? ( self.field[op](...operands) ? bigInt.one: bigInt.zero) : self.field[op](...operands) v: adjustBool ? ( self.F[op](...operands) ? self.F.one: self.F.zero) : self.F[op](...operands)
}; };
}; };
} }
@@ -129,7 +128,7 @@ class LCAlgebra {
t: "LC", t: "LC",
coefs: {} coefs: {}
}; };
lc.coefs[a.sIdx] = bigInt(1); lc.coefs[a.sIdx] = self.F.one;
return lc; return lc;
} else { } else {
return a; return a;
@@ -200,17 +199,17 @@ class LCAlgebra {
function add_N_N(a,b) { function add_N_N(a,b) {
return { return {
t: "N", t: "N",
v: self.field.add(a.v, b.v) v: self.F.add(a.v, b.v)
}; };
} }
function add_LC_N(a,b) { function add_LC_N(a,b) {
let res = self._clone(a); let res = self._clone(a);
if (b.v.isZero()) return res; if (self.F.isZero(b.v)) return res;
if (!utils.isDefined(res.coefs[sONE])) { if (!utils.isDefined(res.coefs[sONE])) {
res.coefs[sONE]= b.v; res.coefs[sONE]= b.v;
} else { } else {
res.coefs[sONE]= self.field.add(res.coefs[sONE], b.v); res.coefs[sONE]= self.F.add(res.coefs[sONE], b.v);
} }
return res; return res;
} }
@@ -221,7 +220,7 @@ class LCAlgebra {
if (!utils.isDefined(res.coefs[k])) { if (!utils.isDefined(res.coefs[k])) {
res.coefs[k]=b.coefs[k]; res.coefs[k]=b.coefs[k];
} else { } else {
res.coefs[k]= self.field.add(res.coefs[k], b.coefs[k]); res.coefs[k]= self.F.add(res.coefs[k], b.coefs[k]);
} }
} }
return res; return res;
@@ -283,14 +282,14 @@ class LCAlgebra {
function mul_N_N(a,b) { function mul_N_N(a,b) {
return { return {
t: "N", t: "N",
v: self.field.mul(a.v, b.v) v: self.F.mul(a.v, b.v)
}; };
} }
function mul_LC_N(a,b) { function mul_LC_N(a,b) {
let res = self._clone(a); let res = self._clone(a);
for (let k in res.coefs) { for (let k in res.coefs) {
res.coefs[k] = self.field.mul(res.coefs[k], b.v); res.coefs[k] = self.F.mul(res.coefs[k], b.v);
} }
return res; return res;
} }
@@ -318,10 +317,10 @@ class LCAlgebra {
const a = this._signal2lc(_a); const a = this._signal2lc(_a);
let res = this._clone(a); let res = this._clone(a);
if (res.t == "N") { if (res.t == "N") {
res.v = this.field.neg(a.v); res.v = this.F.neg(a.v);
} else if (res.t == "LC") { } else if (res.t == "LC") {
for (let k in res.coefs) { for (let k in res.coefs) {
res.coefs[k] = this.field.neg(res.coefs[k]); res.coefs[k] = this.F.neg(res.coefs[k]);
} }
} else if (res.t == "QEX") { } else if (res.t == "QEX") {
res.a = this.neg(res.a); res.a = this.neg(res.a);
@@ -338,10 +337,10 @@ class LCAlgebra {
div(a, b) { div(a, b) {
if (b.t == "N") { if (b.t == "N") {
if (b.v.isZero()) throw new Error("Division by zero"); if (this.F.isZero(b.v)) throw new Error("Division by zero");
const inv = { const inv = {
t: "N", t: "N",
v: this.field.inv(b.v) v: this.F.inv(b.v)
}; };
return this.mul(a, inv); return this.mul(a, inv);
} else { } else {
@@ -351,23 +350,23 @@ class LCAlgebra {
pow(a, b) { pow(a, b) {
if (b.t == "N") { if (b.t == "N") {
if (b.v.isZero()) { if (this.F.isZero(b.v)) {
if (this.isZero(a)) { if (this.isZero(a)) {
throw new Error("Zero to the Zero"); throw new Error("Zero to the Zero");
} }
return { return {
t: "N", t: "N",
v: this.field.one v: this.F.one
}; };
} else if (b.v.eq(this.field.one)) { } else if (this.F.eq(b.v, this.F.one)) {
return a; return a;
} else if (b.v.eq(bigInt(2))) { } else if (this.F.eq(b.v, this.F.two)) {
return this.mul(a,a); return this.mul(a,a);
} else { } else {
if (a.t=="N") { if (a.t=="N") {
return { return {
t: "N", t: "N",
v: this.field.pow(a.v, b.v) v: this.F.pow(a.v, b.v)
}; };
} else { } else {
return {t: "NQ"}; return {t: "NQ"};
@@ -381,18 +380,18 @@ class LCAlgebra {
substitute(where, signal, equivalence) { substitute(where, signal, equivalence) {
if (equivalence.t != "LC") throw new Error("Equivalence must be a Linear Combination"); if (equivalence.t != "LC") throw new Error("Equivalence must be a Linear Combination");
if (where.t == "LC") { if (where.t == "LC") {
if (!utils.isDefined(where.coefs[signal]) || where.coefs[signal].isZero()) return where; if (!utils.isDefined(where.coefs[signal]) || this.F.isZero(where.coefs[signal])) return where;
const res=this._clone(where); const res=this._clone(where);
const coef = res.coefs[signal]; const coef = res.coefs[signal];
for (let k in equivalence.coefs) { for (let k in equivalence.coefs) {
if (k != signal) { if (k != signal) {
const v = this.field.mul( coef, equivalence.coefs[k] ); const v = this.F.mul( coef, equivalence.coefs[k] );
if (!utils.isDefined(res.coefs[k])) { if (!utils.isDefined(res.coefs[k])) {
res.coefs[k]=v; res.coefs[k]=v;
} else { } else {
res.coefs[k]= this.field.add(res.coefs[k],v); res.coefs[k]= this.F.add(res.coefs[k],v);
} }
if (res.coefs[k].isZero()) delete res.coefs[k]; if (this.F.isZero(res.coefs[k])) delete res.coefs[k];
} }
} }
delete res.coefs[signal]; delete res.coefs[signal];
@@ -436,10 +435,10 @@ class LCAlgebra {
isZero(a) { isZero(a) {
if (a.t == "N") { if (a.t == "N") {
return a.v.isZero(); return this.F.isZero(a.v);
} else if (a.t == "LC") { } else if (a.t == "LC") {
for (let k in a.coefs) { for (let k in a.coefs) {
if (!a.coefs[k].isZero()) return false; if (!this.F.isZero(a.coefs[k])) return false;
} }
return true; return true;
} else if (a.t == "QEX") { } else if (a.t == "QEX") {
@@ -455,16 +454,16 @@ class LCAlgebra {
} else if (a.t == "LC") { } else if (a.t == "LC") {
let S=""; let S="";
for (let k in a.coefs) { for (let k in a.coefs) {
if (!a.coefs[k].isZero()) { if (!this.F.isZero(a.coefs[k])) {
let c; let c;
if (a.coefs[k].greater(this.field.p.divide(2))) { if (a.coefs[k].greater(this.F.p.divide(2))) {
S = S + "-"; S = S + "-";
c = this.field.p.minus(a.coefs[k]); c = this.F.p.minus(a.coefs[k]);
} else { } else {
if (S!="") S=S+" + "; if (S!="") S=S+" + ";
c = a.coefs[k]; c = a.coefs[k];
} }
if (!c.equals(bigInt.one)) { if (!c.equals(this.F.one)) {
S = S + c.toString() + "*"; S = S + c.toString() + "*";
} }
let sIdx = k; let sIdx = k;
@@ -491,11 +490,11 @@ class LCAlgebra {
} else if (n.t == "SIGNAL") { } else if (n.t == "SIGNAL") {
return getSignalValue(ctx, n.sIdx); return getSignalValue(ctx, n.sIdx);
} else if (n.t == "LC") { } else if (n.t == "LC") {
let v= this.field.zero; let v= this.F.zero;
for (let k in n.coefs) { for (let k in n.coefs) {
const s = getSignalValue(ctx, k); const s = getSignalValue(ctx, k);
if (s === null) return null; if (s === null) return null;
v = this.field.add(v, this.field.mul( n.coefs[k], s)); v = this.F.add(v, this.F.mul( n.coefs[k], s));
} }
return v; return v;
} else if (n.type == "QEX") { } else if (n.type == "QEX") {
@@ -506,7 +505,7 @@ class LCAlgebra {
const c = this.evaluate(ctx, n.c); const c = this.evaluate(ctx, n.c);
if (c === null) return null; if (c === null) return null;
return this.field.add(this.field.mul(a,b), c); return this.F.add(this.F.mul(a,b), c);
} else { } else {
return null; return null;
} }
@@ -529,24 +528,24 @@ class LCAlgebra {
let s = k; let s = k;
while (ctx.signals[s].e>=0) s= ctx.signals[s].e; while (ctx.signals[s].e>=0) s= ctx.signals[s].e;
if (utils.isDefined(ctx.signals[s].v)&&(k != sONE)) { if (utils.isDefined(ctx.signals[s].v)&&(k != sONE)) {
const v = this.field.mul(res.coefs[k], ctx.signals[s].v); const v = this.F.mul(res.coefs[k], ctx.signals[s].v);
if (!utils.isDefined(res.coefs[sONE])) { if (!utils.isDefined(res.coefs[sONE])) {
res.coefs[sONE]=v; res.coefs[sONE]=v;
} else { } else {
res.coefs[sONE]= this.field.add(res.coefs[sONE], v); res.coefs[sONE]= this.F.add(res.coefs[sONE], v);
} }
delete res.coefs[k]; delete res.coefs[k];
} else if (s != k) { } else if (s != k) {
if (!utils.isDefined(res.coefs[s])) { if (!utils.isDefined(res.coefs[s])) {
res.coefs[s]=res.coefs[k]; res.coefs[s]=res.coefs[k];
} else { } else {
res.coefs[s]= this.field.add(res.coefs[s], res.coefs[k]); res.coefs[s]= this.F.add(res.coefs[s], res.coefs[k]);
} }
delete res.coefs[k]; delete res.coefs[k];
} }
} }
for (let k in res.coefs) { for (let k in res.coefs) {
if (res.coefs[k].isZero()) delete res.coefs[k]; if (this.F.isZero(res.coefs[k])) delete res.coefs[k];
} }
return res; return res;
} else if (a.t == "QEX") { } else if (a.t == "QEX") {

View File

@@ -1,16 +1,15 @@
const fs = require("fs"); const fastFile = require("fastfile");
const assert = require("assert"); const assert = require("assert");
const bigInt = require("big-integer");
module.exports.buildR1cs = buildR1cs; module.exports.buildR1cs = buildR1cs;
async function buildR1cs(ctx, fileName) { async function buildR1cs(ctx, fileName) {
const fd = await fs.promises.open(fileName, "w"); const fd = await fastFile.createOverride(fileName);
await fd.write("r1cs"); // Magic "r1cs" await fd.write(Buffer.from("r1cs"), 0); // Magic "r1cs"
let p = 4; let p = 4;
await writeU32(1); // Version await writeU32(1); // Version
@@ -23,10 +22,10 @@ async function buildR1cs(ctx, fileName) {
await writeU64(0); // Temporally set to 0 length await writeU64(0); // Temporally set to 0 length
const n8 = (Math.floor( (ctx.field.p.bitLength() - 1) / 64) +1)*8; const n8 = (Math.floor( (ctx.F.bitLength - 1) / 64) +1)*8;
// Field Def // Field Def
await writeU32(n8); // Temporally set to 0 length await writeU32(n8); // Temporally set to 0 length
await writeBigInt(ctx.field.p); await writeBigInt(ctx.F.p);
const NWires = const NWires =
ctx.totals[ctx.stONE] + ctx.totals[ctx.stONE] +
@@ -53,7 +52,6 @@ async function buildR1cs(ctx, fileName) {
for (let i=0; i<ctx.constraints.length; i++) { for (let i=0; i<ctx.constraints.length; i++) {
if ((ctx.verbose)&&(i%10000 == 0)) { if ((ctx.verbose)&&(i%10000 == 0)) {
if (ctx.verbose) console.log("writing constraint: ", i); if (ctx.verbose) console.log("writing constraint: ", i);
await fd.datasync();
} }
await writeConstraint(ctx.constraints[i]); await writeConstraint(ctx.constraints[i]);
} }
@@ -89,19 +87,22 @@ async function buildR1cs(ctx, fileName) {
await writeU32(constraintsSize, pConstraintsSize); await writeU32(constraintsSize, pConstraintsSize);
await writeU32(mapSize, pMapSize); await writeU32(mapSize, pMapSize);
await fd.sync();
await fd.close(); await fd.close();
async function writeU32(v, pos) { async function writeU32(v, pos) {
let o = (typeof pos == "undefined") ? p : pos;
const b = Buffer.allocUnsafe(4); const b = Buffer.allocUnsafe(4);
b.writeInt32LE(v); b.writeInt32LE(v);
await fd.write(b, 0, 4, pos); await fd.write(b, o);
if (typeof(pos) == "undefined") p += 4; if (typeof(pos) == "undefined") p += 4;
} }
async function writeU64(v, pos) { async function writeU64(v, pos) {
let o = (typeof pos == "undefined") ? p : pos;
const b = Buffer.allocUnsafe(8); const b = Buffer.allocUnsafe(8);
const LSB = v & 0xFFFFFFFF; const LSB = v & 0xFFFFFFFF;
@@ -109,7 +110,7 @@ async function buildR1cs(ctx, fileName) {
b.writeInt32LE(LSB, 0); b.writeInt32LE(LSB, 0);
b.writeInt32LE(MSB, 4); b.writeInt32LE(MSB, 4);
await fd.write(b, 0, 8, pos); await fd.write(b, o);
if (typeof(pos) == "undefined") p += 8; if (typeof(pos) == "undefined") p += 8;
} }
@@ -134,16 +135,15 @@ async function buildR1cs(ctx, fileName) {
} }
async function writeBigInt(n, pos) { async function writeBigInt(n, pos) {
const b = Buffer.allocUnsafe(n8);
const dwords = bigInt(n).toArray(0x100000000).value; let o = (typeof pos == "undefined") ? p : pos;
for (let i=0; i<dwords.length; i++) { const s = n.toString(16);
b.writeUInt32LE(dwords[dwords.length-1-i], i*4, 4 ); const b = Buffer.from(s.padStart(n8*2, "0"), "hex");
} const buff = Buffer.allocUnsafe(b.length);
b.fill(0, dwords.length*4); for (let i=0; i<b.length; i++) buff[i] = b[b.length-1-i];
await fd.write(b, 0, fs, pos); await fd.write(buff, o);
if (typeof(pos) == "undefined") p += n8; if (typeof(pos) == "undefined") p += n8;
} }

View File

@@ -1,5 +1,4 @@
const fnv = require("fnv-plus"); const fnv = require("fnv-plus");
const bigInt = require("big-integer");
module.exports.ident =ident; module.exports.ident =ident;
@@ -8,8 +7,6 @@ module.exports.flatArray = flatArray;
module.exports.csArr = csArr; module.exports.csArr = csArr;
module.exports.accSizes = accSizes; module.exports.accSizes = accSizes;
module.exports.fnvHash = fnvHash; module.exports.fnvHash = fnvHash;
module.exports.stringifyBigInts = stringifyBigInts;
module.exports.unstringifyBigInts = unstringifyBigInts;
module.exports.sameSizes = sameSizes; module.exports.sameSizes = sameSizes;
module.exports.isDefined = isDefined; module.exports.isDefined = isDefined;
module.exports.accSizes2Str = accSizes2Str; module.exports.accSizes2Str = accSizes2Str;
@@ -45,7 +42,7 @@ function flatArray(a) {
fillArray(res, a[i]); fillArray(res, a[i]);
} }
} else { } else {
res.push(bigInt(a)); res.push(a);
} }
} }
} }
@@ -74,42 +71,6 @@ function fnvHash(str) {
return fnv.hash(str, 64).hex(); return fnv.hash(str, 64).hex();
} }
function stringifyBigInts(o) {
if ((typeof(o) == "bigint") || o.eq !== undefined) {
return o.toString(10);
} else if (Array.isArray(o)) {
return o.map(stringifyBigInts);
} else if (typeof o == "object") {
const res = {};
for (let k in o) {
res[k] = stringifyBigInts(o[k]);
}
return res;
} else {
return o;
}
}
function unstringifyBigInts(o) {
if ((typeof(o) == "string") && (/^[0-9]+$/.test(o) )) {
return bigInt(o);
} else if (Array.isArray(o)) {
return o.map(unstringifyBigInts);
} else if (typeof o == "object") {
const res = {};
for (let k in o) {
res[k] = unstringifyBigInts(o[k]);
}
return res;
} else {
return bigInt(o);
}
}
function sameSizes(s1, s2) { function sameSizes(s1, s2) {
if (!Array.isArray(s1)) return false; if (!Array.isArray(s1)) return false;
if (!Array.isArray(s2)) return false; if (!Array.isArray(s2)) return false;

View File

@@ -1,17 +1,19 @@
const path = require("path"); const path = require("path");
const bigInt = require("big-integer"); const Scalar = require("ffjavascript").Scalar;
const F1Field = require("ffjavascript").F1Field;
const c_tester = require("../index.js").c_tester; const c_tester = require("../index.js").c_tester;
const wasm_tester = require("../index.js").wasm_tester; const wasm_tester = require("../index.js").wasm_tester;
const __P__ = new bigInt("21888242871839275222246405745257275088548364400416034343698204186575808495617"); const __P__ = Scalar.fromString("21888242871839275222246405745257275088548364400416034343698204186575808495617");
const Fr = new F1Field(__P__);
const basicCases = require("./basiccases.json"); const basicCases = require("./basiccases.json");
function normalize(o) { function normalize(o) {
if ((typeof(o) == "bigint") || o.isZero !== undefined) { if ((typeof(o) == "bigint") || o.isZero !== undefined) {
const res = bigInt(o); return Fr.e(o);
return norm(res);
} else if (Array.isArray(o)) { } else if (Array.isArray(o)) {
return o.map(normalize); return o.map(normalize);
} else if (typeof o == "object") { } else if (typeof o == "object") {
@@ -21,15 +23,9 @@ function normalize(o) {
} }
return res; return res;
} else { } else {
const res = bigInt(o); return Fr.e(o);
return norm(res);
} }
function norm(n) {
let res = n.mod(__P__);
if (res.isNegative()) res = __P__.add(res);
return res;
}
} }