Zokrates / ZoKrates

A toolbox for zkSNARKs on Ethereum
https://zokrates.github.io
GNU Lesser General Public License v3.0
1.83k stars 361 forks source link

Invalid value: expected variant index 0 <= i < 2 #1024

Closed nicolac93 closed 3 years ago

nicolac93 commented 3 years ago

Description

when I launch the function compute-witness I get the following error

  called `Result::unwrap()` on an `Err` value: Custom("invalid value: integer `16777216`, expected variant index 0 <= i < 2") (/home/circleci/project/zokrates_core/src/ir/serialize.rs:51:60)\nThis is unexpected, please submit a full bug report at https://github.com/Zokrates/ZoKrates/issues\

Environment

Steps to Reproduce

I launch the following python file

from commands import *

i = generate_inputs_auto(2,4,7,9,23)

file that contains the functions

import subprocess
import os
import json

CIRCUITS_DIR = 'circuits'

def compute_w(circuit, inputs):

    params = ['zokrates', 
    'compute-witness', 
    '-i',
    os.getcwd()+f"/{CIRCUITS_DIR}/{circuit}",
    "-o",
    os.getcwd()+"/witness",
    "-a"
    ]

    for i in inputs:
        params.append(str(i))

    out = subprocess.Popen(
    params, 
    stdout=subprocess.PIPE, 
    stderr=subprocess.STDOUT)
    res,e = out.communicate()

    return eval(res.split()[-1])

def mimc_hash(point):
    """Hashes a point"""
    return compute_w("mimc_hash", point)

def generate_inputs_auto(val1,val2,val3,val4,threshold):

    tot = val1 + val2 + val3 +val4
    print(f"Total value is {tot}")

    leaf1 = mimc_hash([val1,0])[0]
    leaf2 = mimc_hash([val2,0])[0]
    leaf3 = mimc_hash([val3,0])[0]
    leaf4 = mimc_hash([val4,0])[0]

    #print(f"{leaf1} {leaf2} {leaf3} {leaf4}")

    lhs = mimc_hash([leaf1,leaf2])[0]
    rhs = mimc_hash([leaf3,leaf4])[0]

    root = mimc_hash([lhs,rhs])[0]

    data = {}
    data['val1'] = str(val1)
    data['val2'] = str(val2)
    data['val3'] = str(val3)
    data['val4'] = str(val4)
    data['threshold'] = str(threshold)
    data['root'] = root

    """ with open('inputs.json', 'w') as outfile:
        json.dump(data, outfile, indent=4) """

    return [data['val1'],data['val2'],data['val3'],data['val4'],data['root'],data['threshold']]
dark64 commented 3 years ago

Hey @nicolac93, thanks for the report!

It seems like it fails to deserialize the program. It might be the following:

This doesn't seem to be an issue with the compiler so I will close this issue. Feel free to open an issue again with a minimal example that gives this error, without any of the python code.