From 3aa4d48ee53a12019a67ab3cae133dfddf53b910 Mon Sep 17 00:00:00 2001 From: Jason Huebert Date: Sat, 5 Sep 2026 10:27:57 -0500 Subject: [PATCH] simple_repeater: sample advert cache key from pubkey middle bytes MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Vanity pubkeys are ground to match at the leading bytes (c0ffee, deadbeef), and sometimes at trailing bytes, so contiguous prefix keys collide far above random chance within a vanity club — worst case, every repeater sharing a 4-byte vanity shares one cache entry, and the least-frequent advertiser gets suppressed indefinitely. Sample the 4-byte key at fixed offsets {8,14,20,26}, clear of the vanity zones at both ends: grinded keys stay uniformly random there, restoring ~2^-32 pairwise collision odds. No RAM change (same 8-byte entry); the cache is RAM-only so there is no config-format impact. --- FILTER.md | 10 ++++++---- examples/simple_repeater/PacketFilter.cpp | 8 +++++++- examples/simple_repeater/PacketFilter.h | 7 ++++--- 3 files changed, 17 insertions(+), 8 deletions(-) diff --git a/FILTER.md b/FILTER.md index 0dfc1754..d16cc8ee 100644 --- a/FILTER.md +++ b/FILTER.md @@ -139,10 +139,12 @@ Independent of the rule list, flood-route adverts can be rate-limited **per originating node**: *each node's advert is forwarded at most once every N hours.* - `filter ratelimit advert ` sets the window (0 = off, max 720 h ≈ 30 days). -- The repeater keeps a 256-entry ring cache of origin pubkey prefixes (first 4 - bytes; two distinct nodes colliding on a prefix is a ~0.001% chance per 256 - nodes, worst case one advert falsely suppressed until the window expires) with - first-seen timestamps (RAM only — cleared on reboot). +- The repeater keeps a 256-entry ring cache of 4-byte keys sampled from the + origin pubkey at fixed middle offsets (`{8,14,20,26}` — clear of the + prefix/suffix vanity zones, so grinded vanity keys collide with plain + random-chance odds, ~0.001% per 256 distinct nodes; worst case is one advert + falsely suppressed until the window expires) with first-seen timestamps (RAM + only — cleared on reboot). - A repeated advert from a known origin inside the window is silently dropped and counted in `limiter`. After the window expires the origin is re-admitted and the window restarts. diff --git a/examples/simple_repeater/PacketFilter.cpp b/examples/simple_repeater/PacketFilter.cpp index 272a30ed..f9af4b5e 100644 --- a/examples/simple_repeater/PacketFilter.cpp +++ b/examples/simple_repeater/PacketFilter.cpp @@ -209,7 +209,13 @@ void FilterRules::clearAdvertCache() { // advert exactly once, so each origin is recorded exactly once per window. bool FilterRules::advertRatelimitDrop(const mesh::Packet* pkt, uint32_t now_millis) { uint32_t window_ms = (uint32_t)ratelimit_hours * 3600UL * 1000UL; - const uint8_t* prefix = pkt->payload; // origin pubkey = payload[0..31] + // cache key: 4 bytes sampled from the origin pubkey (payload[0..31]) at fixed + // offsets clear of the vanity zones at both ends — prefix/suffix grinding + // leaves the middle bytes uniformly random, so two vanity keys collide with + // plain random-chance odds instead of deterministically + static const uint8_t KEY_OFFSETS[4] = { 8, 14, 20, 26 }; + uint8_t prefix[4]; + for (int i = 0; i < 4; i++) prefix[i] = pkt->payload[KEY_OFFSETS[i]]; int total = advert_cache_count < FILTER_ADVERT_CACHE_SIZE ? advert_cache_count : FILTER_ADVERT_CACHE_SIZE; diff --git a/examples/simple_repeater/PacketFilter.h b/examples/simple_repeater/PacketFilter.h index 89f00b11..8036ce6b 100644 --- a/examples/simple_repeater/PacketFilter.h +++ b/examples/simple_repeater/PacketFilter.h @@ -97,9 +97,10 @@ struct FilterRule { }; struct AdvertSeenEntry { // RAM-only; cleared on reboot - uint8_t pub_key_prefix[4]; // first 4 bytes of the advert's pubkey (collision - // odds ~0.001% per 256 distinct nodes; worst case - // is one falsely suppressed advert per window) + uint8_t pub_key_prefix[4]; // 4 pubkey bytes sampled at fixed offsets (see + // advertRatelimitDrop); collision odds ~0.001% + // per 256 distinct nodes, vanity-robust; worst + // case is one falsely suppressed advert/window uint32_t first_seen_millis; // by this repeater's own monotonic clock };