diff --git a/Changelog.md b/Changelog.md index cb5060ea3..fe1f3eb2f 100644 --- a/Changelog.md +++ b/Changelog.md @@ -23,6 +23,7 @@ Breaking Changes: * Type System: Explicit conversions from literals to integer type is as strict as implicit conversions. * Type System: Support ``address(...).codehash`` to retrieve the codehash of an account. * Type System: Unary negation can only be used on signed integers, not on unsigned integers. + * View Pure Checker: Mark ``chainid`` as view. Language Features: * Super constructors can now be called using the member notation e.g. ``M.C(123)``. diff --git a/docs/080-breaking-changes.rst b/docs/080-breaking-changes.rst index af81f1c4b..53165a26e 100644 --- a/docs/080-breaking-changes.rst +++ b/docs/080-breaking-changes.rst @@ -91,6 +91,8 @@ New Restrictions * Remove support for the ``\b``, ``\f``, and ``\v`` escape sequences in code. They can still be inserted via hexadecimal escapes, e.g. ``\x08``, ``\x0c``, and ``\x0b``, respectively. +* The ``chainid`` builtin in inline assembly is now considered ``view`` instead of ``pure``. + Interface Changes ================= diff --git a/libevmasm/SemanticInformation.cpp b/libevmasm/SemanticInformation.cpp index 1826aac5f..a6f8d7a9f 100644 --- a/libevmasm/SemanticInformation.cpp +++ b/libevmasm/SemanticInformation.cpp @@ -365,6 +365,7 @@ bool SemanticInformation::invalidInPureFunctions(Instruction _instruction) case Instruction::ORIGIN: case Instruction::CALLER: case Instruction::CALLVALUE: + case Instruction::CHAINID: case Instruction::GAS: case Instruction::GASPRICE: case Instruction::EXTCODESIZE: diff --git a/test/libsolidity/syntaxTests/inlineAssembly/evm_istanbul.sol b/test/libsolidity/syntaxTests/inlineAssembly/evm_istanbul.sol index 5e6334749..f28f3ca0d 100644 --- a/test/libsolidity/syntaxTests/inlineAssembly/evm_istanbul.sol +++ b/test/libsolidity/syntaxTests/inlineAssembly/evm_istanbul.sol @@ -1,5 +1,5 @@ contract C { - function f() pure external returns (uint id) { + function f() view external returns (uint id) { assembly { id := chainid() } diff --git a/test/libsolidity/syntaxTests/viewPureChecker/assembly_chainid_not_pure.sol b/test/libsolidity/syntaxTests/viewPureChecker/assembly_chainid_not_pure.sol new file mode 100644 index 000000000..375fc7940 --- /dev/null +++ b/test/libsolidity/syntaxTests/viewPureChecker/assembly_chainid_not_pure.sol @@ -0,0 +1,9 @@ +contract C { + function f() public pure { + assembly { pop(chainid()) } + } +} +// ==== +// EVMVersion: >=istanbul +// ---- +// TypeError 2527: (67-76): Function declared as pure, but this expression (potentially) reads from the environment or state and thus requires "view". diff --git a/test/libsolidity/syntaxTests/viewPureChecker/assembly_istanbul.sol b/test/libsolidity/syntaxTests/viewPureChecker/assembly_istanbul.sol index 4cb626736..644975ed7 100644 --- a/test/libsolidity/syntaxTests/viewPureChecker/assembly_istanbul.sol +++ b/test/libsolidity/syntaxTests/viewPureChecker/assembly_istanbul.sol @@ -1,5 +1,5 @@ contract C { - function f() public pure { + function f() public view { assembly { pop(chainid()) } } }