Commit 44c61afc authored by Adrien Béraud's avatar Adrien Béraud Committed by Guillaume Roguez

eth: bump sources, remove dependency to boost, cryptopp

Update "eth" to latest version from
https://github.com/ethereum/cpp-ethereum

This new version makes use of secp256k1 instead of custom
code and cryptopp to handle EC generation, and reduces its dependency
to boost to use more of the C++11 STL.

This allows to trim the code to completely remove the boost and
cryptopp dependencies.

Change-Id: I19118d3b833a9425cddbeabf6d0b6e07d5a4b15e
parent dc7891c4
#pragma comment(lib, "secp256k1.lib")
/* Define to one of `_getb67', `GETB67', `getb67' for Cray-2 and Cray-YMP
systems. This function is required for `alloca.c' support on those systems.
*/
......
......@@ -150,6 +150,7 @@
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<OutDir>$(SolutionDir)$(Platform)\$(Configuration)\bin\</OutDir>
<TargetName>dring</TargetName>
<LinkIncremental>true</LinkIncremental>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='ReleaseLib|x64'">
<TargetExt>.lib</TargetExt>
......@@ -395,11 +396,12 @@
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
<AdditionalLibraryDirectories>..\contrib\lib\x64;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
<AdditionalDependencies>ws2_32.lib;iphlpapi.lib;kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;odbc32.lib;odbccp32.lib;Strmiids.lib;libavcodec.lib;libavdevice.lib;libavfilter.lib;libavformat.lib;libavutil.lib;libswresample.lib;libswscale.lib;libsamplerate.lib;libsndfile.lib;libgnutls.lib;lib_json.lib;opendht.lib;Argon2Ref.lib;pcre.lib;pjlib.lib;pjlib_util.lib;pjmedia.lib;pjmedia_codec.lib;pjnath.lib;pjsip_core.lib;pjsip_simple.lib;pjsip_ua.lib;pjsua2_lib.lib;pjsua_lib.lib;yaml-cpp.lib;libupnp.lib;pthreadVC2.lib;portaudio.lib;libspeex-pj.lib;%(AdditionalDependencies)</AdditionalDependencies>
<AdditionalDependencies>ws2_32.lib;iphlpapi.lib;kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;odbc32.lib;odbccp32.lib;Strmiids.lib;libavcodec.lib;libavdevice.lib;libavfilter.lib;libavformat.lib;libavutil.lib;libswresample.lib;libswscale.lib;libsamplerate.lib;libsndfile.lib;libgnutls.lib;lib_json.lib;opendht.lib;Argon2Ref.lib;pcre.lib;pjlib.lib;pjlib_util.lib;pjmedia.lib;pjmedia_codec.lib;pjnath.lib;pjsip_core.lib;pjsip_simple.lib;pjsip_ua.lib;pjsua2_lib.lib;pjsua_lib.lib;yaml-cpp.lib;libupnp.lib;pthreadVC2.lib;portaudio.lib;libspeex-pj.lib;secp256k1.lib;%(AdditionalDependencies)</AdditionalDependencies>
<AdditionalOptions>/VERBOSE:LIB /NODEFAULTLIB:libcmtd /NODEFAULTLIB:libcmt /OPT:NOLBR /OPT:NOICF /ignore:4006 %(AdditionalOptions)</AdditionalOptions>
<TargetMachine>MachineX64</TargetMachine>
<LinkTimeCodeGeneration>UseFastLinkTimeCodeGeneration</LinkTimeCodeGeneration>
<ForceFileOutput>MultiplyDefinedSymbolOnly</ForceFileOutput>
<LinkStatus>false</LinkStatus>
</Link>
<ProjectReference>
<UseLibraryDependencyInputs>false</UseLibraryDependencyInputs>
......@@ -544,22 +546,13 @@
<ClInclude Include="..\src\registration_states.h" />
<ClInclude Include="..\src\ringdht\accountarchive.h" />
<ClInclude Include="..\src\ringdht\configkeys.h" />
<ClInclude Include="..\src\ringdht\eth\libdevcore\boost_multiprecision_number_compare_bug_workaround.hpp" />
<ClInclude Include="..\src\ringdht\eth\libdevcore\Address.h" />
<ClInclude Include="..\src\ringdht\eth\libdevcore\Common.h" />
<ClInclude Include="..\src\ringdht\eth\libdevcore\CommonData.h" />
<ClInclude Include="..\src\ringdht\eth\libdevcore\Exceptions.h" />
<ClInclude Include="..\src\ringdht\eth\libdevcore\FixedHash.h" />
<ClInclude Include="..\src\ringdht\eth\libdevcore\Guards.h" />
<ClInclude Include="..\src\ringdht\eth\libdevcore\Hash.h" />
<ClInclude Include="..\src\ringdht\eth\libdevcore\picosha2.h" />
<ClInclude Include="..\src\ringdht\eth\libdevcore\RLP.h" />
<ClInclude Include="..\src\ringdht\eth\libdevcore\SHA3.h" />
<ClInclude Include="..\src\ringdht\eth\libdevcore\vector_ref.h" />
<ClInclude Include="..\src\ringdht\eth\libdevcrypto\AES.h" />
<ClInclude Include="..\src\ringdht\eth\libdevcrypto\Common.h" />
<ClInclude Include="..\src\ringdht\eth\libdevcrypto\CryptoPP.h" />
<ClInclude Include="..\src\ringdht\eth\libdevcrypto\ECDHE.h" />
<ClInclude Include="..\src\ringdht\eth\libdevcrypto\Exceptions.h" />
<ClInclude Include="..\src\ringdht\namedirectory.h" />
<ClInclude Include="..\src\ringdht\ringaccount.h" />
<ClInclude Include="..\src\ringdht\ringcontact.h" />
......@@ -672,14 +665,8 @@
<ClCompile Include="..\src\ringdht\eth\libdevcore\Common.cpp" />
<ClCompile Include="..\src\ringdht\eth\libdevcore\CommonData.cpp" />
<ClCompile Include="..\src\ringdht\eth\libdevcore\FixedHash.cpp" />
<ClCompile Include="..\src\ringdht\eth\libdevcore\Guards.cpp" />
<ClCompile Include="..\src\ringdht\eth\libdevcore\Hash.cpp" />
<ClCompile Include="..\src\ringdht\eth\libdevcore\RLP.cpp" />
<ClCompile Include="..\src\ringdht\eth\libdevcore\SHA3.cpp" />
<ClCompile Include="..\src\ringdht\eth\libdevcrypto\AES.cpp" />
<ClCompile Include="..\src\ringdht\eth\libdevcrypto\Common.cpp" />
<ClCompile Include="..\src\ringdht\eth\libdevcrypto\CryptoPP.cpp" />
<ClCompile Include="..\src\ringdht\eth\libdevcrypto\ECDHE.cpp" />
<ClCompile Include="..\src\ringdht\namedirectory.cpp" />
<ClCompile Include="..\src\ringdht\ringaccount.cpp" />
<ClCompile Include="..\src\ringdht\sips_transport_ice.cpp" />
......
......@@ -442,54 +442,24 @@
<ClInclude Include="unistd.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="..\src\ringdht\eth\libdevcrypto\AES.h">
<Filter>Header Files\ringdht\eth\libdevcrypto</Filter>
</ClInclude>
<ClInclude Include="..\src\ringdht\eth\libdevcrypto\Common.h">
<Filter>Header Files\ringdht\eth\libdevcrypto</Filter>
</ClInclude>
<ClInclude Include="..\src\ringdht\eth\libdevcrypto\CryptoPP.h">
<Filter>Header Files\ringdht\eth\libdevcrypto</Filter>
</ClInclude>
<ClInclude Include="..\src\ringdht\eth\libdevcrypto\ECDHE.h">
<Filter>Header Files\ringdht\eth\libdevcrypto</Filter>
</ClInclude>
<ClInclude Include="..\src\ringdht\eth\libdevcrypto\Exceptions.h">
<Filter>Header Files\ringdht\eth\libdevcrypto</Filter>
</ClInclude>
<ClInclude Include="..\src\ringdht\eth\libdevcore\Common.h">
<Filter>Header Files\ringdht\eth\libdevcore</Filter>
</ClInclude>
<ClInclude Include="..\src\ringdht\eth\libdevcore\CommonData.h">
<Filter>Header Files\ringdht\eth\libdevcore</Filter>
</ClInclude>
<ClInclude Include="..\src\ringdht\eth\libdevcore\Exceptions.h">
<Filter>Header Files\ringdht\eth\libdevcore</Filter>
</ClInclude>
<ClInclude Include="..\src\ringdht\eth\libdevcore\FixedHash.h">
<Filter>Header Files\ringdht\eth\libdevcore</Filter>
</ClInclude>
<ClInclude Include="..\src\ringdht\eth\libdevcore\Guards.h">
<Filter>Header Files\ringdht\eth\libdevcore</Filter>
</ClInclude>
<ClInclude Include="..\src\ringdht\eth\libdevcore\Hash.h">
<Filter>Header Files\ringdht\eth\libdevcore</Filter>
</ClInclude>
<ClInclude Include="..\src\ringdht\eth\libdevcore\picosha2.h">
<Filter>Header Files\ringdht\eth\libdevcore</Filter>
</ClInclude>
<ClInclude Include="..\src\ringdht\eth\libdevcore\RLP.h">
<Filter>Header Files\ringdht\eth\libdevcore</Filter>
</ClInclude>
<ClInclude Include="..\src\ringdht\eth\libdevcore\SHA3.h">
<Filter>Header Files\ringdht\eth\libdevcore</Filter>
</ClInclude>
<ClInclude Include="..\src\ringdht\eth\libdevcore\vector_ref.h">
<Filter>Header Files\ringdht\eth\libdevcore</Filter>
</ClInclude>
<ClInclude Include="..\src\ringdht\eth\libdevcore\boost_multiprecision_number_compare_bug_workaround.hpp">
<Filter>Header Files\ringdht\eth\libdevcore</Filter>
</ClInclude>
<ClInclude Include="..\src\thread_pool.h">
<Filter>Header Files</Filter>
</ClInclude>
......@@ -526,6 +496,9 @@
<ClInclude Include="..\src\ringdht\ringcontact.h">
<Filter>Header Files\ringdht</Filter>
</ClInclude>
<ClInclude Include="..\src\ringdht\eth\libdevcore\Address.h">
<Filter>Header Files\ringdht\eth\libdevcore</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<ClCompile Include="..\src\preferences.cpp">
......@@ -804,30 +777,9 @@
<ClCompile Include="..\src\ringdht\eth\libdevcore\FixedHash.cpp">
<Filter>Source Files\ringdht\eth\libdevcore</Filter>
</ClCompile>
<ClCompile Include="..\src\ringdht\eth\libdevcore\Guards.cpp">
<Filter>Source Files\ringdht\eth\libdevcore</Filter>
</ClCompile>
<ClCompile Include="..\src\ringdht\eth\libdevcore\Hash.cpp">
<Filter>Source Files\ringdht\eth\libdevcore</Filter>
</ClCompile>
<ClCompile Include="..\src\ringdht\eth\libdevcore\RLP.cpp">
<Filter>Source Files\ringdht\eth\libdevcore</Filter>
</ClCompile>
<ClCompile Include="..\src\ringdht\eth\libdevcore\SHA3.cpp">
<Filter>Source Files\ringdht\eth\libdevcore</Filter>
</ClCompile>
<ClCompile Include="..\src\ringdht\eth\libdevcrypto\AES.cpp">
<Filter>Source Files\ringdht\eth\libdevcrypto</Filter>
</ClCompile>
<ClCompile Include="..\src\ringdht\eth\libdevcrypto\Common.cpp">
<Filter>Source Files\ringdht\eth\libdevcrypto</Filter>
</ClCompile>
<ClCompile Include="..\src\ringdht\eth\libdevcrypto\CryptoPP.cpp">
<Filter>Source Files\ringdht\eth\libdevcrypto</Filter>
</ClCompile>
<ClCompile Include="..\src\ringdht\eth\libdevcrypto\ECDHE.cpp">
<Filter>Source Files\ringdht\eth\libdevcrypto</Filter>
</ClCompile>
<ClCompile Include="..\src\thread_pool.cpp">
<Filter>Source Files</Filter>
</ClCompile>
......@@ -846,5 +798,8 @@
<ClCompile Include="..\src\ringdht\accountarchive.cpp">
<Filter>Source Files\ringdht</Filter>
</ClCompile>
<ClCompile Include="..\src\ringdht\eth\libdevcore\SHA3.cpp">
<Filter>Source Files\ringdht\eth\libdevcore</Filter>
</ClCompile>
</ItemGroup>
</Project>
\ No newline at end of file
......@@ -607,17 +607,7 @@ PKG_CHECK_MODULES([OPENDHT], [opendht >= 0.6.1],, AC_MSG_WARN([Missing OpenDHT])
dnl check for argon2
PKG_CHECK_MODULES([ARGON2], [libargon2],, AC_MSG_FAILURE([Missing Argon2]))
AC_CHECK_HEADER([cryptopp/cryptlib.h], , AC_MSG_FAILURE([Unable to find the cryptopp headers (you may need to install the dev package).]))
LDFLAGS+=" -lcryptopp"
AS_IF([test "${SYS}" = "mingw32"],[
LDFLAGS+=" -lboost_random -lboost_system"
CPPFLAGS+=" -DBOOST_SYSTEM_NO_DEPRECATED"
], [
AX_BOOST_BASE([1.48],,[AC_MSG_ERROR([Ring needs Boost but it was not found in your system])])
AC_CHECK_LIB([boost_system], exit, , [AC_MSG_FAILURE(['Can't find boost system'])])
AC_CHECK_LIB([boost_random], exit, , [AC_MSG_FAILURE(['Can't find boost random'])])
CPPFLAGS+=" -DBOOST_SYSTEM_NO_DEPRECATED"
])
PKG_CHECK_MODULES([SECP256K1], [libsecp256k1 >= 0.1],, AC_MSG_FAILURE([Missing secp256k1]))
dnl IPv6 mode is default-disabled
AC_ARG_ENABLE([ipv6], AS_HELP_STRING([--enable-ipv6], [Enable IPv6 support]))
......
......@@ -55,6 +55,7 @@ libring_la_LDFLAGS = \
@GNUTLS_LIBS@ \
@OPENDHT_LIBS@ \
@ARGON2_LIBS@ \
@SECP256K1_LIBS@ \
@ZLIB_LIBS@ \
$(PCRE_LIBS) \
@LIBS@
......
......@@ -2,16 +2,12 @@ include $(top_srcdir)/globals.mk
SUBDIRS = eth/libdevcore eth/libdevcrypto
AM_CPPFLAGS += -I$(top_srcdir)/src/ringdht/eth $(BOOST_CPPFLAGS)
AM_CPPFLAGS += -I$(top_srcdir)/src/ringdht/eth
noinst_LTLIBRARIES = libringacc.la
AM_LDFLAGS = $(BOOST_LDFLAGS)
libringacc_la_CXXFLAGS = @CXXFLAGS@ @JSONCPP_CFLAGS@
libringacc_la_LIBADD = $(DHT_LIBS) \
$(BOOST_SYSTEM_LIB) \
$(BOOST_RANDOM_LIB) \
./eth/libdevcore/libdevcore.la \
./eth/libdevcrypto/libdevcrypto.la
......
......@@ -14,25 +14,25 @@
You should have received a copy of the GNU General Public License
along with cpp-ethereum. If not, see <http://www.gnu.org/licenses/>.
*/
/** @file Hash.h
* @author Gav Wood <i@gavwood.com>
* @date 2014
*
* The FixedHash fixed-size "hash" container type.
*/
/// @file
/// This file defined Address alias for FixedHash of 160 bits and some
/// special Address constants.
#pragma once
#include <string>
#include "FixedHash.h"
#include "vector_ref.h"
#include "SHA3.h"
namespace dev
{
h256 sha256(bytesConstRef _input);
/// An Ethereum address: 20 bytes.
/// @NOTE This is not endian-specific; it's just a bunch of bytes.
using Address = h160;
h160 ripemd160(bytesConstRef _input);
/// A vector of Ethereum addresses.
using Addresses = h160s;
/// A hash set of Ethereum addresses.
using AddressHash = std::unordered_set<h160>;
}
......@@ -20,28 +20,13 @@
*/
#include "Common.h"
#include "Exceptions.h"
using namespace std;
using namespace dev;
namespace dev
{
char const* Version = "1.2.4";
const u256 Invalid256 = ~(u256)0;
void InvariantChecker::checkInvariants(HasInvariants const* _this, char const* _fn, char const* _file, int _line, bool _pre)
{
if (!_this->invariants())
{
::boost::exception_detail::throw_exception_(FailedInvariant(), _fn, _file, _line);
}
}
TimerHelper::~TimerHelper()
{
}
bytes const NullBytes;
uint64_t utcTime()
{
......@@ -51,43 +36,4 @@ uint64_t utcTime()
return time(0);
}
string inUnits(bigint const& _b, strings const& _units)
{
ostringstream ret;
u256 b;
if (_b < 0)
{
ret << "-";
b = (u256)-_b;
}
else
b = (u256)_b;
u256 biggest = 1;
for (unsigned i = _units.size() - 1; !!i; --i)
biggest *= 1000;
if (b > biggest * 1000)
{
ret << (b / biggest) << " " << _units.back();
return ret.str();
}
ret << setprecision(3);
u256 unit = biggest;
for (auto it = _units.rbegin(); it != _units.rend(); ++it)
{
auto i = *it;
if (i != _units.front() && b >= unit)
{
ret << (double(b / (unit / 1000)) / 1000.0) << " " << i;
return ret.str();
}
else
unit /= 1000;
}
ret << b << " " << _units.front();
return ret.str();
}
}
......@@ -23,7 +23,7 @@
#pragma once
// way to many unsigned to size_t warnings in 32 bit build
// way too many unsigned to size_t warnings in 32 bit build
#ifdef _M_IX86
#pragma warning(disable:4244)
#endif
......@@ -45,16 +45,6 @@
#include <functional>
#include <string>
#include <chrono>
#pragma warning(push)
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wunused-parameter"
#include <boost/version.hpp>
#if (BOOST_VERSION == 105800)
#include "boost_multiprecision_number_compare_bug_workaround.hpp"
#endif
#include <boost/multiprecision/cpp_int.hpp>
#pragma warning(pop)
#pragma GCC diagnostic pop
#include "vector_ref.h"
// CryptoPP defines byte in the global namespace, so must we.
......@@ -66,7 +56,6 @@ using byte = uint8_t;
#define DEV_IGNORE_EXCEPTIONS(X) try { X; } catch (...) {}
#define DEV_IF_NO_ELSE(X) if(!(X)){}else
#define DEV_IF_THROWS(X) try{X;}catch(...)
namespace dev
......@@ -74,7 +63,7 @@ namespace dev
extern char const* Version;
static const std::string EmptyString;
extern std::string const EmptyString;
// Binary data types.
using bytes = std::vector<byte>;
......@@ -87,8 +76,8 @@ class secure_vector
public:
secure_vector() {}
secure_vector(secure_vector<T> const& /*_c*/) = default; // See https://github.com/ethereum/libweb3core/pull/44
explicit secure_vector(unsigned _size): m_data(_size) {}
explicit secure_vector(unsigned _size, T _item): m_data(_size, _item) {}
explicit secure_vector(size_t _size): m_data(_size) {}
explicit secure_vector(size_t _size, T _item): m_data(_size, _item) {}
explicit secure_vector(std::vector<T> const& _c): m_data(_c) {}
explicit secure_vector(vector_ref<T> _c): m_data(_c.data(), _c.data() + _c.size()) {}
explicit secure_vector(vector_ref<const T> _c): m_data(_c.data(), _c.data() + _c.size()) {}
......@@ -122,83 +111,23 @@ private:
using bytesSec = secure_vector<byte>;
// Numeric types.
using bigint = boost::multiprecision::number<boost::multiprecision::cpp_int_backend<>>;
using u64 = boost::multiprecision::number<boost::multiprecision::cpp_int_backend<64, 64, boost::multiprecision::unsigned_magnitude, boost::multiprecision::unchecked, void>>;
using u128 = boost::multiprecision::number<boost::multiprecision::cpp_int_backend<128, 128, boost::multiprecision::unsigned_magnitude, boost::multiprecision::unchecked, void>>;
using u256 = boost::multiprecision::number<boost::multiprecision::cpp_int_backend<256, 256, boost::multiprecision::unsigned_magnitude, boost::multiprecision::unchecked, void>>;
using s256 = boost::multiprecision::number<boost::multiprecision::cpp_int_backend<256, 256, boost::multiprecision::signed_magnitude, boost::multiprecision::unchecked, void>>;
using u160 = boost::multiprecision::number<boost::multiprecision::cpp_int_backend<160, 160, boost::multiprecision::unsigned_magnitude, boost::multiprecision::unchecked, void>>;
using s160 = boost::multiprecision::number<boost::multiprecision::cpp_int_backend<160, 160, boost::multiprecision::signed_magnitude, boost::multiprecision::unchecked, void>>;
using u512 = boost::multiprecision::number<boost::multiprecision::cpp_int_backend<512, 512, boost::multiprecision::unsigned_magnitude, boost::multiprecision::unchecked, void>>;
using s512 = boost::multiprecision::number<boost::multiprecision::cpp_int_backend<512, 512, boost::multiprecision::signed_magnitude, boost::multiprecision::unchecked, void>>;
using u256s = std::vector<u256>;
using u160s = std::vector<u160>;
using u256Set = std::set<u256>;
using u160Set = std::set<u160>;
// Map types.
using StringMap = std::map<std::string, std::string>;
using BytesMap = std::map<bytes, bytes>;
using u256Map = std::map<u256, u256>;
using HexMap = std::map<bytes, bytes>;
// Hash types.
using StringHashMap = std::unordered_map<std::string, std::string>;
using u256HashMap = std::unordered_map<u256, u256>;
//using u256HashMap = std::unordered_map<u256, u256>;
// String types.
using strings = std::vector<std::string>;
// Fixed-length string types.
using string32 = std::array<char, 32>;
static const string32 ZeroString32 = {{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }};
// Null/Invalid values for convenience.
static const bytes NullBytes;
static const std::map<u256, u256> EmptyMapU256U256;
extern const u256 Invalid256;
/// Interprets @a _u as a two's complement signed number and returns the resulting s256.
inline s256 u2s(u256 _u)
{
static const bigint c_end = bigint(1) << 256;
if (boost::multiprecision::bit_test(_u, 255))
return s256(-(c_end - _u));
else
return s256(_u);
}
/// @returns the two's complement signed representation of the signed number _u.
inline u256 s2u(s256 _u)
{
static const bigint c_end = bigint(1) << 256;
if (_u >= 0)
return u256(_u);
else
return u256(c_end + _u);
}
/// Converts given int to a string and appends one of a series of units according to its size.
std::string inUnits(bigint const& _b, strings const& _units);
/// @returns the smallest n >= 0 such that (1 << n) >= _x
inline unsigned int toLog2(u256 _x)
{
unsigned ret;
for (ret = 0; _x >>= 1; ++ret) {}
return ret;
}
template <size_t n> inline u256 exp10()
{
return exp10<n - 1>() * u256(10);
}
template <> inline u256 exp10<0>()
{
return u256(1);
}
extern bytes const NullBytes;
/// @returns the absolute distance between _a and _b.
template <class N>
......@@ -226,22 +155,6 @@ public:
virtual bool invariants() const = 0;
};
/// RAII checker for invariant assertions.
class InvariantChecker
{
public:
InvariantChecker(HasInvariants* _this, char const* _fn, char const* _file, int _line): m_this(_this), m_function(_fn), m_file(_file), m_line(_line) { checkInvariants(_this, _fn , _file, _line, true); }
~InvariantChecker() { checkInvariants(m_this, m_function, m_file, m_line, false); }
/// Check invariants are met, throw if not.
static void checkInvariants(HasInvariants const* _this, char const* _fn, char const* _file, int line, bool _pre);
private:
HasInvariants const* m_this;
char const* m_function;
char const* m_file;
int m_line;
};
/// Scope guard for invariant check in a class derived from HasInvariants.
#if ETH_DEBUG
#define DEV_INVARIANT_CHECK ::dev::InvariantChecker __dev_invariantCheck(this, BOOST_CURRENT_FUNCTION, __FILE__, __LINE__)
......@@ -312,23 +225,3 @@ enum class WithExisting: int
uint64_t utcTime();
}
namespace std
{
inline dev::WithExisting max(dev::WithExisting _a, dev::WithExisting _b)
{
return static_cast<dev::WithExisting>(max(static_cast<int>(_a), static_cast<int>(_b)));
}
template <> struct hash<dev::u256>
{
size_t operator()(dev::u256 const& _a) const
{
unsigned size = _a.backend().size();
auto limbs = _a.backend().limbs();
return boost::hash_range(limbs, limbs + size);
}
};
}
......@@ -20,27 +20,30 @@
*/
#include "CommonData.h"
#include <random>
#if defined(_MSC_VER)
#pragma warning(push)
#pragma warning(disable:4724) // potential mod by 0, line 78 of boost/random/uniform_int_distribution.hpp (boost 1.55)
#endif
#include <boost/random/uniform_int_distribution.hpp>
#if defined(_MSC_VER)
#pragma warning(pop)
#endif
#include "Exceptions.h"
using namespace std;
using namespace dev;
bool dev::isHex(string const& _s)
namespace
{
unsigned i = (_s.size() >= 2 && _s.substr(0, 2) == "0x") ? 2 : 0;
for (; i < _s.size(); ++i)
if (fromHex(_s[i], WhenError::DontThrow) == -1)
return false;
return true;
int fromHexChar(char _i) noexcept
{
if (_i >= '0' && _i <= '9')
return _i - '0';
if (_i >= 'a' && _i <= 'f')
return _i - 'a' + 10;
if (_i >= 'A' && _i <= 'F')
return _i - 'A' + 10;
return -1;
}
}
bool dev::isHex(string const& _s) noexcept
{
auto it = _s.begin();
if (_s.compare(0, 2, "0x") == 0)
it += 2;
return std::all_of(it, _s.end(), [](char c){ return fromHexChar(c) != -1; });
}
std::string dev::escaped(std::string const& _s, bool _all)
......@@ -71,31 +74,6 @@ std::string dev::escaped(std::string const& _s, bool _all)
return ret;
}
std::string dev::randomWord()
{
static std::mt19937_64 s_eng(0);
std::string ret(boost::random::uniform_int_distribution<int>(1, 5)(s_eng), ' ');
char const n[] = "qwertyuiop";//asdfghjklzxcvbnmQWERTYUIOPASDFGHJKLZXCVBNM1234567890";
boost::random::uniform_int_distribution<int> d(0, sizeof(n) - 2);
for (char& c: ret)
c = n[d(s_eng)];
return ret;
}
int dev::fromHex(char _i, WhenError _throw)
{
if (_i >= '0' && _i <= '9')
return _i - '0';
if (_i >= 'a' && _i <= 'f')
return _i - 'a' + 10;
if (_i >= 'A' && _i <= 'F')
return _i - 'A' + 10;
if (_throw == WhenError::Throw)
BOOST_THROW_EXCEPTION(BadHexCharacter() << errinfo_invalidSymbol(_i));
else
return -1;
}
bytes dev::fromHex(std::string const& _s, WhenError _throw)
{
unsigned s = (_s.size() >= 2 && _s[0] == '0' && _s[1] == 'x') ? 2 : 0;
......@@ -104,22 +82,22 @@ bytes dev::fromHex(std::string const& _s, WhenError _throw)
if (_s.size() % 2)
{
int h = fromHex(_s[s++], WhenError::DontThrow);
int h = fromHexChar(_s[s++]);
if (h != -1)
ret.push_back(h);