question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Unable to use 0.4.* BIN compiler with latest package

See original GitHub issue

Preface

This is a replication of the issue from https://github.com/ConsenSys/solc-typed-ast/pull/92.

Setup

  • package.json
    {
        "name": "test-server",
        "version": "1.0.0",
        "description": "",
        "main": "index.js",
        "author": "",
        "license": "UNLICENSED",
        "dependencies": {
            "solc-0811": "npm:solc@0.8.11",
            "solc-0426": "npm:solc@0.4.26",
            "axios": "^0.26.0",
            "fs-extra": "^10.0.0"
        }
    }
    
  • index.js
    const axios = require("axios");
    const fse = require("fs-extra");
    const path = require("path");
    const { argv } = require("process");
    const solc0426 = require("solc-0426");
    const solc0811 = require("solc-0811");
    const stream = require('stream');
    const util = require('util');
    
    const CACHE_DIR = path.join(__dirname, ".compiler_cache");;
    const BINARIES_URL = "https://binaries.soliditylang.org";
    
    async function getCompilerList(arch) {
        const cachedListPath = path.join(CACHE_DIR, arch, "list.json");
    
        if (fse.existsSync(cachedListPath)) {
            return fse.readJSONSync(cachedListPath);
        }
    
        const response = await axios.get(`${BINARIES_URL}/${arch}/list.json`);
        const metaData = response.data;
    
        fse.ensureDirSync(path.join(CACHE_DIR, arch));
        fse.writeJSONSync(cachedListPath, metaData);
    
        return metaData;
    }
    
    async function getCompilerForVersion(arch, version) {
        const list = await getCompilerList(arch);
        const compilerFileName = list.releases[version];
    
        if (compilerFileName === undefined) {
            return undefined;
        }
    
        const compilerLocalPath = path.join(CACHE_DIR, arch, compilerFileName);
    
        if (!fse.existsSync(compilerLocalPath)) {
            const response = await axios({
                method: "GET",
                url: `${BINARIES_URL}/${arch}/${compilerFileName}`,
                responseType: "stream"
            });
    
            const target = fse.createWriteStream(compilerLocalPath, { mode: 0o555 });
            const pipeline = util.promisify(stream.pipeline);
    
            await pipeline(response.data, target);
        }
    
        return compilerLocalPath;
    }
    
    (async () => {
        const [arch, version, mode] = argv.slice(2);
    
        console.log(`ARCH: ${arch}`);
        console.log(`VERSION: ${version}`);
        console.log(`MODE: ${mode}`);
        console.log();
    
        const compilerFileName = await getCompilerForVersion(arch, version);
        const compilerModule = require(compilerFileName);
    
        if (mode === "legacy") {
            const wrappedCompilerModule = solc0426.setupMethods(compilerModule);
            // const wrappedCompilerModule = solc0811.setupMethods(compilerModule);
    
            const input = {
                "language": "Solidity",
                "sources": {
                    "sample.sol": "contract Test{}"
                },
                "settings": {
                    "outputSelection": {
                        "*": {
                            "*": [
                                "*"
                            ],
                            "": [
                                "*"
                            ]
                        }
                    }
                }
            }
    
            const output = wrappedCompilerModule.compile(input);
            // const output = wrappedCompilerModule.compile(JSON.stringify(input));
        
            console.log(output);
        } else {
            const wrappedCompilerModule = solc0811.setupMethods(compilerModule);
    
            const input = {
                "language": "Solidity",
                "sources": {
                    "sample.sol": {
                        "content": "contract Test{}"
                    } 
                },
                "settings": {
                    "outputSelection": {
                        "*": {
                            "*": [
                                "*"
                            ],
                            "": [
                                "*"
                            ]
                        }
                    }
                }
            }
    
            const output = wrappedCompilerModule.compile(JSON.stringify(input));
        
            console.log(JSON.parse(output));
        }
    })();
    
    
  • commands
    npm install
    node index.js bin 0.4.26 legacy
    

Details

This scenario is originally working but as I undestand, SolcJS should make a flow of interaction with compiler to be universal.

If we uncomment lines 68 and 90, then comment lines 67 and 89, we will get

{"errors":[{"component":"general","formattedMessage":"Source input is not a JSON object.","message":"Source input is not a JSON object.","severity":"error","type":"JSONError"}]}

If we try to uncomment 89 and comment 90, then we will get

{"errors":[{"component":"general","formattedMessage":"* Line 1, Column 1\n  Syntax error: value, object or array expected.\n* Line 1, Column 1\n  A valid JSON document must be either an array or an object value.\n","message":"* Line 1, Column 1\n  Syntax error: value, object or array expected.\n* Line 1, Column 1\n  A valid JSON document must be either an array or an object value.\n","severity":"error","type":"JSONError"}]}

The original expectation was that we are able to use side-loaded compiler as on lines 94 and 117:

const wrappedCompilerModule = solc0811.setupMethods(compilerModule);
// const input = ...
const output = wrappedCompilerModule.compile(JSON.stringify(input));

Can somebody take a look at this? Thanks in advance.

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:6 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
blitz-1306commented, Feb 15, 2022

@axic @cameel The issue was a bit abstracted in an original repo. Even though I used latest SolcJS, the input was composed somewhere else and it was composed for legacy version, so there was a plain string instead of { content: "..." }. When switching SolcJS we actually were have to simplify input composition logic.

Thank you both for pointing out an issue with input. It is on our end and now it is understood now to fix it. I will close this thread, as it not relates to latest SolcJS release.

1reaction
axiccommented, Feb 15, 2022

Sorry, I think this is hard to follow without line numbers when you refer to line numbers.

        const output = wrappedCompilerModule.compile(input);
        // const output = wrappedCompilerModule.compile(JSON.stringify(input));

The current API always expects stringified JSON as an input.

The problem you are facing here is using an older package, which should not be needed. The ideal setup is using the very latest solc-js with every past version.

If you still want to use the 0.4.26 package, then it needs to call wrappedCompilerModule.compileStandard(JSON.stringify(input)). compile was a different function altogether.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Meaning of common message when install a package "There ...
This often means that the package has updated recently on CRAN but the binary isn't yet available for your OS (can take a...
Read more >
Build Failed with Missing Dependencies Error with Clang-11 ...
Building latest master with Clang-11 failed with 404 Not Found Warning and missing dependency declarations. I tried to access the file ...
Read more >
namespace 'rlang' 0.4.5 is being loaded, but >= 0.4.10 is ...
I believe the simplest solution would be downloading the source package and installing it as source. install.packages("https://cran.r-project.
Read more >
VSIXColorCompiler package version 17.0.31410.258 does ...
I updated my extension from VS 2019 to VS 2022. We use the VSIXColorCompiler to compile a .vstheme file into .pkgdef. It looks...
Read more >
I can't install TensorFlow-macos a… | Apple Developer Forums
However, all installing instruction commands not work at all. After that, I looked into pypi.org and found out there are whl files for...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found