Draft
Conversation
numtel
commented
Dec 4, 2024
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}`; |
Contributor
Author
There was a problem hiding this comment.
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
Owner
|
man this is the coolest thing ever <3 |
Contributor
Author
|
Let me know any suggestions you have. It definitely is helping me think about constraints better so far as is |
numtel
commented
Dec 8, 2024
| const r1csPath = this.path.ofCircuit(circuit, 'r1cs'); | ||
| const symPath = this.path.ofCircuit(circuit, 'sym'); | ||
| // @ts-ignore | ||
| const r1csFile = await import('r1csfile'); |
Contributor
Author
There was a problem hiding this comment.
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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
computematch 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: