From 588535566fe011f61e6b55574fade746b1f952df Mon Sep 17 00:00:00 2001 From: Daniel Kirchner Date: Wed, 9 Dec 2020 16:00:02 +0100 Subject: [PATCH] Mark chainid as view. --- Changelog.md | 1 + docs/080-breaking-changes.rst | 2 ++ libevmasm/SemanticInformation.cpp | 1 + .../syntaxTests/inlineAssembly/evm_istanbul.sol | 2 +- .../viewPureChecker/assembly_chainid_not_pure.sol | 9 +++++++++ .../syntaxTests/viewPureChecker/assembly_istanbul.sol | 2 +- 6 files changed, 15 insertions(+), 2 deletions(-) create mode 100644 test/libsolidity/syntaxTests/viewPureChecker/assembly_chainid_not_pure.sol diff --git a/Changelog.md b/Changelog.md index 296c49570..866400455 100644 --- a/Changelog.md +++ b/Changelog.md @@ -22,6 +22,7 @@ Breaking Changes: * Type System: Explicit conversions from literals to enums are only allowed if the value fits in the enum. * Type System: Explicit conversions from literals to integer type is as strict as implicit conversions. * 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()) } } }