From bfc8fd23ac41117bcfc9943cdf6f8f4695e5968d Mon Sep 17 00:00:00 2001 From: chriseth Date: Thu, 19 Sep 2019 11:00:43 +0200 Subject: [PATCH] Document chainid and selfbalance. --- docs/assembly.rst | 7 ++++++- docs/using-the-compiler.rst | 3 ++- test/libsolidity/InlineAssembly.cpp | 14 ++++++++++++++ .../syntaxTests/inlineAssembly/istanbul.sol | 15 +++++++++++++++ 4 files changed, 37 insertions(+), 2 deletions(-) create mode 100644 test/libsolidity/syntaxTests/inlineAssembly/istanbul.sol diff --git a/docs/assembly.rst b/docs/assembly.rst index 99279a3e8..119242aea 100644 --- a/docs/assembly.rst +++ b/docs/assembly.rst @@ -163,7 +163,8 @@ If an opcode takes arguments (always from the top of the stack), they are given Note that the order of arguments can be seen to be reversed in non-functional style (explained below). Opcodes marked with ``-`` do not push an item onto the stack (do not return a result), those marked with ``*`` are special and all others push exactly one item onto the stack (their "return value"). -Opcodes marked with ``F``, ``H``, ``B`` or ``C`` are present since Frontier, Homestead, Byzantium or Constantinople, respectively. +Opcodes marked with ``F``, ``H``, ``B``, ``C`` or ``I`` are present since Frontier, Homestead, +Byzantium, Constantinople or Istanbul, respectively. In the following, ``mem[a...b)`` signifies the bytes of memory starting at position ``a`` up to but not including position ``b`` and ``storage[p]`` signifies the storage contents at position ``p``. @@ -259,6 +260,8 @@ In the grammar, opcodes are represented as pre-defined identifiers. +-------------------------+-----+---+-----------------------------------------------------------------+ | balance(a) | | F | wei balance at address a | +-------------------------+-----+---+-----------------------------------------------------------------+ +| selfbalance() | | I | equivalent to balance(address()), but cheaper | ++-------------------------+-----+---+-----------------------------------------------------------------+ | caller | | F | call sender (excluding ``delegatecall``) | +-------------------------+-----+---+-----------------------------------------------------------------+ | callvalue | | F | wei sent together with the current call | @@ -325,6 +328,8 @@ In the grammar, opcodes are represented as pre-defined identifiers. | log4(p, s, t1, t2, t3, | `-` | F | log with topics t1, t2, t3, t4 and data mem[p...(p+s)) | | t4) | | | | +-------------------------+-----+---+-----------------------------------------------------------------+ +| chainid | | I | ID of the executing chain (EIP 1344) | ++-------------------------+-----+---+-----------------------------------------------------------------+ | origin | | F | transaction sender | +-------------------------+-----+---+-----------------------------------------------------------------+ | gasprice | | F | gas price of the transaction | diff --git a/docs/using-the-compiler.rst b/docs/using-the-compiler.rst index 5b2e9b8ca..12df74e84 100644 --- a/docs/using-the-compiler.rst +++ b/docs/using-the-compiler.rst @@ -122,7 +122,8 @@ at each version. Backward compatibility is not guaranteed between each version. - Shifting operators use shifting opcodes and thus need less gas. - ``petersburg`` (**default**) - The compiler behaves the same way as with constantinople. -- ``istanbul`` (**experimental**) +- ``istanbul`` + - Opcodes ``chainid`` and ``selfbalance`` are available in assembly. - ``berlin`` (**experimental**) diff --git a/test/libsolidity/InlineAssembly.cpp b/test/libsolidity/InlineAssembly.cpp index 39cc6fbf2..76985f54d 100644 --- a/test/libsolidity/InlineAssembly.cpp +++ b/test/libsolidity/InlineAssembly.cpp @@ -836,6 +836,20 @@ BOOST_AUTO_TEST_CASE(shift_constantinople_warning) CHECK_PARSE_WARNING("{ pop(sar(10, 32)) }", TypeError, "The \"sar\" instruction is only available for Constantinople-compatible VMs"); } +BOOST_AUTO_TEST_CASE(chainid_instanbul_warning) +{ + if (dev::test::Options::get().evmVersion().hasChainID()) + return; + CHECK_PARSE_WARNING("{ pop(chainid()) }", TypeError, "The \"chainid\" instruction is only available for Istanbul-compatible VMs"); +} + +BOOST_AUTO_TEST_CASE(selfbalance_instanbul_warning) +{ + if (dev::test::Options::get().evmVersion().hasSelfBalance()) + return; + CHECK_PARSE_WARNING("{ pop(selfbalance()) }", TypeError, "The \"selfbalance\" instruction is only available for Istanbul-compatible VMs"); +} + BOOST_AUTO_TEST_CASE(jump_warning) { CHECK_PARSE_WARNING("{ 1 jump }", Warning, "Jump instructions"); diff --git a/test/libsolidity/syntaxTests/inlineAssembly/istanbul.sol b/test/libsolidity/syntaxTests/inlineAssembly/istanbul.sol new file mode 100644 index 000000000..3e1a1cd2a --- /dev/null +++ b/test/libsolidity/syntaxTests/inlineAssembly/istanbul.sol @@ -0,0 +1,15 @@ +contract C { + function f() pure external { + assembly { + pop(chainid()) + } + } + function g() view external { + assembly { + pop(selfbalance()) + } + } +} +// ==== +// EVMVersion: >=istanbul +// ----