iden3 / circom_old

Circuit compiler for zkSNARKs
GNU General Public License v3.0
471 stars 82 forks source link

Coredump / out of memory when compiling sha256_2_test.circom #11

Closed weijiekoh closed 5 years ago

weijiekoh commented 5 years ago

Using circom version 0.0.15:

git clone git@github.com:iden3/circom.git
cd circom/test/circuits/
circom sha256_2_test.circom -o sha256_2_test.json

After several minutes:


<--- Last few GCs --->

[31367:0x2e7ebd0]   278187 ms: Mark-sweep 2078.6 (2301.9) -> 1253.1 (1890.4) MB, 737.7 / 0.0 ms  allocation failure GC in old space requested
[31367:0x2e7ebd0]   279057 ms: Mark-sweep 1253.1 (1890.4) -> 1252.7 (1599.4) MB, 870.1 / 0.0 ms  last resort GC in old space requested
[31367:0x2e7ebd0]   279914 ms: Mark-sweep 1252.7 (1599.4) -> 1252.7 (1521.4) MB, 856.6 / 0.0 ms  last resort GC in old space requested

<--- JS stacktrace --->

==== JS stack trace =========================================

Security context: 0x1a3b682255e9 <JSObject>
    0: builtin exit frame: stringify(this=0x1a3b68208e19 <Object map = 0x1a4f59682ba1>,1,0x77443982201 <null>,0x132dd8eccea9 <Object map = 0x22001e6be951>)

    1: /* anonymous */ [/usr/local/share/.config/yarn/global/node_modules/circom/cli.js:60] [bytecode=0x1780f0dfdb31 offset=40](this=0x136bee7066f1 <JSGlobal Object>,cir=0x
132dd8eccea9 <Object map = 0x22001e6be951>)
    2: /* anonymous */(ak...

FATAL ERROR: CALL_AND_RETRY_LAST Allocation failed - JavaScript heap out of memory
 1: node::Abort() [node]
 2: 0x8d05bc [node]
 3: v8::Utils::ReportOOMFailure(char const*, bool) [node]
 4: v8::internal::V8::FatalProcessOutOfMemory(char const*, bool) [node]
 5: v8::internal::Factory::NewFixedArray(int, v8::internal::PretenureFlag) [node]
 6: v8::internal::KeyAccumulator::GetOwnEnumPropertyKeys(v8::internal::Isolate*, v8::internal::Handle<v8::internal::JSObject>) [node]
 7: v8::internal::FastKeyAccumulator::GetKeysFast(v8::internal::GetKeysConversion) [node]
 8: v8::internal::KeyAccumulator::GetKeys(v8::internal::Handle<v8::internal::JSReceiver>, v8::internal::KeyCollectionMode, v8::internal::PropertyFilter, v8::internal::GetKe
ysConversion, bool) [node]
 9: v8::internal::JsonStringifier::SerializeJSReceiverSlow(v8::internal::Handle<v8::internal::JSReceiver>) [node]
10: v8::internal::JsonStringifier::Result v8::internal::JsonStringifier::Serialize_<true>(v8::internal::Handle<v8::internal::Object>, bool, v8::internal::Handle<v8::interna
l::Object>) [node]
11: v8::internal::JsonStringifier::Result v8::internal::JsonStringifier::Serialize_<false>(v8::internal::Handle<v8::internal::Object>, bool, v8::internal::Handle<v8::intern
al::Object>) [node]
12: v8::internal::JsonStringifier::Stringify(v8::internal::Handle<v8::internal::Object>, v8::internal::Handle<v8::internal::Object>, v8::internal::Handle<v8::internal::Obje
ct>) [node]
13: v8::internal::Builtin_JsonStringify(int, v8::internal::Object**, v8::internal::Isolate*) [node]
14: 0x20678088697d
Aborted (core dumped)

However, it works fine with sum_test.circom and constants_test.circom.

weijiekoh commented 5 years ago

I tried again with this code:

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const compile = require("circom");
compile("circuits/circuit.circom").then((cir) => {
    console.log(cir);
}).catch((err) => {
    console.error(err);
});
<--- Last few GCs --->

[8384:0x38dad20]   202887 ms: Mark-sweep 2076.6 (2269.4) -> 1250.9 (1950.4) MB, 580.1 / 0.0 ms  allocation failure GC in old space requested
[8384:0x38dad20]   203568 ms: Mark-sweep 1250.9 (1950.4) -> 1250.5 (1661.4) MB, 680.6 / 0.0 ms  last resort GC in old space requested
[8384:0x38dad20]   204234 ms: Mark-sweep 1250.5 (1661.4) -> 1250.5 (1583.9) MB, 665.4 / 0.0 ms  last resort GC in old space requested

<--- JS stacktrace --->

==== JS stack trace =========================================

Security context: 0xa0c1aea5879 <JSObject>
    0: builtin exit frame: getOwnPropertySymbols(this=0xa0c1ae847f1 <JSFunction Object (sfi = 0x26f866d89cf9)>,0x3d601cfb9b1 <Object map = 0x36fc78902361>)

    1: formatValue(aka formatValue) [util.js:414] [bytecode=0x184f00c5fb49 offset=435](this=0x26f866d822d1 <undefined>,ctx=0x31af8b31e681 <Object map = 0x26ab96e6f499>,valu
e=0x3d601cfb9b1 <Object map = 0x36fc78902361>,recurseTimes=1,ln=0x26f8...

FATAL ERROR: CALL_AND_RETRY_LAST Allocation failed - JavaScript heap out of memory
 1: node::Abort() [node]
 2: 0x8c21ec [node]
 3: v8::Utils::ReportOOMFailure(char const*, bool) [node]
 4: v8::internal::V8::FatalProcessOutOfMemory(char const*, bool) [node]
 5: v8::internal::Factory::NewFixedArray(int, v8::internal::PretenureFlag) [node]
 6: v8::internal::BaseNameDictionary<v8::internal::NameDictionary, v8::internal::NameDictionaryShape>::CollectKeysTo(v8::internal::Handle<v8::internal::NameDictionary>, v8:
:internal::KeyAccumulator*) [node]
 7: v8::internal::KeyAccumulator::CollectOwnPropertyNames(v8::internal::Handle<v8::internal::JSReceiver>, v8::internal::Handle<v8::internal::JSObject>) [node]
 8: v8::internal::KeyAccumulator::CollectOwnKeys(v8::internal::Handle<v8::internal::JSReceiver>, v8::internal::Handle<v8::internal::JSObject>) [node]
 9: v8::internal::KeyAccumulator::CollectKeys(v8::internal::Handle<v8::internal::JSReceiver>, v8::internal::Handle<v8::internal::JSReceiver>) [node]
10: v8::internal::KeyAccumulator::GetKeys(v8::internal::Handle<v8::internal::JSReceiver>, v8::internal::KeyCollectionMode, v8::internal::PropertyFilter, v8::internal::GetKe
ysConversion, bool) [node]
11: v8::internal::Builtin_ObjectGetOwnPropertySymbols(int, v8::internal::Object**, v8::internal::Isolate*) [node]
12: 0x1465bca8697d
Aborted (core dumped)
weijiekoh commented 5 years ago

Resolved by running the above JS code as such:

nodejs --max_old_space_size=4000 build/index.js

I found the solution by realising that the npm test command specifies --max_old_space_size, which is also a nodejs flag.

weijiekoh commented 5 years ago

To fix this, perhaps cli.js could specify the --max_old_space_size flag in the shebang.

jbaylina commented 5 years ago

Yes. I need to profile where the memory is spent.

In any case, I just extended the memory in cli.js. And now it works without problems.

weijiekoh commented 5 years ago

Thank you!!