-
Notifications
You must be signed in to change notification settings - Fork 1.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
backport: merge bitcoin#22976, #23242, #23155, #22787, #23602, #12315, #22805, #23640, #23879, #24154, #23975, #12677, #23408, partial bitcoin#20861 (auxiliary backports: part 23) #6542
Changes from all commits
756f227
0220757
3f8593d
b88769e
650ee25
98d21f1
0328045
f1e7245
57c0671
be215a9
4632cdd
3740522
7ca7dac
84b9711
b78a8c0
480122e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,14 @@ | ||
// Copyright (c) 2017 Pieter Wuille | ||
// Copyright (c) 2017, 2021 Pieter Wuille | ||
// Distributed under the MIT software license, see the accompanying | ||
// file COPYING or http://www.opensource.org/licenses/mit-license.php. | ||
|
||
// Bech32 is a string encoding format used in newer address types. | ||
// The output consists of a human-readable part (alphanumeric), a | ||
// separator character (1), and a base32 data section, the last | ||
// 6 characters of which are a checksum. | ||
// Bech32 and Bech32m are string encoding formats used in newer | ||
// address types. The outputs consist of a human-readable part | ||
// (alphanumeric), a separator character (1), and a base32 data | ||
// section, the last 6 characters of which are a checksum. The | ||
// module is namespaced under bech32 for historical reasons. | ||
// | ||
// For more information, see BIP 173. | ||
// For more information, see BIP 173 and BIP 350. | ||
|
||
#ifndef BITCOIN_BECH32_H | ||
#define BITCOIN_BECH32_H | ||
|
@@ -19,11 +20,29 @@ | |
namespace bech32 | ||
{ | ||
|
||
/** Encode a Bech32 string. If hrp contains uppercase characters, this will cause an assertion error. */ | ||
std::string Encode(const std::string& hrp, const std::vector<uint8_t>& values); | ||
enum class Encoding { | ||
INVALID, //!< Failed decoding | ||
|
||
/** Decode a Bech32 string. Returns (hrp, data). Empty hrp means failure. */ | ||
std::pair<std::string, std::vector<uint8_t>> Decode(const std::string& str); | ||
BECH32, //!< Bech32 encoding as defined in BIP173 | ||
BECH32M, //!< Bech32m encoding as defined in BIP350 | ||
}; | ||
|
||
/** Encode a Bech32 or Bech32m string. If hrp contains uppercase characters, this will cause an | ||
* assertion error. Encoding must be one of BECH32 or BECH32M. */ | ||
std::string Encode(Encoding encoding, const std::string& hrp, const std::vector<uint8_t>& values); | ||
|
||
Comment on lines
+30
to
+32
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 💡 Verification agent 🧩 Analysis chainUpdate all calls to The Run the following script to identify any calls to 🏁 Script executed: #!/bin/bash
# Description: Find all calls to `Encode` missing the new `Encoding` parameter.
# Search for calls to Encode with only two parameters (old signature)
rg 'Encode\(\s*[^,]+,\s*[^,]+\s*\)' --glob '*.cpp' --glob '*.h' Length of output: 133 Missing Encoding Parameter in The output from the shell script found a call to
Please update these calls accordingly to ensure the code compiles and functions as expected. |
||
struct DecodeResult | ||
{ | ||
Encoding encoding; //!< What encoding was detected in the result; Encoding::INVALID if failed. | ||
std::string hrp; //!< The human readable part | ||
std::vector<uint8_t> data; //!< The payload (excluding checksum) | ||
|
||
DecodeResult() : encoding(Encoding::INVALID) {} | ||
DecodeResult(Encoding enc, std::string&& h, std::vector<uint8_t>&& d) : encoding(enc), hrp(std::move(h)), data(std::move(d)) {} | ||
}; | ||
|
||
/** Decode a Bech32 or Bech32m string. */ | ||
DecodeResult Decode(const std::string& str); | ||
|
||
} // namespace bech32 | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -66,11 +66,11 @@ void CCoinJoinClientOptions::Init() | |
assert(!CCoinJoinClientOptions::_instance); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fix formatting according to clang-format. The pipeline failure indicates formatting issues that need to be addressed. Run clang-format on the file to fix the formatting issues: clang-format -i src/coinjoin/options.cpp 🧰 Tools🪛 GitHub Actions: Clang Diff Format Check[warning] 66-66: Clang format differences found. Code does not adhere to formatting standards. |
||
static CCoinJoinClientOptions instance; | ||
instance.fCoinJoinMultiSession = gArgs.GetBoolArg("-coinjoinmultisession", DEFAULT_COINJOIN_MULTISESSION); | ||
instance.nCoinJoinSessions = std::min(std::max((int)gArgs.GetArg("-coinjoinsessions", DEFAULT_COINJOIN_SESSIONS), MIN_COINJOIN_SESSIONS), MAX_COINJOIN_SESSIONS); | ||
instance.nCoinJoinRounds = std::min(std::max((int)gArgs.GetArg("-coinjoinrounds", DEFAULT_COINJOIN_ROUNDS), MIN_COINJOIN_ROUNDS), MAX_COINJOIN_ROUNDS); | ||
instance.nCoinJoinAmount = std::min(std::max((int)gArgs.GetArg("-coinjoinamount", DEFAULT_COINJOIN_AMOUNT), MIN_COINJOIN_AMOUNT), MAX_COINJOIN_AMOUNT); | ||
instance.nCoinJoinDenomsGoal = std::min(std::max((int)gArgs.GetArg("-coinjoindenomsgoal", DEFAULT_COINJOIN_DENOMS_GOAL), MIN_COINJOIN_DENOMS_GOAL), MAX_COINJOIN_DENOMS_GOAL); | ||
instance.nCoinJoinDenomsHardCap = std::min(std::max((int)gArgs.GetArg("-coinjoindenomshardcap", DEFAULT_COINJOIN_DENOMS_HARDCAP), MIN_COINJOIN_DENOMS_HARDCAP), MAX_COINJOIN_DENOMS_HARDCAP); | ||
instance.nCoinJoinSessions = std::min(std::max((int)gArgs.GetIntArg("-coinjoinsessions", DEFAULT_COINJOIN_SESSIONS), MIN_COINJOIN_SESSIONS), MAX_COINJOIN_SESSIONS); | ||
instance.nCoinJoinRounds = std::min(std::max((int)gArgs.GetIntArg("-coinjoinrounds", DEFAULT_COINJOIN_ROUNDS), MIN_COINJOIN_ROUNDS), MAX_COINJOIN_ROUNDS); | ||
instance.nCoinJoinAmount = std::min(std::max((int)gArgs.GetIntArg("-coinjoinamount", DEFAULT_COINJOIN_AMOUNT), MIN_COINJOIN_AMOUNT), MAX_COINJOIN_AMOUNT); | ||
instance.nCoinJoinDenomsGoal = std::min(std::max((int)gArgs.GetIntArg("-coinjoindenomsgoal", DEFAULT_COINJOIN_DENOMS_GOAL), MIN_COINJOIN_DENOMS_GOAL), MAX_COINJOIN_DENOMS_GOAL); | ||
instance.nCoinJoinDenomsHardCap = std::min(std::max((int)gArgs.GetIntArg("-coinjoindenomshardcap", DEFAULT_COINJOIN_DENOMS_HARDCAP), MIN_COINJOIN_DENOMS_HARDCAP), MAX_COINJOIN_DENOMS_HARDCAP); | ||
CCoinJoinClientOptions::_instance = &instance; | ||
} | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Avoid using assert for input validation in production code
The use of
assert(c < 'A' || c > 'Z');
will cause the program to terminate if an uppercase character is encountered in the HRP in debug builds. Since asserts may be disabled in release builds, this check might not be effective. Consider replacing the assert with proper input validation and error handling to ensure robustness.Apply this diff to replace the
assert
with proper error handling:📝 Committable suggestion