Zokrates / ZoKrates

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

Fatal JavaScript invalid size error 134324592 #1276

Closed vinayprolitus closed 1 year ago

vinayprolitus commented 1 year ago

Description

I have an array of json objects. Something like this: [[{"age":"57"},{"age":"62"},{"age":"51"},{"age":"28"},{"age":"20"}... (800+ items)] Till the length of array is 800 or less, code is working fine. But if its 800 or more than that I am getting the below error, on zokrates-js.

node:internal/errors:484
    ErrorCaptureStackTrace(err);
    ^

TypeError [ERR_ENCODING_INVALID_ENCODED_DATA]: The encoded data was not valid for encoding utf-8
    at new NodeError (node:internal/errors:393:5)
    at TextDecoder.decode (node:internal/encoding:433:15)
    at getStringFromWasm0 (file:///home/vinay/Documents/zokrates/mox/zkp/node_modules/zokrates-js/wasm.js:15:28)
    at imports.wbg.__wbindgen_json_parse (file:///home/vinay/Documents/zokrates/mox/zkp/node_modules/zokrates-js/wasm.js:332:28)
    at wasm://wasm/06434de2:wasm-function[19391]:0x17df4df
    at wasm://wasm/06434de2:wasm-function[13686]:0x165c499
    at wasm://wasm/06434de2:wasm-function[2085]:0xbb1bf9
    at Module.setup (file:///home/vinay/Documents/zokrates/mox/zkp/node_modules/zokrates-js/wasm.js:157:10)
    at Object.setup (file:///home/vinay/Documents/zokrates/mox/zkp/node_modules/zokrates-js/index.js:71:26)
    at Object.setup (file:///home/vinay/Documents/zokrates/mox/zkp/node_modules/zokrates-js/index.js:112:25) {
  errno: 1,
  code: 'ERR_ENCODING_INVALID_ENCODED_DATA'
}

If I have only one key and smaller source file, I am getting error at length 800 or more. But if I am increasing the number of keys in JSON object then getting this error at around length 120 or 150.

Environment

Steps to Reproduce

Using zokrates-js pass the input.json and you'll get the error

// Some *minimal* ZoKrates source code to reproduce the bug.
const u32 PRIVATE_DATA_LENGTH = 800;
struct PrivateData {
  u32 age;
}
struct PublicData {
   u32[2] age;
}
struct NonMandateFields{}

def main(private PrivateData[PRIVATE_DATA_LENGTH] x, PublicData y, NonMandateFields z, u8 fieldMatchCount) {
    for u32 i in 0..PRIVATE_DATA_LENGTH {
         assert(y.age[0] <= x[i].age && x[i].age <= y.age[1]);
    }
    return;
}
// ...

-->

vinaykharayat commented 1 year ago

what will be the limit of input now?