From 965dc7201626ceb9f5406ca84189a478cd8a55bd Mon Sep 17 00:00:00 2001 From: Alex Beregszaszi Date: Fri, 27 Jan 2017 13:24:05 +0000 Subject: [PATCH 1/3] Mention in changelog that invalid as an opcode is valid inline assembly --- Changelog.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Changelog.md b/Changelog.md index 8dd1b89c7..7a9d48180 100644 --- a/Changelog.md +++ b/Changelog.md @@ -4,13 +4,14 @@ Features: * Compiler interface: Contracts and libraries can be referenced with a ``file:`` prefix to make them unique. * Compiler interface: Report source location for "stack too deep" errors. * AST: Use deterministic node identifiers. + * Inline assembly: introduce ``invalid`` (EIP141) as an opcode. * Type system: Introduce type identifier strings. * Type checker: Warn about invalid checksum for addresses and deduce type from valid ones. * Metadata: Do not include platform in the version number. * Metadata: Add option to store sources as literal content. * Code generator: Extract array utils into low-level functions. * Code generator: Internal errors (array out of bounds, etc.) now cause a reversion by using an invalid - instruction (0xfe) instead of an invalid jump. Invalid jump is still kept for explicit throws. + instruction (0xfe - EIP141) instead of an invalid jump. Invalid jump is still kept for explicit throws. Bugfixes: * Code generator: Allow recursive structs. From bfa3b4ca78fd1afe0756631ce0d1ccb9a6d9c467 Mon Sep 17 00:00:00 2001 From: Alex Beregszaszi Date: Fri, 27 Jan 2017 13:26:40 +0000 Subject: [PATCH 2/3] Mention invalid in docs --- docs/control-structures.rst | 2 ++ 1 file changed, 2 insertions(+) diff --git a/docs/control-structures.rst b/docs/control-structures.rst index ff9b245a9..c83d654e7 100644 --- a/docs/control-structures.rst +++ b/docs/control-structures.rst @@ -632,6 +632,8 @@ The opcodes ``pushi`` and ``jumpdest`` cannot be used directly. +-------------------------+------+-----------------------------------------------------------------+ | selfdestruct(a) | `-` | end execution, destroy current contract and send funds to a | +-------------------------+------+-----------------------------------------------------------------+ +| invalid | `-` | end execution with invalid instruction | ++-------------------------+------+-----------------------------------------------------------------+ | log0(p, s) | `-` | log without topics and data mem[p..(p+s)) | +-------------------------+------+-----------------------------------------------------------------+ | log1(p, s, t1) | `-` | log with topic t1 and data mem[p..(p+s)) | From eb530aa217387092a84057b550c7665a4acf72b6 Mon Sep 17 00:00:00 2001 From: Alex Beregszaszi Date: Fri, 27 Jan 2017 21:24:58 +0000 Subject: [PATCH 3/3] Add tests for invalid instruction --- test/libsolidity/InlineAssembly.cpp | 5 +++++ test/libsolidity/SolidityEndToEndTest.cpp | 15 +++++++++++++++ 2 files changed, 20 insertions(+) diff --git a/test/libsolidity/InlineAssembly.cpp b/test/libsolidity/InlineAssembly.cpp index c051a9822..cf0343a92 100644 --- a/test/libsolidity/InlineAssembly.cpp +++ b/test/libsolidity/InlineAssembly.cpp @@ -182,6 +182,11 @@ BOOST_AUTO_TEST_CASE(error_tag) BOOST_CHECK(successAssemble("{ invalidJumpLabel }")); } +BOOST_AUTO_TEST_CASE(designated_invalid_instruction) +{ + BOOST_CHECK(successAssemble("{ invalid }")); +} + BOOST_AUTO_TEST_CASE(inline_assembly_shadowed_instruction_declaration) { // Error message: "Cannot use instruction names for identifier names." diff --git a/test/libsolidity/SolidityEndToEndTest.cpp b/test/libsolidity/SolidityEndToEndTest.cpp index 646017fbf..4075a0160 100644 --- a/test/libsolidity/SolidityEndToEndTest.cpp +++ b/test/libsolidity/SolidityEndToEndTest.cpp @@ -9043,6 +9043,21 @@ BOOST_AUTO_TEST_CASE(recursive_structs) BOOST_CHECK(callContractFunction("f()") == encodeArgs(u256(1))); } +BOOST_AUTO_TEST_CASE(invalid_instruction) +{ + char const* sourceCode = R"( + contract C { + function f() { + assembly { + invalid + } + } + } + )"; + compileAndRun(sourceCode, 0, "C"); + BOOST_CHECK(callContractFunction("f()") == encodeArgs()); +} + BOOST_AUTO_TEST_SUITE_END() }