ethereum / solidity

Solidity, the Smart Contract Programming Language
https://soliditylang.org
GNU General Public License v3.0
23.01k stars 5.7k forks source link

`outputSelection` with contract name and not `*` leads to empty compiler output in `<=0.5.8` #14214

Open kuzdogan opened 1 year ago

kuzdogan commented 1 year ago

Description

Summary:

Providing a contract name in the contract selection of the outputSelection field of the JSON input is outputting empty JSON fields in versions <=0.5.8.

Doesn't work:

"outputSelection": {
  "*": {
    "Storage": ["*"]
  }
}

Works:

"outputSelection": {
  "*": {
    "*": ["*"]
  }
}

Details

I've encountered multiple issues about the outputSelection.

Digging into the issue https://github.com/ethereum/sourcify/issues/1017 in Sourcify, I came across this issue which affects versions <=0.5.8 but not >=0.5.9. I couldn't find any related changes in this version about the outputSelection so I'm opening the issue.

To reproduce, here's the compiler input JSON:

{
  "language": "Solidity",
  "settings": {
    "optimizer": { "enabled": true, "runs": 200 },
    "outputSelection": {
      "*": {
        "Storage": ["evm.bytecode"]
      }
    }
  },
  "sources": {
    "Storage.sol": {
      "content": "pragma solidity >=0.4.0 <0.9.0;\n\ncontract Storage {\n\n    uint256 number;\n\n    function store(uint256 num) public {\n        number = num;\n    }\n\n    function retrieve() public view returns (uint256){\n        return number;\n    }\n}\n"
    }
  }
}

This would generate the following unexpected output:

{
  "contracts": {
    "Storage.sol": {
      "Storage": {
        "evm": {
          "bytecode": {
            "linkReferences": {},
            "object": "",
            "opcodes": "",
            "sourceMap": ""
          }
        }
      }
    }
  },
  "sources": {
    "Storage.sol": {
      "id": 0
    }
  }
}

Changing the "Storage" field in the JSON to "*" will lead to an expected compiler output with bytecode.

The contract is fairly simple and attached here: Storage.sol.txt

Environment

ekpyron commented 1 year ago

Since we won't touch old releases, the fix for this will probably be something similar to https://github.com/ethereum/solc-js/issues/690, although we may want to come up with a nicer cross-platform way to do such input/output translations.

kuzdogan commented 1 year ago

Right. Putting this for the record and if it is indeed a bug, maybe to be listed in bugs.

We just went forward with the workaround of using * on all levels, so all fine if this should be closed.