Skip to content
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

Add partial utreexo implementation to test build. #1572

Merged
merged 7 commits into from
Dec 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -362,6 +362,8 @@ test_libbitcoin_system_test_SOURCES = \
test/unicode/utf8_everywhere/ofstream.cpp \
test/unicode/utf8_everywhere/unicode_istream.cpp \
test/unicode/utf8_everywhere/unicode_ostream.cpp \
test/utreexo/utreexo.cpp \
test/utreexo/utreexo.hpp \
test/wallet/context.cpp \
test/wallet/message.cpp \
test/wallet/neutrino_filter.cpp \
Expand Down
2 changes: 2 additions & 0 deletions builds/cmake/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -849,6 +849,8 @@ if (with-tests)
"../../test/unicode/utf8_everywhere/ofstream.cpp"
"../../test/unicode/utf8_everywhere/unicode_istream.cpp"
"../../test/unicode/utf8_everywhere/unicode_ostream.cpp"
"../../test/utreexo/utreexo.cpp"
"../../test/utreexo/utreexo.hpp"
"../../test/wallet/context.cpp"
"../../test/wallet/message.cpp"
"../../test/wallet/neutrino_filter.cpp"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,7 @@
<ClCompile Include="..\..\..\..\test\unicode\utf8_everywhere\ofstream.cpp" />
<ClCompile Include="..\..\..\..\test\unicode\utf8_everywhere\unicode_istream.cpp" />
<ClCompile Include="..\..\..\..\test\unicode\utf8_everywhere\unicode_ostream.cpp" />
<ClCompile Include="..\..\..\..\test\utreexo\utreexo.cpp" />
<ClCompile Include="..\..\..\..\test\wallet\addresses\bitcoin_uri.cpp" />
<ClCompile Include="..\..\..\..\test\wallet\addresses\checked.cpp" />
<ClCompile Include="..\..\..\..\test\wallet\addresses\payment_address.cpp" />
Expand Down Expand Up @@ -305,6 +306,7 @@
<ClInclude Include="..\..\..\..\test\hash\performance\performance.hpp" />
<ClInclude Include="..\..\..\..\test\hash\siphash.hpp" />
<ClInclude Include="..\..\..\..\test\test.hpp" />
<ClInclude Include="..\..\..\..\test\utreexo\utreexo.hpp" />
<ClInclude Include="..\..\..\..\test\wallet\mnemonics\electrum.hpp" />
<ClInclude Include="..\..\..\..\test\wallet\mnemonics\electrum_v1.hpp" />
<ClInclude Include="..\..\..\..\test\wallet\mnemonics\mnemonic.hpp" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
<UniqueIdentifier>{51A424A9-2C12-4211-0000-000000000001}</UniqueIdentifier>
</Filter>
<Filter Include="src\chain\enums">
<UniqueIdentifier>{51A424A9-2C12-4211-0000-000000000002}</UniqueIdentifier>
<UniqueIdentifier>{51A424A9-2C12-4211-0000-000000000003}</UniqueIdentifier>
</Filter>
<Filter Include="src\config">
<UniqueIdentifier>{51A424A9-2C12-4211-0000-000000000002}</UniqueIdentifier>
Expand All @@ -35,22 +35,22 @@
<UniqueIdentifier>{51A424A9-2C12-4211-0000-000000000007}</UniqueIdentifier>
</Filter>
<Filter Include="src\hash\performance">
<UniqueIdentifier>{51A424A9-2C12-4211-0000-000000000003}</UniqueIdentifier>
<UniqueIdentifier>{51A424A9-2C12-4211-0000-000000000004}</UniqueIdentifier>
</Filter>
<Filter Include="src\hash\performance\baseline">
<UniqueIdentifier>{51A424A9-2C12-4211-0000-000000000006}</UniqueIdentifier>
<UniqueIdentifier>{51A424A9-2C12-4211-0000-000000000007}</UniqueIdentifier>
</Filter>
<Filter Include="src\hash\rmd">
<UniqueIdentifier>{51A424A9-2C12-4211-0000-000000000004}</UniqueIdentifier>
<UniqueIdentifier>{51A424A9-2C12-4211-0000-000000000005}</UniqueIdentifier>
</Filter>
<Filter Include="src\hash\sha">
<UniqueIdentifier>{51A424A9-2C12-4211-0000-000000000005}</UniqueIdentifier>
<UniqueIdentifier>{51A424A9-2C12-4211-0000-000000000006}</UniqueIdentifier>
</Filter>
<Filter Include="src\intrinsics">
<UniqueIdentifier>{51A424A9-2C12-4211-0000-000000000008}</UniqueIdentifier>
</Filter>
<Filter Include="src\intrinsics\xcpu">
<UniqueIdentifier>{51A424A9-2C12-4211-0000-000000000007}</UniqueIdentifier>
<UniqueIdentifier>{51A424A9-2C12-4211-0000-000000000008}</UniqueIdentifier>
</Filter>
<Filter Include="src\machine">
<UniqueIdentifier>{51A424A9-2C12-4211-0000-000000000009}</UniqueIdentifier>
Expand All @@ -68,37 +68,40 @@
<UniqueIdentifier>{51A424A9-2C12-4211-0000-00000000000D}</UniqueIdentifier>
</Filter>
<Filter Include="src\stream\devices">
<UniqueIdentifier>{51A424A9-2C12-4211-0000-000000000008}</UniqueIdentifier>
<UniqueIdentifier>{51A424A9-2C12-4211-0000-000000000009}</UniqueIdentifier>
</Filter>
<Filter Include="src\stream\iostream">
<UniqueIdentifier>{51A424A9-2C12-4211-0000-000000000009}</UniqueIdentifier>
<UniqueIdentifier>{51A424A9-2C12-4211-0000-000000000010}</UniqueIdentifier>
</Filter>
<Filter Include="src\stream\streamers">
<UniqueIdentifier>{51A424A9-2C12-4211-0000-000000000010}</UniqueIdentifier>
<UniqueIdentifier>{51A424A9-2C12-4211-0000-0000000000A1}</UniqueIdentifier>
</Filter>
<Filter Include="src\unicode">
<UniqueIdentifier>{51A424A9-2C12-4211-0000-00000000000E}</UniqueIdentifier>
</Filter>
<Filter Include="src\unicode\utf8_everywhere">
<UniqueIdentifier>{51A424A9-2C12-4211-0000-0000000000A1}</UniqueIdentifier>
<UniqueIdentifier>{51A424A9-2C12-4211-0000-0000000000B1}</UniqueIdentifier>
</Filter>
<Filter Include="src\wallet">
<Filter Include="src\utreexo">
<UniqueIdentifier>{51A424A9-2C12-4211-0000-00000000000F}</UniqueIdentifier>
</Filter>
<Filter Include="src\wallet">
<UniqueIdentifier>{51A424A9-2C12-4211-0000-000000000001}</UniqueIdentifier>
</Filter>
<Filter Include="src\wallet\addresses">
<UniqueIdentifier>{51A424A9-2C12-4211-0000-0000000000B1}</UniqueIdentifier>
<UniqueIdentifier>{51A424A9-2C12-4211-0000-0000000000C1}</UniqueIdentifier>
</Filter>
<Filter Include="src\wallet\keys">
<UniqueIdentifier>{51A424A9-2C12-4211-0000-0000000000C1}</UniqueIdentifier>
<UniqueIdentifier>{51A424A9-2C12-4211-0000-0000000000D1}</UniqueIdentifier>
</Filter>
<Filter Include="src\wallet\mnemonics">
<UniqueIdentifier>{51A424A9-2C12-4211-0000-0000000000D1}</UniqueIdentifier>
<UniqueIdentifier>{51A424A9-2C12-4211-0000-0000000000E1}</UniqueIdentifier>
</Filter>
<Filter Include="src\words">
<UniqueIdentifier>{51A424A9-2C12-4211-0000-000000000001}</UniqueIdentifier>
<UniqueIdentifier>{51A424A9-2C12-4211-0000-000000000002}</UniqueIdentifier>
</Filter>
<Filter Include="src\words\catalogs">
<UniqueIdentifier>{51A424A9-2C12-4211-0000-0000000000E1}</UniqueIdentifier>
<UniqueIdentifier>{51A424A9-2C12-4211-0000-0000000000F1}</UniqueIdentifier>
</Filter>
</ItemGroup>
<ItemGroup>
Expand Down Expand Up @@ -561,6 +564,9 @@
<ClCompile Include="..\..\..\..\test\unicode\utf8_everywhere\unicode_ostream.cpp">
<Filter>src\unicode\utf8_everywhere</Filter>
</ClCompile>
<ClCompile Include="..\..\..\..\test\utreexo\utreexo.cpp">
<Filter>src\utreexo</Filter>
</ClCompile>
<ClCompile Include="..\..\..\..\test\wallet\addresses\bitcoin_uri.cpp">
<Filter>src\wallet\addresses</Filter>
</ClCompile>
Expand Down Expand Up @@ -695,6 +701,9 @@
<ClInclude Include="..\..\..\..\test\test.hpp">
<Filter>src</Filter>
</ClInclude>
<ClInclude Include="..\..\..\..\test\utreexo\utreexo.hpp">
<Filter>src\utreexo</Filter>
</ClInclude>
<ClInclude Include="..\..\..\..\test\wallet\mnemonics\electrum.hpp">
<Filter>src\wallet\mnemonics</Filter>
</ClInclude>
Expand Down
4 changes: 2 additions & 2 deletions include/bitcoin/system/impl/math/bits.ipp
Original file line number Diff line number Diff line change
Expand Up @@ -294,8 +294,8 @@ template <typename Value, if_unsigned_integral_integer<Value>>
constexpr void shift_left_into(Value& value, size_t shift, bool overflow) NOEXCEPT
{
constexpr auto span = bits<Value>;
overflow && shift >= span ? value = 0 :
value <<= (shift % span);
overflow && shift >= span ? value = 0 : depromote<Value>(
value <<= (shift % span));
}

// signed overloads (shift left of negative is undefined behavior).
Expand Down
15 changes: 15 additions & 0 deletions include/bitcoin/system/impl/math/overflow.ipp
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,21 @@ constexpr Integral minimum_ = std::numeric_limits<Integral>::min();
template <typename Integral, if_integer<Integral> = true>
constexpr Integral maximum_ = std::numeric_limits<Integral>::max();

// shift
// ----------------------------------------------------------------------------

template <typename Value, if_unsigned_integral_integer<Value>>
constexpr bool is_left_shift_overflow(Value value, size_t shift) NOEXCEPT
{
return to_bool(bit_and(value, unmask_left<Value>(shift)));
}

template <typename Value, if_unsigned_integral_integer<Value>>
constexpr bool is_right_shift_overflow(Value value, size_t shift) NOEXCEPT
{
return to_bool(bit_and(value, unmask_right<Value>(shift)));
}

// add/subtract
// ----------------------------------------------------------------------------

Expand Down
13 changes: 12 additions & 1 deletion include/bitcoin/system/math/overflow.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,19 @@

namespace libbitcoin {
namespace system {

/// shift
/// ---------------------------------------------------------------------------

/// Shift would cause 1-valued bit(s) to be left-shifted out.
template <typename Value, if_unsigned_integral_integer<Value> = true>
constexpr bool is_left_shift_overflow(Value value, size_t shift) NOEXCEPT;

/// Shift would cause 1-valued bit(s) to be right-shifted out.
template <typename Value, if_unsigned_integral_integer<Value> = true>
constexpr bool is_right_shift_overflow(Value value, size_t shift) NOEXCEPT;

/// add/subtract.
/// shift/add/subtract.
/// ---------------------------------------------------------------------------
// TODO: generalize is_add_overflow() and is_subtract_overflow() argument types.

Expand Down
63 changes: 62 additions & 1 deletion test/math/overflow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,67 @@ constexpr auto signed_zero = 0_i16;
constexpr auto signed_max = max_int16;
constexpr auto signed_half = to_half(signed_max);

// is_left_shift_overflow
// ----------------------------------------------------------------------------

// unsigned only
static_assert(!is_left_shift_overflow<uint8_t>(0b00000000, 0));
static_assert(!is_left_shift_overflow<uint8_t>(0b00000000, 1));
static_assert(!is_left_shift_overflow<uint8_t>(0b00000000, 2));
static_assert(!is_left_shift_overflow<uint8_t>(0b00000000, 4));
static_assert(!is_left_shift_overflow<uint8_t>(0b00000000, 8));

static_assert(!is_left_shift_overflow<uint8_t>(0b00000001, 0));
static_assert(!is_left_shift_overflow<uint8_t>(0b00000001, 1));
static_assert(!is_left_shift_overflow<uint8_t>(0b00000001, 2));
static_assert(!is_left_shift_overflow<uint8_t>(0b00000001, 4));
static_assert( is_left_shift_overflow<uint8_t>(0b00000001, 8));

static_assert(!is_left_shift_overflow<uint8_t>(0b10000000, 0));
static_assert( is_left_shift_overflow<uint8_t>(0b10000000, 1));
static_assert( is_left_shift_overflow<uint8_t>(0b10000000, 2));
static_assert( is_left_shift_overflow<uint8_t>(0b10000000, 4));
static_assert( is_left_shift_overflow<uint8_t>(0b10000000, 8));

static_assert(!is_left_shift_overflow<uint8_t>(0b00101010, 0));
static_assert(!is_left_shift_overflow<uint8_t>(0b00101010, 1));
static_assert(!is_left_shift_overflow<uint8_t>(0b00101010, 2));
static_assert( is_left_shift_overflow<uint8_t>(0b00101010, 4));
static_assert( is_left_shift_overflow<uint8_t>(0b00101010, 8));

static_assert(!is_left_shift_overflow<uint8_t>(0b11111111, 0));
static_assert( is_left_shift_overflow<uint8_t>(0b11111111, 1));
static_assert( is_left_shift_overflow<uint8_t>(0b11111111, 2));
static_assert( is_left_shift_overflow<uint8_t>(0b11111111, 4));
static_assert( is_left_shift_overflow<uint8_t>(0b11111111, 8));

static_assert(!is_left_shift_overflow<uint16_t>(0b00010000'00000000, 0));
static_assert(!is_left_shift_overflow<uint16_t>(0b00010000'00000000, 1));
static_assert(!is_left_shift_overflow<uint16_t>(0b00010000'00000000, 2));
static_assert( is_left_shift_overflow<uint16_t>(0b00010000'00000000, 4));
static_assert( is_left_shift_overflow<uint16_t>(0b00010000'00000000, 8));
static_assert( is_left_shift_overflow<uint16_t>(0b00000000'00000001, bits<uint16_t>));
static_assert(!is_left_shift_overflow<uint16_t>(0b00000000'00000001, sub1(bits<uint16_t>)));

static_assert(!is_left_shift_overflow<uint32_t>(0b00010000'00000000'00000000'00000000, 0));
static_assert(!is_left_shift_overflow<uint32_t>(0b00010000'00000000'00000000'00000000, 1));
static_assert(!is_left_shift_overflow<uint32_t>(0b00010000'00000000'00000000'00000000, 2));
static_assert( is_left_shift_overflow<uint32_t>(0b00010000'00000000'00000000'00000000, 4));
static_assert( is_left_shift_overflow<uint32_t>(0b00010000'00000000'00000000'00000000, 8));
static_assert( is_left_shift_overflow<uint32_t>(0b00000000'00000000'00000000'00000001, bits<uint32_t>));
static_assert(!is_left_shift_overflow<uint32_t>(0b00000000'00000000'00000000'00000001, sub1(bits<uint32_t>)));

static_assert(!is_left_shift_overflow<uint64_t>(0b00010000'00000000'00000000'00000000'00010000'00000000'00000000'00000000, 0));
static_assert(!is_left_shift_overflow<uint64_t>(0b00010000'00000000'00000000'00000000'00010000'00000000'00000000'00000000, 1));
static_assert(!is_left_shift_overflow<uint64_t>(0b00010000'00000000'00000000'00000000'00010000'00000000'00000000'00000000, 2));
static_assert( is_left_shift_overflow<uint64_t>(0b00010000'00000000'00000000'00000000'00010000'00000000'00000000'00000000, 4));
static_assert( is_left_shift_overflow<uint64_t>(0b00010000'00000000'00000000'00000000'00010000'00000000'00000000'00000000, 8));
static_assert( is_left_shift_overflow<uint64_t>(0b00000000'00000000'00000000'00000000'00000000'00000000'00000000'00000001, bits<uint64_t>));
static_assert(!is_left_shift_overflow<uint64_t>(0b00000000'00000000'00000000'00000000'00000000'00000000'00000000'00000001, sub1(bits<uint64_t>)));

// is_right_shift_overflow
// ----------------------------------------------------------------------------

// is_negate_overflow
// ----------------------------------------------------------------------------

Expand Down Expand Up @@ -68,7 +129,7 @@ static_assert(is_add_overflow(unsigned_max, unsigned_half));
static_assert(is_add_overflow(unsigned_half, unsigned_max));
static_assert(!is_add_overflow(unsigned_half, unsigned_half));

// is_underflow
// is_subtract_overflow
// ----------------------------------------------------------------------------

// signed
Expand Down
Loading
Loading