naddison36 / sol2uml

Solidity contract visualisation tool
MIT License
1.13k stars 268 forks source link

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

Closed plotchy closed 1 year ago

plotchy commented 1 year ago

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

naddison36 commented 1 year ago

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 commented 1 year ago

You're the man! Thank you :)