2020-09-23 10:29:00 +00:00
***** ***** ***** ***** ***** ***** **
Solidity v0.8.0 Breaking Changes
***** ***** ***** ***** ***** ***** **
This section highlights the main breaking changes introduced in Solidity
2020-10-26 15:58:27 +00:00
version 0.8.0.
2020-09-23 10:29:00 +00:00
For the full list check
`the release changelog <https://github.com/ethereum/solidity/releases/tag/v0.8.0> `_ .
2020-10-26 15:58:27 +00:00
Silent Changes of the Semantics
===============================
2020-09-23 10:29:00 +00:00
2020-10-26 15:58:27 +00:00
This section lists changes where existing code changes its behaviour without
the compiler notifying you about it.
* Arithmetic operations revert on underflow and overflow. You can use `` unchecked { ... } `` to use
the previous wrapping behaviour.
Checks for overflow are very common, so we made them the default to increase readability of code,
even if it comes at a slight increase of gas costs.
2020-09-23 10:29:00 +00:00
2020-10-13 11:20:32 +00:00
* Exponentiation is right associative, i.e., the expression `` a**b**c `` is parsed as `` a**(b**c) `` .
Before 0.8.0, it was parsed as `` (a**b)**c `` .
2020-10-21 16:57:10 +00:00
2020-10-26 15:58:27 +00:00
This is the common way to parse the exponentiation operator.
* Failing assertions and other internal checks like division by zero or arithmetic overflow do
not use the invalid opcode but instead the revert opcode.
More specifically, they will use error data equal to a function call to `` Panic(uint256) `` with an error code specific
to the circumstances.
2020-10-15 15:56:20 +00:00
2020-10-26 15:58:27 +00:00
This will save gas on errors while it still allows static analysis tools to distinguish
these situations from a revert on invalid input, like a failing `` require `` .
2020-10-15 15:56:20 +00:00
2020-11-10 10:09:54 +00:00
* If a byte array in storage is accessed whose length is encoded incorrectly, a panic is caused.
A contract cannot get into this situation unless inline assembly is used to modify the raw representation of storage byte arrays.
2020-10-26 15:58:27 +00:00
New Restrictions
================
2020-10-15 15:56:20 +00:00
2020-11-06 16:39:44 +00:00
* There are new restrictions related to explicit conversion of literals. The previous behaviour in
the following cases was likely ambiguous:
1. Explicit conversions from negative literals and literals larger than `` type(uint160).max `` to
`` address `` are disallowed.
2. Explicit conversions between literals and an integer type `` T `` are only allowed if the literal
lies between `` type(T).min `` and `` type(T).max `` . In particular, replace usages of `` uint(-1) ``
with `` type(uint).max `` .
3. Explicit conversions between literals and enums are only allowed if the literal can
represent a value in the enum.
2020-10-21 16:57:10 +00:00
2020-11-10 13:14:43 +00:00
* There are new restrictions on explicit type conversions. The conversion is only allowed when there
is at most one change in sign, width or type-category (`` int `` , `` address `` , `` bytesNN `` , etc.)
Let us use the notation `` T(S) `` to denote the explicit conversion `` T(x) `` , where, `` T `` and
`` S `` are types, and `` x `` is any arbitrary variable of type `` S `` . An example of such a
disallowed conversion would be `` uint16(int8) `` since it changes both width (8 bits to 16 bits)
and sign (signed integer to unsigned integer). In order to do the conversion, one has to go
through an intermediate type. In the previous example, this would be `` uint16(uint8(int8)) `` or
`` uint16(int16(int8)) `` . Note that the two ways to convert will produce different results e.g.,
for `` -1 `` . The following are some examples of conversions that are disallowed by this rule.
- `` address(uint) `` and `` uint(address) `` : converting both type-category and width. Replace this by
2020-11-09 09:12:38 +00:00
`` address(uint160(uint)) `` and `` uint(uint160(address)) `` respectively.
2020-11-10 13:14:43 +00:00
- `` int80(bytes10) `` and `` bytes10(int80) `` : converting both type-category and sign. Replace this by
2020-11-09 09:12:38 +00:00
`` int80(uint80(bytes10)) `` and `` bytes10(uint80(int80) `` respectively.
2020-11-10 13:14:43 +00:00
- `` Contract(uint) `` : converting both type-category and width. Replace this by
2020-11-09 09:12:38 +00:00
`` Contract(address(uint160(uint))) `` .
2020-11-10 13:14:43 +00:00
These conversions were disallowed to avoid ambiguity. For example, in the expression `` uint16 x =
uint16(int8(-1))`` , the value of ` ` x `` would depend on whether the sign or the width conversion
was applied first.
2020-11-09 09:12:38 +00:00
2020-11-02 13:10:37 +00:00
* Function call options can only be given once, i.e. `` c.f{gas: 10000}{value: 1}() `` is invalid and has to be changed to `` c.f{gas: 10000, value: 1}() `` .
2020-10-21 16:57:10 +00:00
* The global functions `` log0 `` , `` log1 `` , `` log2 `` , `` log3 `` and `` log4 `` have been removed.
2020-10-26 10:01:18 +00:00
These are low-level functions that were largely unused. Their behaviour can be accessed from inline assembly.
2020-11-10 10:41:38 +00:00
* `` enum `` definitions cannot contain more than 256 members.
This will make it safe to assume that the underlying type in the ABI is always `` uint8 `` .
2020-11-13 13:51:38 +00:00
* Declarations with the name `` this `` , `` super `` and `` _ `` are disallowed, with the exception of
public functions and events.
2020-11-26 10:43:35 +00:00
Interface Changes
=================
* Changed output of `` --combined-json `` . JSON fields `` abi `` , `` devdoc `` , `` userdoc `` and `` storage-layout `` are sub-objects now. Before 0.8.0 they used to be serialised as strings.