diff --git a/eth/AccountManager.cpp b/eth/AccountManager.cpp index 6360972fb2a..ce26898244d 100644 --- a/eth/AccountManager.cpp +++ b/eth/AccountManager.cpp @@ -215,7 +215,7 @@ KeyPair AccountManager::makeKey() const { bool icap = true; KeyPair k(Secret::random()); - while (icap && k.address()[0]) + while (icap && to_integer(k.address()[0])) k = KeyPair(Secret(sha3(k.secret().ref()))); return k; } diff --git a/ethkey/KeyAux.h b/ethkey/KeyAux.h index 0017f95f519..ddef6178941 100644 --- a/ethkey/KeyAux.h +++ b/ethkey/KeyAux.h @@ -270,7 +270,7 @@ class KeyCLI KeyPair makeKey() const { KeyPair k(Secret::random()); - while (m_icap && k.address()[0]) + while (m_icap && to_integer(k.address()[0])) k = KeyPair(Secret(sha3(k.secret().ref()))); return k; } diff --git a/ethvm/main.cpp b/ethvm/main.cpp index b724f1aec64..5497234ce5e 100755 --- a/ethvm/main.cpp +++ b/ethvm/main.cpp @@ -281,7 +281,7 @@ int main(int argc, char** argv) if (inputFile == "-") for (int i = cin.get(); i != -1; i = cin.get()) - code.push_back((char)i); + code.push_back((dev::byte)i); else code = contents(inputFile); @@ -321,14 +321,14 @@ int main(int argc, char** argv) executive.setResultRecipient(res); t.forceSender(sender); - unordered_map> counts; + unordered_map> counts; unsigned total = 0; bigint memTotal; auto onOp = [&](uint64_t step, uint64_t PC, Instruction inst, bigint m, bigint gasCost, bigint gas, VM* vm, ExtVMFace const* extVM) { if (mode == Mode::Statistics) { - counts[(byte)inst].first++; - counts[(byte)inst].second += gasCost; + counts[(unsigned char)inst].first++; + counts[(unsigned char)inst].second += gasCost; total++; if (m > 0) memTotal = m; @@ -370,8 +370,8 @@ int main(int argc, char** argv) cout << "Maximum memory usage: " << memTotal * 32 << " bytes\n"; cout << "Expensive operations:\n"; for (auto const& c: {Instruction::SSTORE, Instruction::SLOAD, Instruction::CALL, Instruction::CREATE, Instruction::CALLCODE, Instruction::DELEGATECALL, Instruction::MSTORE8, Instruction::MSTORE, Instruction::MLOAD, Instruction::SHA3}) - if (!!counts[(byte)c].first) - cout << " " << instructionInfo(c).name << " x " << counts[(byte)c].first << " (" << counts[(byte)c].second << " gas)\n"; + if (!!counts[(unsigned char)c].first) + cout << " " << instructionInfo(c).name << " x " << counts[(unsigned char)c].first << " (" << counts[(unsigned char)c].second << " gas)\n"; } else if (mode == Mode::Trace) cout << st.json(styledJson); diff --git a/libdevcore/Base64.cpp b/libdevcore/Base64.cpp index 8ee2b29f720..a3dc79d1c06 100644 --- a/libdevcore/Base64.cpp +++ b/libdevcore/Base64.cpp @@ -33,17 +33,17 @@ using namespace dev; static inline bool is_base64(byte c) { - return (isalnum(c) || (c == '+') || (c == '/')); + return (isalnum(to_integer(c)) || (to_integer(c) == '+') || (to_integer(c) == '/')); } static inline byte find_base64_char_index(byte c) { - if ('A' <= c && c <= 'Z') return c - 'A'; - else if ('a' <= c && c <= 'z') return c - 'a' + 1 + find_base64_char_index('Z'); - else if ('0' <= c && c <= '9') return c - '0' + 1 + find_base64_char_index('z'); - else if (c == '+') return 1 + find_base64_char_index('9'); - else if (c == '/') return 1 + find_base64_char_index('+'); - else return 1 + find_base64_char_index('/'); + if ('A' <= to_integer(c) && to_integer(c) <= 'Z') return byte(to_integer(c) - 'A'); + else if ('a' <= to_integer(c) && to_integer(c) <= 'z') return byte(to_integer(c) - 'a' + 1 + to_integer(find_base64_char_index((byte)'Z'))); + else if ('0' <= to_integer(c) && to_integer(c) <= '9') return byte(to_integer(c) - '0' + 1 + to_integer(find_base64_char_index((byte)'z'))); + else if (to_integer(c) == '+') return byte(1 + to_integer(find_base64_char_index((byte)'9'))); + else if (to_integer(c) == '/') return byte(1 + to_integer(find_base64_char_index((byte)'+'))); + else return (byte)(1 + to_integer(find_base64_char_index((byte)'/'))); } string dev::toBase64(bytesConstRef _in) @@ -67,13 +67,13 @@ string dev::toBase64(bytesConstRef _in) char_array_3[i++] = *(buf++); if (i == 3) { - char_array_4[0] = (char_array_3[0] & 0xfc) >> 2; - char_array_4[1] = ((char_array_3[0] & 0x03) << 4) + ((char_array_3[1] & 0xf0) >> 4); - char_array_4[2] = ((char_array_3[1] & 0x0f) << 2) + ((char_array_3[2] & 0xc0) >> 6); - char_array_4[3] = char_array_3[2] & 0x3f; + char_array_4[0] = (char_array_3[0] & (byte)0xfc) >> 2; + char_array_4[1] = (byte)(to_integer((char_array_3[0] & (byte)0x03) << 4) + to_integer((char_array_3[1] & (byte)0xf0) >> 4)); + char_array_4[2] = (byte)(to_integer((char_array_3[1] & (byte)0x0f) << 2) + to_integer((char_array_3[2] & (byte)0xc0) >> 6)); + char_array_4[3] = char_array_3[2] & (byte)0x3f; for (i = 0; i < 4; i++) - ret += base64_chars[char_array_4[i]]; + ret += base64_chars[to_integer(char_array_4[i])]; i = 0; } } @@ -81,15 +81,15 @@ string dev::toBase64(bytesConstRef _in) if (i) { for (j = i; j < 3; j++) - char_array_3[j] = '\0'; + char_array_3[j] = (byte)('\0'); - char_array_4[0] = (char_array_3[0] & 0xfc) >> 2; - char_array_4[1] = ((char_array_3[0] & 0x03) << 4) + ((char_array_3[1] & 0xf0) >> 4); - char_array_4[2] = ((char_array_3[1] & 0x0f) << 2) + ((char_array_3[2] & 0xc0) >> 6); - char_array_4[3] = char_array_3[2] & 0x3f; + char_array_4[0] = (char_array_3[0] & (byte)0xfc) >> 2; + char_array_4[1] = (byte)(to_integer((char_array_3[0] & (byte)0x03) << 4) + to_integer((char_array_3[1] & (byte)0xf0) >> 4)); + char_array_4[2] = (byte)(to_integer((char_array_3[1] & (byte)0x0f) << 2) + to_integer((char_array_3[2] & (byte)0xc0) >> 6)); + char_array_4[3] = char_array_3[2] & (byte)0x3f; for (j = 0; j < i + 1; j++) - ret += base64_chars[char_array_4[j]]; + ret += base64_chars[to_integer(char_array_4[j])]; while (i++ < 3) ret += '='; @@ -108,18 +108,17 @@ bytes dev::fromBase64(string const& encoded_string) byte char_array_4[4]; bytes ret; - while (in_len-- && encoded_string[in_] != '=' && is_base64(encoded_string[in_])) + while (in_len-- && encoded_string[in_] != '=' && is_base64((byte)encoded_string[in_])) { - char_array_4[i++] = encoded_string[in_]; in_++; + char_array_4[i++] = (byte)(encoded_string[in_]); in_++; if (i == 4) { for (i = 0; i < 4; i++) char_array_4[i] = find_base64_char_index(char_array_4[i]); - char_array_3[0] = (char_array_4[0] << 2) + ((char_array_4[1] & 0x30) >> 4); - char_array_3[1] = ((char_array_4[1] & 0xf) << 4) + ((char_array_4[2] & 0x3c) >> 2); - char_array_3[2] = ((char_array_4[2] & 0x3) << 6) + char_array_4[3]; - + char_array_3[0] = (byte)(to_integer(char_array_4[0] << 2) + to_integer((char_array_4[1] & (byte)0x30) >> 4)); + char_array_3[1] = (byte)(to_integer((char_array_4[1] & (byte)0xf) << 4) + to_integer((char_array_4[2] & (byte)0x3c) >> 2)); + char_array_3[2] = (byte)(to_integer((char_array_4[2] & (byte)0x3) << 6) + to_integer(char_array_4[3])); for (i = 0; (i < 3); i++) ret.push_back(char_array_3[i]); i = 0; @@ -129,15 +128,14 @@ bytes dev::fromBase64(string const& encoded_string) if (i) { for (j = i; j < 4; j++) - char_array_4[j] = 0; + char_array_4[j] = (byte)0; for (j = 0; j < 4; j++) char_array_4[j] = find_base64_char_index(char_array_4[j]); - char_array_3[0] = (char_array_4[0] << 2) + ((char_array_4[1] & 0x30) >> 4); - char_array_3[1] = ((char_array_4[1] & 0xf) << 4) + ((char_array_4[2] & 0x3c) >> 2); - char_array_3[2] = ((char_array_4[2] & 0x3) << 6) + char_array_4[3]; - + char_array_3[0] = (byte)(to_integer(char_array_4[0] << 2) + to_integer((char_array_4[1] & (byte)0x30) >> 4)); + char_array_3[1] = (byte)(to_integer((char_array_4[1] & (byte)0xf) << 4) + to_integer((char_array_4[2] & (byte)0x3c) >> 2)); + char_array_3[2] = (byte)(to_integer((char_array_4[2] & (byte)0x3) << 6) + to_integer(char_array_4[3])); for (j = 0; j < i - 1; j++) ret.push_back(char_array_3[j]); } diff --git a/libdevcore/Common.h b/libdevcore/Common.h index bc39f456f66..4ed905d2c9c 100644 --- a/libdevcore/Common.h +++ b/libdevcore/Common.h @@ -53,8 +53,6 @@ #pragma GCC diagnostic pop #include "vector_ref.h" -// CryptoPP defines byte in the global namespace, so must we. -using byte = uint8_t; // Quote a given token stream to turn it into a string. #define DEV_QUOTED_HELPER(s) #s @@ -200,6 +198,69 @@ inline N diff(N const& _a, N const& _b) return std::max(_a, _b) - std::min(_a, _b); } +// template ::value>> +inline constexpr uint8_t to_integer(byte b) noexcept +{ + return static_cast(b); +} + +template ::value>> +inline constexpr byte& operator<<=(byte& b, IntegerType shift) noexcept +{ + return b = byte(static_cast(b) << shift); +} + +template ::value>> +inline constexpr byte operator<<(byte b, IntegerType shift) noexcept +{ + return byte(static_cast(b) << shift); +} + +template ::value>> +inline constexpr byte& operator>>=(byte& b, IntegerType shift) noexcept +{ + return b = byte(static_cast(b) >> shift); +} + +template ::value>> +inline constexpr byte operator>>(byte b, IntegerType shift) noexcept +{ + return byte(static_cast(b) >> shift); +} + +inline constexpr byte& operator|=(byte& l, byte r) noexcept +{ + return l = byte(static_cast(l) | static_cast(r)); +} + +inline constexpr byte operator|(byte l, byte r) noexcept +{ + return byte(static_cast(l) | static_cast(r)); +} + +inline constexpr byte& operator&=(byte& l, byte r) noexcept +{ + return l = byte(static_cast(l) & static_cast(r)); +} + +inline constexpr byte operator&(byte l, byte r) noexcept +{ + return byte(static_cast(l) & static_cast(r)); +} + +inline constexpr byte& operator^=(byte& l, byte r) noexcept +{ + return l = byte(static_cast(l) ^ static_cast(r)); +} + +inline constexpr byte operator^(byte l, byte r) noexcept +{ + return byte(static_cast(l) ^ static_cast(r)); +} + +inline constexpr byte operator~(byte b) noexcept { return byte(~static_cast(b)); } + + /// RAII utility class whose destructor calls a given function. class ScopeGuard { diff --git a/libdevcore/CommonData.cpp b/libdevcore/CommonData.cpp index 4047b7b8965..865356243c2 100644 --- a/libdevcore/CommonData.cpp +++ b/libdevcore/CommonData.cpp @@ -93,14 +93,14 @@ std::string dev::randomWord() bytes dev::fromHex(std::string const& _s, WhenError _throw) { unsigned s = (_s.size() >= 2 && _s[0] == '0' && _s[1] == 'x') ? 2 : 0; - std::vector ret; + std::vector ret; ret.reserve((_s.size() - s + 1) / 2); if (_s.size() % 2) { int h = fromHexChar(_s[s++]); if (h != -1) - ret.push_back(h); + ret.push_back((byte)h); else if (_throw == WhenError::Throw) BOOST_THROW_EXCEPTION(BadHexCharacter()); else @@ -122,12 +122,12 @@ bytes dev::fromHex(std::string const& _s, WhenError _throw) bytes dev::asNibbles(bytesConstRef const& _s) { - std::vector ret; + std::vector ret; ret.reserve(_s.size() * 2); for (auto i: _s) { - ret.push_back(i / 16); - ret.push_back(i % 16); + ret.push_back((byte)(to_integer(i) / 16)); + ret.push_back((byte)(to_integer(i) % 16)); } return ret; } diff --git a/libdevcore/CommonData.h b/libdevcore/CommonData.h index 69baec34849..53b193a2c91 100644 --- a/libdevcore/CommonData.h +++ b/libdevcore/CommonData.h @@ -54,8 +54,8 @@ std::string toHex(Iterator _it, Iterator _end, std::string const& _prefix) hex.replace(0, off, _prefix); for (; _it != _end; _it++) { - hex[off++] = hexdigits[(*_it >> 4) & 0x0f]; - hex[off++] = hexdigits[*_it & 0x0f]; + hex[off++] = hexdigits[to_integer((byte)(*_it >> 4) & (byte)0x0f)]; + hex[off++] = hexdigits[to_integer((byte)*_it & (byte)0x0f)]; } return hex; } @@ -139,7 +139,7 @@ inline T fromBigEndian(_In const& _bytes) { T ret = (T)0; for (auto i: _bytes) - ret = (T)((ret << 8) | (byte)(typename std::make_unsigned::type)i); + ret = (T)((ret << 8) | (typename std::make_unsigned::type)i); return ret; } @@ -157,13 +157,13 @@ inline bytes toCompactBigEndian(T _val, unsigned _min = 0) static_assert(std::is_same::value || !std::numeric_limits::is_signed, "only unsigned types or bigint supported"); //bigint does not carry sign bit on shift int i = 0; for (T v = _val; v; ++i, v >>= 8) {} - bytes ret(std::max(_min, i), 0); + bytes ret(std::max(_min, i), (byte)0); toBigEndian(_val, ret); return ret; } inline bytes toCompactBigEndian(byte _val, unsigned _min = 0) { - return (_min || _val) ? bytes{ _val } : bytes{}; + return (_min || to_integer(_val)) ? bytes{ _val } : bytes{}; } /// Convenience function for toBigEndian. diff --git a/libdevcore/CommonIO.cpp b/libdevcore/CommonIO.cpp index b34a6bfba8f..20f6d7cd72c 100644 --- a/libdevcore/CommonIO.cpp +++ b/libdevcore/CommonIO.cpp @@ -45,13 +45,13 @@ string dev::memDump(bytes const& _bytes, unsigned _width, bool _html) ret << hex << setw(4) << setfill('0') << i << " "; for (unsigned j = i; j < i + _width; ++j) if (j < _bytes.size()) - if (_bytes[j] >= 32 && _bytes[j] < 127) - if ((char)_bytes[j] == '<' && _html) + if (to_integer(_bytes[j]) >= 32 && to_integer(_bytes[j]) < 127) + if (to_integer(_bytes[j]) == '<' && _html) ret << "<"; - else if ((char)_bytes[j] == '&' && _html) + else if (to_integer(_bytes[j]) == '&' && _html) ret << "&"; else - ret << (char)_bytes[j]; + ret << to_integer(_bytes[j]); else ret << '?'; else diff --git a/libdevcore/CommonJS.cpp b/libdevcore/CommonJS.cpp index fa187f30207..6234a0af8bf 100644 --- a/libdevcore/CommonJS.cpp +++ b/libdevcore/CommonJS.cpp @@ -47,7 +47,7 @@ bytes jsToBytes(string const& _s, OnFailed _f) bytes padded(bytes _b, unsigned _l) { while (_b.size() < _l) - _b.insert(_b.begin(), 0); + _b.insert(_b.begin(), (byte)0); return asBytes(asString(_b).substr(_b.size() - max(_l, _l))); } diff --git a/libdevcore/FixedHash.h b/libdevcore/FixedHash.h index ec518d8a566..e59e8eeb0d1 100644 --- a/libdevcore/FixedHash.h +++ b/libdevcore/FixedHash.h @@ -62,10 +62,10 @@ class FixedHash enum ConstructFromHashType { AlignLeft, AlignRight, FailIfDifferent }; /// Construct an empty hash. - FixedHash() { m_data.fill(0); } + FixedHash() { m_data.fill((byte)0); } /// Construct from another hash, filling with zeroes or cropping as necessary. - template explicit FixedHash(FixedHash const& _h, ConstructFromHashType _t = AlignLeft) { m_data.fill(0); unsigned c = std::min(M, N); for (unsigned i = 0; i < c; ++i) m_data[_t == AlignRight ? N - 1 - i : i] = _h[_t == AlignRight ? M - 1 - i : i]; } + template explicit FixedHash(FixedHash const& _h, ConstructFromHashType _t = AlignLeft) { m_data.fill((byte)0); unsigned c = std::min(M, N); for (unsigned i = 0; i < c; ++i) m_data[_t == AlignRight ? N - 1 - i : i] = _h[_t == AlignRight ? M - 1 - i : i]; } /// Convert from the corresponding arithmetic type. FixedHash(Arith const& _arith) { toBigEndian(_arith, m_data); } @@ -74,10 +74,10 @@ class FixedHash explicit FixedHash(unsigned _u) { toBigEndian(_u, m_data); } /// Explicitly construct, copying from a byte array. - explicit FixedHash(bytes const& _b, ConstructFromHashType _t = FailIfDifferent) { if (_b.size() == N) memcpy(m_data.data(), _b.data(), std::min(_b.size(), N)); else { m_data.fill(0); if (_t != FailIfDifferent) { auto c = std::min(_b.size(), N); for (unsigned i = 0; i < c; ++i) m_data[_t == AlignRight ? N - 1 - i : i] = _b[_t == AlignRight ? _b.size() - 1 - i : i]; } } } + explicit FixedHash(bytes const& _b, ConstructFromHashType _t = FailIfDifferent) { if (_b.size() == N) memcpy(m_data.data(), _b.data(), std::min(_b.size(), N)); else { m_data.fill((byte)0); if (_t != FailIfDifferent) { auto c = std::min(_b.size(), N); for (unsigned i = 0; i < c; ++i) m_data[_t == AlignRight ? N - 1 - i : i] = _b[_t == AlignRight ? _b.size() - 1 - i : i]; } } } /// Explicitly construct, copying from a byte array. - explicit FixedHash(bytesConstRef _b, ConstructFromHashType _t = FailIfDifferent) { if (_b.size() == N) memcpy(m_data.data(), _b.data(), std::min(_b.size(), N)); else { m_data.fill(0); if (_t != FailIfDifferent) { auto c = std::min(_b.size(), N); for (unsigned i = 0; i < c; ++i) m_data[_t == AlignRight ? N - 1 - i : i] = _b[_t == AlignRight ? _b.size() - 1 - i : i]; } } } + explicit FixedHash(bytesConstRef _b, ConstructFromHashType _t = FailIfDifferent) { if (_b.size() == N) memcpy(m_data.data(), _b.data(), std::min(_b.size(), N)); else { m_data.fill((byte)0); if (_t != FailIfDifferent) { auto c = std::min(_b.size(), N); for (unsigned i = 0; i < c; ++i) m_data[_t == AlignRight ? N - 1 - i : i] = _b[_t == AlignRight ? _b.size() - 1 - i : i]; } } } /// Explicitly construct, copying from a bytes in memory with given pointer. explicit FixedHash(byte const* _bs, ConstructFromPointerType) { memcpy(m_data.data(), _bs, N); } @@ -89,7 +89,7 @@ class FixedHash operator Arith() const { return fromBigEndian(m_data); } /// @returns true iff this is the empty hash. - explicit operator bool() const { return std::any_of(m_data.begin(), m_data.end(), [](byte _b) { return _b != 0; }); } + explicit operator bool() const { return std::any_of(m_data.begin(), m_data.end(), [](byte _b) { return to_integer(_b) != 0; }); } // The obvious comparison operators. bool operator==(FixedHash const& _c) const { return m_data == _c.m_data; } @@ -109,7 +109,17 @@ class FixedHash FixedHash operator~() const { FixedHash ret; for (unsigned i = 0; i < N; ++i) ret[i] = ~m_data[i]; return ret; } // Big-endian increment. - FixedHash& operator++() { for (unsigned i = size; i > 0 && !++m_data[--i]; ) {} return *this; } + FixedHash& operator++() + { + for (unsigned i = size; i > 0;) + { + unsigned j = --i; + m_data[j] = (byte)(to_integer(m_data[j]) + 1); + if(!to_integer(m_data[j])) continue; + else break; + } + return *this; + } /// @returns true if all one-bits in @a _c are set in this object. bool contains(FixedHash const& _c) const { return (*this & _c) == _c; } @@ -160,7 +170,7 @@ class FixedHash void randomize(Engine& _eng) { for (auto& i: m_data) - i = (uint8_t)std::uniform_int_distribution(0, 255)(_eng); + i = (byte)std::uniform_int_distribution(0, 255)(_eng); } /// @returns a random valued object. @@ -197,9 +207,9 @@ class FixedHash { unsigned index = 0; for (unsigned j = 0; j < c_bloomBytes; ++j, ++p) - index = (index << 8) | *p; + index = (index << 8) | to_integer(*p); index &= c_mask; - ret[M - 1 - index / 8] |= (1 << (index % 8)); + ret[M - 1 - index / 8] |= (byte)(1 << (index % 8)); } return ret; } @@ -209,9 +219,9 @@ class FixedHash { unsigned ret = 0; for (auto d: m_data) - if (d) + if (to_integer(d)) for (;; ++ret, d <<= 1) - if (d & 0x80) + if (to_integer(d) & 0x80) return ret; else {} else diff --git a/libdevcore/OverlayDB.cpp b/libdevcore/OverlayDB.cpp index 03b72f228ea..cb01278b545 100644 --- a/libdevcore/OverlayDB.cpp +++ b/libdevcore/OverlayDB.cpp @@ -57,7 +57,7 @@ void OverlayDB::commit() if (i.second.second) { bytes b = i.first.asBytes(); - b.push_back(255); // for aux + b.push_back((byte)255); // for aux batch.Put(bytesConstRef(&b), bytesConstRef(&i.second.first)); } } @@ -95,7 +95,7 @@ bytes OverlayDB::lookupAux(h256 const& _h) const return ret; std::string v; bytes b = _h.asBytes(); - b.push_back(255); // for aux + b.push_back((byte)(255)); // for aux m_db->Get(m_readOptions, bytesConstRef(&b), &v); if (v.empty()) cwarn << "Aux not found: " << _h; diff --git a/libdevcore/RLP.cpp b/libdevcore/RLP.cpp index 45b3a2db0e1..c103efd4d57 100644 --- a/libdevcore/RLP.cpp +++ b/libdevcore/RLP.cpp @@ -121,7 +121,7 @@ void RLP::requireGood() const if (isNull()) BOOST_THROW_EXCEPTION(BadRLP()); byte n = m_data[0]; - if (n != c_rlpDataImmLenStart + 1) + if (to_integer(n) != to_integer(c_rlpDataImmLenStart) + 1) return; if (m_data.size() < 2) BOOST_THROW_EXCEPTION(BadRLP()); @@ -136,20 +136,20 @@ bool RLP::isInt() const requireGood(); byte n = m_data[0]; if (n < c_rlpDataImmLenStart) - return !!n; + return !!to_integer(n); else if (n == c_rlpDataImmLenStart) return true; else if (n <= c_rlpDataIndLenZero) { if (m_data.size() <= 1) BOOST_THROW_EXCEPTION(BadRLP()); - return m_data[1] != 0; + return to_integer(m_data[1]) != 0; } else if (n < c_rlpListStart) { - if (m_data.size() <= size_t(1 + n - c_rlpDataIndLenZero)) + if (m_data.size() <= size_t(1 + to_integer(n) - to_integer(c_rlpDataIndLenZero))) BOOST_THROW_EXCEPTION(BadRLP()); - return m_data[1 + n - c_rlpDataIndLenZero] != 0; + return m_data[1 + to_integer(n) - to_integer(c_rlpDataIndLenZero)] != byte(0); } else return false; @@ -166,45 +166,45 @@ size_t RLP::length() const if (n < c_rlpDataImmLenStart) return 1; else if (n <= c_rlpDataIndLenZero) - return n - c_rlpDataImmLenStart; + return to_integer(n) - to_integer(c_rlpDataImmLenStart); else if (n < c_rlpListStart) { - if (m_data.size() <= size_t(n - c_rlpDataIndLenZero)) + if (m_data.size() <= size_t(to_integer(n) - to_integer(c_rlpDataIndLenZero))) BOOST_THROW_EXCEPTION(BadRLP()); if (m_data.size() > 1) - if (m_data[1] == 0) + if (to_integer(m_data[1]) == 0) BOOST_THROW_EXCEPTION(BadRLP()); - unsigned lengthSize = n - c_rlpDataIndLenZero; + unsigned lengthSize = to_integer(n) - to_integer(c_rlpDataIndLenZero); if (lengthSize > sizeof(ret)) // We did not check, but would most probably not fit in our memory. BOOST_THROW_EXCEPTION(UndersizeRLP()); // No leading zeroes. - if (!m_data[1]) + if (!to_integer(m_data[1])) BOOST_THROW_EXCEPTION(BadRLP()); for (unsigned i = 0; i < lengthSize; ++i) - ret = (ret << 8) | m_data[i + 1]; + ret = (ret << 8) | to_integer(m_data[i + 1]); // Must be greater than the limit. - if (ret < c_rlpListStart - c_rlpDataImmLenStart - c_rlpMaxLengthBytes) + if (ret < to_integer(c_rlpListStart) - to_integer(c_rlpDataImmLenStart) - to_integer(c_rlpMaxLengthBytes)) BOOST_THROW_EXCEPTION(BadRLP()); } else if (n <= c_rlpListIndLenZero) - return n - c_rlpListStart; + return to_integer(n) - to_integer(c_rlpListStart); else { - unsigned lengthSize = n - c_rlpListIndLenZero; + unsigned lengthSize = to_integer(n) - to_integer(c_rlpListIndLenZero); if (m_data.size() <= lengthSize) BOOST_THROW_EXCEPTION(BadRLP()); if (m_data.size() > 1) - if (m_data[1] == 0) + if (to_integer(m_data[1]) == 0) BOOST_THROW_EXCEPTION(BadRLP()); if (lengthSize > sizeof(ret)) // We did not check, but would most probably not fit in our memory. BOOST_THROW_EXCEPTION(UndersizeRLP()); - if (!m_data[1]) + if (!to_integer(m_data[1])) BOOST_THROW_EXCEPTION(BadRLP()); for (unsigned i = 0; i < lengthSize; ++i) - ret = (ret << 8) | m_data[i + 1]; - if (ret < 0x100 - c_rlpListStart - c_rlpMaxLengthBytes) + ret = ret << 8 | to_integer(m_data[i + 1]); + if (ret < 0x100 - to_integer(c_rlpListStart) - to_integer(c_rlpMaxLengthBytes)) BOOST_THROW_EXCEPTION(BadRLP()); } // We have to be able to add payloadOffset to length without overflow. @@ -252,16 +252,16 @@ void RLPStream::noteAppended(size_t _itemCount) m_listStack.pop_back(); size_t s = m_out.size() - p; // list size auto brs = bytesRequired(s); - unsigned encodeSize = s < c_rlpListImmLenCount ? 1 : (1 + brs); + unsigned encodeSize = s < to_integer(c_rlpListImmLenCount) ? 1 : (1 + brs); // cdebug << "s: " << s << ", p: " << p << ", m_out.size(): " << m_out.size() << ", encodeSize: " << encodeSize << " (br: " << brs << ")"; auto os = m_out.size(); m_out.resize(os + encodeSize); memmove(m_out.data() + p + encodeSize, m_out.data() + p, os - p); - if (s < c_rlpListImmLenCount) - m_out[p] = (byte)(c_rlpListStart + s); - else if (c_rlpListIndLenZero + brs <= 0xff) + if (s < to_integer(c_rlpListImmLenCount)) + m_out[p] = (byte)(to_integer(c_rlpListStart) + s); + else if (to_integer(c_rlpListIndLenZero) + brs <= 0xff) { - m_out[p] = (byte)(c_rlpListIndLenZero + brs); + m_out[p] = (byte)(to_integer(c_rlpListIndLenZero) + brs); byte* b = &(m_out[p + brs]); for (; s; s >>= 8) *(b--) = (byte)s; @@ -285,8 +285,8 @@ RLPStream& RLPStream::appendList(size_t _items) RLPStream& RLPStream::appendList(bytesConstRef _rlp) { - if (_rlp.size() < c_rlpListImmLenCount) - m_out.push_back((byte)(_rlp.size() + c_rlpListStart)); + if (_rlp.size() < to_integer(c_rlpListImmLenCount)) + m_out.push_back((byte)(_rlp.size() + to_integer(c_rlpListStart))); else pushCount(_rlp.size(), c_rlpListIndLenZero); appendRaw(_rlp, 1); @@ -298,14 +298,14 @@ RLPStream& RLPStream::append(bytesConstRef _s, bool _compact) size_t s = _s.size(); byte const* d = _s.data(); if (_compact) - for (size_t i = 0; i < _s.size() && !*d; ++i, --s, ++d) {} + for (size_t i = 0; i < _s.size() && !to_integer(*d); ++i, --s, ++d) {} if (s == 1 && *d < c_rlpDataImmLenStart) m_out.push_back(*d); else { - if (s < c_rlpDataImmLenCount) - m_out.push_back((byte)(s + c_rlpDataImmLenStart)); + if (s < to_integer(c_rlpDataImmLenCount)) + m_out.push_back((byte)(s + to_integer(c_rlpDataImmLenStart))); else pushCount(s, c_rlpDataIndLenZero); appendRaw(bytesConstRef(d, s), 0); @@ -318,19 +318,19 @@ RLPStream& RLPStream::append(bigint _i) { if (!_i) m_out.push_back(c_rlpDataImmLenStart); - else if (_i < c_rlpDataImmLenStart) - m_out.push_back((byte)_i); + else if (_i < to_integer(c_rlpDataImmLenStart)) + m_out.push_back((byte)(uint8_t)_i); else { unsigned br = bytesRequired(_i); - if (br < c_rlpDataImmLenCount) - m_out.push_back((byte)(br + c_rlpDataImmLenStart)); + if (br < to_integer(c_rlpDataImmLenCount)) + m_out.push_back((byte)(br + to_integer(c_rlpDataImmLenStart))); else { auto brbr = bytesRequired(br); - if (c_rlpDataIndLenZero + brbr > 0xff) + if (to_integer(c_rlpDataIndLenZero) + brbr > 0xff) BOOST_THROW_EXCEPTION(RLPException() << errinfo_comment("Number too large for RLP")); - m_out.push_back((byte)(c_rlpDataIndLenZero + brbr)); + m_out.push_back((byte)(to_integer(c_rlpDataIndLenZero) + brbr)); pushInt(br, brbr); } pushInt(_i, br); @@ -342,9 +342,9 @@ RLPStream& RLPStream::append(bigint _i) void RLPStream::pushCount(size_t _count, byte _base) { auto br = bytesRequired(_count); - if (int(br) + _base > 0xff) + if (int(br) + to_integer(_base) > 0xff) BOOST_THROW_EXCEPTION(RLPException() << errinfo_comment("Count too large for RLP")); - m_out.push_back((byte)(br + _base)); // max 8 bytes. + m_out.push_back((byte)(br + to_integer(_base))); // max 8 bytes. pushInt(_count, br); } diff --git a/libdevcore/RLP.h b/libdevcore/RLP.h index 32297a2c3e2..21945d10585 100644 --- a/libdevcore/RLP.h +++ b/libdevcore/RLP.h @@ -43,14 +43,14 @@ template <> struct intTraits { static const unsigned maxSize = 20; }; template <> struct intTraits { static const unsigned maxSize = 32; }; template <> struct intTraits { static const unsigned maxSize = ~(unsigned)0; }; -static const byte c_rlpMaxLengthBytes = 8; -static const byte c_rlpDataImmLenStart = 0x80; -static const byte c_rlpListStart = 0xc0; +static const byte c_rlpMaxLengthBytes = (byte)8; +static const byte c_rlpDataImmLenStart = (byte)0x80; +static const byte c_rlpListStart = (byte)0xc0; -static const byte c_rlpDataImmLenCount = c_rlpListStart - c_rlpDataImmLenStart - c_rlpMaxLengthBytes; -static const byte c_rlpDataIndLenZero = c_rlpDataImmLenStart + c_rlpDataImmLenCount - 1; -static const byte c_rlpListImmLenCount = 256 - c_rlpListStart - c_rlpMaxLengthBytes; -static const byte c_rlpListIndLenZero = c_rlpListStart + c_rlpListImmLenCount - 1; +static const byte c_rlpDataImmLenCount = (byte)(to_integer(c_rlpListStart) - to_integer(c_rlpDataImmLenStart) - to_integer(c_rlpMaxLengthBytes)); +static const byte c_rlpDataIndLenZero = (byte)(to_integer(c_rlpDataImmLenStart) + to_integer(c_rlpDataImmLenCount) - 1); +static const byte c_rlpListImmLenCount = (byte)(256 - to_integer(c_rlpListStart) - to_integer(c_rlpMaxLengthBytes)); +static const byte c_rlpListIndLenZero = (byte)(to_integer(c_rlpListStart) + to_integer(c_rlpListImmLenCount) - 1); template struct Converter { static T convert(RLP const&, int) { BOOST_THROW_EXCEPTION(BadCast()); } }; @@ -334,7 +334,7 @@ class RLP bool isSingleByte() const { return !isNull() && m_data[0] < c_rlpDataImmLenStart; } /// @returns the amount of bytes used to encode the length of the data. Valid for all types. - unsigned lengthSize() const { if (isData() && m_data[0] > c_rlpDataIndLenZero) return m_data[0] - c_rlpDataIndLenZero; if (isList() && m_data[0] > c_rlpListIndLenZero) return m_data[0] - c_rlpListIndLenZero; return 0; } + unsigned lengthSize() const { if (isData() && to_integer(m_data[0]) > to_integer(c_rlpDataIndLenZero)) return to_integer(m_data[0]) - to_integer(c_rlpDataIndLenZero); if (isList() && m_data[0] > c_rlpListIndLenZero) return to_integer(m_data[0]) - to_integer(c_rlpListIndLenZero); return 0; } /// @returns the size in bytes of the payload, as given by the RLP as opposed to as inferred from m_data. size_t length() const; @@ -450,7 +450,7 @@ class RLPStream m_out.resize(m_out.size() + _br); byte* b = &m_out.back(); for (; _i; _i >>= 8) - *(b--) = (byte)_i; + *(b--) = (byte)(uint8_t)_i; } /// Our output byte stream. diff --git a/libdevcore/SHA3.cpp b/libdevcore/SHA3.cpp index d4e8e7e557b..a66f6288c42 100644 --- a/libdevcore/SHA3.cpp +++ b/libdevcore/SHA3.cpp @@ -215,7 +215,7 @@ bool sha3(bytesConstRef _input, bytesRef o_output) // FIXME: What with unaligned memory? if (o_output.size() != 32) return false; - keccak::sha3_256(o_output.data(), 32, _input.data(), _input.size()); + keccak::sha3_256((unsigned char *)o_output.data(), 32, (unsigned char *)_input.data(), _input.size()); // keccak::keccak(ret.data(), 32, (uint64_t const*)_input.data(), _input.size()); return true; } diff --git a/libdevcore/TrieCommon.cpp b/libdevcore/TrieCommon.cpp index 2b2ff098a0d..638c048af14 100644 --- a/libdevcore/TrieCommon.cpp +++ b/libdevcore/TrieCommon.cpp @@ -52,11 +52,11 @@ std::string hexPrefixEncode(bytes const& _hexVector, bool _leaf, int _begin, int std::string ret(1, ((_leaf ? 2 : 0) | (odd ? 1 : 0)) * 16); if (odd) { - ret[0] |= _hexVector[begin]; + ret[0] |= (char)_hexVector[begin]; ++begin; } for (unsigned i = begin; i < end; i += 2) - ret += _hexVector[i] * 16 + _hexVector[i + 1]; + ret += char((int)_hexVector[i] * 16 + (int)_hexVector[i + 1]); return ret; } @@ -74,9 +74,9 @@ std::string hexPrefixEncode(bytesConstRef _data, bool _leaf, int _beginNibble, i { byte n = nibble(_data, i); if (d & 1) // odd - ret.back() |= n; // or the nibble onto the back + ret.back() |= (uint8_t)n; // or the nibble onto the back else - ret.push_back(n << 4); // push the nibble on to the back << 4 + ret.push_back(uint8_t(n << 4)); // push the nibble on to the back << 4 } return ret; } @@ -98,31 +98,31 @@ std::string hexPrefixEncode(bytesConstRef _d1, unsigned _o1, bytesConstRef _d2, { byte n = nibble(_d1, i); if (d & 1) // odd - ret.back() |= n; // or the nibble onto the back + ret.back() |= to_integer(n); // or the nibble onto the back else - ret.push_back(n << 4); // push the nibble on to the back << 4 + ret.push_back(to_integer(n << 4)); // push the nibble on to the back << 4 } for (auto i = begin2; i < end2; ++i, ++d) { byte n = nibble(_d2, i); if (d & 1) // odd - ret.back() |= n; // or the nibble onto the back + ret.back() |= to_integer(n); // or the nibble onto the back else - ret.push_back(n << 4); // push the nibble on to the back << 4 + ret.push_back(to_integer(n << 4)); // push the nibble on to the back << 4 } return ret; } byte uniqueInUse(RLP const& _orig, byte except) { - byte used = 255; + byte used = (byte)255; for (unsigned i = 0; i < 17; ++i) - if (i != except && !_orig[i].isEmpty()) + if (i != to_integer(except) && !_orig[i].isEmpty()) { - if (used == 255) + if (to_integer(used) == 255) used = (byte)i; else - return 255; + return (byte)255; } return used; } diff --git a/libdevcore/TrieCommon.h b/libdevcore/TrieCommon.h index 893d3071f59..b84157e290e 100644 --- a/libdevcore/TrieCommon.h +++ b/libdevcore/TrieCommon.h @@ -30,7 +30,7 @@ extern const h256 EmptyTrie; inline byte nibble(bytesConstRef _data, unsigned _i) { - return (_i & 1) ? (_data[_i / 2] & 15) : (_data[_i / 2] >> 4); + return (_i & 1) ? (_data[_i / 2] & (byte)15) : (_data[_i / 2] >> 4); } /// Interprets @a _first and @a _second as vectors of nibbles and returns the length of the longest common @@ -98,14 +98,14 @@ inline bool isLeaf(RLP const& _twoItem) { assert(_twoItem.isList() && _twoItem.itemCount() == 2); auto pl = _twoItem[0].payload(); - return (pl[0] & 0x20) != 0; + return to_integer(pl[0] & (byte)0x20) != 0; } inline NibbleSlice keyOf(bytesConstRef _hpe) { if (!_hpe.size()) return NibbleSlice(_hpe, 0); - if (_hpe[0] & 0x10) + if (to_integer(_hpe[0] & (byte)0x10)) return NibbleSlice(_hpe, 1); else return NibbleSlice(_hpe, 2); diff --git a/libdevcore/TrieDB.h b/libdevcore/TrieDB.h index fc7710715f7..a7b623b1f38 100644 --- a/libdevcore/TrieDB.h +++ b/libdevcore/TrieDB.h @@ -139,9 +139,9 @@ class GenericTrieDB // 255 -> 16 -> 0 -> 1 -> ... -> 15 -> 17 - void setChild(unsigned _i) { child = _i; } - void setFirstChild() { child = 16; } - void incrementChild() { child = child == 16 ? 0 : child == 15 ? 17 : (child + 1); } + void setChild(unsigned _i) { child = (byte)_i; } + void setFirstChild() { child = (byte)16; } + void incrementChild() { child = child == (byte)16 ? (byte)0 : child == (byte)15 ? (byte)17 : (byte)(to_integer(child) + 1); } bool operator==(Node const& _c) const { return rlp == _c.rlp && key == _c.key && child == _c.child; } bool operator!=(Node const& _c) const { return !operator==(_c); } @@ -505,14 +505,14 @@ namespace dev template GenericTrieDB::iterator::iterator(GenericTrieDB const* _db) { m_that = _db; - m_trail.push_back({_db->node(_db->m_root), std::string(1, '\0'), 255}); // one null byte is the HPE for the empty key. + m_trail.push_back({_db->node(_db->m_root), std::string(1, '\0'), (byte)255}); // one null byte is the HPE for the empty key. next(); } template GenericTrieDB::iterator::iterator(GenericTrieDB const* _db, bytesConstRef _fullKey) { m_that = _db; - m_trail.push_back({_db->node(_db->m_root), std::string(1, '\0'), 255}); // one null byte is the HPE for the empty key. + m_trail.push_back({_db->node(_db->m_root), std::string(1, '\0'), (byte)255}); // one null byte is the HPE for the empty key. next(_fullKey); } @@ -541,7 +541,7 @@ template void GenericTrieDB::iterator::next(NibbleSlice _key) Node const& b = m_trail.back(); RLP rlp(b.rlp); - if (m_trail.back().child == 255) + if (to_integer(m_trail.back().child) == 255) { // Entering. Look for first... if (rlp.isEmpty()) @@ -593,7 +593,7 @@ template void GenericTrieDB::iterator::next(NibbleSlice _key) // leaf - exit now. if (k.empty()) { - m_trail.back().child = 0; + m_trail.back().child = (byte)0; return; } // Still data in key we're supposed to be looking for when we're at a leaf. Go for next one. @@ -612,7 +612,7 @@ template void GenericTrieDB::iterator::next(NibbleSlice _key) // Already a branch - look for first valid. if (k.size()) { - m_trail.back().setChild(k[0]); + m_trail.back().setChild(to_integer(k[0])); k = k.mid(1); } else @@ -636,16 +636,16 @@ template void GenericTrieDB::iterator::next(NibbleSlice _key) // ...here. should only get here if we're a list. assert(rlp.isList() && rlp.itemCount() == 17); for (;; m_trail.back().incrementChild()) - if (m_trail.back().child == 17) + if (to_integer(m_trail.back().child) == 17) { // finished here. k.clear(); m_trail.pop_back(); break; } - else if (!rlp[m_trail.back().child].isEmpty()) + else if (!rlp[to_integer(m_trail.back().child)].isEmpty()) { - if (m_trail.back().child == 16) + if (to_integer(m_trail.back().child) == 16) return; // have a value at this node - exit now. else { @@ -653,9 +653,9 @@ template void GenericTrieDB::iterator::next(NibbleSlice _key) // fixed so that Node passed into push_back is constructed *before* m_trail is potentially resized (which invalidates back and rlp) Node const& back = m_trail.back(); m_trail.push_back(Node{ - m_that->deref(rlp[back.child]), + m_that->deref(rlp[to_integer(back.child)]), hexPrefixEncode(keyOf(back.key), NibbleSlice(bytesConstRef(&back.child, 1), 1), false), - 255 + (byte)255 }); break; } @@ -678,7 +678,7 @@ template void GenericTrieDB::iterator::next() Node const& b = m_trail.back(); RLP rlp(b.rlp); - if (m_trail.back().child == 255) + if (to_integer(m_trail.back().child) == 255) { // Entering. Look for first... if (rlp.isEmpty()) @@ -707,7 +707,7 @@ template void GenericTrieDB::iterator::next() if (isLeaf(rlp)) { // leaf - exit now. - m_trail.back().child = 0; + m_trail.back().child = (byte)0; return; } @@ -738,15 +738,15 @@ template void GenericTrieDB::iterator::next() // ...here. should only get here if we're a list. assert(rlp.isList() && rlp.itemCount() == 17); for (;; m_trail.back().incrementChild()) - if (m_trail.back().child == 17) + if (to_integer(m_trail.back().child) == 17) { // finished here. m_trail.pop_back(); break; } - else if (!rlp[m_trail.back().child].isEmpty()) + else if (!rlp[to_integer(m_trail.back().child)].isEmpty()) { - if (m_trail.back().child == 16) + if (to_integer(m_trail.back().child) == 16) return; // have a value at this node - exit now. else { @@ -754,9 +754,9 @@ template void GenericTrieDB::iterator::next() // fixed so that Node passed into push_back is constructed *before* m_trail is potentially resized (which invalidates back and rlp) Node const& back = m_trail.back(); m_trail.push_back(Node{ - m_that->deref(rlp[back.child]), + m_that->deref(rlp[to_integer(back.child)]), hexPrefixEncode(keyOf(back.key), NibbleSlice(bytesConstRef(&back.child, 1), 1), false), - 255 + (byte)255 }); break; } @@ -821,7 +821,7 @@ template std::string GenericTrieDB::atAux(RLP const& _here, Nibbl { if (_key.size() == 0) return _here[16].toString(); - auto n = _here[_key[0]]; + auto n = _here[to_integer(_key[0])]; if (n.isEmpty()) return std::string(); else @@ -900,8 +900,8 @@ template bytes GenericTrieDB::mergeAt(RLP const& _orig, h256 cons // not exactly our node - delve to next level at the correct index. byte n = _k[0]; RLPStream r(17); - for (byte i = 0; i < 17; ++i) - if (i == n) + for (unsigned i = 0; i < 17; ++i) + if (i == to_integer(n)) mergeAtAux(r, _orig[i], _k.mid(1), _v); else r.append(_orig[i]); @@ -1008,9 +1008,9 @@ template bytes GenericTrieDB::deleteAt(RLP const& _orig, NibbleSl // Kill the node. killNode(_orig); - byte used = uniqueInUse(_orig, 16); - if (used != 255) - if (isTwoItemNode(_orig[used])) + byte used = uniqueInUse(_orig, (byte)16); + if (used != (byte)255) + if (isTwoItemNode(_orig[to_integer(used)])) { auto merged = merge(_orig, used); return graft(RLP(merged)); @@ -1020,7 +1020,7 @@ template bytes GenericTrieDB::deleteAt(RLP const& _orig, NibbleSl else { RLPStream r(17); - for (byte i = 0; i < 16; ++i) + for (unsigned i = 0; i < 16; ++i) r << _orig[i]; r << ""; return r.out(); @@ -1031,8 +1031,8 @@ template bytes GenericTrieDB::deleteAt(RLP const& _orig, NibbleSl // not exactly our node - delve to next level at the correct index. RLPStream r(17); byte n = _k[0]; - for (byte i = 0; i < 17; ++i) - if (i == n) + for (unsigned i = 0; i < 17; ++i) + if (i == to_integer(n)) if (!deleteAtAux(r, _orig[i], _k.mid(1))) // bomb out if the key didn't turn up. return bytes(); else {} @@ -1044,12 +1044,12 @@ template bytes GenericTrieDB::deleteAt(RLP const& _orig, NibbleSl // check if we ended up leaving the node invalid. RLP rlp(r.out()); - byte used = uniqueInUse(rlp, 255); - if (used == 255) // no - all ok. + byte used = uniqueInUse(rlp, (byte)255); + if (used == (byte)255) // no - all ok. return r.out(); // yes; merge - if (isTwoItemNode(rlp[used])) + if (isTwoItemNode(rlp[to_integer(used)])) { auto merged = merge(rlp, used); return graft(RLP(merged)); @@ -1186,14 +1186,14 @@ template bytes GenericTrieDB::merge(RLP const& _orig, byte _i) assert(_orig.isList() && _orig.itemCount() == 17); RLPStream s(2); - if (_i != 16) + if (_i != (byte)16) { - assert(!_orig[_i].isEmpty()); + assert(!_orig[to_integer(_i)].isEmpty()); s << hexPrefixEncode(bytesConstRef(&_i, 1), false, 1, 2, 0); } else s << hexPrefixEncode(bytes(), true); - s << _orig[_i]; + s << _orig[to_integer(_i)]; return s.out(); } @@ -1219,7 +1219,7 @@ template bytes GenericTrieDB::branch(RLP const& _orig) { byte b = k[0]; for (unsigned i = 0; i < 16; ++i) - if (i == b) + if (i == to_integer(b)) if (isLeaf(_orig) || k.size() > 1) streamNode(r, rlpList(hexPrefixEncode(k.mid(1), isLeaf(_orig)), _orig[1])); else diff --git a/libdevcore/TrieHash.cpp b/libdevcore/TrieHash.cpp index 4c9622ab2ec..7a59dee5e83 100644 --- a/libdevcore/TrieHash.cpp +++ b/libdevcore/TrieHash.cpp @@ -62,7 +62,7 @@ void hash256rlp(HexMap const& _s, HexMap::const_iterator _begin, HexMap::const_i for (auto i = 0; i < 16; ++i) { auto n = b; - for (; n != _end && n->first[_preLen] == i; ++n) {} + for (; n != _end && to_integer(n->first[_preLen]) == i; ++n) {} if (b == n) _rlp << ""; else diff --git a/libdevcore/vector_ref.h b/libdevcore/vector_ref.h index ce380b9d921..02f2bf1b157 100644 --- a/libdevcore/vector_ref.h +++ b/libdevcore/vector_ref.h @@ -16,6 +16,8 @@ namespace dev { +enum class byte : unsigned char {}; + /** * A modifiable reference to an existing object or vector in memory. */ @@ -45,7 +47,7 @@ class vector_ref bool contentsEqual(std::vector const& _c) const { if (!m_data || m_count == 0) return _c.empty(); else return _c.size() == m_count && !memcmp(_c.data(), m_data, m_count * sizeof(_T)); } std::vector toVector() const { return std::vector(m_data, m_data + m_count); } - std::vector toBytes() const { return std::vector(reinterpret_cast(m_data), reinterpret_cast(m_data) + m_count * sizeof(_T)); } + std::vector toBytes() const { return std::vector(reinterpret_cast(m_data), reinterpret_cast(m_data) + m_count * sizeof(_T)); } std::string toString() const { return std::string((char const*)m_data, ((char const*)m_data) + m_count * sizeof(_T)); } template explicit operator vector_ref<_T2>() const { assert(m_count * sizeof(_T) / sizeof(_T2) * sizeof(_T2) / sizeof(_T) == m_count); return vector_ref<_T2>(reinterpret_cast<_T2*>(m_data), m_count * sizeof(_T) / sizeof(_T2)); } diff --git a/libdevcrypto/AES.cpp b/libdevcrypto/AES.cpp index c4320ff2d94..13843b20e93 100644 --- a/libdevcrypto/AES.cpp +++ b/libdevcrypto/AES.cpp @@ -37,17 +37,17 @@ bytes dev::aesDecrypt(bytesConstRef _ivCipher, std::string const& _password, uns _salt = &pw; bytes target(64); - CryptoPP::PKCS5_PBKDF2_HMAC().DeriveKey(target.data(), target.size(), 0, pw.data(), pw.size(), _salt.data(), _salt.size(), _rounds); + CryptoPP::PKCS5_PBKDF2_HMAC().DeriveKey(reinterpret_cast(target.data()), target.size(), 0, reinterpret_cast(pw.data()), pw.size(), reinterpret_cast(_salt.data()), _salt.size(), _rounds); try { - CryptoPP::AES::Decryption aesDecryption(target.data(), 16); + CryptoPP::AES::Decryption aesDecryption(reinterpret_cast(target.data()), 16); auto cipher = _ivCipher.cropped(16); auto iv = _ivCipher.cropped(0, 16); - CryptoPP::CBC_Mode_ExternalCipher::Decryption cbcDecryption(aesDecryption, iv.data()); + CryptoPP::CBC_Mode_ExternalCipher::Decryption cbcDecryption(aesDecryption, reinterpret_cast(iv.data())); std::string decrypted; CryptoPP::StreamTransformationFilter stfDecryptor(cbcDecryption, new CryptoPP::StringSink(decrypted)); - stfDecryptor.Put(cipher.data(), cipher.size()); + stfDecryptor.Put(reinterpret_cast(cipher.data()), cipher.size()); stfDecryptor.MessageEnd(); return asBytes(decrypted); } diff --git a/libdevcrypto/Common.cpp b/libdevcrypto/Common.cpp index 236e4c3e50c..e49b66296dd 100644 --- a/libdevcrypto/Common.cpp +++ b/libdevcrypto/Common.cpp @@ -59,7 +59,7 @@ bool dev::SignatureStruct::isValid() const noexcept static const h256 s_max{"0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141"}; static const h256 s_zero; - return (v <= 1 && r > s_zero && s > s_zero && r < s_max && s < s_max); + return (to_integer(v) <= 1 && r > s_zero && s > s_zero && r < s_max && s < s_max); } Public dev::toPublic(Secret const& _secret) @@ -67,17 +67,17 @@ Public dev::toPublic(Secret const& _secret) auto* ctx = getCtx(); secp256k1_pubkey rawPubkey; // Creation will fail if the secret key is invalid. - if (!secp256k1_ec_pubkey_create(ctx, &rawPubkey, _secret.data())) + if (!secp256k1_ec_pubkey_create(ctx, &rawPubkey, reinterpret_cast(_secret.data()))) return {}; std::array serializedPubkey; size_t serializedPubkeySize = serializedPubkey.size(); secp256k1_ec_pubkey_serialize( - ctx, serializedPubkey.data(), &serializedPubkeySize, + ctx, reinterpret_cast(serializedPubkey.data()), &serializedPubkeySize, &rawPubkey, SECP256K1_EC_UNCOMPRESSED ); assert(serializedPubkeySize == serializedPubkey.size()); // Expect single byte header of value 0x04 -- uncompressed public key. - assert(serializedPubkey[0] == 0x04); + assert(to_integer(serializedPubkey[0]) == 0x04); // Create the Public skipping the header. return Public{&serializedPubkey[1], Public::ConstructFromPointer}; } @@ -162,13 +162,13 @@ bytes dev::encryptAES128CTR(bytesConstRef _k, h128 const& _iv, bytesConstRef _pl { if (_k.size() != 16 && _k.size() != 24 && _k.size() != 32) return bytes(); - CryptoPP::SecByteBlock key(_k.data(), _k.size()); + CryptoPP::SecByteBlock key(reinterpret_cast(_k.data()), _k.size()); try { CryptoPP::CTR_Mode::Encryption e; - e.SetKeyWithIV(key, key.size(), _iv.data()); + e.SetKeyWithIV(key, key.size(), reinterpret_cast(_iv.data())); bytes ret(_plain.size()); - e.ProcessData(ret.data(), _plain.data(), _plain.size()); + e.ProcessData(reinterpret_cast(ret.data()), reinterpret_cast(_plain.data()), _plain.size()); return ret; } catch (CryptoPP::Exception& _e) @@ -182,13 +182,13 @@ bytesSec dev::decryptAES128CTR(bytesConstRef _k, h128 const& _iv, bytesConstRef { if (_k.size() != 16 && _k.size() != 24 && _k.size() != 32) return bytesSec(); - CryptoPP::SecByteBlock key(_k.data(), _k.size()); + CryptoPP::SecByteBlock key(reinterpret_cast(_k.data()), _k.size()); try { CryptoPP::CTR_Mode::Decryption d; - d.SetKeyWithIV(key, key.size(), _iv.data()); + d.SetKeyWithIV(key, key.size(), reinterpret_cast(_iv.data())); bytesSec ret(_cipher.size()); - d.ProcessData(ret.writable().data(), _cipher.data(), _cipher.size()); + d.ProcessData(reinterpret_cast(ret.writable().data()), reinterpret_cast(_cipher.data()), _cipher.size()); return ret; } catch (CryptoPP::Exception& _e) @@ -200,28 +200,28 @@ bytesSec dev::decryptAES128CTR(bytesConstRef _k, h128 const& _iv, bytesConstRef Public dev::recover(Signature const& _sig, h256 const& _message) { - int v = _sig[64]; + int v = to_integer(_sig[64]); if (v > 3) return {}; auto* ctx = getCtx(); secp256k1_ecdsa_recoverable_signature rawSig; - if (!secp256k1_ecdsa_recoverable_signature_parse_compact(ctx, &rawSig, _sig.data(), v)) + if (!secp256k1_ecdsa_recoverable_signature_parse_compact(ctx, &rawSig, reinterpret_cast(_sig.data()), v)) return {}; secp256k1_pubkey rawPubkey; - if (!secp256k1_ecdsa_recover(ctx, &rawPubkey, &rawSig, _message.data())) + if (!secp256k1_ecdsa_recover(ctx, &rawPubkey, &rawSig, reinterpret_cast(_message.data()))) return {}; std::array serializedPubkey; size_t serializedPubkeySize = serializedPubkey.size(); secp256k1_ec_pubkey_serialize( - ctx, serializedPubkey.data(), &serializedPubkeySize, + ctx, reinterpret_cast(serializedPubkey.data()), &serializedPubkeySize, &rawPubkey, SECP256K1_EC_UNCOMPRESSED ); assert(serializedPubkeySize == serializedPubkey.size()); // Expect single byte header of value 0x04 -- uncompressed public key. - assert(serializedPubkey[0] == 0x04); + assert(to_integer(serializedPubkey[0]) == 0x04); // Create the Public skipping the header. return Public{&serializedPubkey[1], Public::ConstructFromPointer}; } @@ -232,18 +232,18 @@ Signature dev::sign(Secret const& _k, h256 const& _hash) { auto* ctx = getCtx(); secp256k1_ecdsa_recoverable_signature rawSig; - if (!secp256k1_ecdsa_sign_recoverable(ctx, &rawSig, _hash.data(), _k.data(), nullptr, nullptr)) + if (!secp256k1_ecdsa_sign_recoverable(ctx, &rawSig, reinterpret_cast(_hash.data()), reinterpret_cast(_k.data()), nullptr, nullptr)) return {}; Signature s; int v = 0; - secp256k1_ecdsa_recoverable_signature_serialize_compact(ctx, s.data(), &v, &rawSig); + secp256k1_ecdsa_recoverable_signature_serialize_compact(ctx, reinterpret_cast(s.data()), &v, &rawSig); SignatureStruct& ss = *reinterpret_cast(&s); ss.v = static_cast(v); if (ss.s > c_secp256k1n / 2) { - ss.v = static_cast(ss.v ^ 1); + ss.v = ss.v ^ (byte)1; ss.s = h256(c_secp256k1n - u256(ss.s)); } assert(ss.s <= c_secp256k1n / 2); @@ -262,12 +262,12 @@ bytesSec dev::pbkdf2(string const& _pass, bytes const& _salt, unsigned _iteratio { bytesSec ret(_dkLen); if (CryptoPP::PKCS5_PBKDF2_HMAC().DeriveKey( - ret.writable().data(), + reinterpret_cast(ret.writable().data()), _dkLen, 0, - reinterpret_cast(_pass.data()), + reinterpret_cast(_pass.data()), _pass.size(), - _salt.data(), + reinterpret_cast(_salt.data()), _salt.size(), _iterations ) != _iterations) @@ -279,14 +279,14 @@ bytesSec dev::scrypt(std::string const& _pass, bytes const& _salt, uint64_t _n, { bytesSec ret(_dkLen); if (libscrypt_scrypt( - reinterpret_cast(_pass.data()), + reinterpret_cast(_pass.data()), _pass.size(), - _salt.data(), + reinterpret_cast(_salt.data()), _salt.size(), _n, _r, _p, - ret.writable().data(), + reinterpret_cast(ret.writable().data()), _dkLen ) != 0) BOOST_THROW_EXCEPTION(CryptoException() << errinfo_comment("Key derivation failed.")); @@ -348,14 +348,14 @@ bool ecdh::agree(Secret const& _s, Public const& _r, Secret& o_s) noexcept auto* ctx = getCtx(); static_assert(sizeof(Secret) == 32, "Invalid Secret type size"); secp256k1_pubkey rawPubkey; - std::array serializedPubKey{{0x04}}; + std::array serializedPubKey{{static_cast(0x04)}}; std::copy(_r.asArray().begin(), _r.asArray().end(), serializedPubKey.begin() + 1); - if (!secp256k1_ec_pubkey_parse(ctx, &rawPubkey, serializedPubKey.data(), serializedPubKey.size())) + if (!secp256k1_ec_pubkey_parse(ctx, &rawPubkey, reinterpret_cast(serializedPubKey.data()), serializedPubKey.size())) return false; // Invalid public key. // FIXME: We should verify the public key when constructed, maybe even keep // secp256k1_pubkey as the internal data of Public. std::array compressedPoint; - if (!secp256k1_ecdh_raw(ctx, compressedPoint.data(), &rawPubkey, _s.data())) + if (!secp256k1_ecdh_raw(ctx, reinterpret_cast(compressedPoint.data()), &rawPubkey, reinterpret_cast(_s.data()))) return false; // Invalid secret key. std::copy(compressedPoint.begin() + 1, compressedPoint.end(), o_s.writable().data()); return true; @@ -367,23 +367,24 @@ bytes ecies::kdf(Secret const& _z, bytes const& _s1, unsigned kdByteLen) // SEC/ISO/Shoup specify counter size SHOULD be equivalent // to size of hash output, however, it also notes that // the 4 bytes is okay. NIST specifies 4 bytes. - std::array ctr{{0, 0, 0, 1}}; + std::array ctr{{(byte)0, (byte)0, (byte)0, (byte)1}}; bytes k; secp256k1_sha256_t ctx; for (unsigned i = 0; i <= reps; i++) { secp256k1_sha256_initialize(&ctx); - secp256k1_sha256_write(&ctx, ctr.data(), ctr.size()); - secp256k1_sha256_write(&ctx, _z.data(), Secret::size); - secp256k1_sha256_write(&ctx, _s1.data(), _s1.size()); + secp256k1_sha256_write(&ctx, reinterpret_cast(ctr.data()), ctr.size()); + secp256k1_sha256_write(&ctx, reinterpret_cast(_z.data()), Secret::size); + secp256k1_sha256_write(&ctx, reinterpret_cast(_s1.data()), _s1.size()); // append hash to k std::array digest; - secp256k1_sha256_finalize(&ctx, digest.data()); + secp256k1_sha256_finalize(&ctx, reinterpret_cast(digest.data())); k.reserve(k.size() + h256::size); move(digest.begin(), digest.end(), back_inserter(k)); - if (++ctr[3] || ++ctr[2] || ++ctr[1] || ++ctr[0]) + for (string::size_type i = 0; i < ctr.size(); i++) ctr[i] = byte(to_integer(ctr[i]) + 1); + if (to_integer(ctr[3]) || to_integer(ctr[2]) || to_integer(ctr[1]) || to_integer(ctr[0])) continue; } diff --git a/libdevcrypto/Common.h b/libdevcrypto/Common.h index 8da7d7bc7fd..cc4739ab3d5 100644 --- a/libdevcrypto/Common.h +++ b/libdevcrypto/Common.h @@ -55,7 +55,7 @@ struct SignatureStruct h256 r; h256 s; - byte v = 0; + byte v = static_cast(0); }; /// A vector of secrets. diff --git a/libdevcrypto/CryptoPP.cpp b/libdevcrypto/CryptoPP.cpp index 4205f77be6a..8bd9788935c 100644 --- a/libdevcrypto/CryptoPP.cpp +++ b/libdevcrypto/CryptoPP.cpp @@ -67,9 +67,9 @@ class Secp256k1PPCtx {} }; -inline CryptoPP::ECP::Point publicToPoint(Public const& _p) { CryptoPP::Integer x(_p.data(), 32); CryptoPP::Integer y(_p.data() + 32, 32); return CryptoPP::ECP::Point(x,y); } +inline CryptoPP::ECP::Point publicToPoint(Public const& _p) { CryptoPP::Integer x(reinterpret_cast(_p.data()), 32); CryptoPP::Integer y(reinterpret_cast(_p.data()) + 32, 32); return CryptoPP::ECP::Point(x,y); } -inline CryptoPP::Integer secretToExponent(Secret const& _s) { return CryptoPP::Integer(_s.data(), Secret::size); } +inline CryptoPP::Integer secretToExponent(Secret const& _s) { return CryptoPP::Integer(reinterpret_cast(_s.data()), Secret::size); } } @@ -94,9 +94,9 @@ void Secp256k1PP::encryptECIES(Public const& _k, bytesConstRef _sharedMacData, b bytesConstRef eKey = bytesConstRef(&key).cropped(0, 16); bytesRef mKeyMaterial = bytesRef(&key).cropped(16, 16); CryptoPP::SHA256 ctx; - ctx.Update(mKeyMaterial.data(), mKeyMaterial.size()); + ctx.Update(reinterpret_cast(mKeyMaterial.data()), mKeyMaterial.size()); bytes mKey(32); - ctx.Final(mKey.data()); + ctx.Final(reinterpret_cast(mKey.data())); auto iv = h128::random(); bytes cipherText = encryptSymNoAuth(SecureFixedHash<16>(eKey), iv, bytesConstRef(&io_cipher)); @@ -104,18 +104,18 @@ void Secp256k1PP::encryptECIES(Public const& _k, bytesConstRef _sharedMacData, b return; bytes msg(1 + Public::size + h128::size + cipherText.size() + 32); - msg[0] = 0x04; + msg[0] = (byte)0x04; r.pub().ref().copyTo(bytesRef(&msg).cropped(1, Public::size)); iv.ref().copyTo(bytesRef(&msg).cropped(1 + Public::size, h128::size)); bytesRef msgCipherRef = bytesRef(&msg).cropped(1 + Public::size + h128::size, cipherText.size()); bytesConstRef(&cipherText).copyTo(msgCipherRef); // tag message - CryptoPP::HMAC hmacctx(mKey.data(), mKey.size()); + CryptoPP::HMAC hmacctx(reinterpret_cast(mKey.data()), mKey.size()); bytesConstRef cipherWithIV = bytesRef(&msg).cropped(1 + Public::size, h128::size + cipherText.size()); - hmacctx.Update(cipherWithIV.data(), cipherWithIV.size()); - hmacctx.Update(_sharedMacData.data(), _sharedMacData.size()); - hmacctx.Final(msg.data() + 1 + Public::size + cipherWithIV.size()); + hmacctx.Update(reinterpret_cast(cipherWithIV.data()), cipherWithIV.size()); + hmacctx.Update(reinterpret_cast(_sharedMacData.data()), _sharedMacData.size()); + hmacctx.Final(reinterpret_cast(msg.data()) + 1 + Public::size + cipherWithIV.size()); io_cipher.resize(msg.size()); io_cipher.swap(msg); @@ -132,7 +132,7 @@ bool Secp256k1PP::decryptECIES(Secret const& _k, bytesConstRef _sharedMacData, b // interop w/go ecies implementation // io_cipher[0] must be 2, 3, or 4, else invalidpublickey - if (io_text.empty() || io_text[0] < 2 || io_text[0] > 4) + if (io_text.empty() || to_integer(io_text[0]) < 2 || to_integer(io_text[0]) > 4) // invalid message: publickey return false; @@ -148,8 +148,8 @@ bool Secp256k1PP::decryptECIES(Secret const& _k, bytesConstRef _sharedMacData, b bytesRef mKeyMaterial = bytesRef(&key).cropped(16, 16); bytes mKey(32); CryptoPP::SHA256 ctx; - ctx.Update(mKeyMaterial.data(), mKeyMaterial.size()); - ctx.Final(mKey.data()); + ctx.Update(reinterpret_cast(mKeyMaterial.data()), mKeyMaterial.size()); + ctx.Final(reinterpret_cast(mKey.data())); bytes plain; size_t cipherLen = io_text.size() - 1 - Public::size - h128::size - h256::size; @@ -160,11 +160,11 @@ bool Secp256k1PP::decryptECIES(Secret const& _k, bytesConstRef _sharedMacData, b h128 iv(cipherIV.toBytes()); // verify tag - CryptoPP::HMAC hmacctx(mKey.data(), mKey.size()); - hmacctx.Update(cipherWithIV.data(), cipherWithIV.size()); - hmacctx.Update(_sharedMacData.data(), _sharedMacData.size()); + CryptoPP::HMAC hmacctx(reinterpret_cast(mKey.data()), mKey.size()); + hmacctx.Update(reinterpret_cast(cipherWithIV.data()), cipherWithIV.size()); + hmacctx.Update(reinterpret_cast(_sharedMacData.data()), _sharedMacData.size()); h256 mac; - hmacctx.Final(mac.data()); + hmacctx.Final(reinterpret_cast(mac.data())); for (unsigned i = 0; i < h256::size; i++) if (mac[i] != msgMac[i]) return false; @@ -200,7 +200,7 @@ void Secp256k1PP::encrypt(Public const& _k, bytes& io_cipher) { Guard l(ctx.x_rng); - e.Encrypt(ctx.m_rng, io_cipher.data(), plen, ciphertext.data()); + e.Encrypt(ctx.m_rng, reinterpret_cast(io_cipher.data()), plen, reinterpret_cast(ciphertext.data())); } memset(io_cipher.data(), 0, io_cipher.size()); @@ -227,7 +227,7 @@ void Secp256k1PP::decrypt(Secret const& _k, bytes& io_text) if (!io_text.size()) { io_text.resize(1); - io_text[0] = 0; + io_text[0] = (byte)0; } size_t clen = io_text.size(); @@ -237,7 +237,7 @@ void Secp256k1PP::decrypt(Secret const& _k, bytes& io_text) CryptoPP::DecodingResult r; { Guard l(ctx.x_rng); - r = d.Decrypt(ctx.m_rng, io_text.data(), clen, plain.data()); + r = d.Decrypt(ctx.m_rng, reinterpret_cast(io_text.data()), clen, reinterpret_cast(plain.data())); } if (!r.isValidCoding) diff --git a/libdevcrypto/Hash.cpp b/libdevcrypto/Hash.cpp index c4c6cab38a1..36c5d5bf761 100644 --- a/libdevcrypto/Hash.cpp +++ b/libdevcrypto/Hash.cpp @@ -31,9 +31,9 @@ h256 sha256(bytesConstRef _input) noexcept { secp256k1_sha256_t ctx; secp256k1_sha256_initialize(&ctx); - secp256k1_sha256_write(&ctx, _input.data(), _input.size()); + secp256k1_sha256_write(&ctx, reinterpret_cast(_input.data(), _input.size()), _input.size()); h256 hash; - secp256k1_sha256_finalize(&ctx, hash.data()); + secp256k1_sha256_finalize(&ctx, reinterpret_cast(hash.data())); return hash; } @@ -425,10 +425,10 @@ h160 ripemd160(bytesConstRef _input) for (unsigned i = 0; i < RMDsize / 8; i += 4) { - hashcode[i] = buffer[i >> 2]; // implicit cast to byte - hashcode[i + 1] = (buffer[i >> 2] >> 8); //extracts the 8 least - hashcode[i + 2] = (buffer[i >> 2] >> 16); // significant bits. - hashcode[i + 3] = (buffer[i >> 2] >> 24); + hashcode[i] = static_cast(buffer[i >> 2]); // implicit cast to byte + hashcode[i + 1] = static_cast(buffer[i >> 2] >> 8); //extracts the 8 least + hashcode[i + 2] = static_cast(buffer[i >> 2] >> 16); // significant bits. + hashcode[i + 3] = static_cast(buffer[i >> 2] >> 24); } return hashcode; diff --git a/libdevcrypto/LibSnark.cpp b/libdevcrypto/LibSnark.cpp index fbd7e387b66..b9408fad1c8 100644 --- a/libdevcrypto/LibSnark.cpp +++ b/libdevcrypto/LibSnark.cpp @@ -67,7 +67,7 @@ h256 fromLibsnarkBigint(libff::bigint const& _b) h256 x; for (size_t i = 0; i < N; i++) for (size_t j = 0; j < L; j++) - x[i * L + j] = uint8_t(_b.data[N - 1 - i] >> (8 * (L - 1 - j))); + x[i * L + j] = static_cast(_b.data[N - 1 - i] >> (8 * (L - 1 - j))); return x; } @@ -97,7 +97,7 @@ libff::alt_bn128_G1 decodePointG1(dev::bytesConstRef _data) bytes encodePointG1(libff::alt_bn128_G1 _p) { if (_p.is_zero()) - return bytes(64, 0); + return bytes(64, static_cast(0)); _p.to_affine_coordinates(); return fromLibsnarkBigint(_p.X.as_bigint()).asBytes() + diff --git a/libethashseal/Ethash.cpp b/libethashseal/Ethash.cpp index 37c1c4b99c8..9917d55be5e 100644 --- a/libethashseal/Ethash.cpp +++ b/libethashseal/Ethash.cpp @@ -299,7 +299,7 @@ void Ethash::generateSeal(BlockHeader const& _bi) m_farm.setWork(m_sealing); // TODO: take out one before or one after... } bytes shouldPrecompute = option("precomputeDAG"); - if (!shouldPrecompute.empty() && shouldPrecompute[0] == 1) + if (!shouldPrecompute.empty() && to_integer(shouldPrecompute[0]) == 1) ensurePrecomputed((unsigned)_bi.number()); } diff --git a/libethashseal/EthashAux.cpp b/libethashseal/EthashAux.cpp index e6ee864089d..bb62afeab80 100644 --- a/libethashseal/EthashAux.cpp +++ b/libethashseal/EthashAux.cpp @@ -236,7 +236,7 @@ EthashProofOfWork::Result EthashAux::FullAllocation::compute(h256 const& _header ethash_return_value_t r = ethash_full_compute(full, *(ethash_h256_t*)_headerHash.data(), (uint64_t)(u64)_nonce); if (!r.success) BOOST_THROW_EXCEPTION(DAGCreationFailure()); - return EthashProofOfWork::Result{h256((uint8_t*)&r.result, h256::ConstructFromPointer), h256((uint8_t*)&r.mix_hash, h256::ConstructFromPointer)}; + return EthashProofOfWork::Result{h256((byte*)&r.result, h256::ConstructFromPointer), h256((byte*)&r.mix_hash, h256::ConstructFromPointer)}; } EthashProofOfWork::Result EthashAux::LightAllocation::compute(h256 const& _headerHash, Nonce const& _nonce) const @@ -244,7 +244,7 @@ EthashProofOfWork::Result EthashAux::LightAllocation::compute(h256 const& _heade ethash_return_value r = ethash_light_compute(light, *(ethash_h256_t*)_headerHash.data(), (uint64_t)(u64)_nonce); if (!r.success) BOOST_THROW_EXCEPTION(DAGCreationFailure()); - return EthashProofOfWork::Result{h256((uint8_t*)&r.result, h256::ConstructFromPointer), h256((uint8_t*)&r.mix_hash, h256::ConstructFromPointer)}; + return EthashProofOfWork::Result{h256((byte*)&r.result, h256::ConstructFromPointer), h256((byte*)&r.mix_hash, h256::ConstructFromPointer)}; } EthashProofOfWork::Result EthashAux::eval(h256 const& _seedHash, h256 const& _headerHash, Nonce const& _nonce) diff --git a/libethashseal/EthashCPUMiner.cpp b/libethashseal/EthashCPUMiner.cpp index 13a0ff54013..99f5aa093f2 100644 --- a/libethashseal/EthashCPUMiner.cpp +++ b/libethashseal/EthashCPUMiner.cpp @@ -78,8 +78,8 @@ void EthashCPUMiner::workLoop() for (; !shouldStop(); tryNonce++, hashCount++) { ethashReturn = ethash_full_compute(dag->full, *(ethash_h256_t*)w.headerHash().data(), tryNonce); - h256 value = h256((uint8_t*)ðashReturn.result, h256::ConstructFromPointer); - if (value <= boundary && submitProof(EthashProofOfWork::Solution{(h64)(u64)tryNonce, h256((uint8_t*)ðashReturn.mix_hash, h256::ConstructFromPointer)})) + h256 value = h256((byte*)ðashReturn.result, h256::ConstructFromPointer); + if (value <= boundary && submitProof(EthashProofOfWork::Solution{(h64)(u64)tryNonce, h256((byte*)ðashReturn.mix_hash, h256::ConstructFromPointer)})) break; if (!(hashCount % 100)) accumulateHashes(100); diff --git a/libethcore/KeyManager.cpp b/libethcore/KeyManager.cpp index 0e3ff6cd511..1ef4efdf595 100644 --- a/libethcore/KeyManager.cpp +++ b/libethcore/KeyManager.cpp @@ -231,7 +231,7 @@ Secret KeyManager::brain(string const& _seed) r = sha3(r); Secret ret(r); r.ref().cleanse(); - while (toAddress(ret)[0]) + while (to_integer(toAddress(ret)[0])) ret = sha3(ret); return ret; } @@ -453,7 +453,7 @@ KeyPair KeyManager::newKeyPair(KeyManager::NewKeyType _type) lp = KeyPair::create(); auto a = lp.address(); if (_type == NewKeyType::NoVanity || - (_type == NewKeyType::DirectICAP && !a[0]) || + (_type == NewKeyType::DirectICAP && !to_integer(a[0])) || (_type == NewKeyType::FirstTwo && a[0] == a[1]) || (_type == NewKeyType::FirstTwoNextTwo && a[0] == a[1] && a[2] == a[3]) || (_type == NewKeyType::FirstThree && a[0] == a[1] && a[1] == a[2]) || diff --git a/libethcore/TransactionBase.cpp b/libethcore/TransactionBase.cpp index cd062505aff..98290e4f870 100644 --- a/libethcore/TransactionBase.cpp +++ b/libethcore/TransactionBase.cpp @@ -71,7 +71,7 @@ TransactionBase::TransactionBase(bytesConstRef _rlpData, CheckTransaction _check if (isZeroSignature(r, s)) { m_chainId = v; - m_vrs = SignatureStruct{r, s, 0}; + m_vrs = SignatureStruct{r, s, static_cast(0)}; } else { @@ -172,7 +172,7 @@ void TransactionBase::streamRLP(RLPStream& _s, IncludeSignature _sig, bool _forE else { int const vOffset = m_chainId * 2 + 35; - _s << (m_vrs->v + vOffset); + _s << (to_integer(m_vrs->v) + vOffset); } _s << (u256)m_vrs->r << (u256)m_vrs->s; } @@ -205,7 +205,7 @@ int64_t TransactionBase::baseGasRequired(bool _contractCreation, bytesConstRef _ // No risk of overflow by using int64 until txDataNonZeroGas is quite small // (the value not in billions). for (auto i: _data) - g += i ? _es.txDataNonZeroGas : _es.txDataZeroGas; + g += to_integer(i) ? _es.txDataNonZeroGas : _es.txDataZeroGas; return g; } diff --git a/libethereum/BlockChain.cpp b/libethereum/BlockChain.cpp index 235a43cfac4..83c9f9590d0 100644 --- a/libethereum/BlockChain.cpp +++ b/libethereum/BlockChain.cpp @@ -97,7 +97,7 @@ ldb::Slice dev::eth::toSlice(h256 const& _h, unsigned _sub) if (!t_h.get()) t_h.reset(new FixedHash<33>); *t_h = FixedHash<33>(_h); - (*t_h)[32] = (uint8_t)_sub; + (*t_h)[32] = (byte)_sub; return (ldb::Slice)t_h->ref(); #endif //ALL_COMPILERS_ARE_CPP11_COMPLIANT } @@ -115,7 +115,7 @@ ldb::Slice dev::eth::toSlice(uint64_t _n, unsigned _sub) t_h.reset(new FixedHash<33>); bytesRef ref(t_h->data() + 24, 8); toBigEndian(_n, ref); - (*t_h)[32] = (uint8_t)_sub; + (*t_h)[32] = (byte)_sub; return (ldb::Slice)t_h->ref(); #endif } diff --git a/libethereum/CommonNet.h b/libethereum/CommonNet.h index 592e01711c2..ea72e2b45ea 100644 --- a/libethereum/CommonNet.h +++ b/libethereum/CommonNet.h @@ -57,7 +57,7 @@ class TransactionQueue; class EthereumHost; class EthereumPeer; -enum SubprotocolPacketType: byte +enum SubprotocolPacketType { StatusPacket = 0x00, NewBlockHashesPacket = 0x01, diff --git a/libethereum/SnapshotImporter.cpp b/libethereum/SnapshotImporter.cpp index cfccf7d5e6a..1280505e9b8 100644 --- a/libethereum/SnapshotImporter.cpp +++ b/libethereum/SnapshotImporter.cpp @@ -138,8 +138,8 @@ void SnapshotImporter::importStateChunks(SnapshotStorageFace const& _snapshotSto storageMap.emplace(keyHash, std::move(value)); } - byte const codeFlag = account[2].toInt(RLP::VeryStrict); - switch (codeFlag) + byte const codeFlag = static_cast(account[2].toInt(RLP::VeryStrict)); + switch (to_integer(codeFlag)) { case 0: codeHash = EmptySHA3; diff --git a/libevm/ExtVMFace.cpp b/libevm/ExtVMFace.cpp index d6305f0d8b8..2d2ee816b14 100644 --- a/libevm/ExtVMFace.cpp +++ b/libevm/ExtVMFace.cpp @@ -89,14 +89,14 @@ void getBalance( *o_result = toEvmC(env.balance(fromEvmC(*_addr))); } -size_t getCode(byte const** o_code, evm_context* _context, evm_address const* _addr) +size_t getCode(uint8_t const** o_code, evm_context* _context, evm_address const* _addr) { auto& env = static_cast(*_context); Address addr = fromEvmC(*_addr); if (o_code != nullptr) { auto& code = env.codeAt(addr); - *o_code = code.data(); + *o_code = reinterpret_cast(code.data()); return code.size(); } return env.codeSizeAt(addr); @@ -129,7 +129,7 @@ void log( assert(fromEvmC(*_addr) == env.myAddress); h256 const* pTopics = reinterpret_cast(_topics); env.log(h256s{pTopics, pTopics + _numTopics}, - bytesConstRef{_data, _dataSize}); + bytesConstRef{reinterpret_cast(_data), _dataSize}); } void getTxContext(evm_tx_context* result, evm_context* _context) noexcept @@ -154,7 +154,7 @@ void create(evm_result* o_result, ExtVMFace& _env, evm_message const* _msg) noex { u256 gas = _msg->gas; u256 value = fromEvmC(_msg->value); - bytesConstRef init = {_msg->input, _msg->input_size}; + bytesConstRef init = {reinterpret_cast(_msg->input), _msg->input_size}; // ExtVM::create takes the sender address from .myAddress. assert(fromEvmC(_msg->sender) == _env.myAddress); @@ -170,7 +170,10 @@ void create(evm_result* o_result, ExtVMFace& _env, evm_message const* _msg) noex // Use reserved data to store the address. static_assert(sizeof(o_result->reserved.data) >= addr.size, "Not enough space to store an address"); - std::copy(addr.begin(), addr.end(), o_result->reserved.data); + std::vector uca; + for (unsigned i = 0; i < addr.size; i++) + uca.push_back(to_integer(addr[i])); + std::copy(uca.begin(), uca.end(), o_result->reserved.data); o_result->output_data = o_result->reserved.data; o_result->output_size = addr.size; } else @@ -182,7 +185,7 @@ void create(evm_result* o_result, ExtVMFace& _env, evm_message const* _msg) noex // First assign reference. References are not invalidated when vector // of bytes is moved. See `.takeBytes()` below. - o_result->output_data = output.data(); + o_result->output_data = reinterpret_cast(output.data()); o_result->output_size = output.size(); // Place a new vector of bytes containing output in result's reserved memory. @@ -218,7 +221,7 @@ void call(evm_result* o_result, evm_context* _context, evm_message const* _msg) params.codeAddress = fromEvmC(_msg->address); params.receiveAddress = _msg->kind == EVM_CALL ? params.codeAddress : env.myAddress; - params.data = {_msg->input, _msg->input_size}; + params.data = {reinterpret_cast(_msg->input), _msg->input_size}; params.staticCall = (_msg->flags & EVM_STATIC) != 0; params.onOp = {}; @@ -237,7 +240,7 @@ void call(evm_result* o_result, evm_context* _context, evm_message const* _msg) // First assign reference. References are not invalidated when vector // of bytes is moved. See `.takeBytes()` below. - o_result->output_data = output.data(); + o_result->output_data = reinterpret_cast(output.data()); o_result->output_size = output.size(); // Place a new vector of bytes containing output in result's reserved memory. diff --git a/libevm/VM.cpp b/libevm/VM.cpp index 21101b7a6af..964a9079468 100755 --- a/libevm/VM.cpp +++ b/libevm/VM.cpp @@ -57,8 +57,8 @@ template S modWorkaround(S const& _a, S const& _b) uint64_t VM::decodeJumpDest(const byte* const _code, uint64_t& _pc) { // turn 2 MSB-first bytes in the code into a native-order integer - uint64_t dest = _code[_pc++]; - dest = (dest << 8) | _code[_pc++]; + uint64_t dest = to_integer(_code[_pc++]); + dest = (dest << 8) | to_integer(_code[_pc++]); return dest; } @@ -71,12 +71,12 @@ uint64_t VM::decodeJumpvDest(const byte* const _code, uint64_t& _pc, byte _voff) // uint64_t pc = _pc; byte n = _code[++pc]; // byte after opcode is number of jumps - if (_voff >= n) _voff = n - 1; // if offset overflows use default jump - pc += _voff * 2; // adjust inout pc before index destination in table + if (_voff >= n) _voff = (byte)(to_integer(n) - 1); // if offset overflows use default jump + pc += to_integer(_voff) * 2; // adjust inout pc before index destination in table uint64_t dest = decodeJumpDest(_code, pc); - _pc += 1 + n * 2; // adust inout _pc to opcode after table + _pc += 1 + to_integer(n) * 2; // adust inout _pc to opcode after table return dest; } @@ -359,7 +359,7 @@ void VM::interpretCases() updateMem(toInt63(m_SP[0]) + 1); updateIOGas(); - m_mem[(unsigned)m_SP[0]] = (byte)(m_SP[1] & 0xff); + m_mem[(unsigned)m_SP[0]] = static_cast((unsigned char)(m_SP[1] & 0xff)); } NEXT @@ -1176,7 +1176,7 @@ void VM::interpretCases() else { h256 r; for (uint64_t i = (uint64_t)m_SP[0], e = (uint64_t)m_SP[0] + (uint64_t)32, j = 0; i < e; ++i, ++j) - r[j] = i < m_ext->data.size() ? m_ext->data[i] : 0; + r[j] = i < m_ext->data.size() ? m_ext->data[i] : static_cast(0); m_SP[0] = (u256)r; }; } @@ -1359,9 +1359,9 @@ void VM::interpretCases() TRACE_OP(2, m_PC, m_OP); unsigned off; ++m_PC; - off = m_code[m_PC++] << 8; - off |= m_code[m_PC++]; - m_PC += m_code[m_PC]; + off = to_integer(m_code[m_PC++]) << 8; + off |= to_integer(m_code[m_PC++]); + m_PC += to_integer(m_code[m_PC]); m_SPP[0] = m_pool[off]; TRACE_VAL(2, "Retrieved pooled const", m_SPP[0]); #else @@ -1375,7 +1375,7 @@ void VM::interpretCases() ON_OP(); updateIOGas(); ++m_PC; - m_SPP[0] = m_code[m_PC]; + m_SPP[0] = to_integer(m_code[m_PC]); ++m_PC; } CONTINUE @@ -1421,7 +1421,7 @@ void VM::interpretCases() // This requires the code has been copied and extended by 32 zero // bytes to handle "out of code" push data here. for (++m_PC; numBytes--; ++m_PC) - m_SPP[0] = (m_SPP[0] << 8) | m_code[m_PC]; + m_SPP[0] = (m_SPP[0] << 8) | to_integer(m_code[m_PC]); } CONTINUE diff --git a/libevm/VMOpt.cpp b/libevm/VMOpt.cpp index dec5e787ccc..ed1b5878956 100755 --- a/libevm/VMOpt.cpp +++ b/libevm/VMOpt.cpp @@ -95,7 +95,7 @@ void VM::optimize() (byte)op <= (byte)Instruction::PUSH32 ) { - pc += (byte)op - (byte)Instruction::PUSH1 + 1; + pc += (static_cast(op) - static_cast(Instruction::PUSH1) + 1); } #if EIP_615 else if ( @@ -132,12 +132,12 @@ void VM::optimize() if ((byte)Instruction::PUSH1 <= (byte)op && (byte)op <= (byte)Instruction::PUSH32) { - byte nPush = (byte)op - (byte)Instruction::PUSH1 + 1; + byte nPush = (byte)(static_cast(op) - static_cast(Instruction::PUSH1) + 1); // decode pushed bytes to integral value - val = m_code[pc+1]; - for (uint64_t i = pc+2, n = nPush; --n; ++i) { - val = (val << 8) | m_code[i]; + val = to_integer(m_code[pc+1]); + for (uint64_t i = pc+2, n = to_integer(nPush); --n; ++i) { + val = (val << 8) | to_integer(m_code[i]); } #if EVM_USE_CONSTANT_POOL @@ -145,7 +145,7 @@ void VM::optimize() // add value to constant pool and replace PUSHn with PUSHC // place offset in code as 2 bytes MSB-first // followed by one byte count of remaining pushed bytes - if (5 < nPush) + if (5 < to_integer(nPush)) { uint16_t pool_off = m_pool.size(); TRACE_VAL(1, "stash", val); @@ -154,9 +154,9 @@ void VM::optimize() TRACE_PRE_OPT(1, pc, op); m_code[pc] = byte(op = Instruction::PUSHC); - m_code[pc+3] = nPush - 2; - m_code[pc+2] = pool_off & 0xff; - m_code[pc+1] = pool_off >> 8; + m_code[pc+3] = byte(to_integer(nPush) - 2); + m_code[pc+2] = (byte)(pool_off & 0xff); + m_code[pc+1] = (byte)(pool_off >> 8); TRACE_POST_OPT(1, pc, op); } @@ -167,7 +167,7 @@ void VM::optimize() // verifyJumpDest is M = log(number of jump destinations) // outer loop is N = number of bytes in code array // so complexity is N log M, worst case is N log N - size_t i = pc + nPush + 1; + size_t i = pc + to_integer(nPush) + 1; op = Instruction(m_code[i]); if (op == Instruction::JUMP) { @@ -191,7 +191,7 @@ void VM::optimize() } #endif - pc += nPush; + pc += to_integer(nPush); } } TRACE_STR(1, "Finished optimizations") diff --git a/libp2p/Capability.cpp b/libp2p/Capability.cpp index 6dd14152b11..27113a1ffec 100644 --- a/libp2p/Capability.cpp +++ b/libp2p/Capability.cpp @@ -42,7 +42,7 @@ void Capability::disable(std::string const& _problem) RLPStream& Capability::prep(RLPStream& _s, unsigned _id, unsigned _args) { - return _s.appendRaw(bytes(1, _id + m_idOffset)).appendList(_args); + return _s.appendRaw(bytes(1, static_cast(_id + m_idOffset))).appendList(_args); } void Capability::sealAndSend(RLPStream& _s) diff --git a/libp2p/Common.cpp b/libp2p/Common.cpp index 15f7a303f18..2147433bbe5 100644 --- a/libp2p/Common.cpp +++ b/libp2p/Common.cpp @@ -157,9 +157,9 @@ void NodeIPEndpoint::streamRLP(RLPStream& _s, RLPAppend _append) const if (_append == StreamList) _s.appendList(3); if (address.is_v4()) - _s << bytesConstRef(&address.to_v4().to_bytes()[0], 4); + _s << bytesConstRef(reinterpret_cast(&address.to_v4().to_bytes()[0]), 4); else if (address.is_v6()) - _s << bytesConstRef(&address.to_v6().to_bytes()[0], 16); + _s << bytesConstRef(reinterpret_cast(&address.to_v6().to_bytes()[0]), 16); else _s << bytes(); _s << udpPort << tcpPort; diff --git a/libp2p/Host.cpp b/libp2p/Host.cpp index 260a04a36ba..c1a98539482 100644 --- a/libp2p/Host.cpp +++ b/libp2p/Host.cpp @@ -921,7 +921,7 @@ void Host::restoreNetwork(bytesConstRef _b) } else if (i.itemCount() == 3 || i.itemCount() == 10) { - Node n((NodeID)i[2], NodeIPEndpoint(bi::address_v4(i[0].toArray()), i[1].toInt(), i[1].toInt())); + Node n((NodeID)i[2], NodeIPEndpoint(bi::address_v4(i[0].toArray()), i[1].toInt(), i[1].toInt())); if (i.itemCount() == 3 && n.endpoint.isAllowed()) addNodeToNodeTable(n); else if (i.itemCount() == 10) diff --git a/libp2p/NodeTable.cpp b/libp2p/NodeTable.cpp index 6e2d78eb925..dd3d095e673 100644 --- a/libp2p/NodeTable.cpp +++ b/libp2p/NodeTable.cpp @@ -611,7 +611,7 @@ unique_ptr DiscoveryDatagram::interpretUDP(bi::udp::endpoint clog(NodeTableWarn) << "Invalid packet (bad signature) from " << _from.address().to_string() << ":" << _from.port(); return decoded; } - switch (signedBytes[0]) + switch (to_integer(signedBytes[0])) { case PingNode::type: decoded.reset(new PingNode(_from, sourceid, echo)); diff --git a/libp2p/RLPXFrameCoder.cpp b/libp2p/RLPXFrameCoder.cpp index 392ea12954e..65db8ce9757 100644 --- a/libp2p/RLPXFrameCoder.cpp +++ b/libp2p/RLPXFrameCoder.cpp @@ -35,7 +35,7 @@ using namespace dev; using namespace dev::p2p; RLPXFrameInfo::RLPXFrameInfo(bytesConstRef _header): - length((_header[0] * 256 + _header[1]) * 256 + _header[2]), + length(to_integer(_header[0]) * 256 + to_integer(_header[1]) * 256 + to_integer(_header[2])), padding((16 - (length % 16)) % 16), data(_header.cropped(3).toBytes()), header(RLP(data, RLP::ThrowOnFail | RLP::FailIfTooSmall)), @@ -121,8 +121,8 @@ void RLPXFrameCoder::setup(bool _originated, h512 const& _remoteEphemeral, h256 m_impl->frameDecKey.resize(h256::size); memcpy(m_impl->frameDecKey.data(), outRef.data(), h256::size); h128 iv; - m_impl->frameEnc.SetKeyWithIV(m_impl->frameEncKey, h256::size, iv.data()); - m_impl->frameDec.SetKeyWithIV(m_impl->frameDecKey, h256::size, iv.data()); + m_impl->frameEnc.SetKeyWithIV(m_impl->frameEncKey, h256::size, reinterpret_cast(iv.data())); + m_impl->frameDec.SetKeyWithIV(m_impl->frameDecKey, h256::size, reinterpret_cast(iv.data())); // mac-secret = sha3(ecdhe-shared-secret || aes-secret) sha3(keyMaterial, outRef); // output mac-secret @@ -140,7 +140,7 @@ void RLPXFrameCoder::setup(bool _originated, h512 const& _remoteEphemeral, h256 keyMaterialBytes.resize(h256::size + egressCipher.size()); keyMaterial.retarget(keyMaterialBytes.data(), keyMaterialBytes.size()); egressCipher.copyTo(keyMaterial.cropped(h256::size, egressCipher.size())); - m_impl->egressMac.Update(keyMaterial.data(), keyMaterial.size()); + m_impl->egressMac.Update(reinterpret_cast(keyMaterial.data()), keyMaterial.size()); // recover mac-secret by re-xoring remoteNonce (*(h256*)keyMaterial.data() ^ _remoteNonce ^ _nonce).ref().copyTo(keyMaterial); @@ -148,7 +148,7 @@ void RLPXFrameCoder::setup(bool _originated, h512 const& _remoteEphemeral, h256 keyMaterialBytes.resize(h256::size + ingressCipher.size()); keyMaterial.retarget(keyMaterialBytes.data(), keyMaterialBytes.size()); ingressCipher.copyTo(keyMaterial.cropped(h256::size, ingressCipher.size())); - m_impl->ingressMac.Update(keyMaterial.data(), keyMaterial.size()); + m_impl->ingressMac.Update(reinterpret_cast(keyMaterial.data()), keyMaterial.size()); } void RLPXFrameCoder::writeFrame(uint16_t _protocolType, bytesConstRef _payload, bytes& o_bytes) @@ -183,7 +183,7 @@ void RLPXFrameCoder::writeFrame(RLPStream const& _header, bytesConstRef _payload // TODO: SECURITY check header values && header <= 16 bytes bytes headerWithMac(h256::size); bytesConstRef(&_header.out()).copyTo(bytesRef(&headerWithMac)); - m_impl->frameEnc.ProcessData(headerWithMac.data(), headerWithMac.data(), 16); + m_impl->frameEnc.ProcessData(reinterpret_cast(headerWithMac.data()), reinterpret_cast(headerWithMac.data()), 16); updateEgressMACWithHeader(bytesConstRef(&headerWithMac).cropped(0, 16)); egressDigest().ref().copyTo(bytesRef(&headerWithMac).cropped(h128::size,h128::size)); @@ -191,10 +191,10 @@ void RLPXFrameCoder::writeFrame(RLPStream const& _header, bytesConstRef _payload o_bytes.swap(headerWithMac); o_bytes.resize(32 + _payload.size() + padding + h128::size); bytesRef packetRef(o_bytes.data() + 32, _payload.size()); - m_impl->frameEnc.ProcessData(packetRef.data(), _payload.data(), _payload.size()); + m_impl->frameEnc.ProcessData(reinterpret_cast(packetRef.data()), reinterpret_cast(_payload.data()), _payload.size()); bytesRef paddingRef(o_bytes.data() + 32 + _payload.size(), padding); if (padding) - m_impl->frameEnc.ProcessData(paddingRef.data(), paddingRef.data(), padding); + m_impl->frameEnc.ProcessData(reinterpret_cast(paddingRef.data()), reinterpret_cast(paddingRef.data()), padding); bytesRef packetWithPaddingRef(o_bytes.data() + 32, _payload.size() + padding); updateEgressMACWithFrame(packetWithPaddingRef); bytesRef macRef(o_bytes.data() + 32 + _payload.size() + padding, h128::size); @@ -206,7 +206,7 @@ void RLPXFrameCoder::writeSingleFramePacket(bytesConstRef _packet, bytes& o_byte RLPStream header; uint32_t len = (uint32_t)_packet.size(); header.appendRaw(bytes({byte((len >> 16) & 0xff), byte((len >> 8) & 0xff), byte(len & 0xff)})); - header.appendRaw(bytes({0xc2,0x80,0x80})); + header.appendRaw(bytes({static_cast(0xc2),static_cast(0x80),static_cast(0x80)})); writeFrame(header, _packet, o_bytes); } @@ -218,7 +218,7 @@ bool RLPXFrameCoder::authAndDecryptHeader(bytesRef io) h128 expected = ingressDigest(); if (*(h128*)macRef.data() != expected) return false; - m_impl->frameDec.ProcessData(io.data(), io.data(), h128::size); + m_impl->frameDec.ProcessData(reinterpret_cast(io.data()), reinterpret_cast(io.data()), h128::size); return true; } @@ -229,7 +229,7 @@ bool RLPXFrameCoder::authAndDecryptFrame(bytesRef io) bytesConstRef frameMac(io.data() + io.size() - h128::size, h128::size); if (*(h128*)frameMac.data() != ingressDigest()) return false; - m_impl->frameDec.ProcessData(io.data(), io.data(), io.size() - h128::size); + m_impl->frameDec.ProcessData(reinterpret_cast(io.data()), reinterpret_cast(io.data()), io.size() - h128::size); return true; } @@ -237,7 +237,7 @@ h128 RLPXFrameCoder::egressDigest() { CryptoPP::Keccak_256 h(m_impl->egressMac); h128 digest; - h.TruncatedFinal(digest.data(), h128::size); + h.TruncatedFinal(reinterpret_cast(digest.data()), h128::size); return digest; } @@ -245,7 +245,7 @@ h128 RLPXFrameCoder::ingressDigest() { CryptoPP::Keccak_256 h(m_impl->ingressMac); h128 digest; - h.TruncatedFinal(digest.data(), h128::size); + h.TruncatedFinal(reinterpret_cast(digest.data()), h128::size); return digest; } @@ -256,7 +256,7 @@ void RLPXFrameCoder::updateEgressMACWithHeader(bytesConstRef _headerCipher) void RLPXFrameCoder::updateEgressMACWithFrame(bytesConstRef _cipher) { - m_impl->egressMac.Update(_cipher.data(), _cipher.size()); + m_impl->egressMac.Update(reinterpret_cast(_cipher.data()), _cipher.size()); m_impl->updateMAC(m_impl->egressMac); } @@ -267,7 +267,7 @@ void RLPXFrameCoder::updateIngressMACWithHeader(bytesConstRef _headerCipher) void RLPXFrameCoder::updateIngressMACWithFrame(bytesConstRef _cipher) { - m_impl->ingressMac.Update(_cipher.data(), _cipher.size()); + m_impl->ingressMac.Update(reinterpret_cast(_cipher.data()), _cipher.size()); m_impl->updateMAC(m_impl->ingressMac); } @@ -278,12 +278,12 @@ void RLPXFrameCoderImpl::updateMAC(CryptoPP::Keccak_256& _mac, bytesConstRef _se CryptoPP::Keccak_256 prevDigest(_mac); h128 encDigest(h128::size); - prevDigest.TruncatedFinal(encDigest.data(), h128::size); + prevDigest.TruncatedFinal(reinterpret_cast(encDigest.data()), h128::size); h128 prevDigestOut = encDigest; { Guard l(x_macEnc); - macEnc.ProcessData(encDigest.data(), encDigest.data(), 16); + macEnc.ProcessData(reinterpret_cast(encDigest.data()), reinterpret_cast(encDigest.data()), 16); } if (_seed.size()) encDigest ^= *(h128*)_seed.data(); @@ -291,5 +291,5 @@ void RLPXFrameCoderImpl::updateMAC(CryptoPP::Keccak_256& _mac, bytesConstRef _se encDigest ^= *(h128*)prevDigestOut.data(); // update mac for final digest - _mac.Update(encDigest.data(), h128::size); + _mac.Update(reinterpret_cast(encDigest.data()), h128::size); } diff --git a/libp2p/RLPxHandshake.cpp b/libp2p/RLPxHandshake.cpp index b3d3d4f850b..ea5d015cee0 100644 --- a/libp2p/RLPxHandshake.cpp +++ b/libp2p/RLPxHandshake.cpp @@ -44,7 +44,7 @@ void RLPXHandshake::writeAuth() sha3(m_ecdheLocal.pub().ref(), hepubk); m_host->m_alias.pub().ref().copyTo(pubk); m_nonce.ref().copyTo(nonce); - m_auth[m_auth.size() - 1] = 0x0; + m_auth[m_auth.size() - 1] = static_cast(0x0); encryptECIES(m_remote, &m_auth, m_authCipher); auto self(shared_from_this()); @@ -62,7 +62,7 @@ void RLPXHandshake::writeAck() bytesRef nonce(&m_ack[Public::size], h256::size); m_ecdheLocal.pub().ref().copyTo(epubk); m_nonce.ref().copyTo(nonce); - m_ack[m_ack.size() - 1] = 0x0; + m_ack[m_ack.size() - 1] = static_cast(0x0); encryptECIES(m_remote, &m_ack, m_ackCipher); auto self(shared_from_this()); @@ -83,7 +83,7 @@ void RLPXHandshake::writeAckEIP8() << c_rlpxVersion; m_ack = rlp.out(); int padAmount(rand()%100 + 100); - m_ack.resize(m_ack.size() + padAmount, 0); + m_ack.resize(m_ack.size() + padAmount, static_cast(0)); bytes prefix(2); toBigEndian(m_ack.size() + c_eciesOverhead, prefix); @@ -133,7 +133,7 @@ void RLPXHandshake::readAuth() void RLPXHandshake::readAuthEIP8() { assert(m_authCipher.size() == 307); - uint16_t size(m_authCipher[0]<<8 | m_authCipher[1]); + uint16_t size(to_integer(m_authCipher[0]<<8 | m_authCipher[1])); clog(NetP2PConnect) << "p2p.connect.ingress receiving " << size << "bytes EIP-8 auth from " << m_socket->remoteEndpoint(); m_authCipher.resize((size_t)size + 2); auto rest = ba::buffer(ba::buffer(m_authCipher) + 307); @@ -188,7 +188,7 @@ void RLPXHandshake::readAck() void RLPXHandshake::readAckEIP8() { assert(m_ackCipher.size() == 210); - uint16_t size(m_ackCipher[0]<<8 | m_ackCipher[1]); + uint16_t size(to_integer(m_ackCipher[0]<<8 | m_ackCipher[1])); clog(NetP2PConnect) << "p2p.connect.egress receiving " << size << "bytes EIP-8 ack from " << m_socket->remoteEndpoint(); m_ackCipher.resize((size_t)size + 2); auto rest = ba::buffer(ba::buffer(m_ackCipher) + 210); @@ -383,7 +383,7 @@ void RLPXHandshake::transition(boost::system::error_code _ech) return; } - PacketType packetType = frame[0] == 0x80 ? HelloPacket : (PacketType)frame[0]; + PacketType packetType = to_integer(frame[0]) == 0x80 ? HelloPacket : (PacketType)frame[0]; if (packetType != HelloPacket) { clog(NetTriviaSummary) << (m_originated ? "p2p.connect.egress" : "p2p.connect.ingress") << "hello frame: invalid packet type"; diff --git a/libp2p/Session.cpp b/libp2p/Session.cpp index 25000fc046e..d0d3b22f9a8 100644 --- a/libp2p/Session.cpp +++ b/libp2p/Session.cpp @@ -198,7 +198,7 @@ void Session::sealAndSend(RLPStream& _s) bool Session::checkPacket(bytesConstRef _msg) { - if (_msg[0] > 0x7f || _msg.size() < 2) + if (to_integer(_msg[0]) > 0x7f || _msg.size() < 2) return false; if (RLP(_msg.cropped(1)).actualSize() + 1 != _msg.size()) return false; diff --git a/libp2p/UDP.cpp b/libp2p/UDP.cpp index 0b85bae4b7c..0bcdab96a74 100644 --- a/libp2p/UDP.cpp +++ b/libp2p/UDP.cpp @@ -33,7 +33,7 @@ h256 RLPXDatagramFace::sign(Secret const& _k) RLPStream rlpxstream; // rlpxstream.appendRaw(toPublic(_k).asBytes()); // for mdc-based signature - rlpxstream.appendRaw(bytes(1, packetType())); // prefix by 1 byte for type + rlpxstream.appendRaw(bytes(1, static_cast(packetType()))); // prefix by 1 byte for type streamRLP(rlpxstream); bytes rlpxBytes(rlpxstream.out()); diff --git a/libweb3jsonrpc/JsonHelper.cpp b/libweb3jsonrpc/JsonHelper.cpp index 514496503d1..b9a43fc9ead 100644 --- a/libweb3jsonrpc/JsonHelper.cpp +++ b/libweb3jsonrpc/JsonHelper.cpp @@ -221,7 +221,7 @@ Json::Value toJson(dev::eth::Transaction const& _t) res["sighash"] = toJS(_t.sha3(WithoutSignature)); res["r"] = toJS(_t.signature().r); res["s"] = toJS(_t.signature().s); - res["v"] = toJS(_t.signature().v); + res["v"] = toJS(to_integer(_t.signature().v)); return res; } diff --git a/libwhisper/BloomFilter.h b/libwhisper/BloomFilter.h index 02cc80505f0..16da707bf1e 100644 --- a/libwhisper/BloomFilter.h +++ b/libwhisper/BloomFilter.h @@ -80,7 +80,7 @@ void TopicBloomFilterBase::removeRaw(FixedHash const& _h) m_refCounter[i]--; if (!m_refCounter[i]) - (*this)[i / 8] &= ~c_powerOfTwoBitMmask[i % 8]; + (*this)[i / 8] &= (byte)(~c_powerOfTwoBitMmask[i % 8]); } } @@ -89,7 +89,7 @@ bool TopicBloomFilterBase::isBitSet(FixedHash const& _h, unsigned _index) { unsigned iByte = _index / 8; unsigned iBit = _index % 8; - return (_h[iByte] & c_powerOfTwoBitMmask[iBit]) != 0; + return to_integer(_h[iByte] & (byte)c_powerOfTwoBitMmask[iBit]) != 0; } template @@ -97,7 +97,7 @@ void TopicBloomFilterBase::setBit(FixedHash& _h, unsigned _index) { unsigned iByte = _index / 8; unsigned iBit = _index % 8; - _h[iByte] |= c_powerOfTwoBitMmask[iBit]; + _h[iByte] |= (byte)c_powerOfTwoBitMmask[iBit]; } template @@ -114,8 +114,8 @@ FixedHash TopicBloomFilterBase::bloom(AbridgedTopic const& _h) if (TopicBloomFilterSize == N) for (unsigned i = 0; i < BitsPerBloom; ++i) { - unsigned x = _h[i]; - if (_h[BitsPerBloom] & c_powerOfTwoBitMmask[i]) + unsigned x = to_integer(_h[i]); + if (to_integer(_h[BitsPerBloom] & (byte)c_powerOfTwoBitMmask[i])) x += 256; setBit(ret, x); diff --git a/libwhisper/Message.cpp b/libwhisper/Message.cpp index 15b76505e67..82abf9a6396 100644 --- a/libwhisper/Message.cpp +++ b/libwhisper/Message.cpp @@ -82,7 +82,7 @@ bool Message::populate(bytes const& _data) return false; byte flags = _data[0]; - if (!!(flags & ContainsSignature) && _data.size() >= sizeof(Signature) + 1) // has a signature + if (!!(to_integer(flags & (byte)ContainsSignature)) && _data.size() >= sizeof(Signature) + 1) // has a signature { bytesConstRef payload = bytesConstRef(&_data).cropped(1, _data.size() - sizeof(Signature) - 1); h256 h = sha3(payload); @@ -103,13 +103,13 @@ Envelope Message::seal(Secret const& _from, Topics const& _fullTopics, unsigned Envelope ret(utcTime() + _ttl, _ttl, topics); bytes input(1 + m_payload.size()); - input[0] = 0; + input[0] = (byte)0; memcpy(input.data() + 1, m_payload.data(), m_payload.size()); if (_from) // needs a signature { input.resize(1 + m_payload.size() + sizeof(Signature)); - input[0] |= ContainsSignature; + input[0] |= (byte)ContainsSignature; *(Signature*)&(input[1 + m_payload.size()]) = sign(_from, sha3(m_payload)); // If this fails, the something is wrong with the sign-recover round-trip. assert(recover(*(Signature*)&(input[1 + m_payload.size()]), sha3(m_payload)) == KeyPair(_from).pub()); diff --git a/rlp/main.cpp b/rlp/main.cpp index 68499f9fefc..2b9d5d5c7a5 100644 --- a/rlp/main.cpp +++ b/rlp/main.cpp @@ -287,15 +287,15 @@ int main(int argc, char** argv) if (encoding == Encoding::Auto) { encoding = Encoding::Hex; - for (char b: in) - if (b != '\n' && b != ' ' && b != '\t') + for (byte b: in) + if (to_integer(b) != '\n' && to_integer(b) != ' ' && to_integer(b) != '\t') { - if (encoding == Encoding::Hex && (b < '0' || b > '9' ) && (b < 'a' || b > 'f' ) && (b < 'A' || b > 'F' )) + if (encoding == Encoding::Hex && (to_integer(b) < '0' || to_integer(b) > '9' ) && (to_integer(b) < 'a' || to_integer(b) > 'f' ) && (to_integer(b) < 'A' || to_integer(b) > 'F' )) { // cerr << "'" << b << "':" << (int)b << endl; encoding = Encoding::Base64; } - if (encoding == Encoding::Base64 && (b < '0' || b > '9' ) && (b < 'a' || b > 'z' ) && (b < 'A' || b > 'Z' ) && b != '+' && b != '/') + if (encoding == Encoding::Base64 && (to_integer(b) < '0' || to_integer(b) > '9' ) && (to_integer(b) < 'a' || to_integer(b) > 'z' ) && (to_integer(b) < 'A' || to_integer(b) > 'Z' ) && to_integer(b) != '+' && to_integer(b) != '/') { encoding = Encoding::Binary; break; diff --git a/test/tools/fuzzTesting/fuzzHelper.cpp b/test/tools/fuzzTesting/fuzzHelper.cpp index a662793e9d7..d9ee2d02487 100755 --- a/test/tools/fuzzTesting/fuzzHelper.cpp +++ b/test/tools/fuzzTesting/fuzzHelper.cpp @@ -174,7 +174,7 @@ int RandomCodeBase::recursiveRLP(std::string& _result, int _depth, std::string& int len = genbug ? randomSmallUniInt() % 255 : randomSmallUniInt() % 55; std::string hex = rndByteSequence(len); if (len == 1) - if (genValidRlp && fromHex(hex)[0] < 128) + if (genValidRlp && to_integer(fromHex(hex)[0]) < 128) hex = toCompactHex((u64)128); _result.insert(0, toCompactHex(128 + len) + emptyZeros + hex); diff --git a/test/tools/jsontests/vm.cpp b/test/tools/jsontests/vm.cpp index 8d90323eb91..8ab33d0f989 100644 --- a/test/tools/jsontests/vm.cpp +++ b/test/tools/jsontests/vm.cpp @@ -265,7 +265,7 @@ eth::OnOpFunc FakeExtVM::simpleTrace() const /*add the memory*/ Array a_mem; for(auto i: vm.memory()) - a_mem.push_back(i); + a_mem.push_back(to_integer(i)); o_step.push_back(Pair("memory", a_mem)); diff --git a/test/tools/libtesteth/FillJsonFunctions.cpp b/test/tools/libtesteth/FillJsonFunctions.cpp index c97eda7b7b6..07a60a1aeb4 100644 --- a/test/tools/libtesteth/FillJsonFunctions.cpp +++ b/test/tools/libtesteth/FillJsonFunctions.cpp @@ -45,7 +45,7 @@ json_spirit::mObject fillJsonWithTransaction(Transaction const& _txn) txObject["gasPrice"] = toCompactHexPrefixed(_txn.gasPrice(), 1); txObject["r"] = toCompactHexPrefixed(_txn.signature().r, 1); txObject["s"] = toCompactHexPrefixed(_txn.signature().s, 1); - txObject["v"] = toCompactHexPrefixed(_txn.signature().v + 27, 1); + txObject["v"] = toCompactHexPrefixed(to_integer(_txn.signature().v) + 27, 1); txObject["to"] = _txn.isCreation() ? "" : toHexPrefixed(_txn.receiveAddress()); txObject["value"] = toCompactHexPrefixed(_txn.value(), 1); txObject = ImportTest::makeAllFieldsHex(txObject); diff --git a/test/tools/libtesteth/TestHelper.cpp b/test/tools/libtesteth/TestHelper.cpp index a105f5f9986..545947557fb 100644 --- a/test/tools/libtesteth/TestHelper.cpp +++ b/test/tools/libtesteth/TestHelper.cpp @@ -105,6 +105,14 @@ void tryRunSingleTestFile(dev::test::TestSuite const& _suite) } } +std::vector bytes2uca(bytes _bytes) +{ + std::vector ret; + for (unsigned i = 0; i < _bytes.size(); i++) + ret.push_back(static_cast(_bytes[i])); + return ret; +} + string netIdToString(eth::Network _netId) { switch(_netId) @@ -220,7 +228,7 @@ byte toByte(json_spirit::mValue const& _v) case json_spirit::real_type: return (byte)_v.get_real(); default: cwarn << "Bad type for scalar: " << _v.type(); } - return 0; + return byte(0); } bytes importByteArray(std::string const& _str) @@ -383,7 +391,7 @@ void checkOutput(bytesConstRef _output, json_spirit::mObject const& _o) else if (_o.at("out").type() == json_spirit::array_type) for (auto const& d: _o.at("out").get_array()) { - BOOST_CHECK_MESSAGE(_output[j] == toInt(d), "Output byte [" << j << "] different!"); + BOOST_CHECK_MESSAGE(to_integer(_output[j]) == toInt(d), "Output byte [" << j << "] different!"); ++j; } else if (expectedOutput.find("0x") == 0) diff --git a/test/tools/libtesteth/TestHelper.h b/test/tools/libtesteth/TestHelper.h index c02f5a1cb19..69803ba3d33 100644 --- a/test/tools/libtesteth/TestHelper.h +++ b/test/tools/libtesteth/TestHelper.h @@ -116,6 +116,9 @@ void tryRunSingleTestFile(dev::test::TestSuite const& _suite); bool createRandomTest(); //returns true if succeed, false if there was an error; void doRlpTests(json_spirit::mValue const& _input); +// Convert bytes to vector +std::vector bytes2uca(bytes _bytes); + /// Allows observing test execution process. /// This class also provides methods for registering and notifying the listener class Listener diff --git a/test/unittests/libdevcore/CommonJS.cpp b/test/unittests/libdevcore/CommonJS.cpp index f8f20a0a6f5..ac097cea82a 100644 --- a/test/unittests/libdevcore/CommonJS.cpp +++ b/test/unittests/libdevcore/CommonJS.cpp @@ -35,7 +35,7 @@ BOOST_AUTO_TEST_CASE(test_toJS) h64 a("0xbaadf00ddeadbeef"); u64 b("0xffff0000bbbaaaa"); uint64_t c = 38990234243; - bytes d = {0xff, 0x0, 0xef, 0xbc}; + bytes d = {(byte)0xff, (byte)0x0, (byte)0xef, (byte)0xbc}; BOOST_CHECK(toJS(a) == "0xbaadf00ddeadbeef"); BOOST_CHECK(toJS(b) == "0xffff0000bbbaaaa"); @@ -45,8 +45,8 @@ BOOST_AUTO_TEST_CASE(test_toJS) BOOST_AUTO_TEST_CASE(test_jsToBytes) { - bytes a = {0xff, 0xaa, 0xbb, 0xcc}; - bytes b = {0x03, 0x89, 0x90, 0x23, 0x42, 0x43}; + bytes a = {(byte)0xff, (byte)0xaa, (byte)0xbb, (byte)0xcc}; + bytes b = {(byte)0x03, (byte)0x89, (byte)0x90, (byte)0x23, (byte)0x42, (byte)0x43}; BOOST_CHECK(a == jsToBytes("0xffaabbcc")); BOOST_CHECK(b == jsToBytes("38990234243")); BOOST_CHECK(bytes() == jsToBytes("")); @@ -55,29 +55,29 @@ BOOST_AUTO_TEST_CASE(test_jsToBytes) BOOST_AUTO_TEST_CASE(test_padded) { - bytes a = {0xff, 0xaa}; - BOOST_CHECK(bytes({0x00, 0x00, 0xff, 0xaa}) == padded(a, 4)); + bytes a = {(byte)0xff, (byte)0xaa}; + BOOST_CHECK(bytes({(byte)0x00, (byte)0x00, (byte)0xff, (byte)0xaa}) == padded(a, 4)); bytes b = {}; - BOOST_CHECK(bytes({0x00, 0x00, 0x00, 0x00}) == padded(b, 4)); - bytes c = {0xff, 0xaa, 0xbb, 0xcc}; - BOOST_CHECK(bytes{0xcc} == padded(c, 1)); + BOOST_CHECK(bytes({(byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00}) == padded(b, 4)); + bytes c = {(byte)0xff, (byte)0xaa, (byte)0xbb, (byte)0xcc}; + BOOST_CHECK(bytes{(byte)0xcc} == padded(c, 1)); } BOOST_AUTO_TEST_CASE(test_paddedRight) { - bytes a = {0xff, 0xaa}; - BOOST_CHECK(bytes({0xff, 0xaa, 0x00, 0x00}) == paddedRight(a, 4)); + bytes a = {(byte)0xff, (byte)0xaa}; + BOOST_CHECK(bytes({(byte)0xff, (byte)0xaa, (byte)0x00, (byte)0x00}) == paddedRight(a, 4)); bytes b = {}; - BOOST_CHECK(bytes({0x00, 0x00, 0x00, 0x00}) == paddedRight(b, 4)); - bytes c = {0xff, 0xaa, 0xbb, 0xcc}; - BOOST_CHECK(bytes{0xff} == paddedRight(c, 1)); + BOOST_CHECK(bytes({(byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00}) == paddedRight(b, 4)); + bytes c = {(byte)0xff, (byte)0xaa, (byte)0xbb, (byte)0xcc}; + BOOST_CHECK(bytes{(byte)0xff} == paddedRight(c, 1)); } BOOST_AUTO_TEST_CASE(test_unpadded) { - bytes a = {0xff, 0xaa, 0x00, 0x00, 0x00}; - BOOST_CHECK(bytes({0xff, 0xaa}) == unpadded(a)); - bytes b = {0x00, 0x00}; + bytes a = {(byte)0xff, (byte)0xaa, (byte)0x00, (byte)0x00, (byte)0x00}; + BOOST_CHECK(bytes({(byte)0xff, (byte)0xaa}) == unpadded(a)); + bytes b = {(byte)0x00, (byte)0x00}; BOOST_CHECK(bytes() == unpadded(b)); bytes c = {}; BOOST_CHECK(bytes() == unpadded(c)); @@ -85,9 +85,9 @@ BOOST_AUTO_TEST_CASE(test_unpadded) BOOST_AUTO_TEST_CASE(test_unpaddedLeft) { - bytes a = {0x00, 0x00, 0x00, 0xff, 0xaa}; - BOOST_CHECK(bytes({0xff, 0xaa}) == unpadLeft(a)); - bytes b = {0x00, 0x00}; + bytes a = {(byte)0x00, (byte)0x00, (byte)0x00, (byte)0xff, (byte)0xaa}; + BOOST_CHECK(bytes({(byte)0xff, (byte)0xaa}) == unpadLeft(a)); + bytes b = {(byte)0x00, (byte)0x00}; BOOST_CHECK(bytes() == unpadLeft(b)); bytes c = {}; BOOST_CHECK(bytes() == unpadLeft(c)); diff --git a/test/unittests/libdevcrypto/LibSnark.cpp b/test/unittests/libdevcrypto/LibSnark.cpp index 8cc41cf47fc..fb66a35baa5 100644 --- a/test/unittests/libdevcrypto/LibSnark.cpp +++ b/test/unittests/libdevcrypto/LibSnark.cpp @@ -73,8 +73,8 @@ bytes addG1(bytes const& _x, bytes const& _y) BOOST_AUTO_TEST_CASE(ecadd) { // "0 + 0 == 0" - bytes input(0x20 * 4, 0); - bytes expectation(0x20 * 2, 0); + bytes input(0x20 * 4, (byte)0); + bytes expectation(0x20 * 2, (byte)0); auto result = alt_bn128_G1_add(ref(input)); BOOST_CHECK(result.first); BOOST_CHECK(result.second == expectation); @@ -97,11 +97,11 @@ BOOST_AUTO_TEST_CASE(fieldPointInvalid) BOOST_CHECK(!alt_bn128_G1_add(ref(input)).first); BOOST_CHECK(!alt_bn128_G1_mul(ref(input)).first); - input = bytes(32, 0) + toBigEndian(pMod); + input = bytes(32, (byte)0) + toBigEndian(pMod); BOOST_CHECK(!alt_bn128_G1_add(ref(input)).first); BOOST_CHECK(!alt_bn128_G1_mul(ref(input)).first); - input = bytes(32, 0) + toBigEndian(pMod + 1); + input = bytes(32, (byte)0) + toBigEndian(pMod + 1); BOOST_CHECK(!alt_bn128_G1_add(ref(input)).first); BOOST_CHECK(!alt_bn128_G1_mul(ref(input)).first); } @@ -112,7 +112,7 @@ BOOST_AUTO_TEST_CASE(invalid) toBigEndian(u256("6851077925310461602867742977619883934042581405263014789956638244065803308498")) + toBigEndian(u256("10336382210592135525880811046708757754106524561907815205241508542912494488506")); bytes invalid = x; - invalid[3] ^= 1; + invalid[3] ^= (byte)1; bytes input = x + invalid; // This should fail because the point is not on the curve @@ -134,7 +134,7 @@ BOOST_AUTO_TEST_CASE(ecmul_add) BOOST_CHECK(ecadd_helper(x, x).second == ecmul_helper(x, u256(2)).second); // x * -1 + x == 0 BOOST_CHECK(ecmul_helper(x, groupOrder - 1).first); - BOOST_CHECK(ecadd_helper(ecmul_helper(x, groupOrder - 1).second, x).second == bytes(0x40, 0)); + BOOST_CHECK(ecadd_helper(ecmul_helper(x, groupOrder - 1).second, x).second == bytes(0x40, (byte)0)); } BOOST_AUTO_TEST_CASE(pairing) @@ -326,11 +326,11 @@ BOOST_AUTO_TEST_CASE(pairingNullInput) auto r = pairingprod_helper({}); BOOST_CHECK(r.first); - r = pairingprod_helper(bytes(2 * 32 + 2 * 64, 0)); + r = pairingprod_helper(bytes(2 * 32 + 2 * 64, (byte)0)); BOOST_CHECK(r.first); // Invalid length of input. - r = pairingprod_helper(bytes(2 * 32 + 2 * 64 + 1, 0)); + r = pairingprod_helper(bytes(2 * 32 + 2 * 64 + 1, (byte)0)); BOOST_CHECK(!r.first); } diff --git a/test/unittests/libdevcrypto/MemTrie.cpp b/test/unittests/libdevcrypto/MemTrie.cpp index e48167028fa..0dfd8f787a6 100644 --- a/test/unittests/libdevcrypto/MemTrie.cpp +++ b/test/unittests/libdevcrypto/MemTrie.cpp @@ -69,14 +69,14 @@ class TrieBranchNode: public MemTrieNode TrieBranchNode(byte _i1, MemTrieNode* _n1, std::string const& _value = std::string()): m_value(_value) { memset(m_nodes.data(), 0, sizeof(MemTrieNode*) * 16); - m_nodes[_i1] = _n1; + m_nodes[to_integer(_i1)] = _n1; } TrieBranchNode(byte _i1, MemTrieNode* _n1, byte _i2, MemTrieNode* _n2) { memset(m_nodes.data(), 0, sizeof(MemTrieNode*) * 16); - m_nodes[_i1] = _n1; - m_nodes[_i2] = _n2; + m_nodes[to_integer(_i1)] = _n1; + m_nodes[to_integer(_i2)] = _n2; } virtual ~TrieBranchNode() @@ -190,8 +190,8 @@ std::string const& TrieBranchNode::at(bytesConstRef _key) const { if (_key.empty()) return m_value; - else if (m_nodes[_key[0]] != nullptr) - return m_nodes[_key[0]]->at(_key.cropped(1)); + else if (m_nodes[to_integer(_key[0])] != nullptr) + return m_nodes[to_integer(_key[0])]->at(_key.cropped(1)); return c_nullString; } @@ -202,10 +202,10 @@ MemTrieNode* TrieBranchNode::insert(bytesConstRef _key, std::string const& _valu if (_key.empty()) m_value = _value; else - if (!m_nodes[_key[0]]) - m_nodes[_key[0]] = new TrieLeafNode(_key.cropped(1), _value); + if (!m_nodes[to_integer(_key[0])]) + m_nodes[to_integer(_key[0])] = new TrieLeafNode(_key.cropped(1), _value); else - m_nodes[_key[0]] = m_nodes[_key[0]]->insert(_key.cropped(1), _value); + m_nodes[to_integer(_key[0])] = m_nodes[to_integer(_key[0])]->insert(_key.cropped(1), _value); return this; } @@ -218,9 +218,9 @@ MemTrieNode* TrieBranchNode::remove(bytesConstRef _key) return rejig(); } else {} - else if (m_nodes[_key[0]] != nullptr) + else if (m_nodes[to_integer(_key[0])] != nullptr) { - m_nodes[_key[0]] = m_nodes[_key[0]]->remove(_key.cropped(1)); + m_nodes[to_integer(_key[0])] = m_nodes[to_integer(_key[0])]->remove(_key.cropped(1)); return rejig(); } return this; @@ -238,23 +238,23 @@ MemTrieNode* TrieBranchNode::rejig() delete this; return r; } - else if (n < 16 && m_value.empty()) + else if (to_integer(n) < 16 && m_value.empty()) { // only branching to n... - if (auto b = dynamic_cast(m_nodes[n])) + if (auto b = dynamic_cast(m_nodes[to_integer(n)])) { // switch to infix - m_nodes[n] = nullptr; + m_nodes[to_integer(n)] = nullptr; delete this; return new TrieInfixNode(bytesConstRef(&n, 1), b); } else { - auto x = dynamic_cast(m_nodes[n]); + auto x = dynamic_cast(m_nodes[to_integer(n)]); assert(x); // include in child pushFront(x->m_ext, n); - m_nodes[n] = nullptr; + m_nodes[to_integer(n)] = nullptr; delete this; return x; } @@ -272,7 +272,7 @@ byte TrieBranchNode::activeBranch() const if (n == (byte)-1) n = (byte)i; else - return 16; + return byte(16); } return n; } diff --git a/test/unittests/libdevcrypto/crypto.cpp b/test/unittests/libdevcrypto/crypto.cpp index 3f07f371b1d..b76ad63806c 100644 --- a/test/unittests/libdevcrypto/crypto.cpp +++ b/test/unittests/libdevcrypto/crypto.cpp @@ -125,7 +125,7 @@ BOOST_AUTO_TEST_CASE(KeyPairVerifySecret) { auto keyPair = KeyPair::create(); auto* ctx = secp256k1_context_create(SECP256K1_CONTEXT_NONE); - BOOST_CHECK(secp256k1_ec_seckey_verify(ctx, keyPair.secret().data())); + BOOST_CHECK(secp256k1_ec_seckey_verify(ctx, reinterpret_cast(keyPair.secret().data()))); secp256k1_context_destroy(ctx); } @@ -198,30 +198,30 @@ BOOST_AUTO_TEST_CASE(sha3_norestart) { CryptoPP::Keccak_256 ctx; bytes input(asBytes("test")); - ctx.Update(input.data(), 4); + ctx.Update(reinterpret_cast(input.data()), 4); CryptoPP::Keccak_256 ctxCopy(ctx); bytes interimDigest(32); - ctx.Final(interimDigest.data()); - ctx.Update(input.data(), 4); + ctx.Final(reinterpret_cast(interimDigest.data())); + ctx.Update(reinterpret_cast(input.data()), 4); bytes firstDigest(32); - ctx.Final(firstDigest.data()); + ctx.Final(reinterpret_cast(firstDigest.data())); BOOST_REQUIRE(interimDigest == firstDigest); - ctxCopy.Update(input.data(), 4); + ctxCopy.Update(reinterpret_cast(input.data()), 4); bytes finalDigest(32); - ctxCopy.Final(interimDigest.data()); + ctxCopy.Final(reinterpret_cast(interimDigest.data())); BOOST_REQUIRE(interimDigest != finalDigest); // we can do this another way -- copy the context for final - ctxCopy.Update(input.data(), 4); - ctxCopy.Update(input.data(), 4); + ctxCopy.Update(reinterpret_cast(input.data()), 4); + ctxCopy.Update(reinterpret_cast(input.data()), 4); CryptoPP::Keccak_256 finalCtx(ctxCopy); bytes finalDigest2(32); - finalCtx.Final(finalDigest2.data()); + finalCtx.Final(reinterpret_cast(finalDigest2.data())); BOOST_REQUIRE(finalDigest2 == interimDigest); - ctxCopy.Update(input.data(), 4); + ctxCopy.Update(reinterpret_cast(input.data()), 4); bytes finalDigest3(32); - finalCtx.Final(finalDigest3.data()); + finalCtx.Final(reinterpret_cast(finalDigest3.data())); BOOST_REQUIRE(finalDigest2 != finalDigest3); } @@ -280,7 +280,7 @@ BOOST_AUTO_TEST_CASE(ecies_standard) s_secp256k1->encryptECIES(k.pub(), b); BOOST_REQUIRE(b != asBytes(original)); - BOOST_REQUIRE(b.size() > 0 && b[0] == 0x04); + BOOST_REQUIRE(b.size() > 0 && to_integer(b[0]) == 0x04); s_secp256k1->decryptECIES(k.secret(), b); BOOST_REQUIRE(bytesConstRef(&b).cropped(0, original.size()).toBytes() == asBytes(original)); @@ -299,7 +299,7 @@ BOOST_AUTO_TEST_CASE(ecies_sharedMacData) s_secp256k1->encryptECIES(k.pub(), shared, b); BOOST_REQUIRE(b != original); - BOOST_REQUIRE(b.size() > 0 && b[0] == 0x04); + BOOST_REQUIRE(b.size() > 0 && to_integer(b[0]) == 0x04); BOOST_REQUIRE(!s_secp256k1->decryptECIES(k.secret(), wrongShared, b)); @@ -359,16 +359,16 @@ BOOST_AUTO_TEST_CASE(ecdhCryptopp) // Now use our keys KeyPair a = KeyPair::create(); - byte puba[65] = {0x04}; + dev::byte puba[65] = {(dev::byte)0x04}; memcpy(&puba[1], a.pub().data(), 64); KeyPair b = KeyPair::create(); - byte pubb[65] = {0x04}; + dev::byte pubb[65] = {(dev::byte)0x04}; memcpy(&pubb[1], b.pub().data(), 64); CryptoPP::ECDH::Domain dhA(curveOID()); Secret shared; - BOOST_REQUIRE(dhA.Agree(shared.writable().data(), a.secret().data(), pubb)); + BOOST_REQUIRE(dhA.Agree(reinterpret_cast(shared.writable().data()), reinterpret_cast(a.secret().data()), reinterpret_cast(pubb))); BOOST_REQUIRE(shared); } @@ -437,7 +437,7 @@ BOOST_AUTO_TEST_CASE(handshakeNew) sha3(eA.pub().ref(), hepubk); nodeA.pub().ref().copyTo(pubk); nonceA.ref().copyTo(nonce); - auth[auth.size() - 1] = 0x0; + auth[auth.size() - 1] = (dev::byte)0x0; } bytes authcipher; encrypt(nodeB.pub(), &auth, authcipher); @@ -462,7 +462,7 @@ BOOST_AUTO_TEST_CASE(handshakeNew) eB.pub().ref().copyTo(epubk); nonceB.ref().copyTo(nonce); - auth[auth.size() - 1] = 0x0; + auth[auth.size() - 1] = (dev::byte)0x0; } bytes ackcipher; encrypt(nodeA.pub(), &ack, ackcipher); @@ -600,7 +600,7 @@ BOOST_AUTO_TEST_CASE(ecies_aes128_ctr_unaligned) SecureFixedHash<16> encryptK(sha3("..."), h128::AlignLeft); h256 egressMac(sha3("+++")); // TESTING: send encrypt magic sequence - bytes magic {0x22,0x40,0x08,0x91}; + bytes magic {(dev::byte)0x22, (dev::byte)0x40, (dev::byte)0x08, (dev::byte)0x91}; bytes magicCipherAndMac; magicCipherAndMac = encryptSymNoAuth(encryptK, h128(), &magic); @@ -621,7 +621,7 @@ BOOST_AUTO_TEST_CASE(ecies_aes128_ctr) { SecureFixedHash<16> k(sha3("0xAAAA"), h128::AlignLeft); string m = "AAAAAAAAAAAAAAAA"; - bytesConstRef msg((byte*)m.data(), m.size()); + bytesConstRef msg((dev::byte*)m.data(), m.size()); bytes ciphertext; h128 iv; @@ -634,7 +634,7 @@ BOOST_AUTO_TEST_CASE(ecies_aes128_ctr) BOOST_AUTO_TEST_CASE(cryptopp_aes128_ctr) { const int aesKeyLen = 16; - BOOST_REQUIRE(sizeof(char) == sizeof(byte)); + BOOST_REQUIRE(sizeof(char) == sizeof(dev::byte)); // generate test key CryptoPP::AutoSeededRandomPool rng; @@ -643,7 +643,7 @@ BOOST_AUTO_TEST_CASE(cryptopp_aes128_ctr) // cryptopp uses IV as nonce/counter which is same as using nonce w/0 ctr FixedHash ctr; - rng.GenerateBlock(ctr.data(), sizeof(ctr)); + rng.GenerateBlock(reinterpret_cast(ctr.data()), sizeof(ctr)); // used for decrypt FixedHash ctrcopy(ctr); @@ -658,7 +658,7 @@ BOOST_AUTO_TEST_CASE(cryptopp_aes128_ctr) try { CryptoPP::CTR_Mode::Encryption e; - e.SetKeyWithIV(key, key.size(), ctr.data()); + e.SetKeyWithIV(key, key.size(), reinterpret_cast(ctr.data())); // 68 % 255 should be difference of counter e.ProcessData(out, in, text.size()); @@ -675,7 +675,7 @@ BOOST_AUTO_TEST_CASE(cryptopp_aes128_ctr) try { CryptoPP::CTR_Mode::Decryption d; - d.SetKeyWithIV(key, key.size(), ctrcopy.data()); + d.SetKeyWithIV(key, key.size(), reinterpret_cast(ctrcopy.data())); d.ProcessData(out, in, text.size()); BOOST_REQUIRE(text == original); } @@ -693,7 +693,7 @@ BOOST_AUTO_TEST_CASE(cryptopp_aes128_ctr) out = (unsigned char*)&cipherCopy[0]; CryptoPP::CTR_Mode::Encryption e; - e.SetKeyWithIV(key, key.size(), ctrcopy.data()); + e.SetKeyWithIV(key, key.size(), reinterpret_cast(ctrcopy.data())); e.ProcessData(out, in, text.size()); // yep, ctr mode. @@ -709,25 +709,25 @@ BOOST_AUTO_TEST_CASE(cryptopp_aes128_ctr) BOOST_AUTO_TEST_CASE(cryptopp_aes128_cbc) { const int aesKeyLen = 16; - BOOST_REQUIRE(sizeof(char) == sizeof(byte)); + BOOST_REQUIRE(sizeof(char) == sizeof(dev::byte)); CryptoPP::AutoSeededRandomPool rng; CryptoPP::SecByteBlock key(0x00, aesKeyLen); rng.GenerateBlock(key, key.size()); // Generate random IV - byte iv[CryptoPP::AES::BLOCKSIZE]; - rng.GenerateBlock(iv, CryptoPP::AES::BLOCKSIZE); + dev::byte iv[CryptoPP::AES::BLOCKSIZE]; + rng.GenerateBlock(reinterpret_cast(iv), CryptoPP::AES::BLOCKSIZE); string string128("AAAAAAAAAAAAAAAA"); string plainOriginal = string128; - CryptoPP::CBC_Mode::Encryption cbcEncryption(key, key.size(), iv); - cbcEncryption.ProcessData((byte*)&string128[0], (byte*)&string128[0], string128.size()); + CryptoPP::CBC_Mode::Encryption cbcEncryption(key, key.size(), reinterpret_cast(iv)); + cbcEncryption.ProcessData(reinterpret_cast((dev::byte*)&string128[0]), reinterpret_cast((dev::byte*)&string128[0]), string128.size()); BOOST_REQUIRE(string128 != plainOriginal); - CryptoPP::CBC_Mode::Decryption cbcDecryption(key, key.size(), iv); - cbcDecryption.ProcessData((byte*)&string128[0], (byte*)&string128[0], string128.size()); + CryptoPP::CBC_Mode::Decryption cbcDecryption(key, key.size(), reinterpret_cast(iv)); + cbcDecryption.ProcessData(reinterpret_cast((dev::byte*)&string128[0]), reinterpret_cast((dev::byte*)&string128[0]), string128.size()); BOOST_REQUIRE(plainOriginal == string128); @@ -740,9 +740,9 @@ BOOST_AUTO_TEST_CASE(cryptopp_aes128_cbc) CryptoPP::StringSource source(string192, true, aesStream); BOOST_REQUIRE(cipher.size() == 32); - byte* pOut = reinterpret_cast(&string192[0]); - byte const* pIn = reinterpret_cast(cipher.data()); - cbcDecryption.ProcessData(pOut, pIn, cipher.size()); + dev::byte* pOut = reinterpret_cast(&string192[0]); + dev::byte const* pIn = reinterpret_cast(cipher.data()); + cbcDecryption.ProcessData(reinterpret_cast(pOut), reinterpret_cast(pIn), cipher.size()); BOOST_REQUIRE(string192 == plainOriginal); } @@ -762,12 +762,12 @@ BOOST_AUTO_TEST_CASE(recoverVgt3) { KeyPair key(secret); Public pkey = key.pub(); - signer.AccessKey().Initialize(params(), CryptoPP::Integer(secret.data(), Secret::size)); + signer.AccessKey().Initialize(params(), CryptoPP::Integer(reinterpret_cast(secret.data()), Secret::size)); h256 he(sha3(e)); - CryptoPP::Integer heInt(he.asBytes().data(), 32); + CryptoPP::Integer heInt(reinterpret_cast(he.asBytes().data()), 32); h256 k(crypto::kdf(secret, he)); - CryptoPP::Integer kInt(k.asBytes().data(), 32); + CryptoPP::Integer kInt(reinterpret_cast(k.asBytes().data()), 32); kInt %= params().GetSubgroupOrder()-1; CryptoPP::ECP::Point rp = params().ExponentiateBase(kInt); @@ -775,16 +775,16 @@ BOOST_AUTO_TEST_CASE(recoverVgt3) CryptoPP::Integer r = params().ConvertElementToInteger(rp); CryptoPP::Integer kInv = kInt.InverseMod(q); - CryptoPP::Integer s = (kInv * (CryptoPP::Integer(secret.data(), 32) * r + heInt)) % q; + CryptoPP::Integer s = (kInv * (CryptoPP::Integer(reinterpret_cast(secret.data()), 32) * r + heInt)) % q; BOOST_REQUIRE(!!r && !!s); //try recover function on diffrent v values (should be invalid) for (size_t i = 0; i < 10; i++) { Signature sig; - sig[64] = i; - r.Encode(sig.data(), 32); - s.Encode(sig.data() + 32, 32); + sig[64] = (dev::byte)i; + r.Encode(reinterpret_cast(sig.data()), 32); + s.Encode(reinterpret_cast(sig.data() + 32), 32); Public p = dev::recover(sig, he); size_t expectI = rp.y.IsOdd() ? 1 : 0; @@ -808,7 +808,7 @@ BOOST_AUTO_TEST_CASE(PerfSHA256_32, *utf::label("perf")) for (auto i = 0; i < 1000000; ++i) hash = sha256(hash.ref()); - BOOST_CHECK_EQUAL(hash[0], 0x2a); + BOOST_CHECK_EQUAL(to_integer(hash[0]), 0x2a); } BOOST_AUTO_TEST_CASE(PerfSHA256_4000, *utf::label("perf")) @@ -824,11 +824,11 @@ BOOST_AUTO_TEST_CASE(PerfSHA256_4000, *utf::label("perf")) for (auto i = 0; i < 100000; ++i) { auto hash = sha256(&data); - auto idx = ((hash[1] << 8) | hash[2]) % (dataSize - hash.size); + auto idx = to_integer((hash[1] << 8) | hash[2]) % (dataSize - hash.size); std::copy(hash.data(), hash.data() + hash.size, data.begin() + idx); } - BOOST_CHECK_EQUAL(data[0], 0x4d); + BOOST_CHECK_EQUAL(to_integer(data[0]), 0x4d); } BOOST_AUTO_TEST_SUITE_END() diff --git a/test/unittests/libdevcrypto/trie.cpp b/test/unittests/libdevcrypto/trie.cpp index 73645f48152..1869afe99ba 100644 --- a/test/unittests/libdevcrypto/trie.cpp +++ b/test/unittests/libdevcrypto/trie.cpp @@ -283,7 +283,7 @@ h256 stringMapHash256(StringMap const& _s) { BytesMap bytesMap; for (auto const& _v: _s) - bytesMap.insert(std::make_pair(bytes(_v.first.begin(), _v.first.end()), bytes(_v.second.begin(), _v.second.end()))); + bytesMap.insert(std::make_pair(asBytes(_v.first), asBytes(_v.second))); return hash256(bytesMap); } @@ -291,7 +291,7 @@ bytes stringMapRlp256(StringMap const& _s) { BytesMap bytesMap; for (auto const& _v: _s) - bytesMap.insert(std::make_pair(bytes(_v.first.begin(), _v.first.end()), bytes(_v.second.begin(), _v.second.end()))); + bytesMap.insert(std::make_pair(asBytes(_v.first), asBytes(_v.second))); return rlp256(bytesMap); } diff --git a/test/unittests/libethcore/PrecompiledTest.cpp b/test/unittests/libethcore/PrecompiledTest.cpp index 47ccead87e9..9747feb14df 100644 --- a/test/unittests/libethcore/PrecompiledTest.cpp +++ b/test/unittests/libethcore/PrecompiledTest.cpp @@ -45,7 +45,7 @@ BOOST_AUTO_TEST_CASE(modexpFermatTheorem) BOOST_REQUIRE(res.first); bytes expected = fromHex("0000000000000000000000000000000000000000000000000000000000000001"); - BOOST_REQUIRE_EQUAL_COLLECTIONS(res.second.begin(), res.second.end(), expected.begin(), expected.end()); + BOOST_REQUIRE_EQUAL_COLLECTIONS(bytes2uca(res.second).begin(), bytes2uca(res.second).end(), bytes2uca(expected).begin(), bytes2uca(expected).end()); } BOOST_AUTO_TEST_CASE(modexpZeroBase) @@ -62,7 +62,7 @@ BOOST_AUTO_TEST_CASE(modexpZeroBase) BOOST_REQUIRE(res.first); bytes expected = fromHex("0000000000000000000000000000000000000000000000000000000000000000"); - BOOST_REQUIRE_EQUAL_COLLECTIONS(res.second.begin(), res.second.end(), expected.begin(), expected.end()); + BOOST_REQUIRE_EQUAL_COLLECTIONS(bytes2uca(res.second).begin(), bytes2uca(res.second).end(), bytes2uca(expected).begin(), bytes2uca(expected).end()); } BOOST_AUTO_TEST_CASE(modexpExtraByteIgnored) @@ -81,7 +81,7 @@ BOOST_AUTO_TEST_CASE(modexpExtraByteIgnored) BOOST_REQUIRE(res.first); bytes expected = fromHex("3b01b01ac41f2d6e917c6d6a221ce793802469026d9ab7578fa2e79e4da6aaab"); - BOOST_REQUIRE_EQUAL_COLLECTIONS(res.second.begin(), res.second.end(), expected.begin(), expected.end()); + BOOST_REQUIRE_EQUAL_COLLECTIONS(bytes2uca(res.second).begin(), bytes2uca(res.second).end(), bytes2uca(expected).begin(), bytes2uca(expected).end()); } BOOST_AUTO_TEST_CASE(modexpRightPadding) @@ -99,7 +99,7 @@ BOOST_AUTO_TEST_CASE(modexpRightPadding) BOOST_REQUIRE(res.first); bytes expected = fromHex("3b01b01ac41f2d6e917c6d6a221ce793802469026d9ab7578fa2e79e4da6aaab"); - BOOST_REQUIRE_EQUAL_COLLECTIONS(res.second.begin(), res.second.end(), expected.begin(), expected.end()); + BOOST_REQUIRE_EQUAL_COLLECTIONS(bytes2uca(res.second).begin(), bytes2uca(res.second).end(), bytes2uca(expected).begin(), bytes2uca(expected).end()); } BOOST_AUTO_TEST_CASE(modexpMissingValues) @@ -115,7 +115,7 @@ BOOST_AUTO_TEST_CASE(modexpMissingValues) BOOST_REQUIRE(res.first); bytes expected = fromHex("0000000000000000000000000000000000000000000000000000000000000000"); - BOOST_REQUIRE_EQUAL_COLLECTIONS(res.second.begin(), res.second.end(), expected.begin(), expected.end()); + BOOST_REQUIRE_EQUAL_COLLECTIONS(bytes2uca(res.second).begin(), bytes2uca(res.second).end(), bytes2uca(expected).begin(), bytes2uca(expected).end()); } BOOST_AUTO_TEST_CASE(modexpEmptyValue) @@ -132,7 +132,7 @@ BOOST_AUTO_TEST_CASE(modexpEmptyValue) BOOST_REQUIRE(res.first); bytes expected = fromHex("0000000000000000000000000000000000000000000000000000000000000001"); - BOOST_REQUIRE_EQUAL_COLLECTIONS(res.second.begin(), res.second.end(), expected.begin(), expected.end()); + BOOST_REQUIRE_EQUAL_COLLECTIONS(bytes2uca(res.second).begin(), bytes2uca(res.second).end(), bytes2uca(expected).begin(), bytes2uca(expected).end()); } BOOST_AUTO_TEST_CASE(modexpZeroPowerZero) @@ -150,7 +150,7 @@ BOOST_AUTO_TEST_CASE(modexpZeroPowerZero) BOOST_REQUIRE(res.first); bytes expected = fromHex("0000000000000000000000000000000000000000000000000000000000000001"); - BOOST_REQUIRE_EQUAL_COLLECTIONS(res.second.begin(), res.second.end(), expected.begin(), expected.end()); + BOOST_REQUIRE_EQUAL_COLLECTIONS(bytes2uca(res.second).begin(), bytes2uca(res.second).end(), bytes2uca(expected).begin(), bytes2uca(expected).end()); } BOOST_AUTO_TEST_CASE(modexpZeroPowerZeroModZero) @@ -168,7 +168,7 @@ BOOST_AUTO_TEST_CASE(modexpZeroPowerZeroModZero) BOOST_REQUIRE(res.first); bytes expected = fromHex("0000000000000000000000000000000000000000000000000000000000000000"); - BOOST_REQUIRE_EQUAL_COLLECTIONS(res.second.begin(), res.second.end(), expected.begin(), expected.end()); + BOOST_REQUIRE_EQUAL_COLLECTIONS(bytes2uca(res.second).begin(), bytes2uca(res.second).end(), bytes2uca(expected).begin(), bytes2uca(expected).end()); } BOOST_AUTO_TEST_CASE(modexpModLengthZero) diff --git a/test/unittests/libethereum/BlockChain.cpp b/test/unittests/libethereum/BlockChain.cpp index d85cfc3f1bd..ae8386a696a 100644 --- a/test/unittests/libethereum/BlockChain.cpp +++ b/test/unittests/libethereum/BlockChain.cpp @@ -268,7 +268,7 @@ BOOST_AUTO_TEST_CASE(attemptImport) BOOST_REQUIRE(importAttempt.first == ImportResult::AlreadyKnown); bytes blockBytes = block.bytes(); - blockBytes[0] = 0; + blockBytes[0] = (byte)0; importAttempt = bcRef.attemptImport(blockBytes, bc.testGenesis().state().db()); BOOST_REQUIRE(importAttempt.first == ImportResult::Malformed); BOOST_REQUIRE(onBadwasCalled == true); diff --git a/test/unittests/libethereum/ClientBase.cpp b/test/unittests/libethereum/ClientBase.cpp index dbd175b0d94..bc0ab3f7c15 100644 --- a/test/unittests/libethereum/ClientBase.cpp +++ b/test/unittests/libethereum/ClientBase.cpp @@ -25,6 +25,7 @@ #include #include #include +#include using namespace std; using namespace dev; @@ -62,8 +63,8 @@ BOOST_AUTO_TEST_CASE(blocks) // codeAt bytes expectedCode = fromHex(_o["code"].asString()); bytes code = _client.codeAt(address, _blockNumber); - ETH_CHECK_EQUAL_COLLECTIONS(expectedCode.begin(), expectedCode.end(), - code.begin(), code.end()); + ETH_CHECK_EQUAL_COLLECTIONS(bytes2uca(expectedCode).begin(), bytes2uca(expectedCode).end(), + bytes2uca(code).begin(), bytes2uca(code).end()); }; for (string const& name: _json["postState"].getMemberNames()) @@ -124,10 +125,10 @@ BOOST_AUTO_TEST_CASE(blocks) ETH_CHECK_EQUAL(expectedBlockInfoCoinbase, _blockInfo.author()); ETH_CHECK_EQUAL(expectedBlockInfoDifficulty, _blockInfo.difficulty()); ETH_CHECK_EQUAL_COLLECTIONS( - expectedBlockInfoExtraData.begin(), - expectedBlockInfoExtraData.end(), - _blockInfo.extraData().begin(), - _blockInfo.extraData().end() + bytes2uca(expectedBlockInfoExtraData).begin(), + bytes2uca(expectedBlockInfoExtraData).end(), + bytes2uca(_blockInfo.extraData()).begin(), + bytes2uca(_blockInfo.extraData()).end() ); ETH_CHECK_EQUAL(expectedBlockInfoGasLimit, _blockInfo.gasLimit()); ETH_CHECK_EQUAL(expectedBlockInfoGasUsed, _blockInfo.gasUsed()); @@ -163,10 +164,10 @@ BOOST_AUTO_TEST_CASE(blocks) // unsigned expectedTransactionSignatureV = jsToInt(t["v"].asString()); ETH_CHECK_EQUAL_COLLECTIONS( - expectedTransactionData.begin(), - expectedTransactionData.end(), - _transaction.data().begin(), - _transaction.data().end() + bytes2uca(expectedTransactionData).begin(), + bytes2uca(expectedTransactionData).end(), + bytes2uca(_transaction.data()).begin(), + bytes2uca(_transaction.data()).end() ); ETH_CHECK_EQUAL(expectedTransactionGasLimit, _transaction.gas()); ETH_CHECK_EQUAL(expectedTransactionGasPrice, _transaction.gasPrice()); diff --git a/test/unittests/libethereum/SnapshotImporterTest.cpp b/test/unittests/libethereum/SnapshotImporterTest.cpp index 3e45dfa676a..0695bf0f139 100644 --- a/test/unittests/libethereum/SnapshotImporterTest.cpp +++ b/test/unittests/libethereum/SnapshotImporterTest.cpp @@ -54,7 +54,7 @@ namespace std::string lookupCode(h256 const& _hash) const override { auto it = std::find_if(importedCodes.begin(), importedCodes.end(), [&_hash](bytes const& _code) { return sha3(_code) == _hash; }); - return it == importedCodes.end() ? std::string{} : std::string(it->begin(), it->end()); + return it == importedCodes.end() ? std::string{} : std::string((char const*)it->data()); } std::vector importedAccounts; @@ -92,7 +92,7 @@ namespace std::string readChunk(h256 const& _chunkHash) const override { auto it = chunks.find(_chunkHash); - return it == chunks.end() ? std::string{} : std::string(it->second.begin(), it->second.end()); + return it == chunks.end() ? std::string{} : std::string((char const*)it->second.data()); } bytes manifest; @@ -127,7 +127,7 @@ namespace bytes createAccount(u256 const& _nonce, u256 const& _balance, byte _codeFlag, bytes const& _code, std::map _storage) { RLPStream s(5); - s << _nonce << _balance << _codeFlag << _code; + s << _nonce << _balance << to_integer(_codeFlag) << _code; s.appendList(_storage.size()); for (auto& keyValue: _storage) { @@ -202,7 +202,7 @@ BOOST_AUTO_TEST_CASE(SnapshotImporterSuite_importNonsplittedAccount) h256 stateChunk = sha3("123"); snapshotStorage.manifest = createManifest(2, {stateChunk}, {}, h256{}, 0, h256{}); - bytes account = createAccount(1, 10, 0, {0x80}, {}); + bytes account = createAccount(1, 10, (byte)0, {(byte)0x80}, {}); h256 addressHash = sha3("456"); bytes chunkBytes = createStateChunk({{addressHash, account}}); snapshotStorage.chunks[stateChunk] = chunkBytes; @@ -225,15 +225,15 @@ BOOST_AUTO_TEST_CASE(SnapshotImporterSuite_importSplittedAccount) snapshotStorage.manifest = createManifest(2, {stateChunk1, stateChunk2}, {}, h256{}, 0, h256{}); h256 addressHash = sha3("456"); - std::pair storagePair1{sha3("111"), {1}}; - std::pair storagePair2{sha3("222"), {2}}; - bytes accountPart1 = createAccount(2, 10, 0, {0x80}, {storagePair1, storagePair2}); + std::pair storagePair1{sha3("111"), {(byte)1}}; + std::pair storagePair2{sha3("222"), {(byte)2}}; + bytes accountPart1 = createAccount(2, 10, (byte)0, {(byte)0x80}, {storagePair1, storagePair2}); bytes chunk1 = createStateChunk({{addressHash, accountPart1}}); snapshotStorage.chunks[stateChunk1] = chunk1; - std::pair storagePair3{sha3("333"),{3}}; - std::pair storagePair4{sha3("444"),{4}}; - bytes accountPart2 = createAccount(2, 10, 0, {0x80}, {storagePair3, storagePair4}); + std::pair storagePair3{sha3("333"),{(byte)3}}; + std::pair storagePair4{sha3("444"),{(byte)4}}; + bytes accountPart2 = createAccount(2, 10, (byte)0, {(byte)0x80}, {storagePair3, storagePair4}); bytes chunk2 = createStateChunk({{addressHash, accountPart2}}); snapshotStorage.chunks[stateChunk2] = chunk2; @@ -255,8 +255,8 @@ BOOST_AUTO_TEST_CASE(SnapshotImporterSuite_importAccountWithCode) h256 stateChunk = sha3("123"); snapshotStorage.manifest = createManifest(2, {stateChunk}, {}, h256{}, 0, h256{}); - bytes code = {1, 2, 3}; - bytes account = createAccount(1, 10, 1, code, {}); + bytes code = {(byte)1, (byte)2, (byte)3}; + bytes account = createAccount(1, 10, (byte)1, code, {}); h256 addressHash = sha3("456"); bytes chunkBytes = createStateChunk({{addressHash, account}}); snapshotStorage.chunks[stateChunk] = chunkBytes; @@ -270,7 +270,7 @@ BOOST_AUTO_TEST_CASE(SnapshotImporterSuite_importAccountWithCode) BOOST_REQUIRE_EQUAL(stateImporter.importedCodes.size(), 1); bytes const& importedCode = stateImporter.importedCodes.front(); - BOOST_CHECK_EQUAL_COLLECTIONS(importedCode.begin(), importedCode.end(), code.begin(), code.end()); + BOOST_CHECK_EQUAL_COLLECTIONS(bytes2uca(importedCode).begin(), bytes2uca(importedCode).end(), bytes2uca(code).begin(), bytes2uca(code).end()); } BOOST_AUTO_TEST_CASE(SnapshotImporterSuite_importAccountsWithEqualCode) @@ -278,12 +278,12 @@ BOOST_AUTO_TEST_CASE(SnapshotImporterSuite_importAccountsWithEqualCode) h256 stateChunk = sha3("123"); snapshotStorage.manifest = createManifest(2, {stateChunk}, {}, h256{}, 0, h256{}); - bytes code = {1, 2, 3}; - bytes account1 = createAccount(1, 10, 1, code, {}); + bytes code = {(byte)1, (byte)2, (byte)3}; + bytes account1 = createAccount(1, 10, (byte)1, code, {}); h256 addressHash1 = sha3("456"); h256 codeHash = sha3(code); - bytes account2 = createAccount(1, 10, 2, codeHash.asBytes(), {}); + bytes account2 = createAccount(1, 10, (byte)2, codeHash.asBytes(), {}); h256 addressHash2 = sha3("789"); snapshotStorage.chunks[stateChunk] = createStateChunk({{addressHash1, account1}, {addressHash2, account2}}); @@ -298,7 +298,7 @@ BOOST_AUTO_TEST_CASE(SnapshotImporterSuite_importAccountsWithEqualCode) BOOST_REQUIRE_EQUAL(stateImporter.importedCodes.size(), 1); bytes const& importedCode = stateImporter.importedCodes.front(); - BOOST_CHECK_EQUAL_COLLECTIONS(importedCode.begin(), importedCode.end(), code.begin(), code.end()); + BOOST_CHECK_EQUAL_COLLECTIONS(bytes2uca(importedCode).begin(), bytes2uca(importedCode).end(), bytes2uca(code).begin(), bytes2uca(code).end()); } BOOST_AUTO_TEST_CASE(SnapshotImporterSuite_commitStateOnceEveryChunk) @@ -308,12 +308,12 @@ BOOST_AUTO_TEST_CASE(SnapshotImporterSuite_commitStateOnceEveryChunk) snapshotStorage.manifest = createManifest(2, {stateChunk1, stateChunk2}, {}, h256{}, 0, h256{}); h256 addressHash1 = sha3("456"); - bytes accountPart1 = createAccount(2, 10, 0, {0x80}, {}); + bytes accountPart1 = createAccount(2, 10, (byte)0, {(byte)0x80}, {}); bytes chunk1 = createStateChunk({{addressHash1, accountPart1}}); snapshotStorage.chunks[stateChunk1] = chunk1; h256 addressHash2 = sha3("345"); - bytes accountPart2 = createAccount(2, 10, 0, {0x80}, {}); + bytes accountPart2 = createAccount(2, 10, (byte)0, {(byte)0x80}, {}); bytes chunk2 = createStateChunk({{addressHash2, accountPart2}}); snapshotStorage.chunks[stateChunk2] = chunk2; @@ -336,7 +336,7 @@ BOOST_AUTO_TEST_CASE(SnapshotImporterSuite_importEmptyBlock) u256 gasLimit = 555; u256 gasUsed = 666; u256 timestamp = 777; - bytes extraData = {8, 8, 8}; + bytes extraData = {(byte)8, (byte)8, (byte)8}; h256 mixHash = sha3("999"); Nonce nonce(012); bytes block = createAbridgedBlock(author, stateRoot, logBloom, difficulty, gasLimit, gasUsed, timestamp, extraData, mixHash, nonce, RLPEmptyList, RLPEmptyList); @@ -359,7 +359,7 @@ BOOST_AUTO_TEST_CASE(SnapshotImporterSuite_importEmptyBlock) BOOST_CHECK_EQUAL(header.gasLimit(), gasLimit); BOOST_CHECK_EQUAL(header.gasUsed(), gasUsed); BOOST_CHECK_EQUAL(header.timestamp(), timestamp); - BOOST_CHECK_EQUAL_COLLECTIONS(header.extraData().begin(), header.extraData().end(), extraData.begin(), extraData.end()); + BOOST_CHECK_EQUAL_COLLECTIONS(bytes2uca(header.extraData()).begin(), bytes2uca(header.extraData()).end(), bytes2uca(extraData).begin(), bytes2uca(extraData).end()); BOOST_CHECK_EQUAL(Ethash::mixHash(header), mixHash); BOOST_CHECK_EQUAL(Ethash::nonce(header), nonce); BOOST_CHECK_EQUAL(header.number(), parentNumber + 1); @@ -376,7 +376,7 @@ BOOST_AUTO_TEST_CASE(SnapshotImporterSuite_importBlockWithTransactions) bytes transactions = createRlpSingleItemList(123); bytes uncles = createRlpSingleItemList(456); - bytes block = createAbridgedBlock(Address("111"), sha3("222"), h2048(333), 444, 555, 666, 777, {8, 8, 8}, sha3("999"), Nonce(012), transactions, uncles); + bytes block = createAbridgedBlock(Address("111"), sha3("222"), h2048(333), 444, 555, 666, 777, {(byte)8, (byte)8, (byte)8}, sha3("999"), Nonce(012), transactions, uncles); bytes receipts = createRlpSingleItemList(789); bytes chunkBytes = createSingleBlockChunk(345, sha3("678"), 910, block, receipts); @@ -386,9 +386,9 @@ BOOST_AUTO_TEST_CASE(SnapshotImporterSuite_importBlockWithTransactions) BOOST_REQUIRE_EQUAL(blockChainImporter.importedBlocks.size(), 1); ImportedBlock const& importedBlock = blockChainImporter.importedBlocks.front(); - BOOST_CHECK_EQUAL_COLLECTIONS(importedBlock.transactions.begin(), importedBlock.transactions.end(), transactions.begin(), transactions.end()); - BOOST_CHECK_EQUAL_COLLECTIONS(importedBlock.uncles.begin(), importedBlock.uncles.end(), uncles.begin(), uncles.end()); - BOOST_CHECK_EQUAL_COLLECTIONS(importedBlock.receipts.begin(), importedBlock.receipts.end(), receipts.begin(), receipts.end()); + BOOST_CHECK_EQUAL_COLLECTIONS(bytes2uca(importedBlock.transactions).begin(), bytes2uca(importedBlock.transactions).end(), bytes2uca(transactions).begin(), bytes2uca(transactions).end()); + BOOST_CHECK_EQUAL_COLLECTIONS(bytes2uca(importedBlock.uncles).begin(), bytes2uca(importedBlock.uncles).end(), bytes2uca(uncles).begin(), bytes2uca(uncles).end()); + BOOST_CHECK_EQUAL_COLLECTIONS(bytes2uca(importedBlock.receipts).begin(), bytes2uca(importedBlock.receipts).end(), bytes2uca(receipts).begin(), bytes2uca(receipts).end()); } BOOST_AUTO_TEST_SUITE_END() diff --git a/test/unittests/libethereum/StateUnitTests.cpp b/test/unittests/libethereum/StateUnitTests.cpp index 4854a3d8a7a..d4b722d3532 100644 --- a/test/unittests/libethereum/StateUnitTests.cpp +++ b/test/unittests/libethereum/StateUnitTests.cpp @@ -44,7 +44,7 @@ BOOST_AUTO_TEST_CASE(LoadAccountCode) Address addr{"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"}; State s{0}; s.createContract(addr); - uint8_t codeData[] = {'c', 'o', 'd', 'e'}; + byte codeData[] = {(byte)'c', (byte)'o', (byte)'d', (byte)'e'}; s.setCode(addr, {std::begin(codeData), std::end(codeData)}); s.commit(State::CommitBehaviour::RemoveEmptyAccounts); diff --git a/test/unittests/libethereum/TransactionQueue.cpp b/test/unittests/libethereum/TransactionQueue.cpp index 5a4a3ddeebd..3b63bfadfb7 100644 --- a/test/unittests/libethereum/TransactionQueue.cpp +++ b/test/unittests/libethereum/TransactionQueue.cpp @@ -206,7 +206,7 @@ BOOST_AUTO_TEST_CASE(tqImport) BOOST_REQUIRE(ir == ImportResult::AlreadyKnown); bytes rlp = testTransaction.transaction().rlp(); - rlp.at(0) = 03; + rlp.at(0) = (byte)03; ir = tq.import(rlp); BOOST_REQUIRE(ir == ImportResult::Malformed); diff --git a/test/unittests/libp2p/net.cpp b/test/unittests/libp2p/net.cpp index 3d6ffec7855..eca1f64f9c0 100644 --- a/test/unittests/libp2p/net.cpp +++ b/test/unittests/libp2p/net.cpp @@ -331,7 +331,7 @@ BOOST_AUTO_TEST_CASE(udpOnce) } unsigned short port = 30333; - UDPDatagram d(bi::udp::endpoint(boost::asio::ip::address::from_string("127.0.0.1"), port), bytes({65,65,65,65})); + UDPDatagram d(bi::udp::endpoint(boost::asio::ip::address::from_string("127.0.0.1"), port), bytes({(byte)65,(byte)65,(byte)65,(byte)65})); TestUDPSocket a{port}; a.m_socket->connect(); a.start(); diff --git a/test/unittests/libp2p/rlpx.cpp b/test/unittests/libp2p/rlpx.cpp index e1572ab2745..1de8c32e28e 100644 --- a/test/unittests/libp2p/rlpx.cpp +++ b/test/unittests/libp2p/rlpx.cpp @@ -97,10 +97,10 @@ BOOST_AUTO_TEST_CASE(test_secrets_cpp_vectors) BOOST_REQUIRE(ephemeralShared == *(Secret*)keyMaterialBytes.data()); CryptoPP::Keccak_256 ctx; - ctx.Update(leftNonce.data(), h256::size); - ctx.Update(rightNonce.data(), h256::size); + ctx.Update(reinterpret_cast(leftNonce.data()), h256::size); + ctx.Update(reinterpret_cast(rightNonce.data()), h256::size); bytes expected(32); - ctx.Final(expected.data()); + ctx.Final(reinterpret_cast(expected.data())); bytes given(32); outRef.copyTo(&given); BOOST_REQUIRE(expected == given); @@ -119,9 +119,9 @@ BOOST_AUTO_TEST_CASE(test_secrets_cpp_vectors) BOOST_REQUIRE(ephemeralShared == *(Secret*)keyMaterialBytes.data()); CryptoPP::Keccak_256 ctx; - ctx.Update(preImage.data(), preImage.size()); + ctx.Update(reinterpret_cast(preImage.data()), preImage.size()); bytes expected(32); - ctx.Final(expected.data()); + ctx.Final(reinterpret_cast(expected.data())); bytes test(32); outRef.copyTo(&test); BOOST_REQUIRE(expected == test); @@ -137,15 +137,15 @@ BOOST_AUTO_TEST_CASE(test_secrets_cpp_vectors) bytes aesSecret(32); outRef.copyTo(&aesSecret); BOOST_REQUIRE(aesSecret == fromHex("12347b4784bcb4e74b84637940482852fe25d78e328cf5c6f7a396bf96cc20bb")); - m_frameEnc.SetKeyWithIV(outRef.data(), h128::size, h128().data()); - m_frameDec.SetKeyWithIV(outRef.data(), h128::size, h128().data()); + m_frameEnc.SetKeyWithIV(reinterpret_cast(const_cast(outRef.data())), h128::size, reinterpret_cast(const_cast(h128().data()))); + m_frameDec.SetKeyWithIV(reinterpret_cast(const_cast(outRef.data())), h128::size, reinterpret_cast(const_cast(h128().data()))); // mac-secret = sha3(ecdhe-shared-secret || aes-secret) sha3(keyMaterial, outRef); // output mac-secret bytes macSecret(32); outRef.copyTo(&macSecret); BOOST_REQUIRE(macSecret == fromHex("2ec149072353d54437422837c886b0538a9206e6c559f6b4a55f65a866867723")); - m_macEnc.SetKey(outRef.data(), h128::size); + m_macEnc.SetKey(reinterpret_cast(const_cast(outRef.data())), h128::size); // Initiator egress-mac: sha3(mac-secret^recipient-nonce || auth-sent-init) // ingress-mac: sha3(mac-secret^initiator-nonce || auth-recvd-ack) @@ -157,13 +157,13 @@ BOOST_AUTO_TEST_CASE(test_secrets_cpp_vectors) keyMaterialBytes.resize(h256::size + egressCipher.size()); keyMaterial.retarget(keyMaterialBytes.data(), keyMaterialBytes.size()); bytesConstRef(&egressCipher).copyTo(keyMaterial.cropped(h256::size, egressCipher.size())); - m_egressMac.Update(keyMaterial.data(), keyMaterial.size()); + m_egressMac.Update(reinterpret_cast(const_cast(keyMaterial.data())), keyMaterial.size()); { bytes egressMac; CryptoPP::Keccak_256 h(m_egressMac); bytes digest(16); - h.TruncatedFinal(digest.data(), 16); + h.TruncatedFinal(reinterpret_cast(digest.data()), 16); BOOST_REQUIRE(digest == fromHex("23e5e8efb6e3765ecae1fca9160b18df")); } @@ -173,13 +173,13 @@ BOOST_AUTO_TEST_CASE(test_secrets_cpp_vectors) keyMaterialBytes.resize(h256::size + ingressCipher.size()); keyMaterial.retarget(keyMaterialBytes.data(), keyMaterialBytes.size()); bytesConstRef(&ingressCipher).copyTo(keyMaterial.cropped(h256::size, ingressCipher.size())); - m_ingressMac.Update(keyMaterial.data(), keyMaterial.size()); + m_ingressMac.Update(reinterpret_cast(const_cast(keyMaterial.data())), keyMaterial.size()); { bytes ingressMac; CryptoPP::Keccak_256 h(m_ingressMac); bytes digest(16); - h.TruncatedFinal(digest.data(), 16); + h.TruncatedFinal(reinterpret_cast(digest.data()), 16); BOOST_REQUIRE(digest == fromHex("ceed64135852064cbdde86e7ea05e8f5")); } } @@ -240,10 +240,10 @@ BOOST_AUTO_TEST_CASE(test_secrets_from_go) BOOST_REQUIRE(ephemeralShared == *(Secret*)keyMaterialBytes.data()); CryptoPP::Keccak_256 ctx; - ctx.Update(leftNonce.data(), h256::size); - ctx.Update(rightNonce.data(), h256::size); + ctx.Update(reinterpret_cast(leftNonce.data()), h256::size); + ctx.Update(reinterpret_cast(rightNonce.data()), h256::size); bytes expected(32); - ctx.Final(expected.data()); + ctx.Final(reinterpret_cast(expected.data())); bytes given(32); outRef.copyTo(&given); BOOST_REQUIRE(expected == given); @@ -259,9 +259,9 @@ BOOST_AUTO_TEST_CASE(test_secrets_from_go) BOOST_REQUIRE(ephemeralShared == *(Secret*)keyMaterialBytes.data()); CryptoPP::Keccak_256 ctx; - ctx.Update(preImage.data(), preImage.size()); + ctx.Update(reinterpret_cast(preImage.data()), preImage.size()); bytes expected(32); - ctx.Final(expected.data()); + ctx.Final(reinterpret_cast(expected.data())); bytes test(32); outRef.copyTo(&test); BOOST_REQUIRE(expected == test); @@ -277,15 +277,15 @@ BOOST_AUTO_TEST_CASE(test_secrets_from_go) bytes aesSecret(32); outRef.copyTo(&aesSecret); BOOST_REQUIRE(aesSecret == fromHex("0xc0458fa97a5230830e05f4f20b7c755c1d4e54b1ce5cf43260bb191eef4e418d")); - m_frameEnc.SetKeyWithIV(outRef.data(), h128::size, h128().data()); - m_frameDec.SetKeyWithIV(outRef.data(), h128::size, h128().data()); + m_frameEnc.SetKeyWithIV(reinterpret_cast(const_cast(outRef.data())), h128::size, reinterpret_cast(const_cast(h128().data()))); + m_frameDec.SetKeyWithIV(reinterpret_cast(const_cast(outRef.data())), h128::size, reinterpret_cast(const_cast(h128().data()))); // mac-secret = sha3(ecdhe-shared-secret || aes-secret) sha3(keyMaterial, outRef); // output mac-secret bytes macSecret(32); outRef.copyTo(&macSecret); BOOST_REQUIRE(macSecret == fromHex("0x48c938884d5067a1598272fcddaa4b833cd5e7d92e8228c0ecdfabbe68aef7f1")); - m_macEnc.SetKey(outRef.data(), h256::size); + m_macEnc.SetKey(reinterpret_cast(const_cast(outRef.data())), h256::size); // Initiator egress-mac: sha3(mac-secret^recipient-nonce || auth-sent-init) // ingress-mac: sha3(mac-secret^initiator-nonce || auth-recvd-ack) @@ -297,13 +297,13 @@ BOOST_AUTO_TEST_CASE(test_secrets_from_go) keyMaterialBytes.resize(h256::size + egressCipher.size()); keyMaterial.retarget(keyMaterialBytes.data(), keyMaterialBytes.size()); bytesConstRef(&egressCipher).copyTo(keyMaterial.cropped(h256::size, egressCipher.size())); - m_egressMac.Update(keyMaterialBytes.data(), keyMaterialBytes.size()); + m_egressMac.Update(reinterpret_cast(const_cast(keyMaterialBytes.data())), keyMaterialBytes.size()); { bytes egressMac; CryptoPP::Keccak_256 h(m_egressMac); bytes digest(32); - h.Final(digest.data()); + h.Final(reinterpret_cast(digest.data())); BOOST_REQUIRE(digest == fromHex("0x09771e93b1a6109e97074cbe2d2b0cf3d3878efafe68f53c41bb60c0ec49097e")); } @@ -317,13 +317,13 @@ BOOST_AUTO_TEST_CASE(test_secrets_from_go) keyMaterialBytes.resize(h256::size + ingressCipher.size()); keyMaterial.retarget(keyMaterialBytes.data(), keyMaterialBytes.size()); bytesConstRef(&ingressCipher).copyTo(keyMaterial.cropped(h256::size, ingressCipher.size())); - m_ingressMac.Update(keyMaterial.data(), keyMaterial.size()); + m_ingressMac.Update(reinterpret_cast(keyMaterial.data()), keyMaterial.size()); { bytes ingressMac; CryptoPP::Keccak_256 h(m_ingressMac); bytes digest(32); - h.Final(digest.data()); + h.Final(reinterpret_cast(digest.data())); BOOST_CHECK(digest == fromHex("0x75823d96e23136c89666ee025fb21a432be906512b3dd4a3049e898adb433847")); } @@ -336,12 +336,12 @@ BOOST_AUTO_TEST_CASE(test_secrets_from_go) CryptoPP::Keccak_256 egressmac(m_egressMac); CryptoPP::Keccak_256 prevDigest(egressmac); h128 prevDigestOut; - prevDigest.TruncatedFinal(prevDigestOut.data(), h128::size); + prevDigest.TruncatedFinal(reinterpret_cast(prevDigestOut.data()), h128::size); h128 encDigest; - m_macEnc.ProcessData(encDigest.data(), prevDigestOut.data(), h128::size); + m_macEnc.ProcessData(reinterpret_cast(encDigest.data()), reinterpret_cast(prevDigestOut.data()), h128::size); encDigest ^= *(h128*)initHello.data(); - egressmac.Update(encDigest.data(), h128::size); - egressmac.TruncatedFinal(encDigest.data(), h128::size); + egressmac.Update(reinterpret_cast(encDigest.data()), h128::size); + egressmac.TruncatedFinal(reinterpret_cast(encDigest.data()), h128::size); bytes provided(16); bytesConstRef(&initHello).cropped(16, 16).copyTo(bytesRef(&provided)); @@ -352,12 +352,12 @@ BOOST_AUTO_TEST_CASE(test_secrets_from_go) CryptoPP::Keccak_256 ingressmac(m_ingressMac); CryptoPP::Keccak_256 prevDigest(ingressmac); h128 prevDigestOut; - prevDigest.TruncatedFinal(prevDigestOut.data(), h128::size); + prevDigest.TruncatedFinal(reinterpret_cast(prevDigestOut.data()), h128::size); h128 encDigest; - m_macEnc.ProcessData(encDigest.data(), prevDigestOut.data(), h128::size); + m_macEnc.ProcessData(reinterpret_cast(encDigest.data()), reinterpret_cast(prevDigestOut.data()), h128::size); encDigest ^= *(h128*)recvHello.data(); - ingressmac.Update(encDigest.data(), h128::size); - ingressmac.TruncatedFinal(encDigest.data(), h128::size); + ingressmac.Update(reinterpret_cast(const_cast(encDigest.data())), h128::size); + ingressmac.TruncatedFinal(reinterpret_cast(encDigest.data()), h128::size); bytes provided(16); bytesConstRef(&recvHello).cropped(16, 16).copyTo(bytesRef(&provided)); @@ -366,7 +366,7 @@ BOOST_AUTO_TEST_CASE(test_secrets_from_go) // test decrypt of frame headers for recvHello bytes plaintext(16); - m_frameDec.ProcessData(plaintext.data(), recvHello.data(), h128::size); + m_frameDec.ProcessData(reinterpret_cast(plaintext.data()), reinterpret_cast(recvHello.data()), h128::size); } @@ -379,35 +379,35 @@ BOOST_AUTO_TEST_CASE(ecies_interop_test_primitives) CryptoPP::SHA256 sha256ctx; bytes emptyExpected(fromHex("0xe3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855")); bytes empty; - sha256ctx.Update(empty.data(), 0); + sha256ctx.Update(reinterpret_cast(const_cast(empty.data())), 0); bytes emptyTestOut(32); - sha256ctx.Final(emptyTestOut.data()); + sha256ctx.Final(reinterpret_cast(emptyTestOut.data())); BOOST_REQUIRE(emptyExpected == emptyTestOut); bytes hash1Expected(fromHex("0x8949b278bbafb8da1aaa18cb724175c5952280f74be5d29ab4b37d1b45c84b08")); bytes hash1input(fromHex("0x55a53b55afb12affff3c")); - sha256ctx.Update(hash1input.data(), hash1input.size()); + sha256ctx.Update(reinterpret_cast(const_cast(hash1input.data())), hash1input.size()); bytes hash1Out(32); - sha256ctx.Final(hash1Out.data()); + sha256ctx.Final(reinterpret_cast(hash1Out.data())); BOOST_REQUIRE(hash1Out == hash1Expected); h128 hmack(fromHex("0x07a4b6dfa06369a570f2dcba2f11a18f")); - CryptoPP::HMAC hmacctx(hmack.data(), h128::size); + CryptoPP::HMAC hmacctx(reinterpret_cast(const_cast(hmack.data())), h128::size); bytes input(fromHex("0x4dcb92ed4fc67fe86832")); - hmacctx.Update(input.data(), input.size()); + hmacctx.Update(reinterpret_cast(const_cast(input.data())), input.size()); bytes hmacExpected(fromHex("0xc90b62b1a673b47df8e395e671a68bfa68070d6e2ef039598bb829398b89b9a9")); bytes hmacOut(hmacExpected.size()); - hmacctx.Final(hmacOut.data()); + hmacctx.Final(reinterpret_cast(hmacOut.data())); BOOST_REQUIRE(hmacExpected == hmacOut); // go messageTag bytes tagSecret(fromHex("0xaf6623e52208c596e17c72cea6f1cb09")); bytes tagInput(fromHex("0x3461282bcedace970df2")); bytes tagExpected(fromHex("0xb3ce623bce08d5793677ba9441b22bb34d3e8a7de964206d26589df3e8eb5183")); - CryptoPP::HMAC hmactagctx(tagSecret.data(), tagSecret.size()); - hmactagctx.Update(tagInput.data(), tagInput.size()); + CryptoPP::HMAC hmactagctx(reinterpret_cast(const_cast(tagSecret.data())), tagSecret.size()); + hmactagctx.Update(reinterpret_cast(const_cast(tagInput.data())), tagInput.size()); h256 mac; - hmactagctx.Final(mac.data()); + hmactagctx.Final(reinterpret_cast(mac.data())); BOOST_REQUIRE(mac.asBytes() == tagExpected); Secret input1(fromHex("0x0de72f1223915fa8b8bf45dffef67aef8d89792d116eb61c9a1eb02c422a4663")); diff --git a/test/unittests/libweb3core/memorydb.cpp b/test/unittests/libweb3core/memorydb.cpp index cc114ca04aa..1b0f0b6ec47 100644 --- a/test/unittests/libweb3core/memorydb.cpp +++ b/test/unittests/libweb3core/memorydb.cpp @@ -58,13 +58,13 @@ BOOST_AUTO_TEST_CASE(purgeMainMem) MemoryDB copy; copy = myDB; BOOST_CHECK(myDB.exists(h256(42))); - BOOST_CHECK_EQUAL(myDB.lookup(h256(42)), toString(value[0])); + BOOST_CHECK_EQUAL(myDB.lookup(h256(42)), toString(to_integer(value[0]))); BOOST_CHECK_EQUAL(myDB.get().size(), 1); BOOST_CHECK(myDB.kill(h256(42))); BOOST_CHECK(myDB.get() == copy.get()); BOOST_CHECK(myDB.exists(h256(42))); - BOOST_CHECK_EQUAL(myDB.lookup(h256(42)), toString(value[0])); + BOOST_CHECK_EQUAL(myDB.lookup(h256(42)), toString(to_integer(value[0]))); BOOST_CHECK_EQUAL(myDB.get().size(), 1); myDB.purge(); @@ -88,7 +88,7 @@ BOOST_AUTO_TEST_CASE(purgeMainMem_Refs) MemoryDB copy; copy = myDB; BOOST_CHECK(myDB.exists(h256(42))); - BOOST_CHECK_EQUAL(myDB.lookup(h256(42)), toString(value[0])); + BOOST_CHECK_EQUAL(myDB.lookup(h256(42)), toString(to_integer(value[0]))); BOOST_CHECK_EQUAL(myDB.get().size(), 1); BOOST_CHECK(myDB.kill(h256(42))); @@ -114,13 +114,13 @@ BOOST_AUTO_TEST_CASE(purgeMainMem_Refs) MemoryDB copy; copy = myDB; BOOST_CHECK(myDB.exists(h256(42))); - BOOST_CHECK_EQUAL(myDB.lookup(h256(42)), toString(value[0])); + BOOST_CHECK_EQUAL(myDB.lookup(h256(42)), toString(to_integer(value[0]))); BOOST_CHECK_EQUAL(myDB.get().size(), 1); BOOST_CHECK(myDB.kill(h256(42))); BOOST_CHECK(myDB.get() == copy.get()); BOOST_CHECK(myDB.exists(h256(42))); - BOOST_CHECK_EQUAL(myDB.lookup(h256(42)), toString(value[0])); + BOOST_CHECK_EQUAL(myDB.lookup(h256(42)), toString(to_integer(value[0]))); BOOST_CHECK_EQUAL(myDB.get().size(), 1); myDB.purge(); @@ -185,16 +185,16 @@ BOOST_AUTO_TEST_CASE(lookUp) myDB.insert(h256(42), &value); BOOST_CHECK(myDB.exists(h256(42))); - BOOST_CHECK_EQUAL(myDB.lookup(h256(42)), toString(value[0])); + BOOST_CHECK_EQUAL(myDB.lookup(h256(42)), toString(to_integer(value[0]))); BOOST_CHECK_EQUAL(myDB.get().size(), 1); myDB.insert(h256(0), &value); BOOST_CHECK(myDB.exists(h256(0))); - BOOST_CHECK_EQUAL(myDB.lookup(h256(0)), toString(value[0])); + BOOST_CHECK_EQUAL(myDB.lookup(h256(0)), toString(to_integer(value[0]))); myDB.insert(h256(std::numeric_limits::max()), &value); BOOST_CHECK(myDB.exists(h256(std::numeric_limits::max()))); - BOOST_CHECK_EQUAL(myDB.lookup(h256(std::numeric_limits::max())), toString(value[0])); + BOOST_CHECK_EQUAL(myDB.lookup(h256(std::numeric_limits::max())), toString(to_integer(value[0]))); BOOST_CHECK_EQUAL(myDB.get().size(), 3); } diff --git a/test/unittests/libweb3core/overlaydb.cpp b/test/unittests/libweb3core/overlaydb.cpp index c6816bc8299..919c5e4e4d3 100644 --- a/test/unittests/libweb3core/overlaydb.cpp +++ b/test/unittests/libweb3core/overlaydb.cpp @@ -53,18 +53,18 @@ BOOST_AUTO_TEST_CASE(basicUsage) odb.insert(h256(42), &value); BOOST_CHECK(odb.get().size()); BOOST_CHECK(odb.exists(h256(42))); - BOOST_CHECK_EQUAL(odb.lookup(h256(42)), toString(value[0])); + BOOST_CHECK_EQUAL(odb.lookup(h256(42)), toString(to_integer(value[0]))); odb.commit(); BOOST_CHECK(!odb.get().size()); BOOST_CHECK(odb.exists(h256(42))); - BOOST_CHECK_EQUAL(odb.lookup(h256(42)), toString(value[0])); + BOOST_CHECK_EQUAL(odb.lookup(h256(42)), toString(to_integer(value[0]))); odb.insert(h256(41), &value); odb.commit(); BOOST_CHECK(!odb.get().size()); BOOST_CHECK(odb.exists(h256(41))); - BOOST_CHECK_EQUAL(odb.lookup(h256(41)), toString(value[0])); + BOOST_CHECK_EQUAL(odb.lookup(h256(41)), toString(to_integer(value[0]))); } BOOST_AUTO_TEST_CASE(auxMem) @@ -95,13 +95,13 @@ BOOST_AUTO_TEST_CASE(auxMem) BOOST_CHECK(!odb.get().size()); BOOST_CHECK(odb.exists(h256(42))); - BOOST_CHECK_EQUAL(odb.lookup(h256(42)), toString(value[0])); + BOOST_CHECK_EQUAL(odb.lookup(h256(42)), toString(to_integer(value[0]))); BOOST_CHECK(odb.exists(h256(0))); - BOOST_CHECK_EQUAL(odb.lookup(h256(0)), toString(value[0])); + BOOST_CHECK_EQUAL(odb.lookup(h256(0)), toString(to_integer(value[0]))); BOOST_CHECK(odb.exists(h256(std::numeric_limits::max()))); - BOOST_CHECK_EQUAL(odb.lookup(h256(std::numeric_limits::max())), toString(value[0])); + BOOST_CHECK_EQUAL(odb.lookup(h256(std::numeric_limits::max())), toString(to_integer(value[0]))); BOOST_CHECK(odb.lookupAux(h256(42)) == valueAux); BOOST_CHECK(odb.lookupAux(h256(0)) == valueAux); diff --git a/test/unittests/libwhisper/whisperMessage.cpp b/test/unittests/libwhisper/whisperMessage.cpp index 6a9cb7bf70a..8bd4ef80534 100644 --- a/test/unittests/libwhisper/whisperMessage.cpp +++ b/test/unittests/libwhisper/whisperMessage.cpp @@ -48,7 +48,7 @@ bytes createRandomPayload(unsigned int i) srand(i); int const sz = rand() % 1024; for (int j = 0; j < sz; ++j) - ret.push_back(rand() % 256); + ret.push_back(static_cast(rand() % 256)); return ret; } @@ -60,7 +60,7 @@ void comparePayloads(Message const& m1, Message const& m2) BOOST_REQUIRE_EQUAL(p1.size(), p2.size()); for (size_t i = 0; i < p1.size(); ++i) - BOOST_REQUIRE_EQUAL(p1[i], p2[i]); + BOOST_REQUIRE_EQUAL(to_integer(p1[i]), to_integer(p2[i])); } void sealAndOpenSingleMessage(unsigned int i)