TransWikia.com

Inheriting from contracts of a different Solidity version

Ethereum Asked on January 3, 2022

The OpenZeppelin version I’m using is Solidity 0.5.0 but I’m using 0.5.15 in my core contracts. Everything is compiling but I’m having some issues verifying the contract on Etherscan and submitting transactions. Is it kosher to inherit from a different Solidity version like this?

2 Answers

It is acceptable.

Some things to understand and clarify.

There is only one compiler version and it will apply to the top-level contract and all inherited contracts. A style I have found useful is

  • a specific version in the pragma of the top-level contract to disambiguate the version and reduce confusion during review, test and verification (e.g. etherscan). It is useful to know, from the code, what version of the compiler must have been used to compile it.
  • an ambiguous pragma in the inherited contracts, because you will know the precise version will be determined at compile-time and it must be the version specified in the main contract.

Ambiguous (convenient - unmodified openzeppelin contracts):

pragma solidity ^0.6.0;

contract Component {}

Unambiguous Top-level contract:

pragma solidity 0.6.6;

contract Main is Component {}

There is no doubt that Main must be compiled with 0.6.6 and, by extension, so is Component because inheritance is a source code roll-up and because it is part of Main.

The scheme works well for large systems with many contracts and components. As the developer, if you change your mind and want to go with a newer compiled (e.g. 0.6.10) you will only change a few top-level contracts and run your tests.

Hope it helps.

Update

Some code auditors favour explicit pragmas at every level so it might be productive to follow the suggested scheme during development and then make the sub-modules precise, as well when polishing a candidate production release.

Answered by Rob Hitchens on January 3, 2022

If the contracts compile they should work without problems.

Usually both Solidity and OpenZeppelin try to maintain compatibility between minor version of the same release.

Answered by Ismael on January 3, 2022

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP