ethereum / solc-js

Javascript bindings for the Solidity compiler
https://soliditylang.org
MIT License
1.46k stars 476 forks source link

Unable to compile source greater than ~1.3MB #330

Closed maxsam4 closed 2 years ago

maxsam4 commented 5 years ago

When trying to compile large codebase, the below error is shown

~/node_modules/solc/soljson.js:1
(function (exports, require, module, __filename, __dirname) { var Module;if(!Module)Module=(typeof Module!=="undefined"?Module:null)||{};var moduleOverrides={};for(var key in Module){if(Module.hasOwnProperty(key)){moduleOverrides[key]=Module[key]}}var ENVIRONMENT_IS_WEB=typeof window==="object";var ENVIRONMENT_IS_WORKER=typeof importScripts==="function";var ENVIRONMENT_IS_NODE=typeof process==="object"&&typeof require==="function"&&!ENVIRONMENT_IS_WEB&&!ENVIRONMENT_IS_WORKER;var ENVIRONMENT_IS_SHELL=!ENVIRONMENT_IS_WEB&&!ENVIRONMENT_IS_NODE&&!ENVIRONMENT_IS_WORKER;if(ENVIRONMENT_IS_NODE){if(!Module["print"])Module["print"]=function print(x){process["stdout"].write(x+"\n")};if(!Module["printErr"])Module["printErr"]=function printErr(x){process["stderr"].write(x+"\n")};var nodeFS=require("fs");var nodePath=require("path");Module["read"]=function read(filename,binary){filename=nodePath["normalize"](filename);var ret=nodeFS["readFileSync"](

RangeError: Source is too large
    at Uint8Array.set (native)
    at _emscripten_memcpy_big (/home/max/Desktop/Ethereum/polymath-core/node_modules/solc/soljson.js:1:1109281)
    at q8a (/home/max/Desktop/Ethereum/polymath-core/node_modules/solc/soljson.js:12:88915)
    at XTa (/home/max/Desktop/Ethereum/polymath-core/node_modules/solc/soljson.js:5:597290)
    at Array.ZSa (/home/max/Desktop/Ethereum/polymath-core/node_modules/solc/soljson.js:5:557122)
    at Object.eab [as dynCall_vii] (/home/max/Desktop/Ethereum/polymath-core/node_modules/solc/soljson.js:12:99737)
    at invoke_vii (/home/max/Desktop/Ethereum/polymath-core/node_modules/solc/soljson.js:1:1114761)
    at Array.ed (/home/max/Desktop/Ethereum/polymath-core/node_modules/solc/soljson.js:6:8702)
    at Object.wjb [as dynCall_viiii] (/home/max/Desktop/Ethereum/polymath-core/node_modules/solc/soljson.js:12:147059)
    at invoke_viiii (/home/max/Desktop/Ethereum/polymath-core/node_modules/solc/soljson.js:1:1121636)

The errorsome contracts can be found at https://github.com/PolymathNetwork/polymath-core/tree/compilation-bug They are huge because solidity-coverage adds tons of events to track coverage.

To make testing easier, I have added the huge source and compile script to https://github.com/maxsam4/solc-bug-sample with instructions to reproduce.

maxsam4 commented 5 years ago

btw, Native solc is able to compile this and even bigger source codes.

axic commented 5 years ago

Which version of the compiler are you using? And through what tools it this done? Via truffle?

maxsam4 commented 5 years ago

Which version of the compiler are you using? And through what tools it this done? Via truffle?

I am using v0.4.24. I haven't really tried this on 0.5.X because I just started using native solc as its faster anyway.

This source code was generated by https://github.com/sc-forks/solidity-coverage . solidity-coverage works by adding events after every branch to measure coverage of tests. This plethora of events caused the source code to be this large.

axic commented 5 years ago

Is solidity-coverage doing the compilation also? If not, how do you execute the compiler?

maxsam4 commented 5 years ago

Is solidity-coverage doing the compilation also? If not, how do you execute the compiler?

Solidity-coverage calls truffle compile (configurable) to compile the contracts. I have included the input passed by truffle to solcjs in https://github.com/maxsam4/solc-bug-sample.

axic commented 5 years ago

From the initial stack trace it really looks like a limitation/bug in Emscripten or the Javascript engine.

maxsam4 commented 5 years ago

I remember I tried converting Uint8 to Uint32 and the error went away but the compilation never finished. A silent error probably. I didn't look further as native solc worked and is anyway a better choice than solcjs.

axic commented 5 years ago

I remember I tried converting Uint8 to Uint64 and the error went away

I'm not sure what you mean by that, but Uint8Array above is a Javascript construct, how solc is translated into Javascript.

maxsam4 commented 5 years ago

I remember I tried converting Uint8 to Uint64 and the error went away

I'm not sure what you mean by that, but Uint8Array above is a Javascript construct, how solc is translated into Javascript.

I just replaced Uint8Array with Uint32Array and prayed lol. It did not work.

axic commented 5 years ago

It shouldn't :)

matheusaaguiar commented 2 years ago

Closing this for inactivity.