0

I am confused about whether the previous contracts were affected if some opcode changed or were removed. for example, it seems gasleft() was removed since 0.8 version. Would the contract including gasleft() not work in the future?

2 Answers 2

1

Just so we're clear and for anyone else who happens upon this question, OPCODES are instructions that are executed by the EVM. Solidity is a compiler that generates bytecode - the machine-readable code the EVM executes.

Have a look here: https://github.com/crytic/evm-opcodes

Solidity is one of several compilers that can translate high-level (developer-friendly) source code into EVM-executable OPCODES. Why is this important? Because changes to the compiler going forward have no bearing on bytecode that is already deployed on the EVM. Compilers can change the dialect, optimize more efficiently, introduce new tricks ...

The interpretation of the OPCODES depends on the EVM and is not absolutely protected from change over time. For example, the gas cost of a particular operation. Changes, however, are constrained by the need for a fork, e.g. "Berlin" upgrade. And, it would not make sense to deprecate or substantially change the meaning of an OPCODE in a way that causes any breakage to previously-deployed contracts.

It is wise to minimize assumptions, particularly gas cost. Avoid, for example, assuming that the cost of an operation is known and will never change.

Hope it helps.

1
  • Thanks. In short, each upgrade of EVM should be backward compatible, where features are allowed to be added but not removed except for breaking upgrades.
    – Howard
    Commented Mar 5, 2023 at 5:52
0

Each contract will have a pragma solidity version specify the version it was built for.

When the contract is compiled into bytecode and deployed, it no longer cares about version changes and deprecations because it has already been built.

To answer your question, a contract including gas left that has been deployed already will work as normal. If you try to recompile that contract using a new version of solidity, it will fail to compile until you make the necessary adjustments.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.