-
Notifications
You must be signed in to change notification settings - Fork 9
Human-readable constraint display #105
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
src/testers/witnessTester.ts
Outdated
const modP = BigInt(fieldSize % coeff); | ||
// XXX: Why within 10000? | ||
if(modP !== BigInt(0) && modP <= BigInt(10000)) { | ||
coeff = `(ρ-${fieldSize % coeff})/${fieldSize/coeff}`; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Changes some hard-to-read numbers into more-readable:
(-1 + (-667976161860329444038281425331337740739391003430665110586493047686029312 * y) + (-84832972556261839392861741017079893073902657435694469044484617056125722624 * x) + (85500948718122168836900022442411230814642048439125134155071110103811751936 * ltQ.n2b.out[0]) + (171001897436244337673800044884822461629284096878250268310142220207623503872 * ltQ.n2b.out[1]) + (342003794872488675347600089769644923258568193756500536620284440415247007744 * ltQ.n2b.out[2]) + (684007589744977350695200179539289846517136387513001073240568880830494015488 * ltQ.n2b.out[3]) + (1368015179489954701390400359078579693034272775026002146481137761660988030976 * ltQ.n2b.out[4]) + (2736030358979909402780800718157159386068545550052004292962275523321976061952 * ltQ.n2b.out[5]) + (5472060717959818805561601436314318772137091100104008585924551046643952123904 * ltQ.n2b.out[6]) + (10944121435919637611123202872628637544274182200208017171849102093287904247808 * ltQ.n2b.out[7])) * ((-667976161860329444038281425331337740739391003430665110586493047686029312 * y) + (-84832972556261839392861741017079893073902657435694469044484617056125722624 * x) + (85500948718122168836900022442411230814642048439125134155071110103811751936 * ltQ.n2b.out[0]) + (171001897436244337673800044884822461629284096878250268310142220207623503872 * ltQ.n2b.out[1]) + (342003794872488675347600089769644923258568193756500536620284440415247007744 * ltQ.n2b.out[2]) + (684007589744977350695200179539289846517136387513001073240568880830494015488 * ltQ.n2b.out[3]) + (1368015179489954701390400359078579693034272775026002146481137761660988030976 * ltQ.n2b.out[4]) + (2736030358979909402780800718157159386068545550052004292962275523321976061952 * ltQ.n2b.out[5]) + (5472060717959818805561601436314318772137091100104008585924551046643952123904 * ltQ.n2b.out[6]) + (10944121435919637611123202872628637544274182200208017171849102093287904247808 * ltQ.n2b.out[7])) = 0
becomes:
(-1 + ((ρ-1)/-32768 * y) + (-84832972556261839392861741017079893073902657435694469044484617056125722624 * x) + ((ρ-1)/256 * ltQ.n2b.out[0]) + ((ρ-1)/128 * ltQ.n2b.out[1]) + ((ρ-1)/64 * ltQ.n2b.out[2]) + ((ρ-1)/32 * ltQ.n2b.out[3]) + ((ρ-1)/16 * ltQ.n2b.out[4]) + ((ρ-1)/8 * ltQ.n2b.out[5]) + ((ρ-1)/4 * ltQ.n2b.out[6]) + ((ρ-1)/2 * ltQ.n2b.out[7])) * (((ρ-1)/-32768 * y) + (-84832972556261839392861741017079893073902657435694469044484617056125722624 * x) + ((ρ-1)/256 * ltQ.n2b.out[0]) + ((ρ-1)/128 * ltQ.n2b.out[1]) + ((ρ-1)/64 * ltQ.n2b.out[2]) + ((ρ-1)/32 * ltQ.n2b.out[3]) + ((ρ-1)/16 * ltQ.n2b.out[4]) + ((ρ-1)/8 * ltQ.n2b.out[5]) + ((ρ-1)/4 * ltQ.n2b.out[6]) + ((ρ-1)/2 * ltQ.n2b.out[7])) = 0
man this is the coolest thing ever <3 |
Let me know any suggestions you have. It definitely is helping me think about constraints better so far as is |
const r1csPath = this.path.ofCircuit(circuit, 'r1cs'); | ||
const symPath = this.path.ofCircuit(circuit, 'sym'); | ||
// @ts-ignore | ||
const r1csFile = await import('r1csfile'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If this dependency is loaded synchronously at the top of the file, when I use the witnessTester to parse the constraints, I get this error:
(node:1210393) Warning: To load an ES module, set "type": "module" in the package.json or use the .mjs extension.
(Use `node --trace-warnings ...` to show where the warning was created)
Exception during run: /home/ben/circomkit/node_modules/web-worker/node.js:17
import URL from 'url';
^^^^^^
SyntaxError: Cannot use import statement outside a module
at wrapSafe (node:internal/modules/cjs/loader:1281:20)
at Module._compile (node:internal/modules/cjs/loader:1321:27)
at Module._extensions..js (node:internal/modules/cjs/loader:1416:10)
at Module.load (node:internal/modules/cjs/loader:1208:32)
at Module._load (node:internal/modules/cjs/loader:1024:12)
at cjsLoader (node:internal/modules/esm/translators:348:17)
at ModuleWrap.<anonymous> (node:internal/modules/esm/translators:297:7)
at ModuleJob.run (node:internal/modules/esm/module_job:222:25)
at async ModuleLoader.import (node:internal/modules/esm/loader:316:24)
at async formattedImport (/home/ben/ntru-circom/node_modules/mocha/lib/nodejs/esm-utils.js:9:14)
at async exports.requireOrImport (/home/ben/ntru-circom/node_modules/mocha/lib/nodejs/esm-utils.js:42:28)
at async exports.loadFilesAsync (/home/ben/ntru-circom/node_modules/mocha/lib/nodejs/esm-utils.js:100:20)
at async singleRun (/home/ben/ntru-circom/node_modules/mocha/lib/cli/run-helpers.js:162:3)
at async exports.handler (/home/ben/ntru-circom/node_modules/mocha/lib/cli/run.js:375:5)
With the dynamic import, I can both print constraints through the witness tester and the cli without error.
I wrote this function to make it easier to understand my circuits. What do you think about this? It's a lot nicer than
snarkjs rp mycircuit.r1cs
.I'll have to come up with something better than that giant string block in the test case before merging.Sorry about just ignoring all the ts errors 🤣
Also, the
compute
match fix is in here. I tried a few more tests but I couldn't get it to fail like I thought it might so there's no test change for it.Since the full list of mutliplier(4) constraints is no longer in the test source, the output is like this: