From a82d1a7dccadd3e1661808aa60ab5a340b882504 Mon Sep 17 00:00:00 2001 From: evoskuil Date: Sun, 21 Jun 2026 18:06:05 -0400 Subject: [PATCH] Update ecdsa and schnorr tables for unified multisig. --- .../database/impl/query/signatures.ipp | 69 +++++------ include/bitcoin/database/query.hpp | 11 +- .../bitcoin/database/tables/caches/ecdsa.hpp | 102 +++++++++++++++- .../database/tables/caches/multisig.hpp | 2 - .../database/tables/caches/schnorr.hpp | 113 +++++++++++++++++- include/bitcoin/database/tables/schema.hpp | 17 ++- include/bitcoin/database/types/type.hpp | 2 +- test/query/signatures.cpp | 45 ++++--- test/tables/caches/ecdsa.cpp | 23 ++-- test/tables/caches/schnorr.cpp | 26 ++-- 10 files changed, 311 insertions(+), 99 deletions(-) diff --git a/include/bitcoin/database/impl/query/signatures.ipp b/include/bitcoin/database/impl/query/signatures.ipp index 68bfe3534..23d4a1df5 100644 --- a/include/bitcoin/database/impl/query/signatures.ipp +++ b/include/bitcoin/database/impl/query/signatures.ipp @@ -74,92 +74,81 @@ bool CLASS::purge_schnorr_signatures() NOEXCEPT TEMPLATE bool CLASS::set_signature(const hash_digest& digest, const ec_compressed& point, - const ec_signature& signature, const header_link& link) NOEXCEPT + const ec_signature& signature, uint16_t id, const header_link& link) NOEXCEPT { // ======================================================================== const auto scope = store_.get_transactor(); // Clean single allocation failure (e.g. disk full). - return store_.ecdsa.put(table::ecdsa::record + return store_.ecdsa.put(table::ecdsa::put_single_ref { {}, digest, point, signature, + id, link }); // ======================================================================== - - return true; } TEMPLATE bool CLASS::set_signature(const hash_digest& digest, const ec_xonly& point, - const ec_signature& signature, const header_link& link) NOEXCEPT + const ec_signature& signature, uint16_t id, const header_link& link) NOEXCEPT { // ======================================================================== const auto scope = store_.get_transactor(); // Clean single allocation failure (e.g. disk full). - return store_.schnorr.put(table::schnorr::record + return store_.schnorr.put(table::schnorr::put_single_ref { {}, digest, point, signature, + id, link }); // ======================================================================== - - return true; } TEMPLATE -bool CLASS::set_signatures(const hash_digest&, const ec_compresseds&, - const ec_signatures&, size_t, const header_link&) NOEXCEPT +bool CLASS::set_signatures(const hash_digest& digest, + const ec_compresseds& keys, const ec_signatures& sigs, uint16_t id, + const header_link& link) NOEXCEPT { // ======================================================================== const auto scope = store_.get_transactor(); - // TODO: flatten via store_.ecdsa.put(); - - ////// Clean single allocation failure (e.g. disk full). - ////return store_.multisig.put(table::multisig::put_ref - ////{ - //// {}, - //// digest, - //// keys, - //// sigs, - //// group, - //// link - ////}); + // Clean single allocation failure (e.g. disk full). + return store_.ecdsa.put(table::ecdsa::put_multiple_ref + { + {}, + digest, + keys, + sigs, + id, + link + }); // ======================================================================== - - return true; } TEMPLATE -bool CLASS::set_signatures(const threshold& , size_t , - const header_link& ) NOEXCEPT +bool CLASS::set_signatures(const threshold& batch, uint16_t id, + const header_link& link) NOEXCEPT { // ======================================================================== const auto scope = store_.get_transactor(); - // TODO: flatten via store_.schnorr.put(); - - ////// Clean single allocation failure (e.g. disk full). - ////return store_.multisig.put(table::multisig::put_ref - ////{ - //// {}, - //// digest, - //// keys, - //// sigs, - //// group, - //// link - ////}); + // Clean single allocation failure (e.g. disk full). + return store_.schnorr.put(table::schnorr::put_multiple_ref + { + {}, + batch, + id, + link + }); // ======================================================================== - - return true; } } // namespace database diff --git a/include/bitcoin/database/query.hpp b/include/bitcoin/database/query.hpp index c9aab7c87..9ba8bbe7f 100644 --- a/include/bitcoin/database/query.hpp +++ b/include/bitcoin/database/query.hpp @@ -574,12 +574,15 @@ class query /// Set signature (ecdsa/schnorr/multisig) table entry. bool set_signature(const hash_digest& digest, const ec_compressed& point, - const ec_signature& signature, const header_link& link) NOEXCEPT; + const ec_signature& signature, uint16_t id, + const header_link& link) NOEXCEPT; bool set_signature(const hash_digest& digest, const ec_xonly& point, - const ec_signature& signature, const header_link& link) NOEXCEPT; + const ec_signature& signature, uint16_t id, + const header_link& link) NOEXCEPT; bool set_signatures(const hash_digest& digest, const ec_compresseds& keys, - const ec_signatures& sigs, size_t set, const header_link& link) NOEXCEPT; - bool set_signatures(const threshold& group, size_t set, + const ec_signatures& sigs, uint16_t id, + const header_link& link) NOEXCEPT; + bool set_signatures(const threshold& batch, uint16_t id, const header_link& link) NOEXCEPT; /// Signature verification. diff --git a/include/bitcoin/database/tables/caches/ecdsa.hpp b/include/bitcoin/database/tables/caches/ecdsa.hpp index 4cd230e8a..fe2c0b473 100644 --- a/include/bitcoin/database/tables/caches/ecdsa.hpp +++ b/include/bitcoin/database/tables/caches/ecdsa.hpp @@ -26,7 +26,7 @@ namespace libbitcoin { namespace database { namespace table { - + /// ecdsa is an array of ecdsa signature validation records. struct ecdsa : public no_map @@ -37,11 +37,18 @@ struct ecdsa struct record : public schema::ecdsa { + inline link count() const NOEXCEPT + { + return 1; + } + inline bool from_data(reader& source) NOEXCEPT { digest = source.read_hash(); point = source.read_forward(); signature = source.read_forward(); + pair = source.read_byte(); + group = source.read_little_endian(); header_fk = source.read_little_endian(); BC_ASSERT(!source || source.get_read_position() == minrow); return source; @@ -52,6 +59,8 @@ struct ecdsa sink.write_bytes(digest); sink.write_bytes(point); sink.write_bytes(signature); + sink.write_byte(pair); + sink.write_little_endian(group); sink.write_little_endian(header_fk); BC_ASSERT(!sink || sink.get_write_position() == minrow); return sink; @@ -62,17 +71,104 @@ struct ecdsa return digest == other.digest && point == other.point && signature == other.signature + && pair == other.pair + && group == other.group && header_fk == other.header_fk; } + /// pair: m (row 0, for all), n (row 1, for n > 1). system::hash_digest digest{}; system::ec_compressed point{}; system::ec_signature signature{}; + uint8_t pair{}; + uint16_t group{}; header::integer header_fk{}; }; -}; -static_assert(sizeof(system::ecdsa::batch) == schema::ecdsa::minrow); + struct put_single_ref + : public schema::ecdsa + { + inline link count() const NOEXCEPT + { + return 1; + } + + /// Writer used for single-sig row, should always write pair = 1. + inline bool to_data(flipper& sink) const NOEXCEPT + { + sink.write_bytes(digest); + sink.write_bytes(point); + sink.write_bytes(signature); + sink.write_byte(0); + sink.write_little_endian(group); + sink.write_little_endian(header_fk); + BC_ASSERT(!sink || sink.get_write_position() == minrow); + return sink; + } + + /// pair: m (row 0, for all), n (row 1, for n > 1). + const system::hash_digest& digest; + const system::ec_compressed& point; + const system::ec_signature& signature; + uint16_t group{}; + header::integer header_fk{}; + }; + + /// Writer for one row multisig, writes as if a single sig. + /// Writer for multisig groups (denormalized m|n in first two rows). + struct put_multiple_ref + : public schema::ecdsa + { + inline link count() const NOEXCEPT + { + using namespace system; + const auto m = sigs.size(); + const auto n = keys.size(); + const auto gap = n - m; + if (is_subtract_overflow(n, m) || is_add_overflow(gap, one)) + return {}; + + const auto sum = add1(gap); + if (is_multiply_overflow(m, sum)) + return {}; + + // Terminal count fails the write attempt, so to_data() is guarded. + return possible_narrow_cast(m * sum); + } + + inline bool to_data(flipper& sink) const NOEXCEPT + { + using namespace system; + constexpr auto max = power2(to_half(byte_bits)); + const auto m = sigs.size(); + const auto n = keys.size(); + if (is_zero(m) || is_zero(n) || n > max || m > n) + return false; + + for (size_t sig{}; sig < m; ++sig) + { + for (auto key = sig; key <= n - (m - sig); ++key) + { + sink.write_bytes(digest); + sink.write_bytes(keys.at(key)); + sink.write_bytes(sigs.at(sig)); + sink.write_byte(pack_word(sig, key)); + sink.write_little_endian(group); + sink.write_little_endian( + header_fk); + } + } + + return sink; + } + + const hash_digest& digest; + const system::ec_compresseds& keys; + const system::ec_signatures& sigs; + const uint16_t group{}; + const header::integer header_fk{}; + }; +}; } // namespace table } // namespace database diff --git a/include/bitcoin/database/tables/caches/multisig.hpp b/include/bitcoin/database/tables/caches/multisig.hpp index f48fb38d2..97c9c57ac 100644 --- a/include/bitcoin/database/tables/caches/multisig.hpp +++ b/include/bitcoin/database/tables/caches/multisig.hpp @@ -137,8 +137,6 @@ struct multisig }; }; -static_assert(sizeof(system::multisig::batch) == schema::multisig::minrow); - } // namespace table } // namespace database } // namespace libbitcoin diff --git a/include/bitcoin/database/tables/caches/schnorr.hpp b/include/bitcoin/database/tables/caches/schnorr.hpp index 2e35a0785..672842e36 100644 --- a/include/bitcoin/database/tables/caches/schnorr.hpp +++ b/include/bitcoin/database/tables/caches/schnorr.hpp @@ -33,15 +33,24 @@ struct schnorr { using header = schema::header::link; using no_map::nomap; + using category_t = system::chain::threshold::category_t; struct record : public schema::schnorr { + inline link count() const NOEXCEPT + { + return 1; + } + inline bool from_data(reader& source) NOEXCEPT { digest = source.read_hash(); point = source.read_forward(); signature = source.read_forward(); + category = static_cast(source.read_byte()); + pair = source.read_little_endian(); + group = source.read_little_endian(); header_fk = source.read_little_endian(); BC_ASSERT(!source || source.get_read_position() == minrow); return source; @@ -52,6 +61,9 @@ struct schnorr sink.write_bytes(digest); sink.write_bytes(point); sink.write_bytes(signature); + sink.write_byte(to_value(category)); + sink.write_little_endian(pair); + sink.write_little_endian(group); sink.write_little_endian(header_fk); BC_ASSERT(!sink || sink.get_write_position() == minrow); return sink; @@ -62,17 +74,114 @@ struct schnorr return digest == other.digest && point == other.point && signature == other.signature + && category == other.category + && pair == other.pair + && group == other.group && header_fk == other.header_fk; } + /// pair: min (row 0, for all), max (row 1, for category::between). system::hash_digest digest{}; system::ec_xonly point{}; system::ec_signature signature{}; + category_t category{}; + uint16_t pair{}; + uint16_t group{}; header::integer header_fk{}; }; -}; -static_assert(sizeof(system::schnorr::batch) == schema::schnorr::minrow); + struct put_single_ref + : public schema::schnorr + { + inline link count() const NOEXCEPT + { + return 1; + } + + inline bool to_data(flipper& sink) const NOEXCEPT + { + constexpr auto category = to_value(category_t::single); + sink.write_bytes(digest); + sink.write_bytes(point); + sink.write_bytes(signature); + sink.write_byte(category); + sink.write_little_endian(1); + sink.write_little_endian(group); + sink.write_little_endian(header_fk); + BC_ASSERT(!sink || sink.get_write_position() == minrow); + return sink; + } + + /// pair: min (row 0, for all), max (row 1, for category::between). + const system::hash_digest& digest; + const system::ec_xonly& point; + const system::ec_signature& signature; + uint16_t group{}; + header::integer header_fk{}; + }; + + /// Writer for threshold groups (denormalized min/max in first two rows). + struct put_multiple_ref + : public schema::schnorr + { + inline link count() const NOEXCEPT + { + using namespace system; + return possible_narrow_cast(batch.tuples.size()); + } + + /// min in first row, max in second row (for within only). + inline uint16_t to_pair(size_t index, size_t count, bool between, + uint16_t min, uint16_t max) const NOEXCEPT + { + using namespace system; + if (is_zero(index)) + return min; + + if (between && is_one(index) && count > one) + return max; + + return {}; + } + + inline bool to_data(flipper& sink) const NOEXCEPT + { + using namespace system; + const auto rows = count(); + if (is_zero(rows)) + return false; + + const bool between = (batch.category == category_t::between); + + for (size_t row{}; row < rows; ++row) + { + // First 1-2 rows only. + const auto pair = to_pair(row, rows, between, + batch.minimum, batch.maximum); + + // First row only. + const auto category = is_nonzero(row) ? 0_u8 : + to_value(batch.category); + + const auto& tuple = batch.tuples.at(row); + sink.write_bytes(tuple.digest); + sink.write_bytes(tuple.point.get()); + sink.write_bytes(tuple.sig.get()); + sink.write_byte(category); + sink.write_little_endian(pair); + sink.write_little_endian(group); + sink.write_little_endian( + header_fk); + } + + return sink; + } + + const system::chain::threshold& batch; + uint16_t group{}; + header::integer header_fk{}; + }; +}; } // namespace table } // namespace database diff --git a/include/bitcoin/database/tables/schema.hpp b/include/bitcoin/database/tables/schema.hpp index b4ddfe54b..33975d322 100644 --- a/include/bitcoin/database/tables/schema.hpp +++ b/include/bitcoin/database/tables/schema.hpp @@ -268,12 +268,14 @@ struct ecdsa system::hash_size + system::ec_compressed_size + system::ec_signature_size + + one + // [m|n] in one byte (m in first row, n in second). + count_ + // input (within block) correlation counter. schema::header::pk; static constexpr size_t minrow = minsize; static constexpr size_t size = minsize; - static constexpr link count() NOEXCEPT { return 1; } - static_assert(minsize == 132u); - static_assert(minrow == 132u); + ////static constexpr link count() NOEXCEPT { return 1; } + static_assert(minsize == 135u); + static_assert(minrow == 135u); static_assert(link::size == 4u); }; @@ -286,12 +288,15 @@ struct schnorr system::hash_size + system::ec_xonly_size + system::ec_signature_size + + one + // category (see system::chain::signatures::category). + two + // [min|max] in two bytes (min in first row, max in second). + count_ + // input (within block) correlation counter. schema::header::pk; static constexpr size_t minrow = minsize; static constexpr size_t size = minsize; - static constexpr link count() NOEXCEPT { return 1; } - static_assert(minsize == 131u); - static_assert(minrow == 131u); + ////static constexpr link count() NOEXCEPT { return 1; } + static_assert(minsize == 136u); + static_assert(minrow == 136u); static_assert(link::size == 4u); }; diff --git a/include/bitcoin/database/types/type.hpp b/include/bitcoin/database/types/type.hpp index def8a2dc3..63a97f533 100644 --- a/include/bitcoin/database/types/type.hpp +++ b/include/bitcoin/database/types/type.hpp @@ -69,7 +69,7 @@ using data_chunk = system::data_chunk; /// Common system::chain aliases. /// --------------------------------------------------------------------------- -using threshold = system::chain::signatures::threshold_group; +using threshold = system::chain::threshold; using checkpoint = system::chain::checkpoint; using inpoint = system::chain::point; diff --git a/test/query/signatures.cpp b/test/query/signatures.cpp index e1b752f17..b7fdfe91c 100644 --- a/test/query/signatures.cpp +++ b/test/query/signatures.cpp @@ -54,7 +54,7 @@ BOOST_AUTO_TEST_CASE(query__verify_ecdsa_signatures__one_valid__empty) const database::settings configuration{}; test::chunk_store store{ configuration }; test::query_accessor query{ store }; - BOOST_REQUIRE(query.set_signature(ecdsa_sighash, ecdsa_compressed, ecdsa_signature, 42)); + BOOST_REQUIRE(query.set_signature(ecdsa_sighash, ecdsa_compressed, ecdsa_signature, 0, 42)); header_links links{}; BOOST_REQUIRE_EQUAL(query.ecdsa_records(), 1u); @@ -68,7 +68,7 @@ BOOST_AUTO_TEST_CASE(query__verify_ecdsa_signatures__one_invalid__expected_link) test::chunk_store store{ configuration }; test::query_accessor query{ store }; constexpr auto expected = 42u; - BOOST_REQUIRE(query.set_signature(sighash_bad, ecdsa_compressed, ecdsa_signature, expected)); + BOOST_REQUIRE(query.set_signature(sighash_bad, ecdsa_compressed, ecdsa_signature, 0, expected)); header_links links{}; BOOST_REQUIRE_EQUAL(query.ecdsa_records(), 1u); @@ -84,21 +84,21 @@ BOOST_AUTO_TEST_CASE(query__verify_ecdsa_signatures__various__expected_links) test::query_accessor query{ store }; constexpr auto expected1 = 42u; constexpr auto expected2 = 24u; - BOOST_REQUIRE(query.set_signature(ecdsa_sighash, ecdsa_compressed, ecdsa_signature, 1)); - BOOST_REQUIRE(query.set_signature(ecdsa_sighash, ecdsa_compressed, ecdsa_signature, 2)); - BOOST_REQUIRE(query.set_signature(sighash_bad, ecdsa_compressed, ecdsa_signature, expected1)); - BOOST_REQUIRE(query.set_signature(ecdsa_sighash, ecdsa_compressed, ecdsa_signature, 3)); - BOOST_REQUIRE(query.set_signature(ecdsa_sighash, ecdsa_compressed, ecdsa_signature, 4)); - BOOST_REQUIRE(query.set_signature(sighash_bad, ecdsa_compressed, ecdsa_signature, expected2)); - BOOST_REQUIRE(query.set_signature(ecdsa_sighash, ecdsa_compressed, ecdsa_signature, 5)); - BOOST_REQUIRE(query.set_signature(ecdsa_sighash, ecdsa_compressed, ecdsa_signature, 6)); + + BOOST_REQUIRE(query.set_signature(ecdsa_sighash, ecdsa_compressed, ecdsa_signature, 0, 1)); + BOOST_REQUIRE(query.set_signature(ecdsa_sighash, ecdsa_compressed, ecdsa_signature, 0, 2)); + BOOST_REQUIRE(query.set_signature(sighash_bad, ecdsa_compressed, ecdsa_signature, 0, expected1)); + BOOST_REQUIRE(query.set_signature(ecdsa_sighash, ecdsa_compressed, ecdsa_signature, 0, 3)); + BOOST_REQUIRE(query.set_signature(ecdsa_sighash, ecdsa_compressed, ecdsa_signature, 0, 4)); + BOOST_REQUIRE(query.set_signature(sighash_bad, ecdsa_compressed, ecdsa_signature, 0, expected2)); + BOOST_REQUIRE(query.set_signature(ecdsa_sighash, ecdsa_compressed, ecdsa_signature, 0, 5)); + BOOST_REQUIRE(query.set_signature(ecdsa_sighash, ecdsa_compressed, ecdsa_signature, 0, 6)); header_links links{}; BOOST_REQUIRE_EQUAL(query.ecdsa_records(), 8u); BOOST_REQUIRE(query.verify_ecdsa_signatures({}, links)); BOOST_REQUIRE_EQUAL(links.size(), 2u); - // Order is not guaranteed. const auto back = links.back(); const auto front = links.front(); BOOST_REQUIRE((front == expected1 && back == expected2) || (front == expected2 && back == expected1)); @@ -106,7 +106,6 @@ BOOST_AUTO_TEST_CASE(query__verify_ecdsa_signatures__various__expected_links) // schnorr -// schnorr (valid BIP-340 test vector #0) const hash_digest schnorr_sighash = base16_array( "0000000000000000000000000000000000000000000000000000000000000000"); const ec_xonly schnorr_xonly = base16_array( @@ -132,7 +131,7 @@ BOOST_AUTO_TEST_CASE(query__verify_schnorr_signatures__one_valid__empty) const database::settings configuration{}; test::chunk_store store{ configuration }; test::query_accessor query{ store }; - BOOST_REQUIRE(query.set_signature(schnorr_sighash, schnorr_xonly, schnorr_signature, 42)); + BOOST_REQUIRE(query.set_signature(schnorr_sighash, schnorr_xonly, schnorr_signature, 0, 42)); header_links links{}; BOOST_REQUIRE_EQUAL(query.schnorr_records(), 1u); @@ -146,7 +145,7 @@ BOOST_AUTO_TEST_CASE(query__verify_schnorr_signatures__one_invalid__expected_lin test::chunk_store store{ configuration }; test::query_accessor query{ store }; constexpr auto expected = 42u; - BOOST_REQUIRE(query.set_signature(sighash_bad, schnorr_xonly, schnorr_signature, expected)); + BOOST_REQUIRE(query.set_signature(sighash_bad, schnorr_xonly, schnorr_signature, 0, expected)); header_links links{}; BOOST_REQUIRE_EQUAL(query.schnorr_records(), 1u); @@ -162,21 +161,21 @@ BOOST_AUTO_TEST_CASE(query__verify_schnorr_signatures__various__expected_links) test::query_accessor query{ store }; constexpr auto expected1 = 42u; constexpr auto expected2 = 24u; - BOOST_REQUIRE(query.set_signature(schnorr_sighash, schnorr_xonly, schnorr_signature, 1)); - BOOST_REQUIRE(query.set_signature(schnorr_sighash, schnorr_xonly, schnorr_signature, 2)); - BOOST_REQUIRE(query.set_signature(sighash_bad, schnorr_xonly, schnorr_signature, expected1)); - BOOST_REQUIRE(query.set_signature(schnorr_sighash, schnorr_xonly, schnorr_signature, 3)); - BOOST_REQUIRE(query.set_signature(schnorr_sighash, schnorr_xonly, schnorr_signature, 4)); - BOOST_REQUIRE(query.set_signature(sighash_bad, schnorr_xonly, schnorr_signature, expected2)); - BOOST_REQUIRE(query.set_signature(schnorr_sighash, schnorr_xonly, schnorr_signature, 5)); - BOOST_REQUIRE(query.set_signature(schnorr_sighash, schnorr_xonly, schnorr_signature, 6)); + + BOOST_REQUIRE(query.set_signature(schnorr_sighash, schnorr_xonly, schnorr_signature, 0, 1)); + BOOST_REQUIRE(query.set_signature(schnorr_sighash, schnorr_xonly, schnorr_signature, 0, 2)); + BOOST_REQUIRE(query.set_signature(sighash_bad, schnorr_xonly, schnorr_signature, 0, expected1)); + BOOST_REQUIRE(query.set_signature(schnorr_sighash, schnorr_xonly, schnorr_signature, 0, 3)); + BOOST_REQUIRE(query.set_signature(schnorr_sighash, schnorr_xonly, schnorr_signature, 0, 4)); + BOOST_REQUIRE(query.set_signature(sighash_bad, schnorr_xonly, schnorr_signature, 0, expected2)); + BOOST_REQUIRE(query.set_signature(schnorr_sighash, schnorr_xonly, schnorr_signature, 0, 5)); + BOOST_REQUIRE(query.set_signature(schnorr_sighash, schnorr_xonly, schnorr_signature, 0, 6)); header_links links{}; BOOST_REQUIRE_EQUAL(query.schnorr_records(), 8u); BOOST_REQUIRE(query.verify_schnorr_signatures({}, links)); BOOST_REQUIRE_EQUAL(links.size(), 2u); - // Order is not guaranteed. const auto back = links.back(); const auto front = links.front(); BOOST_REQUIRE((front == expected1 && back == expected2) || (front == expected2 && back == expected1)); diff --git a/test/tables/caches/ecdsa.cpp b/test/tables/caches/ecdsa.cpp index 433af3bce..8ccd893e1 100644 --- a/test/tables/caches/ecdsa.cpp +++ b/test/tables/caches/ecdsa.cpp @@ -29,7 +29,9 @@ const table::ecdsa::record record1 base16_hash("1111111111111111111111111111111111111111111111111111111111111111"), base16_array("222222222222222222222222222222222222222222222222222222222222222222"), base16_array("33333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333"), - 0x00345678_u32 + 0x78, // pair + 0x5678_u16, // group (16-bit) + 0x00345678_u32 // header_fk (3 bytes used) }; const table::ecdsa::record record2 @@ -38,24 +40,31 @@ const table::ecdsa::record record2 base16_hash("4444444444444444444444444444444444444444444444444444444444444444"), base16_array("555555555555555555555555555555555555555555555555555555555555555555"), base16_array("66666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666"), - 0x00cdef12_u32 + 0x12, // pair + 0xcdef_u16, // group + 0x00cdef12_u32 // header_fk }; const auto expected_head = base16_chunk("00000000"); -const auto closed_head = base16_chunk("02000000"); +const auto closed_head = base16_chunk("02000000"); + const auto expected_body = base16_chunk ( // record 1 "1111111111111111111111111111111111111111111111111111111111111111" "222222222222222222222222222222222222222222222222222222222222222222" "33333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333" - "785634" + "78" // pair + "7856" // group (little-endian, 2 bytes) + "785634" // header_fk (3 bytes) // record 2 "4444444444444444444444444444444444444444444444444444444444444444" "555555555555555555555555555555555555555555555555555555555555555555" "66666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666" - "12efcd" + "12" // pair + "efcd" // group + "12efcd" // header_fk ); BOOST_AUTO_TEST_CASE(ecdsa__put__two__expected) @@ -86,8 +95,6 @@ BOOST_AUTO_TEST_CASE(ecdsa__get__two__expected) test::chunk_storage head_store{ head }; test::chunk_storage body_store{ body }; table::ecdsa instance{ head_store, body_store }; - BOOST_REQUIRE_EQUAL(head_store.buffer(), expected_head); - BOOST_REQUIRE_EQUAL(body_store.buffer(), expected_body); table::ecdsa::record out{}; BOOST_REQUIRE(instance.get(0u, out)); @@ -103,8 +110,6 @@ BOOST_AUTO_TEST_CASE(ecdsa__truncate__from_two__expected) test::chunk_storage head_store{ head }; test::chunk_storage body_store{ body }; table::ecdsa instance{ head_store, body_store }; - BOOST_REQUIRE_EQUAL(head_store.buffer(), expected_head); - BOOST_REQUIRE_EQUAL(body_store.buffer(), expected_body); BOOST_REQUIRE_EQUAL(instance.count(), 2u); BOOST_REQUIRE(instance.truncate(1)); diff --git a/test/tables/caches/schnorr.cpp b/test/tables/caches/schnorr.cpp index f9fee9aa1..a6422b5ad 100644 --- a/test/tables/caches/schnorr.cpp +++ b/test/tables/caches/schnorr.cpp @@ -29,7 +29,10 @@ const table::schnorr::record record1 base16_hash("1111111111111111111111111111111111111111111111111111111111111111"), base16_array("2222222222222222222222222222222222222222222222222222222222222222"), base16_array("33333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333"), - 0x00345678_u32 + chain::threshold::category_t::single, + 0x5678_u16, // pair + 0x1234_u16, // group + 0x00cdef12_u32 // header_fk }; const table::schnorr::record record2 @@ -38,24 +41,33 @@ const table::schnorr::record record2 base16_hash("4444444444444444444444444444444444444444444444444444444444444444"), base16_array("5555555555555555555555555555555555555555555555555555555555555555"), base16_array("66666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666"), - 0x00cdef12_u32 + chain::threshold::category_t::between, + 0xcdef_u16, // pair + 0x5678_u16, // group + 0x00345678_u32 // header_fk }; const auto expected_head = base16_chunk("00000000"); -const auto closed_head = base16_chunk("02000000"); +const auto closed_head = base16_chunk("02000000"); const auto expected_body = base16_chunk ( // record 1 "1111111111111111111111111111111111111111111111111111111111111111" "2222222222222222222222222222222222222222222222222222222222222222" "33333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333" - "785634" + "01" // category (checksig/single) + "7856" // pair + "3412" // group + "12efcd" // header_fk (3 bytes) // record 2 "4444444444444444444444444444444444444444444444444444444444444444" "5555555555555555555555555555555555555555555555555555555555555555" "66666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666" - "12efcd" + "08" // category (within/between) + "efcd" // pair + "7856" // group + "785634" // header_fk ); BOOST_AUTO_TEST_CASE(schnorr__put__two__expected) @@ -86,8 +98,6 @@ BOOST_AUTO_TEST_CASE(schnorr__get__two__expected) test::chunk_storage head_store{ head }; test::chunk_storage body_store{ body }; table::schnorr instance{ head_store, body_store }; - BOOST_REQUIRE_EQUAL(head_store.buffer(), expected_head); - BOOST_REQUIRE_EQUAL(body_store.buffer(), expected_body); table::schnorr::record out{}; BOOST_REQUIRE(instance.get(0u, out)); @@ -103,8 +113,6 @@ BOOST_AUTO_TEST_CASE(schnorr__truncate__from_two__expected) test::chunk_storage head_store{ head }; test::chunk_storage body_store{ body }; table::schnorr instance{ head_store, body_store }; - BOOST_REQUIRE_EQUAL(head_store.buffer(), expected_head); - BOOST_REQUIRE_EQUAL(body_store.buffer(), expected_body); BOOST_REQUIRE_EQUAL(instance.count(), 2u); BOOST_REQUIRE(instance.truncate(1));