simple_repeater: sample advert cache key from pubkey middle bytes

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.
This commit is contained in:
Jason Huebert authored and github-actions[bot] committed 2026-10-05 10:46:04 +00:00
1 parent 3976cc5087
commit 3aa4d48ee5
3 files changed
+17 -8

No files matched your search

+6 -4
View File
@@ -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 <hours>` 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.
+7 -1
View File
@@ -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;
+4 -3
View File
@@ -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
};