From 5281c5fc97a1953975ba8bdb9cb72a7d1788d5f2 Mon Sep 17 00:00:00 2001 From: Anthony Tseng Date: Tue, 23 Aug 2022 18:04:27 -0700 Subject: [PATCH] Revert Boost BigInt workaround --- .gitignore | 2 -- DEPS | 2 -- build/BUILD.gn | 4 ++++ .../brave_wallet/browser/eth_abi_decoder.cc | 4 ++-- .../brave_wallet/browser/fil_tx_manager.cc | 8 +++++-- components/brave_wallet/common/BUILD.gn | 2 -- .../brave_wallet/common/brave_wallet_types.h | 24 ++++++++----------- components/brave_wallet/common/hex_utils.cc | 7 +----- third_party/boost/BUILD.gn | 19 --------------- third_party/boost/LICENSE | 23 ------------------ third_party/boost/README.chromium | 5 ---- 11 files changed, 23 insertions(+), 77 deletions(-) delete mode 100644 third_party/boost/BUILD.gn delete mode 100644 third_party/boost/LICENSE delete mode 100644 third_party/boost/README.chromium diff --git a/.gitignore b/.gitignore index 1d47f7b39d8..5d082239a12 100644 --- a/.gitignore +++ b/.gitignore @@ -16,8 +16,6 @@ patches/**/*.patchinfo /third_party/argon2/src /third_party/ethash/src /third_party/bitcoin-core/src -/third_party/boost/config -/third_party/boost/multiprecision /third_party/rust/cxx *.xcodeproj *.swp diff --git a/DEPS b/DEPS index b1addc108d1..8a5502693c1 100644 --- a/DEPS +++ b/DEPS @@ -24,8 +24,6 @@ deps = { "third_party/ethash/src": "https://github.com/chfast/ethash.git@e4a15c3d76dc09392c7efd3e30d84ee3b871e9ce", "third_party/bitcoin-core/src": "https://github.com/bitcoin/bitcoin.git@95ea54ba089610019a74c1176a2c7c0dba144b1c", "third_party/argon2/src": "https://github.com/P-H-C/phc-winner-argon2.git@62358ba2123abd17fccf2a108a301d4b52c01a7c", - "third_party/boost/config": "https://github.com/boostorg/config.git@e108255ffb5d2557ed3398b3fc575a2e9fd434cc", - "third_party/boost/multiprecision": "https://github.com/boostorg/multiprecision.git@32aefd37f055cc2abeced1cd2873b4564ea339f2", } recursedeps = [ diff --git a/build/BUILD.gn b/build/BUILD.gn index 45d164d81f3..fc7951f8346 100644 --- a/build/BUILD.gn +++ b/build/BUILD.gn @@ -28,6 +28,10 @@ if (is_redirect_cc_build) { } config("compiler") { + cflags = [ + "-Xclang", + "-fexperimental-max-bitint-width=256", + ] configs = [ ":brave_chromium_src_support" ] if (is_redirect_cc_build) { configs -= [ ":brave_chromium_src_support" ] diff --git a/components/brave_wallet/browser/eth_abi_decoder.cc b/components/brave_wallet/browser/eth_abi_decoder.cc index 95013d1da7b..73ef4540c17 100644 --- a/components/brave_wallet/browser/eth_abi_decoder.cc +++ b/components/brave_wallet/browser/eth_abi_decoder.cc @@ -125,9 +125,9 @@ absl::optional GetBoolFromData(const std::vector& input, if (!value) return absl::nullopt; - if (value == 0) + if (value == static_cast(0)) return "false"; - else if (value == 1) + else if (value == static_cast(1)) return "true"; return absl::nullopt; diff --git a/components/brave_wallet/browser/fil_tx_manager.cc b/components/brave_wallet/browser/fil_tx_manager.cc index 471aad6a993..85f4ebb6474 100644 --- a/components/brave_wallet/browser/fil_tx_manager.cc +++ b/components/brave_wallet/browser/fil_tx_manager.cc @@ -178,7 +178,9 @@ void FilTxManager::OnGetNextNonce(std::unique_ptr meta, l10n_util::GetStringUTF8(IDS_WALLET_GET_NONCE_ERROR)); return; } - DCHECK_LE(nonce, static_cast(UINT64_MAX)); + // DCHECK_LE will eventually be expanded into `CheckOpValueStr` which doesn't + // have uint256_t overload. + DCHECK(nonce <= static_cast(UINT64_MAX)); meta->tx()->set_nonce(static_cast(nonce)); DCHECK(!keyring_service_->IsLocked()); meta->set_status(mojom::TransactionStatus::Approved); @@ -296,7 +298,9 @@ void FilTxManager::OnGetNextNonceForHardware( std::move(callback).Run(nullptr); return; } - DCHECK_LE(nonce, static_cast(UINT64_MAX)); + // DCHECK_LE will eventually be expanded into `CheckOpValueStr` which doesn't + // have uint256_t overload. + DCHECK(nonce <= static_cast(UINT64_MAX)); meta->tx()->set_nonce(static_cast(nonce)); DCHECK(!keyring_service_->IsLocked()); meta->set_status(mojom::TransactionStatus::Approved); diff --git a/components/brave_wallet/common/BUILD.gn b/components/brave_wallet/common/BUILD.gn index cd03bb88c15..d610329b631 100644 --- a/components/brave_wallet/common/BUILD.gn +++ b/components/brave_wallet/common/BUILD.gn @@ -52,8 +52,6 @@ static_library("common") { "//net", "//url", ] - - public_deps = [ "//brave/third_party/boost" ] } source_set("common_constants") { diff --git a/components/brave_wallet/common/brave_wallet_types.h b/components/brave_wallet/common/brave_wallet_types.h index 4c7dd7cc745..bb4bc43c780 100644 --- a/components/brave_wallet/common/brave_wallet_types.h +++ b/components/brave_wallet/common/brave_wallet_types.h @@ -11,29 +11,25 @@ #include #include "base/values.h" -#include "boost/multiprecision/cpp_int.hpp" #include "third_party/abseil-cpp/absl/types/optional.h" namespace brave_wallet { -typedef boost::multiprecision::uint256_t uint256_t; -typedef boost::multiprecision::int256_t int256_t; +using uint256_t = unsigned _BitInt(256); +using int256_t = _BitInt(256); -typedef boost::multiprecision::uint128_t uint128_t; -typedef boost::multiprecision::int128_t int128_t; - -// Note that boost's int256/128_t has 256/128 precision bits and it uses an -// extra sign bit so its max and min value differs from 2's complement types. +using uint128_t = unsigned _BitInt(128); +using int128_t = _BitInt(128); // 2^255 - 1 -constexpr int256_t kMax256BitInt = std::numeric_limits::max() >> 1; +constexpr int256_t kMax256BitInt = std::numeric_limits::max(); // -(2^255 -1) -constexpr int256_t kMin256BitInt = std::numeric_limits::min() >> 1; +constexpr int256_t kMin256BitInt = std::numeric_limits::min(); -// 2^128 - 1 -constexpr int128_t kMax128BitInt = std::numeric_limits::max() >> 1; -// -(2^128 -1) -constexpr int128_t kMin128BitInt = std::numeric_limits::min() >> 1; +// 2^127 - 1 +constexpr int128_t kMax128BitInt = std::numeric_limits::max(); +// -(2^127 -1) +constexpr int128_t kMin128BitInt = std::numeric_limits::min(); constexpr uint64_t kMaxSafeIntegerUint64 = 9007199254740991; // 2^53-1 diff --git a/components/brave_wallet/common/hex_utils.cc b/components/brave_wallet/common/hex_utils.cc index 427b04c4036..81f6d9c6795 100644 --- a/components/brave_wallet/common/hex_utils.cc +++ b/components/brave_wallet/common/hex_utils.cc @@ -136,12 +136,7 @@ bool HexValueToInt256(const std::string& hex_input, int256_t* out) { // This is the same as ~val + 1 // To convert a positive number into a negative number, using the two’s // complement representation, invert all of the bits of the number + 1 - if (val >> 255) { - *out = ~val + 1; - *out = -*out; - } else { - *out = static_cast(val); - } + *out = static_cast(val); return true; } diff --git a/third_party/boost/BUILD.gn b/third_party/boost/BUILD.gn deleted file mode 100644 index 191a1727b89..00000000000 --- a/third_party/boost/BUILD.gn +++ /dev/null @@ -1,19 +0,0 @@ -config("boost_config") { - visibility = [ ":*" ] - - defines = [ - "BOOST_MP_STANDALONE=1", - "BOOST_NO_EXCEPTIONS=1", - "BOOST_DISABLE_THREADS=1", - ] - - include_dirs = [ - "config/include", - "multiprecision/include", - ] -} - -group("boost") { - visibility = [ "//brave/components/brave_wallet/common" ] - public_configs = [ ":boost_config" ] -} diff --git a/third_party/boost/LICENSE b/third_party/boost/LICENSE deleted file mode 100644 index 36b7cd93cdf..00000000000 --- a/third_party/boost/LICENSE +++ /dev/null @@ -1,23 +0,0 @@ -Boost Software License - Version 1.0 - August 17th, 2003 - -Permission is hereby granted, free of charge, to any person or organization -obtaining a copy of the software and accompanying documentation covered by -this license (the "Software") to use, reproduce, display, distribute, -execute, and transmit the Software, and to prepare derivative works of the -Software, and to permit third-parties to whom the Software is furnished to -do so, all subject to the following: - -The copyright notices in the Software and this entire statement, including -the above license grant, this restriction and the following disclaimer, -must be included in all copies of the Software, in whole or in part, and -all derivative works of the Software, unless such copies or derivative -works are solely in the form of machine-executable object code generated by -a source language processor. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT -SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE -FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, -ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER -DEALINGS IN THE SOFTWARE. diff --git a/third_party/boost/README.chromium b/third_party/boost/README.chromium deleted file mode 100644 index 928efea9304..00000000000 --- a/third_party/boost/README.chromium +++ /dev/null @@ -1,5 +0,0 @@ -Name: Boost Library -URL: https://github.com/boostorg/boost -License: Boost Software License 1.0 -License File: LICENSE -