Skip to content
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

feat: adding a use_latest_patch option to solc compiler config #1383

Merged

Conversation

mariuspod
Copy link
Contributor

@mariuspod mariuspod commented Dec 22, 2021

What I did

I've noticed that there's an issue with the chainlink contract 0x514910771AF9Ca656af840dff83E8264EcF986CA wrt. to overloaded events. This contract is both ERC-20 and ERC-677 based and so it emits both types of events which have a different signature and can't be matched properly with log filters. AFAIS, overloaded events have been fixed in solidity compiler version 0.4.17, the contract defines 0.4.16 in its pragma version. The fact that brownie doesn't compile solidity contracts with version <0.4.22 causes it to use the given abi from the explorer etherscan which is also incomplete in terms of overloaded events. To overcome this issue and generate a more complete abi I've added a solc compiler setting that enables the download of the latest patch version of a given compiler based on the contract's version pragma.

How I did it

In this change, I've implemented a solidity compiler config flag called use_latest_patch.
It can be turned on for all contracts by setting the value true:

compiler:
    solc:
        use_latest_patch: true

Alternatively, specific contracts can be added as a string list:

compiler:
    solc:
        use_latest_patch:
            - '0x514910771AF9Ca656af840dff83E8264EcF986CA'

In both cases the latest semver patch version of the solc compiler is downloaded and if it's >= 0.4.22 this causes local re-compilation of the contract with the latest compiler instead of the one which is hard-coded in the contract sources.

For the chainlink contract, this fixes the issue that the abi contained only a single Transfer event definition and now includes both event definitions as the re-compilation is done locally.

How to verify it

The contract 0x514910771AF9Ca656af840dff83E8264EcF986CA specifies the compiler version 0.4.16 in its source code.
The latest patch semver version for solidity is therefore 0.4.26

If the flag is set to either true or if the contract is contained in the list, the 0.4.26 version will be used, otherwise the 0.4.16 will be used.

# with use_latest_patch = true
>>> Contract.get_solc_version("v0.4.16", "0x514910771AF9Ca656af840dff83E8264EcF986CA")
Version('0.4.26')

# with use_latest_patch = false
>>> Contract.get_solc_version("v0.4.16", "0x514910771AF9Ca656af840dff83E8264EcF986CA")
Version('0.4.16')

Checklist

  • I have confirmed that my PR passes all linting checks
  • I have included test cases
  • I have updated the documentation
  • I have added an entry to the changelog

@mariuspod
Copy link
Contributor Author

Is there anything I could add to improve this PR ?

I'm using this functionality for capturing transfer events for the given chainlink contract. Without it, the decoding of the received events fail because they don't match the transfer topic from the cached abi.

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

Successfully merging this pull request may close these issues.

2 participants