Skip to content

Commit 530eff3

Browse files
authored
Merge pull request #1572 from evoskuil/master
Add partial utreexo implementation to test build.
2 parents 85a6aca + 68b0744 commit 530eff3

10 files changed

Lines changed: 428 additions & 276 deletions

File tree

Makefile.am

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -362,6 +362,8 @@ test_libbitcoin_system_test_SOURCES = \
362362
test/unicode/utf8_everywhere/ofstream.cpp \
363363
test/unicode/utf8_everywhere/unicode_istream.cpp \
364364
test/unicode/utf8_everywhere/unicode_ostream.cpp \
365+
test/utreexo/utreexo.cpp \
366+
test/utreexo/utreexo.hpp \
365367
test/wallet/context.cpp \
366368
test/wallet/message.cpp \
367369
test/wallet/neutrino_filter.cpp \

builds/cmake/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -849,6 +849,8 @@ if (with-tests)
849849
"../../test/unicode/utf8_everywhere/ofstream.cpp"
850850
"../../test/unicode/utf8_everywhere/unicode_istream.cpp"
851851
"../../test/unicode/utf8_everywhere/unicode_ostream.cpp"
852+
"../../test/utreexo/utreexo.cpp"
853+
"../../test/utreexo/utreexo.hpp"
852854
"../../test/wallet/context.cpp"
853855
"../../test/wallet/message.cpp"
854856
"../../test/wallet/neutrino_filter.cpp"

builds/msvc/vs2022/libbitcoin-system-test/libbitcoin-system-test.vcxproj

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -245,6 +245,7 @@
245245
<ClCompile Include="..\..\..\..\test\unicode\utf8_everywhere\ofstream.cpp" />
246246
<ClCompile Include="..\..\..\..\test\unicode\utf8_everywhere\unicode_istream.cpp" />
247247
<ClCompile Include="..\..\..\..\test\unicode\utf8_everywhere\unicode_ostream.cpp" />
248+
<ClCompile Include="..\..\..\..\test\utreexo\utreexo.cpp" />
248249
<ClCompile Include="..\..\..\..\test\wallet\addresses\bitcoin_uri.cpp" />
249250
<ClCompile Include="..\..\..\..\test\wallet\addresses\checked.cpp" />
250251
<ClCompile Include="..\..\..\..\test\wallet\addresses\payment_address.cpp" />
@@ -305,6 +306,7 @@
305306
<ClInclude Include="..\..\..\..\test\hash\performance\performance.hpp" />
306307
<ClInclude Include="..\..\..\..\test\hash\siphash.hpp" />
307308
<ClInclude Include="..\..\..\..\test\test.hpp" />
309+
<ClInclude Include="..\..\..\..\test\utreexo\utreexo.hpp" />
308310
<ClInclude Include="..\..\..\..\test\wallet\mnemonics\electrum.hpp" />
309311
<ClInclude Include="..\..\..\..\test\wallet\mnemonics\electrum_v1.hpp" />
310312
<ClInclude Include="..\..\..\..\test\wallet\mnemonics\mnemonic.hpp" />

builds/msvc/vs2022/libbitcoin-system-test/libbitcoin-system-test.vcxproj.filters

Lines changed: 25 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
<UniqueIdentifier>{51A424A9-2C12-4211-0000-000000000001}</UniqueIdentifier>
1515
</Filter>
1616
<Filter Include="src\chain\enums">
17-
<UniqueIdentifier>{51A424A9-2C12-4211-0000-000000000002}</UniqueIdentifier>
17+
<UniqueIdentifier>{51A424A9-2C12-4211-0000-000000000003}</UniqueIdentifier>
1818
</Filter>
1919
<Filter Include="src\config">
2020
<UniqueIdentifier>{51A424A9-2C12-4211-0000-000000000002}</UniqueIdentifier>
@@ -35,22 +35,22 @@
3535
<UniqueIdentifier>{51A424A9-2C12-4211-0000-000000000007}</UniqueIdentifier>
3636
</Filter>
3737
<Filter Include="src\hash\performance">
38-
<UniqueIdentifier>{51A424A9-2C12-4211-0000-000000000003}</UniqueIdentifier>
38+
<UniqueIdentifier>{51A424A9-2C12-4211-0000-000000000004}</UniqueIdentifier>
3939
</Filter>
4040
<Filter Include="src\hash\performance\baseline">
41-
<UniqueIdentifier>{51A424A9-2C12-4211-0000-000000000006}</UniqueIdentifier>
41+
<UniqueIdentifier>{51A424A9-2C12-4211-0000-000000000007}</UniqueIdentifier>
4242
</Filter>
4343
<Filter Include="src\hash\rmd">
44-
<UniqueIdentifier>{51A424A9-2C12-4211-0000-000000000004}</UniqueIdentifier>
44+
<UniqueIdentifier>{51A424A9-2C12-4211-0000-000000000005}</UniqueIdentifier>
4545
</Filter>
4646
<Filter Include="src\hash\sha">
47-
<UniqueIdentifier>{51A424A9-2C12-4211-0000-000000000005}</UniqueIdentifier>
47+
<UniqueIdentifier>{51A424A9-2C12-4211-0000-000000000006}</UniqueIdentifier>
4848
</Filter>
4949
<Filter Include="src\intrinsics">
5050
<UniqueIdentifier>{51A424A9-2C12-4211-0000-000000000008}</UniqueIdentifier>
5151
</Filter>
5252
<Filter Include="src\intrinsics\xcpu">
53-
<UniqueIdentifier>{51A424A9-2C12-4211-0000-000000000007}</UniqueIdentifier>
53+
<UniqueIdentifier>{51A424A9-2C12-4211-0000-000000000008}</UniqueIdentifier>
5454
</Filter>
5555
<Filter Include="src\machine">
5656
<UniqueIdentifier>{51A424A9-2C12-4211-0000-000000000009}</UniqueIdentifier>
@@ -68,37 +68,40 @@
6868
<UniqueIdentifier>{51A424A9-2C12-4211-0000-00000000000D}</UniqueIdentifier>
6969
</Filter>
7070
<Filter Include="src\stream\devices">
71-
<UniqueIdentifier>{51A424A9-2C12-4211-0000-000000000008}</UniqueIdentifier>
71+
<UniqueIdentifier>{51A424A9-2C12-4211-0000-000000000009}</UniqueIdentifier>
7272
</Filter>
7373
<Filter Include="src\stream\iostream">
74-
<UniqueIdentifier>{51A424A9-2C12-4211-0000-000000000009}</UniqueIdentifier>
74+
<UniqueIdentifier>{51A424A9-2C12-4211-0000-000000000010}</UniqueIdentifier>
7575
</Filter>
7676
<Filter Include="src\stream\streamers">
77-
<UniqueIdentifier>{51A424A9-2C12-4211-0000-000000000010}</UniqueIdentifier>
77+
<UniqueIdentifier>{51A424A9-2C12-4211-0000-0000000000A1}</UniqueIdentifier>
7878
</Filter>
7979
<Filter Include="src\unicode">
8080
<UniqueIdentifier>{51A424A9-2C12-4211-0000-00000000000E}</UniqueIdentifier>
8181
</Filter>
8282
<Filter Include="src\unicode\utf8_everywhere">
83-
<UniqueIdentifier>{51A424A9-2C12-4211-0000-0000000000A1}</UniqueIdentifier>
83+
<UniqueIdentifier>{51A424A9-2C12-4211-0000-0000000000B1}</UniqueIdentifier>
8484
</Filter>
85-
<Filter Include="src\wallet">
85+
<Filter Include="src\utreexo">
8686
<UniqueIdentifier>{51A424A9-2C12-4211-0000-00000000000F}</UniqueIdentifier>
8787
</Filter>
88+
<Filter Include="src\wallet">
89+
<UniqueIdentifier>{51A424A9-2C12-4211-0000-000000000001}</UniqueIdentifier>
90+
</Filter>
8891
<Filter Include="src\wallet\addresses">
89-
<UniqueIdentifier>{51A424A9-2C12-4211-0000-0000000000B1}</UniqueIdentifier>
92+
<UniqueIdentifier>{51A424A9-2C12-4211-0000-0000000000C1}</UniqueIdentifier>
9093
</Filter>
9194
<Filter Include="src\wallet\keys">
92-
<UniqueIdentifier>{51A424A9-2C12-4211-0000-0000000000C1}</UniqueIdentifier>
95+
<UniqueIdentifier>{51A424A9-2C12-4211-0000-0000000000D1}</UniqueIdentifier>
9396
</Filter>
9497
<Filter Include="src\wallet\mnemonics">
95-
<UniqueIdentifier>{51A424A9-2C12-4211-0000-0000000000D1}</UniqueIdentifier>
98+
<UniqueIdentifier>{51A424A9-2C12-4211-0000-0000000000E1}</UniqueIdentifier>
9699
</Filter>
97100
<Filter Include="src\words">
98-
<UniqueIdentifier>{51A424A9-2C12-4211-0000-000000000001}</UniqueIdentifier>
101+
<UniqueIdentifier>{51A424A9-2C12-4211-0000-000000000002}</UniqueIdentifier>
99102
</Filter>
100103
<Filter Include="src\words\catalogs">
101-
<UniqueIdentifier>{51A424A9-2C12-4211-0000-0000000000E1}</UniqueIdentifier>
104+
<UniqueIdentifier>{51A424A9-2C12-4211-0000-0000000000F1}</UniqueIdentifier>
102105
</Filter>
103106
</ItemGroup>
104107
<ItemGroup>
@@ -561,6 +564,9 @@
561564
<ClCompile Include="..\..\..\..\test\unicode\utf8_everywhere\unicode_ostream.cpp">
562565
<Filter>src\unicode\utf8_everywhere</Filter>
563566
</ClCompile>
567+
<ClCompile Include="..\..\..\..\test\utreexo\utreexo.cpp">
568+
<Filter>src\utreexo</Filter>
569+
</ClCompile>
564570
<ClCompile Include="..\..\..\..\test\wallet\addresses\bitcoin_uri.cpp">
565571
<Filter>src\wallet\addresses</Filter>
566572
</ClCompile>
@@ -695,6 +701,9 @@
695701
<ClInclude Include="..\..\..\..\test\test.hpp">
696702
<Filter>src</Filter>
697703
</ClInclude>
704+
<ClInclude Include="..\..\..\..\test\utreexo\utreexo.hpp">
705+
<Filter>src\utreexo</Filter>
706+
</ClInclude>
698707
<ClInclude Include="..\..\..\..\test\wallet\mnemonics\electrum.hpp">
699708
<Filter>src\wallet\mnemonics</Filter>
700709
</ClInclude>

include/bitcoin/system/impl/math/bits.ipp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -294,8 +294,8 @@ template <typename Value, if_unsigned_integral_integer<Value>>
294294
constexpr void shift_left_into(Value& value, size_t shift, bool overflow) NOEXCEPT
295295
{
296296
constexpr auto span = bits<Value>;
297-
overflow && shift >= span ? value = 0 :
298-
value <<= (shift % span);
297+
overflow && shift >= span ? value = 0 : depromote<Value>(
298+
value <<= (shift % span));
299299
}
300300

301301
// signed overloads (shift left of negative is undefined behavior).

include/bitcoin/system/impl/math/overflow.ipp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,21 @@ constexpr Integral minimum_ = std::numeric_limits<Integral>::min();
3333
template <typename Integral, if_integer<Integral> = true>
3434
constexpr Integral maximum_ = std::numeric_limits<Integral>::max();
3535

36+
// shift
37+
// ----------------------------------------------------------------------------
38+
39+
template <typename Value, if_unsigned_integral_integer<Value>>
40+
constexpr bool is_left_shift_overflow(Value value, size_t shift) NOEXCEPT
41+
{
42+
return to_bool(bit_and(value, unmask_left<Value>(shift)));
43+
}
44+
45+
template <typename Value, if_unsigned_integral_integer<Value>>
46+
constexpr bool is_right_shift_overflow(Value value, size_t shift) NOEXCEPT
47+
{
48+
return to_bool(bit_and(value, unmask_right<Value>(shift)));
49+
}
50+
3651
// add/subtract
3752
// ----------------------------------------------------------------------------
3853

include/bitcoin/system/math/overflow.hpp

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,19 @@
2323

2424
namespace libbitcoin {
2525
namespace system {
26+
27+
/// shift
28+
/// ---------------------------------------------------------------------------
29+
30+
/// Shift would cause 1-valued bit(s) to be left-shifted out.
31+
template <typename Value, if_unsigned_integral_integer<Value> = true>
32+
constexpr bool is_left_shift_overflow(Value value, size_t shift) NOEXCEPT;
33+
34+
/// Shift would cause 1-valued bit(s) to be right-shifted out.
35+
template <typename Value, if_unsigned_integral_integer<Value> = true>
36+
constexpr bool is_right_shift_overflow(Value value, size_t shift) NOEXCEPT;
2637

27-
/// add/subtract.
38+
/// shift/add/subtract.
2839
/// ---------------------------------------------------------------------------
2940
// TODO: generalize is_add_overflow() and is_subtract_overflow() argument types.
3041

test/math/overflow.cpp

Lines changed: 62 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,67 @@ constexpr auto signed_zero = 0_i16;
3030
constexpr auto signed_max = max_int16;
3131
constexpr auto signed_half = to_half(signed_max);
3232

33+
// is_left_shift_overflow
34+
// ----------------------------------------------------------------------------
35+
36+
// unsigned only
37+
static_assert(!is_left_shift_overflow<uint8_t>(0b00000000, 0));
38+
static_assert(!is_left_shift_overflow<uint8_t>(0b00000000, 1));
39+
static_assert(!is_left_shift_overflow<uint8_t>(0b00000000, 2));
40+
static_assert(!is_left_shift_overflow<uint8_t>(0b00000000, 4));
41+
static_assert(!is_left_shift_overflow<uint8_t>(0b00000000, 8));
42+
43+
static_assert(!is_left_shift_overflow<uint8_t>(0b00000001, 0));
44+
static_assert(!is_left_shift_overflow<uint8_t>(0b00000001, 1));
45+
static_assert(!is_left_shift_overflow<uint8_t>(0b00000001, 2));
46+
static_assert(!is_left_shift_overflow<uint8_t>(0b00000001, 4));
47+
static_assert( is_left_shift_overflow<uint8_t>(0b00000001, 8));
48+
49+
static_assert(!is_left_shift_overflow<uint8_t>(0b10000000, 0));
50+
static_assert( is_left_shift_overflow<uint8_t>(0b10000000, 1));
51+
static_assert( is_left_shift_overflow<uint8_t>(0b10000000, 2));
52+
static_assert( is_left_shift_overflow<uint8_t>(0b10000000, 4));
53+
static_assert( is_left_shift_overflow<uint8_t>(0b10000000, 8));
54+
55+
static_assert(!is_left_shift_overflow<uint8_t>(0b00101010, 0));
56+
static_assert(!is_left_shift_overflow<uint8_t>(0b00101010, 1));
57+
static_assert(!is_left_shift_overflow<uint8_t>(0b00101010, 2));
58+
static_assert( is_left_shift_overflow<uint8_t>(0b00101010, 4));
59+
static_assert( is_left_shift_overflow<uint8_t>(0b00101010, 8));
60+
61+
static_assert(!is_left_shift_overflow<uint8_t>(0b11111111, 0));
62+
static_assert( is_left_shift_overflow<uint8_t>(0b11111111, 1));
63+
static_assert( is_left_shift_overflow<uint8_t>(0b11111111, 2));
64+
static_assert( is_left_shift_overflow<uint8_t>(0b11111111, 4));
65+
static_assert( is_left_shift_overflow<uint8_t>(0b11111111, 8));
66+
67+
static_assert(!is_left_shift_overflow<uint16_t>(0b00010000'00000000, 0));
68+
static_assert(!is_left_shift_overflow<uint16_t>(0b00010000'00000000, 1));
69+
static_assert(!is_left_shift_overflow<uint16_t>(0b00010000'00000000, 2));
70+
static_assert( is_left_shift_overflow<uint16_t>(0b00010000'00000000, 4));
71+
static_assert( is_left_shift_overflow<uint16_t>(0b00010000'00000000, 8));
72+
static_assert( is_left_shift_overflow<uint16_t>(0b00000000'00000001, bits<uint16_t>));
73+
static_assert(!is_left_shift_overflow<uint16_t>(0b00000000'00000001, sub1(bits<uint16_t>)));
74+
75+
static_assert(!is_left_shift_overflow<uint32_t>(0b00010000'00000000'00000000'00000000, 0));
76+
static_assert(!is_left_shift_overflow<uint32_t>(0b00010000'00000000'00000000'00000000, 1));
77+
static_assert(!is_left_shift_overflow<uint32_t>(0b00010000'00000000'00000000'00000000, 2));
78+
static_assert( is_left_shift_overflow<uint32_t>(0b00010000'00000000'00000000'00000000, 4));
79+
static_assert( is_left_shift_overflow<uint32_t>(0b00010000'00000000'00000000'00000000, 8));
80+
static_assert( is_left_shift_overflow<uint32_t>(0b00000000'00000000'00000000'00000001, bits<uint32_t>));
81+
static_assert(!is_left_shift_overflow<uint32_t>(0b00000000'00000000'00000000'00000001, sub1(bits<uint32_t>)));
82+
83+
static_assert(!is_left_shift_overflow<uint64_t>(0b00010000'00000000'00000000'00000000'00010000'00000000'00000000'00000000, 0));
84+
static_assert(!is_left_shift_overflow<uint64_t>(0b00010000'00000000'00000000'00000000'00010000'00000000'00000000'00000000, 1));
85+
static_assert(!is_left_shift_overflow<uint64_t>(0b00010000'00000000'00000000'00000000'00010000'00000000'00000000'00000000, 2));
86+
static_assert( is_left_shift_overflow<uint64_t>(0b00010000'00000000'00000000'00000000'00010000'00000000'00000000'00000000, 4));
87+
static_assert( is_left_shift_overflow<uint64_t>(0b00010000'00000000'00000000'00000000'00010000'00000000'00000000'00000000, 8));
88+
static_assert( is_left_shift_overflow<uint64_t>(0b00000000'00000000'00000000'00000000'00000000'00000000'00000000'00000001, bits<uint64_t>));
89+
static_assert(!is_left_shift_overflow<uint64_t>(0b00000000'00000000'00000000'00000000'00000000'00000000'00000000'00000001, sub1(bits<uint64_t>)));
90+
91+
// is_right_shift_overflow
92+
// ----------------------------------------------------------------------------
93+
3394
// is_negate_overflow
3495
// ----------------------------------------------------------------------------
3596

@@ -68,7 +129,7 @@ static_assert(is_add_overflow(unsigned_max, unsigned_half));
68129
static_assert(is_add_overflow(unsigned_half, unsigned_max));
69130
static_assert(!is_add_overflow(unsigned_half, unsigned_half));
70131

71-
// is_underflow
132+
// is_subtract_overflow
72133
// ----------------------------------------------------------------------------
73134

74135
// signed

0 commit comments

Comments
 (0)