Skip to content

Commit

Permalink
Merge branch 'bitcoin' into auxpow
Browse files Browse the repository at this point in the history
  • Loading branch information
domob1812 committed Jun 10, 2024
2 parents 813f901 + a44b0f7 commit c0e83d0
Show file tree
Hide file tree
Showing 87 changed files with 1,555 additions and 543 deletions.
2 changes: 1 addition & 1 deletion build-aux/m4/ax_cxx_compile_stdcxx.m4
Original file line number Diff line number Diff line change
Expand Up @@ -983,7 +983,7 @@ m4_define([_AX_CXX_COMPILE_STDCXX_testbody_new_in_20], [[
#error "This is not a C++ compiler"
#elif __cplusplus < 201709L // Temporary patch on top of upstream to allow g++-10
#elif __cplusplus < 202002L
#error "This is not a C++20 compiler"
Expand Down
13 changes: 1 addition & 12 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -238,12 +238,6 @@ AC_ARG_ENABLE([lcov],
[use_lcov=$enableval],
[use_lcov=no])

AC_ARG_ENABLE([lcov-branch-coverage],
[AS_HELP_STRING([--enable-lcov-branch-coverage],
[enable lcov testing branch coverage (default is no)])],
[use_lcov_branch=yes],
[use_lcov_branch=no])

AC_ARG_ENABLE([zmq],
[AS_HELP_STRING([--disable-zmq],
[disable ZMQ notifications])],
Expand Down Expand Up @@ -423,9 +417,6 @@ dnl unknown options if any other warning is produced. Test the -Wfoo case, and
dnl set the -Wno-foo case if it works.
AX_CHECK_COMPILE_FLAG([-Wunused-parameter], [NOWARN_CXXFLAGS="$NOWARN_CXXFLAGS -Wno-unused-parameter"], [], [$CXXFLAG_WERROR])
AX_CHECK_COMPILE_FLAG([-Wself-assign], [NOWARN_CXXFLAGS="$NOWARN_CXXFLAGS -Wno-self-assign"], [], [$CXXFLAG_WERROR])
if test "$suppress_external_warnings" != "yes" ; then
AX_CHECK_COMPILE_FLAG([-Wdeprecated-copy], [NOWARN_CXXFLAGS="$NOWARN_CXXFLAGS -Wno-deprecated-copy"], [], [$CXXFLAG_WERROR])
fi

dnl Don't allow extended (non-ASCII) symbols in identifiers. This is easier for code review.
AX_CHECK_COMPILE_FLAG([-fno-extended-identifiers], [CORE_CXXFLAGS="$CORE_CXXFLAGS -fno-extended-identifiers"], [], [$CXXFLAG_WERROR])
Expand Down Expand Up @@ -821,10 +812,8 @@ if test "$use_lcov" = "yes"; then
AX_CHECK_COMPILE_FLAG([--coverage],[CORE_CXXFLAGS="$CORE_CXXFLAGS --coverage"],
[AC_MSG_ERROR([lcov testing requested but --coverage flag does not work])])
CORE_CXXFLAGS="$CORE_CXXFLAGS -Og"
fi

if test "$use_lcov_branch" != "no"; then
AC_SUBST(LCOV_OPTS, "$LCOV_OPTS --rc lcov_branch_coverage=1")
AC_SUBST(LCOV_OPTS)
fi

dnl Check for endianness
Expand Down
4 changes: 4 additions & 0 deletions contrib/guix/guix-build
Original file line number Diff line number Diff line change
Expand Up @@ -361,6 +361,10 @@ INFO: Building ${VERSION:?not set} for platform triple ${HOST:?not set}:
...bind-mounted in container to: '$(DISTSRC_BASE=/distsrc-base && distsrc_for_host "$HOST")'
...outputting in: '$(outdir_for_host "$HOST")'
...bind-mounted in container to: '$(OUTDIR_BASE=/outdir-base && outdir_for_host "$HOST")'
ADDITIONAL FLAGS (if set)
ADDITIONAL_GUIX_COMMON_FLAGS: ${ADDITIONAL_GUIX_COMMON_FLAGS}
ADDITIONAL_GUIX_ENVIRONMENT_FLAGS: ${ADDITIONAL_GUIX_ENVIRONMENT_FLAGS}
ADDITIONAL_GUIX_TIMEMACHINE_FLAGS: ${ADDITIONAL_GUIX_TIMEMACHINE_FLAGS}
EOF

# Run the build script 'contrib/guix/libexec/build.sh' in the build
Expand Down
2 changes: 1 addition & 1 deletion contrib/guix/libexec/prelude.bash
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ fi
time-machine() {
# shellcheck disable=SC2086
guix time-machine --url=https://git.savannah.gnu.org/git/guix.git \
--commit=dc4842797bfdc5f9f3f5f725bf189c2b68bd6b5a \
--commit=f0bb724211872cd6158fce6162e0b8c73efed126 \
--cores="$JOBS" \
--keep-failed \
--fallback \
Expand Down
13 changes: 6 additions & 7 deletions contrib/seeds/generate-seeds.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@

from base64 import b32decode
from enum import Enum
import struct
import sys
import os
import re
Expand Down Expand Up @@ -115,24 +114,24 @@ def parse_spec(s):
def ser_compact_size(l):
r = b""
if l < 253:
r = struct.pack("B", l)
r = l.to_bytes(1, "little")
elif l < 0x10000:
r = struct.pack("<BH", 253, l)
r = (253).to_bytes(1, "little") + l.to_bytes(2, "little")
elif l < 0x100000000:
r = struct.pack("<BI", 254, l)
r = (254).to_bytes(1, "little") + l.to_bytes(4, "little")
else:
r = struct.pack("<BQ", 255, l)
r = (255).to_bytes(1, "little") + l.to_bytes(8, "little")
return r

def bip155_serialize(spec):
'''
Serialize (networkID, addr, port) tuple to BIP155 binary format.
'''
r = b""
r += struct.pack('B', spec[0].value)
r += spec[0].value.to_bytes(1, "little")
r += ser_compact_size(len(spec[1]))
r += spec[1]
r += struct.pack('>H', spec[2])
r += spec[2].to_bytes(2, "big")
return r

def process_nodes(g, f, structname):
Expand Down
4 changes: 2 additions & 2 deletions contrib/signet/miner
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,10 @@ def signet_txs(block, challenge):
mroot = block.get_merkle_root(hashes)

sd = b""
sd += struct.pack("<i", block.nVersion)
sd += block.nVersion.to_bytes(4, "little", signed=True)
sd += ser_uint256(block.hashPrevBlock)
sd += ser_uint256(mroot)
sd += struct.pack("<I", block.nTime)
sd += block.nTime.to_bytes(4, "little")

to_spend = CTransaction()
to_spend.nVersion = 0
Expand Down
2 changes: 1 addition & 1 deletion depends/packages/boost.mk
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package=boost
$(package)_version=1.81.0
$(package)_download_path=https://boostorg.jfrog.io/artifactory/main/release/$($(package)_version)/source/
$(package)_download_path=https://archives.boost.io/release/$($(package)_version)/source/
$(package)_file_name=boost_$(subst .,_,$($(package)_version)).tar.gz
$(package)_sha256_hash=205666dea9f6a7cfed87c7a6dfbeb52a2c1b9de55712c9c1a87735d7181452b6

Expand Down
8 changes: 4 additions & 4 deletions doc/JSON-RPC-interface.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,10 @@ requests when multiple wallets are in use.

```sh
# Get block count from the / endpoint when rpcuser=alice and rpcport=38332
$ curl --user alice --data-binary '{"jsonrpc": "1.0", "id": "0", "method": "getblockcount", "params": []}' -H 'content-type: text/plain;' localhost:38332/
$ curl --user alice --data-binary '{"jsonrpc": "2.0", "id": "0", "method": "getblockcount", "params": []}' -H 'content-type: application/json' localhost:38332/

# Get balance from the /wallet/walletname endpoint when rpcuser=alice, rpcport=38332 and rpcwallet=desc-wallet
$ curl --user alice --data-binary '{"jsonrpc": "1.0", "id": "0", "method": "getbalance", "params": []}' -H 'content-type: text/plain;' localhost:38332/wallet/desc-wallet
$ curl --user alice --data-binary '{"jsonrpc": "2.0", "id": "0", "method": "getbalance", "params": []}' -H 'content-type: application/json' localhost:38332/wallet/desc-wallet

```

Expand Down Expand Up @@ -80,15 +80,15 @@ The server recognizes [JSON-RPC v2.0](https://www.jsonrpc.org/specification) req
and responds accordingly. A 2.0 request is identified by the presence of
`"jsonrpc": "2.0"` in the request body. If that key + value is not present in a request,
the legacy JSON-RPC v1.1 protocol is followed instead, which was the only available
protocol in previous releases.
protocol in v27.0 and prior releases.

|| 1.1 | 2.0 |
|-|-|-|
| Request marker | `"version": "1.1"` (or none) | `"jsonrpc": "2.0"` |
| Response marker | (none) | `"jsonrpc": "2.0"` |
| `"error"` and `"result"` fields in response | both present | only one is present |
| HTTP codes in response | `200` unless there is any kind of RPC error (invalid parameters, method not found, etc) | Always `200` unless there is an actual HTTP server error (request parsing error, endpoint not found, etc) |
| Notifications: requests that get no reply | (not supported) | Supported for requests that exclude the "id" field |
| Notifications: requests that get no reply | (not supported) | Supported for requests that exclude the "id" field. Returns HTTP status `204` "No Content" |

## Security

Expand Down
1 change: 1 addition & 0 deletions doc/bips.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,3 +69,4 @@ BIPs that are implemented by Bitcoin Core:
[`385`](https://github.com/bitcoin/bips/blob/master/bip-0385.mediawiki):
Output Script Descriptors, and most of Script Expressions are implemented as of **v0.17.0** ([PR 13697](https://github.com/bitcoin/bitcoin/pull/13697)).
* [`BIP 386`](https://github.com/bitcoin/bips/blob/master/bip-0386.mediawiki): tr() Output Script Descriptors are implemented as of **v22.0** ([PR 22051](https://github.com/bitcoin/bitcoin/pull/22051)).
* [`BIP 431`](https://github.com/bitcoin/bips/blob/master/bip-0431.mediawiki): transactions with nVersion=3 are standard and treated as Topologically Restricted Until Confirmation as of **v28.0** ([PR 29496](https://github.com/bitcoin/bitcoin/pull/29496)).
4 changes: 4 additions & 0 deletions doc/developer-notes.md
Original file line number Diff line number Diff line change
Expand Up @@ -497,6 +497,10 @@ make cov
# unit and functional tests.
```

Additional LCOV options can be specified using `LCOV_OPTS`, but may be dependant
on the version of LCOV. For example, when using LCOV `2.x`, branch coverage can be
enabled by setting `LCOV_OPTS="--rc branch_coverage=1"`, when configuring.

### Performance profiling with perf

Profiling is a good way to get a precise idea of where time is being spent in
Expand Down
4 changes: 2 additions & 2 deletions doc/init.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ This allows for running bitcoind without having to do any manual configuration.
`conf`, `pid`, and `wallet` accept relative paths which are interpreted as
relative to the data directory. `wallet` *only* supports relative paths.

For an example configuration file that describes the configuration settings,
see `share/examples/bitcoin.conf`.
To generate an example configuration file that describes the configuration settings,
see [contrib/devtools/README.md](../contrib/devtools/README.md#gen-bitcoin-confsh).

Paths
---------------------------------
Expand Down
7 changes: 2 additions & 5 deletions doc/release-notes-27101.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,5 @@ JSON-RPC
--------

The JSON-RPC server now recognizes JSON-RPC 2.0 requests and responds with
strict adherence to the specification (https://www.jsonrpc.org/specification):

- Returning HTTP "204 No Content" responses to JSON-RPC 2.0 notifications instead of full responses.
- Returning HTTP "200 OK" responses in all other cases, rather than 404 responses for unknown methods, 500 responses for invalid parameters, etc.
- Returning either "result" fields or "error" fields in JSON-RPC responses, rather than returning both fields with one field set to null.
strict adherence to the [specification](https://www.jsonrpc.org/specification).
See [JSON-RPC-interface.md](/doc/JSON-RPC-interface.md#json-rpc-11-vs-20) for details.
8 changes: 8 additions & 0 deletions doc/release-notes-29612.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
RPC
---

- The `dumptxoutset` RPC now returns the UTXO set dump in a new and
improved format. At the same time the `loadtxoutset` RPC now
expects this new format in dumps it tries to load. Dumps with the
old format are no longer supported and need to be recreated using
the new format in order to be usable.
6 changes: 6 additions & 0 deletions doc/release-notes-30192.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
Build
-----

`--enable-lcov-branch-coverage` has been removed, given
incompatibilities between lcov version 1 & 2. `LCOV_OPTS`
should be used to set any options instead.
1 change: 1 addition & 0 deletions src/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -336,6 +336,7 @@ BITCOIN_CORE_H = \
util/translation.h \
util/types.h \
util/ui_change_type.h \
util/vecdeque.h \
util/vector.h \
validation.h \
validationinterface.h \
Expand Down
4 changes: 3 additions & 1 deletion src/Makefile.test.include
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,7 @@ endif
FUZZ_WALLET_SRC = \
wallet/test/fuzz/coincontrol.cpp \
wallet/test/fuzz/coinselection.cpp \
wallet/test/fuzz/crypter.cpp \
wallet/test/fuzz/fees.cpp \
wallet/test/fuzz/parse_iso8601.cpp \
wallet/test/fuzz/wallet_bdb_parser.cpp
Expand Down Expand Up @@ -279,7 +280,7 @@ FUZZ_SUITE_LD_COMMON += $(LIBBITCOIN_ZMQ) $(ZMQ_LIBS)
endif

if ENABLE_FUZZ_BINARY
test_fuzz_fuzz_CPPFLAGS = $(AM_CPPFLAGS) $(BITCOIN_INCLUDES) $(BOOST_CPPFLAGS)
test_fuzz_fuzz_CPPFLAGS = $(AM_CPPFLAGS) $(BITCOIN_INCLUDES) $(BOOST_CPPFLAGS) $(EVENT_CFLAGS)
test_fuzz_fuzz_CXXFLAGS = $(AM_CXXFLAGS) $(PIE_FLAGS)
test_fuzz_fuzz_LDADD = $(FUZZ_SUITE_LD_COMMON)
test_fuzz_fuzz_LDFLAGS = $(RELDFLAGS) $(AM_LDFLAGS) $(LIBTOOL_APP_LDFLAGS) $(PTHREAD_FLAGS)
Expand Down Expand Up @@ -398,6 +399,7 @@ test_fuzz_fuzz_SOURCES = \
test/fuzz/utxo_snapshot.cpp \
test/fuzz/utxo_total_supply.cpp \
test/fuzz/validation_load_mempool.cpp \
test/fuzz/vecdeque.cpp \
test/fuzz/versionbits.cpp
endif # ENABLE_FUZZ_BINARY

Expand Down
56 changes: 31 additions & 25 deletions src/bech32.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ namespace

typedef std::vector<uint8_t> data;

/** The Bech32 and Bech32m checksum size */
constexpr size_t CHECKSUM_SIZE = 6;

/** The Bech32 and Bech32m character set for encoding. */
const char* CHARSET = "qpzry9x8gf2tvdw0s3jn54khce6mua7l";

Expand Down Expand Up @@ -308,18 +311,18 @@ bool CheckCharacters(const std::string& str, std::vector<int>& errors)
return errors.empty();
}

/** Expand a HRP for use in checksum computation. */
data ExpandHRP(const std::string& hrp)
std::vector<unsigned char> PreparePolynomialCoefficients(const std::string& hrp, const data& values)
{
data ret;
ret.reserve(hrp.size() + 90);
ret.resize(hrp.size() * 2 + 1);
for (size_t i = 0; i < hrp.size(); ++i) {
unsigned char c = hrp[i];
ret[i] = c >> 5;
ret[i + hrp.size() + 1] = c & 0x1f;
}
ret[hrp.size()] = 0;
ret.reserve(hrp.size() + 1 + hrp.size() + values.size() + CHECKSUM_SIZE);

/** Expand a HRP for use in checksum computation. */
for (size_t i = 0; i < hrp.size(); ++i) ret.push_back(hrp[i] >> 5);
ret.push_back(0);
for (size_t i = 0; i < hrp.size(); ++i) ret.push_back(hrp[i] & 0x1f);

ret.insert(ret.end(), values.begin(), values.end());

return ret;
}

Expand All @@ -331,7 +334,8 @@ Encoding VerifyChecksum(const std::string& hrp, const data& values)
// list of values would result in a new valid list. For that reason, Bech32 requires the
// resulting checksum to be 1 instead. In Bech32m, this constant was amended. See
// https://gist.github.com/sipa/14c248c288c3880a3b191f978a34508e for details.
const uint32_t check = PolyMod(Cat(ExpandHRP(hrp), values));
auto enc = PreparePolynomialCoefficients(hrp, values);
const uint32_t check = PolyMod(enc);
if (check == EncodingConstant(Encoding::BECH32)) return Encoding::BECH32;
if (check == EncodingConstant(Encoding::BECH32M)) return Encoding::BECH32M;
return Encoding::INVALID;
Expand All @@ -340,11 +344,11 @@ Encoding VerifyChecksum(const std::string& hrp, const data& values)
/** Create a checksum. */
data CreateChecksum(Encoding encoding, const std::string& hrp, const data& values)
{
data enc = Cat(ExpandHRP(hrp), values);
enc.resize(enc.size() + 6); // Append 6 zeroes
auto enc = PreparePolynomialCoefficients(hrp, values);
enc.insert(enc.end(), CHECKSUM_SIZE, 0x00);
uint32_t mod = PolyMod(enc) ^ EncodingConstant(encoding); // Determine what to XOR into those 6 zeroes.
data ret(6);
for (size_t i = 0; i < 6; ++i) {
data ret(CHECKSUM_SIZE);
for (size_t i = 0; i < CHECKSUM_SIZE; ++i) {
// Convert the 5-bit groups in mod to checksum values.
ret[i] = (mod >> (5 * (5 - i))) & 31;
}
Expand All @@ -370,11 +374,12 @@ std::string Encode(Encoding encoding, const std::string& hrp, const data& values
}

/** Decode a Bech32 or Bech32m string. */
DecodeResult Decode(const std::string& str) {
DecodeResult Decode(const std::string& str, CharLimit limit) {
std::vector<int> errors;
if (!CheckCharacters(str, errors)) return {};
size_t pos = str.rfind('1');
if (str.size() > 90 || pos == str.npos || pos == 0 || pos + 7 > str.size()) {
if (str.size() > limit) return {};
if (pos == str.npos || pos == 0 || pos + CHECKSUM_SIZE >= str.size()) {
return {};
}
data values(str.size() - 1 - pos);
Expand All @@ -393,16 +398,16 @@ DecodeResult Decode(const std::string& str) {
}
Encoding result = VerifyChecksum(hrp, values);
if (result == Encoding::INVALID) return {};
return {result, std::move(hrp), data(values.begin(), values.end() - 6)};
return {result, std::move(hrp), data(values.begin(), values.end() - CHECKSUM_SIZE)};
}

/** Find index of an incorrect character in a Bech32 string. */
std::pair<std::string, std::vector<int>> LocateErrors(const std::string& str) {
std::pair<std::string, std::vector<int>> LocateErrors(const std::string& str, CharLimit limit) {
std::vector<int> error_locations{};

if (str.size() > 90) {
error_locations.resize(str.size() - 90);
std::iota(error_locations.begin(), error_locations.end(), 90);
if (str.size() > limit) {
error_locations.resize(str.size() - limit);
std::iota(error_locations.begin(), error_locations.end(), static_cast<int>(limit));
return std::make_pair("Bech32 string too long", std::move(error_locations));
}

Expand All @@ -414,7 +419,7 @@ std::pair<std::string, std::vector<int>> LocateErrors(const std::string& str) {
if (pos == str.npos) {
return std::make_pair("Missing separator", std::vector<int>{});
}
if (pos == 0 || pos + 7 > str.size()) {
if (pos == 0 || pos + CHECKSUM_SIZE >= str.size()) {
error_locations.push_back(pos);
return std::make_pair("Invalid separator position", std::move(error_locations));
}
Expand All @@ -441,9 +446,10 @@ std::pair<std::string, std::vector<int>> LocateErrors(const std::string& str) {
std::optional<Encoding> error_encoding;
for (Encoding encoding : {Encoding::BECH32, Encoding::BECH32M}) {
std::vector<int> possible_errors;
// Recall that (ExpandHRP(hrp) ++ values) is interpreted as a list of coefficients of a polynomial
// Recall that (expanded hrp + values) is interpreted as a list of coefficients of a polynomial
// over GF(32). PolyMod computes the "remainder" of this polynomial modulo the generator G(x).
uint32_t residue = PolyMod(Cat(ExpandHRP(hrp), values)) ^ EncodingConstant(encoding);
auto enc = PreparePolynomialCoefficients(hrp, values);
uint32_t residue = PolyMod(enc) ^ EncodingConstant(encoding);

// All valid codewords should be multiples of G(x), so this remainder (after XORing with the encoding
// constant) should be 0 - hence 0 indicates there are no errors present.
Expand Down
12 changes: 10 additions & 2 deletions src/bech32.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,14 @@ enum class Encoding {
BECH32M, //!< Bech32m encoding as defined in BIP350
};

/** Character limits for Bech32(m) encoded strings. Character limits are how we provide error location guarantees.
* These values should never exceed 2^31 - 1 (max value for a 32-bit int), since there are places where we may need to
* convert the CharLimit::VALUE to an int. In practice, this should never happen since this CharLimit applies to an address encoding
* and we would never encode an address with such a massive value */
enum CharLimit : size_t {
BECH32 = 90, //!< BIP173/350 imposed character limit for Bech32(m) encoded addresses. This guarantees finding up to 4 errors.
};

/** 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);
Expand All @@ -43,10 +51,10 @@ struct DecodeResult
};

/** Decode a Bech32 or Bech32m string. */
DecodeResult Decode(const std::string& str);
DecodeResult Decode(const std::string& str, CharLimit limit = CharLimit::BECH32);

/** Return the positions of errors in a Bech32 string. */
std::pair<std::string, std::vector<int>> LocateErrors(const std::string& str);
std::pair<std::string, std::vector<int>> LocateErrors(const std::string& str, CharLimit limit = CharLimit::BECH32);

} // namespace bech32

Expand Down
Loading

0 comments on commit c0e83d0

Please sign in to comment.