We again introduced several changes that are scheduled for version 0.5.0 and can be activated using pragma experimental "v0.5.0";. In this release, this pragma does not generate a warning anymore, so you can (and should) use it in production code.

In addition to that, you can now specify which EVM version the contract should be compiled for. Valid values are “homestead”, “tangerineWhistle”, “spuriousDragon”, “byzantium” (the default) and “constantinople”. Depending on this setting, different opcodes will be used in some cases. The only place where this is currently used by default is that all gas is forwarded with calls starting from “tangerineWhistle” (in homestead, some gas has to be retained for the call opcode itself). Also, the gas estimator reports different costs for the opcodes depending on the version and thus the optimizer might generate different code.

The new “0.5.0” features are explained in more detail below the list of features and bugfixes.

Features:

  • Code Generator: Assert that k != 0 for mulmod(a, b, k) and addmod(a, b, k) as experimental 0.5.0 feature.
  • Code Generator: Do not retain any gas in calls (except if EVM version is set to homestead).
  • Code Generator: Use STATICCALL opcode for calling view and pure functions as experimenal 0.5.0 feature.
  • General: C99/C++-style scoping rules (instead of JavaScript function scoping) take effect as experimental v0.5.0 feature.
  • General: Improved messaging when error spans multiple lines of a sourcefile
  • General: Support and recommend using emit EventName(); to call events explicitly.
  • Inline Assembly: Enforce strict mode as experimental 0.5.0 feature.
  • Interface: Provide ability to select target EVM version (homestead or byzantium, with byzantium being the default).
  • Standard JSON: Reject badly formatted invalid JSON inputs.
  • Type Checker: Disallow uninitialized storage pointers as experimental 0.5.0 feature.
  • Syntax Analyser: Do not warn about experimental features if they do not concern code generation.
  • Syntax Analyser: Do not warn about pragma experimental "v0.5.0" and do not set the experimental flag in the bytecode for this.
  • Syntax Checker: Mark throw as an error as experimental 0.5.0 feature.
  • Syntax Checker: Issue error if no visibility is specified on contract functions as experimental 0.5.0 feature.
  • Syntax Checker: Issue warning when using overloads of address on contract instances.
  • Type Checker: disallow combining hex numbers and unit denominations as experimental 0.5.0 feature.

Bugfixes:

  • Assembly: Raise error on oversized number literals in assembly.
  • JSON-AST: Add “documentation” property to function, event and modifier definition.
  • Resolver: Properly determine shadowing for imports with aliases.
  • Standalone Assembly: Do not ignore input after closing brace of top level block.
  • Standard JSON: Catch errors properly when invalid “sources” are passed.
  • Standard JSON: Ensure that library addresses supplied are of correct length and hex prefixed.
  • Type Checker: Properly detect which array and struct types are unsupported by the old ABI encoder.
  • Type Checker: Properly warn when using _offset and _slot for constants in inline assembly.
  • Commandline interface: throw error if option is unknown

Details:

  • Code Generator: Use STATICCALL opcode for calling view and pure functions as experimenal 0.5.0 feature.

This ensures that functions marked as view or pure (previously constant) cannot modify the state. This is especially important if you call unknown code via a generic interface and you cannot be sure whether the function modifies the state or not. This way, view and pure functions cannot have reentrancy effects.

  • General: C99/C++-style scoping rules (instead of JavaScript function scoping) take effect as experimental v0.5.0 feature.

Variables are no longer valid in the whole function and even before they were declared as in JavaScript, but instead only in the {/}-enclosed block where they are declared and only starting after their declaration. These are the rules also used by C++ or Java. There is a common exception where variables declared in the initializing part of the for header are also valid in the rest of the for loop construct which we also use in Solidity. Currently, the stack slot reserved for the variable still spans the whole function, but this is planned to be improved for the next release.

  • General: Support and recommend using emit EventName(); to call events explicitly.

In order to make events stand out with regards to regular function calls, emit EventName() as opposed to just EventName() should now be used to “call” events.

  • Inline Assembly: Enforce strict mode as experimental 0.5.0 feature.

Strict mode disallows labels, jumps and opcodes that directly modify the stack. It is much safer than non-strict mode, since you do not have to keep track of the current state of the stack. Furthermore, it allows an optimizer stage (to be finished soon) to be created much more easily. Because of that, the optimizer will refuse to work on non-strict assembly.

  • Type Checker: Disallow uninitialized storage pointers as experimental 0.5.0 feature.

Storage pointers (e.g. StructType storage x;) can lead to severe storage corruption if used without being assigned. In 0.5.0 it will be illegal to declare a storage pointer without directly initializing it.

  • Syntax Checker: Mark throw as an error as experimental 0.5.0 feature.

The throw keyword creates the impression that exceptions are a feature of Solidity, while in reality, it only supports state-reversion that can soon also include error data. Because of that, throw is deprecated.

  • Syntax Checker: Issue error if no visibility is specified on contract functions as experimental 0.5.0 feature.

Since there were bugs where people did not realize that the default visibility of functions is public, specifying a visibility was made mandatory.

  • Syntax Checker: Issue warning when using overloads of address on contract instances.

Collisions between native members of the address type and user-defined members of contracts can easily deceive users. Because of that, address members are no longer available in contracts. If you want to use an address member (transfer is one of them!), then convert it to address: address(contractInstance).transfer(2 wei).

  • Type Checker: disallow combining hex numbers and unit denominations as experimental 0.5.0 feature.

We could not think of any situation where unit denominations like seconds or ether combined with hexadecimal literals would be meaningful (0x1234 ether or 0x20 minutes) and thus deprecated this combination.

A big thank you to all contributors who helped make this release possible!

Download the new version of Solidity here.