From fc10fc30730b94bbefb4fe9560ca335daa518562 Mon Sep 17 00:00:00 2001 From: Alex Beregszaszi Date: Wed, 20 Nov 2019 19:32:52 +0000 Subject: [PATCH 1/4] Move InvalidDeposit/InvalidOpcode from Instructions.h to Exceptions.h --- libevmasm/Exceptions.h | 3 +++ libevmasm/Instruction.h | 3 --- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/libevmasm/Exceptions.h b/libevmasm/Exceptions.h index 06b0ac788..d6557d399 100644 --- a/libevmasm/Exceptions.h +++ b/libevmasm/Exceptions.h @@ -33,5 +33,8 @@ struct OptimizerException: virtual AssemblyException {}; struct StackTooDeepException: virtual OptimizerException {}; struct ItemNotAvailableException: virtual OptimizerException {}; +DEV_SIMPLE_EXCEPTION(InvalidDeposit); +DEV_SIMPLE_EXCEPTION(InvalidOpcode); + } } diff --git a/libevmasm/Instruction.h b/libevmasm/Instruction.h index f2f5879d9..c93fbf158 100644 --- a/libevmasm/Instruction.h +++ b/libevmasm/Instruction.h @@ -31,9 +31,6 @@ namespace dev namespace eth { -DEV_SIMPLE_EXCEPTION(InvalidDeposit); -DEV_SIMPLE_EXCEPTION(InvalidOpcode); - /// Virtual machine bytecode instruction. enum class Instruction: uint8_t { From dc351ae5fadbeea96aef0ca1e8ee0d572460e9d1 Mon Sep 17 00:00:00 2001 From: Alex Beregszaszi Date: Wed, 20 Nov 2019 21:35:25 +0000 Subject: [PATCH 2/4] Simplify the BadHexChar exception Use comment and remove the invalidSymbol tag. Also use asserts. --- libdevcore/CommonData.cpp | 6 +++--- libdevcore/Exceptions.h | 1 - 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/libdevcore/CommonData.cpp b/libdevcore/CommonData.cpp index ebdc81a38..eef798fb0 100644 --- a/libdevcore/CommonData.cpp +++ b/libdevcore/CommonData.cpp @@ -86,7 +86,7 @@ int dev::fromHex(char _i, WhenError _throw) if (_i >= 'A' && _i <= 'F') return _i - 'A' + 10; if (_throw == WhenError::Throw) - BOOST_THROW_EXCEPTION(BadHexCharacter() << errinfo_invalidSymbol(_i)); + assertThrow(false, BadHexCharacter, to_string(_i)); else return -1; } @@ -103,7 +103,7 @@ bytes dev::fromHex(std::string const& _s, WhenError _throw) if (h != -1) ret.push_back(h); else if (_throw == WhenError::Throw) - BOOST_THROW_EXCEPTION(BadHexCharacter()); + assertThrow(false, BadHexCharacter, ""); else return bytes(); } @@ -114,7 +114,7 @@ bytes dev::fromHex(std::string const& _s, WhenError _throw) if (h != -1 && l != -1) ret.push_back((uint8_t)(h * 16 + l)); else if (_throw == WhenError::Throw) - BOOST_THROW_EXCEPTION(BadHexCharacter()); + assertThrow(false, BadHexCharacter, ""); else return bytes(); } diff --git a/libdevcore/Exceptions.h b/libdevcore/Exceptions.h index a0ab7c6b5..df7a9ba01 100644 --- a/libdevcore/Exceptions.h +++ b/libdevcore/Exceptions.h @@ -51,7 +51,6 @@ DEV_SIMPLE_EXCEPTION(FileError); DEV_SIMPLE_EXCEPTION(DataTooLong); // error information to be added to exceptions -using errinfo_invalidSymbol = boost::error_info; using errinfo_comment = boost::error_info; } From e2627e2232023a1d3e5d39db90792abae196f4eb Mon Sep 17 00:00:00 2001 From: Alex Beregszaszi Date: Fri, 22 Nov 2019 16:59:06 +0000 Subject: [PATCH 3/4] Simplify fromHex by passing the throw flag around --- libdevcore/CommonData.cpp | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/libdevcore/CommonData.cpp b/libdevcore/CommonData.cpp index eef798fb0..8e077261c 100644 --- a/libdevcore/CommonData.cpp +++ b/libdevcore/CommonData.cpp @@ -99,22 +99,18 @@ bytes dev::fromHex(std::string const& _s, WhenError _throw) if (_s.size() % 2) { - int h = fromHex(_s[s++], WhenError::DontThrow); + int h = fromHex(_s[s++], _throw); if (h != -1) ret.push_back(h); - else if (_throw == WhenError::Throw) - assertThrow(false, BadHexCharacter, ""); else return bytes(); } for (unsigned i = s; i < _s.size(); i += 2) { - int h = fromHex(_s[i], WhenError::DontThrow); - int l = fromHex(_s[i + 1], WhenError::DontThrow); + int h = fromHex(_s[i], _throw); + int l = fromHex(_s[i + 1], _throw); if (h != -1 && l != -1) ret.push_back((uint8_t)(h * 16 + l)); - else if (_throw == WhenError::Throw) - assertThrow(false, BadHexCharacter, ""); else return bytes(); } From 991fbd2956074b89ad2abdc093f31ca30991b893 Mon Sep 17 00:00:00 2001 From: Alex Beregszaszi Date: Fri, 22 Nov 2019 17:02:12 +0000 Subject: [PATCH 4/4] Replace uses of BOOST_THROW_EXCEPTION with assertThrow Where appropriate. --- libdevcore/IpfsHash.cpp | 7 ++----- libevmasm/Assembly.cpp | 4 ++-- libevmasm/AssemblyItem.cpp | 6 +++--- libevmasm/CommonSubexpressionEliminator.cpp | 18 +++++++----------- libyul/backends/evm/AsmCodeGen.cpp | 10 +++++----- 5 files changed, 19 insertions(+), 26 deletions(-) diff --git a/libdevcore/IpfsHash.cpp b/libdevcore/IpfsHash.cpp index add459a2c..22ad7100c 100644 --- a/libdevcore/IpfsHash.cpp +++ b/libdevcore/IpfsHash.cpp @@ -17,6 +17,7 @@ #include +#include #include #include #include @@ -55,11 +56,7 @@ string base58Encode(bytes const& _data) bytes dev::ipfsHash(string _data) { - if (_data.length() >= 1024 * 256) - BOOST_THROW_EXCEPTION( - DataTooLong() << - errinfo_comment("Ipfs hash for large (chunked) files not yet implemented.") - ); + assertThrow(_data.length() < 1024 * 256, DataTooLong, "IPFS hash for large (chunked) files not yet implemented."); bytes lengthAsVarint = varintEncoding(_data.size()); diff --git a/libevmasm/Assembly.cpp b/libevmasm/Assembly.cpp index 88bddd7f7..079567193 100644 --- a/libevmasm/Assembly.cpp +++ b/libevmasm/Assembly.cpp @@ -323,7 +323,7 @@ Json::Value Assembly::assemblyJSON(StringMap const& _sourceCodes) const collection.append(createJsonValue("PUSH data", i.location().start, i.location().end, toStringInHex(i.data()))); break; default: - BOOST_THROW_EXCEPTION(InvalidOpcode()); + assertThrow(false, InvalidOpcode, ""); } } @@ -641,7 +641,7 @@ LinkerObject const& Assembly::assemble() const ret.bytecode.push_back((uint8_t)Instruction::JUMPDEST); break; default: - BOOST_THROW_EXCEPTION(InvalidOpcode()); + assertThrow(false, InvalidOpcode, "Unexpected opcode while assembling."); } } diff --git a/libevmasm/AssemblyItem.cpp b/libevmasm/AssemblyItem.cpp index 61355530e..53d4b79a0 100644 --- a/libevmasm/AssemblyItem.cpp +++ b/libevmasm/AssemblyItem.cpp @@ -81,7 +81,7 @@ unsigned AssemblyItem::bytesRequired(unsigned _addressLength) const default: break; } - BOOST_THROW_EXCEPTION(InvalidOpcode()); + assertThrow(false, InvalidOpcode, ""); } int AssemblyItem::arguments() const @@ -212,7 +212,7 @@ string AssemblyItem::toAssemblyText() const assertThrow(false, AssemblyException, "Invalid assembly item."); break; default: - BOOST_THROW_EXCEPTION(InvalidOpcode()); + assertThrow(false, InvalidOpcode, ""); } if (m_jumpType == JumpType::IntoFunction || m_jumpType == JumpType::OutOfFunction) { @@ -277,7 +277,7 @@ ostream& dev::eth::operator<<(ostream& _out, AssemblyItem const& _item) _out << " ???"; break; default: - BOOST_THROW_EXCEPTION(InvalidOpcode()); + assertThrow(false, InvalidOpcode, ""); } return _out; } diff --git a/libevmasm/CommonSubexpressionEliminator.cpp b/libevmasm/CommonSubexpressionEliminator.cpp index 949d2c75a..c8e2f9210 100644 --- a/libevmasm/CommonSubexpressionEliminator.cpp +++ b/libevmasm/CommonSubexpressionEliminator.cpp @@ -158,11 +158,10 @@ AssemblyItems CSECodeGenerator::generateCode( for (auto id: {p.first, p.second}) if (unsigned seqNr = m_expressionClasses.representative(id).sequenceNumber) { - if (seqNr < _initialSequenceNumber) - // Invalid sequenced operation. - // @todo quick fix for now. Proper fix needs to choose representative with higher - // sequence number during dependency analysis. - BOOST_THROW_EXCEPTION(StackTooDeepException()); + // Invalid sequenced operation. + // @todo quick fix for now. Proper fix needs to choose representative with higher + // sequence number during dependency analysis. + assertThrow(seqNr >= _initialSequenceNumber, StackTooDeepException, ""); sequencedExpressions.insert(make_pair(seqNr, id)); } @@ -222,12 +221,9 @@ void CSECodeGenerator::addDependencies(Id _c) return; // we already computed the dependencies for _c ExpressionClasses::Expression expr = m_expressionClasses.representative(_c); assertThrow(expr.item, OptimizerException, ""); - if (expr.item->type() == UndefinedItem) - BOOST_THROW_EXCEPTION( - // If this exception happens, we need to find a different way to generate the - // compound expression. - ItemNotAvailableException() << errinfo_comment("Undefined item requested but not available.") - ); + // If this exception happens, we need to find a different way to generate the + // compound expression. + assertThrow(expr.item->type() != UndefinedItem, ItemNotAvailableException, "Undefined item requested but not available."); for (Id argument: expr.arguments) { addDependencies(argument); diff --git a/libyul/backends/evm/AsmCodeGen.cpp b/libyul/backends/evm/AsmCodeGen.cpp index 999d215a3..ca0aeb86a 100644 --- a/libyul/backends/evm/AsmCodeGen.cpp +++ b/libyul/backends/evm/AsmCodeGen.cpp @@ -207,11 +207,11 @@ void CodeGenerator::assemble( } catch (StackTooDeepError const& _e) { - BOOST_THROW_EXCEPTION( - InternalCompilerError() << errinfo_comment( - "Stack too deep when compiling inline assembly" + - (_e.comment() ? ": " + *_e.comment() : ".") - )); + solAssert( + false, + "Stack too deep when compiling inline assembly" + + (_e.comment() ? ": " + *_e.comment() : ".") + ); } solAssert(transform.stackErrors().empty(), "Stack errors present but not thrown."); }