weijiekoh / circom_zkutil

4 stars 4 forks source link

One adhoc solution for this #1

Closed lispc closed 3 years ago

lispc commented 3 years ago

I encountered a similar problem. Then I found circom did not optimize some unused variables away. So I wrote an adhoc script to deal with this. It worked.

import json
j = json.load(open('circuit.r1cs.json'))
cs = j['constraints']
s = set()
for c in cs:
    for item in c:
        for elem in item:
            s.add(elem)
for v in range(j['nVars']):
    if str(v) not in s:
        j['constraints'].append([{}, {}, {str(v): "1"}])

json.dump(j, open('circuit.r1cs.json.new', 'w'))

( Of course, the right solution would be to optimize this in circom and make a PR into it. )

weijiekoh commented 3 years ago

Thank you @lispc ! I faced the same issue here: https://github.com/weijiekoh/circom_sha256 Your script made it work. Anyway, I've contacted Jordi to let him know that this issue exists.

lispc commented 3 years ago

I also added an end2end test.sh for this.

https://github.com/Fluidex/circom_zkutil/blob/master/test.sh

lispc commented 3 years ago

A new version for this script https://github.com/Fluidex/zkutil/blob/master/contrib/process_circom_files.mjs

weijiekoh commented 3 years ago

Hi @lispc , I think the latest version of circom (0.5.32 onwards) has fixed this issue at the compiler level. Hopefully there's no need to run the script now.

lispc commented 3 years ago

Thanks for the information ! I just deleted related codes in our PLONK zkutil.