trustwallet / wallet-core

Cross-platform, cross-blockchain wallet library.
https://developer.trustwallet.com/wallet-core
Apache License 2.0
2.76k stars 1.55k forks source link

[Improvements]: Remove usage of boost library #2540

Open Milerius opened 1 year ago

Milerius commented 1 year ago

Motivation

Most of the use of boost in the project is replaceable by our own implementations or the standard library.

This passing of dependencies in the project allows us to have more sovereignty, simplify security audits and facilitate compilation in wasm and facilitate the distribution/compilation of the project.

Additional context

➜  src git:(m/ontology_variant) ✗ grep -Hrn "boost" .
./Crc.cpp:9:#include <boost/crc.hpp>  // for boost::crc_32_type
./Crc.cpp:37:    boost::crc_32_type result;
./Crc.cpp:44:    using crc_32c_type = boost::crc_optimal<32, 0x1EDC6F41, 0xFFFFFFFF, 0xFFFFFFFF, true, true>;
./Keystore/EncryptionParameters.h:15:#include <boost/variant.hpp>
./Keystore/EncryptionParameters.h:43:    boost::variant<ScryptParameters, PBKDF2Parameters> kdfParams = ScryptParameters();
./Keystore/EncryptionParameters.h:48:    EncryptionParameters(AESParameters cipherParams, boost::variant<ScryptParameters, PBKDF2Parameters> kdfParams)
./Keystore/EncryptionParameters.cpp:16:#include <boost/variant/get.hpp>
./Keystore/EncryptionParameters.cpp:62:        auto scryptParams = boost::get<ScryptParameters>(kdfParams);
./Keystore/EncryptionParameters.cpp:66:        auto pbkdf2Params = boost::get<PBKDF2Parameters>(kdfParams);
./Keystore/EncryptionParameters.cpp:76:    auto scryptParams = boost::get<ScryptParameters>(params.kdfParams);
./Keystore/EncryptionParameters.cpp:104:        auto scryptParams = boost::get<ScryptParameters>(params.kdfParams);
./Keystore/EncryptionParameters.cpp:111:        auto pbkdf2Params = boost::get<PBKDF2Parameters>(params.kdfParams);
./Keystore/StoredKey.cpp:16:#include <boost/lexical_cast.hpp>
./Keystore/StoredKey.cpp:17:#include <boost/uuid/uuid.hpp>
./Keystore/StoredKey.cpp:18:#include <boost/uuid/uuid_generators.hpp>
./Keystore/StoredKey.cpp:19:#include <boost/uuid/uuid_io.hpp>
./Keystore/StoredKey.cpp:77:    boost::uuids::random_generator gen;
./Keystore/StoredKey.cpp:78:    id = boost::lexical_cast<std::string>(gen());
./Tezos/Forging.cpp:282:    auto abs = boost::multiprecision::abs(value);
./Base64.cpp:9:#include <boost/algorithm/string.hpp>
./Base64.cpp:10:#include <boost/archive/iterators/base64_from_binary.hpp>
./Base64.cpp:11:#include <boost/archive/iterators/binary_from_base64.hpp>
./Base64.cpp:12:#include <boost/archive/iterators/transform_width.hpp>
./Base64.cpp:20:    using namespace boost::archive::iterators;
./Base64.cpp:22:    return boost::algorithm::trim_right_copy_if(Data(It(begin(val)), It(end(val))),
./Base64.cpp:27:    using namespace boost::archive::iterators;
./Base64.cpp:72:    using namespace boost::archive::iterators;
./Aion/RLP.h:13:#include <boost/multiprecision/cpp_int.hpp>
./Aion/RLP.h:23:    static Data encodeLong(boost::multiprecision::uint128_t l) noexcept {
./Aion/Transaction.cpp:12:using boost::multiprecision::uint128_t;
./Aion/Signer.cpp:11:#include <boost/multiprecision/cpp_int.hpp>
./Aion/Signer.cpp:18:    using boost::multiprecision::uint128_t;
./Aion/Transaction.h:12:#include <boost/multiprecision/cpp_int.hpp>
./Aion/Transaction.h:18:    using uint128_t = boost::multiprecision::uint128_t;
./Nano/Signer.cpp:14:#include <boost/multiprecision/cpp_int.hpp>
./Nano/Signer.cpp:19:using uint128_t = boost::multiprecision::uint128_t;
./Nano/Signer.cpp:32:    using boost::multiprecision::cpp_int;
./VeChain/Signer.h:15:#include <boost/multiprecision/cpp_int.hpp>
./Harmony/Staking.h:9:#include <boost/algorithm/string.hpp>
./Harmony/Signer.h:16:#include <boost/multiprecision/cpp_int.hpp>
./HexCoding.h:11:#include <boost/algorithm/hex.hpp>
./HexCoding.h:74:        boost::algorithm::unhex(it, end, std::back_inserter(temp));
./uint256.h:11:#include <boost/lexical_cast.hpp>
./uint256.h:12:#include <boost/multiprecision/cpp_int.hpp>
./uint256.h:16:using int256_t = boost::multiprecision::int256_t;
./uint256.h:17:using uint256_t = boost::multiprecision::uint256_t;
./uint256.h:22:    using boost::multiprecision::cpp_int;
./uint256.h:35:    using boost::multiprecision::cpp_int;
./uint256.h:48:    using boost::multiprecision::cpp_int;
./uint256.h:61:    using boost::multiprecision::cpp_int;
./uint256.h:90:    return boost::lexical_cast<std::string>(value);
./Icon/Signer.cpp:15:#include <boost/multiprecision/cpp_int.hpp>
./Polkadot/ScaleCodec.h:13:#include <boost/multiprecision/cpp_int.hpp>
./Polkadot/ScaleCodec.h:20:using CompactInteger = boost::multiprecision::cpp_int;
./EOS/Name.cpp:10:#include <boost/algorithm/string/trim.hpp>
./EOS/Name.cpp:56:    boost::algorithm::trim_right_if( str, []( char c ){ return c == '.'; } );
./EOS/Asset.cpp:9:#include <boost/algorithm/string/trim.hpp>
./EOS/Asset.cpp:10:#include <boost/lexical_cast.hpp>
./EOS/Asset.cpp:43:    boost::algorithm::trim(assetString);
./EOS/Asset.cpp:51:    auto symbolString = boost::algorithm::trim_copy(assetString.substr(spacePosition + 1));
./EOS/Asset.cpp:70:        intPart = boost::lexical_cast<int64_t>(amountString.data(), dotPosition);
./EOS/Asset.cpp:71:        fractPart = boost::lexical_cast<int64_t>(amountString.data() + dotPosition + 1, decimals);
./EOS/Asset.cpp:76:        intPart = boost::lexical_cast<int64_t>(amountString);
./Ethereum/ContractCall.cpp:11:#include <boost/algorithm/string/predicate.hpp>
./Ethereum/ContractCall.cpp:26:    if (boost::algorithm::ends_with(type, "[]")) {
./Ethereum/ContractCall.cpp:67:        if (boost::algorithm::ends_with(type.get<string>(), "[]")) {
./Ethereum/ABI/ParamNumber.h:15:#include <boost/lexical_cast.hpp>
./Ethereum/ABI/ParamNumber.h:60:        return boost::conversion::detail::try_lexical_convert(value, _val);
./Ethereum/ABI/ParamFactory.cpp:12:#include <boost/algorithm/string/predicate.hpp>
./Ethereum/ABI/ParamFactory.cpp:15:using namespace boost::algorithm;
./Ethereum/ABI/ParamFactory.cpp:146:        result = boost::lexical_cast<std::string>((uint)dynamic_pointer_cast<ParamUInt8>(param)->getVal());
./Ethereum/ABI/ParamFactory.cpp:148:        result = boost::lexical_cast<std::string>(dynamic_pointer_cast<ParamUInt16>(param)->getVal());
./Ethereum/ABI/ParamFactory.cpp:150:        result = boost::lexical_cast<std::string>(dynamic_pointer_cast<ParamUInt32>(param)->getVal());
./Ethereum/ABI/ParamFactory.cpp:152:        result = boost::lexical_cast<std::string>(dynamic_pointer_cast<ParamUInt64>(param)->getVal());
./Ethereum/ABI/ParamFactory.cpp:154:        result = boost::lexical_cast<std::string>(dynamic_pointer_cast<ParamUInt256>(param)->getVal());
./Ethereum/ABI/ParamFactory.cpp:156:        result = boost::lexical_cast<std::string>((int)dynamic_pointer_cast<ParamInt8>(param)->getVal());
./Ethereum/ABI/ParamFactory.cpp:158:        result = boost::lexical_cast<std::string>(dynamic_pointer_cast<ParamInt16>(param)->getVal());
./Ethereum/ABI/ParamFactory.cpp:160:        result = boost::lexical_cast<std::string>(dynamic_pointer_cast<ParamInt32>(param)->getVal());
./Ethereum/ABI/ParamFactory.cpp:162:        result = boost::lexical_cast<std::string>(dynamic_pointer_cast<ParamInt64>(param)->getVal());
./Ethereum/ABI/ParamFactory.cpp:164:        result = boost::lexical_cast<std::string>(dynamic_pointer_cast<ParamInt256>(param)->getVal());
./Ethereum/ABI/ParamFactory.cpp:167:        result = boost::lexical_cast<std::string>(value->getVal());
./Ethereum/ABI/ParamFactory.cpp:170:        result = boost::lexical_cast<std::string>(value->getVal());
./Ethereum/ABI/ParamNumber.cpp:13:#include <boost/lexical_cast.hpp>
./Ethereum/ABI/ParamNumber.cpp:28:    return boost::conversion::detail::try_lexical_convert(value, dest);
./Ethereum/ABI/ParamNumber.cpp:37:    return boost::conversion::detail::try_lexical_convert(value, dest);
./Ethereum/ABI/ParamNumber.cpp:48:    if (!boost::conversion::detail::try_lexical_convert(value, val)) { return false; }
./Ethereum/ABI/ParamNumber.cpp:55:    if (!boost::conversion::detail::try_lexical_convert(value, val)) { return false; }
./Ethereum/RLP.cpp:19:    using boost::multiprecision::cpp_int;
./Ethereum/Signer.cpp:87:    boost::multiprecision::uint256_t r, s, v;
./Ethereum/Signer.h:17:#include <boost/multiprecision/cpp_int.hpp>
hewigovens commented 1 year ago

Nice wrap up , can you sort them from easy/small to hard? so we can tackle one by one

Milerius commented 1 year ago

Nice wrap up , can you sort them from easy/small to hard? so we can tackle one by one

done

gituser commented 1 year ago

While you are at it, maybe also get rid of ruby / rust as the project is in C++?

Also noticed the actual requirements isn't listed here: https://developer.trustwallet.com/wallet-core/developing-the-library/building

As you need Ubuntu 20.04+, ruby > 2.6, latest rust, clang-14. Building wallet-core on Ubuntu 18.04 no longer works.

Milerius commented 1 year ago

While you are at it, maybe also get rid of ruby / rust as the project is in C++?

Also noticed the actual requirements isn't listed here: https://developer.trustwallet.com/wallet-core/developing-the-library/building

As you need Ubuntu 20.04+, ruby > 2.6, latest rust, clang-14. Building wallet-core on Ubuntu 18.04 no longer works.

Rust is something that we would like to extend in the future, most likely moving C++ logic to rust.

Regarding ruby, it's used for codegen our bindings in swift wasm and kotlin, we do not plan to remove it for now, eventually the tool will be re-written in rust