fix(relay): a name read aloud is unambiguous, and the secret label holds 128 bits

The word list had 'dong' and three words of death and estates (probate,
testament, executor); it held both a word and its inflection (accrue and
accrued, audit and audited, ...) and homophones (peer and pier, sell and
cell, current and currant, ...). Four spoken words must identify one
name, so each pair keeps the base form or one spelling, 'fulfil' is
'fulfill', and the list is 1 427 words: 41.9 bits for four, over the
40-bit floor, which a test now states. A second test scans the list for
stem + ed/s/ing pairs and a list of alike-sounding groups.

The secret label was accepted at 16 characters ('aaaaaaaaaaaaaaaa'). The
app makes it from at least 128 random bits, 25 or more base 36 characters,
and the relay now refuses a label shorter than 25.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
This commit is contained in:
swaitsandClaude Fable 5.2 committed 2026-11-21 09:52:54 -07:00
1 parent 5902580819
commit 8988769015
2 files changed
+99 -30

No files matched your search

+98 -2
View File
@@ -133,8 +133,10 @@ impl fmt::Debug for Name {
}
/// The shortest and longest secret label the relay will route. The app
/// makes the label; the relay checks only its shape.
pub const SECRET_LEN: std::ops::RangeInclusive<usize> = 16..=63;
/// makes the label, from at least 128 random bits (25 or more random
/// base 36 characters: 25 of them are 129.2 bits); the relay checks only
/// its shape, and refuses a label too short to hold that much.
pub const SECRET_LEN: std::ops::RangeInclusive<usize> = 25..=63;
/// What a host name (a TLS server name or a DNS name) is.
#[derive(Debug, Clone, PartialEq, Eq)]
@@ -243,9 +245,79 @@ mod tests {
] {
assert!(list.binary_search(&bad).is_err(), "{bad} is on the list");
}
// Words with a reading a customer would not want in an address, and
// words of death and estates (an assistant's name should not be
// "executor" or "testament" of anything).
for bad in ["dong", "probate", "testament", "executor"] {
assert!(list.binary_search(&bad).is_err(), "{bad} is on the list");
}
assert!(name_bits() > 40.0, "{} bits", name_bits());
}
/// Four words must be at least 40 bits of choice (1 024 words is the
/// floor), so a name is hard to guess and rare to collide. Removing
/// words for being confusable must be made up with finance and
/// accounting words before this goes red.
#[test]
fn four_words_are_at_least_40_bits() {
assert!(words().len() >= 1024, "{} words", words().len());
assert!(name_bits() >= 40.0, "{} bits", name_bits());
}
/// A name read aloud must be unambiguous: no word is the inflection of
/// another on the list (the base form stays), and no two words sound
/// alike.
#[test]
fn no_word_is_an_inflection_or_a_homophone_of_another() {
let list = words();
let has = |w: &str| list.binary_search(&w).is_ok();
for w in list {
for suffix in ["s", "es", "d", "ed", "ing", "ies", "ied"] {
assert!(!has(&format!("{w}{suffix}")), "{w} and {w}{suffix}");
}
if let Some(stem) = w.strip_suffix('e') {
assert!(!has(&format!("{stem}ing")), "{w} and {stem}ing");
}
if let Some(stem) = w.strip_suffix('y') {
for suffix in ["ied", "ies"] {
assert!(!has(&format!("{stem}{suffix}")), "{w} and {stem}{suffix}");
}
}
if let Some(last) = w.chars().last() {
for suffix in ["ed", "ing"] {
assert!(
!has(&format!("{w}{last}{suffix}")),
"{w} and {w}{last}{suffix}"
);
}
}
}
// Words that sound alike: at most one of each group is listed.
for group in [
["peer", "pier", "", ""],
["sell", "cell", "", ""],
["current", "currant", "", ""],
["real", "riel", "reel", ""],
["sum", "som", "some", ""],
["sole", "sol", "soul", ""],
["site", "sight", "cite", ""],
["cache", "cash", "", ""],
["fair", "fare", "", ""],
["steel", "steal", "", ""],
["suite", "sweet", "", ""],
["route", "root", "", ""],
["counsel", "council", "", ""],
["principal", "principle", "", ""],
["profit", "prophet", "", ""],
["stake", "steak", "", ""],
] {
let listed: Vec<_> = group.iter().filter(|w| !w.is_empty() && has(w)).collect();
assert!(listed.len() <= 1, "alike-sounding words listed: {listed:?}");
}
assert!(!has("fulfil"), "it is fulfill");
assert!(has("fulfill"));
}
#[test]
fn a_name_is_four_listed_words_and_prints_as_itself() {
let n = Name::parse("ledger-accrual-tally-mint").expect("listed words");
@@ -296,6 +368,30 @@ mod tests {
}
}
/// The secret label is at least 128 bits when the app makes it (25 or
/// more random base 36 characters); a label too short to hold that is
/// not routed, whatever it spells.
#[test]
fn a_secret_label_under_25_characters_is_not_routed() {
let zone = Zone::new("wanderbooks.link", "relay.wanderbooks.link");
let name = Name::parse("ledger-accrual-tally-mint").unwrap();
let on = |secret: &str| {
zone.classify(&format!(
"{secret}.ledger-accrual-tally-mint.wanderbooks.link"
))
};
assert_eq!(on("aaaaaaaaaaaaaaaa"), HostKind::Other, "16 characters");
assert_eq!(on(&"a".repeat(24)), HostKind::Other, "24 characters");
assert_eq!(on(&"a".repeat(25)), HostKind::App(name), "25 characters");
assert_eq!(on(&"a".repeat(63)), HostKind::App(name), "63 characters");
assert_eq!(on(&"a".repeat(64)), HostKind::Other, "64 characters");
assert!(
25.0 * 36f64.log2() >= 128.0,
"25 base 36 characters are 128 bits"
);
assert!(24.0 * 36f64.log2() < 128.0);
}
#[test]
fn below_names_the_labels_under_the_zone() {
let zone = Zone::new("wanderbooks.link", "relay.wanderbooks.link");
+1 -28
View File
@@ -6,7 +6,6 @@ accountant
accredit
accrual
accrue
accrued
accumulate
accurate
acquire
@@ -67,7 +66,6 @@ attain
attest
auction
audit
audited
auditor
authorize
avail
@@ -75,7 +73,6 @@ average
award
baht
balance
balanced
balboa
ballast
banker
@@ -107,10 +104,8 @@ blueprint
boardroom
bolivar
bond
bonded
bonus
book
booked
bookkeeper
bookkeeping
booth
@@ -124,7 +119,6 @@ brokerage
bronze
brook
budget
budgeted
buffer
bulk
bullion
@@ -155,7 +149,6 @@ cashier
catalog
cedar
cedi
cell
cent
centime
certificate
@@ -164,7 +157,6 @@ chamber
charity
chart
charter
chartered
check
checkbook
checklist
@@ -176,7 +168,6 @@ circuit
citrus
claim
clear
clearing
clerk
client
clientele
@@ -254,7 +245,6 @@ crop
crossfoot
crown
cumulative
currant
currency
current
curve
@@ -324,7 +314,6 @@ docket
document
dollar
domain
dong
donor
dossier
draft
@@ -393,7 +382,6 @@ excel
excess
exchange
execute
executor
exemption
exercise
exhibit
@@ -440,7 +428,6 @@ flux
folder
folio
foot
footing
footnote
footprint
forecast
@@ -462,7 +449,7 @@ freight
frequency
front
frugal
fulfil
fulfill
full
fund
fundamental
@@ -518,7 +505,6 @@ hinge
hire
historic
hold
holding
home
honest
honor
@@ -644,7 +630,6 @@ liable
liberty
library
license
licensed
lighthouse
lime
limit
@@ -655,7 +640,6 @@ linkage
liquid
lira
list
listing
literal
live
loading
@@ -698,7 +682,6 @@ marketable
mart
master
match
matched
material
mature
maximum
@@ -783,7 +766,6 @@ omit
onboard
ongoing
open
opening
operate
operator
opinion
@@ -862,7 +844,6 @@ personal
peso
petty
phase
pier
pilot
pine
pinnacle
@@ -925,7 +906,6 @@ priority
private
privilege
prize
probate
procedure
proceed
process
@@ -1079,7 +1059,6 @@ rial
ribbon
rice
ridge
riel
rigor
ring
ringgit
@@ -1123,7 +1102,6 @@ scribe
scroll
scrutiny
seal
sealed
search
season
secure
@@ -1153,7 +1131,6 @@ shift
shilling
ship
shipment
shipping
shoal
shop
sign
@@ -1176,12 +1153,10 @@ smooth
snapshot
social
society
sol
sole
solid
solution
solvent
som
sound
source
sovereign
@@ -1288,7 +1263,6 @@ tenure
term
terrace
territory
testament
thaler
thorough
thread
@@ -1351,7 +1325,6 @@ unanimous
undertake
underwrite
unearned
unified
uniform
unify
union