Skip to content

Commit

Permalink
Merge pull request #129 from kallewoof/202305-rebase-24.0.1
Browse files Browse the repository at this point in the history
Rebase onto 24.0.1
  • Loading branch information
kallewoof authored May 10, 2023
2 parents d919e9a + a3780d3 commit b2f3d4d
Show file tree
Hide file tree
Showing 142 changed files with 32,319 additions and 4,508 deletions.
9 changes: 5 additions & 4 deletions Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ LIBBITCOIN_DEB_H = \
# bitcoin core #
BITCOIN_CORE_H = \
$(LIBBITCOIN_DEB_H) \
amount.h \
arith_uint256.h \
attributes.h \
base58.h \
Expand All @@ -45,14 +44,15 @@ BITCOIN_CORE_H = \
compat/byteswap.h \
compat/cpuid.h \
compat/endian.h \
consensus/amount.h \
consensus/merkle.h \
crypto/common.h \
crypto/hmac_sha512.h \
crypto/ripemd160.h \
crypto/sha1.h \
crypto/sha256.h \
crypto/sha512.h \
hash.h \
merkle.h \
policy/policy.h \
prevector.h \
primitives/transaction.h \
Expand All @@ -69,6 +69,7 @@ BITCOIN_CORE_H = \
support/lockedpool.h \
tinyformat.h \
uint256.h \
util/overflow.h \
util/spanparsing.h \
util/strencodings.h \
util/vector.h \
Expand All @@ -86,20 +87,20 @@ libbitcoin_deb_a_SOURCES = \
$(BITCOIN_CORE_H)

# bitcoin: shared between all the tools
libbitcoin_a_LIBADD = $(LIBSECP256K1)
# libbitcoin_a_LIBADD = $(LIBSECP256K1)
libbitcoin_a_CPPFLAGS = $(AM_CPPFLAGS) $(BITCOIN_INCLUDES)
libbitcoin_a_CXXFLAGS = $(AM_CXXFLAGS)
libbitcoin_a_SOURCES = \
arith_uint256.cpp \
base58.cpp \
bech32.cpp \
consensus/merkle.cpp \
crypto/hmac_sha512.cpp \
crypto/ripemd160.cpp \
crypto/sha1.cpp \
crypto/sha256.cpp \
crypto/sha512.cpp \
hash.cpp \
merkle.cpp \
primitives/transaction.cpp \
pubkey.cpp \
script/interpreter.cpp \
Expand Down
33 changes: 14 additions & 19 deletions arith_uint256.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ base_uint<BITS>& base_uint<BITS>::operator/=(const base_uint& b)
while (shift >= 0) {
if (num >= div) {
num -= div;
pn[shift / 32] |= (1 << (shift & 31)); // set a bit of the result.
pn[shift / 32] |= (1U << (shift & 31)); // set a bit of the result.
}
div >>= 1; // shift back.
shift--;
Expand Down Expand Up @@ -146,13 +146,21 @@ double base_uint<BITS>::getdouble() const
template <unsigned int BITS>
std::string base_uint<BITS>::GetHex() const
{
return ArithToUint256(*this).GetHex();
base_blob<BITS> b;
for (int x = 0; x < this->WIDTH; ++x) {
WriteLE32(b.begin() + x*4, this->pn[x]);
}
return b.GetHex();
}

template <unsigned int BITS>
void base_uint<BITS>::SetHex(const char* psz)
{
*this = UintToArith256(uint256S(psz));
base_blob<BITS> b;
b.SetHex(psz);
for (int x = 0; x < this->WIDTH; ++x) {
this->pn[x] = ReadLE32(b.begin() + x*4);
}
}

template <unsigned int BITS>
Expand All @@ -164,7 +172,7 @@ void base_uint<BITS>::SetHex(const std::string& str)
template <unsigned int BITS>
std::string base_uint<BITS>::ToString() const
{
return (GetHex());
return GetHex();
}

template <unsigned int BITS>
Expand All @@ -183,20 +191,7 @@ unsigned int base_uint<BITS>::bits() const
}

// Explicit instantiations for base_uint<256>
template base_uint<256>::base_uint(const std::string&);
template base_uint<256>& base_uint<256>::operator<<=(unsigned int);
template base_uint<256>& base_uint<256>::operator>>=(unsigned int);
template base_uint<256>& base_uint<256>::operator*=(uint32_t b32);
template base_uint<256>& base_uint<256>::operator*=(const base_uint<256>& b);
template base_uint<256>& base_uint<256>::operator/=(const base_uint<256>& b);
template int base_uint<256>::CompareTo(const base_uint<256>&) const;
template bool base_uint<256>::EqualTo(uint64_t) const;
template double base_uint<256>::getdouble() const;
template std::string base_uint<256>::GetHex() const;
template std::string base_uint<256>::ToString() const;
template void base_uint<256>::SetHex(const char*);
template void base_uint<256>::SetHex(const std::string&);
template unsigned int base_uint<256>::bits() const;
template class base_uint<256>;

// This implementation directly uses shifts instead of going
// through an intermediate MPI representation.
Expand Down Expand Up @@ -236,7 +231,7 @@ uint32_t arith_uint256::GetCompact(bool fNegative) const
nCompact >>= 8;
nSize++;
}
assert((nCompact & ~0x007fffff) == 0);
assert((nCompact & ~0x007fffffU) == 0);
assert(nSize < 256);
nCompact |= nSize << 24;
nCompact |= (fNegative && (nCompact & 0x007fffff) ? 0x00800000 : 0);
Expand Down
9 changes: 3 additions & 6 deletions arith_uint256.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,22 +24,19 @@ template<unsigned int BITS>
class base_uint
{
protected:
static_assert(BITS / 32 > 0 && BITS % 32 == 0, "Template parameter BITS must be a positive multiple of 32.");
static constexpr int WIDTH = BITS / 32;
uint32_t pn[WIDTH];
public:

base_uint()
{
static_assert(BITS/32 > 0 && BITS%32 == 0, "Template parameter BITS must be a positive multiple of 32.");

for (int i = 0; i < WIDTH; i++)
pn[i] = 0;
}

base_uint(const base_uint& b)
{
static_assert(BITS/32 > 0 && BITS%32 == 0, "Template parameter BITS must be a positive multiple of 32.");

for (int i = 0; i < WIDTH; i++)
pn[i] = b.pn[i];
}
Expand All @@ -53,8 +50,6 @@ class base_uint

base_uint(uint64_t b)
{
static_assert(BITS/32 > 0 && BITS%32 == 0, "Template parameter BITS must be a positive multiple of 32.");

pn[0] = (unsigned int)b;
pn[1] = (unsigned int)(b >> 32);
for (int i = 2; i < WIDTH; i++)
Expand Down Expand Up @@ -288,4 +283,6 @@ class arith_uint256 : public base_uint<256> {
uint256 ArithToUint256(const arith_uint256 &);
arith_uint256 UintToArith256(const uint256 &);

extern template class base_uint<256>;

#endif // BITCOIN_ARITH_UINT256_H
9 changes: 5 additions & 4 deletions base58.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) 2014-2020 The Bitcoin Core developers
// Copyright (c) 2014-2021 The Bitcoin Core developers
// Distributed under the MIT software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php.

Expand All @@ -7,6 +7,7 @@
#include <hash.h>
#include <uint256.h>
#include <util/strencodings.h>
#include <util/string.h>

#include <assert.h>
#include <string.h>
Expand Down Expand Up @@ -125,7 +126,7 @@ std::string EncodeBase58(Span<const unsigned char> input)

bool DecodeBase58(const std::string& str, std::vector<unsigned char>& vchRet, int max_ret_len)
{
if (!ValidAsCString(str)) {
if (!ContainsNoNUL(str)) {
return false;
}
return DecodeBase58(str.c_str(), vchRet, max_ret_len);
Expand All @@ -148,7 +149,7 @@ std::string EncodeBase58Check(Span<const unsigned char> input)
return false;
}
// re-calculate the checksum, ensure it matches the included 4-byte checksum
uint256 hash = Hash(MakeSpan(vchRet).first(vchRet.size() - 4));
uint256 hash = Hash(Span{vchRet}.first(vchRet.size() - 4));
if (memcmp(&hash, &vchRet[vchRet.size() - 4], 4) != 0) {
vchRet.clear();
return false;
Expand All @@ -159,7 +160,7 @@ std::string EncodeBase58Check(Span<const unsigned char> input)

bool DecodeBase58Check(const std::string& str, std::vector<unsigned char>& vchRet, int max_ret)
{
if (!ValidAsCString(str)) {
if (!ContainsNoNUL(str)) {
return false;
}
return DecodeBase58Check(str.c_str(), vchRet, max_ret);
Expand Down
1 change: 0 additions & 1 deletion base58.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
#ifndef BITCOIN_BASE58_H
#define BITCOIN_BASE58_H

#include <attributes.h>
#include <span.h>

#include <string>
Expand Down
Loading

0 comments on commit b2f3d4d

Please sign in to comment.