From 2b2a681b017683153ed747f693b21f67049a2b27 Mon Sep 17 00:00:00 2001 From: moneromooo-monero Date: Sun, 12 Aug 2018 21:45:10 +0000 Subject: [PATCH] blockchain_blackball: avoid false positives for different amounts Identical offset based rings may not actually be identical rings since they represent different outputs --- .../blockchain_blackball.cpp | 20 +++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/src/blockchain_utilities/blockchain_blackball.cpp b/src/blockchain_utilities/blockchain_blackball.cpp index 833a19a0b..42e04f195 100644 --- a/src/blockchain_utilities/blockchain_blackball.cpp +++ b/src/blockchain_utilities/blockchain_blackball.cpp @@ -298,14 +298,18 @@ static void close() } } -static std::string compress_ring(const std::vector &ring) +static std::string compress_ring(const std::vector &ring, std::string s = "") { - std::string s; for (uint64_t out: ring) s += tools::get_varint_data(out); return s; } +static std::string compress_ring(uint64_t amount, const std::vector &ring) +{ + return compress_ring(ring, tools::get_varint_data(amount)); +} + static std::vector decompress_ring(const std::string &s) { std::vector ring; @@ -583,9 +587,9 @@ static std::string keep_under_511(const std::string &s) return std::string((const char*)&hash, 32); } -static uint64_t get_ring_instances(MDB_txn *txn, const std::vector &ring) +static uint64_t get_ring_instances(MDB_txn *txn, uint64_t amount, const std::vector &ring) { - const std::string sring = keep_under_511(compress_ring(ring)); + const std::string sring = keep_under_511(compress_ring(amount, ring)); MDB_val k, v; k.mv_data = (void*)sring.data(); k.mv_size = sring.size(); @@ -596,9 +600,9 @@ static uint64_t get_ring_instances(MDB_txn *txn, const std::vector &ri return *(const uint64_t*)v.mv_data; } -static void set_ring_instances(MDB_txn *txn, const std::vector &ring, uint64_t count) +static void set_ring_instances(MDB_txn *txn, uint64_t amount, const std::vector &ring, uint64_t count) { - const std::string sring = keep_under_511(compress_ring(ring)); + const std::string sring = keep_under_511(compress_ring(amount, ring)); MDB_val k, v; k.mv_data = (void*)sring.data(); k.mv_size = sring.size(); @@ -945,9 +949,9 @@ int main(int argc, char* argv[]) std::vector relative_ring; std::vector new_ring = canonicalize(txin.key_offsets); const uint32_t ring_size = txin.key_offsets.size(); - uint64_t instances = get_ring_instances(txn, new_ring); + uint64_t instances = get_ring_instances(txn, txin.amount, new_ring); ++instances; - set_ring_instances(txn, new_ring, instances); + set_ring_instances(txn, txin.amount, new_ring, instances); if (n == 0 && ring_size == 1) { const crypto::public_key pkey = get_output_key(cur0, txin.amount, absolute[0]);