Skip to content

feature request: have flatten utilize the Compiler Version from etherscan-like sites #104

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
plotchy opened this issue Sep 28, 2022 · 2 comments

Comments

@plotchy
Copy link

plotchy commented Sep 28, 2022

Recently I have been using flatten a lot (awesome tool!), and I noticed a repeated issue that came up in my compilation pipeline with using flatten'd contracts.

The flattened files tend to have multiple pragma solidity ... statements, and often times they do not match exactly. Some statements may use ^0.8.0 and others =0.8.X. Of course, this can still compile fine if you know the correct solc version to use, but specifically the ethers-rs and foundry suite of tools often fails to compile these types of files, as it struggles to auto-detect the solc version required to satisfy each of the pragma statements in these. I assume dapptools, hardhat etc have similar issues with multiple pragma solidity ... statements.

I noticed there is a Compiler Version field on the etherscan-like sites that displays the exact solc version that was used to compile the contracts. This is a required field upon contract verification, so it should be present on all verified contracts. Would it be possible to utilize this field and insert a pragma solidity =<compiler version>; at the top of the file and comment out each of the other pragma solidity ... statements?

Example of different etherscan-like sites verified contracts with Compiler Version:
https://etherscan.io/address/0x27761c482000f2fc91e74587576c2b267eeb4546#code
https://polygonscan.com/address/0xAe8C44b49f9756BFEdA7b6B5F0F66bf42d96aD8C#code
https://snowtrace.io/address/0x711555f2b421da9a86a18dc163d04699310fe297#code
https://arbiscan.io/address/0xD91D0d52D6e09f0b93db80E1A8935aA47CFFd075#code

Minimal file example for failed auto-detect solc version compilation

pragma solidity =0.8.15;
interface A {
    function f() external;
}

pragma solidity ^0.8.0;
interface B {
    function g() external;
}

Foundry + ethers-rs detects this as requiring latest solc (0.8.17) as it matches on last entry of pragma solidity

Proposed Feature

Say Compiler Version: v0.8.15+commit.e14f2714

pragma solidity =0.8.15;
//pragma solidity =0.8.15;
interface A {
    function f() external;
}

//pragma solidity ^0.8.0;
interface B {
    function g() external;
}

Footguns

  • Specifically lines beginning with pragma solidity should be commented as to not accidentally comment out pragma experimental ... lines
  • <compiler version> should likely always be pre-pended with an =
@naddison36
Copy link
Owner

Thanks for taking the time to raise a well-documented feature request. This was pretty easy to do and has been released in v2.2.2

@plotchy
Copy link
Author

plotchy commented Sep 29, 2022

You're the man! Thank you :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants