ethereum / solc-js

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

Older nightlies with leading zeros in version string crash `soljson` #562

Open cameel opened 3 years ago

cameel commented 3 years ago

Originally reported in https://github.com/ethereum/solc-bin/pull/21#discussion_r746961386.

soljson-v0.4.1-nightly.2016.9.9+commit.79867f49.js crashes solc-js because the version it reports apparently does not conform to semver. solc-js should be able to handle that more gracefully.

This happens for --version and --bin. Probably in other cases too.

Repro

npm install solc
curl https://binaries.soliditylang.org/bin/soljson-v0.4.1-nightly.2016.9.9+commit.79867f49.js --location --output node_modules/solc
npx solcjs --version

Running the above produces the following exception:

TypeError: Invalid Version: 0.4.1-nightly.2016.09.09+commit.79867f49.Emscripten.clang
    at new SemVer (/tmp/s/node_modules/semver/semver.js:323:11)
    at compare (/tmp/s/node_modules/semver/semver.js:614:10)
    at Function.gt (/tmp/s/node_modules/semver/semver.js:643:10)
    at setupMethods (/tmp/s/node_modules/solc/wrapper.js:20:27)
    at Object.<anonymous> (/tmp/s/node_modules/solc/index.js:3:18)
    at Module._compile (internal/modules/cjs/loader.js:999:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1027:10)
    at Module.load (internal/modules/cjs/loader.js:863:32)
    at Function.Module._load (internal/modules/cjs/loader.js:708:14)
    at Module.require (internal/modules/cjs/loader.js:887:19)
axic commented 3 years ago

It must added to translate.js. Let me give this a look.

axic commented 3 years ago

It seems based on semver rules a dot cannot be followed by a leading zero. As @cameel has observed.

cameel commented 3 years ago

By the way, I checked that nightly in Remix and it just fails silently - the compile button keeps spinning but on the console there is Uncaught TypeError: Invalid Version: 0.4.1-nightly.2016.09.09+commit.79867f49.Emscripten.clang.